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

Chris Lattner lattner at cs.uiuc.edu
Tue Nov 19 15:55:04 PST 2002


Changes in directory llvm/lib/Transforms/Utils:

CloneFunction.cpp updated: 1.7 -> 1.8

---
Log message:

Rework inline pass to use cloning infrastructure to do the dirty work



---
Diffs of the changes:

Index: llvm/lib/Transforms/Utils/CloneFunction.cpp
diff -u llvm/lib/Transforms/Utils/CloneFunction.cpp:1.7 llvm/lib/Transforms/Utils/CloneFunction.cpp:1.8
--- llvm/lib/Transforms/Utils/CloneFunction.cpp:1.7	Tue Nov 19 14:59:39 2002
+++ llvm/lib/Transforms/Utils/CloneFunction.cpp	Tue Nov 19 15:54:07 2002
@@ -4,6 +4,7 @@
 // FIXME: document
 
 #include "llvm/Transforms/Utils/Cloning.h"
+#include "llvm/iTerminators.h"
 #include "llvm/Function.h"
 #include <map>
 
@@ -35,9 +36,10 @@
 // ArgMap values.
 //
 void CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
-                       const std::vector<Value*> &ArgMap) {
-  assert(OldFunc->aempty() || !NewFunc->aempty() &&
-         "Synthesization of arguments is not implemented yet!");
+                       const std::vector<Value*> &ArgMap,
+                       std::vector<ReturnInst*> &Returns,
+                       const char *NameSuffix) {
+  assert(NameSuffix && "NameSuffix cannot be null!");
   assert(OldFunc->asize() == ArgMap.size() &&
          "Improper number of argument values to map specified!");
   
@@ -55,25 +57,30 @@
 
 
   // Loop over all of the basic blocks in the function, cloning them as
-  // appropriate.
+  // appropriate.  Note that we save BE this way in order to handle cloning of
+  // recursive functions into themselves.
   //
   for (Function::const_iterator BI = OldFunc->begin(), BE = OldFunc->end();
        BI != BE; ++BI) {
     const BasicBlock &BB = *BI;
-    assert(BB.getTerminator() && "BasicBlock doesn't have terminator!?!?");
     
     // Create a new basic block to copy instructions into!
-    BasicBlock *CBB = new BasicBlock(BB.getName(), NewFunc);
+    BasicBlock *CBB = new BasicBlock("", NewFunc);
+    if (BB.hasName()) CBB->setName(BB.getName()+NameSuffix);
     ValueMap[&BB] = CBB;                       // Add basic block mapping.
 
     // Loop over all instructions copying them over...
     for (BasicBlock::const_iterator II = BB.begin(), IE = BB.end();
          II != IE; ++II) {
       Instruction *NewInst = II->clone();
-      NewInst->setName(II->getName());       // Name is not cloned...
+      if (II->hasName())
+        NewInst->setName(II->getName()+NameSuffix);     // Name is not cloned...
       CBB->getInstList().push_back(NewInst);
       ValueMap[II] = NewInst;                // Add instruction map to value.
     }
+
+    if (ReturnInst *RI = dyn_cast<ReturnInst>(CBB->getTerminator()))
+      Returns.push_back(RI);
   }
 
   // Loop over all of the instructions in the function, fixing up operand 





More information about the llvm-commits mailing list