mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-12 07:40:58 +00:00
[PM] CorrelatedValuePropagation: pass state to function. NFCI.
While here, convert the logic of the pass to use static function(s). This is in preparation for porting this pass to the new PM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270734 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
068cdecac2
commit
92cd490ebb
@ -40,19 +40,6 @@ STATISTIC(NumSDivs, "Number of sdiv converted to udiv");
|
||||
namespace {
|
||||
class CorrelatedValuePropagation : public FunctionPass {
|
||||
LazyValueInfo *LVI;
|
||||
|
||||
bool processSelect(SelectInst *SI);
|
||||
bool processPHI(PHINode *P);
|
||||
bool processMemAccess(Instruction *I);
|
||||
bool processCmp(CmpInst *C);
|
||||
bool processSwitch(SwitchInst *SI);
|
||||
bool processCallSite(CallSite CS);
|
||||
bool processSDiv(BinaryOperator *SDI);
|
||||
|
||||
/// Return a constant value for V usable at At and everything it
|
||||
/// dominates. If no such Constant can be found, return nullptr.
|
||||
Constant *getConstantAt(Value *V, Instruction *At);
|
||||
|
||||
public:
|
||||
static char ID;
|
||||
CorrelatedValuePropagation(): FunctionPass(ID) {
|
||||
@ -80,7 +67,7 @@ Pass *llvm::createCorrelatedValuePropagationPass() {
|
||||
return new CorrelatedValuePropagation();
|
||||
}
|
||||
|
||||
bool CorrelatedValuePropagation::processSelect(SelectInst *S) {
|
||||
static bool processSelect(SelectInst *S, LazyValueInfo *LVI) {
|
||||
if (S->getType()->isVectorTy()) return false;
|
||||
if (isa<Constant>(S->getOperand(0))) return false;
|
||||
|
||||
@ -103,7 +90,7 @@ bool CorrelatedValuePropagation::processSelect(SelectInst *S) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CorrelatedValuePropagation::processPHI(PHINode *P) {
|
||||
static bool processPHI(PHINode *P, LazyValueInfo *LVI) {
|
||||
bool Changed = false;
|
||||
|
||||
BasicBlock *BB = P->getParent();
|
||||
@ -171,7 +158,7 @@ bool CorrelatedValuePropagation::processPHI(PHINode *P) {
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool CorrelatedValuePropagation::processMemAccess(Instruction *I) {
|
||||
static bool processMemAccess(Instruction *I, LazyValueInfo *LVI) {
|
||||
Value *Pointer = nullptr;
|
||||
if (LoadInst *L = dyn_cast<LoadInst>(I))
|
||||
Pointer = L->getPointerOperand();
|
||||
@ -192,7 +179,7 @@ bool CorrelatedValuePropagation::processMemAccess(Instruction *I) {
|
||||
/// or range information is sufficient to prove this comparison. Even for
|
||||
/// local conditions, this can sometimes prove conditions instcombine can't by
|
||||
/// exploiting range information.
|
||||
bool CorrelatedValuePropagation::processCmp(CmpInst *C) {
|
||||
static bool processCmp(CmpInst *C, LazyValueInfo *LVI) {
|
||||
Value *Op0 = C->getOperand(0);
|
||||
Constant *Op1 = dyn_cast<Constant>(C->getOperand(1));
|
||||
if (!Op1) return false;
|
||||
@ -227,7 +214,7 @@ bool CorrelatedValuePropagation::processCmp(CmpInst *C) {
|
||||
/// on that edge. Cases that cannot fire no matter what the incoming edge can
|
||||
/// safely be removed. If a case fires on every incoming edge then the entire
|
||||
/// switch can be removed and replaced with a branch to the case destination.
|
||||
bool CorrelatedValuePropagation::processSwitch(SwitchInst *SI) {
|
||||
static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI) {
|
||||
Value *Cond = SI->getCondition();
|
||||
BasicBlock *BB = SI->getParent();
|
||||
|
||||
@ -308,7 +295,7 @@ bool CorrelatedValuePropagation::processSwitch(SwitchInst *SI) {
|
||||
|
||||
/// processCallSite - Infer nonnull attributes for the arguments at the
|
||||
/// specified callsite.
|
||||
bool CorrelatedValuePropagation::processCallSite(CallSite CS) {
|
||||
static bool processCallSite(CallSite CS, LazyValueInfo *LVI) {
|
||||
SmallVector<unsigned, 4> Indices;
|
||||
unsigned ArgNo = 0;
|
||||
|
||||
@ -344,7 +331,7 @@ bool CorrelatedValuePropagation::processCallSite(CallSite CS) {
|
||||
/// positive. If this is the case, replace the SDiv with a UDiv. Even for local
|
||||
/// conditions, this can sometimes prove conditions instcombine can't by
|
||||
/// exploiting range information.
|
||||
bool CorrelatedValuePropagation::processSDiv(BinaryOperator *SDI) {
|
||||
static bool processSDiv(BinaryOperator *SDI, LazyValueInfo *LVI) {
|
||||
if (SDI->getType()->isVectorTy())
|
||||
return false;
|
||||
|
||||
@ -375,7 +362,7 @@ bool CorrelatedValuePropagation::processSDiv(BinaryOperator *SDI) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Constant *CorrelatedValuePropagation::getConstantAt(Value *V, Instruction *At) {
|
||||
static Constant *getConstantAt(Value *V, Instruction *At, LazyValueInfo *LVI) {
|
||||
if (Constant *C = LVI->getConstant(V, At->getParent(), At))
|
||||
return C;
|
||||
|
||||
@ -412,25 +399,25 @@ bool CorrelatedValuePropagation::runOnFunction(Function &F) {
|
||||
Instruction *II = &*BI++;
|
||||
switch (II->getOpcode()) {
|
||||
case Instruction::Select:
|
||||
BBChanged |= processSelect(cast<SelectInst>(II));
|
||||
BBChanged |= processSelect(cast<SelectInst>(II), LVI);
|
||||
break;
|
||||
case Instruction::PHI:
|
||||
BBChanged |= processPHI(cast<PHINode>(II));
|
||||
BBChanged |= processPHI(cast<PHINode>(II), LVI);
|
||||
break;
|
||||
case Instruction::ICmp:
|
||||
case Instruction::FCmp:
|
||||
BBChanged |= processCmp(cast<CmpInst>(II));
|
||||
BBChanged |= processCmp(cast<CmpInst>(II), LVI);
|
||||
break;
|
||||
case Instruction::Load:
|
||||
case Instruction::Store:
|
||||
BBChanged |= processMemAccess(II);
|
||||
BBChanged |= processMemAccess(II, LVI);
|
||||
break;
|
||||
case Instruction::Call:
|
||||
case Instruction::Invoke:
|
||||
BBChanged |= processCallSite(CallSite(II));
|
||||
BBChanged |= processCallSite(CallSite(II), LVI);
|
||||
break;
|
||||
case Instruction::SDiv:
|
||||
BBChanged |= processSDiv(cast<BinaryOperator>(II));
|
||||
BBChanged |= processSDiv(cast<BinaryOperator>(II), LVI);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -438,7 +425,7 @@ bool CorrelatedValuePropagation::runOnFunction(Function &F) {
|
||||
Instruction *Term = FI->getTerminator();
|
||||
switch (Term->getOpcode()) {
|
||||
case Instruction::Switch:
|
||||
BBChanged |= processSwitch(cast<SwitchInst>(Term));
|
||||
BBChanged |= processSwitch(cast<SwitchInst>(Term), LVI);
|
||||
break;
|
||||
case Instruction::Ret: {
|
||||
auto *RI = cast<ReturnInst>(Term);
|
||||
@ -448,7 +435,7 @@ bool CorrelatedValuePropagation::runOnFunction(Function &F) {
|
||||
auto *RetVal = RI->getReturnValue();
|
||||
if (!RetVal) break; // handle "ret void"
|
||||
if (isa<Constant>(RetVal)) break; // nothing to do
|
||||
if (auto *C = getConstantAt(RetVal, RI)) {
|
||||
if (auto *C = getConstantAt(RetVal, RI, LVI)) {
|
||||
++NumReturns;
|
||||
RI->replaceUsesOfWith(RetVal, C);
|
||||
BBChanged = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user