LLVM  6.0.0svn
Classes | Public Member Functions | Friends | List of all members
llvm::SCEVExpander Class Reference

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

#include "llvm/Analysis/ScalarEvolutionExpander.h"

Inheritance diagram for llvm::SCEVExpander:
Inheritance graph
[legend]
Collaboration diagram for llvm::SCEVExpander:
Collaboration graph
[legend]

Public Member Functions

 SCEVExpander (ScalarEvolution &se, const DataLayout &DL, const char *name)
 Construct a SCEVExpander in "canonical" mode. More...
 
 ~SCEVExpander ()
 
void setDebugType (const char *s)
 
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. More...
 
bool isHighCostExpansion (const SCEV *Expr, Loop *L, const Instruction *At=nullptr)
 Return true for expressions that may incur non-trivial cost to evaluate at runtime. More...
 
PHINodegetOrInsertCanonicalInductionVariable (const Loop *L, Type *Ty)
 This method returns the canonical induction variable of the specified type for the specified loop (inserting one if there is none). More...
 
InstructiongetIVIncOperand (Instruction *IncV, Instruction *InsertPos, bool allowScale)
 Return the induction variable increment's IV operand. More...
 
bool hoistIVInc (Instruction *IncV, Instruction *InsertPos)
 Utility for hoisting an IV increment. More...
 
unsigned replaceCongruentIVs (Loop *L, const DominatorTree *DT, SmallVectorImpl< WeakTrackingVH > &DeadInsts, const TargetTransformInfo *TTI=nullptr)
 replace congruent phis with their most canonical representative. More...
 
ValueexpandCodeFor (const SCEV *SH, Type *Ty, Instruction *I)
 Insert code to directly compute the specified SCEV expression into the program. More...
 
ValueexpandCodeFor (const SCEV *SH, Type *Ty=nullptr)
 Insert code to directly compute the specified SCEV expression into the program. More...
 
ValueexpandCodeForPredicate (const SCEVPredicate *Pred, Instruction *Loc)
 Generates a code sequence that evaluates this predicate. More...
 
ValueexpandEqualPredicate (const SCEVEqualPredicate *Pred, Instruction *Loc)
 A specialized variant of expandCodeForPredicate, handling the case when we are expanding code for a SCEVEqualPredicate. More...
 
ValuegenerateOverflowCheck (const SCEVAddRecExpr *AR, Instruction *Loc, bool Signed)
 Generates code that evaluates if the AR expression will overflow. More...
 
ValueexpandWrapPredicate (const SCEVWrapPredicate *P, Instruction *Loc)
 A specialized variant of expandCodeForPredicate, handling the case when we are expanding code for a SCEVWrapPredicate. More...
 
ValueexpandUnionPredicate (const SCEVUnionPredicate *Pred, Instruction *Loc)
 A specialized variant of expandCodeForPredicate, handling the case when we are expanding code for a SCEVUnionPredicate. More...
 
void setIVIncInsertPos (const Loop *L, Instruction *Pos)
 Set the current IV increment loop and position. More...
 
void setPostInc (const PostIncLoopSet &L)
 Enable post-inc expansion for addrecs referring to the given loops. More...
 
void clearPostInc ()
 Disable all post-inc expansion. More...
 
void disableCanonicalMode ()
 Disable the behavior of expanding expressions in canonical form rather than in a more literal form. More...
 
void enableLSRMode ()
 
void setInsertPoint (Instruction *IP)
 Set the current insertion point. More...
 
void clearInsertPoint ()
 Clear the current insertion point. More...
 
bool isInsertedInstruction (Instruction *I) const
 Return true if the specified instruction was inserted by the code rewriter. More...
 
void setChainedPhi (PHINode *PN)
 
ValuegetExactExistingExpansion (const SCEV *S, const Instruction *At, Loop *L)
 Try to find existing LLVM IR value for S available at the point At. More...
 
Optional< ScalarEvolution::ValueOffsetPair > getRelatedExistingExpansion (const SCEV *S, const Instruction *At, Loop *L)
 Try to find the ValueOffsetPair for S. More...
 
- Public Member Functions inherited from llvm::SCEVVisitor< SCEVExpander, Value *>
Valuevisit (const SCEV *S)
 
ValuevisitCouldNotCompute (const SCEVCouldNotCompute *S)
 

Friends

struct SCEVVisitor< SCEVExpander, Value *>
 

Detailed Description

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 39 of file ScalarEvolutionExpander.h.

Constructor & Destructor Documentation

◆ SCEVExpander()

llvm::SCEVExpander::SCEVExpander ( ScalarEvolution se,
const DataLayout DL,
const char name 
)
inlineexplicit

Construct a SCEVExpander in "canonical" mode.

Definition at line 135 of file ScalarEvolutionExpander.h.

◆ ~SCEVExpander()

llvm::SCEVExpander::~SCEVExpander ( )
inline

Definition at line 145 of file ScalarEvolutionExpander.h.

References assert(), and llvm::SmallVectorBase::empty().

Member Function Documentation

◆ 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 157 of file ScalarEvolutionExpander.h.

References llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::clear(), and llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::clear().

Referenced by genLoopLimit(), and mayLoopAccessLocation().

◆ 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 272 of file ScalarEvolutionExpander.h.

References llvm::IRBuilderBase::ClearInsertionPoint().

Referenced by ConvertToSInt().

◆ 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 257 of file ScalarEvolutionExpander.h.

Referenced by genLoopLimit().

◆ enableLSRMode()

void llvm::SCEVExpander::enableLSRMode ( )
inline

Definition at line 259 of file ScalarEvolutionExpander.h.

◆ expandCodeFor() [1/2]

Value * SCEVExpander::expandCodeFor ( const SCEV SH,
Type Ty,
Instruction I 
)

◆ expandCodeFor() [2/2]

Value * SCEVExpander::expandCodeFor ( const SCEV SH,
Type Ty = nullptr 
)

◆ expandCodeForPredicate()

Value * SCEVExpander::expandCodeForPredicate ( const SCEVPredicate Pred,
Instruction Loc 
)

Generates a code sequence that evaluates this predicate.

The inserted instructions will be at position Loc. The result will be of type i1 and will have a value of 0 when the predicate is false and 1 otherwise.

Definition at line 2091 of file ScalarEvolutionExpander.cpp.

References assert(), llvm::SCEVPredicate::getKind(), llvm_unreachable, llvm::SCEVPredicate::P_Equal, llvm::SCEVPredicate::P_Union, and llvm::SCEVPredicate::P_Wrap.

Referenced by isHighCostExpansion().

◆ expandEqualPredicate()

Value * SCEVExpander::expandEqualPredicate ( const SCEVEqualPredicate Pred,
Instruction Loc 
)

A specialized variant of expandCodeForPredicate, handling the case when we are expanding code for a SCEVEqualPredicate.

Definition at line 2107 of file ScalarEvolutionExpander.cpp.

References llvm::SCEVEqualPredicate::getLHS(), llvm::SCEVEqualPredicate::getRHS(), llvm::SCEV::getType(), and I.

Referenced by isHighCostExpansion().

◆ expandUnionPredicate()

Value * SCEVExpander::expandUnionPredicate ( const SCEVUnionPredicate Pred,
Instruction Loc 
)

◆ expandWrapPredicate()

Value * SCEVExpander::expandWrapPredicate ( const SCEVWrapPredicate P,
Instruction Loc 
)

◆ generateOverflowCheck()

Value * SCEVExpander::generateOverflowCheck ( const SCEVAddRecExpr AR,
Instruction Loc,
bool  Signed 
)

◆ getExactExistingExpansion()

Value * SCEVExpander::getExactExistingExpansion ( const SCEV S,
const Instruction At,
Loop L 
)

Try to find existing LLVM IR value for S available at the point At.

Definition at line 1965 of file ScalarEvolutionExpander.cpp.

References llvm::Optional< T >::getValue().

Referenced by ConvertToSInt(), and setChainedPhi().

◆ getIVIncOperand()

Instruction * SCEVExpander::getIVIncOperand ( Instruction IncV,
Instruction InsertPos,
bool  allowScale 
)

Return the induction variable increment's IV operand.

getIVIncOperand returns an induction variable increment's induction variable operand.

If allowScale is set, any type of GEP is allowed as long as the nonIV operands dominate InsertPos.

If allowScale is not set, ensure that a GEP increment conforms to one of the simple patterns generated by getAddRecExprPHILiterally and expandAddtoGEP. If the pattern isn't recognized, return NULL.

Definition at line 896 of file ScalarEvolutionExpander.cpp.

References llvm::MCID::Add, AS, llvm::dyn_cast(), E, llvm::Type::getInt1PtrTy(), llvm::Type::getInt8PtrTy(), llvm::User::getNumOperands(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Value::getType(), I, llvm::User::op_begin(), and llvm::User::op_end().

Referenced by isHighCostExpansion().

◆ getOrInsertCanonicalInductionVariable()

PHINode * SCEVExpander::getOrInsertCanonicalInductionVariable ( const Loop L,
Type Ty 
)

This method returns the canonical induction variable of the specified type for the specified loop (inserting one if there is none).

getOrInsertCanonicalInductionVariable - This method returns the canonical induction variable of the specified type for the specified loop (inserting one if there is none).

A canonical induction variable starts at zero and steps by one on each iteration.

Definition at line 1802 of file ScalarEvolutionExpander.cpp.

References assert(), llvm::SCEV::FlagAnyWrap, llvm::BasicBlock::front(), llvm::LoopBase< BlockT, LoopT >::getHeader(), H, and llvm::Type::isIntegerTy().

Referenced by isHighCostExpansion().

◆ getRelatedExistingExpansion()

Optional< ScalarEvolution::ValueOffsetPair > SCEVExpander::getRelatedExistingExpansion ( const SCEV S,
const Instruction At,
Loop L 
)

Try to find the ValueOffsetPair for S.

The function is mainly used to check whether S can be expanded cheaply. If this returns a non-None value, we know we can codegen the ValueOffsetPair into a suitable expansion identical with S so that S can be expanded cheaply.

L is a hint which tells in which loop to look for the suitable value. On success return value which is equivalent to the expanded S at point At. Return nullptr if value was not found.

Note that this function does not perform an exhaustive search. I.e if it didn't find any value it does not mean that there is no such value.

Definition at line 1975 of file ScalarEvolutionExpander.cpp.

References llvm::BasicBlock::back(), getBitWidth(), llvm::Module::getDataLayout(), llvm::LoopBase< BlockT, LoopT >::getExitingBlock(), llvm::LoopBase< BlockT, LoopT >::getExitingBlocks(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::SCEV::getSCEVType(), llvm::SCEV::getType(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::DataLayout::isIllegalInteger(), llvm::PatternMatch::m_Br(), llvm::PatternMatch::m_ICmp(), llvm::PatternMatch::m_Instruction(), llvm::PatternMatch::match(), llvm::None, llvm::PPCISD::SC, llvm::scConstant, llvm::scSignExtend, llvm::scTruncate, llvm::scUnknown, and llvm::scZeroExtend.

Referenced by setChainedPhi().

◆ hoistIVInc()

bool SCEVExpander::hoistIVInc ( Instruction IncV,
Instruction InsertPos 
)

◆ isHighCostExpansion()

bool llvm::SCEVExpander::isHighCostExpansion ( const SCEV Expr,
Loop L,
const Instruction At = nullptr 
)
inline

Return true for expressions that may incur non-trivial cost to evaluate at runtime.

At is an optional parameter which specifies point in code where user is going to expand this expression. Sometimes this knowledge can lead to a more accurate cost estimation.

Definition at line 170 of file ScalarEvolutionExpander.h.

References expandCodeFor(), expandCodeForPredicate(), expandEqualPredicate(), expandUnionPredicate(), expandWrapPredicate(), generateOverflowCheck(), getIVIncOperand(), getOrInsertCanonicalInductionVariable(), hoistIVInc(), I, P, replaceCongruentIVs(), and Signed.

Referenced by canExpandBackedgeTakenCount(), ConvertToSInt(), and llvm::UnrollRuntimeLoopRemainder().

◆ isInsertedInstruction()

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

Return true if the specified instruction was inserted by the code rewriter.

If so, the client should not modify the instruction.

Definition at line 278 of file ScalarEvolutionExpander.h.

References llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::count().

◆ replaceCongruentIVs()

unsigned SCEVExpander::replaceCongruentIVs ( Loop L,
const DominatorTree DT,
SmallVectorImpl< WeakTrackingVH > &  DeadInsts,
const TargetTransformInfo TTI = nullptr 
)

◆ setChainedPhi()

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

◆ setDebugType()

void llvm::SCEVExpander::setDebugType ( const char s)
inline

Definition at line 151 of file ScalarEvolutionExpander.h.

Referenced by genLoopLimit(), and ReduceLoopStrength().

◆ setInsertPoint()

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 265 of file ScalarEvolutionExpander.h.

References assert(), and llvm::IRBuilderBase::SetInsertPoint().

◆ setIVIncInsertPos()

void llvm::SCEVExpander::setIVIncInsertPos ( const Loop L,
Instruction Pos 
)
inline

Set the current IV increment loop and position.

Definition at line 230 of file ScalarEvolutionExpander.h.

References assert().

◆ setPostInc()

void llvm::SCEVExpander::setPostInc ( const PostIncLoopSet L)
inline

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

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

Definition at line 239 of file ScalarEvolutionExpander.h.

References assert().

Friends And Related Function Documentation

◆ SCEVVisitor< SCEVExpander, Value *>

friend struct SCEVVisitor< SCEVExpander, Value * >
friend

Definition at line 131 of file ScalarEvolutionExpander.h.


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