summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp10
-rw-r--r--llvm/lib/Transforms/Utils/InlineFunction.cpp19
2 files changed, 18 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
index 6fe5e188b1a..8f6855e6a30 100644
--- a/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
@@ -253,12 +253,7 @@ bool TailCallElim::markTails(Function &F, bool &AllCallsAreTailCalls) {
return false;
AllCallsAreTailCalls = true;
- // The local stack holds all alloca instructions and all byval arguments.
AllocaDerivedValueTracker Tracker;
- for (Argument &Arg : F.args()) {
- if (Arg.hasByValAttr())
- Tracker.walk(&Arg);
- }
for (auto &BB : F) {
for (auto &I : BB)
if (AllocaInst *AI = dyn_cast<AllocaInst>(&I))
@@ -314,9 +309,8 @@ bool TailCallElim::markTails(Function &F, bool &AllCallsAreTailCalls) {
for (auto &Arg : CI->arg_operands()) {
if (isa<Constant>(Arg.getUser()))
continue;
- if (Argument *A = dyn_cast<Argument>(Arg.getUser()))
- if (!A->hasByValAttr())
- continue;
+ if (isa<Argument>(Arg.getUser()))
+ continue;
SafeToTail = false;
break;
}
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 1b2e2089415..c1589400b85 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -743,7 +743,8 @@ static void HandleByValArgumentInit(Value *Dst, Value *Src, Module *M,
static Value *HandleByValArgument(Value *Arg, Instruction *TheCall,
const Function *CalledFunc,
InlineFunctionInfo &IFI,
- unsigned ByValAlignment) {
+ unsigned ByValAlignment,
+ bool &AddedNewAllocas) {
PointerType *ArgTy = cast<PointerType>(Arg->getType());
Type *AggTy = ArgTy->getElementType();
@@ -785,6 +786,7 @@ static Value *HandleByValArgument(Value *Arg, Instruction *TheCall,
// Uses of the argument in the function should use our new alloca
// instead.
+ AddedNewAllocas = true;
return NewAlloca;
}
@@ -958,6 +960,7 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
SmallVector<ReturnInst*, 8> Returns;
ClonedCodeInfo InlinedFunctionInfo;
Function::iterator FirstNewBlock;
+ bool AddedNewAllocas = false;
{ // Scope to destroy VMap after cloning.
ValueToValueMapTy VMap;
@@ -981,7 +984,8 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
// modify the struct.
if (CS.isByValArgument(ArgNo)) {
ActualArg = HandleByValArgument(ActualArg, TheCall, CalledFunc, IFI,
- CalledFunc->getParamAlignment(ArgNo+1));
+ CalledFunc->getParamAlignment(ArgNo+1),
+ AddedNewAllocas);
if (ActualArg != *AI)
ByValInit.push_back(std::make_pair(ActualArg, (Value*) *AI));
}
@@ -1096,9 +1100,18 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI,
// f -> musttail g -> tail f ==> f -> tail f
// f -> g -> musttail f ==> f -> f
// f -> g -> tail f ==> f -> f
+ //
+ // If an alloca was introduced in the frame due to a byval parameter
+ // being passed to a subsequent call, tail calls must have the tail
+ // stripped as they may not access variables in the caller's stack.
+ // A single alloca ripples through out as the alloca may be aliased by
+ // bitcasts or may escape and be mutated outside of the function.
CallInst::TailCallKind ChildTCK = CI->getTailCallKind();
ChildTCK = std::min(CallSiteTailKind, ChildTCK);
- CI->setTailCallKind(ChildTCK);
+ if (AddedNewAllocas)
+ CI->setTailCallKind(CallInst::TCK_None);
+ else
+ CI->setTailCallKind(ChildTCK);
InlinedMustTailCalls |= CI->isMustTailCall();
// Calls inlined through a 'nounwind' call site should be marked
OpenPOWER on IntegriCloud