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"
@@ -722,8 +723,9 @@ static Error splitExtsByUnderscore(StringRef Exts,
722
723
}
723
724
724
725
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,
727
729
bool IgnoreUnknown, bool EnableExperimentalExtension,
728
730
bool ExperimentalExtensionVersionCheck) {
729
731
StringRef Type = getExtensionType (RawExt);
@@ -756,21 +758,21 @@ static Error processMultiLetterExtension(
756
758
}
757
759
758
760
// Check if duplicated extension.
759
- if (!IgnoreUnknown && llvm::is_contained (SeenExts, Name))
761
+ if (!IgnoreUnknown && (SeenExtMap. find ( Name. str ()) != SeenExtMap. end () ))
760
762
return createStringError (errc::invalid_argument, " duplicated %s '%s'" ,
761
763
Desc.str ().c_str (), Name.str ().c_str ());
762
764
763
765
if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension (Name))
764
766
return Error::success ();
765
767
766
- SeenExts.push_back (Name.str ());
767
- ExtsVersion.push_back ({Major, Minor});
768
+ SeenExtMap[Name.str ()] = {Major, Minor};
768
769
return Error::success ();
769
770
}
770
771
771
772
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,
774
776
bool IgnoreUnknown, bool EnableExperimentalExtension,
775
777
bool ExperimentalExtensionVersionCheck) {
776
778
unsigned Major, Minor, ConsumeLength;
@@ -790,16 +792,15 @@ static Error processSingleLetterExtension(
790
792
RawExt = RawExt.substr (ConsumeLength);
791
793
792
794
// Check if duplicated extension.
793
- if (!IgnoreUnknown && llvm::is_contained (SeenExts, Name))
795
+ if (!IgnoreUnknown && (SeenExtMap. find ( Name. str ()) != SeenExtMap. end () ))
794
796
return createStringError (errc::invalid_argument,
795
797
" duplicated standard user-level extension '%s'" ,
796
798
Name.str ().c_str ());
797
799
798
800
if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension (Name))
799
801
return Error::success ();
800
802
801
- SeenExts.push_back (Name.str ());
802
- ExtsVersion.push_back ({Major, Minor});
803
+ SeenExtMap[Name.str ()] = {Major, Minor};
803
804
return Error::success ();
804
805
}
805
806
@@ -823,8 +824,9 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
823
824
824
825
unsigned XLen = HasRV64 ? 64 : 32 ;
825
826
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;
828
830
829
831
// The canonical order specified in ISA manual.
830
832
// Ref: Table 22.1 in RISC-V User-Level ISA V2.2
@@ -866,8 +868,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
866
868
for (const auto *Ext : RISCVGImplications) {
867
869
if (auto Version = findDefaultVersion (Ext)) {
868
870
// 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 };
871
872
} else
872
873
llvm_unreachable (" Default extension version not found?" );
873
874
}
@@ -887,8 +888,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
887
888
}
888
889
889
890
// 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};
892
892
}
893
893
894
894
// Consume the base ISA version number and any '_' between rvxxx and the
@@ -905,8 +905,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
905
905
while (!CurrExt.empty ()) {
906
906
if (AllStdExts.contains (CurrExt.front ())) {
907
907
if (auto E = processSingleLetterExtension (
908
- CurrExt, SeenExts, ExtsVersion, IgnoreUnknown ,
909
- EnableExperimentalExtension, ExperimentalExtensionVersionCheck))
908
+ CurrExt, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension ,
909
+ ExperimentalExtensionVersionCheck))
910
910
return E;
911
911
} else if (CurrExt.front () == ' z' || CurrExt.front () == ' s' ||
912
912
CurrExt.front () == ' x' ) {
@@ -919,8 +919,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
919
919
// version number (major, minor) and are separated by a single
920
920
// underscore '_'. We do not enforce a canonical order for them.
921
921
if (auto E = processMultiLetterExtension (
922
- CurrExt, SeenExts, ExtsVersion, IgnoreUnknown ,
923
- EnableExperimentalExtension, ExperimentalExtensionVersionCheck))
922
+ CurrExt, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension ,
923
+ ExperimentalExtensionVersionCheck))
924
924
return E;
925
925
// Multi-letter extension must be seperate following extension with
926
926
// underscore
@@ -935,20 +935,21 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
935
935
}
936
936
937
937
// 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 ) {
941
944
return createStringError (
942
945
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 ());
945
947
}
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 ());
950
951
}
951
- ISAInfo->addExtension (SeenExts[Idx], ExtsVersion[Idx] );
952
+ ISAInfo->addExtension (ExtName, ExtVers );
952
953
}
953
954
954
955
return RISCVISAInfo::postProcessAndChecking (std::move (ISAInfo));
0 commit comments