29 #define DEBUG_TYPE "correlated-value-propagation"
31 STATISTIC(NumPhis,
"Number of phis propagated");
32 STATISTIC(NumSelects,
"Number of selects propagated");
33 STATISTIC(NumMemAccess,
"Number of memory access targets propagated");
34 STATISTIC(NumCmps,
"Number of comparisons propagated");
35 STATISTIC(NumDeadCases,
"Number of switch cases removed");
63 "Value Propagation",
false,
false)
70 return new CorrelatedValuePropagation();
73 bool CorrelatedValuePropagation::processSelect(
SelectInst *S) {
75 if (isa<Constant>(S->
getOperand(0)))
return false;
81 if (!CI)
return false;
96 bool CorrelatedValuePropagation::processPHI(
PHINode *
P) {
102 if (isa<Constant>(Incoming))
continue;
116 if (
Constant *C = LVI->getConstantOnEdge(
143 DEBUG(
dbgs() <<
"CVP: Threading PHI over " << *SI <<
'\n');
164 bool CorrelatedValuePropagation::processMemAccess(
Instruction *
I) {
165 Value *Pointer =
nullptr;
166 if (
LoadInst *L = dyn_cast<LoadInst>(I))
167 Pointer = L->getPointerOperand();
171 if (isa<Constant>(Pointer))
return false;
174 if (!C)
return false;
186 bool CorrelatedValuePropagation::processCmp(
CmpInst *C) {
188 if (isa<Instruction>(Op0) &&
193 if (!Op1)
return false;
196 if (PI == PE)
return false;
208 if (Res != Result)
return false;
231 bool CorrelatedValuePropagation::processSwitch(
SwitchInst *SI) {
237 if (isa<Instruction>(Cond) && cast<Instruction>(Cond)->
getParent() == BB)
242 if (PB == PE)
return false;
246 bool Changed =
false;
274 if (Value != State) {
282 CI.getCaseSuccessor()->removePredecessor(BB);
310 bool CorrelatedValuePropagation::runOnFunction(
Function &
F) {
311 if (skipOptnoneFunction(F))
314 LVI = &getAnalysis<LazyValueInfo>();
316 bool FnChanged =
false;
319 bool BBChanged =
false;
324 BBChanged |= processSelect(cast<SelectInst>(II));
327 BBChanged |= processPHI(cast<PHINode>(II));
329 case Instruction::ICmp:
330 case Instruction::FCmp:
331 BBChanged |= processCmp(cast<CmpInst>(II));
335 BBChanged |= processMemAccess(II);
342 case Instruction::Switch:
343 BBChanged |= processSwitch(cast<SwitchInst>(Term));
347 FnChanged |= BBChanged;
Pass interface - Implemented by all 'passes'.
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
A parsed version of the target data layout string in and methods for querying it. ...
static ConstantInt * getFalse(LLVMContext &Context)
CaseIt case_end()
Returns a read/write iterator that points one past the last in the SwitchInst.
This class is the base class for the comparison instructions.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
STATISTIC(NumFunctions,"Total number of functions")
bool isOneValue() const
Returns true if the value is one.
CaseIt case_begin()
Returns a read/write iterator that points to the first case in SwitchInst.
LoadInst - an instruction for reading from memory.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
static Value * getPointerOperand(Instruction &Inst)
SelectInst - This class represents the LLVM 'select' instruction.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldTerminator - If a terminator instruction is predicated on a constant value, convert it into an unconditional branch to the constant destination.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Windows NT (Windows on ARM)
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
unsigned getNumIncomingValues() const
getNumIncomingValues - Return the number of incoming edges
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Pass * createCorrelatedValuePropagationPass()
LLVM Basic Block Representation.
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
This is an important base class in LLVM.
const Value * getCondition() const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isZeroValue() const
Return true if the value is negative zero or null value.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Represent the analysis usage information of a pass.
BasicBlock * getIncomingBlock(unsigned i) const
getIncomingBlock - Return incoming basic block number i.
FunctionPass class - This class is used to implement most global optimizations.
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
Predicate getPredicate() const
Return the predicate for this instruction.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
const Value * getTrueValue() const
Tristate
This is used to return true/false/dunno results.
This is the shared class of boolean and integer constants.
void initializeCorrelatedValuePropagationPass(PassRegistry &)
Value * getIncomingValue(unsigned i) const
getIncomingValue - Return incoming value number x
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
static ConstantInt * getTrue(LLVMContext &Context)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Value * getCondition() const
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void setCondition(Value *V)
void removeCase(CaseIt i)
removeCase - This method removes the specified case and its successor from the switch instruction...
unsigned getNumCases() const
getNumCases - return the number of 'cases' in this switch instruction, except the default case ...
SwitchInst - Multiway switch.
This pass computes, caches, and vends lazy value constraint information.
LLVM Value Representation.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
static const Function * getParent(const Value *V)
const Value * getFalseValue() const
Value * SimplifyInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr)
SimplifyInstruction - See if we can compute a simplified version of this instruction.
void setIncomingValue(unsigned i, Value *V)
const BasicBlock * getParent() const
bool isOne() const
This is just a convenience method to make client code smaller for a common case.