mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-25 21:16:19 +00:00
Add SCCP support for constant folding calls, implementing:
test/Regression/Transforms/SCCP/calltest.ll llvm-svn: 12921
This commit is contained in:
parent
486436b5ad
commit
545e77c9d5
@ -29,6 +29,7 @@
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Type.h"
|
||||
#include "llvm/Support/InstVisitor.h"
|
||||
#include "llvm/Transforms/Utils/Local.h"
|
||||
#include "Support/Debug.h"
|
||||
#include "Support/Statistic.h"
|
||||
#include "Support/STLExtras.h"
|
||||
@ -220,7 +221,7 @@ private:
|
||||
void visitStoreInst (Instruction &I) { /*returns void*/ }
|
||||
void visitLoadInst (LoadInst &I);
|
||||
void visitGetElementPtrInst(GetElementPtrInst &I);
|
||||
void visitCallInst (Instruction &I) { markOverdefined(&I); }
|
||||
void visitCallInst (CallInst &I);
|
||||
void visitInvokeInst (TerminatorInst &I) {
|
||||
if (I.getType() != Type::VoidTy) markOverdefined(&I);
|
||||
visitTerminatorInst(I);
|
||||
@ -777,3 +778,34 @@ void SCCP::visitLoadInst(LoadInst &I) {
|
||||
// Bail out.
|
||||
markOverdefined(IV, &I);
|
||||
}
|
||||
|
||||
void SCCP::visitCallInst(CallInst &I) {
|
||||
InstVal &IV = ValueState[&I];
|
||||
if (IV.isOverdefined()) return;
|
||||
|
||||
Function *F = I.getCalledFunction();
|
||||
if (F == 0 || !canConstantFoldCallTo(F)) {
|
||||
markOverdefined(IV, &I);
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<Constant*> Operands;
|
||||
Operands.reserve(I.getNumOperands()-1);
|
||||
|
||||
for (unsigned i = 1, e = I.getNumOperands(); i != e; ++i) {
|
||||
InstVal &State = getValueState(I.getOperand(i));
|
||||
if (State.isUndefined())
|
||||
return; // Operands are not resolved yet...
|
||||
else if (State.isOverdefined()) {
|
||||
markOverdefined(IV, &I);
|
||||
return;
|
||||
}
|
||||
assert(State.isConstant() && "Unknown state!");
|
||||
Operands.push_back(State.getConstant());
|
||||
}
|
||||
|
||||
if (Constant *C = ConstantFoldCall(F, Operands))
|
||||
markConstant(IV, &I, C);
|
||||
else
|
||||
markOverdefined(IV, &I);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user