[PATCH] D40228: [Target] Keep the TargetOptions feature list sorted instead of sorting during CodeGen

Craig Topper via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 19 13:06:01 PST 2017


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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40228.123511.patch
Type: text/x-patch
Size: 1833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171119/de02215a/attachment.bin>


More information about the cfe-commits mailing list