r235936 - Always add the target-cpu and target-features sets if they're non-null.

Eric Christopher echristo at gmail.com
Mon Apr 27 16:11:34 PDT 2015


Author: echristo
Date: Mon Apr 27 18:11:34 2015
New Revision: 235936

URL: http://llvm.org/viewvc/llvm-project?rev=235936&view=rev
Log:
Always add the target-cpu and target-features sets if they're non-null.
This makes sure that the front end is specific about what they're expecting
the backend to produce. Update a FIXME with the idea that the target-features
could be more precise using backend knowledge.

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    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=235936&r1=235935&r2=235936&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Apr 27 18:11:34 2015
@@ -1483,15 +1483,15 @@ void CodeGenModule::ConstructAttributeLi
 
     // Add target-cpu and target-features work if they differ from the defaults.
     std::string &CPU = getTarget().getTargetOpts().CPU;
-    if (CPU != "" && CPU != getTarget().getTriple().getArchName())
-      FuncAttrs.addAttribute("target-cpu", getTarget().getTargetOpts().CPU);
+    if (CPU != "")
+      FuncAttrs.addAttribute("target-cpu", CPU);
 
-    // TODO: FeaturesAsWritten gets us the features on the command line,
-    // for canonicalization purposes we might want to 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.
-    std::vector<std::string> &Features =
-        getTarget().getTargetOpts().FeaturesAsWritten;
+    // TODO: Features gets us the features on the command line including
+    // feature dependencies. For canonicalization purposes we might want to
+    // 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;
     if (!Features.empty()) {
       std::stringstream S;
       std::copy(Features.begin(), Features.end(),

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=235936&r1=235935&r2=235936&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/function-target-features.c (original)
+++ cfe/trunk/test/CodeGen/function-target-features.c Mon Apr 27 18:11:34 2015
@@ -7,15 +7,15 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -target-feature +avx512f -target-feature +avx512er | FileCheck %s -check-prefix=TWO-AVX
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -target-cpu corei7 | FileCheck %s -check-prefix=CORE-CPU
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -target-cpu corei7 -target-feature +avx | FileCheck %s -check-prefix=CORE-CPU-AND-FEATURES
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -target-cpu x86-64 | FileCheck %s -check-prefix=X86-64-CPU-NOT
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -target-cpu x86-64 | FileCheck %s -check-prefix=X86-64-CPU
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -target-cpu corei7-avx -target-feature -avx | FileCheck %s -check-prefix=AVX-MINUS-FEATURE
 
 void foo() {}
 
-// AVX-FEATURE: "target-features"="+avx"
+// AVX-FEATURE: "target-features"{{.*}}+avx
 // AVX-NO-CPU-NOT: target-cpu
-// TWO-AVX: "target-features"="+avx512f,+avx512er"
+// TWO-AVX: "target-features"={{.*}}+avx512er{{.*}}+avx512f
 // CORE-CPU: "target-cpu"="corei7"
-// CORE-CPU-AND-FEATURES: "target-cpu"="corei7" "target-features"="+avx"
-// X86-64-CPU-NOT: "target-cpu"
-// AVX-MINUS-FEATURE: "target-features"="-avx"
+// CORE-CPU-AND-FEATURES: "target-cpu"="corei7" "target-features"={{.*}}+avx
+// X86-64-CPU: "target-cpu"="x86-64"
+// AVX-MINUS-FEATURE: "target-features"={{.*}}-avx





More information about the cfe-commits mailing list