From bbcdf4e2a5d57fed745d4c2a549c57c25f1e3aec Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 10 Oct 2012 07:36:45 +0000 Subject: [PATCH] Remove the final bits of Attributes being declared in the Attribute namespace. Use the attribute's enum value instead. No functionality change intended. llvm-svn: 165610 --- llvm/include/llvm/Attributes.h | 44 ++----------------------- llvm/lib/CodeGen/Analysis.cpp | 6 ++-- llvm/lib/Target/CppBackend/CPPBackend.cpp | 29 ++++++++-------- llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 20 +++++++---- llvm/lib/Transforms/IPO/GlobalOpt.cpp | 7 ++-- llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp | 3 +- llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp | 4 ++- llvm/lib/VMCore/Attributes.cpp | 17 ++++++++-- 8 files changed, 61 insertions(+), 69 deletions(-) diff --git a/llvm/include/llvm/Attributes.h b/llvm/include/llvm/Attributes.h index 4825c97..ac9ddf0 100644 --- a/llvm/include/llvm/Attributes.h +++ b/llvm/include/llvm/Attributes.h @@ -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; diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp index d7214e8..09e30eb 100644 --- a/llvm/lib/CodeGen/Analysis.cpp +++ b/llvm/lib/CodeGen/Analysis.cpp @@ -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. diff --git a/llvm/lib/Target/CppBackend/CPPBackend.cpp b/llvm/lib/Target/CppBackend/CPPBackend.cpp index 444da2b..096e2bc 100644 --- a/llvm/lib/Target/CppBackend/CPPBackend.cpp +++ b/llvm/lib/Target/CppBackend/CPPBackend.cpp @@ -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); diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp index e0deb43..43e12d4 100644 --- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp @@ -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; } diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index e8e54ec..a1b9765 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -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. diff --git a/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp b/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp index 2a52580..4d31444 100644 --- a/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp +++ b/llvm/lib/Transforms/Scalar/CodeGenPrepare.cpp @@ -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 diff --git a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp index 15625f9..73f53b7 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -636,7 +636,9 @@ struct StrToOpt : public LibCallOptimization { if (isa(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; diff --git a/llvm/lib/VMCore/Attributes.cpp b/llvm/lib/VMCore/Attributes.cpp index 88f20e9..90a7c7e 100644 --- a/llvm/lib/VMCore/Attributes.cpp +++ b/llvm/lib/VMCore/Attributes.cpp @@ -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 &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; } -- 2.7.4