[llvm] [RFC][CodeGen] Add generic target feature checks for intrinsics (PR #201470)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 4 01:53:33 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");
----------------
arsenm wrote:
report_fatal_error is deprecated
https://github.com/llvm/llvm-project/pull/201470
More information about the llvm-commits
mailing list