[llvm-commits] CVS: llvm/lib/Transforms/IPO/GlobalOpt.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Sep 26 22:02:55 PDT 2005



Changes in directory llvm/lib/Transforms/IPO:

GlobalOpt.cpp updated: 1.56 -> 1.57
---
Log message:

Add support for external calls that we know how to constant fold.  This implements
ctor-list-opt.ll:CTOR8


---
Diffs of the changes:  (+20 -11)

 GlobalOpt.cpp |   31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)


Index: llvm/lib/Transforms/IPO/GlobalOpt.cpp
diff -u llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.56 llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.57
--- llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.56	Mon Sep 26 23:50:03 2005
+++ llvm/lib/Transforms/IPO/GlobalOpt.cpp	Tue Sep 27 00:02:43 2005
@@ -1450,21 +1450,30 @@
       // Resolve function pointers.
       Function *Callee = dyn_cast<Function>(getVal(Values, CI->getOperand(0)));
       if (!Callee) return false;  // Cannot resolve.
-      
-      if (Callee->isExternal() || Callee->getFunctionType()->isVarArg()) {
-        return false;  // TODO: Constant fold calls.
-      }
-      
+
       std::vector<Constant*> Formals;
       for (unsigned i = 1, e = CI->getNumOperands(); i != e; ++i)
         Formals.push_back(getVal(Values, CI->getOperand(i)));
-      Constant *RetVal;
       
-      // Execute the call, if successful, use the return value.
-      if (!EvaluateFunction(Callee, RetVal, Formals, CallStack,
-                            MutatedMemory, AllocaTmps))
-        return false;
-      InstResult = RetVal;
+      if (Callee->isExternal()) {
+        // If this is a function we can constant fold, do it.
+        if (Constant *C = ConstantFoldCall(Callee, Formals)) {
+          InstResult = C;
+        } else {
+          return false;
+        }
+      } else {
+        if (Callee->getFunctionType()->isVarArg())
+          return false;
+        
+        Constant *RetVal;
+        
+        // Execute the call, if successful, use the return value.
+        if (!EvaluateFunction(Callee, RetVal, Formals, CallStack,
+                              MutatedMemory, AllocaTmps))
+          return false;
+        InstResult = RetVal;
+      }
     } else if (TerminatorInst *TI = dyn_cast<TerminatorInst>(CurInst)) {
       BasicBlock *NewBB = 0;
       if (BranchInst *BI = dyn_cast<BranchInst>(CurInst)) {






More information about the llvm-commits mailing list