Skip to content

Commit cf3c714

Browse files
authored
[RISCV] Merge RISCVISAInfo::updateFLen/MinVLen/MaxELen into a single function. (#90665)
This simplifies the callers.
1 parent 09f4b06 commit cf3c714

File tree

2 files changed

+37
-41
lines changed

2 files changed

+37
-41
lines changed

llvm/include/llvm/TargetParser/RISCVISAInfo.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,12 @@ class RISCVISAInfo {
7878
static std::string getTargetFeatureForExtension(StringRef Ext);
7979

8080
private:
81-
RISCVISAInfo(unsigned XLen)
82-
: XLen(XLen), FLen(0), MinVLen(0), MaxELen(0), MaxELenFp(0) {}
81+
RISCVISAInfo(unsigned XLen) : XLen(XLen) {}
8382

8483
unsigned XLen;
85-
unsigned FLen;
86-
unsigned MinVLen;
87-
unsigned MaxELen, MaxELenFp;
84+
unsigned FLen = 0;
85+
unsigned MinVLen = 0;
86+
unsigned MaxELen = 0, MaxELenFp = 0;
8887

8988
RISCVISAUtils::OrderedExtensionMap Exts;
9089

@@ -94,9 +93,9 @@ class RISCVISAInfo {
9493

9594
void updateImplication();
9695
void updateCombination();
97-
void updateFLen();
98-
void updateMinVLen();
99-
void updateMaxELen();
96+
97+
/// Update FLen, MinVLen, MaxELen, and MaxELenFp.
98+
void updateImpliedLengths();
10099
};
101100

102101
} // namespace llvm

llvm/lib/TargetParser/RISCVISAInfo.cpp

+30-33
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,7 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
478478
"failed to parse major version number");
479479
ISAInfo->addExtension(ExtName, {MajorVersion, MinorVersion});
480480
}
481-
ISAInfo->updateFLen();
482-
ISAInfo->updateMinVLen();
483-
ISAInfo->updateMaxELen();
481+
ISAInfo->updateImpliedLengths();
484482
return std::move(ISAInfo);
485483
}
486484

@@ -906,50 +904,51 @@ void RISCVISAInfo::updateCombination() {
906904
} while (MadeChange);
907905
}
908906

909-
void RISCVISAInfo::updateFLen() {
910-
FLen = 0;
907+
void RISCVISAInfo::updateImpliedLengths() {
908+
assert(FLen == 0 && MaxELenFp == 0 && MaxELen == 0 && MinVLen == 0 &&
909+
"Expected lengths to be initialied to zero");
910+
911911
// TODO: Handle q extension.
912912
if (Exts.count("d"))
913913
FLen = 64;
914914
else if (Exts.count("f"))
915915
FLen = 32;
916-
}
917916

918-
void RISCVISAInfo::updateMinVLen() {
919-
for (auto const &Ext : Exts) {
920-
StringRef ExtName = Ext.first;
921-
bool IsZvlExt = ExtName.consume_front("zvl") && ExtName.consume_back("b");
922-
if (IsZvlExt) {
923-
unsigned ZvlLen;
924-
if (!ExtName.getAsInteger(10, ZvlLen))
925-
MinVLen = std::max(MinVLen, ZvlLen);
926-
}
927-
}
928-
}
929-
930-
void RISCVISAInfo::updateMaxELen() {
931-
assert(MaxELenFp == 0 && MaxELen == 0);
932917
if (Exts.count("v")) {
933918
MaxELenFp = std::max(MaxELenFp, 64u);
934919
MaxELen = std::max(MaxELen, 64u);
935920
}
936921

937-
// handles EEW restriction by sub-extension zve
938922
for (auto const &Ext : Exts) {
939923
StringRef ExtName = Ext.first;
940-
bool IsZveExt = ExtName.consume_front("zve");
941-
if (IsZveExt) {
942-
if (ExtName.back() == 'f')
924+
// Infer MaxELen and MaxELenFp from Zve(32/64)(x/f/d)
925+
if (ExtName.consume_front("zve")) {
926+
unsigned ZveELen;
927+
if (ExtName.consumeInteger(10, ZveELen))
928+
continue;
929+
930+
if (ExtName == "f")
943931
MaxELenFp = std::max(MaxELenFp, 32u);
944-
else if (ExtName.back() == 'd')
932+
else if (ExtName == "d")
945933
MaxELenFp = std::max(MaxELenFp, 64u);
946-
else if (ExtName.back() != 'x')
934+
else if (ExtName != "x")
947935
continue;
948936

949-
ExtName = ExtName.drop_back();
950-
unsigned ZveELen;
951-
if (!ExtName.getAsInteger(10, ZveELen))
952-
MaxELen = std::max(MaxELen, ZveELen);
937+
MaxELen = std::max(MaxELen, ZveELen);
938+
continue;
939+
}
940+
941+
// Infer MinVLen from zvl*b.
942+
if (ExtName.consume_front("zvl")) {
943+
unsigned ZvlLen;
944+
if (ExtName.consumeInteger(10, ZvlLen))
945+
continue;
946+
947+
if (ExtName != "b")
948+
continue;
949+
950+
MinVLen = std::max(MinVLen, ZvlLen);
951+
continue;
953952
}
954953
}
955954
}
@@ -975,9 +974,7 @@ llvm::Expected<std::unique_ptr<RISCVISAInfo>>
975974
RISCVISAInfo::postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo) {
976975
ISAInfo->updateImplication();
977976
ISAInfo->updateCombination();
978-
ISAInfo->updateFLen();
979-
ISAInfo->updateMinVLen();
980-
ISAInfo->updateMaxELen();
977+
ISAInfo->updateImpliedLengths();
981978

982979
if (Error Result = ISAInfo->checkDependency())
983980
return std::move(Result);

0 commit comments

Comments
 (0)