[llvm] [RISCV] Introduce a new tune feature string syntax and its parser (PR #168160)
Sam Elliott via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 17 20:02:15 PST 2025
================
@@ -145,6 +149,101 @@ void getFeaturesForCPU(StringRef CPU,
EnabledFeatures.push_back(F.substr(1));
}
+using RISCVImpliedTuneFeature = std::pair<const char *, const char *>;
+
+#define GET_TUNE_FEATURES
+#define GET_IMPLIED_TUNE_FEATURES
+#include "llvm/TargetParser/RISCVTargetParserDef.inc"
+
+void getAllTuneFeatures(SmallVectorImpl<StringRef> &Features) {
+ Features.assign(std::begin(TuneFeatures), std::end(TuneFeatures));
+}
+
+Error parseTuneFeatureString(StringRef TFString,
+ SmallVectorImpl<std::string> &ResFeatures) {
+ const StringSet<> AllTuneFeatureSet(llvm::from_range, TuneFeatures);
+ using SmallStringSet = SmallSet<StringRef, 4>;
+
+ TFString = TFString.trim();
+ // Note: StringSet is not really ergnomic to use in this case here.
+ SmallStringSet PositiveFeatures;
+ SmallStringSet NegativeFeatures;
+ // Phase 1: Collect explicit features.
+ StringRef FeatureStr;
+ do {
+ std::tie(FeatureStr, TFString) = TFString.split(",");
+ if (AllTuneFeatureSet.count(FeatureStr)) {
+ if (!PositiveFeatures.insert(FeatureStr).second)
+ return createStringError(inconvertibleErrorCode(),
+ "cannot specify more than one instance of '" +
+ Twine(FeatureStr) + "'");
+ } else if (FeatureStr.starts_with("no-")) {
+ // Check if this is a negative feature, like `no-foo` for `foo`.
+ StringRef ActualFeature = FeatureStr.drop_front(3);
+ if (AllTuneFeatureSet.count(ActualFeature)) {
+ if (!NegativeFeatures.insert(ActualFeature).second)
+ return createStringError(
+ inconvertibleErrorCode(),
+ "cannot specify more than one instance of '" + Twine(FeatureStr) +
+ "'");
+ }
+ } else {
+ return createStringError(inconvertibleErrorCode(),
+ "unrecognized tune feature directive '" +
+ Twine(FeatureStr) + "'");
----------------
lenary wrote:
Agreed.
https://github.com/llvm/llvm-project/pull/168160
More information about the llvm-commits
mailing list