Give CloneBasicBlock an optional function argument to specify which function

to add the cloned block to.  This allows the block to be added to the function
immediately, and all of the instructions to be immediately added to the function
symbol table, which speeds up the inliner from 3.7 -> 3.38s on the PR209.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11107 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2004-02-04 01:19:43 +00:00
parent 786993c01e
commit 23b4c68f46
2 changed files with 10 additions and 13 deletions

View File

@ -42,8 +42,8 @@ static inline void RemapInstruction(Instruction *I,
// CloneBasicBlock - See comments in Cloning.h // CloneBasicBlock - See comments in Cloning.h
BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB,
std::map<const Value*, Value*> &ValueMap, std::map<const Value*, Value*> &ValueMap,
const char *NameSuffix) { const char *NameSuffix, Function *F) {
BasicBlock *NewBB = new BasicBlock(""); BasicBlock *NewBB = new BasicBlock("", F);
if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix); if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
// Loop over all instructions copying them over... // Loop over all instructions copying them over...
@ -82,8 +82,7 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
const BasicBlock &BB = *BI; const BasicBlock &BB = *BI;
// Create a new basic block and copy instructions into it! // Create a new basic block and copy instructions into it!
BasicBlock *CBB = CloneBasicBlock(&BB, ValueMap, NameSuffix); BasicBlock *CBB = CloneBasicBlock(&BB, ValueMap, NameSuffix, NewFunc);
NewFunc->getBasicBlockList().push_back(CBB);
ValueMap[&BB] = CBB; // Add basic block mapping. ValueMap[&BB] = CBB; // Add basic block mapping.
if (ReturnInst *RI = dyn_cast<ReturnInst>(CBB->getTerminator())) if (ReturnInst *RI = dyn_cast<ReturnInst>(CBB->getTerminator()))

View File

@ -7,11 +7,11 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// //
// This file implements the CloneTrace interface, which is used // This file implements the CloneTrace interface, which is used when writing
// when writing runtime optimizations. It takes a vector of basic blocks // runtime optimizations. It takes a vector of basic blocks clones the basic
// clones the basic blocks, removes internal phi nodes, adds it to the // blocks, removes internal phi nodes, adds it to the same function as the
// same function as the original (although there is no jump to it) and // original (although there is no jump to it) and returns the new vector of
// returns the new vector of basic blocks. // basic blocks.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -34,7 +34,8 @@ llvm::CloneTrace(const std::vector<BasicBlock*> &origTrace) {
End = origTrace.end(); T != End; ++T) { End = origTrace.end(); T != End; ++T) {
//Clone Basic Block //Clone Basic Block
BasicBlock *clonedBlock = CloneBasicBlock(*T, ValueMap); BasicBlock *clonedBlock =
CloneBasicBlock(*T, ValueMap, ".tr", (*T)->getParent());
//Add it to our new trace //Add it to our new trace
clonedTrace.push_back(clonedBlock); clonedTrace.push_back(clonedBlock);
@ -42,9 +43,6 @@ llvm::CloneTrace(const std::vector<BasicBlock*> &origTrace) {
//Add this new mapping to our Value Map //Add this new mapping to our Value Map
ValueMap[*T] = clonedBlock; ValueMap[*T] = clonedBlock;
//Add this cloned BB to the old BB's function
(*T)->getParent()->getBasicBlockList().push_back(clonedBlock);
//Loop over the phi instructions and delete operands //Loop over the phi instructions and delete operands
//that are from blocks not in the trace //that are from blocks not in the trace
//only do this if we are NOT the first block //only do this if we are NOT the first block