Skip to content

Commit 7944c7c

Browse files
committed
Use MapVector instead of SmallVector
1 parent b995086 commit 7944c7c

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/Support/RISCVISAInfo.h"
10+
#include "llvm/ADT/MapVector.h"
1011
#include "llvm/ADT/STLExtras.h"
1112
#include "llvm/ADT/SetVector.h"
1213
#include "llvm/ADT/StringExtras.h"
@@ -726,8 +727,9 @@ static Error splitExtsByUnderscore(StringRef Exts,
726727
}
727728

728729
static Error processMultiLetterExtension(
729-
StringRef RawExt, SmallVector<std::string, 8> &SeenExts,
730-
SmallVector<RISCVISAInfo::ExtensionVersion, 8> &ExtsVersion,
730+
StringRef RawExt,
731+
MapVector<std::string, RISCVISAInfo::ExtensionVersion,
732+
std::map<std::string, unsigned>> &SeenExtMap,
731733
bool IgnoreUnknown, bool EnableExperimentalExtension,
732734
bool ExperimentalExtensionVersionCheck) {
733735
StringRef Type = getExtensionType(RawExt);
@@ -760,21 +762,21 @@ static Error processMultiLetterExtension(
760762
}
761763

762764
// Check if duplicated extension.
763-
if (!IgnoreUnknown && llvm::is_contained(SeenExts, Name))
765+
if (!IgnoreUnknown && (SeenExtMap.find(Name.str()) != SeenExtMap.end()))
764766
return createStringError(errc::invalid_argument, "duplicated %s '%s'",
765767
Desc.str().c_str(), Name.str().c_str());
766768

767769
if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension(Name))
768770
return Error::success();
769771

770-
SeenExts.push_back(Name.str());
771-
ExtsVersion.push_back({Major, Minor});
772+
SeenExtMap[Name.str()] = {Major, Minor};
772773
return Error::success();
773774
}
774775

775776
static Error processSingleLetterExtension(
776-
StringRef &RawExt, SmallVector<std::string, 8> &SeenExts,
777-
SmallVector<RISCVISAInfo::ExtensionVersion, 8> &ExtsVersion,
777+
StringRef &RawExt,
778+
MapVector<std::string, RISCVISAInfo::ExtensionVersion,
779+
std::map<std::string, unsigned>> &SeenExtMap,
778780
bool IgnoreUnknown, bool EnableExperimentalExtension,
779781
bool ExperimentalExtensionVersionCheck) {
780782
unsigned Major, Minor, ConsumeLength;
@@ -794,16 +796,15 @@ static Error processSingleLetterExtension(
794796
RawExt = RawExt.substr(ConsumeLength);
795797

796798
// Check if duplicated extension.
797-
if (!IgnoreUnknown && llvm::is_contained(SeenExts, Name))
799+
if (!IgnoreUnknown && (SeenExtMap.find(Name.str()) != SeenExtMap.end()))
798800
return createStringError(errc::invalid_argument,
799801
"duplicated standard user-level extension '%s'",
800802
Name.str().c_str());
801803

802804
if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension(Name))
803805
return Error::success();
804806

805-
SeenExts.push_back(Name.str());
806-
ExtsVersion.push_back({Major, Minor});
807+
SeenExtMap[Name.str()] = {Major, Minor};
807808
return Error::success();
808809
}
809810

@@ -827,8 +828,9 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
827828

828829
unsigned XLen = HasRV64 ? 64 : 32;
829830
std::unique_ptr<RISCVISAInfo> ISAInfo(new RISCVISAInfo(XLen));
830-
SmallVector<std::string, 8> SeenExts;
831-
SmallVector<RISCVISAInfo::ExtensionVersion, 8> ExtsVersion;
831+
MapVector<std::string, RISCVISAInfo::ExtensionVersion,
832+
std::map<std::string, unsigned>>
833+
SeenExtMap;
832834

833835
// The canonical order specified in ISA manual.
834836
// Ref: Table 22.1 in RISC-V User-Level ISA V2.2
@@ -870,8 +872,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
870872
for (const auto *Ext : RISCVGImplications) {
871873
if (auto Version = findDefaultVersion(Ext)) {
872874
// Postpone AddExtension until end of this function
873-
SeenExts.push_back(Ext);
874-
ExtsVersion.push_back({Version->Major, Version->Minor});
875+
SeenExtMap[Ext] = {Version->Major, Version->Minor};
875876
} else
876877
llvm_unreachable("Default extension version not found?");
877878
}
@@ -891,8 +892,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
891892
}
892893

893894
// Postpone AddExtension until end of this function
894-
SeenExts.push_back(StringRef(&Baseline, 1).str());
895-
ExtsVersion.push_back({Major, Minor});
895+
SeenExtMap[StringRef(&Baseline, 1).str()] = {Major, Minor};
896896
}
897897

898898
// Consume the base ISA version number and any '_' between rvxxx and the
@@ -909,8 +909,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
909909
while (!CurrExt.empty()) {
910910
if (AllStdExts.contains(CurrExt.front())) {
911911
if (auto E = processSingleLetterExtension(
912-
CurrExt, SeenExts, ExtsVersion, IgnoreUnknown,
913-
EnableExperimentalExtension, ExperimentalExtensionVersionCheck))
912+
CurrExt, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension,
913+
ExperimentalExtensionVersionCheck))
914914
return E;
915915
} else if (CurrExt.front() == 'z' || CurrExt.front() == 's' ||
916916
CurrExt.front() == 'x') {
@@ -923,8 +923,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
923923
// version number (major, minor) and are separated by a single
924924
// underscore '_'. We do not enforce a canonical order for them.
925925
if (auto E = processMultiLetterExtension(
926-
CurrExt, SeenExts, ExtsVersion, IgnoreUnknown,
927-
EnableExperimentalExtension, ExperimentalExtensionVersionCheck))
926+
CurrExt, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension,
927+
ExperimentalExtensionVersionCheck))
928928
return E;
929929
// Multi-letter extension must be seperate following extension with
930930
// underscore
@@ -939,20 +939,21 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
939939
}
940940

941941
// Check all Extensions are supported.
942-
for (size_t Idx = 0; Idx < SeenExts.size(); Idx++) {
943-
if (!RISCVISAInfo::isSupportedExtension(SeenExts[Idx])) {
944-
if (SeenExts[Idx].size() == 1) {
942+
for (auto SeenExtAndVers : SeenExtMap) {
943+
std::string ExtName = SeenExtAndVers.first;
944+
RISCVISAInfo::ExtensionVersion ExtVers = SeenExtAndVers.second;
945+
946+
if (!RISCVISAInfo::isSupportedExtension(ExtName)) {
947+
if (ExtName.size() == 1) {
945948
return createStringError(
946949
errc::invalid_argument,
947-
"unsupported standard user-level extension '%s'",
948-
SeenExts[Idx].c_str());
950+
"unsupported standard user-level extension '%s'", ExtName.c_str());
949951
}
950-
return createStringError(
951-
errc::invalid_argument, "unsupported %s '%s'",
952-
getExtensionTypeDesc(SeenExts[Idx]).str().c_str(),
953-
SeenExts[Idx].c_str());
952+
return createStringError(errc::invalid_argument, "unsupported %s '%s'",
953+
getExtensionTypeDesc(ExtName).str().c_str(),
954+
ExtName.c_str());
954955
}
955-
ISAInfo->addExtension(SeenExts[Idx], ExtsVersion[Idx]);
956+
ISAInfo->addExtension(ExtName, ExtVers);
956957
}
957958

958959
return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo));

0 commit comments

Comments
 (0)