1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00

[DAE] Simplify call site replacement code with CallSite NFC

llvm-svn: 300235
This commit is contained in:
Reid Kleckner 2017-04-13 18:42:03 +00:00
parent 6fe9669cc0
commit 6990c95d43

View File

@ -181,30 +181,28 @@ bool DeadArgumentEliminationPass::DeleteDeadVarargs(Function &Fn) {
SmallVector<OperandBundleDef, 1> OpBundles;
CS.getOperandBundlesAsDefs(OpBundles);
Instruction *New;
CallSite NewCS;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
Args, OpBundles, "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
cast<InvokeInst>(New)->setAttributes(PAL);
NewCS = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
Args, OpBundles, "", Call);
} else {
New = CallInst::Create(NF, Args, OpBundles, "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
cast<CallInst>(New)->setAttributes(PAL);
cast<CallInst>(New)->setTailCallKind(
cast<CallInst>(Call)->getTailCallKind());
NewCS = CallInst::Create(NF, Args, OpBundles, "", Call);
cast<CallInst>(NewCS.getInstruction())
->setTailCallKind(cast<CallInst>(Call)->getTailCallKind());
}
New->setDebugLoc(Call->getDebugLoc());
NewCS.setCallingConv(CS.getCallingConv());
NewCS.setAttributes(PAL);
NewCS->setDebugLoc(Call->getDebugLoc());
uint64_t W;
if (Call->extractProfTotalWeight(W))
New->setProfWeight(W);
NewCS->setProfWeight(W);
Args.clear();
if (!Call->use_empty())
Call->replaceAllUsesWith(New);
Call->replaceAllUsesWith(NewCS.getInstruction());
New->takeName(Call);
NewCS->takeName(Call);
// Finally, remove the old call from the program, reducing the use-count of
// F.
@ -868,26 +866,25 @@ bool DeadArgumentEliminationPass::RemoveDeadStuffFromFunction(Function *F) {
SmallVector<OperandBundleDef, 1> OpBundles;
CS.getOperandBundlesAsDefs(OpBundles);
Instruction *New;
CallSite NewCS;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
Args, OpBundles, "", Call->getParent());
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
cast<InvokeInst>(New)->setAttributes(NewCallPAL);
NewCS = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
Args, OpBundles, "", Call->getParent());
} else {
New = CallInst::Create(NF, Args, OpBundles, "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
cast<CallInst>(New)->setAttributes(NewCallPAL);
cast<CallInst>(New)->setTailCallKind(
cast<CallInst>(Call)->getTailCallKind());
NewCS = CallInst::Create(NF, Args, OpBundles, "", Call);
cast<CallInst>(NewCS.getInstruction())
->setTailCallKind(cast<CallInst>(Call)->getTailCallKind());
}
New->setDebugLoc(Call->getDebugLoc());
NewCS.setCallingConv(CS.getCallingConv());
NewCS.setAttributes(NewCallPAL);
NewCS->setDebugLoc(Call->getDebugLoc());
uint64_t W;
if (Call->extractProfTotalWeight(W))
New->setProfWeight(W);
NewCS->setProfWeight(W);
Args.clear();
ArgAttrVec.clear();
Instruction *New = NewCS.getInstruction();
if (!Call->use_empty()) {
if (New->getType() == Call->getType()) {
// Return type not changed? Just replace users then.