diff options
author | Chris Lattner <sabre@nondot.org> | 2006-01-13 19:15:15 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-01-13 19:15:15 +0000 |
commit | 727d1dd58793447e83ade712f0e58172f156edcf (patch) | |
tree | 8a7b14538e488fadf6f7639ccb745c6c97d1d2ad /lib/Transforms | |
parent | cd4d339ec187182c9abc22b80560349f8ba5010f (diff) | |
download | external_llvm-727d1dd58793447e83ade712f0e58172f156edcf.zip external_llvm-727d1dd58793447e83ade712f0e58172f156edcf.tar.gz external_llvm-727d1dd58793447e83ade712f0e58172f156edcf.tar.bz2 |
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
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Utils/InlineFunction.cpp | 129 |
1 files changed, 67 insertions, 62 deletions
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index 9fb7c16..f7b4ab8 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -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 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 (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, 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; + } } - - // 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); + 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); + } } } } |