craig.topper created this revision.
Herald added a subscriber: nhaehnle.
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.
This moves the sorting up to the creation/modification of TargetOptions.
https://reviews.llvm.org/D40228
Files:
lib/Basic/Targets.cpp
lib/Basic/Targets/AMDGPU.cpp
lib/CodeGen/CGCall.cpp
Index: lib/CodeGen/CGCall.cpp
===================================================================
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1909,11 +1909,13 @@
} else {
// Otherwise just add the existing target cpu and target features to the
// function.
- std::vector<std::string> &Features =
getTarget().getTargetOpts().Features;
+ const std::vector<std::string> &Features =
+ getTarget().getTargetOpts().Features;
if (TargetCPU != "")
FuncAttrs.addAttribute("target-cpu", TargetCPU);
if (!Features.empty()) {
- std::sort(Features.begin(), Features.end());
+ assert(std::is_sorted(Features.begin(), Features.end()) &&
+ "Features not sorted?");
FuncAttrs.addAttribute(
"target-features",
llvm::join(Features, ","));
Index: lib/Basic/Targets/AMDGPU.cpp
===================================================================
--- lib/Basic/Targets/AMDGPU.cpp
+++ lib/Basic/Targets/AMDGPU.cpp
@@ -226,6 +226,9 @@
// Always do not flush fp64 or fp16 denorms.
if (!hasFP64Denormals && hasFP64)
TargetOpts.Features.push_back("+fp64-fp16-denormals");
+
+ // Re-sort the features for CodeGen.
+ std::sort(TargetOpts.Features.begin(), TargetOpts.Features.end());
}
AMDGPUTargetInfo::GPUKind AMDGPUTargetInfo::parseR600Name(StringRef Name) {
Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -618,6 +618,9 @@
if (!Target->handleTargetFeatures(Opts->Features, Diags))
return nullptr;
+ // Sort the features.
+ std::sort(Opts->Features.begin(), Opts->Features.end());
+
Target->setSupportedOpenCLOpts();
Target->setOpenCLExtensionOpts();
Target->setMaxAtomicWidth();
Index: lib/CodeGen/CGCall.cpp
===================================================================
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1909,11 +1909,13 @@
} else {
// Otherwise just add the existing target cpu and target features to the
// function.
- std::vector<std::string> &Features = getTarget().getTargetOpts().Features;
+ const std::vector<std::string> &Features =
+ getTarget().getTargetOpts().Features;
if (TargetCPU != "")
FuncAttrs.addAttribute("target-cpu", TargetCPU);
if (!Features.empty()) {
- std::sort(Features.begin(), Features.end());
+ assert(std::is_sorted(Features.begin(), Features.end()) &&
+ "Features not sorted?");
FuncAttrs.addAttribute(
"target-features",
llvm::join(Features, ","));
Index: lib/Basic/Targets/AMDGPU.cpp
===================================================================
--- lib/Basic/Targets/AMDGPU.cpp
+++ lib/Basic/Targets/AMDGPU.cpp
@@ -226,6 +226,9 @@
// Always do not flush fp64 or fp16 denorms.
if (!hasFP64Denormals && hasFP64)
TargetOpts.Features.push_back("+fp64-fp16-denormals");
+
+ // Re-sort the features for CodeGen.
+ std::sort(TargetOpts.Features.begin(), TargetOpts.Features.end());
}
AMDGPUTargetInfo::GPUKind AMDGPUTargetInfo::parseR600Name(StringRef Name) {
Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -618,6 +618,9 @@
if (!Target->handleTargetFeatures(Opts->Features, Diags))
return nullptr;
+ // Sort the features.
+ std::sort(Opts->Features.begin(), Opts->Features.end());
+
Target->setSupportedOpenCLOpts();
Target->setOpenCLExtensionOpts();
Target->setMaxAtomicWidth();
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits