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