@@ -6947,22 +6947,18 @@ static void ExpandCryptoAEK(const AArch64::ArchInfo &ArchInfo,
6947
6947
}
6948
6948
}
6949
6949
6950
- static SMLoc incrementLoc (SMLoc L, int Offset) {
6951
- return SMLoc::getFromPointer (L.getPointer () + Offset);
6952
- }
6953
-
6954
6950
// / parseDirectiveArch
6955
6951
// / ::= .arch token
6956
6952
bool AArch64AsmParser::parseDirectiveArch (SMLoc L) {
6957
- SMLoc CurLoc = getLoc ();
6953
+ SMLoc ArchLoc = getLoc ();
6958
6954
6959
6955
StringRef Arch, ExtensionString;
6960
6956
std::tie (Arch, ExtensionString) =
6961
6957
getParser ().parseStringToEndOfStatement ().trim ().split (' +' );
6962
6958
6963
6959
const AArch64::ArchInfo *ArchInfo = AArch64::parseArch (Arch);
6964
6960
if (!ArchInfo)
6965
- return Error (CurLoc , " unknown arch name" );
6961
+ return Error (ArchLoc , " unknown arch name" );
6966
6962
6967
6963
if (parseToken (AsmToken::EndOfStatement))
6968
6964
return true ;
@@ -6982,30 +6978,27 @@ bool AArch64AsmParser::parseDirectiveArch(SMLoc L) {
6982
6978
ExtensionString.split (RequestedExtensions, ' +' );
6983
6979
6984
6980
ExpandCryptoAEK (*ArchInfo, RequestedExtensions);
6985
- CurLoc = incrementLoc (CurLoc, Arch.size ());
6986
6981
6982
+ FeatureBitset Features = STI.getFeatureBits ();
6983
+ setAvailableFeatures (ComputeAvailableFeatures (Features));
6987
6984
for (auto Name : RequestedExtensions) {
6988
- // Advance source location past '+'.
6989
- CurLoc = incrementLoc (CurLoc, 1 );
6990
-
6991
6985
bool EnableFeature = !Name.consume_front_insensitive (" no" );
6992
6986
6993
- auto It = llvm::find_if (ExtensionMap, [&Name](const auto &Extension) {
6994
- return Extension.Name == Name;
6995
- });
6996
-
6997
- if (It == std::end (ExtensionMap))
6998
- return Error (CurLoc, " unsupported architectural extension: " + Name);
6987
+ for (const auto &Extension : ExtensionMap) {
6988
+ if (Extension.Name != Name)
6989
+ continue ;
6999
6990
7000
- if (EnableFeature)
7001
- STI.SetFeatureBitsTransitively (It->Features );
7002
- else
7003
- STI.ClearFeatureBitsTransitively (It->Features );
6991
+ if (Extension.Features .none ())
6992
+ report_fatal_error (" unsupported architectural extension: " + Name);
7004
6993
7005
- CurLoc = incrementLoc (CurLoc, Name.size ());
6994
+ FeatureBitset ToggleFeatures =
6995
+ EnableFeature
6996
+ ? STI.SetFeatureBitsTransitively (~Features & Extension.Features )
6997
+ : STI.ToggleFeature (Features & Extension.Features );
6998
+ setAvailableFeatures (ComputeAvailableFeatures (ToggleFeatures));
6999
+ break ;
7000
+ }
7006
7001
}
7007
- FeatureBitset Features = ComputeAvailableFeatures (STI.getFeatureBits ());
7008
- setAvailableFeatures (Features);
7009
7002
return false ;
7010
7003
}
7011
7004
@@ -7025,21 +7018,28 @@ bool AArch64AsmParser::parseDirectiveArchExtension(SMLoc L) {
7025
7018
Name = Name.substr (2 );
7026
7019
}
7027
7020
7028
- auto It = llvm::find_if (ExtensionMap, [&Name](const auto &Extension) {
7029
- return Extension.Name == Name;
7030
- });
7021
+ MCSubtargetInfo &STI = copySTI ();
7022
+ FeatureBitset Features = STI.getFeatureBits ();
7023
+ for (const auto &Extension : ExtensionMap) {
7024
+ if (Extension.Name != Name)
7025
+ continue ;
7026
+
7027
+ if (Extension.Features .none ())
7028
+ return Error (ExtLoc, " unsupported architectural extension: " + Name);
7029
+
7030
+ FeatureBitset ToggleFeatures =
7031
+ EnableFeature
7032
+ ? STI.SetFeatureBitsTransitively (~Features & Extension.Features )
7033
+ : STI.ToggleFeature (Features & Extension.Features );
7034
+ setAvailableFeatures (ComputeAvailableFeatures (ToggleFeatures));
7035
+ return false ;
7036
+ }
7031
7037
7032
- if (It == std::end (ExtensionMap))
7033
- return Error (ExtLoc, " unsupported architectural extension: " + Name);
7038
+ return Error (ExtLoc, " unknown architectural extension: " + Name);
7039
+ }
7034
7040
7035
- MCSubtargetInfo &STI = copySTI ();
7036
- if (EnableFeature)
7037
- STI.SetFeatureBitsTransitively (It->Features );
7038
- else
7039
- STI.ClearFeatureBitsTransitively (It->Features );
7040
- FeatureBitset Features = ComputeAvailableFeatures (STI.getFeatureBits ());
7041
- setAvailableFeatures (Features);
7042
- return false ;
7041
+ static SMLoc incrementLoc (SMLoc L, int Offset) {
7042
+ return SMLoc::getFromPointer (L.getPointer () + Offset);
7043
7043
}
7044
7044
7045
7045
// / parseDirectiveCPU
@@ -7075,22 +7075,30 @@ bool AArch64AsmParser::parseDirectiveCPU(SMLoc L) {
7075
7075
7076
7076
bool EnableFeature = !Name.consume_front_insensitive (" no" );
7077
7077
7078
- auto It = llvm::find_if (ExtensionMap, [&Name](const auto &Extension) {
7079
- return Extension.Name == Name;
7080
- });
7078
+ bool FoundExtension = false ;
7079
+ for (const auto &Extension : ExtensionMap) {
7080
+ if (Extension.Name != Name)
7081
+ continue ;
7081
7082
7082
- if (It == std::end (ExtensionMap ))
7083
- Error (CurLoc, " unsupported architectural extension: " + Name);
7083
+ if (Extension. Features . none ( ))
7084
+ report_fatal_error ( " unsupported architectural extension: " + Name);
7084
7085
7085
- if (EnableFeature)
7086
- STI.SetFeatureBitsTransitively (It->Features );
7087
- else
7088
- STI.ClearFeatureBitsTransitively (It->Features );
7086
+ FeatureBitset Features = STI.getFeatureBits ();
7087
+ FeatureBitset ToggleFeatures =
7088
+ EnableFeature
7089
+ ? STI.SetFeatureBitsTransitively (~Features & Extension.Features )
7090
+ : STI.ToggleFeature (Features & Extension.Features );
7091
+ setAvailableFeatures (ComputeAvailableFeatures (ToggleFeatures));
7092
+ FoundExtension = true ;
7093
+
7094
+ break ;
7095
+ }
7096
+
7097
+ if (!FoundExtension)
7098
+ Error (CurLoc, " unsupported architectural extension" );
7089
7099
7090
7100
CurLoc = incrementLoc (CurLoc, Name.size ());
7091
7101
}
7092
- FeatureBitset Features = ComputeAvailableFeatures (STI.getFeatureBits ());
7093
- setAvailableFeatures (Features);
7094
7102
return false ;
7095
7103
}
7096
7104
0 commit comments