diff --git a/llvm/include/llvm/TargetParser/RISCVTargetParser.h b/llvm/include/llvm/TargetParser/RISCVTargetParser.h index e7da677c7d3ea..553b4efe0e303 100644 --- a/llvm/include/llvm/TargetParser/RISCVTargetParser.h +++ b/llvm/include/llvm/TargetParser/RISCVTargetParser.h @@ -25,6 +25,9 @@ namespace RISCV { // We use 64 bits as the known part in the scalable vector types. static constexpr unsigned RVVBitsPerBlock = 64; +void getFeaturesForCPU(StringRef CPU, + SmallVectorImpl &EnabledFeatures, + bool NeedPlus = false); bool parseCPU(StringRef CPU, bool IsRV64); bool parseTuneCPU(StringRef CPU, bool IsRV64); StringRef getMArchFromMcpu(StringRef CPU); diff --git a/llvm/lib/TargetParser/RISCVTargetParser.cpp b/llvm/lib/TargetParser/RISCVTargetParser.cpp index 85cdd1289a953..8036df46fb47f 100644 --- a/llvm/lib/TargetParser/RISCVTargetParser.cpp +++ b/llvm/lib/TargetParser/RISCVTargetParser.cpp @@ -14,6 +14,7 @@ #include "llvm/TargetParser/RISCVTargetParser.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/Support/RISCVISAInfo.h" #include "llvm/TargetParser/Triple.h" namespace llvm { @@ -95,5 +96,28 @@ void fillValidTuneCPUArchList(SmallVectorImpl &Values, bool IsRV64) { #include "llvm/TargetParser/RISCVTargetParserDef.inc" } +// This function is currently used by IREE, so it's not dead code. +void getFeaturesForCPU(StringRef CPU, + SmallVectorImpl &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 FeatStrings = + (*RII)->toFeatures(/* AddAllExtensions */ false); + for (const auto &F : FeatStrings) + if (NeedPlus) + EnabledFeatures.push_back(F); + else + EnabledFeatures.push_back(F.substr(1)); +} } // namespace RISCV } // namespace llvm