[llvm] 299d3dd - [RISCV] Simplify some control flow in RISCVISAInfo::parseArchString. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 1 18:23:06 PDT 2024
Author: Craig Topper
Date: 2024-07-01T18:22:33-07:00
New Revision: 299d3ddc618e9a95aa1050e4c1a7dfddbcd94395
URL: https://github.com/llvm/llvm-project/commit/299d3ddc618e9a95aa1050e4c1a7dfddbcd94395
DIFF: https://github.com/llvm/llvm-project/commit/299d3ddc618e9a95aa1050e4c1a7dfddbcd94395.diff
LOG: [RISCV] Simplify some control flow in RISCVISAInfo::parseArchString. NFC
Merge handling of the baseline ISA into the switch that checks if
the baseline is valid.
Invert a condition to allow a better early out to reduce curly braces.
Added:
Modified:
llvm/lib/TargetParser/RISCVISAInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index 91ade25584894..869be57928890 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -585,6 +585,10 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
// The canonical order specified in ISA manual.
// Ref: Table 22.1 in RISC-V User-Level ISA V2.2
char Baseline = Arch.front();
+ // Skip the baseline.
+ StringRef Exts = Arch.drop_front();
+
+ unsigned Major, Minor, ConsumeLength;
// First letter should be 'e', 'i' or 'g'.
switch (Baseline) {
@@ -594,20 +598,29 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
"\' should be 'e', 'i' or 'g'");
case 'e':
case 'i':
+ // Baseline is `i` or `e`
+ if (auto E = getExtensionVersion(
+ StringRef(&Baseline, 1), Exts, Major, Minor, ConsumeLength,
+ EnableExperimentalExtension, ExperimentalExtensionVersionCheck)) {
+ if (!IgnoreUnknown)
+ return std::move(E);
+ // If IgnoreUnknown, then ignore an unrecognised version of the baseline
+ // ISA and just use the default supported version.
+ consumeError(std::move(E));
+ auto Version = findDefaultVersion(StringRef(&Baseline, 1));
+ Major = Version->Major;
+ Minor = Version->Minor;
+ }
+
+ // Postpone AddExtension until end of this function
+ SeenExtMap[StringRef(&Baseline, 1).str()] = {Major, Minor};
break;
case 'g':
// g expands to extensions in RISCVGImplications.
if (Arch.size() > 1 && isDigit(Arch[1]))
return createStringError(errc::invalid_argument,
"version not supported for 'g'");
- break;
- }
-
- // Skip baseline.
- StringRef Exts = Arch.drop_front(1);
- unsigned Major, Minor, ConsumeLength;
- if (Baseline == 'g') {
// Versions for g are disallowed, and this was checked for previously.
ConsumeLength = 0;
@@ -620,23 +633,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
// Postpone AddExtension until end of this function
SeenExtMap[Ext] = {Version->Major, Version->Minor};
}
- } else {
- // Baseline is `i` or `e`
- if (auto E = getExtensionVersion(
- StringRef(&Baseline, 1), Exts, Major, Minor, ConsumeLength,
- EnableExperimentalExtension, ExperimentalExtensionVersionCheck)) {
- if (!IgnoreUnknown)
- return std::move(E);
- // If IgnoreUnknown, then ignore an unrecognised version of the baseline
- // ISA and just use the default supported version.
- consumeError(std::move(E));
- auto Version = findDefaultVersion(StringRef(&Baseline, 1));
- Major = Version->Major;
- Minor = Version->Minor;
- }
-
- // Postpone AddExtension until end of this function
- SeenExtMap[StringRef(&Baseline, 1).str()] = {Major, Minor};
+ break;
}
// Consume the base ISA version number and any '_' between rvxxx and the
@@ -694,13 +691,13 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
EnableExperimentalExtension,
ExperimentalExtensionVersionCheck)) {
- if (IgnoreUnknown) {
- consumeError(std::move(E));
- if (Name.size() == 1)
- Ext = Ext.substr(ConsumeLength);
- continue;
- }
- return E;
+ if (!IgnoreUnknown)
+ return E;
+
+ consumeError(std::move(E));
+ if (Name.size() == 1)
+ Ext = Ext.substr(ConsumeLength);
+ continue;
}
if (Name.size() == 1)
More information about the llvm-commits
mailing list