[llvm] [RISCV] Add getFeaturesForCPU function support (PR #83269)

Brandon Wu via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 18:00:08 PST 2024


================
@@ -95,5 +96,31 @@ void fillValidTuneCPUArchList(SmallVectorImpl<StringRef> &Values, bool IsRV64) {
 #include "llvm/TargetParser/RISCVTargetParserDef.inc"
 }
 
+void getFeaturesForCPU(StringRef CPU,
+                       SmallVectorImpl<std::string> &EnabledFeatures,
+                       bool NeedPlus) {
+  StringRef MarchFromCPU = llvm::RISCV::getMArchFromMcpu(CPU);
+  if (MarchFromCPU == "")
+    return;
+
+  EnabledFeatures.clear();
+  auto RII = RISCVISAInfo::parseArchString(
+      MarchFromCPU, /* EnableExperimentalExtension */ true);
+
+  if (llvm::errorToBool(RII.takeError()))
+    return;
+
+  std::vector<std::string> FeatStrings =
+      (*RII)->toFeatures(/* AddAllExtensions */ true);
+  for (const auto &F : FeatStrings) {
+    if (F[0] == '-')
----------------
4vtomat wrote:

You are right, I can set AddAllExtensions=false directly.

https://github.com/llvm/llvm-project/pull/83269


More information about the llvm-commits mailing list