summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2024-05-01 10:44:10 -0700
committerGitHub <noreply@github.com>2024-05-01 10:44:10 -0700
commitcf3c714e4bd7b8a68793f2827080fe3388ae8bb1 (patch)
tree98632ffc1e5ad1ec364ebec6e52c8000aa482a17
parent09f4b06dde65adcd077bd1d10f1165083c1fe410 (diff)
[RISCV] Merge RISCVISAInfo::updateFLen/MinVLen/MaxELen into a single function. (#90665)
This simplifies the callers.
-rw-r--r--llvm/include/llvm/TargetParser/RISCVISAInfo.h15
-rw-r--r--llvm/lib/TargetParser/RISCVISAInfo.cpp63
2 files changed, 37 insertions, 41 deletions
diff --git a/llvm/include/llvm/TargetParser/RISCVISAInfo.h b/llvm/include/llvm/TargetParser/RISCVISAInfo.h
index 0d5637155daa..36617a9b6259 100644
--- a/llvm/include/llvm/TargetParser/RISCVISAInfo.h
+++ b/llvm/include/llvm/TargetParser/RISCVISAInfo.h
@@ -78,13 +78,12 @@ public:
static std::string getTargetFeatureForExtension(StringRef Ext);
private:
- RISCVISAInfo(unsigned XLen)
- : XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {}
+ RISCVISAInfo(unsigned XLen) : XLen(XLen) {}
unsigned XLen;
- unsigned FLen;
- unsigned MinVLen;
- unsigned MaxELen, MaxELenFp;
+ unsigned FLen = 0;
+ unsigned MinVLen = 0;
+ unsigned MaxELen = 0, MaxELenFp = 0;
RISCVISAUtils::OrderedExtensionMap Exts;
@@ -94,9 +93,9 @@ private:
void updateImplication();
void updateCombination();
- void updateFLen();
- void updateMinVLen();
- void updateMaxELen();
+
+ /// Update FLen, MinVLen, MaxELen, and MaxELenFp.
+ void updateImpliedLengths();
};
} // namespace llvm
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index d154c00a7859..64405ca8cb9f 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -478,9 +478,7 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
"failed to parse major version number");
ISAInfo->addExtension(ExtName, {MajorVersion, MinorVersion});
}
- ISAInfo->updateFLen();
- ISAInfo->updateMinVLen();
- ISAInfo->updateMaxELen();
+ ISAInfo->updateImpliedLengths();
return std::move(ISAInfo);
}
@@ -906,50 +904,51 @@ void RISCVISAInfo::updateCombination() {
} while (MadeChange);
}
-void RISCVISAInfo::updateFLen() {
- FLen = 0;
+void RISCVISAInfo::updateImpliedLengths() {
+ assert(FLen == 0 && MaxELenFp == 0 && MaxELen == 0 && MinVLen == 0 &&
+ "Expected lengths to be initialied to zero");
+
// TODO: Handle q extension.
if (Exts.count("d"))
FLen = 64;
else if (Exts.count("f"))
FLen = 32;
-}
-void RISCVISAInfo::updateMinVLen() {
- for (auto const &Ext : Exts) {
- StringRef ExtName = Ext.first;
- bool IsZvlExt = ExtName.consume_front("zvl") && ExtName.consume_back("b");
- if (IsZvlExt) {
- unsigned ZvlLen;
- if (!ExtName.getAsInteger(10, ZvlLen))
- MinVLen = std::max(MinVLen, ZvlLen);
- }
- }
-}
-
-void RISCVISAInfo::updateMaxELen() {
- assert(MaxELenFp == 0 && MaxELen == 0);
if (Exts.count("v")) {
MaxELenFp = std::max(MaxELenFp, 64u);
MaxELen = std::max(MaxELen, 64u);
}
- // handles EEW restriction by sub-extension zve
for (auto const &Ext : Exts) {
StringRef ExtName = Ext.first;
- bool IsZveExt = ExtName.consume_front("zve");
- if (IsZveExt) {
- if (ExtName.back() == 'f')
+ // Infer MaxELen and MaxELenFp from Zve(32/64)(x/f/d)
+ if (ExtName.consume_front("zve")) {
+ unsigned ZveELen;
+ if (ExtName.consumeInteger(10, ZveELen))
+ continue;
+
+ if (ExtName == "f")
MaxELenFp = std::max(MaxELenFp, 32u);
- else if (ExtName.back() == 'd')
+ else if (ExtName == "d")
MaxELenFp = std::max(MaxELenFp, 64u);
- else if (ExtName.back() != 'x')
+ else if (ExtName != "x")
continue;
- ExtName = ExtName.drop_back();
- unsigned ZveELen;
- if (!ExtName.getAsInteger(10, ZveELen))
- MaxELen = std::max(MaxELen, ZveELen);
+ MaxELen = std::max(MaxELen, ZveELen);
+ continue;
+ }
+
+ // Infer MinVLen from zvl*b.
+ if (ExtName.consume_front("zvl")) {
+ unsigned ZvlLen;
+ if (ExtName.consumeInteger(10, ZvlLen))
+ continue;
+
+ if (ExtName != "b")
+ continue;
+
+ MinVLen = std::max(MinVLen, ZvlLen);
+ continue;
}
}
}
@@ -975,9 +974,7 @@ llvm::Expected<std::unique_ptr<RISCVISAInfo>>
RISCVISAInfo::postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo) {
ISAInfo->updateImplication();
ISAInfo->updateCombination();
- ISAInfo->updateFLen();
- ISAInfo->updateMinVLen();
- ISAInfo->updateMaxELen();
+ ISAInfo->updateImpliedLengths();
if (Error Result = ISAInfo->checkDependency())
return std::move(Result);