[llvm-commits] [llvm] r77932 - in /llvm/trunk: include/llvm/Analysis/LoopDependenceAnalysis.h lib/Analysis/LoopDependenceAnalysis.cpp

Andreas Bolka a at bolka.at
Sun Aug 2 18:03:49 PDT 2009


Author: abolka
Date: Sun Aug  2 20:03:48 2009
New Revision: 77932

URL: http://llvm.org/viewvc/llvm-project?rev=77932&view=rev
Log:
Restrict LDA to affine subscripts.

Modified:
    llvm/trunk/include/llvm/Analysis/LoopDependenceAnalysis.h
    llvm/trunk/lib/Analysis/LoopDependenceAnalysis.cpp

Modified: llvm/trunk/include/llvm/Analysis/LoopDependenceAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopDependenceAnalysis.h?rev=77932&r1=77931&r2=77932&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopDependenceAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopDependenceAnalysis.h Sun Aug  2 20:03:48 2009
@@ -67,6 +67,15 @@
   /// 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;

Modified: llvm/trunk/lib/Analysis/LoopDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopDependenceAnalysis.cpp?rev=77932&r1=77931&r2=77932&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/LoopDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopDependenceAnalysis.cpp Sun Aug  2 20:03:48 2009
@@ -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 @@
   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 @@
     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");





More information about the llvm-commits mailing list