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