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

Chris Lattner lattner at cs.uiuc.edu
Wed Feb 4 15:34:05 PST 2004


Changes in directory llvm/lib/Transforms/Utils:

InlineFunction.cpp updated: 1.21 -> 1.22

---
Log message:

Two changes:
  1. Don't scan to the end of alloca instructions in the caller function to
     insert inlined allocas, just insert at the top.  This saves a lot of
     time inlining into functions with a lot of allocas.
  2. Use splice to move the alloca instructions over, instead of remove/insert.
     This allows us to transfer a block at a time, and eliminates a bunch of
     silly symbol table manipulations.

This speeds up the inliner on the testcase in PR209 from 1.73s -> 1.04s (67%)


---
Diffs of the changes:  (+12 -5)

Index: llvm/lib/Transforms/Utils/InlineFunction.cpp
diff -u llvm/lib/Transforms/Utils/InlineFunction.cpp:1.21 llvm/lib/Transforms/Utils/InlineFunction.cpp:1.22
--- llvm/lib/Transforms/Utils/InlineFunction.cpp:1.21	Tue Feb  3 22:17:06 2004
+++ llvm/lib/Transforms/Utils/InlineFunction.cpp	Wed Feb  4 15:33:42 2004
@@ -73,7 +73,7 @@
     // Clone the entire body of the callee into the caller.  
     CloneFunctionInto(Caller, CalledFunc, ValueMap, Returns, ".i");
   }    
-  
+
   // Remember the first block that is newly cloned over.
   Function::iterator FirstNewBlock = LastBlock; ++FirstNewBlock;
 
@@ -84,14 +84,21 @@
   //
   if (isa<AllocaInst>(FirstNewBlock->begin())) {
     BasicBlock::iterator InsertPoint = Caller->begin()->begin();
-    while (isa<AllocaInst>(InsertPoint)) ++InsertPoint;
-    
     for (BasicBlock::iterator I = FirstNewBlock->begin(),
            E = FirstNewBlock->end(); I != E; )
       if (AllocaInst *AI = dyn_cast<AllocaInst>(I++))
         if (isa<Constant>(AI->getArraySize())) {
-          FirstNewBlock->getInstList().remove(AI);
-          Caller->front().getInstList().insert(InsertPoint, AI);      
+          // Scan for the block of allocas that we can move over.
+          while (isa<AllocaInst>(I) &&
+                 isa<Constant>(cast<AllocaInst>(I)->getArraySize()))
+            ++I;
+
+          // Transfer all of the allocas over in a block.  Using splice means
+          // that they instructions aren't removed from the symbol table, then
+          // reinserted.
+          Caller->front().getInstList().splice(InsertPoint,
+                                               FirstNewBlock->getInstList(),
+                                               AI, I);
         }
   }
 





More information about the llvm-commits mailing list