From: Benjamin Kramer Date: Mon, 5 Mar 2012 15:10:44 +0000 (+0000) Subject: TargetInfo: create less temporary strings. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=713575afdac1f31de39b4a730143b8d96eeadb6d;p=clang TargetInfo: create less temporary strings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152029 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index ef73c82980..bbd376a824 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -587,7 +587,7 @@ public: /// /// \return - False on error (invalid feature name). virtual bool setFeatureEnabled(llvm::StringMap &Features, - const std::string &Name, + StringRef Name, bool Enabled) const { return false; } diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index a7c4f225c3..19fa423dc2 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -1007,7 +1007,7 @@ namespace { } virtual bool setFeatureEnabled(llvm::StringMap &Features, - const std::string &Name, + StringRef Name, bool Enabled) const; }; @@ -1029,7 +1029,7 @@ namespace { } bool PTXTargetInfo::setFeatureEnabled(llvm::StringMap &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 &Features, - const std::string &Name, + StringRef Name, bool Enabled) const; virtual void getDefaultFeatures(llvm::StringMap &Features) const; virtual bool hasFeature(StringRef Feature) const; @@ -1701,7 +1701,7 @@ void X86TargetInfo::getDefaultFeatures(llvm::StringMap &Features) const { } bool X86TargetInfo::setFeatureEnabled(llvm::StringMap &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 &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(Features[i].substr(1)) + X86SSEEnum Level = llvm::StringSwitch(Feature) .Case("avx2", AVX2) .Case("avx", AVX) .Case("sse42", SSE42) @@ -1859,7 +1861,7 @@ void X86TargetInfo::HandleTargetFeatures(std::vector &Features) { SSELevel = std::max(SSELevel, Level); MMX3DNowEnum ThreeDNowLevel = - llvm::StringSwitch(Features[i].substr(1)) + llvm::StringSwitch(Feature) .Case("3dnowa", AMD3DNowAthlon) .Case("3dnow", AMD3DNow) .Case("mmx", MMX) @@ -2713,7 +2715,7 @@ public: } virtual bool setFeatureEnabled(llvm::StringMap &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 &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::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();