summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2015-12-15 19:40:57 +0000
committerJustin Bogner <mail@justinbogner.com>2015-12-15 19:40:57 +0000
commit843fb204b7102bc1abd7fdadf39f3ac2e0acb479 (patch)
tree911cfa2d243582a779de1e1edffbc4a01045d384 /llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
parent33beb24318f9e5355f1aa481cddcbb50eaf2a156 (diff)
downloadbcm5719-llvm-843fb204b7102bc1abd7fdadf39f3ac2e0acb479.tar.gz
bcm5719-llvm-843fb204b7102bc1abd7fdadf39f3ac2e0acb479.zip
LPM: Stop threading `Pass *` through all of the loop utility APIs. NFC
A large number of loop utility functions take a `Pass *` and reach into it to find out which analyses to preserve. There are a number of problems with this: - The APIs have access to pretty well any Pass state they want, so it's hard to tell what they may or may not do. - Other APIs have copied these and pass around a `Pass *` even though they don't even use it. Some of these just hand a nullptr to the API since the callers don't even have a pass available. - Passes in the new pass manager don't work like the current ones, so the APIs can't be used as is there. Instead, we should explicitly thread the analysis results that we actually care about through these APIs. This is both simpler and more reusable. llvm-svn: 255669
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp27
1 files changed, 10 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
index 8fecc341d7b..0d68f18ad0e 100644
--- a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
@@ -63,7 +63,7 @@ static void ConnectProlog(Loop *L, Value *BECount, unsigned Count,
BasicBlock *LastPrologBB, BasicBlock *PrologEnd,
BasicBlock *OrigPH, BasicBlock *NewPH,
ValueToValueMapTy &VMap, DominatorTree *DT,
- LoopInfo *LI, Pass *P) {
+ LoopInfo *LI, bool PreserveLCSSA) {
BasicBlock *Latch = L->getLoopLatch();
assert(Latch && "Loop must have a latch");
@@ -128,7 +128,7 @@ static void ConnectProlog(Loop *L, Value *BECount, unsigned Count,
// Split the exit to maintain loop canonicalization guarantees
SmallVector<BasicBlock*, 4> Preds(pred_begin(Exit), pred_end(Exit));
SplitBlockPredecessors(Exit, Preds, ".unr-lcssa", DT, LI,
- P->mustPreserveAnalysisID(LCSSAID));
+ PreserveLCSSA);
// Add the branch to the exit block (around the unrolled loop)
B.CreateCondBr(BrLoopExit, Exit, NewPH);
InsertPt->eraseFromParent();
@@ -279,7 +279,8 @@ static void CloneLoopBlocks(Loop *L, Value *NewIter, const bool UnrollProlog,
///
bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count,
bool AllowExpensiveTripCount, LoopInfo *LI,
- LPPassManager *LPM) {
+ ScalarEvolution *SE, DominatorTree *DT,
+ bool PreserveLCSSA) {
// for now, only unroll loops that contain a single exit
if (!L->getExitingBlock())
return false;
@@ -291,16 +292,12 @@ bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count,
// Use Scalar Evolution to compute the trip count. This allows more
// loops to be unrolled than relying on induction var simplification
- if (!LPM)
+ if (!SE)
return false;
- auto *SEWP = LPM->getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
- if (!SEWP)
- return false;
- ScalarEvolution &SE = SEWP->getSE();
// Only unroll loops with a computable trip count and the trip count needs
// to be an int value (allowing a pointer type is a TODO item)
- const SCEV *BECountSC = SE.getBackedgeTakenCount(L);
+ const SCEV *BECountSC = SE->getBackedgeTakenCount(L);
if (isa<SCEVCouldNotCompute>(BECountSC) ||
!BECountSC->getType()->isIntegerTy())
return false;
@@ -309,13 +306,13 @@ bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count,
// Add 1 since the backedge count doesn't include the first loop iteration
const SCEV *TripCountSC =
- SE.getAddExpr(BECountSC, SE.getConstant(BECountSC->getType(), 1));
+ SE->getAddExpr(BECountSC, SE->getConstant(BECountSC->getType(), 1));
if (isa<SCEVCouldNotCompute>(TripCountSC))
return false;
BasicBlock *Header = L->getHeader();
const DataLayout &DL = Header->getModule()->getDataLayout();
- SCEVExpander Expander(SE, DL, "loop-unroll");
+ SCEVExpander Expander(*SE, DL, "loop-unroll");
if (!AllowExpensiveTripCount && Expander.isHighCostExpansion(TripCountSC, L))
return false;
@@ -332,11 +329,7 @@ bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count,
// If this loop is nested, then the loop unroller changes the code in
// parent loop, so the Scalar Evolution pass needs to be run again
if (Loop *ParentLoop = L->getParentLoop())
- SE.forgetLoop(ParentLoop);
-
- // Grab analyses that we preserve.
- auto *DTWP = LPM->getAnalysisIfAvailable<DominatorTreeWrapperPass>();
- auto *DT = DTWP ? &DTWP->getDomTree() : nullptr;
+ SE->forgetLoop(ParentLoop);
BasicBlock *PH = L->getLoopPreheader();
BasicBlock *Latch = L->getLoopLatch();
@@ -416,7 +409,7 @@ bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count,
// PHI functions.
BasicBlock *LastLoopBB = cast<BasicBlock>(VMap[Latch]);
ConnectProlog(L, BECount, Count, LastLoopBB, PEnd, PH, NewPH, VMap, DT, LI,
- LPM->getAsPass());
+ PreserveLCSSA);
NumRuntimeUnrolled++;
return true;
}
OpenPOWER on IntegriCloud