Skip to content

Commit 880bc58

Browse files
committed
Use MapVector instead of SmallVector
1 parent 77ce1e4 commit 880bc58

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

725726
static Error processMultiLetterExtension(
726-
StringRef RawExt, SmallVector<std::string, 8> &SeenExts,
727-
SmallVector<RISCVISAInfo::ExtensionVersion, 8> &ExtsVersion,
727+
StringRef RawExt,
728+
MapVector<std::string, RISCVISAInfo::ExtensionVersion,
729+
std::map<std::string, unsigned>> &SeenExtMap,
728730
bool IgnoreUnknown, bool EnableExperimentalExtension,
729731
bool ExperimentalExtensionVersionCheck) {
730732
StringRef Type = getExtensionType(RawExt);
@@ -757,21 +759,21 @@ static Error processMultiLetterExtension(
757759
}
758760

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

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

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

772773
static Error processSingleLetterExtension(
773-
StringRef &RawExt, SmallVector<std::string, 8> &SeenExts,
774-
SmallVector<RISCVISAInfo::ExtensionVersion, 8> &ExtsVersion,
774+
StringRef &RawExt,
775+
MapVector<std::string, RISCVISAInfo::ExtensionVersion,
776+
std::map<std::string, unsigned>> &SeenExtMap,
775777
bool IgnoreUnknown, bool EnableExperimentalExtension,
776778
bool ExperimentalExtensionVersionCheck) {
777779
unsigned Major, Minor, ConsumeLength;
@@ -791,16 +793,15 @@ static Error processSingleLetterExtension(
791793
RawExt = RawExt.substr(ConsumeLength);
792794

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

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

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

@@ -824,8 +825,9 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
824825

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

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

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

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

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

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

0 commit comments

Comments
 (0)