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

Andreas Bolka a at bolka.at
Fri Aug 7 11:23:41 PDT 2009


Author: abolka
Date: Fri Aug  7 13:23:41 2009
New Revision: 78394

URL: http://llvm.org/viewvc/llvm-project?rev=78394&view=rev
Log:
SIV/MIV classification for LDA.

LoopDependenceAnalysis::getLoops is currently O(N*M) for a loop-nest of
depth N and a compound SCEV of M atomic SCEVs. As both N and M will
typically be very small, this should not be a problem. If it turns out
to be one, rewriting getLoops as SCEVVisitor will reduce complexity to
O(M).

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=78394&r1=78393&r2=78394&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopDependenceAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopDependenceAnalysis.h Fri Aug  7 13:23:41 2009
@@ -20,6 +20,7 @@
 #ifndef LLVM_ANALYSIS_LOOP_DEPENDENCE_ANALYSIS_H
 #define LLVM_ANALYSIS_LOOP_DEPENDENCE_ANALYSIS_H
 
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Analysis/LoopPass.h"
@@ -67,6 +68,10 @@
   /// created. The third argument is set to the pair found or created.
   bool findOrInsertDependencePair(Value*, Value*, DependencePair*&);
 
+  /// getLoops - Collect all loops of the loop-nest L a given SCEV is variant
+  /// in.
+  void getLoops(const SCEV*, DenseSet<const Loop*>*) const;
+
   /// 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;
@@ -78,7 +83,10 @@
 
   /// TODO: doc
   bool isZIVPair(const SCEV*, const SCEV*) const;
+  bool isSIVPair(const SCEV*, const SCEV*) const;
   DependenceResult analyseZIV(const SCEV*, const SCEV*, Subscript*) const;
+  DependenceResult analyseSIV(const SCEV*, const SCEV*, Subscript*) const;
+  DependenceResult analyseMIV(const SCEV*, const SCEV*, Subscript*) const;
   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=78394&r1=78393&r2=78394&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/LoopDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopDependenceAnalysis.cpp Fri Aug  7 13:23:41 2009
@@ -20,6 +20,7 @@
 //===----------------------------------------------------------------------===//
 
 #define DEBUG_TYPE "lda"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/LoopDependenceAnalysis.h"
@@ -124,11 +125,18 @@
   return false;
 }
 
-bool LoopDependenceAnalysis::isLoopInvariant(const SCEV *S) const {
+void LoopDependenceAnalysis::getLoops(const SCEV *S,
+                                      DenseSet<const Loop*>* Loops) const {
+  // Refactor this into an SCEVVisitor, if efficiency becomes a concern.
   for (const Loop *L = this->L; L != 0; L = L->getParentLoop())
     if (!S->isLoopInvariant(L))
-      return false;
-  return true;
+      Loops->insert(L);
+}
+
+bool LoopDependenceAnalysis::isLoopInvariant(const SCEV *S) const {
+  DenseSet<const Loop*> loops;
+  getLoops(S, &loops);
+  return loops.empty();
 }
 
 bool LoopDependenceAnalysis::isAffine(const SCEV *S) const {
@@ -140,6 +148,13 @@
   return isLoopInvariant(A) && isLoopInvariant(B);
 }
 
+bool LoopDependenceAnalysis::isSIVPair(const SCEV *A, const SCEV *B) const {
+  DenseSet<const Loop*> loops;
+  getLoops(A, &loops);
+  getLoops(B, &loops);
+  return loops.size() == 1;
+}
+
 LoopDependenceAnalysis::DependenceResult
 LoopDependenceAnalysis::analyseZIV(const SCEV *A,
                                    const SCEV *B,
@@ -149,6 +164,20 @@
 }
 
 LoopDependenceAnalysis::DependenceResult
+LoopDependenceAnalysis::analyseSIV(const SCEV *A,
+                                   const SCEV *B,
+                                   Subscript *S) const {
+  return Unknown; // TODO: Implement.
+}
+
+LoopDependenceAnalysis::DependenceResult
+LoopDependenceAnalysis::analyseMIV(const SCEV *A,
+                                   const SCEV *B,
+                                   Subscript *S) const {
+  return Unknown; // TODO: Implement.
+}
+
+LoopDependenceAnalysis::DependenceResult
 LoopDependenceAnalysis::analyseSubscript(const SCEV *A,
                                          const SCEV *B,
                                          Subscript *S) const {
@@ -167,10 +196,10 @@
   if (isZIVPair(A, B))
     return analyseZIV(A, B, S);
 
-  // TODO: Implement SIV/MIV testers.
+  if (isSIVPair(A, B))
+    return analyseSIV(A, B, S);
 
-  DEBUG(errs() << "  -> [?] cannot analyse subscript\n");
-  return Unknown;
+  return analyseMIV(A, B, S);
 }
 
 LoopDependenceAnalysis::DependenceResult





More information about the llvm-commits mailing list