mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-09 13:33:17 +00:00
Use the ClonedCodeInfo object to avoid scans of the inlined code when
it doesn't contain any calls. This is a fairly common case for C++ code, so it will probably speed up the inliner marginally in these cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25284 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cd4d339ec1
commit
727d1dd587
@ -51,70 +51,75 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock,
|
||||
// The inlined code is currently at the end of the function, scan from the
|
||||
// start of the inlined code to its end, checking for stuff we need to
|
||||
// rewrite.
|
||||
for (Function::iterator BB = FirstNewBlock, E = Caller->end();
|
||||
BB != E; ++BB) {
|
||||
for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E; ) {
|
||||
Instruction *I = BBI++;
|
||||
|
||||
// We only need to check for function calls: inlined invoke instructions
|
||||
// require no special handling.
|
||||
if (!isa<CallInst>(I)) continue;
|
||||
CallInst *CI = cast<CallInst>(I);
|
||||
if (InlinedCodeInfo.ContainsCalls || InlinedCodeInfo.ContainsUnwinds) {
|
||||
for (Function::iterator BB = FirstNewBlock, E = Caller->end();
|
||||
BB != E; ++BB) {
|
||||
if (InlinedCodeInfo.ContainsCalls) {
|
||||
for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E; ){
|
||||
Instruction *I = BBI++;
|
||||
|
||||
// We only need to check for function calls: inlined invoke
|
||||
// instructions require no special handling.
|
||||
if (!isa<CallInst>(I)) continue;
|
||||
CallInst *CI = cast<CallInst>(I);
|
||||
|
||||
// If this is an intrinsic function call, do not convert it to an invoke.
|
||||
if (CI->getCalledFunction() &&
|
||||
CI->getCalledFunction()->getIntrinsicID())
|
||||
continue;
|
||||
|
||||
// Convert this function call into an invoke instruction.
|
||||
// First, split the basic block.
|
||||
BasicBlock *Split = BB->splitBasicBlock(CI, CI->getName()+".noexc");
|
||||
|
||||
// Next, create the new invoke instruction, inserting it at the end
|
||||
// of the old basic block.
|
||||
InvokeInst *II =
|
||||
new InvokeInst(CI->getCalledValue(), Split, InvokeDest,
|
||||
std::vector<Value*>(CI->op_begin()+1, CI->op_end()),
|
||||
CI->getName(), BB->getTerminator());
|
||||
II->setCallingConv(CI->getCallingConv());
|
||||
|
||||
// Make sure that anything using the call now uses the invoke!
|
||||
CI->replaceAllUsesWith(II);
|
||||
|
||||
// Delete the unconditional branch inserted by splitBasicBlock
|
||||
BB->getInstList().pop_back();
|
||||
Split->getInstList().pop_front(); // Delete the original call
|
||||
|
||||
// Update any PHI nodes in the exceptional block to indicate that
|
||||
// there is now a new entry in them.
|
||||
unsigned i = 0;
|
||||
for (BasicBlock::iterator I = InvokeDest->begin();
|
||||
isa<PHINode>(I); ++I, ++i) {
|
||||
PHINode *PN = cast<PHINode>(I);
|
||||
PN->addIncoming(InvokeDestPHIValues[i], BB);
|
||||
// If this is an intrinsic function call, don't convert it to an
|
||||
// invoke.
|
||||
if (CI->getCalledFunction() &&
|
||||
CI->getCalledFunction()->getIntrinsicID())
|
||||
continue;
|
||||
|
||||
// Convert this function call into an invoke instruction.
|
||||
// First, split the basic block.
|
||||
BasicBlock *Split = BB->splitBasicBlock(CI, CI->getName()+".noexc");
|
||||
|
||||
// Next, create the new invoke instruction, inserting it at the end
|
||||
// of the old basic block.
|
||||
InvokeInst *II =
|
||||
new InvokeInst(CI->getCalledValue(), Split, InvokeDest,
|
||||
std::vector<Value*>(CI->op_begin()+1, CI->op_end()),
|
||||
CI->getName(), BB->getTerminator());
|
||||
II->setCallingConv(CI->getCallingConv());
|
||||
|
||||
// Make sure that anything using the call now uses the invoke!
|
||||
CI->replaceAllUsesWith(II);
|
||||
|
||||
// Delete the unconditional branch inserted by splitBasicBlock
|
||||
BB->getInstList().pop_back();
|
||||
Split->getInstList().pop_front(); // Delete the original call
|
||||
|
||||
// Update any PHI nodes in the exceptional block to indicate that
|
||||
// there is now a new entry in them.
|
||||
unsigned i = 0;
|
||||
for (BasicBlock::iterator I = InvokeDest->begin();
|
||||
isa<PHINode>(I); ++I, ++i) {
|
||||
PHINode *PN = cast<PHINode>(I);
|
||||
PN->addIncoming(InvokeDestPHIValues[i], BB);
|
||||
}
|
||||
|
||||
// This basic block is now complete, start scanning the next one.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator())) {
|
||||
// An UnwindInst requires special handling when it gets inlined into an
|
||||
// invoke site. Once this happens, we know that the unwind would cause
|
||||
// a control transfer to the invoke exception destination, so we can
|
||||
// transform it into a direct branch to the exception destination.
|
||||
new BranchInst(InvokeDest, UI);
|
||||
|
||||
// This basic block is now complete, start scanning the next one.
|
||||
break;
|
||||
}
|
||||
|
||||
if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator())) {
|
||||
// An UnwindInst requires special handling when it gets inlined into an
|
||||
// invoke site. Once this happens, we know that the unwind would cause
|
||||
// a control transfer to the invoke exception destination, so we can
|
||||
// transform it into a direct branch to the exception destination.
|
||||
new BranchInst(InvokeDest, UI);
|
||||
|
||||
// Delete the unwind instruction!
|
||||
UI->getParent()->getInstList().pop_back();
|
||||
|
||||
// Update any PHI nodes in the exceptional block to indicate that
|
||||
// there is now a new entry in them.
|
||||
unsigned i = 0;
|
||||
for (BasicBlock::iterator I = InvokeDest->begin();
|
||||
isa<PHINode>(I); ++I, ++i) {
|
||||
PHINode *PN = cast<PHINode>(I);
|
||||
PN->addIncoming(InvokeDestPHIValues[i], BB);
|
||||
// Delete the unwind instruction!
|
||||
UI->getParent()->getInstList().pop_back();
|
||||
|
||||
// Update any PHI nodes in the exceptional block to indicate that
|
||||
// there is now a new entry in them.
|
||||
unsigned i = 0;
|
||||
for (BasicBlock::iterator I = InvokeDest->begin();
|
||||
isa<PHINode>(I); ++I, ++i) {
|
||||
PHINode *PN = cast<PHINode>(I);
|
||||
PN->addIncoming(InvokeDestPHIValues[i], BB);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user