[llvm] r270734 - [PM] CorrelatedValuePropagation: pass state to function. NFCI.
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Wed May 25 10:39:55 PDT 2016
Author: davide
Date: Wed May 25 12:39:54 2016
New Revision: 270734
URL: http://llvm.org/viewvc/llvm-project?rev=270734&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp?rev=270734&r1=270733&r2=270734&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp Wed May 25 12:39:54 2016
@@ -40,19 +40,6 @@ STATISTIC(NumSDivs, "Number of sdiv
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::createCorrelatedValuePropaga
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::process
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::process
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::process
/// 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::process
/// 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::process
/// 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::process
/// 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::process
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::runOnFu
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::runOnFu
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::runOnFu
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;
More information about the llvm-commits
mailing list