Remove the final bits of Attributes being declared in the Attribute
authorBill Wendling <isanbard@gmail.com>
Wed, 10 Oct 2012 07:36:45 +0000 (07:36 +0000)
committerBill Wendling <isanbard@gmail.com>
Wed, 10 Oct 2012 07:36:45 +0000 (07:36 +0000)
namespace. Use the attribute's enum value instead. No functionality change
intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165610 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Attributes.h
lib/CodeGen/Analysis.cpp
lib/Target/CppBackend/CPPBackend.cpp
lib/Transforms/IPO/FunctionAttrs.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/Scalar/CodeGenPrepare.cpp
lib/Transforms/Scalar/SimplifyLibCalls.cpp
lib/VMCore/Attributes.cpp

index 4825c97a9b9db3cba0ffa762ff21aeef32c592a0..ac9ddf0090fbc9aed9656fccf0f99d65081a76ca 100644 (file)
@@ -55,46 +55,6 @@ struct AttrConst {
 #define DECLARE_LLVM_ATTRIBUTE(name, value) \
   const AttrConst name = {value};
 
-DECLARE_LLVM_ATTRIBUTE(None,0)    ///< No attributes have been set
-DECLARE_LLVM_ATTRIBUTE(ZExt,1<<0) ///< Zero extended before/after call
-DECLARE_LLVM_ATTRIBUTE(SExt,1<<1) ///< Sign extended before/after call
-DECLARE_LLVM_ATTRIBUTE(NoReturn,1<<2) ///< Mark the function as not returning
-DECLARE_LLVM_ATTRIBUTE(InReg,1<<3) ///< Force argument to be passed in register
-DECLARE_LLVM_ATTRIBUTE(StructRet,1<<4) ///< Hidden pointer to structure to return
-DECLARE_LLVM_ATTRIBUTE(NoUnwind,1<<5) ///< Function doesn't unwind stack
-DECLARE_LLVM_ATTRIBUTE(NoAlias,1<<6) ///< Considered to not alias after call
-DECLARE_LLVM_ATTRIBUTE(ByVal,1<<7) ///< Pass structure by value
-DECLARE_LLVM_ATTRIBUTE(Nest,1<<8) ///< Nested function static chain
-DECLARE_LLVM_ATTRIBUTE(ReadNone,1<<9) ///< Function does not access memory
-DECLARE_LLVM_ATTRIBUTE(ReadOnly,1<<10) ///< Function only reads from memory
-DECLARE_LLVM_ATTRIBUTE(NoInline,1<<11) ///< inline=never
-DECLARE_LLVM_ATTRIBUTE(AlwaysInline,1<<12) ///< inline=always
-DECLARE_LLVM_ATTRIBUTE(OptimizeForSize,1<<13) ///< opt_size
-DECLARE_LLVM_ATTRIBUTE(StackProtect,1<<14) ///< Stack protection.
-DECLARE_LLVM_ATTRIBUTE(StackProtectReq,1<<15) ///< Stack protection required.
-DECLARE_LLVM_ATTRIBUTE(Alignment,31<<16) ///< Alignment of parameter (5 bits)
-                                     // stored as log2 of alignment with +1 bias
-                                     // 0 means unaligned different from align 1
-DECLARE_LLVM_ATTRIBUTE(NoCapture,1<<21) ///< Function creates no aliases of pointer
-DECLARE_LLVM_ATTRIBUTE(NoRedZone,1<<22) /// disable redzone
-DECLARE_LLVM_ATTRIBUTE(NoImplicitFloat,1<<23) /// disable implicit floating point
-                                           /// instructions.
-DECLARE_LLVM_ATTRIBUTE(Naked,1<<24) ///< Naked function
-DECLARE_LLVM_ATTRIBUTE(InlineHint,1<<25) ///< source said inlining was
-                                           ///desirable
-DECLARE_LLVM_ATTRIBUTE(StackAlignment,7<<26) ///< Alignment of stack for
-                                           ///function (3 bits) stored as log2
-                                           ///of alignment with +1 bias
-                                           ///0 means unaligned (different from
-                                           ///alignstack= {1))
-DECLARE_LLVM_ATTRIBUTE(ReturnsTwice,1<<29) ///< Function can return twice
-DECLARE_LLVM_ATTRIBUTE(UWTable,1<<30) ///< Function must be in a unwind
-                                           ///table
-DECLARE_LLVM_ATTRIBUTE(NonLazyBind,1U<<31) ///< Function is called early and/or
-                                            /// often, so lazy binding isn't
-                                            /// worthwhile.
-DECLARE_LLVM_ATTRIBUTE(AddressSafety,1ULL<<32) ///< Address safety checking is on.
-
 #undef DECLARE_LLVM_ATTRIBUTE
 
 }  // namespace Attribute
@@ -175,11 +135,13 @@ public:
 
     void clear() { Bits = 0; }
 
+    bool hasAttribute(Attributes::AttrVal A) const;
     bool hasAttributes() const;
     bool hasAttributes(const Attributes &A) const;
     bool hasAlignmentAttr() const;
 
     uint64_t getAlignment() const;
+    uint64_t getStackAlignment() const;
 
     Builder &addAttribute(Attributes::AttrVal Val);
     Builder &removeAttribute(Attributes::AttrVal Val);
@@ -467,7 +429,7 @@ public:
 
   /// hasAttrSomewhere - Return true if the specified attribute is set for at
   /// least one parameter or for the return value.
-  bool hasAttrSomewhere(Attributes Attr) const;
+  bool hasAttrSomewhere(Attributes::AttrVal Attr) const;
 
   unsigned getNumAttrs() const;
   Attributes &getAttributesAtIndex(unsigned i) const;
index d7214e8b58a6aacf65bf524ffb131d952681cffc..09e30eba57954a4c7080d5a2b3d56fc4d0416470 100644 (file)
@@ -314,7 +314,8 @@ bool llvm::isInTailCallPosition(ImmutableCallSite CS, Attributes CalleeRetAttr,
   // the return. Ignore noalias because it doesn't affect the call sequence.
   const Function *F = ExitBB->getParent();
   Attributes CallerRetAttr = F->getAttributes().getRetAttributes();
-  if ((CalleeRetAttr ^ CallerRetAttr) & ~Attribute::NoAlias)
+  if (Attributes::Builder(CalleeRetAttr ^ CallerRetAttr)
+      .removeAttribute(Attributes::NoAlias).hasAttributes())
     return false;
 
   // It's not safe to eliminate the sign / zero extension of the return value.
@@ -355,7 +356,8 @@ bool llvm::isInTailCallPosition(SelectionDAG &DAG, SDNode *Node,
   // Conservatively require the attributes of the call to match those of
   // the return. Ignore noalias because it doesn't affect the call sequence.
   Attributes CallerRetAttr = F->getAttributes().getRetAttributes();
-  if (CallerRetAttr & ~Attribute::NoAlias)
+  if (Attributes::Builder(CallerRetAttr)
+      .removeAttribute(Attributes::NoAlias).hasAttributes())
     return false;
 
   // It's not safe to eliminate the sign / zero extension of the return value.
index 444da2bb21eef87d517cf9a29bc1febe29b8aae8..096e2bc13b09cf31a29b3bb6e330b098c07e801e 100644 (file)
@@ -474,13 +474,15 @@ void CppWriter::printAttributes(const AttrListPtr &PAL,
     Out << "AttributeWithIndex PAWI;"; nl(Out);
     for (unsigned i = 0; i < PAL.getNumSlots(); ++i) {
       unsigned index = PAL.getSlot(i).Index;
-      Attributes attrs = PAL.getSlot(i).Attrs;
-      Out << "PAWI.Index = " << index << "U; PAWI.Attrs = Attribute::None ";
-#define HANDLE_ATTR(X)                 \
-      if (attrs & Attribute::X)      \
-        Out << " | Attribute::" #X;  \
-      attrs &= ~Attribute::X;
-      
+      Attributes::Builder attrs(PAL.getSlot(i).Attrs);
+      Out << "PAWI.Index = " << index << "U;\n";
+      Out << "   Attributes::Builder B;\n";
+
+#define HANDLE_ATTR(X)                                     \
+      if (attrs.hasAttribute(Attributes::X))               \
+        Out << "   B.addAttribute(Attributes::" #X ");\n"; \
+      attrs.removeAttribute(Attributes::X);
+
       HANDLE_ATTR(SExt);
       HANDLE_ATTR(ZExt);
       HANDLE_ATTR(NoReturn);
@@ -506,13 +508,14 @@ void CppWriter::printAttributes(const AttrListPtr &PAL,
       HANDLE_ATTR(UWTable);
       HANDLE_ATTR(NonLazyBind);
 #undef HANDLE_ATTR
-      if (attrs & Attribute::StackAlignment)
-        Out << " | Attribute::constructStackAlignmentFromInt("
+      if (attrs.hasAttribute(Attributes::StackAlignment))
+        Out << "B.addStackAlignmentAttr(Attribute::constructStackAlignmentFromInt("
             << attrs.getStackAlignment()
-            << ")"; 
-      attrs &= ~Attribute::StackAlignment;
-      assert(attrs == 0 && "Unhandled attribute!");
-      Out << ";";
+            << "))";
+      nl(Out);
+      attrs.removeAttribute(Attributes::StackAlignment);
+      assert(!attrs.hasAttributes() && "Unhandled attribute!");
+      Out << "PAWI.Attrs = Attributes::get(B);";
       nl(Out);
       Out << "Attrs.push_back(PAWI);";
       nl(Out);
index e0deb433112d8c78a26b3cfd8147e2d4250353a8..43e12d4444130731a97a0264d6468ffb1593c4a3 100644 (file)
@@ -212,10 +212,15 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
     MadeChange = true;
 
     // Clear out any existing attributes.
-    F->removeAttribute(~0, Attribute::ReadOnly | Attribute::ReadNone);
+    Attributes::Builder B;
+    B.addAttribute(Attributes::ReadOnly)
+      .addAttribute(Attributes::ReadNone);
+    F->removeAttribute(~0, Attributes::get(B));
 
     // Add in the new attribute.
-    F->addAttribute(~0, ReadsMemory? Attribute::ReadOnly : Attribute::ReadNone);
+    B.clear();
+    B.addAttribute(ReadsMemory ? Attributes::ReadOnly : Attributes::ReadNone);
+    F->addAttribute(~0, Attributes::get(B));
 
     if (ReadsMemory)
       ++NumReadOnly;
@@ -350,6 +355,9 @@ bool FunctionAttrs::AddNoCaptureAttrs(const CallGraphSCC &SCC) {
 
   ArgumentGraph AG;
 
+  Attributes::Builder B;
+  B.addAttribute(Attributes::NoCapture);
+
   // Check each function in turn, determining which pointer arguments are not
   // captured.
   for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
@@ -371,7 +379,7 @@ bool FunctionAttrs::AddNoCaptureAttrs(const CallGraphSCC &SCC) {
       for (Function::arg_iterator A = F->arg_begin(), E = F->arg_end();
            A != E; ++A) {
         if (A->getType()->isPointerTy() && !A->hasNoCaptureAttr()) {
-          A->addAttr(Attribute::NoCapture);
+          A->addAttr(Attributes::get(B));
           ++NumNoCapture;
           Changed = true;
         }
@@ -386,7 +394,7 @@ bool FunctionAttrs::AddNoCaptureAttrs(const CallGraphSCC &SCC) {
         if (!Tracker.Captured) {
           if (Tracker.Uses.empty()) {
             // If it's trivially not captured, mark it nocapture now.
-            A->addAttr(Attribute::NoCapture);
+            A->addAttr(Attributes::get(B));
             ++NumNoCapture;
             Changed = true;
           } else {
@@ -419,7 +427,7 @@ bool FunctionAttrs::AddNoCaptureAttrs(const CallGraphSCC &SCC) {
       // eg. "void f(int* x) { if (...) f(x); }"
       if (ArgumentSCC[0]->Uses.size() == 1 &&
           ArgumentSCC[0]->Uses[0] == ArgumentSCC[0]) {
-        ArgumentSCC[0]->Definition->addAttr(Attribute::NoCapture);
+        ArgumentSCC[0]->Definition->addAttr(Attributes::get(B));
         ++NumNoCapture;
         Changed = true;
       }
@@ -461,7 +469,7 @@ bool FunctionAttrs::AddNoCaptureAttrs(const CallGraphSCC &SCC) {
 
     for (unsigned i = 0, e = ArgumentSCC.size(); i != e; ++i) {
       Argument *A = ArgumentSCC[i]->Definition;
-      A->addAttr(Attribute::NoCapture);
+      A->addAttr(Attributes::get(B));
       ++NumNoCapture;
       Changed = true;
     }
index e8e54ec9aef2bc027e13bf7e0ad750f27efe1766..a1b976577a74e8366295df6b8652cb623b222679 100644 (file)
@@ -2062,12 +2062,15 @@ static void ChangeCalleesToFastCall(Function *F) {
 }
 
 static AttrListPtr StripNest(const AttrListPtr &Attrs) {
+  Attributes::Builder B;
+  B.addAttribute(Attributes::Nest);
+
   for (unsigned i = 0, e = Attrs.getNumSlots(); i != e; ++i) {
     if (!Attrs.getSlot(i).Attrs.hasAttribute(Attributes::Nest))
       continue;
 
     // There can be only one.
-    return Attrs.removeAttr(Attrs.getSlot(i).Index, Attribute::Nest);
+    return Attrs.removeAttr(Attrs.getSlot(i).Index, Attributes::get(B));
   }
 
   return Attrs;
@@ -2108,7 +2111,7 @@ bool GlobalOpt::OptimizeFunctions(Module &M) {
         Changed = true;
       }
 
-      if (F->getAttributes().hasAttrSomewhere(Attribute::Nest) &&
+      if (F->getAttributes().hasAttrSomewhere(Attributes::Nest) &&
           !F->hasAddressTaken()) {
         // The function is not used by a trampoline intrinsic, so it is safe
         // to remove the 'nest' attribute.
index 2a52580eaadf898b7f03f82c6bd9181467ac1d3a..4d31444b7641aef197a259f9552918a741dd405e 100644 (file)
@@ -774,7 +774,8 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(ReturnInst *RI) {
     // Conservatively require the attributes of the call to match those of the
     // return. Ignore noalias because it doesn't affect the call sequence.
     Attributes CalleeRetAttr = CS.getAttributes().getRetAttributes();
-    if ((CalleeRetAttr ^ CallerRetAttr) & ~Attribute::NoAlias)
+    if (Attributes::Builder(CalleeRetAttr ^ CallerRetAttr)
+        .removeAttribute(Attributes::NoAlias).hasAttributes())
       continue;
 
     // Make sure the call instruction is followed by an unconditional branch to
index 15625f9a403a1fa16c8898893c4e87e0bf1edf26..73f53b7cecc78eda73787dbbd603f223e2bd119c 100644 (file)
@@ -636,7 +636,9 @@ struct StrToOpt : public LibCallOptimization {
     if (isa<ConstantPointerNull>(EndPtr)) {
       // With a null EndPtr, this function won't capture the main argument.
       // It would be readonly too, except that it still may write to errno.
-      CI->addAttribute(1, Attribute::NoCapture);
+      Attributes::Builder B;
+      B.addAttribute(Attributes::NoCapture);
+      CI->addAttribute(1, Attributes::get(B));
     }
 
     return 0;
index 88f20e94a5c5f86623e5c2d8d46d5ac79642d884..90a7c7ea6ae57a95dbc2f4732e16760922f6a740 100644 (file)
@@ -238,6 +238,10 @@ void Attributes::Builder::removeAttributes(const Attributes &A) {
   Bits &= ~A.Raw();
 }
 
+bool Attributes::Builder::hasAttribute(Attributes::AttrVal A) const {
+  return Bits & AttributesImpl::getAttrMask(A);
+}
+
 bool Attributes::Builder::hasAttributes() const {
   return Bits != 0;
 }
@@ -255,6 +259,13 @@ uint64_t Attributes::Builder::getAlignment() const {
     (((Bits & AttributesImpl::getAttrMask(Attributes::Alignment)) >> 16) - 1);
 }
 
+uint64_t Attributes::Builder::getStackAlignment() const {
+  if (!hasAlignmentAttr())
+    return 0;
+  return 1U <<
+    (((Bits & AttributesImpl::getAttrMask(Attributes::StackAlignment))>>26)-1);
+}
+
 //===----------------------------------------------------------------------===//
 // AttributeImpl Definition
 //===----------------------------------------------------------------------===//
@@ -468,12 +479,12 @@ Attributes AttrListPtr::getAttributes(unsigned Idx) const {
 
 /// hasAttrSomewhere - Return true if the specified attribute is set for at
 /// least one parameter or for the return value.
-bool AttrListPtr::hasAttrSomewhere(Attributes Attr) const {
+bool AttrListPtr::hasAttrSomewhere(Attributes::AttrVal Attr) const {
   if (AttrList == 0) return false;
-  
+
   const SmallVector<AttributeWithIndex, 4> &Attrs = AttrList->Attrs;
   for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
-    if (Attrs[i].Attrs.hasAttributes(Attr))
+    if (Attrs[i].Attrs.hasAttribute(Attr))
       return true;
   return false;
 }