aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2024-06-27 14:05:59 -0700
committerCraig Topper <craig.topper@sifive.com>2024-06-27 15:04:17 -0700
commitf906e3dd62b979814658e8610388117dd7db7bbf (patch)
treedc70937da2327fef87d8e434fa19e571f3c311fa
parente55aa027f813679ca63c9b803690ce792a3d7b28 (diff)
downloadllvm-f906e3dd62b979814658e8610388117dd7db7bbf.zip
llvm-f906e3dd62b979814658e8610388117dd7db7bbf.tar.gz
llvm-f906e3dd62b979814658e8610388117dd7db7bbf.tar.bz2
[RISCV] Fold processSingleLetterExtension/processMultiLetterExtension into RISCVISAInfo::parseArchString.
The end of both functions was very similar. Merging reduces the duplication. I'm planning to make additional changes to this code soon.
-rw-r--r--llvm/lib/TargetParser/RISCVISAInfo.cpp134
1 files changed, 42 insertions, 92 deletions
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index 739a364..8b3fba1 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -521,87 +521,6 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
return std::move(ISAInfo);
}
-static Error processMultiLetterExtension(
- StringRef RawExt,
- MapVector<std::string, RISCVISAUtils::ExtensionVersion,
- std::map<std::string, unsigned>> &SeenExtMap,
- bool IgnoreUnknown, bool EnableExperimentalExtension,
- bool ExperimentalExtensionVersionCheck) {
- StringRef Type = getExtensionType(RawExt);
- StringRef Desc = getExtensionTypeDesc(RawExt);
- auto Pos = findLastNonVersionCharacter(RawExt) + 1;
- StringRef Name(RawExt.substr(0, Pos));
- StringRef Vers(RawExt.substr(Pos));
-
- if (Type.empty()) {
- if (IgnoreUnknown)
- return Error::success();
- return createStringError(errc::invalid_argument,
- "invalid extension prefix '" + RawExt + "'");
- }
-
- if (!IgnoreUnknown && Name.size() == Type.size())
- return createStringError(errc::invalid_argument,
- Desc + " name missing after '" + Type + "'");
-
- unsigned Major, Minor, ConsumeLength;
- if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
- EnableExperimentalExtension,
- ExperimentalExtensionVersionCheck)) {
- if (IgnoreUnknown) {
- consumeError(std::move(E));
- return Error::success();
- }
- return E;
- }
-
- // Check if duplicated extension.
- if (!IgnoreUnknown && SeenExtMap.contains(Name.str()))
- return createStringError(errc::invalid_argument,
- "duplicated " + Desc + " '" + Name + "'");
-
- if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension(Name))
- return Error::success();
-
- SeenExtMap[Name.str()] = {Major, Minor};
- return Error::success();
-}
-
-static Error processSingleLetterExtension(
- StringRef &RawExt,
- MapVector<std::string, RISCVISAUtils::ExtensionVersion,
- std::map<std::string, unsigned>> &SeenExtMap,
- bool IgnoreUnknown, bool EnableExperimentalExtension,
- bool ExperimentalExtensionVersionCheck) {
- unsigned Major, Minor, ConsumeLength;
- StringRef Name = RawExt.take_front(1);
- RawExt.consume_front(Name);
- if (auto E = getExtensionVersion(Name, RawExt, Major, Minor, ConsumeLength,
- EnableExperimentalExtension,
- ExperimentalExtensionVersionCheck)) {
- if (IgnoreUnknown) {
- consumeError(std::move(E));
- RawExt = RawExt.substr(ConsumeLength);
- return Error::success();
- }
- return E;
- }
-
- RawExt = RawExt.substr(ConsumeLength);
-
- // Check if duplicated extension.
- if (!IgnoreUnknown && SeenExtMap.contains(Name.str()))
- return createStringError(errc::invalid_argument,
- "duplicated standard user-level extension '" +
- Name + "'");
-
- if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension(Name))
- return Error::success();
-
- SeenExtMap[Name.str()] = {Major, Minor};
- return Error::success();
-}
-
llvm::Expected<std::unique_ptr<RISCVISAInfo>>
RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
bool ExperimentalExtensionVersionCheck,
@@ -738,11 +657,12 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
Exts = Exts.slice(Idx, StringRef::npos);
do {
+ StringRef Name, Vers, Desc;
if (RISCVISAUtils::AllStdExts.contains(Ext.front())) {
- if (auto E = processSingleLetterExtension(
- Ext, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension,
- ExperimentalExtensionVersionCheck))
- return std::move(E);
+ Name = Ext.take_front(1);
+ Ext = Ext.drop_front();
+ Vers = Ext;
+ Desc = "standard user-level extension";
} else if (Ext.front() == 'z' || Ext.front() == 's' ||
Ext.front() == 'x') {
// Handle other types of extensions other than the standard
@@ -753,19 +673,49 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
// These extensions start with 'z', 's', 'x' prefixes, might have a
// version number (major, minor) and are separated by a single
// underscore '_'. We do not enforce a canonical order for them.
- if (auto E = processMultiLetterExtension(
- Ext, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension,
- ExperimentalExtensionVersionCheck))
- return std::move(E);
- // Multi-letter extension must be separate following extension with
- // underscore
- break;
+ StringRef Type = getExtensionType(Ext);
+ Desc = getExtensionTypeDesc(Ext);
+ auto Pos = findLastNonVersionCharacter(Ext) + 1;
+ Name = Ext.substr(0, Pos);
+ Vers = Ext.substr(Pos);
+ Ext = StringRef();
+
+ assert(!Type.empty() && "Empty type?");
+ if (!IgnoreUnknown && Name.size() == Type.size())
+ return createStringError(errc::invalid_argument,
+ Desc + " name missing after '" + Type + "'");
} else {
// FIXME: Could it be ignored by IgnoreUnknown?
return createStringError(errc::invalid_argument,
"invalid standard user-level extension '" +
Twine(Ext.front()) + "'");
}
+
+ unsigned Major, Minor, ConsumeLength;
+ 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 (Name.size() == 1)
+ Ext = Ext.substr(ConsumeLength);
+
+ // Check if duplicated extension.
+ if (!IgnoreUnknown && SeenExtMap.contains(Name.str()))
+ return createStringError(errc::invalid_argument,
+ "duplicated " + Desc + " '" + Name + "'");
+
+ if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension(Name))
+ continue;
+
+ SeenExtMap[Name.str()] = {Major, Minor};
} while (!Ext.empty());
}