summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp49
1 files changed, 30 insertions, 19 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index c850e2e7393..af4c9ac7537 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -23,7 +23,6 @@
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/ValueTracking.h"
-#include "llvm/IR/AttributeSetNode.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
@@ -3993,7 +3992,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
if (!CastInst::isBitOrNoopPointerCastable(ActTy, ParamTy, DL))
return false; // Cannot transform this parameter value.
- if (AttrBuilder(CallerPAL.getParamAttributes(i + 1)).
+ if (AttrBuilder(CallerPAL.getParamAttributes(i + 1), i + 1).
overlaps(AttributeFuncs::typeIncompatible(ParamTy)))
return false; // Attribute not compatible with transformed value.
@@ -4002,7 +4001,9 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
// If the parameter is passed as a byval argument, then we have to have a
// sized type and the sized type has to have the same size as the old type.
- if (ParamTy != ActTy && CallerPAL.hasAttribute(i + 1, Attribute::ByVal)) {
+ if (ParamTy != ActTy &&
+ CallerPAL.getParamAttributes(i + 1).hasAttribute(i + 1,
+ Attribute::ByVal)) {
PointerType *ParamPTy = dyn_cast<PointerType>(ParamTy);
if (!ParamPTy || !ParamPTy->getElementType()->isSized())
return false;
@@ -4083,7 +4084,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
}
// Add any parameter attributes.
- AttrBuilder PAttrs(CallerPAL.getParamAttributes(i + 1));
+ AttrBuilder PAttrs(CallerPAL.getParamAttributes(i + 1), i + 1);
if (PAttrs.hasAttributes())
attrVec.push_back(
AttributeList::get(Caller->getContext(), i + 1, PAttrs));
@@ -4111,7 +4112,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
}
// Add any parameter attributes.
- AttrBuilder PAttrs(CallerPAL.getParamAttributes(i + 1));
+ AttrBuilder PAttrs(CallerPAL.getParamAttributes(i + 1), i + 1);
if (PAttrs.hasAttributes())
attrVec.push_back(
AttributeList::get(FT->getContext(), i + 1, PAttrs));
@@ -4119,11 +4120,9 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
}
}
- AttributeSetNode *FnAttrs = CallerPAL.getFnAttributes();
+ AttributeList FnAttrs = CallerPAL.getFnAttributes();
if (CallerPAL.hasAttributes(AttributeList::FunctionIndex))
- attrVec.push_back(AttributeList::get(Callee->getContext(),
- AttributeList::FunctionIndex,
- AttrBuilder(FnAttrs)));
+ attrVec.push_back(AttributeList::get(Callee->getContext(), FnAttrs));
if (NewRetTy->isVoidTy())
Caller->setName(""); // Void type should not have a name.
@@ -4201,7 +4200,7 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS,
Value *Callee = CS.getCalledValue();
PointerType *PTy = cast<PointerType>(Callee->getType());
FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
- AttributeList Attrs = CS.getAttributes();
+ const AttributeList &Attrs = CS.getAttributes();
// If the call already has the 'nest' attribute somewhere then give up -
// otherwise 'nest' would occur twice after splicing in the chain.
@@ -4214,11 +4213,11 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS,
Function *NestF =cast<Function>(Tramp->getArgOperand(1)->stripPointerCasts());
FunctionType *NestFTy = cast<FunctionType>(NestF->getValueType());
- AttributeList NestAttrs = NestF->getAttributes();
+ const AttributeList &NestAttrs = NestF->getAttributes();
if (!NestAttrs.isEmpty()) {
unsigned NestIdx = 1;
Type *NestTy = nullptr;
- AttributeSetNode *NestAttr;
+ AttributeList NestAttr;
// Look for a parameter marked with the 'nest' attribute.
for (FunctionType::param_iterator I = NestFTy->param_begin(),
@@ -4233,15 +4232,18 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS,
if (NestTy) {
Instruction *Caller = CS.getInstruction();
std::vector<Value*> NewArgs;
- std::vector<AttributeSetNode *> NewAttrs;
NewArgs.reserve(CS.arg_size() + 1);
- NewAttrs.reserve(CS.arg_size() + 2);
+
+ SmallVector<AttributeList, 8> NewAttrs;
+ NewAttrs.reserve(Attrs.getNumSlots() + 1);
// Insert the nest argument into the call argument list, which may
// mean appending it. Likewise for attributes.
// Add any result attributes.
- NewAttrs.push_back(Attrs.getRetAttributes());
+ if (Attrs.hasAttributes(AttributeList::ReturnIndex))
+ NewAttrs.push_back(
+ AttributeList::get(Caller->getContext(), Attrs.getRetAttributes()));
{
unsigned Idx = 1;
@@ -4253,7 +4255,8 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS,
if (NestVal->getType() != NestTy)
NestVal = Builder->CreateBitCast(NestVal, NestTy, "nest");
NewArgs.push_back(NestVal);
- NewAttrs.push_back(NestAttr);
+ NewAttrs.push_back(
+ AttributeList::get(Caller->getContext(), NestAttr));
}
if (I == E)
@@ -4261,7 +4264,12 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS,
// Add the original argument and attributes.
NewArgs.push_back(*I);
- NewAttrs.push_back(Attrs.getParamAttributes(Idx));
+ AttributeList Attr = Attrs.getParamAttributes(Idx);
+ if (Attr.hasAttributes(Idx)) {
+ AttrBuilder B(Attr, Idx);
+ NewAttrs.push_back(AttributeList::get(Caller->getContext(),
+ Idx + (Idx >= NestIdx), B));
+ }
++Idx;
++I;
@@ -4269,7 +4277,9 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS,
}
// Add any function attributes.
- NewAttrs.push_back(Attrs.getFnAttributes());
+ if (Attrs.hasAttributes(AttributeList::FunctionIndex))
+ NewAttrs.push_back(
+ AttributeList::get(FTy->getContext(), Attrs.getFnAttributes()));
// The trampoline may have been bitcast to a bogus type (FTy).
// Handle this by synthesizing a new function type, equal to FTy
@@ -4309,7 +4319,8 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS,
NestF->getType() == PointerType::getUnqual(NewFTy) ?
NestF : ConstantExpr::getBitCast(NestF,
PointerType::getUnqual(NewFTy));
- AttributeList NewPAL = AttributeList::get(FTy->getContext(), NewAttrs);
+ const AttributeList &NewPAL =
+ AttributeList::get(FTy->getContext(), NewAttrs);
SmallVector<OperandBundleDef, 1> OpBundles;
CS.getOperandBundlesAsDefs(OpBundles);
OpenPOWER on IntegriCloud