diff options
author | Bill Wendling <isanbard@gmail.com> | 2013-01-21 21:57:28 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2013-01-21 21:57:28 +0000 |
commit | c5f1bc88a2eb7ad9ff924ca90cf88494e5f947b9 (patch) | |
tree | fdb62d85df750d2679b71fdab4d43d4e8258162b /lib | |
parent | 8e528100d210e225cee417229d94af91355118c0 (diff) | |
download | external_llvm-c5f1bc88a2eb7ad9ff924ca90cf88494e5f947b9.zip external_llvm-c5f1bc88a2eb7ad9ff924ca90cf88494e5f947b9.tar.gz external_llvm-c5f1bc88a2eb7ad9ff924ca90cf88494e5f947b9.tar.bz2 |
Make AttributeSet::getFnAttributes() return an AttributeSet instead of an Attribute.
This is more code to isolate the use of the Attribute class to that of just
holding one attribute instead of a collection of attributes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173094 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/IR/AttributeImpl.h | 2 | ||||
-rw-r--r-- | lib/IR/Attributes.cpp | 20 | ||||
-rw-r--r-- | lib/Transforms/IPO/ArgumentPromotion.cpp | 6 | ||||
-rw-r--r-- | lib/Transforms/IPO/DeadArgumentElimination.cpp | 24 | ||||
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCalls.cpp | 13 |
5 files changed, 45 insertions, 20 deletions
diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h index 10f30e7..b5d292e 100644 --- a/lib/IR/AttributeImpl.h +++ b/lib/IR/AttributeImpl.h @@ -39,6 +39,8 @@ public: ArrayRef<Constant*> values); AttributeImpl(LLVMContext &C, StringRef data); + LLVMContext &getContext() { return Context; } + ArrayRef<Constant*> getValues() const { return Vals; } bool hasAttribute(Attribute::AttrKind A) const; diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp index 5de1827..d3f284a 100644 --- a/lib/IR/Attributes.cpp +++ b/lib/IR/Attributes.cpp @@ -530,9 +530,29 @@ void AttributeImpl::Profile(FoldingSetNodeID &ID, Constant *Data, } //===----------------------------------------------------------------------===// +// AttributeWithIndex Definition +//===----------------------------------------------------------------------===// + +AttributeWithIndex AttributeWithIndex::get(LLVMContext &C, unsigned Idx, + AttributeSet AS) { + // FIXME: This is temporary, but necessary for the conversion. + AttrBuilder B(AS, Idx); + return get(Idx, Attribute::get(C, B)); +} + +//===----------------------------------------------------------------------===// // AttributeSetImpl Definition //===----------------------------------------------------------------------===// +AttributeSet AttributeSet::getFnAttributes() const { + // FIXME: Remove. + return AttrList ? + AttributeSet::get(AttrList->getContext(), + AttributeWithIndex::get(FunctionIndex, + getAttributes(FunctionIndex))) : + AttributeSet(); +} + AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<AttributeWithIndex> Attrs) { // If there are no attributes then return a null AttributesList pointer. diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 75c0504..c5b17db 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -591,7 +591,8 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F, // Add any function attributes. if (PAL.hasAttributes(AttributeSet::FunctionIndex)) - AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, + AttributesVec.push_back(AttributeWithIndex::get(FTy->getContext(), + AttributeSet::FunctionIndex, PAL.getFnAttributes())); Type *RetTy = FTy->getReturnType(); @@ -719,7 +720,8 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F, // Add any function attributes. if (CallPAL.hasAttributes(AttributeSet::FunctionIndex)) - AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, + AttributesVec.push_back(AttributeWithIndex::get(Call->getContext(), + AttributeSet::FunctionIndex, CallPAL.getFnAttributes())); Instruction *New; diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index 5b5a015..f6486e1 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -276,10 +276,10 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { SmallVector<AttributeWithIndex, 8> AttributesVec; for (unsigned i = 0; PAL.getSlot(i).Index <= NumArgs; ++i) AttributesVec.push_back(PAL.getSlot(i)); - Attribute FnAttrs = PAL.getFnAttributes(); if (PAL.hasAttributes(AttributeSet::FunctionIndex)) - AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, - FnAttrs)); + AttributesVec.push_back(AttributeWithIndex::get(Fn.getContext(), + AttributeSet::FunctionIndex, + PAL.getFnAttributes())); PAL = AttributeSet::get(Fn.getContext(), AttributesVec); } @@ -702,10 +702,8 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { // The existing function return attributes. Attribute RAttrs = PAL.getRetAttributes(); - Attribute FnAttrs = PAL.getFnAttributes(); // Find out the new return value. - Type *RetTy = FTy->getReturnType(); Type *NRetTy = NULL; unsigned RetCount = NumRetVals(F); @@ -801,9 +799,10 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { } } - if (FnAttrs.hasAttributes()) - AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, - FnAttrs)); + if (PAL.hasAttributes(AttributeSet::FunctionIndex)) + AttributesVec.push_back(AttributeWithIndex::get(F->getContext(), + AttributeSet::FunctionIndex, + PAL.getFnAttributes())); // Reconstruct the AttributesList based on the vector we constructed. AttributeSet NewPAL = AttributeSet::get(F->getContext(), AttributesVec); @@ -837,7 +836,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { // The call return attributes. Attribute RAttrs = CallPAL.getRetAttributes(); - Attribute FnAttrs = CallPAL.getFnAttributes(); + // Adjust in case the function was changed to return void. RAttrs = Attribute::get(NF->getContext(), AttrBuilder(RAttrs). @@ -869,9 +868,10 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { AttributesVec.push_back(AttributeWithIndex::get(Args.size(), Attrs)); } - if (FnAttrs.hasAttributes()) - AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, - FnAttrs)); + if (CallPAL.hasAttributes(AttributeSet::FunctionIndex)) + AttributesVec.push_back(AttributeWithIndex::get(Call->getContext(), + AttributeSet::FunctionIndex, + CallPAL.getFnAttributes())); // Reconstruct the AttributesList based on the vector we constructed. AttributeSet NewCallPAL = AttributeSet::get(F->getContext(), AttributesVec); diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index 1ac9a9d..f3036d8 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1175,16 +1175,17 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { } } - Attribute FnAttrs = CallerPAL.getFnAttributes(); + AttributeSet FnAttrs = CallerPAL.getFnAttributes(); if (CallerPAL.hasAttributes(AttributeSet::FunctionIndex)) - attrVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, + attrVec.push_back(AttributeWithIndex::get(Callee->getContext(), + AttributeSet::FunctionIndex, FnAttrs)); if (NewRetTy->isVoidTy()) Caller->setName(""); // Void type should not have a name. const AttributeSet &NewCallerPAL = AttributeSet::get(Callee->getContext(), - attrVec); + attrVec); Instruction *NC; if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) { @@ -1319,10 +1320,10 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS, } // Add any function attributes. - Attr = Attrs.getFnAttributes(); if (Attrs.hasAttributes(AttributeSet::FunctionIndex)) - NewAttrs.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex, - Attr)); + NewAttrs.push_back(AttributeWithIndex::get(FTy->getContext(), + AttributeSet::FunctionIndex, + Attrs.getFnAttributes())); // The trampoline may have been bitcast to a bogus type (FTy). // Handle this by synthesizing a new function type, equal to FTy |