mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 01:06:06 +00:00
[RISCV][NFC] Refactor RISCVISAInfo.
1. Remove computeDefaultABIFromArch and add computeDefaultABI in RISCVISAInfo. 2. Add parseFeatureBits which may used in D118333. Differential Revision: https://reviews.llvm.org/D119250
This commit is contained in:
parent
5e71bbfb6c
commit
cfe7f69036
@ -272,7 +272,7 @@ bool RISCVTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
|
||||
}
|
||||
|
||||
if (ABI.empty())
|
||||
ABI = llvm::RISCV::computeDefaultABIFromArch(*ISAInfo).str();
|
||||
ABI = ISAInfo->computeDefaultABI().str();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {
|
||||
// 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
|
||||
//
|
||||
|
@ -66,6 +66,7 @@ public:
|
||||
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);
|
||||
|
@ -170,7 +170,6 @@ void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values, bool IsRV64);
|
||||
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
|
||||
|
||||
|
@ -914,3 +914,18 @@ RISCVISAInfo::postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo) {
|
||||
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");
|
||||
}
|
||||
|
@ -329,21 +329,6 @@ bool getCPUFeaturesExceptStdExt(CPUKind Kind,
|
||||
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
|
||||
|
||||
|
@ -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 @@ void validate(const Triple &TT, const FeatureBitset &FeatureBits) {
|
||||
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
|
||||
|
@ -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 @@ namespace RISCVFeatures {
|
||||
// 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
|
||||
|
||||
|
@ -45,11 +45,8 @@ void RISCVTargetStreamer::emitTargetAttributes(const MCSubtargetInfo &STI) {
|
||||
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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user