Use the AttributeSet when removing multiple attributes. Use Attribute::AttrKind

when removing one attribute. This further encapsulates the use of the attributes.

llvm-svn: 173214
This commit is contained in:
Bill Wendling 2013-01-23 00:45:55 +00:00
parent f8317679cb
commit 430fa9bfb3
9 changed files with 59 additions and 23 deletions

View File

@ -217,6 +217,11 @@ private:
/// list. /// list.
AttributeSet addAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const; AttributeSet addAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const;
/// \brief Remove the specified attribute at the specified index from this
/// attribute list. Since attribute lists are immutable, this returns the new
/// list.
AttributeSet removeAttr(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) {}
@ -254,9 +259,16 @@ public:
} }
/// \brief Remove the specified attribute at the specified index from this /// \brief Remove the specified attribute at the specified index from this
/// attribute list. Since attribute lists are immutable, this returns the new /// attribute list. Since attribute lists are immutable, this returns the new
/// list. /// list.
AttributeSet removeAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const; AttributeSet removeAttribute(LLVMContext &C, unsigned Idx,
Attribute::AttrKind Attr) const;
/// \brief Remove the specified attributes at the specified index from this
/// attribute list. Since attribute lists are immutable, this returns the new
/// list.
AttributeSet removeAttributes(LLVMContext &C, unsigned Idx,
AttributeSet Attrs) const;
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
// Attribute List Accessors // Attribute List Accessors

View File

@ -189,7 +189,7 @@ public:
void addAttributes(unsigned i, AttributeSet attrs); void addAttributes(unsigned i, AttributeSet attrs);
/// @brief removes the attributes from the list of attributes. /// @brief removes the attributes from the list of attributes.
void removeAttribute(unsigned i, Attribute attr); void removeAttributes(unsigned i, AttributeSet attr);
/// @brief Extract the alignment for a call or parameter (0=unknown). /// @brief Extract the alignment for a call or parameter (0=unknown).
unsigned getParamAlignment(unsigned i) const { unsigned getParamAlignment(unsigned i) const {

View File

@ -730,6 +730,16 @@ AttributeSet AttributeSet::addAttr(LLVMContext &C, unsigned Idx,
return get(C, NewAttrList); return get(C, NewAttrList);
} }
AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Idx,
Attribute::AttrKind Attr) const {
return removeAttr(C, Idx, Attribute::get(C, Attr));
}
AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Idx,
AttributeSet Attrs) const {
return removeAttr(C, Idx, Attrs.getAttributes(Idx));
}
AttributeSet AttributeSet::removeAttr(LLVMContext &C, unsigned Idx, AttributeSet AttributeSet::removeAttr(LLVMContext &C, unsigned Idx,
Attribute Attrs) const { Attribute Attrs) const {
#ifndef NDEBUG #ifndef NDEBUG

View File

@ -1394,8 +1394,9 @@ void LLVMRemoveFunctionAttr(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.removeAttr(Func->getContext(), AttributeSet::FunctionIndex, PAL.removeAttributes(Func->getContext(), AttributeSet::FunctionIndex,
Attribute::get(Func->getContext(), B)); AttributeSet::get(Func->getContext(),
AttributeSet::FunctionIndex, B));
Func->setAttributes(PALnew); Func->setAttributes(PALnew);
} }
@ -1686,9 +1687,10 @@ void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
LLVMAttribute PA) { LLVMAttribute PA) {
CallSite Call = CallSite(unwrap<Instruction>(Instr)); CallSite Call = CallSite(unwrap<Instruction>(Instr));
AttrBuilder B(PA); AttrBuilder B(PA);
Call.setAttributes( Call.setAttributes(Call.getAttributes()
Call.getAttributes().removeAttr(Call->getContext(), index, .removeAttributes(Call->getContext(), index,
Attribute::get(Call->getContext(), B))); AttributeSet::get(Call->getContext(),
index, B)));
} }
void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,

View File

@ -133,7 +133,10 @@ void Argument::addAttr(Attribute attr) {
/// removeAttr - Remove a Attribute from an argument /// removeAttr - Remove a Attribute from an argument
void Argument::removeAttr(Attribute attr) { void Argument::removeAttr(Attribute attr) {
getParent()->removeAttribute(getArgNo() + 1, attr); AttrBuilder B(attr);
getParent()->removeAttributes(getArgNo() + 1,
AttributeSet::get(getParent()->getContext(),
getArgNo() + 1, B));
} }
@ -263,9 +266,9 @@ void Function::addAttributes(unsigned i, AttributeSet attrs) {
setAttributes(PAL); setAttributes(PAL);
} }
void Function::removeAttribute(unsigned i, Attribute attrs) { void Function::removeAttributes(unsigned i, AttributeSet attrs) {
AttributeSet PAL = getAttributes(); AttributeSet PAL = getAttributes();
PAL = PAL.removeAttr(getContext(), i, attrs); PAL = PAL.removeAttributes(getContext(), i, attrs);
setAttributes(PAL); setAttributes(PAL);
} }

View File

@ -334,14 +334,18 @@ 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();
AttrBuilder B(attr); AttrBuilder B(attr);
PAL = PAL.addAttributes(getContext(), i, LLVMContext &Context = getContext();
AttributeSet::get(getContext(), i, B)); PAL = PAL.addAttributes(Context, i,
AttributeSet::get(Context, i, B));
setAttributes(PAL); setAttributes(PAL);
} }
void CallInst::removeAttribute(unsigned i, Attribute attr) { void CallInst::removeAttribute(unsigned i, Attribute attr) {
AttributeSet PAL = getAttributes(); AttributeSet PAL = getAttributes();
PAL = PAL.removeAttr(getContext(), i, attr); AttrBuilder B(attr);
LLVMContext &Context = getContext();
PAL = PAL.removeAttributes(Context, i,
AttributeSet::get(Context, i, B));
setAttributes(PAL); setAttributes(PAL);
} }
@ -599,7 +603,9 @@ void InvokeInst::addAttribute(unsigned i, Attribute attr) {
void InvokeInst::removeAttribute(unsigned i, Attribute attr) { void InvokeInst::removeAttribute(unsigned i, Attribute attr) {
AttributeSet PAL = getAttributes(); AttributeSet PAL = getAttributes();
PAL = PAL.removeAttr(getContext(), i, attr); AttrBuilder B(attr);
PAL = PAL.removeAttributes(getContext(), i,
AttributeSet::get(getContext(), i, B));
setAttributes(PAL); setAttributes(PAL);
} }

View File

@ -215,8 +215,9 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
AttrBuilder B; AttrBuilder B;
B.addAttribute(Attribute::ReadOnly) B.addAttribute(Attribute::ReadOnly)
.addAttribute(Attribute::ReadNone); .addAttribute(Attribute::ReadNone);
F->removeAttribute(AttributeSet::FunctionIndex, F->removeAttributes(AttributeSet::FunctionIndex,
Attribute::get(F->getContext(), B)); AttributeSet::get(F->getContext(),
AttributeSet::FunctionIndex, B));
// Add in the new attribute. // Add in the new attribute.
F->addAttribute(AttributeSet::FunctionIndex, F->addAttribute(AttributeSet::FunctionIndex,

View File

@ -2072,8 +2072,7 @@ static AttributeSet StripNest(LLVMContext &C, const AttributeSet &Attrs) {
continue; continue;
// There can be only one. // There can be only one.
return Attrs.removeAttr(C, Attrs.getSlot(i).Index, return Attrs.removeAttribute(C, Attrs.getSlot(i).Index, Attribute::Nest);
Attribute::get(C, Attribute::Nest));
} }
return Attrs; return Attrs;

View File

@ -1461,8 +1461,10 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
AttrBuilder B; AttrBuilder B;
B.addAttribute(Attribute::ReadOnly) B.addAttribute(Attribute::ReadOnly)
.addAttribute(Attribute::ReadNone); .addAttribute(Attribute::ReadNone);
Func->removeAttribute(AttributeSet::FunctionIndex, Func->removeAttributes(AttributeSet::FunctionIndex,
Attribute::get(Func->getContext(), B)); AttributeSet::get(Func->getContext(),
AttributeSet::FunctionIndex,
B));
} }
} }
IRBuilder<> IRB(&I); IRBuilder<> IRB(&I);
@ -1853,8 +1855,9 @@ bool MemorySanitizer::runOnFunction(Function &F) {
AttrBuilder B; AttrBuilder B;
B.addAttribute(Attribute::ReadOnly) B.addAttribute(Attribute::ReadOnly)
.addAttribute(Attribute::ReadNone); .addAttribute(Attribute::ReadNone);
F.removeAttribute(AttributeSet::FunctionIndex, F.removeAttributes(AttributeSet::FunctionIndex,
Attribute::get(F.getContext(), B)); AttributeSet::get(F.getContext(),
AttributeSet::FunctionIndex, B));
return Visitor.runOnFunction(); return Visitor.runOnFunction();
} }