Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 1 | //===- MemoryDependenceAnalysis.cpp - Mem Deps Implementation --*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements an analysis that determines, for a given memory |
| 11 | // operation, what preceding memory operations it depends on. It builds on |
Owen Anderson | 80b1f09 | 2007-08-08 22:01:54 +0000 | [diff] [blame] | 12 | // alias analysis information, and tries to provide a lazy, caching interface to |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 13 | // a common kind of alias information query. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Chris Lattner | 0e575f4 | 2008-11-28 21:45:17 +0000 | [diff] [blame] | 17 | #define DEBUG_TYPE "memdep" |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 18 | #include "llvm/Analysis/MemoryDependenceAnalysis.h" |
Owen Anderson | 7a616a1 | 2007-07-10 17:25:03 +0000 | [diff] [blame] | 19 | #include "llvm/Constants.h" |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 20 | #include "llvm/Instructions.h" |
| 21 | #include "llvm/Function.h" |
| 22 | #include "llvm/Analysis/AliasAnalysis.h" |
Chris Lattner | baad888 | 2008-11-28 22:28:27 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/Statistic.h" |
| 24 | #include "llvm/ADT/STLExtras.h" |
Owen Anderson | 4beedbd | 2007-07-24 21:52:37 +0000 | [diff] [blame] | 25 | #include "llvm/Support/CFG.h" |
Tanya Lattner | 63aa160 | 2008-02-06 00:54:55 +0000 | [diff] [blame] | 26 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | 0e575f4 | 2008-11-28 21:45:17 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Debug.h" |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetData.h" |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 29 | using namespace llvm; |
| 30 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 31 | STATISTIC(NumCacheNonLocal, "Number of fully cached non-local responses"); |
| 32 | STATISTIC(NumCacheDirtyNonLocal, "Number of dirty cached non-local responses"); |
Chris Lattner | 0ec48dd | 2008-11-29 22:02:15 +0000 | [diff] [blame] | 33 | STATISTIC(NumUncacheNonLocal, "Number of uncached non-local responses"); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 34 | char MemoryDependenceAnalysis::ID = 0; |
| 35 | |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 36 | // Register this pass... |
Owen Anderson | 776ee1f | 2007-07-10 20:21:08 +0000 | [diff] [blame] | 37 | static RegisterPass<MemoryDependenceAnalysis> X("memdep", |
Chris Lattner | 0e575f4 | 2008-11-28 21:45:17 +0000 | [diff] [blame] | 38 | "Memory Dependence Analysis", false, true); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 39 | |
| 40 | /// getAnalysisUsage - Does not modify anything. It uses Alias Analysis. |
| 41 | /// |
| 42 | void MemoryDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { |
| 43 | AU.setPreservesAll(); |
| 44 | AU.addRequiredTransitive<AliasAnalysis>(); |
| 45 | AU.addRequiredTransitive<TargetData>(); |
| 46 | } |
| 47 | |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 48 | bool MemoryDependenceAnalysis::runOnFunction(Function &) { |
| 49 | AA = &getAnalysis<AliasAnalysis>(); |
| 50 | TD = &getAnalysis<TargetData>(); |
| 51 | return false; |
| 52 | } |
| 53 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 54 | |
Owen Anderson | 642a9e3 | 2007-08-08 22:26:03 +0000 | [diff] [blame] | 55 | /// getCallSiteDependency - Private helper for finding the local dependencies |
| 56 | /// of a call site. |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 57 | MemDepResult MemoryDependenceAnalysis:: |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame^] | 58 | getCallSiteDependency(CallSite CS, BasicBlock::iterator ScanIt, BasicBlock *BB) { |
Owen Anderson | 642a9e3 | 2007-08-08 22:26:03 +0000 | [diff] [blame] | 59 | // Walk backwards through the block, looking for dependencies |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 60 | while (ScanIt != BB->begin()) { |
| 61 | Instruction *Inst = --ScanIt; |
Owen Anderson | 5f32320 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 62 | |
| 63 | // If this inst is a memory op, get the pointer it accessed |
Chris Lattner | 00314b3 | 2008-11-29 09:15:21 +0000 | [diff] [blame] | 64 | Value *Pointer = 0; |
| 65 | uint64_t PointerSize = 0; |
| 66 | if (StoreInst *S = dyn_cast<StoreInst>(Inst)) { |
| 67 | Pointer = S->getPointerOperand(); |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 68 | PointerSize = TD->getTypeStoreSize(S->getOperand(0)->getType()); |
Chris Lattner | 00314b3 | 2008-11-29 09:15:21 +0000 | [diff] [blame] | 69 | } else if (VAArgInst *V = dyn_cast<VAArgInst>(Inst)) { |
| 70 | Pointer = V->getOperand(0); |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 71 | PointerSize = TD->getTypeStoreSize(V->getType()); |
Chris Lattner | 00314b3 | 2008-11-29 09:15:21 +0000 | [diff] [blame] | 72 | } else if (FreeInst *F = dyn_cast<FreeInst>(Inst)) { |
| 73 | Pointer = F->getPointerOperand(); |
Owen Anderson | 5f32320 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 74 | |
| 75 | // FreeInsts erase the entire structure |
Chris Lattner | 00314b3 | 2008-11-29 09:15:21 +0000 | [diff] [blame] | 76 | PointerSize = ~0UL; |
| 77 | } else if (isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) { |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame^] | 78 | CallSite InstCS = CallSite::get(Inst); |
| 79 | // If these two calls do not interfere, look past it. |
| 80 | if (AA->getModRefInfo(CS, InstCS) == AliasAnalysis::NoModRef) |
Chris Lattner | 00314b3 | 2008-11-29 09:15:21 +0000 | [diff] [blame] | 81 | continue; |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame^] | 82 | |
| 83 | // FIXME: If this is a ref/ref result, we should ignore it! |
| 84 | // X = strlen(P); |
| 85 | // Y = strlen(Q); |
| 86 | // Z = strlen(P); // Z = X |
| 87 | |
| 88 | // If they interfere, we generally return clobber. However, if they are |
| 89 | // calls to the same read-only functions we return Def. |
| 90 | if (!AA->onlyReadsMemory(CS) || CS.getCalledFunction() == 0 || |
| 91 | CS.getCalledFunction() != InstCS.getCalledFunction()) |
| 92 | return MemDepResult::getClobber(Inst); |
| 93 | return MemDepResult::getDef(Inst); |
Chris Lattner | cfbb634 | 2008-11-30 01:44:00 +0000 | [diff] [blame] | 94 | } else { |
| 95 | // Non-memory instruction. |
Owen Anderson | 202da14 | 2007-07-10 20:39:07 +0000 | [diff] [blame] | 96 | continue; |
Chris Lattner | cfbb634 | 2008-11-30 01:44:00 +0000 | [diff] [blame] | 97 | } |
Owen Anderson | 5f32320 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 98 | |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame^] | 99 | if (AA->getModRefInfo(CS, Pointer, PointerSize) != AliasAnalysis::NoModRef) |
| 100 | return MemDepResult::getClobber(Inst); |
Owen Anderson | 5f32320 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 103 | // No dependence found. |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 104 | return MemDepResult::getNonLocal(); |
Owen Anderson | 5f32320 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 107 | /// getDependencyFrom - Return the instruction on which a memory operation |
| 108 | /// depends. |
| 109 | MemDepResult MemoryDependenceAnalysis:: |
| 110 | getDependencyFrom(Instruction *QueryInst, BasicBlock::iterator ScanIt, |
| 111 | BasicBlock *BB) { |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 112 | // Get the pointer value for which dependence will be determined |
Chris Lattner | 25a0814 | 2008-11-29 08:51:16 +0000 | [diff] [blame] | 113 | Value *MemPtr = 0; |
| 114 | uint64_t MemSize = 0; |
| 115 | bool MemVolatile = false; |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 116 | |
| 117 | if (StoreInst* S = dyn_cast<StoreInst>(QueryInst)) { |
Chris Lattner | 25a0814 | 2008-11-29 08:51:16 +0000 | [diff] [blame] | 118 | MemPtr = S->getPointerOperand(); |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 119 | MemSize = TD->getTypeStoreSize(S->getOperand(0)->getType()); |
Chris Lattner | 25a0814 | 2008-11-29 08:51:16 +0000 | [diff] [blame] | 120 | MemVolatile = S->isVolatile(); |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame^] | 121 | } else if (LoadInst* LI = dyn_cast<LoadInst>(QueryInst)) { |
| 122 | MemPtr = LI->getPointerOperand(); |
| 123 | MemSize = TD->getTypeStoreSize(LI->getType()); |
| 124 | MemVolatile = LI->isVolatile(); |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 125 | } else if (VAArgInst* V = dyn_cast<VAArgInst>(QueryInst)) { |
Chris Lattner | 25a0814 | 2008-11-29 08:51:16 +0000 | [diff] [blame] | 126 | MemPtr = V->getOperand(0); |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 127 | MemSize = TD->getTypeStoreSize(V->getType()); |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 128 | } else if (FreeInst* F = dyn_cast<FreeInst>(QueryInst)) { |
Chris Lattner | 25a0814 | 2008-11-29 08:51:16 +0000 | [diff] [blame] | 129 | MemPtr = F->getPointerOperand(); |
| 130 | // FreeInsts erase the entire structure, not just a field. |
| 131 | MemSize = ~0UL; |
Chris Lattner | 6951381 | 2008-12-05 18:46:19 +0000 | [diff] [blame] | 132 | } else { |
| 133 | assert((isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)) && |
| 134 | "Can only get dependency info for memory instructions!"); |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 135 | return getCallSiteDependency(CallSite::get(QueryInst), ScanIt, BB); |
Chris Lattner | 6951381 | 2008-12-05 18:46:19 +0000 | [diff] [blame] | 136 | } |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 137 | |
Owen Anderson | 642a9e3 | 2007-08-08 22:26:03 +0000 | [diff] [blame] | 138 | // Walk backwards through the basic block, looking for dependencies |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 139 | while (ScanIt != BB->begin()) { |
| 140 | Instruction *Inst = --ScanIt; |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 141 | |
Chris Lattner | cfbb634 | 2008-11-30 01:44:00 +0000 | [diff] [blame] | 142 | // Values depend on loads if the pointers are must aliased. This means that |
| 143 | // a load depends on another must aliased load from the same value. |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame^] | 144 | if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) { |
| 145 | // If the access is volatile and this is volatile, return a dependence. |
| 146 | if (MemVolatile && LI->isVolatile()) |
| 147 | return MemDepResult::getClobber(LI); |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 148 | |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame^] | 149 | Value *Pointer = LI->getPointerOperand(); |
| 150 | uint64_t PointerSize = TD->getTypeStoreSize(LI->getType()); |
| 151 | |
| 152 | // If we found a pointer, check if it could be the same as our pointer. |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 153 | AliasAnalysis::AliasResult R = |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 154 | AA->alias(Pointer, PointerSize, MemPtr, MemSize); |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 155 | if (R == AliasAnalysis::NoAlias) |
| 156 | continue; |
| 157 | |
| 158 | // May-alias loads don't depend on each other without a dependence. |
| 159 | if (isa<LoadInst>(QueryInst) && R == AliasAnalysis::MayAlias) |
| 160 | continue; |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame^] | 161 | return MemDepResult::getDef(Inst); |
| 162 | } |
| 163 | |
| 164 | if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) { |
| 165 | // If the access is volatile and this is volatile, return a dependence. |
| 166 | if (MemVolatile && SI->isVolatile()) |
| 167 | return MemDepResult::getClobber(SI); |
| 168 | |
| 169 | Value *Pointer = SI->getPointerOperand(); |
| 170 | uint64_t PointerSize = TD->getTypeStoreSize(SI->getOperand(0)->getType()); |
| 171 | |
| 172 | // If we found a pointer, check if it could be the same as our pointer. |
| 173 | AliasAnalysis::AliasResult R = |
| 174 | AA->alias(Pointer, PointerSize, MemPtr, MemSize); |
| 175 | |
| 176 | if (R == AliasAnalysis::NoAlias) |
| 177 | continue; |
| 178 | if (R == AliasAnalysis::MayAlias) |
| 179 | return MemDepResult::getClobber(Inst); |
| 180 | return MemDepResult::getDef(Inst); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 181 | } |
Chris Lattner | 237a828 | 2008-11-30 01:39:32 +0000 | [diff] [blame] | 182 | |
| 183 | // If this is an allocation, and if we know that the accessed pointer is to |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame^] | 184 | // the allocation, return Def. This means that there is no dependence and |
Chris Lattner | 237a828 | 2008-11-30 01:39:32 +0000 | [diff] [blame] | 185 | // the access can be optimized based on that. For example, a load could |
| 186 | // turn into undef. |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 187 | if (AllocationInst *AI = dyn_cast<AllocationInst>(Inst)) { |
Chris Lattner | 237a828 | 2008-11-30 01:39:32 +0000 | [diff] [blame] | 188 | Value *AccessPtr = MemPtr->getUnderlyingObject(); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 189 | |
Chris Lattner | 237a828 | 2008-11-30 01:39:32 +0000 | [diff] [blame] | 190 | if (AccessPtr == AI || |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 191 | AA->alias(AI, 1, AccessPtr, 1) == AliasAnalysis::MustAlias) |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame^] | 192 | return MemDepResult::getDef(AI); |
Chris Lattner | 237a828 | 2008-11-30 01:39:32 +0000 | [diff] [blame] | 193 | continue; |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 194 | } |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 195 | |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame^] | 196 | // See if this instruction (e.g. a call or vaarg) mod/ref's the pointer. |
| 197 | if (AA->getModRefInfo(Inst, MemPtr, MemSize) == AliasAnalysis::NoModRef) |
Chris Lattner | 25a0814 | 2008-11-29 08:51:16 +0000 | [diff] [blame] | 198 | continue; |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 199 | |
| 200 | // Otherwise, there is a dependence. |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame^] | 201 | return MemDepResult::getClobber(Inst); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 204 | // If we found nothing, return the non-local flag. |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 205 | return MemDepResult::getNonLocal(); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 208 | /// getDependency - Return the instruction on which a memory operation |
| 209 | /// depends. |
| 210 | MemDepResult MemoryDependenceAnalysis::getDependency(Instruction *QueryInst) { |
| 211 | Instruction *ScanPos = QueryInst; |
| 212 | |
| 213 | // Check for a cached result |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 214 | MemDepResult &LocalCache = LocalDeps[QueryInst]; |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 215 | |
Chris Lattner | 0ec48dd | 2008-11-29 22:02:15 +0000 | [diff] [blame] | 216 | // If the cached entry is non-dirty, just return it. Note that this depends |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 217 | // on MemDepResult's default constructing to 'dirty'. |
| 218 | if (!LocalCache.isDirty()) |
| 219 | return LocalCache; |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 220 | |
| 221 | // Otherwise, if we have a dirty entry, we know we can start the scan at that |
| 222 | // instruction, which may save us some work. |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 223 | if (Instruction *Inst = LocalCache.getInst()) { |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 224 | ScanPos = Inst; |
Chris Lattner | 4a69bad | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 225 | |
| 226 | SmallPtrSet<Instruction*, 4> &InstMap = ReverseLocalDeps[Inst]; |
| 227 | InstMap.erase(QueryInst); |
| 228 | if (InstMap.empty()) |
| 229 | ReverseLocalDeps.erase(Inst); |
| 230 | } |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 231 | |
| 232 | // Do the scan. |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 233 | LocalCache = getDependencyFrom(QueryInst, ScanPos, QueryInst->getParent()); |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 234 | |
| 235 | // Remember the result! |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 236 | if (Instruction *I = LocalCache.getInst()) |
Chris Lattner | 8c46527 | 2008-11-29 09:20:15 +0000 | [diff] [blame] | 237 | ReverseLocalDeps[I].insert(QueryInst); |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 238 | |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 239 | return LocalCache; |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 242 | /// getNonLocalDependency - Perform a full dependency query for the |
| 243 | /// specified instruction, returning the set of blocks that the value is |
| 244 | /// potentially live across. The returned set of results will include a |
| 245 | /// "NonLocal" result for all blocks where the value is live across. |
| 246 | /// |
| 247 | /// This method assumes the instruction returns a "nonlocal" dependency |
| 248 | /// within its own block. |
| 249 | /// |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 250 | const MemoryDependenceAnalysis::NonLocalDepInfo & |
| 251 | MemoryDependenceAnalysis::getNonLocalDependency(Instruction *QueryInst) { |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 252 | assert(getDependency(QueryInst).isNonLocal() && |
| 253 | "getNonLocalDependency should only be used on insts with non-local deps!"); |
Chris Lattner | 4a69bad | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 254 | PerInstNLInfo &CacheP = NonLocalDeps[QueryInst]; |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 255 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 256 | NonLocalDepInfo &Cache = CacheP.first; |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 257 | |
| 258 | /// DirtyBlocks - This is the set of blocks that need to be recomputed. In |
| 259 | /// the cached case, this can happen due to instructions being deleted etc. In |
| 260 | /// the uncached case, this starts out as the set of predecessors we care |
| 261 | /// about. |
| 262 | SmallVector<BasicBlock*, 32> DirtyBlocks; |
| 263 | |
| 264 | if (!Cache.empty()) { |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 265 | // Okay, we have a cache entry. If we know it is not dirty, just return it |
| 266 | // with no computation. |
| 267 | if (!CacheP.second) { |
| 268 | NumCacheNonLocal++; |
| 269 | return Cache; |
| 270 | } |
| 271 | |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 272 | // If we already have a partially computed set of results, scan them to |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 273 | // determine what is dirty, seeding our initial DirtyBlocks worklist. |
| 274 | for (NonLocalDepInfo::iterator I = Cache.begin(), E = Cache.end(); |
| 275 | I != E; ++I) |
| 276 | if (I->second.isDirty()) |
| 277 | DirtyBlocks.push_back(I->first); |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 278 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 279 | // Sort the cache so that we can do fast binary search lookups below. |
| 280 | std::sort(Cache.begin(), Cache.end()); |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 281 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 282 | ++NumCacheDirtyNonLocal; |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 283 | //cerr << "CACHED CASE: " << DirtyBlocks.size() << " dirty: " |
| 284 | // << Cache.size() << " cached: " << *QueryInst; |
| 285 | } else { |
| 286 | // Seed DirtyBlocks with each of the preds of QueryInst's block. |
| 287 | BasicBlock *QueryBB = QueryInst->getParent(); |
| 288 | DirtyBlocks.append(pred_begin(QueryBB), pred_end(QueryBB)); |
| 289 | NumUncacheNonLocal++; |
| 290 | } |
| 291 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 292 | // Visited checked first, vector in sorted order. |
| 293 | SmallPtrSet<BasicBlock*, 64> Visited; |
| 294 | |
| 295 | unsigned NumSortedEntries = Cache.size(); |
| 296 | |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 297 | // Iterate while we still have blocks to update. |
| 298 | while (!DirtyBlocks.empty()) { |
| 299 | BasicBlock *DirtyBB = DirtyBlocks.back(); |
| 300 | DirtyBlocks.pop_back(); |
| 301 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 302 | // Already processed this block? |
| 303 | if (!Visited.insert(DirtyBB)) |
| 304 | continue; |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 305 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 306 | // Do a binary search to see if we already have an entry for this block in |
| 307 | // the cache set. If so, find it. |
| 308 | NonLocalDepInfo::iterator Entry = |
| 309 | std::upper_bound(Cache.begin(), Cache.begin()+NumSortedEntries, |
| 310 | std::make_pair(DirtyBB, MemDepResult())); |
| 311 | if (Entry != Cache.begin() && (&*Entry)[-1].first == DirtyBB) |
| 312 | --Entry; |
| 313 | |
| 314 | MemDepResult *ExistingResult = 0; |
| 315 | if (Entry != Cache.begin()+NumSortedEntries && |
| 316 | Entry->first == DirtyBB) { |
| 317 | // If we already have an entry, and if it isn't already dirty, the block |
| 318 | // is done. |
| 319 | if (!Entry->second.isDirty()) |
| 320 | continue; |
| 321 | |
| 322 | // Otherwise, remember this slot so we can update the value. |
| 323 | ExistingResult = &Entry->second; |
| 324 | } |
| 325 | |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 326 | // If the dirty entry has a pointer, start scanning from it so we don't have |
| 327 | // to rescan the entire block. |
| 328 | BasicBlock::iterator ScanPos = DirtyBB->end(); |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 329 | if (ExistingResult) { |
| 330 | if (Instruction *Inst = ExistingResult->getInst()) { |
| 331 | ScanPos = Inst; |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 332 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 333 | // We're removing QueryInst's use of Inst. |
| 334 | SmallPtrSet<Instruction*, 4> &InstMap = ReverseNonLocalDeps[Inst]; |
| 335 | InstMap.erase(QueryInst); |
| 336 | if (InstMap.empty()) ReverseNonLocalDeps.erase(Inst); |
| 337 | } |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 338 | } |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 339 | |
Chris Lattner | 73ec3cd | 2008-11-30 01:26:32 +0000 | [diff] [blame] | 340 | // Find out if this block has a local dependency for QueryInst. |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 341 | MemDepResult Dep = getDependencyFrom(QueryInst, ScanPos, DirtyBB); |
| 342 | |
| 343 | // If we had a dirty entry for the block, update it. Otherwise, just add |
| 344 | // a new entry. |
| 345 | if (ExistingResult) |
| 346 | *ExistingResult = Dep; |
| 347 | else |
| 348 | Cache.push_back(std::make_pair(DirtyBB, Dep)); |
| 349 | |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 350 | // If the block has a dependency (i.e. it isn't completely transparent to |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 351 | // the value), remember the association! |
| 352 | if (!Dep.isNonLocal()) { |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 353 | // Keep the ReverseNonLocalDeps map up to date so we can efficiently |
| 354 | // update this when we remove instructions. |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 355 | if (Instruction *Inst = Dep.getInst()) |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 356 | ReverseNonLocalDeps[Inst].insert(QueryInst); |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 357 | } else { |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 358 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 359 | // If the block *is* completely transparent to the load, we need to check |
| 360 | // the predecessors of this block. Add them to our worklist. |
| 361 | DirtyBlocks.append(pred_begin(DirtyBB), pred_end(DirtyBB)); |
| 362 | } |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 365 | return Cache; |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 368 | /// removeInstruction - Remove an instruction from the dependence analysis, |
| 369 | /// updating the dependence of instructions that previously depended on it. |
Owen Anderson | 642a9e3 | 2007-08-08 22:26:03 +0000 | [diff] [blame] | 370 | /// This method attempts to keep the cache coherent using the reverse map. |
Chris Lattner | 5f589dc | 2008-11-28 22:04:47 +0000 | [diff] [blame] | 371 | void MemoryDependenceAnalysis::removeInstruction(Instruction *RemInst) { |
Chris Lattner | 5f589dc | 2008-11-28 22:04:47 +0000 | [diff] [blame] | 372 | // Walk through the Non-local dependencies, removing this one as the value |
| 373 | // for any cached queries. |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 374 | NonLocalDepMapType::iterator NLDI = NonLocalDeps.find(RemInst); |
| 375 | if (NLDI != NonLocalDeps.end()) { |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 376 | NonLocalDepInfo &BlockMap = NLDI->second.first; |
Chris Lattner | 25f4b2b | 2008-11-30 02:30:50 +0000 | [diff] [blame] | 377 | for (NonLocalDepInfo::iterator DI = BlockMap.begin(), DE = BlockMap.end(); |
| 378 | DI != DE; ++DI) |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 379 | if (Instruction *Inst = DI->second.getInst()) |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 380 | ReverseNonLocalDeps[Inst].erase(RemInst); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 381 | NonLocalDeps.erase(NLDI); |
| 382 | } |
Owen Anderson | 5fc4aba | 2007-12-08 01:37:09 +0000 | [diff] [blame] | 383 | |
Chris Lattner | 5f589dc | 2008-11-28 22:04:47 +0000 | [diff] [blame] | 384 | // If we have a cached local dependence query for this instruction, remove it. |
Chris Lattner | baad888 | 2008-11-28 22:28:27 +0000 | [diff] [blame] | 385 | // |
Chris Lattner | 39f372e | 2008-11-29 01:43:36 +0000 | [diff] [blame] | 386 | LocalDepMapType::iterator LocalDepEntry = LocalDeps.find(RemInst); |
| 387 | if (LocalDepEntry != LocalDeps.end()) { |
Chris Lattner | 125ce36 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 388 | // Remove us from DepInst's reverse set now that the local dep info is gone. |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 389 | if (Instruction *Inst = LocalDepEntry->second.getInst()) { |
Chris Lattner | 125ce36 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 390 | SmallPtrSet<Instruction*, 4> &RLD = ReverseLocalDeps[Inst]; |
| 391 | RLD.erase(RemInst); |
| 392 | if (RLD.empty()) |
| 393 | ReverseLocalDeps.erase(Inst); |
| 394 | } |
| 395 | |
Chris Lattner | baad888 | 2008-11-28 22:28:27 +0000 | [diff] [blame] | 396 | // Remove this local dependency info. |
Chris Lattner | 39f372e | 2008-11-29 01:43:36 +0000 | [diff] [blame] | 397 | LocalDeps.erase(LocalDepEntry); |
Chris Lattner | 125ce36 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 398 | } |
Chris Lattner | baad888 | 2008-11-28 22:28:27 +0000 | [diff] [blame] | 399 | |
Chris Lattner | d3d12ec | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 400 | // Loop over all of the things that depend on the instruction we're removing. |
| 401 | // |
Chris Lattner | 4f8c18c | 2008-11-29 23:30:39 +0000 | [diff] [blame] | 402 | SmallVector<std::pair<Instruction*, Instruction*>, 8> ReverseDepsToAdd; |
| 403 | |
Chris Lattner | 8c46527 | 2008-11-29 09:20:15 +0000 | [diff] [blame] | 404 | ReverseDepMapType::iterator ReverseDepIt = ReverseLocalDeps.find(RemInst); |
| 405 | if (ReverseDepIt != ReverseLocalDeps.end()) { |
Chris Lattner | d3d12ec | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 406 | SmallPtrSet<Instruction*, 4> &ReverseDeps = ReverseDepIt->second; |
Chris Lattner | 125ce36 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 407 | // RemInst can't be the terminator if it has stuff depending on it. |
| 408 | assert(!ReverseDeps.empty() && !isa<TerminatorInst>(RemInst) && |
| 409 | "Nothing can locally depend on a terminator"); |
| 410 | |
| 411 | // Anything that was locally dependent on RemInst is now going to be |
| 412 | // dependent on the instruction after RemInst. It will have the dirty flag |
| 413 | // set so it will rescan. This saves having to scan the entire block to get |
| 414 | // to this point. |
| 415 | Instruction *NewDepInst = next(BasicBlock::iterator(RemInst)); |
| 416 | |
Chris Lattner | d3d12ec | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 417 | for (SmallPtrSet<Instruction*, 4>::iterator I = ReverseDeps.begin(), |
| 418 | E = ReverseDeps.end(); I != E; ++I) { |
| 419 | Instruction *InstDependingOnRemInst = *I; |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 420 | assert(InstDependingOnRemInst != RemInst && |
| 421 | "Already removed our local dep info"); |
Chris Lattner | 125ce36 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 422 | |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 423 | LocalDeps[InstDependingOnRemInst] = MemDepResult::getDirty(NewDepInst); |
Chris Lattner | d3d12ec | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 424 | |
Chris Lattner | 125ce36 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 425 | // Make sure to remember that new things depend on NewDepInst. |
| 426 | ReverseDepsToAdd.push_back(std::make_pair(NewDepInst, |
| 427 | InstDependingOnRemInst)); |
Chris Lattner | d3d12ec | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 428 | } |
Chris Lattner | 4f8c18c | 2008-11-29 23:30:39 +0000 | [diff] [blame] | 429 | |
| 430 | ReverseLocalDeps.erase(ReverseDepIt); |
| 431 | |
| 432 | // Add new reverse deps after scanning the set, to avoid invalidating the |
| 433 | // 'ReverseDeps' reference. |
| 434 | while (!ReverseDepsToAdd.empty()) { |
| 435 | ReverseLocalDeps[ReverseDepsToAdd.back().first] |
| 436 | .insert(ReverseDepsToAdd.back().second); |
| 437 | ReverseDepsToAdd.pop_back(); |
| 438 | } |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 439 | } |
Owen Anderson | 4d13de4 | 2007-08-16 21:27:05 +0000 | [diff] [blame] | 440 | |
Chris Lattner | 8c46527 | 2008-11-29 09:20:15 +0000 | [diff] [blame] | 441 | ReverseDepIt = ReverseNonLocalDeps.find(RemInst); |
| 442 | if (ReverseDepIt != ReverseNonLocalDeps.end()) { |
Chris Lattner | d3d12ec | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 443 | SmallPtrSet<Instruction*, 4>& set = ReverseDepIt->second; |
Owen Anderson | 4d13de4 | 2007-08-16 21:27:05 +0000 | [diff] [blame] | 444 | for (SmallPtrSet<Instruction*, 4>::iterator I = set.begin(), E = set.end(); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 445 | I != E; ++I) { |
| 446 | assert(*I != RemInst && "Already removed NonLocalDep info for RemInst"); |
| 447 | |
Chris Lattner | 4a69bad | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 448 | PerInstNLInfo &INLD = NonLocalDeps[*I]; |
Chris Lattner | 4a69bad | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 449 | // The information is now dirty! |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 450 | INLD.second = true; |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 451 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 452 | for (NonLocalDepInfo::iterator DI = INLD.first.begin(), |
| 453 | DE = INLD.first.end(); DI != DE; ++DI) { |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 454 | if (DI->second.getInst() != RemInst) continue; |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 455 | |
| 456 | // Convert to a dirty entry for the subsequent instruction. |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 457 | Instruction *NextI = 0; |
| 458 | if (!RemInst->isTerminator()) { |
| 459 | NextI = next(BasicBlock::iterator(RemInst)); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 460 | ReverseDepsToAdd.push_back(std::make_pair(NextI, *I)); |
Chris Lattner | 0ec48dd | 2008-11-29 22:02:15 +0000 | [diff] [blame] | 461 | } |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 462 | DI->second = MemDepResult::getDirty(NextI); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 463 | } |
| 464 | } |
Chris Lattner | 4f8c18c | 2008-11-29 23:30:39 +0000 | [diff] [blame] | 465 | |
| 466 | ReverseNonLocalDeps.erase(ReverseDepIt); |
| 467 | |
Chris Lattner | 0ec48dd | 2008-11-29 22:02:15 +0000 | [diff] [blame] | 468 | // Add new reverse deps after scanning the set, to avoid invalidating 'Set' |
| 469 | while (!ReverseDepsToAdd.empty()) { |
| 470 | ReverseNonLocalDeps[ReverseDepsToAdd.back().first] |
| 471 | .insert(ReverseDepsToAdd.back().second); |
| 472 | ReverseDepsToAdd.pop_back(); |
| 473 | } |
Owen Anderson | 4d13de4 | 2007-08-16 21:27:05 +0000 | [diff] [blame] | 474 | } |
Owen Anderson | 5fc4aba | 2007-12-08 01:37:09 +0000 | [diff] [blame] | 475 | |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 476 | assert(!NonLocalDeps.count(RemInst) && "RemInst got reinserted?"); |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 477 | AA->deleteValue(RemInst); |
Chris Lattner | 5f589dc | 2008-11-28 22:04:47 +0000 | [diff] [blame] | 478 | DEBUG(verifyRemoved(RemInst)); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 479 | } |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 480 | |
| 481 | /// verifyRemoved - Verify that the specified instruction does not occur |
| 482 | /// in our internal data structures. |
| 483 | void MemoryDependenceAnalysis::verifyRemoved(Instruction *D) const { |
| 484 | for (LocalDepMapType::const_iterator I = LocalDeps.begin(), |
| 485 | E = LocalDeps.end(); I != E; ++I) { |
| 486 | assert(I->first != D && "Inst occurs in data structures"); |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 487 | assert(I->second.getInst() != D && |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 488 | "Inst occurs in data structures"); |
| 489 | } |
| 490 | |
| 491 | for (NonLocalDepMapType::const_iterator I = NonLocalDeps.begin(), |
| 492 | E = NonLocalDeps.end(); I != E; ++I) { |
| 493 | assert(I->first != D && "Inst occurs in data structures"); |
Chris Lattner | 4a69bad | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 494 | const PerInstNLInfo &INLD = I->second; |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 495 | for (NonLocalDepInfo::const_iterator II = INLD.first.begin(), |
| 496 | EE = INLD.first.end(); II != EE; ++II) |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 497 | assert(II->second.getInst() != D && "Inst occurs in data structures"); |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | for (ReverseDepMapType::const_iterator I = ReverseLocalDeps.begin(), |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 501 | E = ReverseLocalDeps.end(); I != E; ++I) { |
| 502 | assert(I->first != D && "Inst occurs in data structures"); |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 503 | for (SmallPtrSet<Instruction*, 4>::const_iterator II = I->second.begin(), |
| 504 | EE = I->second.end(); II != EE; ++II) |
| 505 | assert(*II != D && "Inst occurs in data structures"); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 506 | } |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 507 | |
| 508 | for (ReverseDepMapType::const_iterator I = ReverseNonLocalDeps.begin(), |
| 509 | E = ReverseNonLocalDeps.end(); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 510 | I != E; ++I) { |
| 511 | assert(I->first != D && "Inst occurs in data structures"); |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 512 | for (SmallPtrSet<Instruction*, 4>::const_iterator II = I->second.begin(), |
| 513 | EE = I->second.end(); II != EE; ++II) |
| 514 | assert(*II != D && "Inst occurs in data structures"); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 515 | } |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 516 | } |