From b3384001883afdf5d4fe7a1f52789386136f4a39 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 28 Nov 2017 18:00:32 +0000 Subject: [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 --- clang/lib/CodeGen/CGCall.cpp | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'clang/lib/CodeGen/CGCall.cpp') 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 Features; const FunctionDecl *FD = dyn_cast_or_null(TargetDecl); if (FD && FD->hasAttr()) { llvm::StringMap FeatureMap; getFunctionFeatureMap(FeatureMap, FD); // Produce the canonical string for this set of features. - std::vector Features; for (llvm::StringMap::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 &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, ",")); } } -- cgit v1.2.3