[llvm-commits] CVS: llvm/lib/Transforms/Utils/CloneFunction.cpp CloneTrace.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Feb 3 19:20:01 PST 2004


Changes in directory llvm/lib/Transforms/Utils:

CloneFunction.cpp updated: 1.19 -> 1.20
CloneTrace.cpp updated: 1.5 -> 1.6

---
Log message:

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.


---
Diffs of the changes:  (+10 -13)

Index: llvm/lib/Transforms/Utils/CloneFunction.cpp
diff -u llvm/lib/Transforms/Utils/CloneFunction.cpp:1.19 llvm/lib/Transforms/Utils/CloneFunction.cpp:1.20
--- llvm/lib/Transforms/Utils/CloneFunction.cpp:1.19	Fri Jan  9 00:12:12 2004
+++ llvm/lib/Transforms/Utils/CloneFunction.cpp	Tue Feb  3 19:19:43 2004
@@ -42,8 +42,8 @@
 // CloneBasicBlock - See comments in Cloning.h
 BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB,
                                   std::map<const Value*, Value*> &ValueMap,
-                                  const char *NameSuffix) {
-  BasicBlock *NewBB = new BasicBlock("");
+                                  const char *NameSuffix, Function *F) {
+  BasicBlock *NewBB = new BasicBlock("", F);
   if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
 
   // Loop over all instructions copying them over...
@@ -82,8 +82,7 @@
     const BasicBlock &BB = *BI;
     
     // Create a new basic block and copy instructions into it!
-    BasicBlock *CBB = CloneBasicBlock(&BB, ValueMap, NameSuffix);
-    NewFunc->getBasicBlockList().push_back(CBB);
+    BasicBlock *CBB = CloneBasicBlock(&BB, ValueMap, NameSuffix, NewFunc);
     ValueMap[&BB] = CBB;                       // Add basic block mapping.
 
     if (ReturnInst *RI = dyn_cast<ReturnInst>(CBB->getTerminator()))


Index: llvm/lib/Transforms/Utils/CloneTrace.cpp
diff -u llvm/lib/Transforms/Utils/CloneTrace.cpp:1.5 llvm/lib/Transforms/Utils/CloneTrace.cpp:1.6
--- llvm/lib/Transforms/Utils/CloneTrace.cpp:1.5	Fri Jan  9 00:12:15 2004
+++ llvm/lib/Transforms/Utils/CloneTrace.cpp	Tue Feb  3 19:19:43 2004
@@ -7,11 +7,11 @@
 // 
 //===----------------------------------------------------------------------===//
 //
-// This file implements the CloneTrace interface, which is used 
-// when writing runtime optimizations. It takes a vector of basic blocks
-// clones the basic blocks, removes internal phi nodes, adds it to the
-// same function as the original (although there is no jump to it) and 
-// returns the new vector of basic blocks.
+// This file implements the CloneTrace interface, which is used when writing
+// runtime optimizations. It takes a vector of basic blocks clones the basic
+// blocks, removes internal phi nodes, adds it to the same function as the
+// original (although there is no jump to it) and returns the new vector of
+// basic blocks.
 //
 //===----------------------------------------------------------------------===//
 
@@ -34,16 +34,14 @@
 	End = origTrace.end(); T != End; ++T) {
 
     //Clone Basic Block
-    BasicBlock *clonedBlock = CloneBasicBlock(*T, ValueMap);
+    BasicBlock *clonedBlock =
+      CloneBasicBlock(*T, ValueMap, ".tr", (*T)->getParent());
     
     //Add it to our new trace
     clonedTrace.push_back(clonedBlock);
 
     //Add this new mapping to our Value Map
     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
     //that are from blocks not in the trace





More information about the llvm-commits mailing list