Use AttributeSet accessor methods instead of Attribute accessor methods.

Further encapsulation of the Attribute object. Don't allow direct access to the
Attribute object as an aggregate.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172853 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling
2013-01-18 21:53:16 +00:00
parent 1a17bd21ff
commit 1b0c54f1c5
8 changed files with 36 additions and 34 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 return attributes to this attribute set. Since attribute sets
/// are immutable, this returns a new set.
AttributeSet addRetAttributes(LLVMContext &C, AttributeSet Attrs) const;
/// \brief Add function attributes to this attribute set. Since attribute sets /// \brief Add function attributes to this attribute set. Since attribute sets
/// are immutable, this returns a new set. /// are immutable, this returns a new set.
AttributeSet addFnAttributes(LLVMContext &C, AttributeSet Attrs) const; AttributeSet addFnAttributes(LLVMContext &C, AttributeSet Attrs) const;

View File

@@ -50,14 +50,14 @@ bool TargetLowering::isInTailCallPosition(SelectionDAG &DAG, SDNode *Node,
// Conservatively require the attributes of the call to match those of // Conservatively require the attributes of the call to match those of
// the return. Ignore noalias because it doesn't affect the call sequence. // the return. Ignore noalias because it doesn't affect the call sequence.
Attribute CallerRetAttr = F->getAttributes().getRetAttributes(); AttributeSet CallerAttrs = F->getAttributes();
if (AttrBuilder(CallerRetAttr) if (AttrBuilder(CallerAttrs, AttributeSet::ReturnIndex)
.removeAttribute(Attribute::NoAlias).hasAttributes()) .removeAttribute(Attribute::NoAlias).hasAttributes())
return false; return false;
// It's not safe to eliminate the sign / zero extension of the return value. // It's not safe to eliminate the sign / zero extension of the return value.
if (CallerRetAttr.hasAttribute(Attribute::ZExt) || if (CallerAttrs.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt) ||
CallerRetAttr.hasAttribute(Attribute::SExt)) CallerAttrs.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
return false; return false;
// Check if the only use is a function return node. // Check if the only use is a function return node.

View File

@@ -1557,9 +1557,8 @@ void AssemblyWriter::printFunction(const Function *F) {
FunctionType *FT = F->getFunctionType(); FunctionType *FT = F->getFunctionType();
const AttributeSet &Attrs = F->getAttributes(); const AttributeSet &Attrs = F->getAttributes();
Attribute RetAttrs = Attrs.getRetAttributes(); if (Attrs.hasAttributes(AttributeSet::ReturnIndex))
if (RetAttrs.hasAttributes()) Out << Attrs.getAsString(AttributeSet::ReturnIndex) << ' ';
Out << Attrs.getRetAttributes().getAsString() << ' ';
TypePrinter.print(F->getReturnType(), Out); TypePrinter.print(F->getReturnType(), Out);
Out << ' '; Out << ' ';
WriteAsOperandInternal(Out, F, &TypePrinter, &Machine, F->getParent()); WriteAsOperandInternal(Out, F, &TypePrinter, &Machine, F->getParent());
@@ -1849,8 +1848,8 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
Type *RetTy = FTy->getReturnType(); Type *RetTy = FTy->getReturnType();
const AttributeSet &PAL = CI->getAttributes(); const AttributeSet &PAL = CI->getAttributes();
if (PAL.getRetAttributes().hasAttributes()) if (PAL.hasAttributes(AttributeSet::ReturnIndex))
Out << ' ' << PAL.getRetAttributes().getAsString(); Out << ' ' << PAL.getAsString(AttributeSet::ReturnIndex);
// If possible, print out the short form of the call instruction. We can // If possible, print out the short form of the call instruction. We can
// only do this if the first argument is a pointer to a nonvararg function, // only do this if the first argument is a pointer to a nonvararg function,
@@ -1888,8 +1887,8 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
PrintCallingConv(II->getCallingConv(), Out); PrintCallingConv(II->getCallingConv(), Out);
} }
if (PAL.getRetAttributes().hasAttributes()) if (PAL.hasAttributes(AttributeSet::ReturnIndex))
Out << ' ' << PAL.getRetAttributes().getAsString(); Out << ' ' << PAL.getAsString(AttributeSet::ReturnIndex);
// If possible, print out the short form of the invoke instruction. We can // If possible, print out the short form of the invoke instruction. We can
// only do this if the first argument is a pointer to a nonvararg function, // only do this if the first argument is a pointer to a nonvararg function,

View File

@@ -660,6 +660,11 @@ bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const {
return false; return false;
} }
AttributeSet AttributeSet::addRetAttributes(LLVMContext &C,
AttributeSet Attrs) const {
return addAttr(C, ReturnIndex, getAttributes(ReturnIndex));
}
AttributeSet AttributeSet::addFnAttributes(LLVMContext &C, AttributeSet AttributeSet::addFnAttributes(LLVMContext &C,
AttributeSet Attrs) const { AttributeSet Attrs) const {
return addAttr(C, FunctionIndex, getAttributes(FunctionIndex)); return addAttr(C, FunctionIndex, getAttributes(FunctionIndex));

View File

@@ -518,10 +518,9 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
const AttributeSet &PAL = F->getAttributes(); const AttributeSet &PAL = F->getAttributes();
// Add any return attributes. // Add any return attributes.
Attribute attrs = PAL.getRetAttributes(); if (PAL.hasAttributes(AttributeSet::ReturnIndex))
if (attrs.hasAttributes())
AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::ReturnIndex, AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::ReturnIndex,
attrs)); PAL.getRetAttributes()));
// First, determine the new argument list // First, determine the new argument list
unsigned ArgIndex = 1; unsigned ArgIndex = 1;
@@ -591,10 +590,9 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
} }
// Add any function attributes. // Add any function attributes.
attrs = PAL.getFnAttributes();
if (PAL.hasAttributes(AttributeSet::FunctionIndex)) if (PAL.hasAttributes(AttributeSet::FunctionIndex))
AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
attrs)); PAL.getFnAttributes()));
Type *RetTy = FTy->getReturnType(); Type *RetTy = FTy->getReturnType();
@@ -639,10 +637,9 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
const AttributeSet &CallPAL = CS.getAttributes(); const AttributeSet &CallPAL = CS.getAttributes();
// Add any return attributes. // Add any return attributes.
Attribute attrs = CallPAL.getRetAttributes(); if (CallPAL.hasAttributes(AttributeSet::ReturnIndex))
if (attrs.hasAttributes())
AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::ReturnIndex, AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::ReturnIndex,
attrs)); CallPAL.getRetAttributes()));
// Loop over the operands, inserting GEP and loads in the caller as // Loop over the operands, inserting GEP and loads in the caller as
// appropriate. // appropriate.
@@ -721,10 +718,9 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
} }
// Add any function attributes. // Add any function attributes.
attrs = CallPAL.getFnAttributes();
if (CallPAL.hasAttributes(AttributeSet::FunctionIndex)) if (CallPAL.hasAttributes(AttributeSet::FunctionIndex))
AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
attrs)); CallPAL.getFnAttributes()));
Instruction *New; Instruction *New;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {

View File

@@ -1014,7 +1014,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
return false; // Cannot transform this return value. return false; // Cannot transform this return value.
if (!CallerPAL.isEmpty() && !Caller->use_empty()) { if (!CallerPAL.isEmpty() && !Caller->use_empty()) {
AttrBuilder RAttrs = CallerPAL.getRetAttributes(); AttrBuilder RAttrs(CallerPAL, AttributeSet::ReturnIndex);
if (RAttrs.hasAttributes(Attribute::typeIncompatible(NewRetTy))) if (RAttrs.hasAttributes(Attribute::typeIncompatible(NewRetTy)))
return false; // Attribute not compatible with transformed value. return false; // Attribute not compatible with transformed value.
} }
@@ -1117,7 +1117,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
attrVec.reserve(NumCommonArgs); attrVec.reserve(NumCommonArgs);
// Get any return attributes. // Get any return attributes.
AttrBuilder RAttrs = CallerPAL.getRetAttributes(); AttrBuilder RAttrs(CallerPAL, AttributeSet::ReturnIndex);
// If the return value is not being used, the type may not be compatible // If the return value is not being used, the type may not be compatible
// with the existing attributes. Wipe out any problematic attributes. // with the existing attributes. Wipe out any problematic attributes.
@@ -1287,7 +1287,7 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS,
// Add any result attributes. // Add any result attributes.
Attribute Attr = Attrs.getRetAttributes(); Attribute Attr = Attrs.getRetAttributes();
if (Attr.hasAttributes()) if (Attrs.hasAttributes(AttributeSet::ReturnIndex))
NewAttrs.push_back(AttributeWithIndex::get(AttributeSet::ReturnIndex, NewAttrs.push_back(AttributeWithIndex::get(AttributeSet::ReturnIndex,
Attr)); Attr));

View File

@@ -729,9 +729,9 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(BasicBlock *BB) {
// It's not safe to eliminate the sign / zero extension of the return value. // It's not safe to eliminate the sign / zero extension of the return value.
// See llvm::isInTailCallPosition(). // See llvm::isInTailCallPosition().
const Function *F = BB->getParent(); const Function *F = BB->getParent();
Attribute CallerRetAttr = F->getAttributes().getRetAttributes(); AttributeSet CallerAttrs = F->getAttributes();
if (CallerRetAttr.hasAttribute(Attribute::ZExt) || if (CallerAttrs.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt) ||
CallerRetAttr.hasAttribute(Attribute::SExt)) CallerAttrs.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
return false; return false;
// Make sure there are no instructions between the PHI and return, or that the // Make sure there are no instructions between the PHI and return, or that the
@@ -788,10 +788,10 @@ bool CodeGenPrepare::DupRetToEnableTailCallOpts(BasicBlock *BB) {
// Conservatively require the attributes of the call to match those of the // Conservatively require the attributes of the call to match those of the
// return. Ignore noalias because it doesn't affect the call sequence. // return. Ignore noalias because it doesn't affect the call sequence.
Attribute CalleeRetAttr = CS.getAttributes().getRetAttributes(); AttributeSet CalleeAttrs = CS.getAttributes();
if (AttrBuilder(CalleeRetAttr). if (AttrBuilder(CalleeAttrs, AttributeSet::ReturnIndex).
removeAttribute(Attribute::NoAlias) != removeAttribute(Attribute::NoAlias) !=
AttrBuilder(CallerRetAttr). AttrBuilder(CalleeAttrs, AttributeSet::ReturnIndex).
removeAttribute(Attribute::NoAlias)) removeAttribute(Attribute::NoAlias))
continue; continue;

View File

@@ -98,10 +98,8 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
Anew->addAttr( OldFunc->getAttributes() Anew->addAttr( OldFunc->getAttributes()
.getParamAttributes(I->getArgNo() + 1)); .getParamAttributes(I->getArgNo() + 1));
NewFunc->setAttributes(NewFunc->getAttributes() NewFunc->setAttributes(NewFunc->getAttributes()
.addAttr(NewFunc->getContext(), .addRetAttributes(NewFunc->getContext(),
AttributeSet::ReturnIndex, OldFunc->getAttributes()));
OldFunc->getAttributes()
.getRetAttributes()));
NewFunc->setAttributes(NewFunc->getAttributes() NewFunc->setAttributes(NewFunc->getAttributes()
.addFnAttributes(NewFunc->getContext(), .addFnAttributes(NewFunc->getContext(),
OldFunc->getAttributes())); OldFunc->getAttributes()));