[llvm] [AArch64][Build Attributes] Improve Parsing and Formatting (PR #126530)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 19 04:03:51 PST 2025


================
@@ -214,22 +215,20 @@ void AArch64TargetStreamer::emitAttribute(StringRef VendorName, unsigned Tag,
         return;
       }
       for (MCELFStreamer::AttributeItem &Item : SubSection.Content) {
+        // Tag already exists
         if (Item.Tag == Tag) {
-          if (!Override) {
-            if ((unsigned(-1) != Value && Item.IntValue != Value) ||
-                ("" != String && Item.StringValue != String)) {
-              assert(0 &&
-                     "Can not add AArch64 build attribute: An attribute with "
-                     "the same tag and a different value already exists");
-              return;
-            } else {
-              // Case Item.IntValue == Value, no need to emit twice
-              assert(0 &&
-                     "AArch64 build attribute: An attribute with the same tag "
-                     "and a same value already exists");
-              return;
-            }
+          // New value for existing tag: update tag
+          if ((unsigned(-1) != Value && Item.IntValue != Value) ||
----------------
sivan-shani wrote:

It might eliminate unnecessary operations, depending on which is preferable: the comparison or updating the values.
It is reasonable to believe that the comparison is cheaper. Since neither case makes sense and should not happen unless as a result of a mistake or oversight, there is no reason to assume that the case requiring updates will be more frequent then the case which does not. Therefore, adding the check makes sense.

Additionally, it enhances readability and makes future behavior changes easier if needed.

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


More information about the llvm-commits mailing list