[PATCH] D62784: [NFC] Include short string attributes in the "Function Attrs" comment

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 1 13:14:03 PDT 2019


jdoerfert created this revision.
jdoerfert added reviewers: rnk, sunfish, pcc, espindola.
Herald added subscribers: bollu, hiraditya.
Herald added a project: LLVM.

So far, the comment above a function in LLVM-IR did not include any
string function attributes. While for many of them it is preferable not
to have them there, sometimes it makes sense. This patch introduces a
heuristic based on the size of the string attribute name and value.
If they together do not contain more than 15 characters we include them
in the comment, otherwise we do not.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62784

Files:
  llvm/lib/IR/AsmWriter.cpp
  llvm/test/Bitcode/attributes.ll


Index: llvm/test/Bitcode/attributes.ll
===================================================================
--- llvm/test/Bitcode/attributes.ll
+++ llvm/test/Bitcode/attributes.ll
@@ -204,7 +204,7 @@
 ; CHECK: define void @f34()
 {
         call void @nobuiltin() nobuiltin
-; CHECK: call void @nobuiltin() #36
+; CHECK: call void @nobuiltin() #37
         ret void;
 }
 
@@ -351,6 +351,14 @@
   ret void
 }
 
+; CHECK:      Function Attrs: "short"="option"
+; CHECK-NOT:  long
+; CHECK-NEXT: define void @f60() #36
+define void @f60() #0
+{
+  ret void
+}
+
 ; CHECK: attributes #0 = { noreturn }
 ; CHECK: attributes #1 = { nounwind }
 ; CHECK: attributes #2 = { readnone }
@@ -387,4 +395,7 @@
 ; CHECK: attributes #33 = { speculatable }
 ; CHECK: attributes #34 = { sanitize_hwaddress }
 ; CHECK: attributes #35 = { shadowcallstack }
-; CHECK: attributes #36 = { nobuiltin }
+; CHECK: attributes #36 = { "long"="options_are_excluded" "short"="option" }
+; CHECK: attributes #37 = { nobuiltin }
+
+attributes #0 = { "long"="options_are_excluded" "short"="option" }
Index: llvm/lib/IR/AsmWriter.cpp
===================================================================
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -3337,10 +3337,14 @@
     std::string AttrStr;
 
     for (const Attribute &Attr : AS) {
-      if (!Attr.isStringAttribute()) {
-        if (!AttrStr.empty()) AttrStr += ' ';
-        AttrStr += Attr.getAsString();
-      }
+      bool IsStringAttr = Attr.isStringAttribute();
+      auto AttrKeyStr = Attr.getAsString();
+      // Filter string attributes based on the size of key + value. This is a heuristic.
+      if (IsStringAttr && (AttrKeyStr.size() > 15 + /* quotes */ 4 + /* equal sign */ 1))
+        continue;
+      if (!AttrStr.empty())
+        AttrStr += ' ';
+      AttrStr += AttrKeyStr;
     }
 
     if (!AttrStr.empty())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62784.202567.patch
Type: text/x-patch
Size: 1873 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190601/4f5d67af/attachment.bin>


More information about the llvm-commits mailing list