khchen created this revision. khchen added reviewers: asb, kito-cheng, craig.topper, jrtc27. Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, vkmr, frasercrmck, dexonsmith, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya. khchen requested review of this revision. Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, eopXD, MaskRay. Herald added projects: clang, LLVM.
1. Remove computeDefaultABIFromArch and add computeDefaultABI in RISCVISAInfo. 2. Add parseFeatureBits which may used in D118333 <https://reviews.llvm.org/D118333>. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D119250 Files: clang/lib/Basic/Targets/RISCV.cpp clang/lib/Driver/ToolChains/Arch/RISCV.cpp llvm/include/llvm/Support/RISCVISAInfo.h llvm/include/llvm/Support/TargetParser.h llvm/lib/Support/RISCVISAInfo.cpp llvm/lib/Support/TargetParser.cpp llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp =================================================================== --- llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp +++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp @@ -45,11 +45,8 @@ else emitAttribute(RISCVAttrs::STACK_ALIGN, RISCVAttrs::ALIGN_16); - unsigned XLen = STI.hasFeature(RISCV::Feature64Bit) ? 64 : 32; - std::vector<std::string> FeatureVector; - RISCVFeatures::toFeatureVector(FeatureVector, STI.getFeatureBits()); - - auto ParseResult = llvm::RISCVISAInfo::parseFeatures(XLen, FeatureVector); + auto ParseResult = RISCVFeatures::parseFeatureBits( + STI.hasFeature(RISCV::Feature64Bit), STI.getFeatureBits()); if (!ParseResult) { /* Assume any error about features should handled earlier. */ consumeError(ParseResult.takeError()); Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h =================================================================== --- llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h +++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h @@ -18,6 +18,7 @@ #include "llvm/ADT/StringSwitch.h" #include "llvm/MC/MCInstrDesc.h" #include "llvm/MC/SubtargetFeature.h" +#include "llvm/Support/RISCVISAInfo.h" namespace llvm { @@ -344,9 +345,8 @@ // triple. Exits with report_fatal_error if not. void validate(const Triple &TT, const FeatureBitset &FeatureBits); -// Convert FeatureBitset to FeatureVector. -void toFeatureVector(std::vector<std::string> &FeatureVector, - const FeatureBitset &FeatureBits); +llvm::Expected<std::unique_ptr<RISCVISAInfo>> +parseFeatureBits(bool IsRV64, const FeatureBitset &FeatureBits); } // namespace RISCVFeatures Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp =================================================================== --- llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp +++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp @@ -16,6 +16,7 @@ #include "llvm/ADT/Triple.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Support/RISCVISAInfo.h" +#include "llvm/Support/TargetParser.h" #include "llvm/Support/raw_ostream.h" namespace llvm { @@ -106,13 +107,17 @@ report_fatal_error("RV32E can't be enabled for an RV64 target"); } -void toFeatureVector(std::vector<std::string> &FeatureVector, - const FeatureBitset &FeatureBits) { +llvm::Expected<std::unique_ptr<RISCVISAInfo>> +parseFeatureBits(bool IsRV64, const FeatureBitset &FeatureBits) { + unsigned XLen = IsRV64 ? 64 : 32; + std::vector<std::string> FeatureVector; + // Convert FeatureBitset to FeatureVector. for (auto Feature : RISCVFeatureKV) { if (FeatureBits[Feature.Value] && llvm::RISCVISAInfo::isSupportedExtensionFeature(Feature.Key)) FeatureVector.push_back(std::string("+") + Feature.Key); } + return llvm::RISCVISAInfo::parseFeatures(XLen, FeatureVector); } } // namespace RISCVFeatures Index: llvm/lib/Support/TargetParser.cpp =================================================================== --- llvm/lib/Support/TargetParser.cpp +++ llvm/lib/Support/TargetParser.cpp @@ -329,21 +329,6 @@ return true; } -StringRef computeDefaultABIFromArch(const llvm::RISCVISAInfo &ISAInfo) { - if (ISAInfo.getXLen() == 32) { - if (ISAInfo.hasExtension("d")) - return "ilp32d"; - if (ISAInfo.hasExtension("e")) - return "ilp32e"; - return "ilp32"; - } else if (ISAInfo.getXLen() == 64) { - if (ISAInfo.hasExtension("d")) - return "lp64d"; - return "lp64"; - } - llvm_unreachable("Invalid XLEN"); -} - } // namespace RISCV } // namespace llvm Index: llvm/lib/Support/RISCVISAInfo.cpp =================================================================== --- llvm/lib/Support/RISCVISAInfo.cpp +++ llvm/lib/Support/RISCVISAInfo.cpp @@ -914,3 +914,18 @@ return std::move(Result); return std::move(ISAInfo); } + +StringRef RISCVISAInfo::computeDefaultABI() const { + if (XLen == 32) { + if (hasExtension("d")) + return "ilp32d"; + if (hasExtension("e")) + return "ilp32e"; + return "ilp32"; + } else if (XLen == 64) { + if (hasExtension("d")) + return "lp64d"; + return "lp64"; + } + llvm_unreachable("Invalid XLEN"); +} Index: llvm/include/llvm/Support/TargetParser.h =================================================================== --- llvm/include/llvm/Support/TargetParser.h +++ llvm/include/llvm/Support/TargetParser.h @@ -170,7 +170,6 @@ void fillValidTuneCPUArchList(SmallVectorImpl<StringRef> &Values, bool IsRV64); bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector<StringRef> &Features); StringRef resolveTuneCPUAlias(StringRef TuneCPU, bool IsRV64); -StringRef computeDefaultABIFromArch(const llvm::RISCVISAInfo &ISAInfo); } // namespace RISCV Index: llvm/include/llvm/Support/RISCVISAInfo.h =================================================================== --- llvm/include/llvm/Support/RISCVISAInfo.h +++ llvm/include/llvm/Support/RISCVISAInfo.h @@ -66,6 +66,7 @@ bool hasExtension(StringRef Ext) const; std::string toString() const; std::vector<std::string> toFeatureVector() const; + StringRef computeDefaultABI() const; static bool isSupportedExtensionFeature(StringRef Ext); static bool isSupportedExtension(StringRef Ext); Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/RISCV.cpp +++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp @@ -198,7 +198,7 @@ // Ignore parsing error, just go 3rd step. consumeError(ParseResult.takeError()); else - return llvm::RISCV::computeDefaultABIFromArch(**ParseResult); + return (*ParseResult)->computeDefaultABI(); // 3. Choose a default based on the triple // Index: clang/lib/Basic/Targets/RISCV.cpp =================================================================== --- clang/lib/Basic/Targets/RISCV.cpp +++ clang/lib/Basic/Targets/RISCV.cpp @@ -272,7 +272,7 @@ } if (ABI.empty()) - ABI = llvm::RISCV::computeDefaultABIFromArch(*ISAInfo).str(); + ABI = ISAInfo->computeDefaultABI().str(); return true; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits