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