[llvm] Reland [AArch64][AsmParser] Directives should clear transitively implied features (#106625) (PR #106850)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 2 06:44:39 PDT 2024


================
@@ -7075,30 +7075,22 @@ bool AArch64AsmParser::parseDirectiveCPU(SMLoc L) {
 
     bool EnableFeature = !Name.consume_front_insensitive("no");
 
-    bool FoundExtension = false;
-    for (const auto &Extension : ExtensionMap) {
-      if (Extension.Name != Name)
-        continue;
+    auto It = llvm::find_if(ExtensionMap, [&Name](const auto &Extension) {
+      return Extension.Name == Name;
+    });
 
-      if (Extension.Features.none())
-        report_fatal_error("unsupported architectural extension: " + Name);
-
-      FeatureBitset Features = STI.getFeatureBits();
-      FeatureBitset ToggleFeatures =
-          EnableFeature
-              ? STI.SetFeatureBitsTransitively(~Features & Extension.Features)
-              : STI.ToggleFeature(Features & Extension.Features);
-      setAvailableFeatures(ComputeAvailableFeatures(ToggleFeatures));
-      FoundExtension = true;
-
-      break;
+    if (It != std::end(ExtensionMap)) {
+      if (EnableFeature)
+        STI.SetFeatureBitsTransitively(It->Features);
+      else
+        STI.ClearFeatureBitsTransitively(It->Features);
+    } else {
+      Error(CurLoc, "unsupported architectural extension: " + Name);
----------------
sdesmalen-arm wrote:

Would it be simpler to just `return Error(..)`, such that the function would return `true` instead of `false` (by convention in the rest of this file and inline with `return Error`). I know it then only emits an error for the first extension that is unsupported, rather than do so for all of them, but I'm not sure if this is important and it simplifies the logic a bit.

I spotted that the case on line 7064 currently returns `false`, which I think should be `true` (or simply `return Error(..)` as well.

https://github.com/llvm/llvm-project/pull/106850


More information about the llvm-commits mailing list