[llvm-commits] CVS: llvm/lib/Transforms/Utils/InlineFunction.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sat Aug 23 23:09:01 PDT 2003
Changes in directory llvm/lib/Transforms/Utils:
InlineFunction.cpp updated: 1.1 -> 1.2
---
Log message:
Implement: Inline/cfg_preserve_test.ll
---
Diffs of the changes:
Index: llvm/lib/Transforms/Utils/InlineFunction.cpp
diff -u llvm/lib/Transforms/Utils/InlineFunction.cpp:1.1 llvm/lib/Transforms/Utils/InlineFunction.cpp:1.2
--- llvm/lib/Transforms/Utils/InlineFunction.cpp:1.1 Thu May 29 10:11:31 2003
+++ llvm/lib/Transforms/Utils/InlineFunction.cpp Sat Aug 23 23:06:56 2003
@@ -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 @@
// 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 @@
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;
}
More information about the llvm-commits
mailing list