Skip to content

Commit 357a77d

Browse files
committed
Use MapVector instead of SmallVector
1 parent bd22631 commit 357a77d

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"
@@ -722,8 +723,9 @@ static Error splitExtsByUnderscore(StringRef Exts,
722723
}
723724

724725
static Error processMultiLetterExtension(
725-
StringRef RawExt, SmallVector<std::string, 8> &SeenExts,
726-
SmallVector<RISCVISAInfo::ExtensionVersion, 8> &ExtsVersion,
726+
StringRef RawExt,
727+
MapVector<std::string, RISCVISAInfo::ExtensionVersion,
728+
std::map<std::string, unsigned>> &SeenExtMap,
727729
bool IgnoreUnknown, bool EnableExperimentalExtension,
728730
bool ExperimentalExtensionVersionCheck) {
729731
StringRef Type = getExtensionType(RawExt);
@@ -756,21 +758,21 @@ static Error processMultiLetterExtension(
756758
}
757759

758760
// Check if duplicated extension.
759-
if (!IgnoreUnknown && llvm::is_contained(SeenExts, Name))
761+
if (!IgnoreUnknown && (SeenExtMap.find(Name.str()) != SeenExtMap.end()))
760762
return createStringError(errc::invalid_argument, "duplicated %s '%s'",
761763
Desc.str().c_str(), Name.str().c_str());
762764

763765
if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension(Name))
764766
return Error::success();
765767

766-
SeenExts.push_back(Name.str());
767-
ExtsVersion.push_back({Major, Minor});
768+
SeenExtMap[Name.str()] = {Major, Minor};
768769
return Error::success();
769770
}
770771

771772
static Error processSingleLetterExtension(
772-
StringRef &RawExt, SmallVector<std::string, 8> &SeenExts,
773-
SmallVector<RISCVISAInfo::ExtensionVersion, 8> &ExtsVersion,
773+
StringRef &RawExt,
774+
MapVector<std::string, RISCVISAInfo::ExtensionVersion,
775+
std::map<std::string, unsigned>> &SeenExtMap,
774776
bool IgnoreUnknown, bool EnableExperimentalExtension,
775777
bool ExperimentalExtensionVersionCheck) {
776778
unsigned Major, Minor, ConsumeLength;
@@ -790,16 +792,15 @@ static Error processSingleLetterExtension(
790792
RawExt = RawExt.substr(ConsumeLength);
791793

792794
// Check if duplicated extension.
793-
if (!IgnoreUnknown && llvm::is_contained(SeenExts, Name))
795+
if (!IgnoreUnknown && (SeenExtMap.find(Name.str()) != SeenExtMap.end()))
794796
return createStringError(errc::invalid_argument,
795797
"duplicated standard user-level extension '%s'",
796798
Name.str().c_str());
797799

798800
if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension(Name))
799801
return Error::success();
800802

801-
SeenExts.push_back(Name.str());
802-
ExtsVersion.push_back({Major, Minor});
803+
SeenExtMap[Name.str()] = {Major, Minor};
803804
return Error::success();
804805
}
805806

@@ -823,8 +824,9 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
823824

824825
unsigned XLen = HasRV64 ? 64 : 32;
825826
std::unique_ptr<RISCVISAInfo> ISAInfo(new RISCVISAInfo(XLen));
826-
SmallVector<std::string, 8> SeenExts;
827-
SmallVector<RISCVISAInfo::ExtensionVersion, 8> ExtsVersion;
827+
MapVector<std::string, RISCVISAInfo::ExtensionVersion,
828+
std::map<std::string, unsigned>>
829+
SeenExtMap;
828830

829831
// The canonical order specified in ISA manual.
830832
// Ref: Table 22.1 in RISC-V User-Level ISA V2.2
@@ -866,8 +868,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
866868
for (const auto *Ext : RISCVGImplications) {
867869
if (auto Version = findDefaultVersion(Ext)) {
868870
// Postpone AddExtension until end of this function
869-
SeenExts.push_back(Ext);
870-
ExtsVersion.push_back({Version->Major, Version->Minor});
871+
SeenExtMap[Ext] = {Version->Major, Version->Minor};
871872
} else
872873
llvm_unreachable("Default extension version not found?");
873874
}
@@ -887,8 +888,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
887888
}
888889

889890
// Postpone AddExtension until end of this function
890-
SeenExts.push_back(StringRef(&Baseline, 1).str());
891-
ExtsVersion.push_back({Major, Minor});
891+
SeenExtMap[StringRef(&Baseline, 1).str()] = {Major, Minor};
892892
}
893893

894894
// Consume the base ISA version number and any '_' between rvxxx and the
@@ -905,8 +905,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
905905
while (!CurrExt.empty()) {
906906
if (AllStdExts.contains(CurrExt.front())) {
907907
if (auto E = processSingleLetterExtension(
908-
CurrExt, SeenExts, ExtsVersion, IgnoreUnknown,
909-
EnableExperimentalExtension, ExperimentalExtensionVersionCheck))
908+
CurrExt, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension,
909+
ExperimentalExtensionVersionCheck))
910910
return E;
911911
} else if (CurrExt.front() == 'z' || CurrExt.front() == 's' ||
912912
CurrExt.front() == 'x') {
@@ -919,8 +919,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
919919
// version number (major, minor) and are separated by a single
920920
// underscore '_'. We do not enforce a canonical order for them.
921921
if (auto E = processMultiLetterExtension(
922-
CurrExt, SeenExts, ExtsVersion, IgnoreUnknown,
923-
EnableExperimentalExtension, ExperimentalExtensionVersionCheck))
922+
CurrExt, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension,
923+
ExperimentalExtensionVersionCheck))
924924
return E;
925925
// Multi-letter extension must be seperate following extension with
926926
// underscore
@@ -935,20 +935,21 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
935935
}
936936

937937
// Check all Extensions are supported.
938-
for (size_t Idx = 0; Idx < SeenExts.size(); Idx++) {
939-
if (!RISCVISAInfo::isSupportedExtension(SeenExts[Idx])) {
940-
if (SeenExts[Idx].size() == 1) {
938+
for (auto SeenExtAndVers : SeenExtMap) {
939+
std::string ExtName = SeenExtAndVers.first;
940+
RISCVISAInfo::ExtensionVersion ExtVers = SeenExtAndVers.second;
941+
942+
if (!RISCVISAInfo::isSupportedExtension(ExtName)) {
943+
if (ExtName.size() == 1) {
941944
return createStringError(
942945
errc::invalid_argument,
943-
"unsupported standard user-level extension '%s'",
944-
SeenExts[Idx].c_str());
946+
"unsupported standard user-level extension '%s'", ExtName.c_str());
945947
}
946-
return createStringError(
947-
errc::invalid_argument, "unsupported %s '%s'",
948-
getExtensionTypeDesc(SeenExts[Idx]).str().c_str(),
949-
SeenExts[Idx].c_str());
948+
return createStringError(errc::invalid_argument, "unsupported %s '%s'",
949+
getExtensionTypeDesc(ExtName).str().c_str(),
950+
ExtName.c_str());
950951
}
951-
ISAInfo->addExtension(SeenExts[Idx], ExtsVersion[Idx]);
952+
ISAInfo->addExtension(ExtName, ExtVers);
952953
}
953954

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

0 commit comments

Comments
 (0)