diff options
author | Adam Nemet <anemet@apple.com> | 2015-02-19 19:15:10 +0000 |
---|---|---|
committer | Adam Nemet <anemet@apple.com> | 2015-02-19 19:15:10 +0000 |
commit | 929c38e8ffbb77e82c2c59bb6fc1045a01224766 (patch) | |
tree | 80bd545073d92161fcb565d37678a05d4c1c6103 /llvm/lib/Analysis/LoopAccessAnalysis.cpp | |
parent | 339f42b3960485d8b568ff4c54acfe1abeba4ec6 (diff) | |
download | bcm5719-llvm-929c38e8ffbb77e82c2c59bb6fc1045a01224766.tar.gz bcm5719-llvm-929c38e8ffbb77e82c2c59bb6fc1045a01224766.zip |
[LoopAccesses] Add canAnalyzeLoop
This allows the analysis to be attempted with any loop. This feature
will be used with -analysis. (LV only requests the analysis on loops
that have already satisfied these tests.)
This is part of the patchset that converts LoopAccessAnalysis into an
actual analysis pass.
llvm-svn: 229895
Diffstat (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/LoopAccessAnalysis.cpp | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index 05917036404..40b70ef30d4 100644 --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -855,6 +855,55 @@ bool MemoryDepChecker::areDepsSafe(AccessAnalysis::DepCandidates &AccessSets, return true; } +bool LoopAccessInfo::canAnalyzeLoop() { + // We can only analyze innermost loops. + if (!TheLoop->empty()) { + emitAnalysis(VectorizationReport() << "loop is not the innermost loop"); + return false; + } + + // We must have a single backedge. + if (TheLoop->getNumBackEdges() != 1) { + emitAnalysis( + VectorizationReport() << + "loop control flow is not understood by analyzer"); + return false; + } + + // We must have a single exiting block. + if (!TheLoop->getExitingBlock()) { + emitAnalysis( + VectorizationReport() << + "loop control flow is not understood by analyzer"); + return false; + } + + // We only handle bottom-tested loops, i.e. loop in which the condition is + // checked at the end of each iteration. With that we can assume that all + // instructions in the loop are executed the same number of times. + if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch()) { + emitAnalysis( + VectorizationReport() << + "loop control flow is not understood by analyzer"); + return false; + } + + // We need to have a loop header. + DEBUG(dbgs() << "LAA: Found a loop: " << + TheLoop->getHeader()->getName() << '\n'); + + // ScalarEvolution needs to be able to find the exit count. + const SCEV *ExitCount = SE->getBackedgeTakenCount(TheLoop); + if (ExitCount == SE->getCouldNotCompute()) { + emitAnalysis(VectorizationReport() << + "could not determine number of loop iterations"); + DEBUG(dbgs() << "LAA: SCEV could not compute the loop exit count.\n"); + return false; + } + + return true; +} + void LoopAccessInfo::analyzeLoop(ValueToValueMap &Strides) { typedef SmallVector<Value*, 16> ValueVector; @@ -1238,7 +1287,8 @@ LoopAccessInfo::LoopAccessInfo(Loop *L, ScalarEvolution *SE, DominatorTree *DT, ValueToValueMap &Strides) : TheLoop(L), SE(SE), DL(DL), TLI(TLI), AA(AA), DT(DT), NumLoads(0), NumStores(0), MaxSafeDepDistBytes(-1U), CanVecMem(false) { - analyzeLoop(Strides); + if (canAnalyzeLoop()) + analyzeLoop(Strides); } LoopAccessInfo &LoopAccessAnalysis::getInfo(Loop *L, ValueToValueMap &Strides) { |