Print pairwise dependence results, add testcases.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74402 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/LoopDependenceAnalysis.cpp b/lib/Analysis/LoopDependenceAnalysis.cpp
index b23459e..4912bf2 100644
--- a/lib/Analysis/LoopDependenceAnalysis.cpp
+++ b/lib/Analysis/LoopDependenceAnalysis.cpp
@@ -40,6 +40,16 @@
   return isa<LoadInst>(I) || isa<StoreInst>(I);
 }
 
+static void getMemRefInstrs(
+    const Loop *L, SmallVectorImpl<Instruction*> &memrefs) {
+  for (Loop::block_iterator b = L->block_begin(), be = L->block_end();
+      b != be; ++b)
+    for (BasicBlock::iterator i = (*b)->begin(), ie = (*b)->end();
+        i != ie; ++i)
+      if (isMemRefInstr(i))
+        memrefs.push_back(i);
+}
+
 //===----------------------------------------------------------------------===//
 //                             Dependence Testing
 //===----------------------------------------------------------------------===//
@@ -71,16 +81,30 @@
 }
 
 static void PrintLoopInfo(
-    raw_ostream &OS, const LoopDependenceAnalysis *LDA, const Loop *L) {
+    raw_ostream &OS, LoopDependenceAnalysis *LDA, const Loop *L) {
   if (!L->empty()) return; // ignore non-innermost loops
 
   OS << "Loop at depth " << L->getLoopDepth() << ", header block: ";
   WriteAsOperand(OS, L->getHeader(), false);
   OS << "\n";
+
+  SmallVector<Instruction*, 8> memrefs;
+  getMemRefInstrs(L, memrefs);
+  OS << "  Load/store instructions: " << memrefs.size() << "\n";
+  OS << "  Pairwise dependence results:\n";
+  for (SmallVector<Instruction*, 8>::const_iterator x = memrefs.begin(),
+      end = memrefs.end(); x != end; ++x)
+    for (SmallVector<Instruction*, 8>::const_iterator y = x + 1;
+        y != end; ++y)
+      if (LDA->isDependencePair(*x, *y))
+        OS << "\t" << (x - memrefs.begin()) << "," << (y - memrefs.begin())
+           << ": " << (LDA->depends(*x, *y) ? "dependent" : "independent")
+           << "\n";
 }
 
 void LoopDependenceAnalysis::print(raw_ostream &OS, const Module*) const {
-  PrintLoopInfo(OS, this, this->L);
+  // TODO: doc why const_cast is safe
+  PrintLoopInfo(OS, const_cast<LoopDependenceAnalysis*>(this), this->L);
 }
 
 void LoopDependenceAnalysis::print(std::ostream &OS, const Module *M) const {