LLVM: llvm::SCEVExpander Class Reference (original) (raw)

This class uses information about analyze scalars to rewrite expressions in canonical form. More...

#include "[llvm/Transforms/Utils/ScalarEvolutionExpander.h](ScalarEvolutionExpander%5F8h%5Fsource.html)"

Public Member Functions
SCEVExpander (ScalarEvolution &se, const DataLayout &DL, const char *name, bool PreserveLCSSA=true)
Construct a SCEVExpander in "canonical" mode.
~SCEVExpander ()
void clear ()
Erase the contents of the InsertedExpressions map so that users trying to expand the same expression into multiple BasicBlocks or different places within the same BasicBlock can do so.
ScalarEvolution * getSE ()
const SmallVectorImpl< WeakVH > & getInsertedIVs () const
SmallVector< Instruction *, 32 > getAllInsertedInstructions () const
Return a vector containing all instructions inserted during expansion.
bool isHighCostExpansion (ArrayRef< const SCEV * > Exprs, Loop *L, unsigned Budget, const TargetTransformInfo *TTI, const Instruction *At)
Return true for expressions that can't be evaluated at runtime within given Budget.
LLVM_ABI Instruction * getIVIncOperand (Instruction *IncV, Instruction *InsertPos, bool allowScale)
Return the induction variable increment's IV operand.
LLVM_ABI bool hoistIVInc (Instruction *IncV, Instruction *InsertPos, bool RecomputePoisonFlags=false)
Utility for hoisting IncV (with all subexpressions requried for its computation) before InsertPos.
LLVM_ABI unsigned replaceCongruentIVs (Loop *L, const DominatorTree *DT, SmallVectorImpl< WeakTrackingVH > &DeadInsts, const TargetTransformInfo *TTI=nullptr)
replace congruent phis with their most canonical representative.
LLVM_ABI bool isSafeToExpand (const SCEV *S) const
Return true if the given expression is safe to expand in the sense that all materialized values are safe to speculate anywhere their operands are defined, and the expander is capable of expanding the expression.
LLVM_ABI bool isSafeToExpandAt (const SCEV *S, const Instruction *InsertionPoint) const
Return true if the given expression is safe to expand in the sense that all materialized values are defined and safe to speculate at the specified location and their operands are defined at this location.
LLVM_ABI Value * expandCodeFor (const SCEV *SH, Type *Ty, BasicBlock::iterator I)
Insert code to directly compute the specified SCEV expression into the program.
Value * expandCodeFor (const SCEV *SH, Type *Ty, Instruction *I)
LLVM_ABI Value * expandCodeFor (const SCEV *SH, Type *Ty=nullptr)
Insert code to directly compute the specified SCEV expression into the program.
LLVM_ABI Value * expandCodeForPredicate (const SCEVPredicate *Pred, Instruction *Loc)
Generates a code sequence that evaluates this predicate.
LLVM_ABI Value * expandComparePredicate (const SCEVComparePredicate *Pred, Instruction *Loc)
A specialized variant of expandCodeForPredicate, handling the case when we are expanding code for a SCEVComparePredicate.
LLVM_ABI Value * generateOverflowCheck (const SCEVAddRecExpr *AR, Instruction *Loc, bool Signed)
Generates code that evaluates if the AR expression will overflow.
LLVM_ABI Value * expandWrapPredicate (const SCEVWrapPredicate *P, Instruction *Loc)
A specialized variant of expandCodeForPredicate, handling the case when we are expanding code for a SCEVWrapPredicate.
LLVM_ABI Value * expandUnionPredicate (const SCEVUnionPredicate *Pred, Instruction *Loc)
A specialized variant of expandCodeForPredicate, handling the case when we are expanding code for a SCEVUnionPredicate.
void setIVIncInsertPos (const Loop *L, Instruction *Pos)
Set the current IV increment loop and position.
void setPostInc (const PostIncLoopSet &L)
Enable post-inc expansion for addrecs referring to the given loops.
void clearPostInc ()
Disable all post-inc expansion.
void disableCanonicalMode ()
Disable the behavior of expanding expressions in canonical form rather than in a more literal form.
void enableLSRMode ()
void setInsertPoint (Instruction *IP)
Set the current insertion point.
void setInsertPoint (BasicBlock::iterator IP)
void clearInsertPoint ()
Clear the current insertion point.
void SetCurrentDebugLocation (DebugLoc L)
Set location information used by debugging information.
DebugLoc getCurrentDebugLocation () const
Get location information used by debugging information.
bool isInsertedInstruction (Instruction *I) const
Return true if the specified instruction was inserted by the code rewriter.
void setChainedPhi (PHINode *PN)
LLVM_ABI bool hasRelatedExistingExpansion (const SCEV *S, const Instruction *At, Loop *L)
Determine whether there is an existing expansion of S that can be reused.
LLVM_ABI BasicBlock::iterator findInsertPointAfter (Instruction *I, Instruction *MustDominate) const
Returns a suitable insert point after I, that dominates MustDominate.
void eraseDeadInstructions (Value *Root)
Remove inserted instructions that are dead, e.g.
Public Member Functions inherited from llvm::SCEVVisitor< SCEVExpander, Value * >
Value * visit (const SCEV *S)
Value * visitCouldNotCompute (const SCEVCouldNotCompute *S)

This class uses information about analyze scalars to rewrite expressions in canonical form.

Clients should create an instance of this class when rewriting is needed, and destroy it when finished to allow the release of the associated memory.

Definition at line 64 of file ScalarEvolutionExpander.h.

~SCEVExpander()

llvm::SCEVExpander::~SCEVExpander ( ) inline

canReuseFlagsFromOriginalIVInc()

clear()

void llvm::SCEVExpander::clear ( ) inline

Erase the contents of the InsertedExpressions map so that users trying to expand the same expression into multiple BasicBlocks or different places within the same BasicBlock can do so.

Definition at line 211 of file ScalarEvolutionExpander.h.

Referenced by RunTermFold().

clearInsertPoint()

void llvm::SCEVExpander::clearInsertPoint ( ) inline

Clear the current insertion point.

This is useful if the instruction that had been serving as the insertion point may have been deleted.

Definition at line 400 of file ScalarEvolutionExpander.h.

clearPostInc()

void llvm::SCEVExpander::clearPostInc ( ) inline

disableCanonicalMode()

void llvm::SCEVExpander::disableCanonicalMode ( ) inline

Disable the behavior of expanding expressions in canonical form rather than in a more literal form.

Non-canonical mode is useful for late optimization passes.

Definition at line 381 of file ScalarEvolutionExpander.h.

enableLSRMode()

void llvm::SCEVExpander::enableLSRMode ( ) inline

eraseDeadInstructions()

void SCEVExpander::eraseDeadInstructions ( Value * Root )

Remove inserted instructions that are dead, e.g.

due to InstSimplifyFolder simplifications. Root is assumed to be used and won't be removed.

Definition at line 179 of file ScalarEvolutionExpander.cpp.

References llvm::append_range(), llvm::SmallPtrSetImpl< PtrType >::contains(), llvm::dyn_cast(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), getAllInsertedInstructions(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), isInsertedInstruction(), llvm::isInstructionTriviallyDead(), and llvm::SmallVectorImpl< T >::pop_back_val().

Referenced by llvm::addDiffRuntimeChecks().

expandCodeFor() [1/3]

Insert code to directly compute the specified SCEV expression into the program.

The code is inserted into the specified block.

Definition at line 1511 of file ScalarEvolutionExpander.cpp.

References expandCodeFor(), and setInsertPoint().

Referenced by llvm::addDiffRuntimeChecks(), expandCodeFor(), expandCodeFor(), llvm::VPlanTransforms::expandSCEVs(), llvm::LoopStructure::parseLoopStructure(), llvm::peelLoop(), llvm::LoopConstrainer::run(), RunTermFold(), splitLoopBound(), and llvm::UnrollRuntimeLoopRemainder().

expandCodeFor() [2/3]

expandCodeFor() [3/3]

expandCodeForPredicate()

expandComparePredicate()

expandUnionPredicate()

expandWrapPredicate()

findInsertPointAfter()

generateOverflowCheck()

Generates code that evaluates if the AR expression will overflow.

Definition at line 2160 of file ScalarEvolutionExpander.cpp.

References llvm::Add, assert(), llvm::IntegerType::get(), llvm::SCEVAddRecExpr::getLoop(), llvm::APInt::getMaxValue(), llvm::SCEVAddRecExpr::getStart(), llvm::SCEVAddRecExpr::getStepRecurrence(), llvm::SCEV::getType(), llvm::SCEVAddRecExpr::getType(), llvm::APInt::getZero(), llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::isa(), llvm::SCEVAddRecExpr::isAffine(), llvm::Mul, llvm::Signed, llvm::Sub, and llvm::APInt::zext().

Referenced by expandWrapPredicate().

getAllInsertedInstructions()

getCurrentDebugLocation()

DebugLoc llvm::SCEVExpander::getCurrentDebugLocation ( ) const inline

getInsertedIVs()

getIVIncOperand()

getSE()

hasRelatedExistingExpansion()

hoistIVInc()

Utility for hoisting IncV (with all subexpressions requried for its computation) before InsertPos.

hoistStep - Attempt to hoist a simple IV increment above InsertPos to make it available to other uses in this loop.

If RecomputePoisonFlags is set, drops all poison-generating flags from instructions being hoisted and tries to re-infer them in the new location. It should be used when we are going to introduce a new use in the new position that didn't exist before, and may trigger new UB in case of poison.

Recursively hoist any operands, until we reach a value that dominates InsertPos.

Definition at line 817 of file ScalarEvolutionExpander.cpp.

References llvm::cast(), llvm::dyn_cast(), llvm::SCEV::FlagNSW, llvm::SCEV::FlagNUW, llvm::ilist_node_impl< OptionsT >::getIterator(), getIVIncOperand(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), I, llvm::isa(), llvm::ScalarEvolution::maskFlags(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::reverse(), llvm::Instruction::setHasNoSignedWrap(), and llvm::Instruction::setHasNoUnsignedWrap().

isHighCostExpansion()

isInsertedInstruction()

bool llvm::SCEVExpander::isInsertedInstruction ( Instruction * I) const inline

isSafeToExpand()

isSafeToExpandAt()

replaceCongruentIVs()

replace congruent phis with their most canonical representative.

replaceCongruentIVs - Check for congruent phis in this loop header and replace them with their most canonical representative.

Return the number of phis eliminated.

Return the number of phis eliminated.

This does not depend on any SCEVExpander state but should be used in the same context that SCEVExpander is used.

Definition at line 1778 of file ScalarEvolutionExpander.cpp.

References llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::dbgs(), llvm::dyn_cast(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::Value::getType(), llvm::isa(), llvm::Type::isPointerTy(), llvm::make_pointer_range(), SCEV_DEBUG_WITH_TYPE, llvm::simplifyInstruction(), and llvm::stable_sort().

setChainedPhi()

void llvm::SCEVExpander::setChainedPhi ( PHINode * PN) inline

SetCurrentDebugLocation()

void llvm::SCEVExpander::SetCurrentDebugLocation ( DebugLoc L) inline

setInsertPoint() [1/2]

setInsertPoint() [2/2]

void llvm::SCEVExpander::setInsertPoint ( Instruction * IP) inline

Set the current insertion point.

This is useful if multiple calls to expandCodeFor() are going to be made with the same insert point and the insert point may be moved during one of the expansions (e.g. if the insert point is not a block terminator).

Definition at line 389 of file ScalarEvolutionExpander.h.

References assert().

Referenced by expandCodeFor().

setIVIncInsertPos()

setPostInc()

Enable post-inc expansion for addrecs referring to the given loops.

Post-inc expansion is only supported in non-canonical mode.

Definition at line 363 of file ScalarEvolutionExpander.h.

References assert().

SCEVExpanderCleaner

SCEVVisitor< SCEVExpander, Value * >


The documentation for this class was generated from the following files: