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
This commit is contained in:
Bill Wendling
2013-01-22 21:15:51 +00:00
parent 5de048ec30
commit defaca00b8
7 changed files with 69 additions and 63 deletions

View File

@ -212,6 +212,11 @@ private:
/// for the result are denoted with Idx = 0. /// for the result are denoted with Idx = 0.
Attribute getAttributes(unsigned Idx) const; Attribute getAttributes(unsigned Idx) const;
/// \brief Add the specified attribute at the specified index to this
/// attribute list. Since attribute lists are immutable, this returns the new
/// list.
AttributeSet addAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const;
explicit AttributeSet(AttributeSetImpl *LI) : AttrList(LI) {} explicit AttributeSet(AttributeSetImpl *LI) : AttrList(LI) {}
public: public:
AttributeSet() : AttrList(0) {} AttributeSet() : AttrList(0) {}
@ -226,10 +231,10 @@ public:
static AttributeSet get(LLVMContext &C, ArrayRef<AttributeWithIndex> Attrs); static AttributeSet get(LLVMContext &C, ArrayRef<AttributeWithIndex> Attrs);
static AttributeSet get(LLVMContext &C, unsigned Idx, AttrBuilder &B); static AttributeSet get(LLVMContext &C, unsigned Idx, AttrBuilder &B);
/// \brief Add the specified attribute at the specified index to this /// \brief Add an attribute to the attribute set at the given index. Since
/// attribute list. Since attribute lists are immutable, this returns the new /// attribute sets are immutable, this returns a new set.
/// list. AttributeSet addAttribute(LLVMContext &C, unsigned Idx,
AttributeSet addAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const; Attribute::AttrKind Attr) const;
/// \brief Add attributes to the attribute set at the given index. Since /// \brief Add attributes to the attribute set at the given index. Since
/// attribute sets are immutable, this returns a new set. /// attribute sets are immutable, this returns a new set.

View File

@ -329,21 +329,18 @@ AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) {
return *this; return *this;
} }
AttrBuilder &AttrBuilder::addAttributes(const Attribute &A) { AttrBuilder &AttrBuilder::addAttributes(const Attribute &Attr) {
uint64_t Mask = A.Raw(); uint64_t Mask = Attr.Raw();
for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds; for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds;
I = Attribute::AttrKind(I + 1)) { I = Attribute::AttrKind(I + 1))
if (uint64_t A = (Mask & AttributeImpl::getAttrMask(I))) { if ((Mask & AttributeImpl::getAttrMask(I)) != 0)
Attrs.insert(I); Attrs.insert(I);
if (I == Attribute::Alignment) if (Attr.getAlignment())
Alignment = 1ULL << ((A >> 16) - 1); Alignment = Attr.getAlignment();
else if (I == Attribute::StackAlignment) if (Attr.getStackAlignment())
StackAlignment = 1ULL << ((A >> 26)-1); StackAlignment = Attr.getStackAlignment();
}
}
return *this; return *this;
} }
@ -601,18 +598,7 @@ AttributeSet AttributeSet::get(LLVMContext &C, unsigned Idx, AttrBuilder &B) {
// AttributeWithIndexes that then are used to create the AttributeSet. // AttributeWithIndexes that then are used to create the AttributeSet.
if (!B.hasAttributes()) if (!B.hasAttributes())
return AttributeSet(); return AttributeSet();
return get(C, AttributeWithIndex::get(Idx, Attribute::get(C, B)));
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));
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -665,8 +651,6 @@ uint64_t AttributeSet::Raw(unsigned Index) const {
} }
/// getAttributes - The attributes for the specified index are returned. /// 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 { Attribute AttributeSet::getAttributes(unsigned Idx) const {
if (AttrList == 0) return Attribute(); if (AttrList == 0) return Attribute();
@ -691,6 +675,11 @@ bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const {
return false; 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 AttributeSet::addAttributes(LLVMContext &C, unsigned Idx,
AttributeSet Attrs) const { AttributeSet Attrs) const {
return addAttr(C, Idx, Attrs.getAttributes(Idx)); return addAttr(C, Idx, Attrs.getAttributes(Idx));

View File

@ -1383,8 +1383,9 @@ void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
const AttributeSet PAL = Func->getAttributes(); const AttributeSet PAL = Func->getAttributes();
AttrBuilder B(PA); AttrBuilder B(PA);
const AttributeSet PALnew = const AttributeSet PALnew =
PAL.addAttr(Func->getContext(), AttributeSet::FunctionIndex, PAL.addFnAttributes(Func->getContext(),
Attribute::get(Func->getContext(), B)); AttributeSet::get(Func->getContext(),
AttributeSet::FunctionIndex, B));
Func->setAttributes(PALnew); Func->setAttributes(PALnew);
} }
@ -1676,8 +1677,9 @@ void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index,
CallSite Call = CallSite(unwrap<Instruction>(Instr)); CallSite Call = CallSite(unwrap<Instruction>(Instr));
AttrBuilder B(PA); AttrBuilder B(PA);
Call.setAttributes( Call.setAttributes(
Call.getAttributes().addAttr(Call->getContext(), index, Call.getAttributes().addAttributes(Call->getContext(), index,
Attribute::get(Call->getContext(), B))); AttributeSet::get(Call->getContext(),
index, B)));
} }
void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
@ -1694,8 +1696,10 @@ void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
CallSite Call = CallSite(unwrap<Instruction>(Instr)); CallSite Call = CallSite(unwrap<Instruction>(Instr));
AttrBuilder B; AttrBuilder B;
B.addAlignmentAttr(align); B.addAlignmentAttr(align);
Call.setAttributes(Call.getAttributes().addAttr(Call->getContext(), index, Call.setAttributes(Call.getAttributes()
Attribute::get(Call->getContext(), B))); .addAttributes(Call->getContext(), index,
AttributeSet::get(Call->getContext(),
index, B)));
} }
/*--.. Operations on call instructions (only) ..............................--*/ /*--.. Operations on call instructions (only) ..............................--*/

View File

@ -250,7 +250,9 @@ void Function::dropAllReferences() {
void Function::addAttribute(unsigned i, Attribute attr) { void Function::addAttribute(unsigned i, Attribute attr) {
AttributeSet PAL = getAttributes(); AttributeSet PAL = getAttributes();
PAL = PAL.addAttr(getContext(), i, attr); AttrBuilder B(attr);
PAL = PAL.addAttributes(getContext(), i,
AttributeSet::get(getContext(), i, B));
setAttributes(PAL); setAttributes(PAL);
} }

View File

@ -333,7 +333,9 @@ CallInst::CallInst(const CallInst &CI)
void CallInst::addAttribute(unsigned i, Attribute attr) { void CallInst::addAttribute(unsigned i, Attribute attr) {
AttributeSet PAL = getAttributes(); AttributeSet PAL = getAttributes();
PAL = PAL.addAttr(getContext(), i, attr); AttrBuilder B(attr);
PAL = PAL.addAttributes(getContext(), i,
AttributeSet::get(getContext(), i, B));
setAttributes(PAL); setAttributes(PAL);
} }
@ -589,7 +591,9 @@ bool InvokeInst::paramHasAttr(unsigned i, Attribute::AttrKind A) const {
void InvokeInst::addAttribute(unsigned i, Attribute attr) { void InvokeInst::addAttribute(unsigned i, Attribute attr) {
AttributeSet PAL = getAttributes(); AttributeSet PAL = getAttributes();
PAL = PAL.addAttr(getContext(), i, attr); AttrBuilder B(attr);
PAL = PAL.addAttributes(getContext(), i,
AttributeSet::get(getContext(), i, B));
setAttributes(PAL); setAttributes(PAL);
} }

View File

@ -146,8 +146,10 @@ bool PruneEH::runOnSCC(CallGraphSCC &SCC) {
Function *F = (*I)->getFunction(); Function *F = (*I)->getFunction();
const AttributeSet &PAL = F->getAttributes(); const AttributeSet &PAL = F->getAttributes();
const AttributeSet &NPAL = PAL.addAttr(F->getContext(), ~0, const AttributeSet &NPAL =
Attribute::get(F->getContext(), PAL.addFnAttributes(F->getContext(),
AttributeSet::get(F->getContext(),
AttributeSet::FunctionIndex,
NewAttributes)); NewAttributes));
if (PAL != NPAL) { if (PAL != NPAL) {
MadeChange = true; MadeChange = true;

View File

@ -1914,8 +1914,8 @@ Constant *ObjCARCOpt::getRetainRVCallee(Module *M) {
Type *Params[] = { I8X }; Type *Params[] = { I8X };
FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false); FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false);
AttributeSet Attribute = AttributeSet Attribute =
AttributeSet().addAttr(M->getContext(), AttributeSet::FunctionIndex, AttributeSet().addAttribute(M->getContext(), AttributeSet::FunctionIndex,
Attribute::get(C, Attribute::NoUnwind)); Attribute::NoUnwind);
RetainRVCallee = RetainRVCallee =
M->getOrInsertFunction("objc_retainAutoreleasedReturnValue", FTy, M->getOrInsertFunction("objc_retainAutoreleasedReturnValue", FTy,
Attribute); Attribute);
@ -1930,8 +1930,8 @@ Constant *ObjCARCOpt::getAutoreleaseRVCallee(Module *M) {
Type *Params[] = { I8X }; Type *Params[] = { I8X };
FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false); FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false);
AttributeSet Attribute = AttributeSet Attribute =
AttributeSet().addAttr(M->getContext(), AttributeSet::FunctionIndex, AttributeSet().addAttribute(M->getContext(), AttributeSet::FunctionIndex,
Attribute::get(C, Attribute::NoUnwind)); Attribute::NoUnwind);
AutoreleaseRVCallee = AutoreleaseRVCallee =
M->getOrInsertFunction("objc_autoreleaseReturnValue", FTy, M->getOrInsertFunction("objc_autoreleaseReturnValue", FTy,
Attribute); Attribute);
@ -1944,8 +1944,8 @@ Constant *ObjCARCOpt::getReleaseCallee(Module *M) {
LLVMContext &C = M->getContext(); LLVMContext &C = M->getContext();
Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) }; Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) };
AttributeSet Attribute = AttributeSet Attribute =
AttributeSet().addAttr(M->getContext(), AttributeSet::FunctionIndex, AttributeSet().addAttribute(M->getContext(), AttributeSet::FunctionIndex,
Attribute::get(C, Attribute::NoUnwind)); Attribute::NoUnwind);
ReleaseCallee = ReleaseCallee =
M->getOrInsertFunction( M->getOrInsertFunction(
"objc_release", "objc_release",
@ -1960,8 +1960,8 @@ Constant *ObjCARCOpt::getRetainCallee(Module *M) {
LLVMContext &C = M->getContext(); LLVMContext &C = M->getContext();
Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) }; Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) };
AttributeSet Attribute = AttributeSet Attribute =
AttributeSet().addAttr(M->getContext(), AttributeSet::FunctionIndex, AttributeSet().addAttribute(M->getContext(), AttributeSet::FunctionIndex,
Attribute::get(C, Attribute::NoUnwind)); Attribute::NoUnwind);
RetainCallee = RetainCallee =
M->getOrInsertFunction( M->getOrInsertFunction(
"objc_retain", "objc_retain",
@ -1991,8 +1991,8 @@ Constant *ObjCARCOpt::getAutoreleaseCallee(Module *M) {
LLVMContext &C = M->getContext(); LLVMContext &C = M->getContext();
Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) }; Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) };
AttributeSet Attribute = AttributeSet Attribute =
AttributeSet().addAttr(M->getContext(), AttributeSet::FunctionIndex, AttributeSet().addAttribute(M->getContext(), AttributeSet::FunctionIndex,
Attribute::get(C, Attribute::NoUnwind)); Attribute::NoUnwind);
AutoreleaseCallee = AutoreleaseCallee =
M->getOrInsertFunction( M->getOrInsertFunction(
"objc_autorelease", "objc_autorelease",
@ -4105,16 +4105,16 @@ Constant *ObjCARCContract::getStoreStrongCallee(Module *M) {
Type *I8XX = PointerType::getUnqual(I8X); Type *I8XX = PointerType::getUnqual(I8X);
Type *Params[] = { I8XX, I8X }; Type *Params[] = { I8XX, I8X };
AttributeSet Attribute = AttributeSet() AttributeSet Attr = AttributeSet()
.addAttr(M->getContext(), AttributeSet::FunctionIndex, .addAttribute(M->getContext(), AttributeSet::FunctionIndex,
Attribute::get(C, Attribute::NoUnwind)) Attribute::NoUnwind)
.addAttr(M->getContext(), 1, Attribute::get(C, Attribute::NoCapture)); .addAttribute(M->getContext(), 1, Attribute::NoCapture);
StoreStrongCallee = StoreStrongCallee =
M->getOrInsertFunction( M->getOrInsertFunction(
"objc_storeStrong", "objc_storeStrong",
FunctionType::get(Type::getVoidTy(C), Params, /*isVarArg=*/false), FunctionType::get(Type::getVoidTy(C), Params, /*isVarArg=*/false),
Attribute); Attr);
} }
return StoreStrongCallee; return StoreStrongCallee;
} }
@ -4126,8 +4126,8 @@ Constant *ObjCARCContract::getRetainAutoreleaseCallee(Module *M) {
Type *Params[] = { I8X }; Type *Params[] = { I8X };
FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false); FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false);
AttributeSet Attribute = AttributeSet Attribute =
AttributeSet().addAttr(M->getContext(), AttributeSet::FunctionIndex, AttributeSet().addAttribute(M->getContext(), AttributeSet::FunctionIndex,
Attribute::get(C, Attribute::NoUnwind)); Attribute::NoUnwind);
RetainAutoreleaseCallee = RetainAutoreleaseCallee =
M->getOrInsertFunction("objc_retainAutorelease", FTy, Attribute); M->getOrInsertFunction("objc_retainAutorelease", FTy, Attribute);
} }
@ -4141,8 +4141,8 @@ Constant *ObjCARCContract::getRetainAutoreleaseRVCallee(Module *M) {
Type *Params[] = { I8X }; Type *Params[] = { I8X };
FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false); FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false);
AttributeSet Attribute = AttributeSet Attribute =
AttributeSet().addAttr(M->getContext(), AttributeSet::FunctionIndex, AttributeSet().addAttribute(M->getContext(), AttributeSet::FunctionIndex,
Attribute::get(C, Attribute::NoUnwind)); Attribute::NoUnwind);
RetainAutoreleaseRVCallee = RetainAutoreleaseRVCallee =
M->getOrInsertFunction("objc_retainAutoreleaseReturnValue", FTy, M->getOrInsertFunction("objc_retainAutoreleaseReturnValue", FTy,
Attribute); Attribute);