mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-26 05:00:39 +00:00
Rewrite ScalarEvolution::hasOperand to use an explicit worklist instead
of recursion, to avoid excessive stack usage on deep expressions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156554 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e54874471c
commit
ac84461e5a
@ -6860,43 +6860,58 @@ bool ScalarEvolution::properlyDominates(const SCEV *S, const BasicBlock *BB) {
|
||||
}
|
||||
|
||||
bool ScalarEvolution::hasOperand(const SCEV *S, const SCEV *Op) const {
|
||||
switch (S->getSCEVType()) {
|
||||
case scConstant:
|
||||
return false;
|
||||
case scTruncate:
|
||||
case scZeroExtend:
|
||||
case scSignExtend: {
|
||||
const SCEVCastExpr *Cast = cast<SCEVCastExpr>(S);
|
||||
const SCEV *CastOp = Cast->getOperand();
|
||||
return Op == CastOp || hasOperand(CastOp, Op);
|
||||
}
|
||||
case scAddRecExpr:
|
||||
case scAddExpr:
|
||||
case scMulExpr:
|
||||
case scUMaxExpr:
|
||||
case scSMaxExpr: {
|
||||
const SCEVNAryExpr *NAry = cast<SCEVNAryExpr>(S);
|
||||
for (SCEVNAryExpr::op_iterator I = NAry->op_begin(), E = NAry->op_end();
|
||||
I != E; ++I) {
|
||||
const SCEV *NAryOp = *I;
|
||||
if (NAryOp == Op || hasOperand(NAryOp, Op))
|
||||
SmallVector<const SCEV *, 8> Worklist;
|
||||
Worklist.push_back(S);
|
||||
do {
|
||||
S = Worklist.pop_back_val();
|
||||
|
||||
switch (S->getSCEVType()) {
|
||||
case scConstant:
|
||||
break;
|
||||
case scTruncate:
|
||||
case scZeroExtend:
|
||||
case scSignExtend: {
|
||||
const SCEVCastExpr *Cast = cast<SCEVCastExpr>(S);
|
||||
const SCEV *CastOp = Cast->getOperand();
|
||||
if (Op == CastOp)
|
||||
return true;
|
||||
Worklist.push_back(CastOp);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case scUDivExpr: {
|
||||
const SCEVUDivExpr *UDiv = cast<SCEVUDivExpr>(S);
|
||||
const SCEV *LHS = UDiv->getLHS(), *RHS = UDiv->getRHS();
|
||||
return LHS == Op || hasOperand(LHS, Op) ||
|
||||
RHS == Op || hasOperand(RHS, Op);
|
||||
}
|
||||
case scUnknown:
|
||||
return false;
|
||||
case scCouldNotCompute:
|
||||
llvm_unreachable("Attempt to use a SCEVCouldNotCompute object!");
|
||||
default:
|
||||
llvm_unreachable("Unknown SCEV kind!");
|
||||
}
|
||||
case scAddRecExpr:
|
||||
case scAddExpr:
|
||||
case scMulExpr:
|
||||
case scUMaxExpr:
|
||||
case scSMaxExpr: {
|
||||
const SCEVNAryExpr *NAry = cast<SCEVNAryExpr>(S);
|
||||
for (SCEVNAryExpr::op_iterator I = NAry->op_begin(), E = NAry->op_end();
|
||||
I != E; ++I) {
|
||||
const SCEV *NAryOp = *I;
|
||||
if (NAryOp == Op)
|
||||
return true;
|
||||
Worklist.push_back(NAryOp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case scUDivExpr: {
|
||||
const SCEVUDivExpr *UDiv = cast<SCEVUDivExpr>(S);
|
||||
const SCEV *LHS = UDiv->getLHS(), *RHS = UDiv->getRHS();
|
||||
if (LHS == Op || RHS == Op)
|
||||
return true;
|
||||
Worklist.push_back(LHS);
|
||||
Worklist.push_back(RHS);
|
||||
break;
|
||||
}
|
||||
case scUnknown:
|
||||
break;
|
||||
case scCouldNotCompute:
|
||||
llvm_unreachable("Attempt to use a SCEVCouldNotCompute object!");
|
||||
default:
|
||||
llvm_unreachable("Unknown SCEV kind!");
|
||||
}
|
||||
} while (!Worklist.empty());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScalarEvolution::forgetMemoizedResults(const SCEV *S) {
|
||||
|
Loading…
Reference in New Issue
Block a user