]> granicus.if.org Git - clang/commitdiff
Add some enum goodness as requested by Chris. Now instead of storing the
authorCharles Davis <cdavis@mines.edu>
Thu, 19 Aug 2010 02:18:14 +0000 (02:18 +0000)
committerCharles Davis <cdavis@mines.edu>
Thu, 19 Aug 2010 02:18:14 +0000 (02:18 +0000)
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. :)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111507 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 9f7debf9c5006a2633ba1b43a8c17499c792bd8b..11e009cb01ea49c95af66ebcee8259307b600897 100644 (file)
@@ -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 @@ class TargetOptions;
 
 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 @@ protected:
   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 @@ public:
   }
 
   /// getCXXABI - Get the C++ ABI in use.
-  virtual llvm::StringRef getCXXABI() const {
+  virtual TargetCXXABI getCXXABI() const {
     return CXXABI;
   }
 
@@ -434,11 +442,13 @@ public:
 
   /// 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;
   }
 
index f53a50e3145955f5e69e38d3de73505c0654e00a..95893a46164ad86e82a19ef1ea784b03593a5fde 100644 (file)
@@ -137,10 +137,12 @@ ASTContext::getCanonicalTemplateTemplateParmDecl(
 
 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,
index 907c359ce4a130d648a8b398566f303a1cbb7ce0..ff77561419e6299c9ac7ea80171b2d73707ebe4a 100644 (file)
@@ -1463,8 +1463,6 @@ RecordLayoutBuilder::ComputeKeyFunction(const CXXRecordDecl *RD) {
 
 // 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 @@ const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D) {
 
     // 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
index 72ec584f6c8606249e386edf8677957da73bdbcf..c0df55b808d68ffb533a99380506562b1147134b 100644 (file)
@@ -90,10 +90,13 @@ void CodeGenModule::createObjCRuntime() {
 }
 
 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() {
index e3628c1d5f09355849f547927a978805e3822f35..1fdb17f4d2a719629372005d9a8b46be86f9bb6e 100644 (file)
@@ -897,7 +897,7 @@ QualType Sema::BuildMemberPointerType(QualType T, QualType Class,
   // 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();