aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Analysis/LoopDependenceAnalysis.h9
-rw-r--r--lib/Analysis/LoopDependenceAnalysis.cpp18
2 files changed, 27 insertions, 0 deletions
diff --git a/include/llvm/Analysis/LoopDependenceAnalysis.h b/include/llvm/Analysis/LoopDependenceAnalysis.h
index 56a6b6eb06..b43eeda728 100644
--- a/include/llvm/Analysis/LoopDependenceAnalysis.h
+++ b/include/llvm/Analysis/LoopDependenceAnalysis.h
@@ -67,6 +67,15 @@ class LoopDependenceAnalysis : public LoopPass {
/// created. The third argument is set to the pair found or created.
bool findOrInsertDependencePair(Value*, Value*, DependencePair*&);
+ /// isLoopInvariant - True if a given SCEV is invariant in all loops of the
+ /// loop-nest starting at the innermost loop L.
+ bool isLoopInvariant(const SCEV*) const;
+
+ /// isAffine - An SCEV is affine with respect to the loop-nest starting at
+ /// the innermost loop L if it is of the form A+B*X where A, B are invariant
+ /// in the loop-nest and X is a induction variable in the loop-nest.
+ bool isAffine(const SCEV*) const;
+
/// TODO: doc
DependenceResult analyseSubscript(const SCEV*, const SCEV*, Subscript*) const;
DependenceResult analysePair(DependencePair*) const;
diff --git a/lib/Analysis/LoopDependenceAnalysis.cpp b/lib/Analysis/LoopDependenceAnalysis.cpp
index 0c8bbd7a56..bf3978ec4e 100644
--- a/lib/Analysis/LoopDependenceAnalysis.cpp
+++ b/lib/Analysis/LoopDependenceAnalysis.cpp
@@ -25,6 +25,7 @@
#include "llvm/Analysis/LoopDependenceAnalysis.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolution.h"
+#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/Instructions.h"
#include "llvm/Operator.h"
#include "llvm/Support/Allocator.h"
@@ -123,6 +124,18 @@ bool LoopDependenceAnalysis::findOrInsertDependencePair(Value *A,
return false;
}
+bool LoopDependenceAnalysis::isLoopInvariant(const SCEV *S) const {
+ for (const Loop *L = this->L; L != 0; L = L->getParentLoop())
+ if (!S->isLoopInvariant(L))
+ return false;
+ return true;
+}
+
+bool LoopDependenceAnalysis::isAffine(const SCEV *S) const {
+ const SCEVAddRecExpr *rec = dyn_cast<SCEVAddRecExpr>(S);
+ return isLoopInvariant(S) || (rec && rec->isAffine());
+}
+
LoopDependenceAnalysis::DependenceResult
LoopDependenceAnalysis::analyseSubscript(const SCEV *A,
const SCEV *B,
@@ -134,6 +147,11 @@ LoopDependenceAnalysis::analyseSubscript(const SCEV *A,
return Dependent;
}
+ if (!isAffine(A) || !isAffine(B)) {
+ DEBUG(errs() << " -> [?] not affine\n");
+ return Unknown;
+ }
+
// TODO: Implement ZIV/SIV/MIV testers.
DEBUG(errs() << " -> [?] cannot analyse subscript\n");