[llvm] r179735 - Add an option `-enable-old-style-attr-syntax' to print out function attributes in the "old" style.

Bill Wendling isanbard at gmail.com
Wed Apr 17 16:35:59 PDT 2013


Author: void
Date: Wed Apr 17 18:35:59 2013
New Revision: 179735

URL: http://llvm.org/viewvc/llvm-project?rev=179735&view=rev
Log:
Add an option `-enable-old-style-attr-syntax' to print out function attributes in the "old" style.

It's sometimes beneficial to emit a testcase with the old style attribute
syntax. Allow someone to do this.
<rdar://problem/13563209>

Modified:
    llvm/trunk/include/llvm/IR/Attributes.h
    llvm/trunk/lib/IR/AsmWriter.cpp
    llvm/trunk/lib/IR/AttributeImpl.h
    llvm/trunk/lib/IR/Attributes.cpp

Modified: llvm/trunk/include/llvm/IR/Attributes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Attributes.h?rev=179735&r1=179734&r2=179735&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Attributes.h (original)
+++ llvm/trunk/include/llvm/IR/Attributes.h Wed Apr 17 18:35:59 2013
@@ -306,7 +306,8 @@ public:
   unsigned getStackAlignment(unsigned Index) const;
 
   /// \brief Return the attributes at the index as a string.
-  std::string getAsString(unsigned Index, bool InAttrGrp = false) const;
+  std::string getAsString(unsigned Index, bool TargetIndependent = false,
+                          bool InAttrGrp = false) const;
 
   typedef ArrayRef<Attribute>::iterator iterator;
 

Modified: llvm/trunk/lib/IR/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=179735&r1=179734&r2=179735&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Wed Apr 17 18:35:59 2013
@@ -33,6 +33,7 @@
 #include "llvm/IR/TypeFinder.h"
 #include "llvm/IR/ValueSymbolTable.h"
 #include "llvm/Support/CFG.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Dwarf.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -42,6 +43,12 @@
 #include <cctype>
 using namespace llvm;
 
+static cl::opt<bool>
+OldStyleAttrSyntax("enable-old-style-attr-syntax",
+    cl::desc("Output attributes on functions rather than in attribute groups"),
+    cl::Hidden,
+    cl::init(false));
+
 // Make virtual table appear in this compilation unit.
 AssemblyAnnotationWriter::~AssemblyAnnotationWriter() {}
 
@@ -1378,7 +1385,7 @@ void AssemblyWriter::printModule(const M
     printFunction(I);
 
   // Output all attribute groups.
-  if (!Machine.as_empty()) {
+  if (!OldStyleAttrSyntax && !Machine.as_empty()) {
     Out << '\n';
     writeAllAttributeGroups();
   }
@@ -1606,24 +1613,9 @@ void AssemblyWriter::printFunction(const
     Out << "; Materializable\n";
 
   const AttributeSet &Attrs = F->getAttributes();
-  if (Attrs.hasAttributes(AttributeSet::FunctionIndex)) {
+  if (!OldStyleAttrSyntax && Attrs.hasAttributes(AttributeSet::FunctionIndex)) {
     AttributeSet AS = Attrs.getFnAttributes();
-    std::string AttrStr;
-
-    unsigned Idx = 0;
-    for (unsigned E = AS.getNumSlots(); Idx != E; ++Idx)
-      if (AS.getSlotIndex(Idx) == AttributeSet::FunctionIndex)
-        break;
-
-    for (AttributeSet::iterator I = AS.begin(Idx), E = AS.end(Idx);
-         I != E; ++I) {
-      Attribute Attr = *I;
-      if (!Attr.isStringAttribute()) {
-        if (!AttrStr.empty()) AttrStr += ' ';
-        AttrStr += Attr.getAsString();
-      }
-    }
-
+    std::string AttrStr = AS.getAsString(AttributeSet::FunctionIndex, true);
     if (!AttrStr.empty())
       Out << "; Function Attrs: " << AttrStr << '\n';
   }
@@ -1685,8 +1677,15 @@ void AssemblyWriter::printFunction(const
   Out << ')';
   if (F->hasUnnamedAddr())
     Out << " unnamed_addr";
-  if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
-    Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes());
+  if (!OldStyleAttrSyntax) {
+    if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
+      Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttributes());
+  } else {
+    AttributeSet AS = Attrs.getFnAttributes();
+    std::string AttrStr = AS.getAsString(AttributeSet::FunctionIndex, true);
+    if (!AttrStr.empty())
+      Out << ' ' << AttrStr;
+  }
   if (F->hasSection()) {
     Out << " section \"";
     PrintEscapedString(F->getSection(), Out);
@@ -2157,7 +2156,8 @@ void AssemblyWriter::writeAllAttributeGr
   for (std::vector<std::pair<AttributeSet, unsigned> >::iterator
          I = asVec.begin(), E = asVec.end(); I != E; ++I)
     Out << "attributes #" << I->second << " = { "
-        << I->first.getAsString(AttributeSet::FunctionIndex, true) << " }\n";
+        << I->first.getAsString(AttributeSet::FunctionIndex, false, true)
+        << " }\n";
 }
 
 //===----------------------------------------------------------------------===//

Modified: llvm/trunk/lib/IR/AttributeImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AttributeImpl.h?rev=179735&r1=179734&r2=179735&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AttributeImpl.h (original)
+++ llvm/trunk/lib/IR/AttributeImpl.h Wed Apr 17 18:35:59 2013
@@ -178,7 +178,7 @@ public:
 
   unsigned getAlignment() const;
   unsigned getStackAlignment() const;
-  std::string getAsString(bool InAttrGrp) const;
+  std::string getAsString(bool TargetIndependent, bool InAttrGrp) const;
 
   typedef SmallVectorImpl<Attribute>::iterator       iterator;
   typedef SmallVectorImpl<Attribute>::const_iterator const_iterator;

Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=179735&r1=179734&r2=179735&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Wed Apr 17 18:35:59 2013
@@ -480,12 +480,17 @@ unsigned AttributeSetNode::getStackAlign
   return 0;
 }
 
-std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
+std::string AttributeSetNode::getAsString(bool TargetIndependent,
+                                          bool InAttrGrp) const {
   std::string Str = "";
   for (SmallVectorImpl<Attribute>::const_iterator I = AttrList.begin(),
          E = AttrList.end(); I != E; ) {
-    Str += I->getAsString(InAttrGrp);
-    if (++I != E) Str += " ";
+    if (!TargetIndependent || !I->isStringAttribute()) {
+      Str += I->getAsString(InAttrGrp);
+      if (++I != E) Str += " ";
+    } else {
+      ++I;
+    }
   }
   return Str;
 }
@@ -841,10 +846,11 @@ unsigned AttributeSet::getStackAlignment
   return ASN ? ASN->getStackAlignment() : 0;
 }
 
-std::string AttributeSet::getAsString(unsigned Index,
+std::string AttributeSet::getAsString(unsigned Index, bool TargetIndependent,
                                       bool InAttrGrp) const {
   AttributeSetNode *ASN = getAttributes(Index);
-  return ASN ? ASN->getAsString(InAttrGrp) : std::string("");
+  return ASN ? ASN->getAsString(TargetIndependent, InAttrGrp) :
+    std::string("");
 }
 
 /// \brief The attributes for the specified index are returned.





More information about the llvm-commits mailing list