r241129 - Fix a TODO dealing with canonicalizing attributes on functions by

Eric Christopher echristo at gmail.com
Tue Jun 30 17:08:29 PDT 2015


Author: echristo
Date: Tue Jun 30 19:08:29 2015
New Revision: 241129

URL: http://llvm.org/viewvc/llvm-project?rev=241129&view=rev
Log:
Fix a TODO dealing with canonicalizing attributes on functions by
using a string map to canonicalize. Fix up a couple of testcases
that needed changing since we are no longer simply appending features
to the list, but all of their mask dependencies as well.

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/test/CodeGen/attr-target.c
    cfe/trunk/test/CodeGen/function-target-features.c

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=241129&r1=241128&r2=241129&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Jun 30 19:08:29 2015
@@ -1493,12 +1493,16 @@ void CodeGenModule::ConstructAttributeLi
     // avoid putting features in the target-features set if we know it'll be
     // one of the default features in the backend, e.g. corei7-avx and +avx or
     // figure out non-explicit dependencies.
-    std::vector<std::string> Features(getTarget().getTargetOpts().Features);
+    // Canonicalize the existing features in a new feature map.
+    // TODO: Migrate the existing backends to keep the map around rather than
+    // the vector.
+    llvm::StringMap<bool> FeatureMap;
+    for (auto F : getTarget().getTargetOpts().Features) {
+      const char *Name = F.c_str();
+      bool Enabled = Name[0] == '+';
+      getTarget().setFeatureEnabled(FeatureMap, Name + 1, Enabled);
+    }
 
-    // TODO: The target attribute complicates this further by allowing multiple
-    // additional features to be tacked on to the feature string for a
-    // particular function. For now we simply append to the set of features and
-    // let backend resolution fix them up.
     const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl);
     if (FD) {
       if (const TargetAttr *TD = FD->getAttr<TargetAttr>()) {
@@ -1507,7 +1511,7 @@ void CodeGenModule::ConstructAttributeLi
         FeaturesStr.split(AttrFeatures, ",");
 
         // Grab the various features and prepend a "+" to turn on the feature to
-        // the backend and add them to our existing set of Features.
+        // the backend and add them to our existing set of features.
         for (auto &Feature : AttrFeatures) {
           // While we're here iterating check for a different target cpu.
           if (Feature.startswith("arch="))
@@ -1521,13 +1525,21 @@ void CodeGenModule::ConstructAttributeLi
 	    // attributes on the function.
 	    ;
 	  else if (Feature.startswith("mno-"))
-            Features.push_back("-" + Feature.split("-").second.str());
+            getTarget().setFeatureEnabled(FeatureMap, Feature.split("-").second,
+                                          false);
           else
-            Features.push_back("+" + Feature.str());
-	}
+            getTarget().setFeatureEnabled(FeatureMap, Feature, true);
+        }
       }
     }
 
+    // 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)
+      Features.push_back((it->second ? "+" : "-") + it->first().str());
+
     // Now add the target-cpu and target-features to the function.
     if (TargetCPU != "")
       FuncAttrs.addAttribute("target-cpu", TargetCPU);

Modified: cfe/trunk/test/CodeGen/attr-target.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-target.c?rev=241129&r1=241128&r2=241129&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/attr-target.c (original)
+++ cfe/trunk/test/CodeGen/attr-target.c Tue Jun 30 19:08:29 2015
@@ -21,5 +21,5 @@ int bar(int a) { return baz(a) + foo(a);
 // CHECK: echidna{{.*}} #2
 // CHECK: bar{{.*}} #0
 // CHECK: #0 = {{.*}}"target-cpu"="x86-64" "target-features"="+sse,+sse2"
-// CHECK: #1 = {{.*}}"target-cpu"="ivybridge" "target-features"="+sse,+sse2,+avx,+sse4.2"
-// CHECK: #2 = {{.*}}"target-cpu"="x86-64" "target-features"="+sse,+sse2,-sse2"
+// CHECK: #1 = {{.*}}"target-cpu"="ivybridge" "target-features"="+sse4.2,+ssse3,+sse3,+sse,+sse2,+sse4.1,+avx"
+// CHECK: #2 = {{.*}}"target-cpu"="x86-64" "target-features"="-sse4a,-sse3,-avx2,-avx512bw,-avx512er,-avx512dq,-avx512pf,-fma4,-avx512vl,+sse,-pclmul,-avx512cd,-avx,-f16c,-ssse3,-avx512f,-fma,-xop,-aes,-sha,-sse2,-sse4.1,-sse4.2"

Modified: cfe/trunk/test/CodeGen/function-target-features.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/function-target-features.c?rev=241129&r1=241128&r2=241129&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/function-target-features.c (original)
+++ cfe/trunk/test/CodeGen/function-target-features.c Tue Jun 30 19:08:29 2015
@@ -17,7 +17,7 @@ void foo() {}
 
 // AVX-FEATURE: "target-features"{{.*}}+avx
 // AVX-NO-CPU-NOT: target-cpu
-// TWO-AVX: "target-features"={{.*}}+avx512er{{.*}}+avx512f
+// TWO-AVX: "target-features"={{.*}}+avx512f{{.*}}+avx512er
 // CORE-CPU: "target-cpu"="corei7"
 // CORE-CPU-AND-FEATURES: "target-cpu"="corei7" "target-features"={{.*}}+avx
 // X86-64-CPU: "target-cpu"="x86-64"





More information about the cfe-commits mailing list