diff options
author | Bill Wendling <isanbard@gmail.com> | 2013-01-22 21:15:51 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2013-01-22 21:15:51 +0000 |
commit | defaca00b8087d452df2b783250a48a32658a910 (patch) | |
tree | dcc4e29343864e54bcfd33035512ca7d6e2bef74 /lib/IR | |
parent | 5de048ec30f9ef9f56c89f9fdb50022beca6ae88 (diff) | |
download | external_llvm-defaca00b8087d452df2b783250a48a32658a910.zip external_llvm-defaca00b8087d452df2b783250a48a32658a910.tar.gz external_llvm-defaca00b8087d452df2b783250a48a32658a910.tar.bz2 |
More encapsulation work.
Use the AttributeSet when we're talking about more than one attribute. Add a
function that adds a single attribute. No functionality change intended.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173196 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r-- | lib/IR/Attributes.cpp | 45 | ||||
-rw-r--r-- | lib/IR/Core.cpp | 16 | ||||
-rw-r--r-- | lib/IR/Function.cpp | 4 | ||||
-rw-r--r-- | lib/IR/Instructions.cpp | 8 |
4 files changed, 36 insertions, 37 deletions
diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp index 420b2e8..c67b1f3 100644 --- a/lib/IR/Attributes.cpp +++ b/lib/IR/Attributes.cpp @@ -150,7 +150,7 @@ uint64_t Attribute::encodeLLVMAttributesForBitcode(Attribute Attrs) { /// the LLVM attributes that have been decoded from the given integer. This /// function must stay in sync with 'encodeLLVMAttributesForBitcode'. Attribute Attribute::decodeLLVMAttributesForBitcode(LLVMContext &C, - uint64_t EncodedAttrs) { + uint64_t EncodedAttrs) { // The alignment is stored as a 16-bit raw value from bits 31--16. We shift // the bits above 31 down by 11 bits. unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16; @@ -318,32 +318,29 @@ AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) { I = Attribute::AttrKind(I + 1)) { if (uint64_t A = (Val & AttributeImpl::getAttrMask(I))) { Attrs.insert(I); - + if (I == Attribute::Alignment) Alignment = 1ULL << ((A >> 16) - 1); else if (I == Attribute::StackAlignment) StackAlignment = 1ULL << ((A >> 26)-1); } } - + return *this; } -AttrBuilder &AttrBuilder::addAttributes(const Attribute &A) { - uint64_t Mask = A.Raw(); +AttrBuilder &AttrBuilder::addAttributes(const Attribute &Attr) { + uint64_t Mask = Attr.Raw(); for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds; - I = Attribute::AttrKind(I + 1)) { - if (uint64_t A = (Mask & AttributeImpl::getAttrMask(I))) { + I = Attribute::AttrKind(I + 1)) + if ((Mask & AttributeImpl::getAttrMask(I)) != 0) Attrs.insert(I); - if (I == Attribute::Alignment) - Alignment = 1ULL << ((A >> 16) - 1); - else if (I == Attribute::StackAlignment) - StackAlignment = 1ULL << ((A >> 26)-1); - } - } - + if (Attr.getAlignment()) + Alignment = Attr.getAlignment(); + if (Attr.getStackAlignment()) + StackAlignment = Attr.getStackAlignment(); return *this; } @@ -601,18 +598,7 @@ AttributeSet AttributeSet::get(LLVMContext &C, unsigned Idx, AttrBuilder &B) { // AttributeWithIndexes that then are used to create the AttributeSet. if (!B.hasAttributes()) return AttributeSet(); - - uint64_t Mask = 0; - - for (AttrBuilder::iterator I = B.begin(), E = B.end(); I != E; ++I) - Mask |= AttributeImpl::getAttrMask(*I); - - Attribute A = Attribute::decodeLLVMAttributesForBitcode(C, Mask); - if (B.getAlignment()) - A.setAlignment(B.getAlignment()); - if (B.getStackAlignment()) - A.setStackAlignment(B.getStackAlignment()); - return get(C, AttributeWithIndex::get(Idx, A)); + return get(C, AttributeWithIndex::get(Idx, Attribute::get(C, B))); } //===----------------------------------------------------------------------===// @@ -665,8 +651,6 @@ uint64_t AttributeSet::Raw(unsigned Index) const { } /// getAttributes - The attributes for the specified index are returned. -/// Attributes for the result are denoted with Idx = 0. Function attributes are -/// denoted with Idx = ~0. Attribute AttributeSet::getAttributes(unsigned Idx) const { if (AttrList == 0) return Attribute(); @@ -691,6 +675,11 @@ bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const { return false; } +AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Idx, + Attribute::AttrKind Attr) const { + return addAttr(C, Idx, Attribute::get(C, Attr)); +} + AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Idx, AttributeSet Attrs) const { return addAttr(C, Idx, Attrs.getAttributes(Idx)); diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 12cb971..e72eb69 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -1383,8 +1383,9 @@ void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { const AttributeSet PAL = Func->getAttributes(); AttrBuilder B(PA); const AttributeSet PALnew = - PAL.addAttr(Func->getContext(), AttributeSet::FunctionIndex, - Attribute::get(Func->getContext(), B)); + PAL.addFnAttributes(Func->getContext(), + AttributeSet::get(Func->getContext(), + AttributeSet::FunctionIndex, B)); Func->setAttributes(PALnew); } @@ -1676,8 +1677,9 @@ void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, CallSite Call = CallSite(unwrap<Instruction>(Instr)); AttrBuilder B(PA); Call.setAttributes( - Call.getAttributes().addAttr(Call->getContext(), index, - Attribute::get(Call->getContext(), B))); + Call.getAttributes().addAttributes(Call->getContext(), index, + AttributeSet::get(Call->getContext(), + index, B))); } void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, @@ -1694,8 +1696,10 @@ void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, CallSite Call = CallSite(unwrap<Instruction>(Instr)); AttrBuilder B; B.addAlignmentAttr(align); - Call.setAttributes(Call.getAttributes().addAttr(Call->getContext(), index, - Attribute::get(Call->getContext(), B))); + Call.setAttributes(Call.getAttributes() + .addAttributes(Call->getContext(), index, + AttributeSet::get(Call->getContext(), + index, B))); } /*--.. Operations on call instructions (only) ..............................--*/ diff --git a/lib/IR/Function.cpp b/lib/IR/Function.cpp index cd35aff..6a5e616 100644 --- a/lib/IR/Function.cpp +++ b/lib/IR/Function.cpp @@ -250,7 +250,9 @@ void Function::dropAllReferences() { void Function::addAttribute(unsigned i, Attribute attr) { AttributeSet PAL = getAttributes(); - PAL = PAL.addAttr(getContext(), i, attr); + AttrBuilder B(attr); + PAL = PAL.addAttributes(getContext(), i, + AttributeSet::get(getContext(), i, B)); setAttributes(PAL); } diff --git a/lib/IR/Instructions.cpp b/lib/IR/Instructions.cpp index aba0fc9..8597d5c 100644 --- a/lib/IR/Instructions.cpp +++ b/lib/IR/Instructions.cpp @@ -333,7 +333,9 @@ CallInst::CallInst(const CallInst &CI) void CallInst::addAttribute(unsigned i, Attribute attr) { AttributeSet PAL = getAttributes(); - PAL = PAL.addAttr(getContext(), i, attr); + AttrBuilder B(attr); + PAL = PAL.addAttributes(getContext(), i, + AttributeSet::get(getContext(), i, B)); setAttributes(PAL); } @@ -589,7 +591,9 @@ bool InvokeInst::paramHasAttr(unsigned i, Attribute::AttrKind A) const { void InvokeInst::addAttribute(unsigned i, Attribute attr) { AttributeSet PAL = getAttributes(); - PAL = PAL.addAttr(getContext(), i, attr); + AttrBuilder B(attr); + PAL = PAL.addAttributes(getContext(), i, + AttributeSet::get(getContext(), i, B)); setAttributes(PAL); } |