Andreas Bolka | 306b5b2 | 2009-06-24 21:29:13 +0000 | [diff] [blame] | 1 | //===- LoopDependenceAnalysis.cpp - LDA Implementation ----------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is the (beginning) of an implementation of a loop dependence analysis |
| 11 | // framework, which is used to detect dependences in memory accesses in loops. |
| 12 | // |
| 13 | // Please note that this is work in progress and the interface is subject to |
| 14 | // change. |
| 15 | // |
| 16 | // TODO: adapt as implementation progresses. |
| 17 | // |
Andreas Bolka | 80478de | 2009-07-29 05:35:53 +0000 | [diff] [blame] | 18 | // TODO: document lingo (pair, subscript, index) |
| 19 | // |
Andreas Bolka | 306b5b2 | 2009-06-24 21:29:13 +0000 | [diff] [blame] | 20 | //===----------------------------------------------------------------------===// |
| 21 | |
| 22 | #define DEBUG_TYPE "lda" |
Andreas Bolka | 43aa1e0 | 2009-07-28 19:49:49 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/Statistic.h" |
Andreas Bolka | 8f9cd69 | 2009-07-01 21:45:23 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/AliasAnalysis.h" |
Andreas Bolka | 306b5b2 | 2009-06-24 21:29:13 +0000 | [diff] [blame] | 25 | #include "llvm/Analysis/LoopDependenceAnalysis.h" |
| 26 | #include "llvm/Analysis/LoopPass.h" |
| 27 | #include "llvm/Analysis/ScalarEvolution.h" |
Andreas Bolka | 3bbe7de | 2009-08-03 01:03:48 +0000 | [diff] [blame] | 28 | #include "llvm/Analysis/ScalarEvolutionExpressions.h" |
Andreas Bolka | f17ab7f | 2009-06-28 00:21:21 +0000 | [diff] [blame] | 29 | #include "llvm/Instructions.h" |
Andreas Bolka | 80478de | 2009-07-29 05:35:53 +0000 | [diff] [blame] | 30 | #include "llvm/Operator.h" |
Andreas Bolka | 127c2e7 | 2009-07-24 23:19:28 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Allocator.h" |
Andreas Bolka | 5771ed9 | 2009-06-30 02:12:10 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Debug.h" |
Edwin Török | 675d562 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ErrorHandling.h" |
Andreas Bolka | 127c2e7 | 2009-07-24 23:19:28 +0000 | [diff] [blame] | 34 | #include "llvm/Support/raw_ostream.h" |
Andreas Bolka | 8f9cd69 | 2009-07-01 21:45:23 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetData.h" |
Andreas Bolka | 306b5b2 | 2009-06-24 21:29:13 +0000 | [diff] [blame] | 36 | using namespace llvm; |
| 37 | |
Andreas Bolka | 43aa1e0 | 2009-07-28 19:49:49 +0000 | [diff] [blame] | 38 | STATISTIC(NumAnswered, "Number of dependence queries answered"); |
| 39 | STATISTIC(NumAnalysed, "Number of distinct dependence pairs analysed"); |
| 40 | STATISTIC(NumDependent, "Number of pairs with dependent accesses"); |
| 41 | STATISTIC(NumIndependent, "Number of pairs with independent accesses"); |
| 42 | STATISTIC(NumUnknown, "Number of pairs with unknown accesses"); |
| 43 | |
Andreas Bolka | 306b5b2 | 2009-06-24 21:29:13 +0000 | [diff] [blame] | 44 | LoopPass *llvm::createLoopDependenceAnalysisPass() { |
| 45 | return new LoopDependenceAnalysis(); |
| 46 | } |
| 47 | |
| 48 | static RegisterPass<LoopDependenceAnalysis> |
| 49 | R("lda", "Loop Dependence Analysis", false, true); |
| 50 | char LoopDependenceAnalysis::ID = 0; |
| 51 | |
| 52 | //===----------------------------------------------------------------------===// |
Andreas Bolka | f17ab7f | 2009-06-28 00:21:21 +0000 | [diff] [blame] | 53 | // Utility Functions |
| 54 | //===----------------------------------------------------------------------===// |
| 55 | |
Andreas Bolka | fc8a04a | 2009-06-29 18:51:11 +0000 | [diff] [blame] | 56 | static inline bool IsMemRefInstr(const Value *V) { |
| 57 | const Instruction *I = dyn_cast<const Instruction>(V); |
| 58 | return I && (I->mayReadFromMemory() || I->mayWriteToMemory()); |
Andreas Bolka | f17ab7f | 2009-06-28 00:21:21 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Andreas Bolka | d14a5eb | 2009-07-23 01:57:06 +0000 | [diff] [blame] | 61 | static void GetMemRefInstrs(const Loop *L, |
| 62 | SmallVectorImpl<Instruction*> &Memrefs) { |
Andreas Bolka | 158c590 | 2009-06-28 00:35:22 +0000 | [diff] [blame] | 63 | for (Loop::block_iterator b = L->block_begin(), be = L->block_end(); |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 64 | b != be; ++b) |
Andreas Bolka | 158c590 | 2009-06-28 00:35:22 +0000 | [diff] [blame] | 65 | for (BasicBlock::iterator i = (*b)->begin(), ie = (*b)->end(); |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 66 | i != ie; ++i) |
Andreas Bolka | 88a17f0 | 2009-06-29 00:50:26 +0000 | [diff] [blame] | 67 | if (IsMemRefInstr(i)) |
Andreas Bolka | d14a5eb | 2009-07-23 01:57:06 +0000 | [diff] [blame] | 68 | Memrefs.push_back(i); |
Andreas Bolka | 158c590 | 2009-06-28 00:35:22 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Andreas Bolka | 5771ed9 | 2009-06-30 02:12:10 +0000 | [diff] [blame] | 71 | static bool IsLoadOrStoreInst(Value *I) { |
| 72 | return isa<LoadInst>(I) || isa<StoreInst>(I); |
| 73 | } |
| 74 | |
| 75 | static Value *GetPointerOperand(Value *I) { |
| 76 | if (LoadInst *i = dyn_cast<LoadInst>(I)) |
| 77 | return i->getPointerOperand(); |
| 78 | if (StoreInst *i = dyn_cast<StoreInst>(I)) |
| 79 | return i->getPointerOperand(); |
Edwin Török | bd448e3 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 80 | llvm_unreachable("Value is no load or store instruction!"); |
Andreas Bolka | 5771ed9 | 2009-06-30 02:12:10 +0000 | [diff] [blame] | 81 | // Never reached. |
| 82 | return 0; |
| 83 | } |
| 84 | |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 85 | static AliasAnalysis::AliasResult UnderlyingObjectsAlias(AliasAnalysis *AA, |
| 86 | const Value *A, |
| 87 | const Value *B) { |
| 88 | const Value *aObj = A->getUnderlyingObject(); |
| 89 | const Value *bObj = B->getUnderlyingObject(); |
| 90 | return AA->alias(aObj, AA->getTypeStoreSize(aObj->getType()), |
| 91 | bObj, AA->getTypeStoreSize(bObj->getType())); |
| 92 | } |
| 93 | |
Andreas Bolka | 80478de | 2009-07-29 05:35:53 +0000 | [diff] [blame] | 94 | static inline const SCEV *GetZeroSCEV(ScalarEvolution *SE) { |
| 95 | return SE->getConstant(Type::Int32Ty, 0L); |
| 96 | } |
| 97 | |
Andreas Bolka | f17ab7f | 2009-06-28 00:21:21 +0000 | [diff] [blame] | 98 | //===----------------------------------------------------------------------===// |
| 99 | // Dependence Testing |
| 100 | //===----------------------------------------------------------------------===// |
| 101 | |
Andreas Bolka | d14a5eb | 2009-07-23 01:57:06 +0000 | [diff] [blame] | 102 | bool LoopDependenceAnalysis::isDependencePair(const Value *A, |
| 103 | const Value *B) const { |
| 104 | return IsMemRefInstr(A) && |
| 105 | IsMemRefInstr(B) && |
| 106 | (cast<const Instruction>(A)->mayWriteToMemory() || |
| 107 | cast<const Instruction>(B)->mayWriteToMemory()); |
Andreas Bolka | f17ab7f | 2009-06-28 00:21:21 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 110 | bool LoopDependenceAnalysis::findOrInsertDependencePair(Value *A, |
| 111 | Value *B, |
Andreas Bolka | 0a528a0 | 2009-07-23 14:32:46 +0000 | [diff] [blame] | 112 | DependencePair *&P) { |
| 113 | void *insertPos = 0; |
| 114 | FoldingSetNodeID id; |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 115 | id.AddPointer(A); |
| 116 | id.AddPointer(B); |
Andreas Bolka | 5771ed9 | 2009-06-30 02:12:10 +0000 | [diff] [blame] | 117 | |
Andreas Bolka | 0a528a0 | 2009-07-23 14:32:46 +0000 | [diff] [blame] | 118 | P = Pairs.FindNodeOrInsertPos(id, insertPos); |
| 119 | if (P) return true; |
Andreas Bolka | 5771ed9 | 2009-06-30 02:12:10 +0000 | [diff] [blame] | 120 | |
Andreas Bolka | 0a528a0 | 2009-07-23 14:32:46 +0000 | [diff] [blame] | 121 | P = PairAllocator.Allocate<DependencePair>(); |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 122 | new (P) DependencePair(id, A, B); |
Andreas Bolka | 0a528a0 | 2009-07-23 14:32:46 +0000 | [diff] [blame] | 123 | Pairs.InsertNode(P, insertPos); |
| 124 | return false; |
| 125 | } |
| 126 | |
Andreas Bolka | 3bbe7de | 2009-08-03 01:03:48 +0000 | [diff] [blame] | 127 | bool LoopDependenceAnalysis::isLoopInvariant(const SCEV *S) const { |
| 128 | for (const Loop *L = this->L; L != 0; L = L->getParentLoop()) |
| 129 | if (!S->isLoopInvariant(L)) |
| 130 | return false; |
| 131 | return true; |
| 132 | } |
| 133 | |
| 134 | bool LoopDependenceAnalysis::isAffine(const SCEV *S) const { |
| 135 | const SCEVAddRecExpr *rec = dyn_cast<SCEVAddRecExpr>(S); |
| 136 | return isLoopInvariant(S) || (rec && rec->isAffine()); |
| 137 | } |
| 138 | |
Andreas Bolka | 4e66125 | 2009-07-28 19:50:13 +0000 | [diff] [blame] | 139 | LoopDependenceAnalysis::DependenceResult |
Andreas Bolka | 80478de | 2009-07-29 05:35:53 +0000 | [diff] [blame] | 140 | LoopDependenceAnalysis::analyseSubscript(const SCEV *A, |
| 141 | const SCEV *B, |
| 142 | Subscript *S) const { |
Andreas Bolka | a89b3b3 | 2009-07-30 02:26:01 +0000 | [diff] [blame] | 143 | DEBUG(errs() << " Testing subscript: " << *A << ", " << *B << "\n"); |
| 144 | |
| 145 | if (A == B) { |
| 146 | DEBUG(errs() << " -> [D] same SCEV\n"); |
| 147 | return Dependent; |
| 148 | } |
| 149 | |
Andreas Bolka | 3bbe7de | 2009-08-03 01:03:48 +0000 | [diff] [blame] | 150 | if (!isAffine(A) || !isAffine(B)) { |
| 151 | DEBUG(errs() << " -> [?] not affine\n"); |
| 152 | return Unknown; |
| 153 | } |
| 154 | |
Andreas Bolka | a89b3b3 | 2009-07-30 02:26:01 +0000 | [diff] [blame] | 155 | // TODO: Implement ZIV/SIV/MIV testers. |
| 156 | |
| 157 | DEBUG(errs() << " -> [?] cannot analyse subscript\n"); |
| 158 | return Unknown; |
Andreas Bolka | 80478de | 2009-07-29 05:35:53 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | LoopDependenceAnalysis::DependenceResult |
Andreas Bolka | 4e66125 | 2009-07-28 19:50:13 +0000 | [diff] [blame] | 162 | LoopDependenceAnalysis::analysePair(DependencePair *P) const { |
Andreas Bolka | 8956988 | 2009-07-25 12:19:58 +0000 | [diff] [blame] | 163 | DEBUG(errs() << "Analysing:\n" << *P->A << "\n" << *P->B << "\n"); |
Andreas Bolka | 0a528a0 | 2009-07-23 14:32:46 +0000 | [diff] [blame] | 164 | |
Andreas Bolka | 0a528a0 | 2009-07-23 14:32:46 +0000 | [diff] [blame] | 165 | // We only analyse loads and stores but no possible memory accesses by e.g. |
| 166 | // free, call, or invoke instructions. |
| 167 | if (!IsLoadOrStoreInst(P->A) || !IsLoadOrStoreInst(P->B)) { |
Andreas Bolka | 8956988 | 2009-07-25 12:19:58 +0000 | [diff] [blame] | 168 | DEBUG(errs() << "--> [?] no load/store\n"); |
Andreas Bolka | 4e66125 | 2009-07-28 19:50:13 +0000 | [diff] [blame] | 169 | return Unknown; |
Andreas Bolka | 0a528a0 | 2009-07-23 14:32:46 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 172 | Value *aPtr = GetPointerOperand(P->A); |
| 173 | Value *bPtr = GetPointerOperand(P->B); |
Andreas Bolka | 5771ed9 | 2009-06-30 02:12:10 +0000 | [diff] [blame] | 174 | |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 175 | switch (UnderlyingObjectsAlias(AA, aPtr, bPtr)) { |
| 176 | case AliasAnalysis::MayAlias: |
| 177 | // We can not analyse objects if we do not know about their aliasing. |
Andreas Bolka | 8956988 | 2009-07-25 12:19:58 +0000 | [diff] [blame] | 178 | DEBUG(errs() << "---> [?] may alias\n"); |
Andreas Bolka | 4e66125 | 2009-07-28 19:50:13 +0000 | [diff] [blame] | 179 | return Unknown; |
Andreas Bolka | 5771ed9 | 2009-06-30 02:12:10 +0000 | [diff] [blame] | 180 | |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 181 | case AliasAnalysis::NoAlias: |
| 182 | // If the objects noalias, they are distinct, accesses are independent. |
Andreas Bolka | 8956988 | 2009-07-25 12:19:58 +0000 | [diff] [blame] | 183 | DEBUG(errs() << "---> [I] no alias\n"); |
Andreas Bolka | 4e66125 | 2009-07-28 19:50:13 +0000 | [diff] [blame] | 184 | return Independent; |
Andreas Bolka | 5771ed9 | 2009-06-30 02:12:10 +0000 | [diff] [blame] | 185 | |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 186 | case AliasAnalysis::MustAlias: |
| 187 | break; // The underlying objects alias, test accesses for dependence. |
| 188 | } |
Andreas Bolka | 8f9cd69 | 2009-07-01 21:45:23 +0000 | [diff] [blame] | 189 | |
Andreas Bolka | 80478de | 2009-07-29 05:35:53 +0000 | [diff] [blame] | 190 | const GEPOperator *aGEP = dyn_cast<GEPOperator>(aPtr); |
| 191 | const GEPOperator *bGEP = dyn_cast<GEPOperator>(bPtr); |
| 192 | |
| 193 | if (!aGEP || !bGEP) |
| 194 | return Unknown; |
| 195 | |
| 196 | // FIXME: Is filtering coupled subscripts necessary? |
| 197 | |
| 198 | // Analyse indices pairwise (FIXME: use GetGEPOperands from BasicAA), adding |
| 199 | // trailing zeroes to the smaller GEP, if needed. |
| 200 | GEPOperator::const_op_iterator aIdx = aGEP->idx_begin(), |
| 201 | aEnd = aGEP->idx_end(), |
| 202 | bIdx = bGEP->idx_begin(), |
| 203 | bEnd = bGEP->idx_end(); |
| 204 | while (aIdx != aEnd && bIdx != bEnd) { |
| 205 | const SCEV* aSCEV = (aIdx != aEnd) ? SE->getSCEV(*aIdx) : GetZeroSCEV(SE); |
| 206 | const SCEV* bSCEV = (bIdx != bEnd) ? SE->getSCEV(*bIdx) : GetZeroSCEV(SE); |
| 207 | Subscript subscript; |
| 208 | DependenceResult result = analyseSubscript(aSCEV, bSCEV, &subscript); |
| 209 | if (result != Dependent) { |
| 210 | // We either proved independence or failed to analyse this subscript. |
| 211 | // Further subscripts will not improve the situation, so abort early. |
| 212 | return result; |
| 213 | } |
| 214 | P->Subscripts.push_back(subscript); |
| 215 | if (aIdx != aEnd) ++aIdx; |
| 216 | if (bIdx != bEnd) ++bIdx; |
| 217 | } |
| 218 | // Either there were no subscripts or all subscripts were analysed to be |
| 219 | // dependent; in both cases we know the accesses are dependent. |
| 220 | return Dependent; |
Andreas Bolka | 0a528a0 | 2009-07-23 14:32:46 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | bool LoopDependenceAnalysis::depends(Value *A, Value *B) { |
| 224 | assert(isDependencePair(A, B) && "Values form no dependence pair!"); |
Andreas Bolka | 43aa1e0 | 2009-07-28 19:49:49 +0000 | [diff] [blame] | 225 | ++NumAnswered; |
Andreas Bolka | 0a528a0 | 2009-07-23 14:32:46 +0000 | [diff] [blame] | 226 | |
| 227 | DependencePair *p; |
| 228 | if (!findOrInsertDependencePair(A, B, p)) { |
| 229 | // The pair is not cached, so analyse it. |
Andreas Bolka | 43aa1e0 | 2009-07-28 19:49:49 +0000 | [diff] [blame] | 230 | ++NumAnalysed; |
Andreas Bolka | 4e66125 | 2009-07-28 19:50:13 +0000 | [diff] [blame] | 231 | switch (p->Result = analysePair(p)) { |
Andreas Bolka | 43aa1e0 | 2009-07-28 19:49:49 +0000 | [diff] [blame] | 232 | case Dependent: ++NumDependent; break; |
| 233 | case Independent: ++NumIndependent; break; |
| 234 | case Unknown: ++NumUnknown; break; |
| 235 | } |
Andreas Bolka | 0a528a0 | 2009-07-23 14:32:46 +0000 | [diff] [blame] | 236 | } |
| 237 | return p->Result != Independent; |
Andreas Bolka | f17ab7f | 2009-06-28 00:21:21 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | //===----------------------------------------------------------------------===// |
Andreas Bolka | 306b5b2 | 2009-06-24 21:29:13 +0000 | [diff] [blame] | 241 | // LoopDependenceAnalysis Implementation |
| 242 | //===----------------------------------------------------------------------===// |
| 243 | |
| 244 | bool LoopDependenceAnalysis::runOnLoop(Loop *L, LPPassManager &) { |
| 245 | this->L = L; |
Andreas Bolka | 8f9cd69 | 2009-07-01 21:45:23 +0000 | [diff] [blame] | 246 | AA = &getAnalysis<AliasAnalysis>(); |
Andreas Bolka | 306b5b2 | 2009-06-24 21:29:13 +0000 | [diff] [blame] | 247 | SE = &getAnalysis<ScalarEvolution>(); |
| 248 | return false; |
| 249 | } |
| 250 | |
Andreas Bolka | 0a528a0 | 2009-07-23 14:32:46 +0000 | [diff] [blame] | 251 | void LoopDependenceAnalysis::releaseMemory() { |
| 252 | Pairs.clear(); |
| 253 | PairAllocator.Reset(); |
| 254 | } |
| 255 | |
Andreas Bolka | 306b5b2 | 2009-06-24 21:29:13 +0000 | [diff] [blame] | 256 | void LoopDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { |
| 257 | AU.setPreservesAll(); |
Andreas Bolka | 8f9cd69 | 2009-07-01 21:45:23 +0000 | [diff] [blame] | 258 | AU.addRequiredTransitive<AliasAnalysis>(); |
Andreas Bolka | b88ee91 | 2009-06-28 00:16:08 +0000 | [diff] [blame] | 259 | AU.addRequiredTransitive<ScalarEvolution>(); |
| 260 | } |
| 261 | |
Andreas Bolka | d14a5eb | 2009-07-23 01:57:06 +0000 | [diff] [blame] | 262 | static void PrintLoopInfo(raw_ostream &OS, |
| 263 | LoopDependenceAnalysis *LDA, const Loop *L) { |
Andreas Bolka | b88ee91 | 2009-06-28 00:16:08 +0000 | [diff] [blame] | 264 | if (!L->empty()) return; // ignore non-innermost loops |
| 265 | |
Andreas Bolka | b512fb0 | 2009-07-03 01:42:52 +0000 | [diff] [blame] | 266 | SmallVector<Instruction*, 8> memrefs; |
| 267 | GetMemRefInstrs(L, memrefs); |
| 268 | |
Andreas Bolka | b88ee91 | 2009-06-28 00:16:08 +0000 | [diff] [blame] | 269 | OS << "Loop at depth " << L->getLoopDepth() << ", header block: "; |
| 270 | WriteAsOperand(OS, L->getHeader(), false); |
| 271 | OS << "\n"; |
Andreas Bolka | 158c590 | 2009-06-28 00:35:22 +0000 | [diff] [blame] | 272 | |
Andreas Bolka | 158c590 | 2009-06-28 00:35:22 +0000 | [diff] [blame] | 273 | OS << " Load/store instructions: " << memrefs.size() << "\n"; |
Andreas Bolka | b512fb0 | 2009-07-03 01:42:52 +0000 | [diff] [blame] | 274 | for (SmallVector<Instruction*, 8>::const_iterator x = memrefs.begin(), |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 275 | end = memrefs.end(); x != end; ++x) |
Andreas Bolka | d14a5eb | 2009-07-23 01:57:06 +0000 | [diff] [blame] | 276 | OS << "\t" << (x - memrefs.begin()) << ": " << **x << "\n"; |
Andreas Bolka | b512fb0 | 2009-07-03 01:42:52 +0000 | [diff] [blame] | 277 | |
Andreas Bolka | 158c590 | 2009-06-28 00:35:22 +0000 | [diff] [blame] | 278 | OS << " Pairwise dependence results:\n"; |
| 279 | for (SmallVector<Instruction*, 8>::const_iterator x = memrefs.begin(), |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 280 | end = memrefs.end(); x != end; ++x) |
Andreas Bolka | 158c590 | 2009-06-28 00:35:22 +0000 | [diff] [blame] | 281 | for (SmallVector<Instruction*, 8>::const_iterator y = x + 1; |
Andreas Bolka | e00b494 | 2009-07-28 19:49:25 +0000 | [diff] [blame] | 282 | y != end; ++y) |
Andreas Bolka | 158c590 | 2009-06-28 00:35:22 +0000 | [diff] [blame] | 283 | if (LDA->isDependencePair(*x, *y)) |
| 284 | OS << "\t" << (x - memrefs.begin()) << "," << (y - memrefs.begin()) |
| 285 | << ": " << (LDA->depends(*x, *y) ? "dependent" : "independent") |
| 286 | << "\n"; |
Andreas Bolka | b88ee91 | 2009-06-28 00:16:08 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void LoopDependenceAnalysis::print(raw_ostream &OS, const Module*) const { |
Andreas Bolka | 158c590 | 2009-06-28 00:35:22 +0000 | [diff] [blame] | 290 | // TODO: doc why const_cast is safe |
| 291 | PrintLoopInfo(OS, const_cast<LoopDependenceAnalysis*>(this), this->L); |
Andreas Bolka | b88ee91 | 2009-06-28 00:16:08 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void LoopDependenceAnalysis::print(std::ostream &OS, const Module *M) const { |
| 295 | raw_os_ostream os(OS); |
| 296 | print(os, M); |
Andreas Bolka | 306b5b2 | 2009-06-24 21:29:13 +0000 | [diff] [blame] | 297 | } |