]> granicus.if.org Git - clang/commitdiff
TargetInfo: create less temporary strings.
authorBenjamin Kramer <benny.kra@googlemail.com>
Mon, 5 Mar 2012 15:10:44 +0000 (15:10 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Mon, 5 Mar 2012 15:10:44 +0000 (15:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152029 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/TargetInfo.h
lib/Basic/Targets.cpp

index ef73c82980ef5dd043914ce01147f3c5685bb2eb..bbd376a82415823b75ab9b94b2fcd9a1ab7ac239 100644 (file)
@@ -587,7 +587,7 @@ public:
   ///
   /// \return - False on error (invalid feature name).
   virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
-                                 const std::string &Name,
+                                 StringRef Name,
                                  bool Enabled) const {
     return false;
   }
index a7c4f225c3c73d4f08855a886c5a56221266746c..19fa423dc2709496eee08d889e00b3f9565885fe 100644 (file)
@@ -1007,7 +1007,7 @@ namespace {
     }
 
     virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
-                                   const std::string &Name,
+                                   StringRef Name,
                                    bool Enabled) const;
   };
 
@@ -1029,7 +1029,7 @@ namespace {
   }
 
   bool PTXTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
-                                        const std::string &Name,
+                                        StringRef Name,
                                         bool Enabled) const {
     if(std::binary_search(AvailableFeatures.begin(), AvailableFeatures.end(),
                           Name)) {
@@ -1422,7 +1422,7 @@ public:
   virtual void getTargetDefines(const LangOptions &Opts,
                                 MacroBuilder &Builder) const;
   virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
-                                 const std::string &Name,
+                                 StringRef Name,
                                  bool Enabled) const;
   virtual void getDefaultFeatures(llvm::StringMap<bool> &Features) const;
   virtual bool hasFeature(StringRef Feature) const;
@@ -1701,7 +1701,7 @@ void X86TargetInfo::getDefaultFeatures(llvm::StringMap<bool> &Features) const {
 }
 
 bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
-                                      const std::string &Name,
+                                      StringRef Name,
                                       bool Enabled) const {
   // FIXME: This *really* should not be here.  We need some way of translating
   // options into llvm subtarget features.
@@ -1815,38 +1815,40 @@ void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) {
     if (Features[i][0] == '-')
       continue;
 
-    if (Features[i].substr(1) == "aes") {
+    StringRef Feature = StringRef(Features[i]).substr(1);
+
+    if (Feature == "aes") {
       HasAES = true;
       continue;
     }
 
-    if (Features[i].substr(1) == "lzcnt") {
+    if (Feature == "lzcnt") {
       HasLZCNT = true;
       continue;
     }
 
-    if (Features[i].substr(1) == "bmi") {
+    if (Feature == "bmi") {
       HasBMI = true;
       continue;
     }
 
-    if (Features[i].substr(1) == "bmi2") {
+    if (Feature == "bmi2") {
       HasBMI2 = true;
       continue;
     }
 
-    if (Features[i].substr(1) == "popcnt") {
+    if (Feature == "popcnt") {
       HasPOPCNT = true;
       continue;
     }
 
-    if (Features[i].substr(1) == "fma4") {
+    if (Feature == "fma4") {
       HasFMA4 = true;
       continue;
     }
 
     assert(Features[i][0] == '+' && "Invalid target feature!");
-    X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Features[i].substr(1))
+    X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
       .Case("avx2", AVX2)
       .Case("avx", AVX)
       .Case("sse42", SSE42)
@@ -1859,7 +1861,7 @@ void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) {
     SSELevel = std::max(SSELevel, Level);
 
     MMX3DNowEnum ThreeDNowLevel =
-      llvm::StringSwitch<MMX3DNowEnum>(Features[i].substr(1))
+      llvm::StringSwitch<MMX3DNowEnum>(Feature)
         .Case("3dnowa", AMD3DNowAthlon)
         .Case("3dnow", AMD3DNow)
         .Case("mmx", MMX)
@@ -2713,7 +2715,7 @@ public:
   }
 
   virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
-                                 const std::string &Name,
+                                 StringRef Name,
                                  bool Enabled) const {
     if (Name == "soft-float" || Name == "soft-float-abi" ||
         Name == "vfp2" || Name == "vfp3" || Name == "neon" || Name == "d16") {
@@ -3148,7 +3150,7 @@ public:
                         "i64:64:64-f32:32:32-f64:64:64-v64:64:64-n32";
   }
   virtual bool setFeatureEnabled(llvm::StringMap<bool> &Features,
-                                 const std::string &Name,
+                                 StringRef Name,
                                  bool Enabled) const {
     if (Name == "soft-float")
       Features[Name] = Enabled;
@@ -4117,8 +4119,7 @@ TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
   Opts.Features.clear();
   for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
          ie = Features.end(); it != ie; ++it)
-    Opts.Features.push_back(std::string(it->second ? "+" : "-") +
-                            it->first().str());
+    Opts.Features.push_back((it->second ? "+" : "-") + it->first().str());
   Target->HandleTargetFeatures(Opts.Features);
 
   return Target.take();