7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " llvm/Support/RISCVISAInfo.h"
10
+ #include " llvm/ADT/MapVector.h"
10
11
#include " llvm/ADT/STLExtras.h"
11
12
#include " llvm/ADT/SetVector.h"
12
13
#include " llvm/ADT/StringExtras.h"
@@ -726,8 +727,9 @@ static Error splitExtsByUnderscore(StringRef Exts,
726
727
}
727
728
728
729
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,
731
733
bool IgnoreUnknown, bool EnableExperimentalExtension,
732
734
bool ExperimentalExtensionVersionCheck) {
733
735
StringRef Type = getExtensionType (RawExt);
@@ -760,21 +762,21 @@ static Error processMultiLetterExtension(
760
762
}
761
763
762
764
// Check if duplicated extension.
763
- if (!IgnoreUnknown && llvm::is_contained (SeenExts, Name))
765
+ if (!IgnoreUnknown && (SeenExtMap. find ( Name. str ()) != SeenExtMap. end () ))
764
766
return createStringError (errc::invalid_argument, " duplicated %s '%s'" ,
765
767
Desc.str ().c_str (), Name.str ().c_str ());
766
768
767
769
if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension (Name))
768
770
return Error::success ();
769
771
770
- SeenExts.push_back (Name.str ());
771
- ExtsVersion.push_back ({Major, Minor});
772
+ SeenExtMap[Name.str ()] = {Major, Minor};
772
773
return Error::success ();
773
774
}
774
775
775
776
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,
778
780
bool IgnoreUnknown, bool EnableExperimentalExtension,
779
781
bool ExperimentalExtensionVersionCheck) {
780
782
unsigned Major, Minor, ConsumeLength;
@@ -794,16 +796,15 @@ static Error processSingleLetterExtension(
794
796
RawExt = RawExt.substr (ConsumeLength);
795
797
796
798
// Check if duplicated extension.
797
- if (!IgnoreUnknown && llvm::is_contained (SeenExts, Name))
799
+ if (!IgnoreUnknown && (SeenExtMap. find ( Name. str ()) != SeenExtMap. end () ))
798
800
return createStringError (errc::invalid_argument,
799
801
" duplicated standard user-level extension '%s'" ,
800
802
Name.str ().c_str ());
801
803
802
804
if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension (Name))
803
805
return Error::success ();
804
806
805
- SeenExts.push_back (Name.str ());
806
- ExtsVersion.push_back ({Major, Minor});
807
+ SeenExtMap[Name.str ()] = {Major, Minor};
807
808
return Error::success ();
808
809
}
809
810
@@ -827,8 +828,9 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
827
828
828
829
unsigned XLen = HasRV64 ? 64 : 32 ;
829
830
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;
832
834
833
835
// The canonical order specified in ISA manual.
834
836
// Ref: Table 22.1 in RISC-V User-Level ISA V2.2
@@ -870,8 +872,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
870
872
for (const auto *Ext : RISCVGImplications) {
871
873
if (auto Version = findDefaultVersion (Ext)) {
872
874
// 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 };
875
876
} else
876
877
llvm_unreachable (" Default extension version not found?" );
877
878
}
@@ -891,8 +892,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
891
892
}
892
893
893
894
// 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};
896
896
}
897
897
898
898
// Consume the base ISA version number and any '_' between rvxxx and the
@@ -909,8 +909,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
909
909
while (!CurrExt.empty ()) {
910
910
if (AllStdExts.contains (CurrExt.front ())) {
911
911
if (auto E = processSingleLetterExtension (
912
- CurrExt, SeenExts, ExtsVersion, IgnoreUnknown ,
913
- EnableExperimentalExtension, ExperimentalExtensionVersionCheck))
912
+ CurrExt, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension ,
913
+ ExperimentalExtensionVersionCheck))
914
914
return E;
915
915
} else if (CurrExt.front () == ' z' || CurrExt.front () == ' s' ||
916
916
CurrExt.front () == ' x' ) {
@@ -923,8 +923,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
923
923
// version number (major, minor) and are separated by a single
924
924
// underscore '_'. We do not enforce a canonical order for them.
925
925
if (auto E = processMultiLetterExtension (
926
- CurrExt, SeenExts, ExtsVersion, IgnoreUnknown ,
927
- EnableExperimentalExtension, ExperimentalExtensionVersionCheck))
926
+ CurrExt, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension ,
927
+ ExperimentalExtensionVersionCheck))
928
928
return E;
929
929
// Multi-letter extension must be seperate following extension with
930
930
// underscore
@@ -939,20 +939,21 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
939
939
}
940
940
941
941
// 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 ) {
945
948
return createStringError (
946
949
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 ());
949
951
}
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 ());
954
955
}
955
- ISAInfo->addExtension (SeenExts[Idx], ExtsVersion[Idx] );
956
+ ISAInfo->addExtension (ExtName, ExtVers );
956
957
}
957
958
958
959
return RISCVISAInfo::postProcessAndChecking (std::move (ISAInfo));
0 commit comments