From 9d09e20142f6767eadcfb27318f6850c1d371c3e Mon Sep 17 00:00:00 2001 From: Andreas Bolka Date: Sun, 28 Jun 2009 00:35:22 +0000 Subject: Print pairwise dependence results, add testcases. llvm-svn: 74402 --- llvm/lib/Analysis/LoopDependenceAnalysis.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Analysis') diff --git a/llvm/lib/Analysis/LoopDependenceAnalysis.cpp b/llvm/lib/Analysis/LoopDependenceAnalysis.cpp index b23459e81ac..4912bf27591 100644 --- a/llvm/lib/Analysis/LoopDependenceAnalysis.cpp +++ b/llvm/lib/Analysis/LoopDependenceAnalysis.cpp @@ -40,6 +40,16 @@ static inline bool isMemRefInstr(const Value *I) { return isa(I) || isa(I); } +static void getMemRefInstrs( + const Loop *L, SmallVectorImpl &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 @@ void LoopDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { } 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 memrefs; + getMemRefInstrs(L, memrefs); + OS << " Load/store instructions: " << memrefs.size() << "\n"; + OS << " Pairwise dependence results:\n"; + for (SmallVector::const_iterator x = memrefs.begin(), + end = memrefs.end(); x != end; ++x) + for (SmallVector::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(this), this->L); } void LoopDependenceAnalysis::print(std::ostream &OS, const Module *M) const { -- cgit v1.2.3