[llvm] [RFC][CodeGen] Add generic target feature checks for intrinsics (PR #201470)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 12 04:29:00 PDT 2026
================
@@ -340,6 +340,98 @@ bool MCSubtargetInfo::checkFeatures(StringRef FS) const {
});
}
+static bool hasFeature(StringRef Feature, const FeatureBitset &FeatureBits,
+ ArrayRef<SubtargetFeatureKV> ProcFeatures) {
+ bool ShouldBeEnabled = true;
+ if (Feature.consume_front("+"))
+ ShouldBeEnabled = true;
+ else if (Feature.consume_front("-"))
+ ShouldBeEnabled = false;
+
+ const SubtargetFeatureKV *FeatureEntry = Find(Feature, ProcFeatures);
+ if (!FeatureEntry) {
+ report_fatal_error(Twine("'") + Feature +
+ "' is not a recognized feature for this target");
+ }
+
+ return FeatureBits.test(FeatureEntry->Value) == ShouldBeEnabled;
+}
+
+namespace {
+class FeatureExpressionParser {
+ StringRef Expr;
+ const FeatureBitset &FeatureBits;
+ ArrayRef<SubtargetFeatureKV> ProcFeatures;
+ size_t Pos = 0;
+
+public:
+ FeatureExpressionParser(StringRef Expr, const FeatureBitset &FeatureBits,
+ ArrayRef<SubtargetFeatureKV> ProcFeatures)
+ : Expr(Expr), FeatureBits(FeatureBits), ProcFeatures(ProcFeatures) {}
+
+ bool parse() {
+ bool Result = parseOr();
+ if (Pos != Expr.size())
+ report_fatal_error("malformed target feature expression");
+ return Result;
+ }
+
+private:
+ bool consume(char C) {
+ if (Pos == Expr.size() || Expr[Pos] != C)
+ return false;
+ ++Pos;
+ return true;
+ }
+
+ bool parseOr() {
+ bool Result = parseAnd();
+ while (consume('|')) {
+ bool RHS = parseAnd();
+ Result = Result || RHS;
+ }
+ return Result;
+ }
+
+ bool parseAnd() {
+ bool Result = parsePrimary();
+ while (consume(',')) {
+ bool RHS = parsePrimary();
+ Result = Result && RHS;
----------------
Pierre-vh wrote:
```suggestion
Result &= parsePrimary();
```
?
https://github.com/llvm/llvm-project/pull/201470
More information about the llvm-commits
mailing list