diff options
| author | Chris Lattner <sabre@nondot.org> | 2005-09-27 05:02:43 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2005-09-27 05:02:43 +0000 |
| commit | 3d27e7f27f37e700a5d6124d010e32c4739f788c (patch) | |
| tree | 6d5c0e4681aed4338e8bc6f82ff3b3640162ee19 /llvm/lib/Transforms | |
| parent | 1f1fd227fb60c12e771067d0c5b9b41d8f30f10c (diff) | |
| download | bcm5719-llvm-3d27e7f27f37e700a5d6124d010e32c4739f788c.tar.gz bcm5719-llvm-3d27e7f27f37e700a5d6124d010e32c4739f788c.zip | |
Add support for external calls that we know how to constant fold. This implements
ctor-list-opt.ll:CTOR8
llvm-svn: 23465
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/IPO/GlobalOpt.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index a3cd8d4f15d..3b2eee05314 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -1450,21 +1450,30 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, // 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)) { |

