From ed42e799dc42fdb0518eae7da36d9331ace4b33a Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 10 Oct 2012 06:13:42 +0000 Subject: [PATCH] Pass into the AttributeWithIndex::get method an ArrayRef of attribute enums. These are then created via the correct Attributes creation method. llvm-svn: 165607 --- llvm/include/llvm/Attributes.h | 39 ++++++++++++------ llvm/include/llvm/Function.h | 14 ++++--- llvm/lib/Transforms/Utils/BuildLibCalls.cpp | 64 +++++++++++++++-------------- llvm/utils/TableGen/IntrinsicEmitter.cpp | 62 ++++++++++++---------------- 4 files changed, 95 insertions(+), 84 deletions(-) diff --git a/llvm/include/llvm/Attributes.h b/llvm/include/llvm/Attributes.h index 1c27709..4825c97 100644 --- a/llvm/include/llvm/Attributes.h +++ b/llvm/include/llvm/Attributes.h @@ -97,18 +97,6 @@ DECLARE_LLVM_ATTRIBUTE(AddressSafety,1ULL<<32) ///< Address safety checking is o #undef DECLARE_LLVM_ATTRIBUTE -/// Note that uwtable is about the ABI or the user mandating an entry in the -/// unwind table. The nounwind attribute is about an exception passing by the -/// function. -/// In a theoretical system that uses tables for profiling and sjlj for -/// exceptions, they would be fully independent. In a normal system that -/// uses tables for both, the semantics are: -/// nil = Needs an entry because an exception might pass by. -/// nounwind = No need for an entry -/// uwtable = Needs an entry because the ABI says so and because -/// an exception might pass by. -/// uwtable + nounwind = Needs an entry because the ABI says so. - } // namespace Attribute /// AttributeImpl - The internal representation of the Attributes class. This is @@ -118,6 +106,20 @@ class AttributesImpl; /// Attributes - A bitset of attributes. class Attributes { public: + /// Note that uwtable is about the ABI or the user mandating an entry in the + /// unwind table. The nounwind attribute is about an exception passing by the + /// function. + /// + /// In a theoretical system that uses tables for profiling and sjlj for + /// exceptions, they would be fully independent. In a normal system that uses + /// tables for both, the semantics are: + /// + /// nil = Needs an entry because an exception might pass by. + /// nounwind = No need for an entry + /// uwtable = Needs an entry because the ABI says so and because + /// an exception might pass by. + /// uwtable + nounwind = Needs an entry because the ABI says so. + enum AttrVal { None = 0, ///< No attributes have been set AddressSafety = 1, ///< Address safety checking is on. @@ -375,6 +377,19 @@ struct AttributeWithIndex { ///< Index 0 is used for return value attributes. ///< Index ~0U is used for function attributes. + static AttributeWithIndex get(unsigned Idx, + ArrayRef Attrs) { + Attributes::Builder B; + + for (ArrayRef::iterator I = Attrs.begin(), + E = Attrs.end(); I != E; ++I) + B.addAttribute(*I); + + AttributeWithIndex P; + P.Index = Idx; + P.Attrs = Attributes::get(B); + return P; + } static AttributeWithIndex get(unsigned Idx, Attributes Attrs) { AttributeWithIndex P; P.Index = Idx; diff --git a/llvm/include/llvm/Function.h b/llvm/include/llvm/Function.h index 2781959..855c926 100644 --- a/llvm/include/llvm/Function.h +++ b/llvm/include/llvm/Function.h @@ -277,9 +277,10 @@ public: bool doesNotAlias(unsigned n) const { return getParamAttributes(n).hasAttribute(Attributes::NoAlias); } - void setDoesNotAlias(unsigned n, bool DoesNotAlias = true) { - if (DoesNotAlias) addAttribute(n, Attribute::NoAlias); - else removeAttribute(n, Attribute::NoAlias); + void setDoesNotAlias(unsigned n) { + Attributes::Builder B; + B.addAttribute(Attributes::NoAlias); + addAttribute(n, Attributes::get(B)); } /// @brief Determine if the parameter can be captured. @@ -287,9 +288,10 @@ public: bool doesNotCapture(unsigned n) const { return getParamAttributes(n).hasAttribute(Attributes::NoCapture); } - void setDoesNotCapture(unsigned n, bool DoesNotCapture = true) { - if (DoesNotCapture) addAttribute(n, Attribute::NoCapture); - else removeAttribute(n, Attribute::NoCapture); + void setDoesNotCapture(unsigned n) { + Attributes::Builder B; + B.addAttribute(Attributes::NoCapture); + addAttribute(n, Attributes::get(B)); } /// copyAttributesFrom - copy all additional attributes (those not needed to diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp index ad01f0b..26240d4d 100644 --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -41,9 +41,9 @@ Value *llvm::EmitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout *TD, Module *M = B.GetInsertBlock()->getParent()->getParent(); AttributeWithIndex AWI[2]; - AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture); - AWI[1] = AttributeWithIndex::get(~0u, Attribute::ReadOnly | - Attribute::NoUnwind); + AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture); + Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind }; + AWI[1] = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2)); LLVMContext &Context = B.GetInsertBlock()->getContext(); Constant *StrLen = M->getOrInsertFunction("strlen", AttrListPtr::get(AWI), @@ -67,9 +67,9 @@ Value *llvm::EmitStrNLen(Value *Ptr, Value *MaxLen, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getParent()->getParent(); AttributeWithIndex AWI[2]; - AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture); - AWI[1] = AttributeWithIndex::get(~0u, Attribute::ReadOnly | - Attribute::NoUnwind); + AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture); + Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind }; + AWI[1] = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2)); LLVMContext &Context = B.GetInsertBlock()->getContext(); Constant *StrNLen = M->getOrInsertFunction("strnlen", AttrListPtr::get(AWI), @@ -93,8 +93,9 @@ Value *llvm::EmitStrChr(Value *Ptr, char C, IRBuilder<> &B, return 0; Module *M = B.GetInsertBlock()->getParent()->getParent(); + Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind }; AttributeWithIndex AWI = - AttributeWithIndex::get(~0u, Attribute::ReadOnly | Attribute::NoUnwind); + AttributeWithIndex::get(~0u, ArrayRef(AVs, 2)); Type *I8Ptr = B.getInt8PtrTy(); Type *I32Ty = B.getInt32Ty(); @@ -116,10 +117,10 @@ Value *llvm::EmitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, Module *M = B.GetInsertBlock()->getParent()->getParent(); AttributeWithIndex AWI[3]; - AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture); - AWI[1] = AttributeWithIndex::get(2, Attribute::NoCapture); - AWI[2] = AttributeWithIndex::get(~0u, Attribute::ReadOnly | - Attribute::NoUnwind); + AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture); + AWI[1] = AttributeWithIndex::get(2, Attributes::NoCapture); + Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind }; + AWI[2] = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2)); LLVMContext &Context = B.GetInsertBlock()->getContext(); Value *StrNCmp = M->getOrInsertFunction("strncmp", AttrListPtr::get(AWI), @@ -146,8 +147,8 @@ Value *llvm::EmitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getParent()->getParent(); AttributeWithIndex AWI[2]; - AWI[0] = AttributeWithIndex::get(2, Attribute::NoCapture); - AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind); + AWI[0] = AttributeWithIndex::get(2, Attributes::NoCapture); + AWI[1] = AttributeWithIndex::get(~0u, Attributes::NoUnwind); Type *I8Ptr = B.getInt8PtrTy(); Value *StrCpy = M->getOrInsertFunction(Name, AttrListPtr::get(AWI), I8Ptr, I8Ptr, I8Ptr, NULL); @@ -168,8 +169,8 @@ Value *llvm::EmitStrNCpy(Value *Dst, Value *Src, Value *Len, Module *M = B.GetInsertBlock()->getParent()->getParent(); AttributeWithIndex AWI[2]; - AWI[0] = AttributeWithIndex::get(2, Attribute::NoCapture); - AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind); + AWI[0] = AttributeWithIndex::get(2, Attributes::NoCapture); + AWI[1] = AttributeWithIndex::get(~0u, Attributes::NoUnwind); Type *I8Ptr = B.getInt8PtrTy(); Value *StrNCpy = M->getOrInsertFunction(Name, AttrListPtr::get(AWI), I8Ptr, I8Ptr, I8Ptr, @@ -192,7 +193,7 @@ Value *llvm::EmitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, Module *M = B.GetInsertBlock()->getParent()->getParent(); AttributeWithIndex AWI; - AWI = AttributeWithIndex::get(~0u, Attribute::NoUnwind); + AWI = AttributeWithIndex::get(~0u, Attributes::NoUnwind); LLVMContext &Context = B.GetInsertBlock()->getContext(); Value *MemCpy = M->getOrInsertFunction("__memcpy_chk", AttrListPtr::get(AWI), @@ -219,7 +220,8 @@ Value *llvm::EmitMemChr(Value *Ptr, Value *Val, Module *M = B.GetInsertBlock()->getParent()->getParent(); AttributeWithIndex AWI; - AWI = AttributeWithIndex::get(~0u, Attribute::ReadOnly | Attribute::NoUnwind); + Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind }; + AWI = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2)); LLVMContext &Context = B.GetInsertBlock()->getContext(); Value *MemChr = M->getOrInsertFunction("memchr", AttrListPtr::get(AWI), B.getInt8PtrTy(), @@ -244,10 +246,10 @@ Value *llvm::EmitMemCmp(Value *Ptr1, Value *Ptr2, Module *M = B.GetInsertBlock()->getParent()->getParent(); AttributeWithIndex AWI[3]; - AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture); - AWI[1] = AttributeWithIndex::get(2, Attribute::NoCapture); - AWI[2] = AttributeWithIndex::get(~0u, Attribute::ReadOnly | - Attribute::NoUnwind); + AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture); + AWI[1] = AttributeWithIndex::get(2, Attributes::NoCapture); + Attributes::AttrVal AVs[2] = { Attributes::ReadOnly, Attributes::NoUnwind }; + AWI[2] = AttributeWithIndex::get(~0u, ArrayRef(AVs, 2)); LLVMContext &Context = B.GetInsertBlock()->getContext(); Value *MemCmp = M->getOrInsertFunction("memcmp", AttrListPtr::get(AWI), @@ -323,8 +325,8 @@ Value *llvm::EmitPutS(Value *Str, IRBuilder<> &B, const DataLayout *TD, Module *M = B.GetInsertBlock()->getParent()->getParent(); AttributeWithIndex AWI[2]; - AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture); - AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind); + AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture); + AWI[1] = AttributeWithIndex::get(~0u, Attributes::NoUnwind); Value *PutS = M->getOrInsertFunction("puts", AttrListPtr::get(AWI), B.getInt32Ty(), @@ -345,8 +347,8 @@ Value *llvm::EmitFPutC(Value *Char, Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getParent()->getParent(); AttributeWithIndex AWI[2]; - AWI[0] = AttributeWithIndex::get(2, Attribute::NoCapture); - AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind); + AWI[0] = AttributeWithIndex::get(2, Attributes::NoCapture); + AWI[1] = AttributeWithIndex::get(~0u, Attributes::NoUnwind); Constant *F; if (File->getType()->isPointerTy()) F = M->getOrInsertFunction("fputc", AttrListPtr::get(AWI), @@ -376,9 +378,9 @@ Value *llvm::EmitFPutS(Value *Str, Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getParent()->getParent(); AttributeWithIndex AWI[3]; - AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture); - AWI[1] = AttributeWithIndex::get(2, Attribute::NoCapture); - AWI[2] = AttributeWithIndex::get(~0u, Attribute::NoUnwind); + AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture); + AWI[1] = AttributeWithIndex::get(2, Attributes::NoCapture); + AWI[2] = AttributeWithIndex::get(~0u, Attributes::NoUnwind); StringRef FPutsName = TLI->getName(LibFunc::fputs); Constant *F; if (File->getType()->isPointerTy()) @@ -407,9 +409,9 @@ Value *llvm::EmitFWrite(Value *Ptr, Value *Size, Value *File, Module *M = B.GetInsertBlock()->getParent()->getParent(); AttributeWithIndex AWI[3]; - AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture); - AWI[1] = AttributeWithIndex::get(4, Attribute::NoCapture); - AWI[2] = AttributeWithIndex::get(~0u, Attribute::NoUnwind); + AWI[0] = AttributeWithIndex::get(1, Attributes::NoCapture); + AWI[1] = AttributeWithIndex::get(4, Attributes::NoCapture); + AWI[2] = AttributeWithIndex::get(~0u, Attributes::NoUnwind); LLVMContext &Context = B.GetInsertBlock()->getContext(); StringRef FWriteName = TLI->getName(LibFunc::fwrite); Constant *F; diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp index 155d1ab..080e711 100644 --- a/llvm/utils/TableGen/IntrinsicEmitter.cpp +++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp @@ -547,6 +547,7 @@ EmitAttributes(const std::vector &Ints, raw_ostream &OS) { OS << " AttributeWithIndex AWI[" << maxArgAttrs+1 << "];\n"; OS << " unsigned NumAttrs = 0;\n"; OS << " if (id != 0) {\n"; + OS << " SmallVector AttrVec;\n"; OS << " switch(IntrinsicsToAttributesMap[id - "; if (TargetOnly) OS << "Intrinsic::num_intrinsics"; @@ -564,58 +565,49 @@ EmitAttributes(const std::vector &Ints, raw_ostream &OS) { unsigned numAttrs = 0; // The argument attributes are alreadys sorted by argument index. - for (unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size(); ai != ae;) { - unsigned argNo = intrinsic.ArgumentAttributes[ai].first; + unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size(); + if (ae) { + while (ai != ae) { + unsigned argNo = intrinsic.ArgumentAttributes[ai].first; - OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(" - << argNo+1 << ", "; + OS << " AttrVec.clear();\n"; - bool moreThanOne = false; + do { + switch (intrinsic.ArgumentAttributes[ai].second) { + case CodeGenIntrinsic::NoCapture: + OS << " AttrVec.push_back(Attributes::NoCapture);\n"; + break; + } - do { - if (moreThanOne) OS << '|'; + ++ai; + } while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo); - switch (intrinsic.ArgumentAttributes[ai].second) { - case CodeGenIntrinsic::NoCapture: - OS << "Attribute::NoCapture"; - break; - } - - ++ai; - moreThanOne = true; - } while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo); - - OS << ");\n"; + OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(" + << argNo+1 << ", AttrVec);\n"; + } } ModRefKind modRef = getModRefKind(intrinsic); if (!intrinsic.canThrow || modRef || intrinsic.isNoReturn) { - OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(~0, "; - bool Emitted = false; - if (!intrinsic.canThrow) { - OS << "Attribute::NoUnwind"; - Emitted = true; - } - - if (intrinsic.isNoReturn) { - if (Emitted) OS << '|'; - OS << "Attribute::NoReturn"; - Emitted = true; - } + OS << " AttrVec.clear();\n"; + + if (!intrinsic.canThrow) + OS << " AttrVec.push_back(Attributes::NoUnwind);\n"; + if (intrinsic.isNoReturn) + OS << " AttrVec.push_back(Attributes::NoReturn);\n"; switch (modRef) { case MRK_none: break; case MRK_readonly: - if (Emitted) OS << '|'; - OS << "Attribute::ReadOnly"; + OS << " AttrVec.push_back(Attributes::ReadOnly);\n"; break; case MRK_readnone: - if (Emitted) OS << '|'; - OS << "Attribute::ReadNone"; + OS << " AttrVec.push_back(Attributes::ReadNone);\n"; break; } - OS << ");\n"; + OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(~0, " + << "AttrVec);\n"; } if (numAttrs) { -- 2.7.4