diff options
author | Craig Topper <craig.topper@intel.com> | 2017-11-28 18:00:32 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2017-11-28 18:00:32 +0000 |
commit | b3384001883afdf5d4fe7a1f52789386136f4a39 (patch) | |
tree | cac176fe64f6430efe1f27f31492a84deb40b940 /clang/lib/CodeGen/CGCall.cpp | |
parent | aa739695a4aed2821650bfe71cbe9c7c288d6ee6 (diff) | |
download | bcm5719-llvm-b3384001883afdf5d4fe7a1f52789386136f4a39.tar.gz bcm5719-llvm-b3384001883afdf5d4fe7a1f52789386136f4a39.zip |
[Target] Make a copy of TargetOptions feature list before sorting during CodeGen
Currently CodeGen is calling std::sort on the features vector in TargetOptions for every function, but I don't think CodeGen should be modifying TargetOptions.
Differential Revision: https://reviews.llvm.org/D40228
llvm-svn: 319195
Diffstat (limited to 'clang/lib/CodeGen/CGCall.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGCall.cpp | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 08f514f94d5..25297eb2e20 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1877,13 +1877,13 @@ void CodeGenModule::ConstructAttributeList( // we have a decl for the function and it has a target attribute then // parse that and add it to the feature set. StringRef TargetCPU = getTarget().getTargetOpts().CPU; + std::vector<std::string> Features; const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl); if (FD && FD->hasAttr<TargetAttr>()) { llvm::StringMap<bool> FeatureMap; getFunctionFeatureMap(FeatureMap, FD); // Produce the canonical string for this set of features. - std::vector<std::string> Features; for (llvm::StringMap<bool>::const_iterator it = FeatureMap.begin(), ie = FeatureMap.end(); it != ie; ++it) @@ -1898,26 +1898,19 @@ void CodeGenModule::ConstructAttributeList( if (ParsedAttr.Architecture != "" && getTarget().isValidCPUName(ParsedAttr.Architecture)) TargetCPU = ParsedAttr.Architecture; - if (TargetCPU != "") - FuncAttrs.addAttribute("target-cpu", TargetCPU); - if (!Features.empty()) { - std::sort(Features.begin(), Features.end()); - FuncAttrs.addAttribute( - "target-features", - llvm::join(Features, ",")); - } } else { // Otherwise just add the existing target cpu and target features to the // function. - std::vector<std::string> &Features = getTarget().getTargetOpts().Features; - if (TargetCPU != "") - FuncAttrs.addAttribute("target-cpu", TargetCPU); - if (!Features.empty()) { - std::sort(Features.begin(), Features.end()); - FuncAttrs.addAttribute( - "target-features", - llvm::join(Features, ",")); - } + Features = getTarget().getTargetOpts().Features; + } + + if (TargetCPU != "") + FuncAttrs.addAttribute("target-cpu", TargetCPU); + if (!Features.empty()) { + std::sort(Features.begin(), Features.end()); + FuncAttrs.addAttribute( + "target-features", + llvm::join(Features, ",")); } } |