46 #define DEBUG_TYPE "loop-interchange"
53 typedef std::vector<std::vector<char>> CharMatrix;
56 static const unsigned MaxMemInstrCount = 100;
59 static const unsigned MaxLoopNestDepth = 10;
61 struct LoopInterchange;
63 #ifdef DUMP_DEP_MATRICIES
64 void printDepMatrix(CharMatrix &DepMatrix) {
65 for (
auto I = DepMatrix.begin(), E = DepMatrix.end();
I != E; ++
I) {
66 std::vector<char> Vec = *
I;
67 for (
auto II = Vec.begin(), EE = Vec.end(); II != EE; ++II)
74 static bool populateDependencyMatrix(CharMatrix &DepMatrix,
unsigned Level,
79 if (Level > MaxLoopNestDepth) {
80 DEBUG(
dbgs() <<
"Cannot handle loops of depth greater than "
81 << MaxLoopNestDepth <<
"\n");
100 if (St && !St->isSimple())
102 MemInstr.push_back(
I);
106 DEBUG(
dbgs() <<
"Found " << MemInstr.size()
107 <<
" Loads and Stores to analyze\n");
109 ValueVector::iterator
I,
IE, J, JE;
111 for (I = MemInstr.begin(), IE = MemInstr.end(); I !=
IE; ++
I) {
112 for (J = I, JE = MemInstr.end(); J != JE; ++J) {
113 std::vector<char> Dep;
118 if (isa<LoadInst>(Src) && isa<LoadInst>(Des))
120 if (
auto D = DA->
depends(Src, Des,
true)) {
121 DEBUG(
dbgs() <<
"Found Dependency between Src=" << Src <<
" Des=" << Des
126 DEBUG(
dbgs() <<
"Flow dependence not handled");
130 DEBUG(
dbgs() <<
"Found Anti dependence \n");
131 unsigned Levels = D->getLevels();
133 for (
unsigned II = 1; II <= Levels; ++II) {
134 const SCEV *Distance = D->getDistance(II);
136 dyn_cast_or_null<SCEVConstant>(Distance);
145 Dep.push_back(Direction);
146 }
else if (D->isScalar(II)) {
148 Dep.push_back(Direction);
150 unsigned Dir = D->getDirection(II);
161 Dep.push_back(Direction);
164 while (Dep.size() !=
Level) {
168 DepMatrix.push_back(Dep);
169 if (DepMatrix.size() > MaxMemInstrCount) {
170 DEBUG(
dbgs() <<
"Cannot handle more than " << MaxMemInstrCount
171 <<
" dependencies inside loop\n");
180 if (DepMatrix.size() == 0)
187 static void interChangeDepedencies(CharMatrix &DepMatrix,
unsigned FromIndx,
189 unsigned numRows = DepMatrix.size();
190 for (
unsigned i = 0; i < numRows; ++i) {
191 char TmpVal = DepMatrix[i][ToIndx];
192 DepMatrix[i][ToIndx] = DepMatrix[i][FromIndx];
193 DepMatrix[i][FromIndx] = TmpVal;
199 static bool isOuterMostDepPositive(CharMatrix &DepMatrix,
unsigned Row,
201 for (
unsigned i = 0; i <= Column; ++i) {
202 if (DepMatrix[Row][i] ==
'<')
204 if (DepMatrix[Row][i] ==
'>')
212 static bool containsNoDependence(CharMatrix &DepMatrix,
unsigned Row,
214 for (
unsigned i = 0; i < Column; ++i) {
215 if (DepMatrix[Row][i] !=
'=' || DepMatrix[Row][i] !=
'S' ||
216 DepMatrix[Row][i] !=
'I')
222 static bool validDepInterchange(CharMatrix &DepMatrix,
unsigned Row,
223 unsigned OuterLoopId,
char InnerDep,
226 if (isOuterMostDepPositive(DepMatrix, Row, OuterLoopId))
229 if (InnerDep == OuterDep)
235 if (InnerDep ==
'=' || InnerDep ==
'S' || InnerDep ==
'I')
241 if (InnerDep ==
'>') {
244 if (OuterLoopId == 0)
250 if (!containsNoDependence(DepMatrix, Row, OuterLoopId))
262 static bool isLegalToInterChangeLoops(CharMatrix &DepMatrix,
263 unsigned InnerLoopId,
264 unsigned OuterLoopId) {
266 unsigned NumRows = DepMatrix.size();
268 for (
unsigned Row = 0; Row < NumRows; ++Row) {
269 char InnerDep = DepMatrix[Row][InnerLoopId];
270 char OuterDep = DepMatrix[Row][OuterLoopId];
271 if (InnerDep ==
'*' || OuterDep ==
'*')
273 else if (!validDepInterchange(DepMatrix, Row, OuterLoopId, InnerDep,
282 DEBUG(
dbgs() <<
"Calling populateWorklist called\n");
284 Loop *CurrentLoop = &L;
285 const std::vector<Loop *> *Vec = &CurrentLoop->
getSubLoops();
286 while (!Vec->empty()) {
290 if (Vec->size() != 1) {
294 LoopList.push_back(CurrentLoop);
295 CurrentLoop = Vec->front();
298 LoopList.push_back(CurrentLoop);
305 return InnerIndexVar;
311 if (!PhiTy->isIntegerTy() && !PhiTy->isFloatingPointTy() &&
312 !PhiTy->isPointerTy())
331 class LoopInterchangeLegality {
334 LoopInterchange *
Pass)
335 : OuterLoop(Outer), InnerLoop(Inner), SE(SE), CurrentPass(Pass),
336 InnerLoopHasReduction(
false) {}
339 bool canInterchangeLoops(
unsigned InnerLoopId,
unsigned OuterLoopId,
340 CharMatrix &DepMatrix);
343 bool isLoopStructureUnderstood(
PHINode *InnerInductionVar);
345 bool currentLimitations();
347 bool hasInnerLoopReduction() {
return InnerLoopHasReduction; }
350 bool tightlyNested(
Loop *Outer,
Loop *Inner);
351 bool containsUnsafeInstructionsInHeader(
BasicBlock *BB);
353 bool containsUnsafeInstructionsInLatch(
BasicBlock *BB);
354 bool findInductionAndReductions(
Loop *L,
362 LoopInterchange *CurrentPass;
364 bool InnerLoopHasReduction;
369 class LoopInterchangeProfitability {
372 : OuterLoop(Outer), InnerLoop(Inner), SE(SE) {}
375 bool isProfitable(
unsigned InnerLoopId,
unsigned OuterLoopId,
376 CharMatrix &DepMatrix);
379 int getInstrOrderCost();
389 class LoopInterchangeTransform {
394 bool InnerLoopContainsReductions)
395 : OuterLoop(Outer), InnerLoop(Inner), SE(SE), LI(LI), DT(DT),
396 LoopExit(LoopNestExit),
397 InnerLoopHasReduction(InnerLoopContainsReductions) {}
401 void restructureLoops(
Loop *InnerLoop,
Loop *OuterLoop);
402 void removeChildLoop(
Loop *OuterLoop,
Loop *InnerLoop);
406 void splitOuterLoopLatch();
407 void splitInnerLoopHeader();
408 bool adjustLoopLinks();
409 void adjustLoopPreheaders();
410 void adjustOuterLoopPreheader();
411 void adjustInnerLoopPreheader();
412 bool adjustLoopBranches();
424 bool InnerLoopHasReduction;
435 :
FunctionPass(
ID), SE(
nullptr), LI(
nullptr), DA(
nullptr), DT(
nullptr) {
449 bool runOnFunction(
Function &
F)
override {
450 SE = &getAnalysis<ScalarEvolution>();
451 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
452 DA = &getAnalysis<DependenceAnalysis>();
453 auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
454 DT = DTWP ? &DTWP->getDomTree() :
nullptr;
459 populateWorklist(*L, Worklist);
461 DEBUG(
dbgs() <<
"Worklist size = " << Worklist.
size() <<
"\n");
463 while (!Worklist.
empty()) {
465 Changed = processLoopList(LoopList, F);
470 bool isComputableLoopNest(LoopVector LoopList) {
471 for (
auto I = LoopList.begin(), E = LoopList.end();
I != E; ++
I) {
475 DEBUG(
dbgs() <<
"Couldn't compute Backedge count\n");
479 DEBUG(
dbgs() <<
"NumBackEdges is not equal to 1\n");
483 DEBUG(
dbgs() <<
"Loop Doesn't have unique exit block\n");
490 unsigned selectLoopForInterchange(LoopVector LoopList) {
493 return LoopList.size() - 1;
496 bool processLoopList(LoopVector LoopList,
Function &F) {
498 bool Changed =
false;
499 CharMatrix DependencyMatrix;
500 if (LoopList.size() < 2) {
501 DEBUG(
dbgs() <<
"Loop doesn't contain minimum nesting level.\n");
504 if (!isComputableLoopNest(LoopList)) {
505 DEBUG(
dbgs() <<
"Not vaild loop candidate for interchange\n");
508 Loop *OuterMostLoop = *(LoopList.begin());
510 DEBUG(
dbgs() <<
"Processing LoopList of size = " << LoopList.size()
513 if (!populateDependencyMatrix(DependencyMatrix, LoopList.size(),
514 OuterMostLoop, DA)) {
515 DEBUG(
dbgs() <<
"Populating Dependency matrix failed\n");
518 #ifdef DUMP_DEP_MATRICIES
519 DEBUG(
dbgs() <<
"Dependence before inter change \n");
520 printDepMatrix(DependencyMatrix);
526 if (!OuterMostLoopLatchBI)
540 if (isa<PHINode>(LoopNestExit->
begin())) {
541 DEBUG(
dbgs() <<
"PHI Nodes in loop nest exit is not handled for now "
542 "since on failure all loops branch to loop nest exit.\n");
546 unsigned SelecLoopId = selectLoopForInterchange(LoopList);
548 for (
unsigned i = SelecLoopId; i > 0; i--) {
550 processLoop(LoopList, i, i - 1, LoopNestExit, DependencyMatrix);
557 interChangeDepedencies(DependencyMatrix, i, i - 1);
559 #ifdef DUMP_DEP_MATRICIES
560 DEBUG(
dbgs() <<
"Dependence after inter change \n");
561 printDepMatrix(DependencyMatrix);
563 Changed |= Interchanged;
568 bool processLoop(LoopVector LoopList,
unsigned InnerLoopId,
569 unsigned OuterLoopId,
BasicBlock *LoopNestExit,
570 std::vector<std::vector<char>> &DependencyMatrix) {
572 DEBUG(
dbgs() <<
"Processing Innder Loop Id = " << InnerLoopId
573 <<
" and OuterLoopId = " << OuterLoopId <<
"\n");
574 Loop *InnerLoop = LoopList[InnerLoopId];
575 Loop *OuterLoop = LoopList[OuterLoopId];
577 LoopInterchangeLegality LIL(OuterLoop, InnerLoop, SE,
this);
578 if (!LIL.canInterchangeLoops(InnerLoopId, OuterLoopId, DependencyMatrix)) {
579 DEBUG(
dbgs() <<
"Not interchanging Loops. Cannot prove legality\n");
582 DEBUG(
dbgs() <<
"Loops are legal to interchange\n");
583 LoopInterchangeProfitability LIP(OuterLoop, InnerLoop, SE);
584 if (!LIP.isProfitable(InnerLoopId, OuterLoopId, DependencyMatrix)) {
585 DEBUG(
dbgs() <<
"Interchanging Loops not profitable\n");
589 LoopInterchangeTransform LIT(OuterLoop, InnerLoop, SE, LI, DT,
this,
590 LoopNestExit, LIL.hasInnerLoopReduction());
606 bool LoopInterchangeLegality::containsUnsafeInstructionsInHeader(
608 for (
auto I = BB->
begin(), E = BB->
end();
I != E; ++
I) {
611 if (
LoadInst *L = dyn_cast<LoadInst>(
I)) {
612 if (!areAllUsesReductions(L, InnerLoop))
614 }
else if (
I->mayHaveSideEffects() ||
I->mayReadFromMemory())
620 bool LoopInterchangeLegality::containsUnsafeInstructionsInLatch(
622 for (
auto I = BB->
begin(), E = BB->
end();
I != E; ++
I) {
629 }
else if (
I->mayHaveSideEffects() ||
I->mayReadFromMemory())
635 bool LoopInterchangeLegality::tightlyNested(
Loop *OuterLoop,
Loop *InnerLoop) {
640 DEBUG(
dbgs() <<
"Checking if Loops are Tightly Nested\n");
647 if (!outerLoopHeaderBI)
650 for (
unsigned i = 0; i < num; i++) {
651 if (outerLoopHeaderBI->
getSuccessor(i) != InnerLoopPreHeader &&
656 DEBUG(
dbgs() <<
"Checking instructions in Loop header and Loop latch \n");
659 if (containsUnsafeInstructionsInHeader(OuterLoopHeader) ||
660 containsUnsafeInstructionsInLatch(OuterLoopLatch))
663 DEBUG(
dbgs() <<
"Loops are perfectly nested \n");
669 bool LoopInterchangeLegality::isLoopStructureUnderstood(
674 for (
unsigned i = 0; i < Num; ++i) {
676 if (isa<Constant>(Val))
686 InnerLoopPreheader &&
694 bool LoopInterchangeLegality::findInductionAndReductions(
709 dbgs() <<
"Failed to recognize PHI as an induction or reduction.\n");
717 for (
auto I = Block->
begin(); isa<PHINode>(
I); ++
I) {
727 if (!isa<PHINode>(Ins) && isOuterLoopExitBlock)
736 unsigned Num = BI->getNumSuccessors();
738 for (
unsigned i = 0; i < Num; ++i) {
739 if (BI->getSuccessor(i) == LoopHeader)
741 return BI->getSuccessor(i);
749 bool LoopInterchangeLegality::currentLimitations() {
760 if (!findInductionAndReductions(InnerLoop, Inductions, Reductions))
764 if (Inductions.
size() != 1) {
765 DEBUG(
dbgs() <<
"We currently only support loops with 1 induction variable."
766 <<
"Failed to interchange due to current limitation\n");
769 if (Reductions.
size() > 0)
770 InnerLoopHasReduction =
true;
774 if (!findInductionAndReductions(OuterLoop, Inductions, Reductions))
779 if (!Reductions.
empty())
782 if (Inductions.
size() != 1)
786 if (!isLoopStructureUnderstood(InnerInductionVar)) {
787 DEBUG(
dbgs() <<
"Loop structure not understood by pass\n");
811 bool FoundInduction =
false;
820 if (!InnerIndexVarInc)
827 for (
auto I = InnerLoopLatch->
rbegin(), E = InnerLoopLatch->
rend();
828 I != E && !FoundInduction; ++
I) {
829 if (isa<BranchInst>(*I) || isa<CmpInst>(*I) || isa<TruncInst>(*I))
837 FoundInduction =
true;
847 bool LoopInterchangeLegality::canInterchangeLoops(
unsigned InnerLoopId,
848 unsigned OuterLoopId,
849 CharMatrix &DepMatrix) {
851 if (!isLegalToInterChangeLoops(DepMatrix, InnerLoopId, OuterLoopId)) {
852 DEBUG(
dbgs() <<
"Failed interchange InnerLoopId = " << InnerLoopId
853 <<
"and OuterLoopId = " << OuterLoopId
854 <<
"due to dependence\n");
867 if (!OuterLoopPreHeader || OuterLoopPreHeader == OuterLoop->
getHeader() ||
868 isa<PHINode>(OuterLoopPreHeader->
begin()) ||
873 if (!InnerLoopPreHeader || InnerLoopPreHeader == InnerLoop->
getHeader() ||
874 InnerLoopPreHeader == OuterLoop->
getHeader()) {
880 if (currentLimitations()) {
881 DEBUG(
dbgs() <<
"Not legal because of current transform limitation\n");
886 if (!tightlyNested(OuterLoop, InnerLoop)) {
887 DEBUG(
dbgs() <<
"Loops not tightly nested\n");
894 int LoopInterchangeProfitability::getInstrOrderCost() {
895 unsigned GoodOrder, BadOrder;
896 BadOrder = GoodOrder = 0;
899 for (
auto I = (*BI)->begin(), E = (*BI)->end(); I != E; ++
I) {
902 unsigned NumOp =
GEP->getNumOperands();
903 bool FoundInnerInduction =
false;
904 bool FoundOuterInduction =
false;
905 for (
unsigned i = 0; i < NumOp; ++i) {
906 const SCEV *OperandVal = SE->getSCEV(
GEP->getOperand(i));
916 if (AR->
getLoop() == InnerLoop) {
919 FoundInnerInduction =
true;
920 if (FoundOuterInduction) {
930 if (AR->
getLoop() == OuterLoop) {
933 FoundOuterInduction =
true;
934 if (FoundInnerInduction) {
943 return GoodOrder - BadOrder;
947 unsigned OuterLoopId,
948 CharMatrix &DepMatrix) {
952 unsigned Row = DepMatrix.size();
953 for (
unsigned i = 0; i < Row; ++i) {
954 if (DepMatrix[i][InnerLoopId] !=
'S' && DepMatrix[i][InnerLoopId] !=
'I')
957 if (DepMatrix[i][OuterLoopId] !=
'=')
965 bool LoopInterchangeProfitability::isProfitable(
unsigned InnerLoopId,
966 unsigned OuterLoopId,
967 CharMatrix &DepMatrix) {
978 Cost += getInstrOrderCost();
979 DEBUG(
dbgs() <<
"Cost = " << Cost <<
"\n");
990 void LoopInterchangeTransform::removeChildLoop(
Loop *OuterLoop,
994 if (*I == InnerLoop) {
999 assert(
false &&
"Couldn't find loop");
1002 void LoopInterchangeTransform::restructureLoops(
Loop *InnerLoop,
1005 if (OuterLoopParent) {
1007 removeChildLoop(OuterLoopParent, OuterLoop);
1008 removeChildLoop(OuterLoop, InnerLoop);
1011 removeChildLoop(OuterLoop, InnerLoop);
1012 LI->changeTopLevelLoop(OuterLoop, InnerLoop);
1015 while (!InnerLoop->
empty())
1021 bool LoopInterchangeTransform::transform() {
1024 bool Transformed =
false;
1029 DEBUG(
dbgs() <<
"Calling Split Inner Loop\n");
1030 PHINode *InductionPHI = getInductionVariable(InnerLoop, SE);
1031 if (!InductionPHI) {
1032 DEBUG(
dbgs() <<
"Failed to find the point to split loop latch \n");
1045 splitInnerLoopLatch(InnerIndexVar);
1046 DEBUG(
dbgs() <<
"splitInnerLoopLatch Done\n");
1049 splitInnerLoopHeader();
1050 DEBUG(
dbgs() <<
"splitInnerLoopHeader Done\n");
1053 Transformed |= adjustLoopLinks();
1055 DEBUG(
dbgs() <<
"adjustLoopLinks Failed\n");
1059 restructureLoops(InnerLoop, OuterLoop);
1063 void LoopInterchangeTransform::splitInnerLoopLatch(
Instruction *Inc) {
1065 BasicBlock *InnerLoopLatchPred = InnerLoopLatch;
1066 InnerLoopLatch =
SplitBlock(InnerLoopLatchPred, Inc, DT, LI);
1069 void LoopInterchangeTransform::splitOuterLoopLatch() {
1071 BasicBlock *OuterLatchLcssaPhiBlock = OuterLoopLatch;
1072 OuterLoopLatch =
SplitBlock(OuterLatchLcssaPhiBlock,
1076 void LoopInterchangeTransform::splitInnerLoopHeader() {
1082 if (InnerLoopHasReduction) {
1085 ++(InnerLoopHeader->
begin()), InnerLoopHeader->
getName() +
".split");
1087 if (
Loop *L = LI->getLoopFor(InnerLoopHeader))
1092 for (
auto I = New->
begin(); isa<PHINode>(
I); ++
I) {
1098 for (
auto I = PHIVec.
begin(), E = PHIVec.
end(); I != E; ++
I) {
1106 DEBUG(
dbgs() <<
"Output of splitInnerLoopHeader InnerLoopHeaderSucc & "
1107 "InnerLoopHeader \n");
1116 ToList.
splice(InsertBefore, FromList, FromList.begin(),
1120 void LoopInterchangeTransform::adjustOuterLoopPreheader() {
1127 void LoopInterchangeTransform::adjustInnerLoopPreheader() {
1134 void LoopInterchangeTransform::updateIncomingBlock(
BasicBlock *CurrBlock,
1137 for (
auto I = CurrBlock->
begin(); isa<PHINode>(
I); ++
I) {
1140 for (
unsigned i = 0; i < Num; ++i) {
1147 bool LoopInterchangeTransform::adjustLoopBranches() {
1149 DEBUG(
dbgs() <<
"adjustLoopBranches called\n");
1172 if (!OuterLoopPredecessor || !InnerLoopLatchPredecessor ||
1173 !OuterLoopLatchBI || !InnerLoopLatchBI || !OuterLoopHeaderBI ||
1182 if (!OuterLoopPredecessorBI || !InnerLoopLatchPredecessorBI)
1185 if (!InnerLoopHeaderSucessor)
1190 unsigned NumSucc = OuterLoopPredecessorBI->getNumSuccessors();
1191 for (
unsigned i = 0; i < NumSucc; ++i) {
1192 if (OuterLoopPredecessorBI->getSuccessor(i) == OuterLoopPreHeader)
1193 OuterLoopPredecessorBI->setSuccessor(i, InnerLoopPreHeader);
1196 NumSucc = OuterLoopHeaderBI->getNumSuccessors();
1197 for (
unsigned i = 0; i < NumSucc; ++i) {
1198 if (OuterLoopHeaderBI->getSuccessor(i) == OuterLoopLatch)
1199 OuterLoopHeaderBI->setSuccessor(i, LoopExit);
1200 else if (OuterLoopHeaderBI->getSuccessor(i) == InnerLoopPreHeader)
1201 OuterLoopHeaderBI->setSuccessor(i, InnerLoopHeaderSucessor);
1205 updateIncomingBlock(InnerLoopHeaderSucessor, InnerLoopHeader,
1209 InnerLoopHeaderBI->eraseFromParent();
1212 if (InnerLoopLatchBI->getSuccessor(0) == InnerLoopHeader)
1213 InnerLoopLatchSuccessor = InnerLoopLatchBI->getSuccessor(1);
1215 InnerLoopLatchSuccessor = InnerLoopLatchBI->getSuccessor(0);
1218 for (
unsigned i = 0; i < NumSucc; ++i) {
1219 if (InnerLoopLatchPredecessorBI->
getSuccessor(i) == InnerLoopLatch)
1220 InnerLoopLatchPredecessorBI->
setSuccessor(i, InnerLoopLatchSuccessor);
1226 for (
auto I = InnerLoopLatchSuccessor->
begin(); isa<PHINode>(
I); ++
I) {
1227 PHINode *LcssaPhi = cast<PHINode>(
I);
1230 for (
auto I = LcssaVec.
begin(), E = LcssaVec.
end(); I != E; ++
I) {
1237 if (OuterLoopLatchBI->
getSuccessor(0) == OuterLoopHeader)
1238 OuterLoopLatchSuccessor = OuterLoopLatchBI->
getSuccessor(1);
1240 OuterLoopLatchSuccessor = OuterLoopLatchBI->
getSuccessor(0);
1242 if (InnerLoopLatchBI->getSuccessor(1) == InnerLoopLatchSuccessor)
1243 InnerLoopLatchBI->setSuccessor(1, OuterLoopLatchSuccessor);
1245 InnerLoopLatchBI->setSuccessor(0, OuterLoopLatchSuccessor);
1247 updateIncomingBlock(OuterLoopLatchSuccessor, OuterLoopLatch, InnerLoopLatch);
1249 if (OuterLoopLatchBI->
getSuccessor(0) == OuterLoopLatchSuccessor) {
1257 void LoopInterchangeTransform::adjustLoopPreheaders() {
1277 bool LoopInterchangeTransform::adjustLoopLinks() {
1280 bool Changed = adjustLoopBranches();
1282 adjustLoopPreheaders();
1288 "Interchanges loops for cache reuse",
false,
false)
unsigned getNumBackEdges() const
getNumBackEdges - Calculate the number of back edges to the loop header
Pass interface - Implemented by all 'passes'.
loop Interchanges loops for cache false
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
void push_back(const T &Elt)
BasicBlock * getUniqueSuccessor()
Return the successor of this block if it has a unique successor.
BasicBlock * getUniquePredecessor()
Return the predecessor of this block if it has a unique predecessor block.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
DependenceAnalysis - This class is the main dependence-analysis driver.
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
SplitBlock - Split the specified block at the specified instruction - every thing before SplitPt stay...
unsigned getNumOperands() const
ScalarEvolution - This class is the main scalar evolution driver.
bool isInductionPHI(PHINode *, ScalarEvolution *, ConstantInt *&)
Checks if the given PHINode in a loop header is an induction variable.
static bool isReductionPHI(PHINode *Phi, Loop *TheLoop, RecurrenceDescriptor &RedDes)
Returns true if Phi is a reduction in TheLoop.
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
getStepRecurrence - This method constructs and returns the recurrence indicating how much this expres...
LoopT * getParentLoop() const
LoadInst - an instruction for reading from memory.
reverse_iterator rbegin()
BlockT * getHeader() const
LoopT * removeChildLoop(iterator I)
removeChildLoop - This removes the specified child from being a subloop of this loop.
StringRef getName() const
Return a constant reference to the value's name.
BlockT * getLoopLatch() const
getLoopLatch - If there is a single latch block for this loop, return it.
iterator begin()
Instruction iterator methods.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
bool isIdenticalTo(const Instruction *I) const
isIdenticalTo - Return true if the specified instruction is exactly identical to the current one...
BasicBlock * InsertPreheaderForLoop(Loop *L, Pass *P)
InsertPreheaderForLoop - Once we discover that a loop doesn't have a preheader, this method is called...
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Instruction * getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
bool isLoopInvariant(const Value *V) const
isLoopInvariant - Return true if the specified value is loop invariant
static BasicBlock * getLoopLatchExitBlock(BasicBlock *LatchBlock, BasicBlock *LoopHeader)
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
addBasicBlockToLoop - This method is used by other analyses to update loop information.
SCEVAddRecExpr - This node represents a polynomial recurrence on the trip count of the specified loop...
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
void addChildLoop(LoopT *NewChild)
addChildLoop - Add the specified loop to be a child of this loop.
BasicBlock * getSuccessor(unsigned i) const
StoreInst - an instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
unsigned getNumIncomingValues() const
getNumIncomingValues - Return the number of incoming edges
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
const SCEV * getCouldNotCompute()
bool isAffine() const
isAffine - Return true if this represents an expression A + B*x where A and B are loop invariant valu...
BlockT * getLoopPreheader() const
getLoopPreheader - If there is a preheader for this loop, return it.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
static bool isProfitabileForVectorization(unsigned InnerLoopId, unsigned OuterLoopId, CharMatrix &DepMatrix)
BranchInst - Conditional or Unconditional Branch instruction.
loop Interchanges loops for cache reuse
Represent the analysis usage information of a pass.
BasicBlock * getIncomingBlock(unsigned i) const
getIncomingBlock - Return incoming basic block number i.
const InstListType & getInstList() const
Return the underlying instruction list container.
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
FunctionPass class - This class is used to implement most global optimizations.
BlockT * getExitingBlock() const
getExitingBlock - If getExitingBlocks would return exactly one block, return that block...
Value * getOperand(unsigned i) const
#define INITIALIZE_AG_DEPENDENCY(depName)
static unsigned getIncomingValueNumForOperand(unsigned i)
void initializeLoopInterchangePass(PassRegistry &)
void setSuccessor(unsigned idx, BasicBlock *NewSucc)
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
INITIALIZE_PASS_BEGIN(LoopInterchange,"loop-interchange","Interchanges loops for cache reuse", false, false) INITIALIZE_PASS_END(LoopInterchange
static bool containsSafePHI(BasicBlock *Block, bool isOuterLoopExitBlock)
This is the shared class of boolean and integer constants.
void setIncomingBlock(unsigned i, BasicBlock *BB)
Pass * createLoopInterchangePass()
Value * getIncomingValue(unsigned i) const
getIncomingValue - Return incoming value number x
AnalysisUsage & addRequiredID(const void *ID)
static void moveBBContents(BasicBlock *FromBB, Instruction *InsertBefore)
Move all instructions except the terminator from FromBB right before InsertBefore.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
PHINode * getCanonicalInductionVariable() const
getCanonicalInductionVariable - Check to see if the loop has a canonical induction variable: an integ...
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
ConstantInt * getValue() const
void splice(iterator where, iplist &L2)
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.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
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)
std::vector< BlockT * >::const_iterator block_iterator
block_iterator block_end() const
SCEV - This class represents an analyzed expression in the program.
unsigned getNumSuccessors() const
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
BlockT * getLoopPredecessor() const
getLoopPredecessor - If the given loop's header has exactly one unique predecessor outside the loop...
const Loop * getLoop() const
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
const SCEV * getBackedgeTakenCount(const Loop *L)
getBackedgeTakenCount - If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCouldNotCompute object.
user_iterator user_begin()
LLVM Value Representation.
const SCEV * getSCEV(Value *V)
getSCEV - Return a SCEV expression for the full generality of the specified expression.
std::unique_ptr< Dependence > depends(Instruction *Src, Instruction *Dst, bool PossiblyLoopIndependent)
depends - Tests for a dependence between the Src and Dst instructions.
const std::vector< LoopT * > & getSubLoops() const
iterator/begin/end - Return the loops contained entirely within this loop.
block_iterator block_begin() const
The legacy pass manager's analysis pass to compute loop information.
C - The default llvm calling convention, compatible with C.
Legacy analysis pass which computes a DominatorTree.
std::vector< LoopT * >::const_iterator iterator
const BasicBlock * getParent() const
SCEVConstant - This class represents a constant integer value.