Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/include/llvm/Transforms/Scalar/LoopOptTutorial.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class LoopSplit {

private:
LoopInfo &LI;

/// Determines if \p L is a candidate for splitting
bool isCandidate(const Loop &L) const;

};

class LoopOptTutorialPass : public PassInfoMixin<LoopOptTutorialPass> {
Expand Down
40 changes: 34 additions & 6 deletions llvm/lib/Transforms/Scalar/LoopOptTutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,50 @@ bool LoopSplit::run(Loop &L) const {

LLVM_DEBUG(dbgs() << "Entering " << __func__ << "\n");

LLVM_DEBUG(dbgs() << "TODO: Need to check if Loop is a valid candidate\n");
if (!isCandidate(L)) {
LLVM_DEBUG(dbgs() << "Loop " << L.getName()
<< " is not a candidate for splitting.\n");
return false;
}

LLVM_DEBUG(dbgs() << "Loop " << L.getName()
<< " is a candidate for splitting!\n");

return false;
}

bool LoopSplit::isCandidate(const Loop &L) const {
// Require loops with preheaders and dedicated exits.
if (!L.isLoopSimplifyForm())
return false;

// Since we use cloning to split the loop, it has to be safe to clone.
if (!L.isSafeToClone())
return false;

// If the loop has multiple exiting blocks, do not split.
if (!L.getExitingBlock())
return false;

// If loop has multiple exit blocks, do not split.
if (!L.getExitBlock())
return false;

// Only split innermost loops. Thus, if the loop has any children, it cannot
// be split.
if (!L.getSubLoops().empty())
return false;

return true;
}

PreservedAnalyses LoopOptTutorialPass::run(Loop &L, LoopAnalysisManager &LAM,
LoopStandardAnalysisResults &AR,
LPMUpdater &U) {
bool Changed = false;

LLVM_DEBUG(dbgs() << "Entering LoopOptTutorialPass::run\n");
LLVM_DEBUG(dbgs() << "Loop: "; L.dump(); dbgs() << "\n");

LoopSplit LS(AR.LI);

Changed = LS.run(L);
bool Changed = LoopSplit(AR.LI).run(L);

if (!Changed)
return PreservedAnalyses::all();
Expand Down