]> granicus.if.org Git - clang/commitdiff
Fix a TODO dealing with canonicalizing attributes on functions by
authorEric Christopher <echristo@gmail.com>
Wed, 1 Jul 2015 00:08:29 +0000 (00:08 +0000)
committerEric Christopher <echristo@gmail.com>
Wed, 1 Jul 2015 00:08:29 +0000 (00:08 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241129 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCall.cpp
test/CodeGen/attr-target.c
test/CodeGen/function-target-features.c

index 58ef171df0d75b1b5b8b93ed5c995610994165fb..245b8274a90e5b88eedf0a7bac5a98e34bf251c2 100644 (file)
@@ -1493,12 +1493,16 @@ void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
     // 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::ConstructAttributeList(const CGFunctionInfo &FI,
         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::ConstructAttributeList(const CGFunctionInfo &FI,
            // 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);
index 8c0f335f857da41d7cbb34f9cff8b20b0e095fdc..a42705a478423d7c5bbee2302afc7295f8a7f177 100644 (file)
@@ -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"
index 351c7f102b12b6e745262140257003bc9b25c7b8..133e89cbbe349dae382895f5851759838fe7a86e 100644 (file)
@@ -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"