================
@@ -727,18 +727,55 @@ llvm::APInt 
PPCTargetInfo::getFMVPriority(ArrayRef<StringRef> Features) const {
     return llvm::APInt(32, 0);
   assert(Features.size() == 1 && "one feature/cpu per clone on PowerPC");
   ParsedTargetAttr ParsedAttr = parseTargetAttr(Features[0]);
+
+  // Priority scheme:
+  // CPU specifications: 100-500 (pwr7=100, pwr8=200, ..., pwr11=500)
+  // For target-features, they can be divided into 3 categories:
+  // 1) non-CPU properties (e.g. invariant-function-descriptors); those cannot
+  //    be tested at runtime, and are currently excluded from target_clones.
+  // 2) CPU properties that cannot be disabled (e.g. mma); these features map 
to
+  //    CPUs directly:
+  //     +feature => __builtin_cpu_supports("<minimum-cpu>")
+  //              => true for CPU <minimum-cpu> and above.
+  //     -feature => !__builtin_cpu_supports("<minimum-cpu>")
+  //              => true for CPU <minimum-cpu-minus-one> and below.
+  // 3) CPU properties that can be disabled (e.g. vsx); those can map to CPUs
+  // directly for the positive requirement (same as (2));
+  // for the negative requirement checking the CPU is incorrect:
+  //   target_clones(no-vsx, cpu=pwr8)
+  // should pick no-vsx when vsx is disabled at runtime, so we need to test
+  // negative form of category 3 first, and will only allow one negative form
+  // from this category on a target_clones.
   if (!ParsedAttr.CPU.empty()) {
     int Priority = llvm::StringSwitch<int>(ParsedAttr.CPU)
-                       .Case("pwr7", 1)
-                       .Case("pwr8", 2)
-                       .Case("pwr9", 3)
-                       .Case("pwr10", 4)
-                       .Case("pwr11", 5)
+#define PPC_AIX_CLONES_CPU(CPU_NAME, _, PRIORITY) .Case(CPU_NAME, PRIORITY)
+#include "llvm/TargetParser/PPCTargetParser.def"
+                       .Default(0);
+    return llvm::APInt(32, Priority);
+  }
+
+  // Feature strings
+  if (ParsedAttr.Features.size() == 1) {
+    StringRef Feature = ParsedAttr.Features[0];
+    bool IsNegated = Feature.starts_with("-");
+    // Remove leading '+' or '-'
+    if (Feature.starts_with("+") || Feature.starts_with("-"))
+      Feature = Feature.drop_front(1);
+
+    // Check if this is a negative category 3 feature (highest priority)
+    // Sema guarantees there's only one such version on a target_clones.
+    if (IsNegated && llvm::PPC::canDisableFeatureOnAIX(Feature))
+      return llvm::APInt(32, NEGATIVE_FEATURE_PRIORITY);
+
+    // Regular feature priority (positive or negative category 2)
+    int Priority = llvm::StringSwitch<int>(Feature)
+#define PPC_AIX_CLONES_FEATURE(FEATURE_NAME, _, PRIORITY)                      
\
+  .Case(FEATURE_NAME, PRIORITY)
+#include "llvm/TargetParser/PPCTargetParser.def"
                        .Default(0);
     return llvm::APInt(32, Priority);
   }
-  assert(false && "unimplemented");
-  return llvm::APInt(32, 0);
+  llvm_unreachable("Invalid target_clones parameter");
----------------
w2yehia wrote:

I feel Diags.Report doesn't suite here. 
getFMVPriority is called during Codegen, after Sema has verified (to the best 
of its abilities) the user input is valid. 
The unreachable points to an internal error, so it can be replaced with an 
assertion, but an unreachable don't turn to no-ops in non-assert builds.

https://github.com/llvm/llvm-project/pull/206786
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to