Push some more methods down to hide the use of the Attribute class.

Because the Attribute class is going to stop representing a collection of
attributes, limit the use of it as an aggregate in favor of using AttributeSet.
This replaces some of the uses for querying the function attributes.

llvm-svn: 172844
This commit is contained in:
Bill Wendling 2013-01-18 21:11:39 +00:00
parent 8bee90d5f3
commit 7754389526
7 changed files with 78 additions and 39 deletions

View File

@ -261,6 +261,10 @@ public:
/// list. /// list.
AttributeSet addAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const; AttributeSet addAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const;
/// \brief Add function attributes to this attribute set. Since attribute sets
/// are immutable, this returns a new set.
AttributeSet addFnAttributes(LLVMContext &C, AttributeSet Attrs) const;
/// \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.
@ -286,9 +290,7 @@ public:
} }
/// \brief Return the alignment for the specified function parameter. /// \brief Return the alignment for the specified function parameter.
unsigned getParamAlignment(unsigned Idx) const { unsigned getParamAlignment(unsigned Idx) const;
return getAttributes(Idx).getAlignment();
}
/// \brief Return true if the attribute exists at the given index. /// \brief Return true if the attribute exists at the given index.
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const; bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const;

View File

@ -255,9 +255,19 @@ AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Idx)
assert(AWI && "Cannot find index in attribute set!"); assert(AWI && "Cannot find index in attribute set!");
/// FIXME: This will be modified in the future. Basically, the uint64_t Mask = AWI->Attrs.Raw();
/// AttributeWithIndex class will contain the
for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds;
I = Attribute::AttrKind(I + 1)) {
if (uint64_t A = (Mask & 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);
}
}
} }
void AttrBuilder::clear() { void AttrBuilder::clear() {
@ -610,6 +620,10 @@ std::string AttributeSet::getAsString(unsigned Index) const {
return getAttributes(Index).getAsString(); return getAttributes(Index).getAsString();
} }
unsigned AttributeSet::getParamAlignment(unsigned Idx) const {
return getAttributes(Idx).getAlignment();
}
unsigned AttributeSet::getStackAlignment(unsigned Index) const { unsigned AttributeSet::getStackAlignment(unsigned Index) const {
return getAttributes(Index).getStackAlignment(); return getAttributes(Index).getStackAlignment();
} }
@ -646,6 +660,11 @@ bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const {
return false; return false;
} }
AttributeSet AttributeSet::addFnAttributes(LLVMContext &C,
AttributeSet Attrs) const {
return addAttr(C, FunctionIndex, getAttributes(FunctionIndex));
}
AttributeSet AttributeSet::addAttr(LLVMContext &C, unsigned Idx, AttributeSet AttributeSet::addAttr(LLVMContext &C, unsigned Idx,
Attribute Attrs) const { Attribute Attrs) const {
Attribute OldAttrs = getAttributes(Idx); Attribute OldAttrs = getAttributes(Idx);

View File

@ -739,41 +739,61 @@ void Verifier::VerifyFunctionAttrs(FunctionType *FT,
Assert1(Attr.Index == 1, "Attribute sret is not on first parameter!", V); Assert1(Attr.Index == 1, "Attribute sret is not on first parameter!", V);
} }
Attribute FAttrs = Attrs.getFnAttributes(); if (!Attrs.hasAttributes(AttributeSet::FunctionIndex))
AttrBuilder NotFn(FAttrs); return;
AttrBuilder NotFn(Attrs, AttributeSet::FunctionIndex);
NotFn.removeFunctionOnlyAttrs(); NotFn.removeFunctionOnlyAttrs();
Assert1(!NotFn.hasAttributes(), "Attribute '" + Assert1(!NotFn.hasAttributes(), "Attribute '" +
Attribute::get(V->getContext(), NotFn).getAsString() + Attribute::get(V->getContext(), NotFn).getAsString() +
"' do not apply to the function!", V); "' do not apply to the function!", V);
// Check for mutually incompatible attributes. // Check for mutually incompatible attributes.
Assert1(!((FAttrs.hasAttribute(Attribute::ByVal) && Assert1(!((Attrs.hasAttribute(AttributeSet::FunctionIndex,
FAttrs.hasAttribute(Attribute::Nest)) || Attribute::ByVal) &&
(FAttrs.hasAttribute(Attribute::ByVal) && Attrs.hasAttribute(AttributeSet::FunctionIndex,
FAttrs.hasAttribute(Attribute::StructRet)) || Attribute::Nest)) ||
(FAttrs.hasAttribute(Attribute::Nest) && (Attrs.hasAttribute(AttributeSet::FunctionIndex,
FAttrs.hasAttribute(Attribute::StructRet))), "Attributes " Attribute::ByVal) &&
"'byval, nest, and sret' are incompatible!", V); Attrs.hasAttribute(AttributeSet::FunctionIndex,
Attribute::StructRet)) ||
(Attrs.hasAttribute(AttributeSet::FunctionIndex,
Attribute::Nest) &&
Attrs.hasAttribute(AttributeSet::FunctionIndex,
Attribute::StructRet))),
"Attributes 'byval, nest, and sret' are incompatible!", V);
Assert1(!((FAttrs.hasAttribute(Attribute::ByVal) && Assert1(!((Attrs.hasAttribute(AttributeSet::FunctionIndex,
FAttrs.hasAttribute(Attribute::Nest)) || Attribute::ByVal) &&
(FAttrs.hasAttribute(Attribute::ByVal) && Attrs.hasAttribute(AttributeSet::FunctionIndex,
FAttrs.hasAttribute(Attribute::InReg)) || Attribute::Nest)) ||
(FAttrs.hasAttribute(Attribute::Nest) && (Attrs.hasAttribute(AttributeSet::FunctionIndex,
FAttrs.hasAttribute(Attribute::InReg))), "Attributes " Attribute::ByVal) &&
"'byval, nest, and inreg' are incompatible!", V); Attrs.hasAttribute(AttributeSet::FunctionIndex,
Attribute::InReg)) ||
(Attrs.hasAttribute(AttributeSet::FunctionIndex,
Attribute::Nest) &&
Attrs.hasAttribute(AttributeSet::FunctionIndex,
Attribute::InReg))),
"Attributes 'byval, nest, and inreg' are incompatible!", V);
Assert1(!(FAttrs.hasAttribute(Attribute::ZExt) && Assert1(!(Attrs.hasAttribute(AttributeSet::FunctionIndex,
FAttrs.hasAttribute(Attribute::SExt)), "Attributes " Attribute::ZExt) &&
"'zeroext and signext' are incompatible!", V); Attrs.hasAttribute(AttributeSet::FunctionIndex,
Attribute::SExt)),
"Attributes 'zeroext and signext' are incompatible!", V);
Assert1(!(FAttrs.hasAttribute(Attribute::ReadNone) && Assert1(!(Attrs.hasAttribute(AttributeSet::FunctionIndex,
FAttrs.hasAttribute(Attribute::ReadOnly)), "Attributes " Attribute::ReadNone) &&
"'readnone and readonly' are incompatible!", V); Attrs.hasAttribute(AttributeSet::FunctionIndex,
Attribute::ReadOnly)),
"Attributes 'readnone and readonly' are incompatible!", V);
Assert1(!(FAttrs.hasAttribute(Attribute::NoInline) && Assert1(!(Attrs.hasAttribute(AttributeSet::FunctionIndex,
FAttrs.hasAttribute(Attribute::AlwaysInline)), "Attributes " Attribute::NoInline) &&
"'noinline and alwaysinline' are incompatible!", V); Attrs.hasAttribute(AttributeSet::FunctionIndex,
Attribute::AlwaysInline)),
"Attributes 'noinline and alwaysinline' are incompatible!", V);
} }
static bool VerifyAttributeCount(const AttributeSet &Attrs, unsigned Params) { static bool VerifyAttributeCount(const AttributeSet &Attrs, unsigned Params) {

View File

@ -592,7 +592,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
// Add any function attributes. // Add any function attributes.
attrs = PAL.getFnAttributes(); attrs = PAL.getFnAttributes();
if (attrs.hasAttributes()) if (PAL.hasAttributes(AttributeSet::FunctionIndex))
AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
attrs)); attrs));
@ -722,7 +722,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
// Add any function attributes. // Add any function attributes.
attrs = CallPAL.getFnAttributes(); attrs = CallPAL.getFnAttributes();
if (attrs.hasAttributes()) if (CallPAL.hasAttributes(AttributeSet::FunctionIndex))
AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
attrs)); attrs));

View File

@ -277,7 +277,7 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
for (unsigned i = 0; PAL.getSlot(i).Index <= NumArgs; ++i) for (unsigned i = 0; PAL.getSlot(i).Index <= NumArgs; ++i)
AttributesVec.push_back(PAL.getSlot(i)); AttributesVec.push_back(PAL.getSlot(i));
Attribute FnAttrs = PAL.getFnAttributes(); Attribute FnAttrs = PAL.getFnAttributes();
if (FnAttrs.hasAttributes()) if (PAL.hasAttributes(AttributeSet::FunctionIndex))
AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
FnAttrs)); FnAttrs));
PAL = AttributeSet::get(Fn.getContext(), AttributesVec); PAL = AttributeSet::get(Fn.getContext(), AttributesVec);

View File

@ -1176,7 +1176,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
} }
Attribute FnAttrs = CallerPAL.getFnAttributes(); Attribute FnAttrs = CallerPAL.getFnAttributes();
if (FnAttrs.hasAttributes()) if (CallerPAL.hasAttributes(AttributeSet::FunctionIndex))
attrVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, attrVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
FnAttrs)); FnAttrs));
@ -1320,7 +1320,7 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS,
// Add any function attributes. // Add any function attributes.
Attr = Attrs.getFnAttributes(); Attr = Attrs.getFnAttributes();
if (Attr.hasAttributes()) if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
NewAttrs.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, NewAttrs.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
Attr)); Attr));

View File

@ -103,10 +103,8 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
OldFunc->getAttributes() OldFunc->getAttributes()
.getRetAttributes())); .getRetAttributes()));
NewFunc->setAttributes(NewFunc->getAttributes() NewFunc->setAttributes(NewFunc->getAttributes()
.addAttr(NewFunc->getContext(), .addFnAttributes(NewFunc->getContext(),
AttributeSet::FunctionIndex, OldFunc->getAttributes()));
OldFunc->getAttributes()
.getFnAttributes()));
} }