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

Chris Lattner lattner at cs.uiuc.edu
Fri May 26 18:28:17 PDT 2006



Changes in directory llvm/lib/Transforms/Utils:

InlineFunction.cpp updated: 1.41 -> 1.42
---
Log message:

Switch the inliner over to using CloneAndPruneFunctionInto.  This effectively
makes it so that it constant folds instructions on the fly.  This is good
for several reasons:

0. Many instructions are constant foldable after inlining, particularly if
   inlining a call with constant arguments.
1. Without this, the inliner has to allocate memory for all of the instructions
   that can be constant folded, then a subsequent pass has to delete them.  This
   gets the job done without this extra work.
2. This makes the inliner *pass* a bit more aggressive: in particular, it
   partially solves a phase order issue where the inliner would inline lots
   of code that folds away to nothing, but think that the resultant function
   is big because of this code that will be gone.  Now the code never exists.

This is the first part of a 2-step process.  The second part will be smart
enough to see when this implicit constant folding propagates a constant into
a branch or switch instruction, making CFG edges dead.

This implements Transforms/Inline/inline_constprop.ll



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

 InlineFunction.cpp |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)


Index: llvm/lib/Transforms/Utils/InlineFunction.cpp
diff -u llvm/lib/Transforms/Utils/InlineFunction.cpp:1.41 llvm/lib/Transforms/Utils/InlineFunction.cpp:1.42
--- llvm/lib/Transforms/Utils/InlineFunction.cpp:1.41	Sat Jan 14 14:07:50 2006
+++ llvm/lib/Transforms/Utils/InlineFunction.cpp	Fri May 26 20:28:04 2006
@@ -193,20 +193,24 @@
   std::vector<ReturnInst*> Returns;
   ClonedCodeInfo InlinedFunctionInfo;
   { // Scope to destroy ValueMap after cloning.
-    // Calculate the vector of arguments to pass into the function cloner...
     std::map<const Value*, Value*> ValueMap;
+
+    // Calculate the vector of arguments to pass into the function cloner, which
+    // matches up the formal to the actual argument values.
     assert(std::distance(CalledFunc->arg_begin(), CalledFunc->arg_end()) ==
            std::distance(CS.arg_begin(), CS.arg_end()) &&
            "No varargs calls can be inlined!");
-
     CallSite::arg_iterator AI = CS.arg_begin();
     for (Function::const_arg_iterator I = CalledFunc->arg_begin(),
            E = CalledFunc->arg_end(); I != E; ++I, ++AI)
       ValueMap[I] = *AI;
 
-    // Clone the entire body of the callee into the caller.
-    CloneFunctionInto(Caller, CalledFunc, ValueMap, Returns, ".i",
-                      &InlinedFunctionInfo);
+    // We want the inliner to prune the code as it copies.  We would LOVE to
+    // have no dead or constant instructions leftover after inlining occurs
+    // (which can happen, e.g., because an argument was constant), but we'll be
+    // happy with whatever the cloner can do.
+    CloneAndPruneFunctionInto(Caller, CalledFunc, ValueMap, Returns, ".i",
+                              &InlinedFunctionInfo);
   }
 
   // Remember the first block that is newly cloned over.






More information about the llvm-commits mailing list