diff options
author | Chris Lattner <sabre@nondot.org> | 2003-08-24 04:06:56 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-08-24 04:06:56 +0000 |
commit | 7152c237b46a920b29d5605af934766b8f9a07a1 (patch) | |
tree | a065d5772f4a86ffd987efdec58d57890990f7c7 /lib | |
parent | 7bf617ab024ae344087abaa584ee707a251c496b (diff) | |
download | external_llvm-7152c237b46a920b29d5605af934766b8f9a07a1.zip external_llvm-7152c237b46a920b29d5605af934766b8f9a07a1.tar.gz external_llvm-7152c237b46a920b29d5605af934766b8f9a07a1.tar.bz2 |
Implement: Inline/cfg_preserve_test.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8099 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Utils/InlineFunction.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index e88153e..2fafef3 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -9,12 +9,13 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/Utils/Cloning.h" +#include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/iTerminators.h" #include "llvm/iPHINode.h" #include "llvm/iMemory.h" #include "llvm/iOther.h" -#include "llvm/DerivedTypes.h" +#include "llvm/Transforms/Utils/Local.h" // InlineFunction - This function inlines the called function into the basic // block of the caller. This returns false if it is not possible to inline this @@ -42,7 +43,8 @@ bool InlineFunction(CallInst *CI) { // immediately before the call. The original basic block now ends with an // unconditional branch to NewBB, and NewBB starts with the call instruction. // - BasicBlock *NewBB = OrigBB->splitBasicBlock(CI); + BasicBlock *NewBB = OrigBB->splitBasicBlock(CI, + CalledFunc->getName()+".entry"); NewBB->setName(OrigBB->getName()+".split"); // Remove (unlink) the CallInst from the start of the new basic block. @@ -160,5 +162,16 @@ bool InlineFunction(CallInst *CI) { Caller->getBasicBlockList().splice(NewBB, Caller->getBasicBlockList(), LastBlock, Caller->end()); + // We should always be able to fold the entry block of the function into the + // single predecessor of the block... + assert(cast<BranchInst>(Br)->isUnconditional() && "splitBasicBlock broken!"); + BasicBlock *CalleeEntry = cast<BranchInst>(Br)->getSuccessor(0); + SimplifyCFG(CalleeEntry); + + // Okay, continue the CFG cleanup. It's often the case that there is only a + // single return instruction in the callee function. If this is the case, + // then we have an unconditional branch from the return block to the 'NewBB'. + // Check for this case, and eliminate the branch is possible. + SimplifyCFG(NewBB); return true; } |