[cfe-commits] r111507 - in /cfe/trunk: include/clang/Basic/TargetInfo.h lib/AST/ASTContext.cpp lib/AST/RecordLayoutBuilder.cpp lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaType.cpp

Charles Davis cdavis at mines.edu
Wed Aug 18 19:18:14 PDT 2010


Author: cdavis
Date: Wed Aug 18 21:18:14 2010
New Revision: 111507

URL: http://llvm.org/viewvc/llvm-project?rev=111507&view=rev
Log:
Add some enum goodness as requested by Chris. Now instead of storing the
active C++ ABI as a raw string, we store it as an enum. This should improve
performance somewhat.

And yes, this time, I started from a clean build directory, and
all the tests passed. :)

Modified:
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=111507&r1=111506&r2=111507&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Wed Aug 18 21:18:14 2010
@@ -16,6 +16,7 @@
 
 // FIXME: Daniel isn't smart enough to use a prototype for this.
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/System/DataTypes.h"
 #include <cassert>
@@ -37,6 +38,13 @@
 
 namespace Builtin { struct Info; }
 
+/// TargetCXXABI - The types of C++ ABIs for which we can generate code.
+enum TargetCXXABI {
+  CXXABI_Unknown = -1,
+  CXXABI_Itanium,
+  CXXABI_Microsoft
+};
+
 /// TargetInfo - This class exposes information about the current target.
 ///
 class TargetInfo {
@@ -58,7 +66,7 @@
   const char *UserLabelPrefix;
   const llvm::fltSemantics *FloatFormat, *DoubleFormat, *LongDoubleFormat;
   unsigned char RegParmMax, SSERegParmMax;
-  std::string CXXABI;
+  TargetCXXABI CXXABI;
 
   unsigned HasAlignMac68kSupport : 1;
   unsigned RealTypeUsesObjCFPRet : 3;
@@ -412,7 +420,7 @@
   }
 
   /// getCXXABI - Get the C++ ABI in use.
-  virtual llvm::StringRef getCXXABI() const {
+  virtual TargetCXXABI getCXXABI() const {
     return CXXABI;
   }
 
@@ -434,11 +442,13 @@
 
   /// setCXXABI - Use this specific C++ ABI.
   ///
-  /// \return - False on error (invalid ABI name).
+  /// \return - False on error (invalid C++ ABI name).
   virtual bool setCXXABI(const std::string &Name) {
-    if (Name != "itanium" && Name != "microsoft")
-      return false;
-    CXXABI = Name;
+    CXXABI = llvm::StringSwitch<TargetCXXABI>(Name)
+      .Case("itanium", CXXABI_Itanium)
+      .Case("microsoft", CXXABI_Microsoft)
+      .Default(CXXABI_Unknown);
+    if (CXXABI == CXXABI_Unknown) return false;
     return true;
   }
 

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=111507&r1=111506&r2=111507&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Aug 18 21:18:14 2010
@@ -137,10 +137,12 @@
 
 CXXABI *ASTContext::createCXXABI(const TargetInfo &T) {
   if (!LangOpts.CPlusPlus) return NULL;
-  if (T.getCXXABI() == "microsoft")
-    return CreateMicrosoftCXXABI(*this);
-  else
+  switch (T.getCXXABI()) {
+  default:
     return CreateItaniumCXXABI(*this);
+  case CXXABI_Microsoft:
+    return CreateMicrosoftCXXABI(*this);
+  }
 }
 
 ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=111507&r1=111506&r2=111507&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed Aug 18 21:18:14 2010
@@ -1463,8 +1463,6 @@
 
 // This class implements layout specific to the Microsoft ABI.
 class MSRecordLayoutBuilder: public RecordLayoutBuilder {
-  friend class ASTContext;
-
 public:
   MSRecordLayoutBuilder(ASTContext& Ctx, EmptySubobjectMap *EmptySubobjects):
     RecordLayoutBuilder(Ctx, EmptySubobjects) {}
@@ -1514,10 +1512,13 @@
 
     // When compiling for Microsoft, use the special MS builder.
     RecordLayoutBuilder *Builder;
-    if (Target.getCXXABI() == "microsoft")
-      Builder = new MSRecordLayoutBuilder(*this, &EmptySubobjects);
-    else
+    switch (Target.getCXXABI()) {
+    default:
       Builder = new RecordLayoutBuilder(*this, &EmptySubobjects);
+      break;
+    case CXXABI_Microsoft:
+      Builder = new MSRecordLayoutBuilder(*this, &EmptySubobjects);
+    }
     Builder->Layout(RD);
 
     // FIXME: This is not always correct. See the part about bitfields at

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=111507&r1=111506&r2=111507&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Aug 18 21:18:14 2010
@@ -90,10 +90,13 @@
 }
 
 void CodeGenModule::createCXXABI() {
-  if (Context.Target.getCXXABI() == "microsoft")
-    ABI = CreateMicrosoftCXXABI(*this);
-  else
+  switch (Context.Target.getCXXABI()) {
+  default:
     ABI = CreateItaniumCXXABI(*this);
+    break;
+  case CXXABI_Microsoft:
+    ABI = CreateMicrosoftCXXABI(*this);
+  }
 }
 
 void CodeGenModule::Release() {

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=111507&r1=111506&r2=111507&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Aug 18 21:18:14 2010
@@ -897,7 +897,7 @@
   // type. In such cases, the compiler makes a worst-case assumption.
   // We make no such assumption right now, so emit an error if the
   // class isn't a complete type.
-  if (Context.Target.getCXXABI() == "microsoft" &&
+  if (Context.Target.getCXXABI() == CXXABI_Microsoft &&
       RequireCompleteType(Loc, Class, diag::err_incomplete_type))
     return QualType();
 





More information about the cfe-commits mailing list