Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
LoopInterchange.cpp File Reference

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "loop-interchange"

Functions

 STATISTIC (LoopsInterchanged, "Number of loops interchanged")
static bool noDuplicateRulesAndIgnore (ArrayRef< RuleTy > Rules)
static void printDepMatrix (CharMatrix &DepMatrix)
static bool inThisOrder (const Instruction *Src, const Instruction *Dst)
 Return true if Src appears before Dst in the same basic block.
static bool populateDependencyMatrix (CharMatrix &DepMatrix, unsigned Level, Loop *L, DependenceInfo *DI, ScalarEvolution *SE, OptimizationRemarkEmitter *ORE)
static void interChangeDependencies (CharMatrix &DepMatrix, unsigned FromIndx, unsigned ToIndx)
static std::optional< boolisLexicographicallyPositive (ArrayRef< char > DV, unsigned Begin, unsigned End)
static bool isLegalToInterChangeLoops (CharMatrix &DepMatrix, unsigned InnerLoopId, unsigned OuterLoopId)
static void populateWorklist (Loop &L, LoopVector &LoopList)
static bool hasSupportedLoopDepth (ArrayRef< Loop * > LoopList, OptimizationRemarkEmitter &ORE)
static bool isComputableLoopNest (ScalarEvolution *SE, ArrayRef< Loop * > LoopList)
static ValuefollowLCSSA (Value *SV)
static PHINodefindInnerReductionPhi (Loop *L, Value *V, SmallVectorImpl< Instruction * > &HasNoWrapInsts)
static bool areInnerLoopExitPHIsSupported (Loop *InnerL, Loop *OuterL, SmallPtrSetImpl< PHINode * > &Reductions)
static bool areOuterLoopExitPHIsSupported (Loop *OuterLoop, Loop *InnerLoop)
static bool areInnerLoopLatchPHIsSupported (Loop *OuterLoop, Loop *InnerLoop)
static bool canVectorize (const CharMatrix &DepMatrix, unsigned LoopId)
 Return true if we can vectorize the loop specified by LoopId.
static void moveBBContents (BasicBlock *FromBB, Instruction *InsertBefore)
 Move all instructions except the terminator from FromBB right before InsertBefore.
static void swapBBContents (BasicBlock *BB1, BasicBlock *BB2)
 Swap instructions between BB1 and BB2 but keep terminators intact.
static void updateSuccessor (BranchInst *BI, BasicBlock *OldBB, BasicBlock *NewBB, std::vector< DominatorTree::UpdateType > &DTUpdates, bool MustUpdateOnce=true)
static void moveLCSSAPhis (BasicBlock *InnerExit, BasicBlock *InnerHeader, BasicBlock *InnerLatch, BasicBlock *OuterHeader, BasicBlock *OuterLatch, BasicBlock *OuterExit, Loop *InnerLoop, LoopInfo *LI)

Variables

static cl::opt< int > LoopInterchangeCostThreshold ("loop-interchange-threshold", cl::init(0), cl::Hidden, cl::desc("Interchange if you gain more than this number"))
static cl::opt< unsigned int > MaxMemInstrCount ("loop-interchange-max-meminstr-count", cl::init(64), cl::Hidden, cl::desc("Maximum number of load-store instructions that should be handled " "in the dependency matrix. Higher value may lead to more interchanges " "at the cost of compile-time"))
static cl::opt< unsigned int > MinLoopNestDepth ("loop-interchange-min-loop-nest-depth", cl::init(2), cl::Hidden, cl::desc("Minimum depth of loop nest considered for the transform"))
static cl::opt< unsigned int > MaxLoopNestDepth ("loop-interchange-max-loop-nest-depth", cl::init(10), cl::Hidden, cl::desc("Maximum depth of loop nest considered for the transform"))
static cl::list< RuleTy > Profitabilities ("loop-interchange-profitabilities", cl::ZeroOrMore, cl::MiscFlags::CommaSeparated, cl::Hidden, cl::desc("List of profitability heuristics to be used. They are applied in " "the given order"), cl::list_init< RuleTy >({RuleTy::PerLoopCacheAnalysis, RuleTy::PerInstrOrderCost, RuleTy::ForVectorization}), cl::values(clEnumValN(RuleTy::PerLoopCacheAnalysis, "cache", "Prioritize loop cache cost"), clEnumValN(RuleTy::PerInstrOrderCost, "instorder", "Prioritize the IVs order of each instruction"), clEnumValN(RuleTy::ForVectorization, "vectorize", "Prioritize vectorization"), clEnumValN(RuleTy::Ignore, "ignore", "Ignore profitability, force interchange (does not " "work with other options)")))

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "loop-interchange"

Definition at line 53 of file LoopInterchange.cpp.

Function Documentation

◆ areInnerLoopExitPHIsSupported()

bool areInnerLoopExitPHIsSupported ( Loop * InnerL,
Loop * OuterL,
SmallPtrSetImpl< PHINode * > & Reductions )
static

◆ areInnerLoopLatchPHIsSupported()

◆ areOuterLoopExitPHIsSupported()

◆ canVectorize()

bool canVectorize ( const CharMatrix & DepMatrix,
unsigned LoopId )
static

Return true if we can vectorize the loop specified by LoopId.

Definition at line 1407 of file LoopInterchange.cpp.

References assert().

◆ findInnerReductionPhi()

◆ followLCSSA()

Value * followLCSSA ( Value * SV)
static

Definition at line 879 of file LoopInterchange.cpp.

References llvm::dyn_cast(), followLCSSA(), and PHI.

Referenced by followLCSSA(), and moveLCSSAPhis().

◆ hasSupportedLoopDepth()

◆ interChangeDependencies()

void interChangeDependencies ( CharMatrix & DepMatrix,
unsigned FromIndx,
unsigned ToIndx )
static

Definition at line 315 of file LoopInterchange.cpp.

References std::swap().

◆ inThisOrder()

bool inThisOrder ( const Instruction * Src,
const Instruction * Dst )
static

Return true if Src appears before Dst in the same basic block.

Precondition: Src and \Dst are distinct instructions within the same basic block.

Definition at line 147 of file LoopInterchange.cpp.

References assert(), I, and llvm_unreachable.

Referenced by populateDependencyMatrix().

◆ isComputableLoopNest()

bool isComputableLoopNest ( ScalarEvolution * SE,
ArrayRef< Loop * > LoopList )
static

◆ isLegalToInterChangeLoops()

bool isLegalToInterChangeLoops ( CharMatrix & DepMatrix,
unsigned InnerLoopId,
unsigned OuterLoopId )
static

Definition at line 338 of file LoopInterchange.cpp.

References isLexicographicallyPositive(), and std::swap().

◆ isLexicographicallyPositive()

std::optional< bool > isLexicographicallyPositive ( ArrayRef< char > DV,
unsigned Begin,
unsigned End )
static

Definition at line 327 of file LoopInterchange.cpp.

References llvm::ArrayRef< T >::slice().

Referenced by isLegalToInterChangeLoops().

◆ moveBBContents()

void moveBBContents ( BasicBlock * FromBB,
Instruction * InsertBefore )
static

◆ moveLCSSAPhis()

◆ noDuplicateRulesAndIgnore()

bool noDuplicateRulesAndIgnore ( ArrayRef< RuleTy > Rules)
static

Definition at line 123 of file LoopInterchange.cpp.

◆ populateDependencyMatrix()

◆ populateWorklist()

void populateWorklist ( Loop & L,
LoopVector & LoopList )
static

◆ printDepMatrix()

void printDepMatrix ( CharMatrix & DepMatrix)
static

Definition at line 134 of file LoopInterchange.cpp.

References D(), llvm::dbgs(), llvm::drop_end(), and LLVM_DEBUG.

◆ STATISTIC()

STATISTIC ( LoopsInterchanged ,
"Number of loops interchanged"  )

◆ swapBBContents()

void swapBBContents ( BasicBlock * BB1,
BasicBlock * BB2 )
static

Swap instructions between BB1 and BB2 but keep terminators intact.

Definition at line 1728 of file LoopInterchange.cpp.

References llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::BasicBlock::getTerminator(), I, llvm::map_range(), and moveBBContents().

◆ updateSuccessor()

void updateSuccessor ( BranchInst * BI,
BasicBlock * OldBB,
BasicBlock * NewBB,
std::vector< DominatorTree::UpdateType > & DTUpdates,
bool MustUpdateOnce = true )
static

Variable Documentation

◆ LoopInterchangeCostThreshold

cl::opt< int > LoopInterchangeCostThreshold("loop-interchange-threshold", cl::init(0), cl::Hidden, cl::desc("Interchange if you gain more than this number")) ( "loop-interchange-threshold" ,
cl::init(0) ,
cl::Hidden ,
cl::desc("Interchange if you gain more than this number")  )
static

◆ MaxLoopNestDepth

cl::opt< unsigned int > MaxLoopNestDepth("loop-interchange-max-loop-nest-depth", cl::init(10), cl::Hidden, cl::desc("Maximum depth of loop nest considered for the transform")) ( "loop-interchange-max-loop-nest-depth" ,
cl::init(10) ,
cl::Hidden ,
cl::desc("Maximum depth of loop nest considered for the transform")  )
static

Referenced by hasSupportedLoopDepth().

◆ MaxMemInstrCount

cl::opt< unsigned int > MaxMemInstrCount("loop-interchange-max-meminstr-count", cl::init(64), cl::Hidden, cl::desc( "Maximum number of load-store instructions that should be handled " "in the dependency matrix. Higher value may lead to more interchanges " "at the cost of compile-time")) ( "loop-interchange-max-meminstr-count" ,
cl::init(64) ,
cl::Hidden ,
cl::desc( "Maximum number of load-store instructions that should be handled " "in the dependency matrix. Higher value may lead to more interchanges " "at the cost of compile-time")  )
static

◆ MinLoopNestDepth

cl::opt< unsigned int > MinLoopNestDepth("loop-interchange-min-loop-nest-depth", cl::init(2), cl::Hidden, cl::desc("Minimum depth of loop nest considered for the transform")) ( "loop-interchange-min-loop-nest-depth" ,
cl::init(2) ,
cl::Hidden ,
cl::desc("Minimum depth of loop nest considered for the transform")  )
static

Referenced by hasSupportedLoopDepth().

◆ Profitabilities

cl::list< RuleTy > Profitabilities("loop-interchange-profitabilities", cl::ZeroOrMore, cl::MiscFlags::CommaSeparated, cl::Hidden, cl::desc("List of profitability heuristics to be used. They are applied in " "the given order"), cl::list_init< RuleTy >({RuleTy::PerLoopCacheAnalysis, RuleTy::PerInstrOrderCost, RuleTy::ForVectorization}), cl::values(clEnumValN(RuleTy::PerLoopCacheAnalysis, "cache", "Prioritize loop cache cost"), clEnumValN(RuleTy::PerInstrOrderCost, "instorder", "Prioritize the IVs order of each instruction"), clEnumValN(RuleTy::ForVectorization, "vectorize", "Prioritize vectorization"), clEnumValN(RuleTy::Ignore, "ignore", "Ignore profitability, force interchange (does not " "work with other options)"))) ( "loop-interchange-profitabilities" ,
cl::ZeroOrMore ,
cl::MiscFlags::CommaSeparated ,
cl::Hidden ,
cl::desc("List of profitability heuristics to be used. They are applied in " "the given order") ,
cl::list_init< RuleTy > {RuleTy::PerLoopCacheAnalysis, RuleTy::PerInstrOrderCost, RuleTy::ForVectorization},
cl::values(clEnumValN(RuleTy::PerLoopCacheAnalysis, "cache", "Prioritize loop cache cost"), clEnumValN(RuleTy::PerInstrOrderCost, "instorder", "Prioritize the IVs order of each instruction"), clEnumValN(RuleTy::ForVectorization, "vectorize", "Prioritize vectorization"), clEnumValN(RuleTy::Ignore, "ignore", "Ignore profitability, force interchange (does not " "work with other options)"))  )
static