mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-23 14:25:07 +00:00
Add support for external calls that we know how to constant fold. This implements
ctor-list-opt.ll:CTOR8 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23465 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1451,13 +1451,21 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
|
|||||||
Function *Callee = dyn_cast<Function>(getVal(Values, CI->getOperand(0)));
|
Function *Callee = dyn_cast<Function>(getVal(Values, CI->getOperand(0)));
|
||||||
if (!Callee) return false; // Cannot resolve.
|
if (!Callee) return false; // Cannot resolve.
|
||||||
|
|
||||||
if (Callee->isExternal() || Callee->getFunctionType()->isVarArg()) {
|
|
||||||
return false; // TODO: Constant fold calls.
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Constant*> Formals;
|
std::vector<Constant*> Formals;
|
||||||
for (unsigned i = 1, e = CI->getNumOperands(); i != e; ++i)
|
for (unsigned i = 1, e = CI->getNumOperands(); i != e; ++i)
|
||||||
Formals.push_back(getVal(Values, CI->getOperand(i)));
|
Formals.push_back(getVal(Values, CI->getOperand(i)));
|
||||||
|
|
||||||
|
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;
|
Constant *RetVal;
|
||||||
|
|
||||||
// Execute the call, if successful, use the return value.
|
// Execute the call, if successful, use the return value.
|
||||||
@@ -1465,6 +1473,7 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
|
|||||||
MutatedMemory, AllocaTmps))
|
MutatedMemory, AllocaTmps))
|
||||||
return false;
|
return false;
|
||||||
InstResult = RetVal;
|
InstResult = RetVal;
|
||||||
|
}
|
||||||
} else if (TerminatorInst *TI = dyn_cast<TerminatorInst>(CurInst)) {
|
} else if (TerminatorInst *TI = dyn_cast<TerminatorInst>(CurInst)) {
|
||||||
BasicBlock *NewBB = 0;
|
BasicBlock *NewBB = 0;
|
||||||
if (BranchInst *BI = dyn_cast<BranchInst>(CurInst)) {
|
if (BranchInst *BI = dyn_cast<BranchInst>(CurInst)) {
|
||||||
|
Reference in New Issue
Block a user