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" |
Owen Anderson | 4beedbd | 2007-07-24 21:52:37 +0000 | [diff] [blame] | 24 | #include "llvm/Support/CFG.h" |
Chris Lattner | 0e575f4 | 2008-11-28 21:45:17 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Debug.h" |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetData.h" |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 27 | using namespace llvm; |
| 28 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 29 | STATISTIC(NumCacheNonLocal, "Number of fully cached non-local responses"); |
| 30 | STATISTIC(NumCacheDirtyNonLocal, "Number of dirty cached non-local responses"); |
Chris Lattner | 0ec48dd | 2008-11-29 22:02:15 +0000 | [diff] [blame] | 31 | STATISTIC(NumUncacheNonLocal, "Number of uncached non-local responses"); |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 32 | |
| 33 | STATISTIC(NumCacheNonLocalPtr, |
| 34 | "Number of fully cached non-local ptr responses"); |
| 35 | STATISTIC(NumCacheDirtyNonLocalPtr, |
| 36 | "Number of cached, but dirty, non-local ptr responses"); |
| 37 | STATISTIC(NumUncacheNonLocalPtr, |
| 38 | "Number of uncached non-local ptr responses"); |
Chris Lattner | 11dcd8d | 2008-12-08 07:31:50 +0000 | [diff] [blame^] | 39 | STATISTIC(NumCacheCompleteNonLocalPtr, |
| 40 | "Number of block queries that were completely cached"); |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 41 | |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 42 | char MemoryDependenceAnalysis::ID = 0; |
| 43 | |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 44 | // Register this pass... |
Owen Anderson | 776ee1f | 2007-07-10 20:21:08 +0000 | [diff] [blame] | 45 | static RegisterPass<MemoryDependenceAnalysis> X("memdep", |
Chris Lattner | 0e575f4 | 2008-11-28 21:45:17 +0000 | [diff] [blame] | 46 | "Memory Dependence Analysis", false, true); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 47 | |
| 48 | /// getAnalysisUsage - Does not modify anything. It uses Alias Analysis. |
| 49 | /// |
| 50 | void MemoryDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { |
| 51 | AU.setPreservesAll(); |
| 52 | AU.addRequiredTransitive<AliasAnalysis>(); |
| 53 | AU.addRequiredTransitive<TargetData>(); |
| 54 | } |
| 55 | |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 56 | bool MemoryDependenceAnalysis::runOnFunction(Function &) { |
| 57 | AA = &getAnalysis<AliasAnalysis>(); |
| 58 | TD = &getAnalysis<TargetData>(); |
| 59 | return false; |
| 60 | } |
| 61 | |
Chris Lattner | d44745d | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 62 | /// RemoveFromReverseMap - This is a helper function that removes Val from |
| 63 | /// 'Inst's set in ReverseMap. If the set becomes empty, remove Inst's entry. |
| 64 | template <typename KeyTy> |
| 65 | static void RemoveFromReverseMap(DenseMap<Instruction*, |
| 66 | SmallPtrSet<KeyTy*, 4> > &ReverseMap, |
| 67 | Instruction *Inst, KeyTy *Val) { |
| 68 | typename DenseMap<Instruction*, SmallPtrSet<KeyTy*, 4> >::iterator |
| 69 | InstIt = ReverseMap.find(Inst); |
| 70 | assert(InstIt != ReverseMap.end() && "Reverse map out of sync?"); |
| 71 | bool Found = InstIt->second.erase(Val); |
| 72 | assert(Found && "Invalid reverse map!"); Found=Found; |
| 73 | if (InstIt->second.empty()) |
| 74 | ReverseMap.erase(InstIt); |
| 75 | } |
| 76 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 8ef57c5 | 2008-12-07 00:35:51 +0000 | [diff] [blame] | 78 | /// getCallSiteDependencyFrom - Private helper for finding the local |
| 79 | /// dependencies of a call site. |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 80 | MemDepResult MemoryDependenceAnalysis:: |
Chris Lattner | 8ef57c5 | 2008-12-07 00:35:51 +0000 | [diff] [blame] | 81 | getCallSiteDependencyFrom(CallSite CS, BasicBlock::iterator ScanIt, |
| 82 | BasicBlock *BB) { |
Owen Anderson | 642a9e3 | 2007-08-08 22:26:03 +0000 | [diff] [blame] | 83 | // Walk backwards through the block, looking for dependencies |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 84 | while (ScanIt != BB->begin()) { |
| 85 | Instruction *Inst = --ScanIt; |
Owen Anderson | 5f32320 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 86 | |
| 87 | // If this inst is a memory op, get the pointer it accessed |
Chris Lattner | 00314b3 | 2008-11-29 09:15:21 +0000 | [diff] [blame] | 88 | Value *Pointer = 0; |
| 89 | uint64_t PointerSize = 0; |
| 90 | if (StoreInst *S = dyn_cast<StoreInst>(Inst)) { |
| 91 | Pointer = S->getPointerOperand(); |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 92 | PointerSize = TD->getTypeStoreSize(S->getOperand(0)->getType()); |
Chris Lattner | 00314b3 | 2008-11-29 09:15:21 +0000 | [diff] [blame] | 93 | } else if (VAArgInst *V = dyn_cast<VAArgInst>(Inst)) { |
| 94 | Pointer = V->getOperand(0); |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 95 | PointerSize = TD->getTypeStoreSize(V->getType()); |
Chris Lattner | 00314b3 | 2008-11-29 09:15:21 +0000 | [diff] [blame] | 96 | } else if (FreeInst *F = dyn_cast<FreeInst>(Inst)) { |
| 97 | Pointer = F->getPointerOperand(); |
Owen Anderson | 5f32320 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 98 | |
| 99 | // FreeInsts erase the entire structure |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 100 | PointerSize = ~0ULL; |
Chris Lattner | 00314b3 | 2008-11-29 09:15:21 +0000 | [diff] [blame] | 101 | } else if (isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) { |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 102 | CallSite InstCS = CallSite::get(Inst); |
| 103 | // If these two calls do not interfere, look past it. |
| 104 | if (AA->getModRefInfo(CS, InstCS) == AliasAnalysis::NoModRef) |
Chris Lattner | 00314b3 | 2008-11-29 09:15:21 +0000 | [diff] [blame] | 105 | continue; |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 106 | |
| 107 | // FIXME: If this is a ref/ref result, we should ignore it! |
| 108 | // X = strlen(P); |
| 109 | // Y = strlen(Q); |
| 110 | // Z = strlen(P); // Z = X |
| 111 | |
| 112 | // If they interfere, we generally return clobber. However, if they are |
| 113 | // calls to the same read-only functions we return Def. |
| 114 | if (!AA->onlyReadsMemory(CS) || CS.getCalledFunction() == 0 || |
| 115 | CS.getCalledFunction() != InstCS.getCalledFunction()) |
| 116 | return MemDepResult::getClobber(Inst); |
| 117 | return MemDepResult::getDef(Inst); |
Chris Lattner | cfbb634 | 2008-11-30 01:44:00 +0000 | [diff] [blame] | 118 | } else { |
| 119 | // Non-memory instruction. |
Owen Anderson | 202da14 | 2007-07-10 20:39:07 +0000 | [diff] [blame] | 120 | continue; |
Chris Lattner | cfbb634 | 2008-11-30 01:44:00 +0000 | [diff] [blame] | 121 | } |
Owen Anderson | 5f32320 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 122 | |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 123 | if (AA->getModRefInfo(CS, Pointer, PointerSize) != AliasAnalysis::NoModRef) |
| 124 | return MemDepResult::getClobber(Inst); |
Owen Anderson | 5f32320 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 127 | // No dependence found. If this is the entry block of the function, it is a |
| 128 | // clobber, otherwise it is non-local. |
| 129 | if (BB != &BB->getParent()->getEntryBlock()) |
| 130 | return MemDepResult::getNonLocal(); |
| 131 | return MemDepResult::getClobber(ScanIt); |
Owen Anderson | 5f32320 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Chris Lattner | e79be94 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 134 | /// getPointerDependencyFrom - Return the instruction on which a memory |
| 135 | /// location depends. If isLoad is true, this routine ignore may-aliases with |
| 136 | /// read-only operations. |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 137 | MemDepResult MemoryDependenceAnalysis:: |
Chris Lattner | e79be94 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 138 | getPointerDependencyFrom(Value *MemPtr, uint64_t MemSize, bool isLoad, |
| 139 | BasicBlock::iterator ScanIt, BasicBlock *BB) { |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 140 | |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 141 | // Walk backwards through the basic block, looking for dependencies. |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 142 | while (ScanIt != BB->begin()) { |
| 143 | Instruction *Inst = --ScanIt; |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 144 | |
Chris Lattner | cfbb634 | 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 | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 147 | if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) { |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 148 | Value *Pointer = LI->getPointerOperand(); |
| 149 | uint64_t PointerSize = TD->getTypeStoreSize(LI->getType()); |
| 150 | |
| 151 | // 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] | 152 | AliasAnalysis::AliasResult R = |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 153 | AA->alias(Pointer, PointerSize, MemPtr, MemSize); |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 154 | if (R == AliasAnalysis::NoAlias) |
| 155 | continue; |
| 156 | |
| 157 | // May-alias loads don't depend on each other without a dependence. |
Chris Lattner | e79be94 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 158 | if (isLoad && R == AliasAnalysis::MayAlias) |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 159 | continue; |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 160 | // Stores depend on may and must aliased loads, loads depend on must-alias |
| 161 | // loads. |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 162 | return MemDepResult::getDef(Inst); |
| 163 | } |
| 164 | |
| 165 | if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) { |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 166 | Value *Pointer = SI->getPointerOperand(); |
| 167 | uint64_t PointerSize = TD->getTypeStoreSize(SI->getOperand(0)->getType()); |
| 168 | |
| 169 | // If we found a pointer, check if it could be the same as our pointer. |
| 170 | AliasAnalysis::AliasResult R = |
| 171 | AA->alias(Pointer, PointerSize, MemPtr, MemSize); |
| 172 | |
| 173 | if (R == AliasAnalysis::NoAlias) |
| 174 | continue; |
| 175 | if (R == AliasAnalysis::MayAlias) |
| 176 | return MemDepResult::getClobber(Inst); |
| 177 | return MemDepResult::getDef(Inst); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 178 | } |
Chris Lattner | 237a828 | 2008-11-30 01:39:32 +0000 | [diff] [blame] | 179 | |
| 180 | // 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] | 181 | // the allocation, return Def. This means that there is no dependence and |
Chris Lattner | 237a828 | 2008-11-30 01:39:32 +0000 | [diff] [blame] | 182 | // the access can be optimized based on that. For example, a load could |
| 183 | // turn into undef. |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 184 | if (AllocationInst *AI = dyn_cast<AllocationInst>(Inst)) { |
Chris Lattner | 237a828 | 2008-11-30 01:39:32 +0000 | [diff] [blame] | 185 | Value *AccessPtr = MemPtr->getUnderlyingObject(); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 186 | |
Chris Lattner | 237a828 | 2008-11-30 01:39:32 +0000 | [diff] [blame] | 187 | if (AccessPtr == AI || |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 188 | AA->alias(AI, 1, AccessPtr, 1) == AliasAnalysis::MustAlias) |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 189 | return MemDepResult::getDef(AI); |
Chris Lattner | 237a828 | 2008-11-30 01:39:32 +0000 | [diff] [blame] | 190 | continue; |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 191 | } |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 192 | |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 193 | // See if this instruction (e.g. a call or vaarg) mod/ref's the pointer. |
Chris Lattner | e79be94 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 194 | // FIXME: If this is a load, we should ignore readonly calls! |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 195 | if (AA->getModRefInfo(Inst, MemPtr, MemSize) == AliasAnalysis::NoModRef) |
Chris Lattner | 25a0814 | 2008-11-29 08:51:16 +0000 | [diff] [blame] | 196 | continue; |
Chris Lattner | a161ab0 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 197 | |
| 198 | // Otherwise, there is a dependence. |
Chris Lattner | b51deb9 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 199 | return MemDepResult::getClobber(Inst); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 202 | // No dependence found. If this is the entry block of the function, it is a |
| 203 | // clobber, otherwise it is non-local. |
| 204 | if (BB != &BB->getParent()->getEntryBlock()) |
| 205 | return MemDepResult::getNonLocal(); |
| 206 | return MemDepResult::getClobber(ScanIt); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 209 | /// getDependency - Return the instruction on which a memory operation |
| 210 | /// depends. |
| 211 | MemDepResult MemoryDependenceAnalysis::getDependency(Instruction *QueryInst) { |
| 212 | Instruction *ScanPos = QueryInst; |
| 213 | |
| 214 | // Check for a cached result |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 215 | MemDepResult &LocalCache = LocalDeps[QueryInst]; |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 216 | |
Chris Lattner | 0ec48dd | 2008-11-29 22:02:15 +0000 | [diff] [blame] | 217 | // 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] | 218 | // on MemDepResult's default constructing to 'dirty'. |
| 219 | if (!LocalCache.isDirty()) |
| 220 | return LocalCache; |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 221 | |
| 222 | // Otherwise, if we have a dirty entry, we know we can start the scan at that |
| 223 | // instruction, which may save us some work. |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 224 | if (Instruction *Inst = LocalCache.getInst()) { |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 225 | ScanPos = Inst; |
Chris Lattner | 4a69bad | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 226 | |
Chris Lattner | d44745d | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 227 | RemoveFromReverseMap(ReverseLocalDeps, Inst, QueryInst); |
Chris Lattner | 4a69bad | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 228 | } |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 229 | |
Chris Lattner | e79be94 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 230 | BasicBlock *QueryParent = QueryInst->getParent(); |
| 231 | |
| 232 | Value *MemPtr = 0; |
| 233 | uint64_t MemSize = 0; |
| 234 | |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 235 | // Do the scan. |
Chris Lattner | e79be94 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 236 | if (BasicBlock::iterator(QueryInst) == QueryParent->begin()) { |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 237 | // No dependence found. If this is the entry block of the function, it is a |
| 238 | // clobber, otherwise it is non-local. |
| 239 | if (QueryParent != &QueryParent->getParent()->getEntryBlock()) |
| 240 | LocalCache = MemDepResult::getNonLocal(); |
| 241 | else |
| 242 | LocalCache = MemDepResult::getClobber(QueryInst); |
Chris Lattner | e79be94 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 243 | } else if (StoreInst *SI = dyn_cast<StoreInst>(QueryInst)) { |
| 244 | // If this is a volatile store, don't mess around with it. Just return the |
| 245 | // previous instruction as a clobber. |
| 246 | if (SI->isVolatile()) |
| 247 | LocalCache = MemDepResult::getClobber(--BasicBlock::iterator(ScanPos)); |
| 248 | else { |
| 249 | MemPtr = SI->getPointerOperand(); |
| 250 | MemSize = TD->getTypeStoreSize(SI->getOperand(0)->getType()); |
| 251 | } |
| 252 | } else if (LoadInst *LI = dyn_cast<LoadInst>(QueryInst)) { |
| 253 | // If this is a volatile load, don't mess around with it. Just return the |
| 254 | // previous instruction as a clobber. |
| 255 | if (LI->isVolatile()) |
| 256 | LocalCache = MemDepResult::getClobber(--BasicBlock::iterator(ScanPos)); |
| 257 | else { |
| 258 | MemPtr = LI->getPointerOperand(); |
| 259 | MemSize = TD->getTypeStoreSize(LI->getType()); |
| 260 | } |
| 261 | } else if (isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)) { |
Chris Lattner | d8dd934 | 2008-12-07 01:21:14 +0000 | [diff] [blame] | 262 | LocalCache = getCallSiteDependencyFrom(CallSite::get(QueryInst), ScanPos, |
Chris Lattner | e79be94 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 263 | QueryParent); |
| 264 | } else if (FreeInst *FI = dyn_cast<FreeInst>(QueryInst)) { |
| 265 | MemPtr = FI->getPointerOperand(); |
| 266 | // FreeInsts erase the entire structure, not just a field. |
| 267 | MemSize = ~0UL; |
| 268 | } else { |
| 269 | // Non-memory instruction. |
| 270 | LocalCache = MemDepResult::getClobber(--BasicBlock::iterator(ScanPos)); |
| 271 | } |
| 272 | |
| 273 | // If we need to do a pointer scan, make it happen. |
| 274 | if (MemPtr) |
| 275 | LocalCache = getPointerDependencyFrom(MemPtr, MemSize, |
| 276 | isa<LoadInst>(QueryInst), |
| 277 | ScanPos, QueryParent); |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 278 | |
| 279 | // Remember the result! |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 280 | if (Instruction *I = LocalCache.getInst()) |
Chris Lattner | 8c46527 | 2008-11-29 09:20:15 +0000 | [diff] [blame] | 281 | ReverseLocalDeps[I].insert(QueryInst); |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 282 | |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 283 | return LocalCache; |
Chris Lattner | 5391a1d | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 286 | /// getNonLocalDependency - Perform a full dependency query for the |
| 287 | /// specified instruction, returning the set of blocks that the value is |
| 288 | /// potentially live across. The returned set of results will include a |
| 289 | /// "NonLocal" result for all blocks where the value is live across. |
| 290 | /// |
| 291 | /// This method assumes the instruction returns a "nonlocal" dependency |
| 292 | /// within its own block. |
| 293 | /// |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 294 | const MemoryDependenceAnalysis::NonLocalDepInfo & |
| 295 | MemoryDependenceAnalysis::getNonLocalDependency(Instruction *QueryInst) { |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 296 | // FIXME: Make this only be for callsites in the future. |
Chris Lattner | e79be94 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 297 | assert(isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst) || |
| 298 | isa<LoadInst>(QueryInst) || isa<StoreInst>(QueryInst)); |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 299 | assert(getDependency(QueryInst).isNonLocal() && |
| 300 | "getNonLocalDependency should only be used on insts with non-local deps!"); |
Chris Lattner | 4a69bad | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 301 | PerInstNLInfo &CacheP = NonLocalDeps[QueryInst]; |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 302 | NonLocalDepInfo &Cache = CacheP.first; |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 303 | |
| 304 | /// DirtyBlocks - This is the set of blocks that need to be recomputed. In |
| 305 | /// the cached case, this can happen due to instructions being deleted etc. In |
| 306 | /// the uncached case, this starts out as the set of predecessors we care |
| 307 | /// about. |
| 308 | SmallVector<BasicBlock*, 32> DirtyBlocks; |
| 309 | |
| 310 | if (!Cache.empty()) { |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 311 | // Okay, we have a cache entry. If we know it is not dirty, just return it |
| 312 | // with no computation. |
| 313 | if (!CacheP.second) { |
| 314 | NumCacheNonLocal++; |
| 315 | return Cache; |
| 316 | } |
| 317 | |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 318 | // 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] | 319 | // determine what is dirty, seeding our initial DirtyBlocks worklist. |
| 320 | for (NonLocalDepInfo::iterator I = Cache.begin(), E = Cache.end(); |
| 321 | I != E; ++I) |
| 322 | if (I->second.isDirty()) |
| 323 | DirtyBlocks.push_back(I->first); |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 324 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 325 | // Sort the cache so that we can do fast binary search lookups below. |
| 326 | std::sort(Cache.begin(), Cache.end()); |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 327 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 328 | ++NumCacheDirtyNonLocal; |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 329 | //cerr << "CACHED CASE: " << DirtyBlocks.size() << " dirty: " |
| 330 | // << Cache.size() << " cached: " << *QueryInst; |
| 331 | } else { |
| 332 | // Seed DirtyBlocks with each of the preds of QueryInst's block. |
| 333 | BasicBlock *QueryBB = QueryInst->getParent(); |
| 334 | DirtyBlocks.append(pred_begin(QueryBB), pred_end(QueryBB)); |
| 335 | NumUncacheNonLocal++; |
| 336 | } |
| 337 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 338 | // Visited checked first, vector in sorted order. |
| 339 | SmallPtrSet<BasicBlock*, 64> Visited; |
| 340 | |
| 341 | unsigned NumSortedEntries = Cache.size(); |
| 342 | |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 343 | // Iterate while we still have blocks to update. |
| 344 | while (!DirtyBlocks.empty()) { |
| 345 | BasicBlock *DirtyBB = DirtyBlocks.back(); |
| 346 | DirtyBlocks.pop_back(); |
| 347 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 348 | // Already processed this block? |
| 349 | if (!Visited.insert(DirtyBB)) |
| 350 | continue; |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 351 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 352 | // Do a binary search to see if we already have an entry for this block in |
| 353 | // the cache set. If so, find it. |
| 354 | NonLocalDepInfo::iterator Entry = |
| 355 | std::upper_bound(Cache.begin(), Cache.begin()+NumSortedEntries, |
| 356 | std::make_pair(DirtyBB, MemDepResult())); |
| 357 | if (Entry != Cache.begin() && (&*Entry)[-1].first == DirtyBB) |
| 358 | --Entry; |
| 359 | |
| 360 | MemDepResult *ExistingResult = 0; |
| 361 | if (Entry != Cache.begin()+NumSortedEntries && |
| 362 | Entry->first == DirtyBB) { |
| 363 | // If we already have an entry, and if it isn't already dirty, the block |
| 364 | // is done. |
| 365 | if (!Entry->second.isDirty()) |
| 366 | continue; |
| 367 | |
| 368 | // Otherwise, remember this slot so we can update the value. |
| 369 | ExistingResult = &Entry->second; |
| 370 | } |
| 371 | |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 372 | // If the dirty entry has a pointer, start scanning from it so we don't have |
| 373 | // to rescan the entire block. |
| 374 | BasicBlock::iterator ScanPos = DirtyBB->end(); |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 375 | if (ExistingResult) { |
| 376 | if (Instruction *Inst = ExistingResult->getInst()) { |
| 377 | ScanPos = Inst; |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 378 | // We're removing QueryInst's use of Inst. |
Chris Lattner | d44745d | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 379 | RemoveFromReverseMap(ReverseNonLocalDeps, Inst, QueryInst); |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 380 | } |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 381 | } |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 382 | |
Chris Lattner | 73ec3cd | 2008-11-30 01:26:32 +0000 | [diff] [blame] | 383 | // Find out if this block has a local dependency for QueryInst. |
Chris Lattner | d8dd934 | 2008-12-07 01:21:14 +0000 | [diff] [blame] | 384 | MemDepResult Dep; |
Chris Lattner | e79be94 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 385 | |
| 386 | Value *MemPtr = 0; |
| 387 | uint64_t MemSize = 0; |
| 388 | |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 389 | if (ScanPos == DirtyBB->begin()) { |
| 390 | // No dependence found. If this is the entry block of the function, it is a |
| 391 | // clobber, otherwise it is non-local. |
| 392 | if (DirtyBB != &DirtyBB->getParent()->getEntryBlock()) |
| 393 | Dep = MemDepResult::getNonLocal(); |
| 394 | else |
| 395 | Dep = MemDepResult::getClobber(ScanPos); |
Chris Lattner | e79be94 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 396 | } else if (StoreInst *SI = dyn_cast<StoreInst>(QueryInst)) { |
| 397 | // If this is a volatile store, don't mess around with it. Just return the |
| 398 | // previous instruction as a clobber. |
| 399 | if (SI->isVolatile()) |
| 400 | Dep = MemDepResult::getClobber(--BasicBlock::iterator(ScanPos)); |
| 401 | else { |
| 402 | MemPtr = SI->getPointerOperand(); |
| 403 | MemSize = TD->getTypeStoreSize(SI->getOperand(0)->getType()); |
| 404 | } |
| 405 | } else if (LoadInst *LI = dyn_cast<LoadInst>(QueryInst)) { |
| 406 | // If this is a volatile load, don't mess around with it. Just return the |
| 407 | // previous instruction as a clobber. |
| 408 | if (LI->isVolatile()) |
| 409 | Dep = MemDepResult::getClobber(--BasicBlock::iterator(ScanPos)); |
| 410 | else { |
| 411 | MemPtr = LI->getPointerOperand(); |
| 412 | MemSize = TD->getTypeStoreSize(LI->getType()); |
| 413 | } |
| 414 | } else { |
| 415 | assert(isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)); |
Chris Lattner | d8dd934 | 2008-12-07 01:21:14 +0000 | [diff] [blame] | 416 | Dep = getCallSiteDependencyFrom(CallSite::get(QueryInst), ScanPos, |
| 417 | DirtyBB); |
Chris Lattner | e79be94 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | if (MemPtr) |
| 421 | Dep = getPointerDependencyFrom(MemPtr, MemSize, isa<LoadInst>(QueryInst), |
| 422 | ScanPos, DirtyBB); |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 423 | |
| 424 | // If we had a dirty entry for the block, update it. Otherwise, just add |
| 425 | // a new entry. |
| 426 | if (ExistingResult) |
| 427 | *ExistingResult = Dep; |
| 428 | else |
| 429 | Cache.push_back(std::make_pair(DirtyBB, Dep)); |
| 430 | |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 431 | // 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] | 432 | // the value), remember the association! |
| 433 | if (!Dep.isNonLocal()) { |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 434 | // Keep the ReverseNonLocalDeps map up to date so we can efficiently |
| 435 | // update this when we remove instructions. |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 436 | if (Instruction *Inst = Dep.getInst()) |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 437 | ReverseNonLocalDeps[Inst].insert(QueryInst); |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 438 | } else { |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 439 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 440 | // If the block *is* completely transparent to the load, we need to check |
| 441 | // the predecessors of this block. Add them to our worklist. |
| 442 | DirtyBlocks.append(pred_begin(DirtyBB), pred_end(DirtyBB)); |
| 443 | } |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 446 | return Cache; |
Chris Lattner | 37d041c | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 449 | /// getNonLocalPointerDependency - Perform a full dependency query for an |
| 450 | /// access to the specified (non-volatile) memory location, returning the |
| 451 | /// set of instructions that either define or clobber the value. |
| 452 | /// |
| 453 | /// This method assumes the pointer has a "NonLocal" dependency within its |
| 454 | /// own block. |
| 455 | /// |
| 456 | void MemoryDependenceAnalysis:: |
| 457 | getNonLocalPointerDependency(Value *Pointer, bool isLoad, BasicBlock *FromBB, |
| 458 | SmallVectorImpl<NonLocalDepEntry> &Result) { |
Chris Lattner | 3f7eb5b | 2008-12-07 18:45:15 +0000 | [diff] [blame] | 459 | assert(isa<PointerType>(Pointer->getType()) && |
| 460 | "Can't get pointer deps of a non-pointer!"); |
Chris Lattner | 9a193fd | 2008-12-07 02:56:57 +0000 | [diff] [blame] | 461 | Result.clear(); |
| 462 | |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 463 | // We know that the pointer value is live into FromBB find the def/clobbers |
| 464 | // from presecessors. |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 465 | const Type *EltTy = cast<PointerType>(Pointer->getType())->getElementType(); |
| 466 | uint64_t PointeeSize = TD->getTypeStoreSize(EltTy); |
| 467 | |
| 468 | // While we have blocks to analyze, get their values. |
| 469 | SmallPtrSet<BasicBlock*, 64> Visited; |
Chris Lattner | 9a193fd | 2008-12-07 02:56:57 +0000 | [diff] [blame] | 470 | |
| 471 | for (pred_iterator PI = pred_begin(FromBB), E = pred_end(FromBB); PI != E; |
| 472 | ++PI) { |
| 473 | // TODO: PHI TRANSLATE. |
| 474 | getNonLocalPointerDepInternal(Pointer, PointeeSize, isLoad, *PI, |
| 475 | Result, Visited); |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | void MemoryDependenceAnalysis:: |
| 480 | getNonLocalPointerDepInternal(Value *Pointer, uint64_t PointeeSize, |
| 481 | bool isLoad, BasicBlock *StartBB, |
| 482 | SmallVectorImpl<NonLocalDepEntry> &Result, |
| 483 | SmallPtrSet<BasicBlock*, 64> &Visited) { |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 484 | // Look up the cached info for Pointer. |
| 485 | ValueIsLoadPair CacheKey(Pointer, isLoad); |
Chris Lattner | 11dcd8d | 2008-12-08 07:31:50 +0000 | [diff] [blame^] | 486 | |
| 487 | std::pair<BasicBlock*, NonLocalDepInfo> &CacheInfo = |
| 488 | NonLocalPointerDeps[CacheKey]; |
| 489 | NonLocalDepInfo *Cache = &CacheInfo.second; |
| 490 | |
| 491 | // If we have valid cached information for exactly the block we are |
| 492 | // investigating, just return it with no recomputation. |
| 493 | if (CacheInfo.first == StartBB) { |
| 494 | for (NonLocalDepInfo::iterator I = Cache->begin(), E = Cache->end(); |
| 495 | I != E; ++I) |
| 496 | if (!I->second.isNonLocal()) |
| 497 | Result.push_back(*I); |
| 498 | ++NumCacheCompleteNonLocalPtr; |
| 499 | return; |
| 500 | } |
| 501 | |
| 502 | // Otherwise, either this is a new block, a block with an invalid cache |
| 503 | // pointer or one that we're about to invalidate by putting more info into it |
| 504 | // than its valid cache info. If empty, the result will be valid cache info, |
| 505 | // otherwise it isn't. |
| 506 | CacheInfo.first = Cache->empty() ? StartBB : 0; |
| 507 | |
| 508 | SmallVector<BasicBlock*, 32> Worklist; |
| 509 | Worklist.push_back(StartBB); |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 510 | |
| 511 | // Keep track of the entries that we know are sorted. Previously cached |
| 512 | // entries will all be sorted. The entries we add we only sort on demand (we |
| 513 | // don't insert every element into its sorted position). We know that we |
| 514 | // won't get any reuse from currently inserted values, because we don't |
| 515 | // revisit blocks after we insert info for them. |
| 516 | unsigned NumSortedEntries = Cache->size(); |
| 517 | |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 518 | while (!Worklist.empty()) { |
Chris Lattner | 9a193fd | 2008-12-07 02:56:57 +0000 | [diff] [blame] | 519 | BasicBlock *BB = Worklist.pop_back_val(); |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 520 | |
| 521 | // Analyze the dependency of *Pointer in FromBB. See if we already have |
| 522 | // been here. |
Chris Lattner | 9a193fd | 2008-12-07 02:56:57 +0000 | [diff] [blame] | 523 | if (!Visited.insert(BB)) |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 524 | continue; |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 525 | |
| 526 | // Get the dependency info for Pointer in BB. If we have cached |
| 527 | // information, we will use it, otherwise we compute it. |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 528 | |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 529 | // Do a binary search to see if we already have an entry for this block in |
| 530 | // the cache set. If so, find it. |
| 531 | NonLocalDepInfo::iterator Entry = |
| 532 | std::upper_bound(Cache->begin(), Cache->begin()+NumSortedEntries, |
| 533 | std::make_pair(BB, MemDepResult())); |
| 534 | if (Entry != Cache->begin() && (&*Entry)[-1].first == BB) |
| 535 | --Entry; |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 536 | |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 537 | MemDepResult *ExistingResult = 0; |
| 538 | if (Entry != Cache->begin()+NumSortedEntries && Entry->first == BB) |
| 539 | ExistingResult = &Entry->second; |
| 540 | |
| 541 | // If we have a cached entry, and it is non-dirty, use it as the value for |
| 542 | // this dependency. |
| 543 | MemDepResult Dep; |
| 544 | if (ExistingResult && !ExistingResult->isDirty()) { |
| 545 | Dep = *ExistingResult; |
| 546 | ++NumCacheNonLocalPtr; |
| 547 | } else { |
| 548 | // Otherwise, we have to scan for the value. If we have a dirty cache |
| 549 | // entry, start scanning from its position, otherwise we scan from the end |
| 550 | // of the block. |
| 551 | BasicBlock::iterator ScanPos = BB->end(); |
| 552 | if (ExistingResult && ExistingResult->getInst()) { |
| 553 | assert(ExistingResult->getInst()->getParent() == BB && |
| 554 | "Instruction invalidated?"); |
| 555 | ++NumCacheDirtyNonLocalPtr; |
| 556 | ScanPos = ExistingResult->getInst(); |
| 557 | |
| 558 | // Eliminating the dirty entry from 'Cache', so update the reverse info. |
Chris Lattner | d44745d | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 559 | RemoveFromReverseMap(ReverseNonLocalPtrDeps, ScanPos, |
| 560 | CacheKey.getOpaqueValue()); |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 561 | } else { |
| 562 | ++NumUncacheNonLocalPtr; |
| 563 | } |
| 564 | |
| 565 | // Scan the block for the dependency. |
| 566 | Dep = getPointerDependencyFrom(Pointer, PointeeSize, isLoad, ScanPos, BB); |
| 567 | |
| 568 | // If we had a dirty entry for the block, update it. Otherwise, just add |
| 569 | // a new entry. |
| 570 | if (ExistingResult) |
| 571 | *ExistingResult = Dep; |
| 572 | else |
| 573 | Cache->push_back(std::make_pair(BB, Dep)); |
| 574 | |
| 575 | // If the block has a dependency (i.e. it isn't completely transparent to |
| 576 | // the value), remember the reverse association because we just added it |
| 577 | // to Cache! |
| 578 | if (!Dep.isNonLocal()) { |
| 579 | // Keep the ReverseNonLocalPtrDeps map up to date so we can efficiently |
| 580 | // update MemDep when we remove instructions. |
| 581 | Instruction *Inst = Dep.getInst(); |
| 582 | assert(Inst && "Didn't depend on anything?"); |
| 583 | ReverseNonLocalPtrDeps[Inst].insert(CacheKey.getOpaqueValue()); |
| 584 | } |
| 585 | } |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 586 | |
| 587 | // If we got a Def or Clobber, add this to the list of results. |
| 588 | if (!Dep.isNonLocal()) { |
Chris Lattner | 9a193fd | 2008-12-07 02:56:57 +0000 | [diff] [blame] | 589 | Result.push_back(NonLocalDepEntry(BB, Dep)); |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 590 | continue; |
| 591 | } |
| 592 | |
| 593 | // Otherwise, we have to process all the predecessors of this block to scan |
| 594 | // them as well. |
Chris Lattner | 9a193fd | 2008-12-07 02:56:57 +0000 | [diff] [blame] | 595 | for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 596 | // TODO: PHI TRANSLATE. |
Chris Lattner | 9a193fd | 2008-12-07 02:56:57 +0000 | [diff] [blame] | 597 | Worklist.push_back(*PI); |
| 598 | } |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 599 | } |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 600 | |
| 601 | // If we computed new values, re-sort Cache. |
| 602 | if (NumSortedEntries != Cache->size()) |
| 603 | std::sort(Cache->begin(), Cache->end()); |
| 604 | } |
| 605 | |
| 606 | /// RemoveCachedNonLocalPointerDependencies - If P exists in |
| 607 | /// CachedNonLocalPointerInfo, remove it. |
| 608 | void MemoryDependenceAnalysis:: |
| 609 | RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair P) { |
| 610 | CachedNonLocalPointerInfo::iterator It = |
| 611 | NonLocalPointerDeps.find(P); |
| 612 | if (It == NonLocalPointerDeps.end()) return; |
| 613 | |
| 614 | // Remove all of the entries in the BB->val map. This involves removing |
| 615 | // instructions from the reverse map. |
Chris Lattner | 11dcd8d | 2008-12-08 07:31:50 +0000 | [diff] [blame^] | 616 | NonLocalDepInfo &PInfo = It->second.second; |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 617 | |
| 618 | for (unsigned i = 0, e = PInfo.size(); i != e; ++i) { |
| 619 | Instruction *Target = PInfo[i].second.getInst(); |
| 620 | if (Target == 0) continue; // Ignore non-local dep results. |
| 621 | assert(Target->getParent() == PInfo[i].first && Target != P.getPointer()); |
| 622 | |
| 623 | // Eliminating the dirty entry from 'Cache', so update the reverse info. |
Chris Lattner | d44745d | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 624 | RemoveFromReverseMap(ReverseNonLocalPtrDeps, Target, P.getOpaqueValue()); |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | // Remove P from NonLocalPointerDeps (which deletes NonLocalDepInfo). |
| 628 | NonLocalPointerDeps.erase(It); |
Chris Lattner | 7ebcf03 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 632 | /// removeInstruction - Remove an instruction from the dependence analysis, |
| 633 | /// updating the dependence of instructions that previously depended on it. |
Owen Anderson | 642a9e3 | 2007-08-08 22:26:03 +0000 | [diff] [blame] | 634 | /// This method attempts to keep the cache coherent using the reverse map. |
Chris Lattner | 5f589dc | 2008-11-28 22:04:47 +0000 | [diff] [blame] | 635 | void MemoryDependenceAnalysis::removeInstruction(Instruction *RemInst) { |
Chris Lattner | 5f589dc | 2008-11-28 22:04:47 +0000 | [diff] [blame] | 636 | // Walk through the Non-local dependencies, removing this one as the value |
| 637 | // for any cached queries. |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 638 | NonLocalDepMapType::iterator NLDI = NonLocalDeps.find(RemInst); |
| 639 | if (NLDI != NonLocalDeps.end()) { |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 640 | NonLocalDepInfo &BlockMap = NLDI->second.first; |
Chris Lattner | 25f4b2b | 2008-11-30 02:30:50 +0000 | [diff] [blame] | 641 | for (NonLocalDepInfo::iterator DI = BlockMap.begin(), DE = BlockMap.end(); |
| 642 | DI != DE; ++DI) |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 643 | if (Instruction *Inst = DI->second.getInst()) |
Chris Lattner | d44745d | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 644 | RemoveFromReverseMap(ReverseNonLocalDeps, Inst, RemInst); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 645 | NonLocalDeps.erase(NLDI); |
| 646 | } |
Owen Anderson | 5fc4aba | 2007-12-08 01:37:09 +0000 | [diff] [blame] | 647 | |
Chris Lattner | 5f589dc | 2008-11-28 22:04:47 +0000 | [diff] [blame] | 648 | // 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] | 649 | // |
Chris Lattner | 39f372e | 2008-11-29 01:43:36 +0000 | [diff] [blame] | 650 | LocalDepMapType::iterator LocalDepEntry = LocalDeps.find(RemInst); |
| 651 | if (LocalDepEntry != LocalDeps.end()) { |
Chris Lattner | 125ce36 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 652 | // Remove us from DepInst's reverse set now that the local dep info is gone. |
Chris Lattner | d44745d | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 653 | if (Instruction *Inst = LocalDepEntry->second.getInst()) |
| 654 | RemoveFromReverseMap(ReverseLocalDeps, Inst, RemInst); |
Chris Lattner | 125ce36 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 655 | |
Chris Lattner | baad888 | 2008-11-28 22:28:27 +0000 | [diff] [blame] | 656 | // Remove this local dependency info. |
Chris Lattner | 39f372e | 2008-11-29 01:43:36 +0000 | [diff] [blame] | 657 | LocalDeps.erase(LocalDepEntry); |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | // If we have any cached pointer dependencies on this instruction, remove |
| 661 | // them. If the instruction has non-pointer type, then it can't be a pointer |
| 662 | // base. |
| 663 | |
| 664 | // Remove it from both the load info and the store info. The instruction |
| 665 | // can't be in either of these maps if it is non-pointer. |
| 666 | if (isa<PointerType>(RemInst->getType())) { |
| 667 | RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst, false)); |
| 668 | RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst, true)); |
| 669 | } |
Chris Lattner | baad888 | 2008-11-28 22:28:27 +0000 | [diff] [blame] | 670 | |
Chris Lattner | d3d12ec | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 671 | // Loop over all of the things that depend on the instruction we're removing. |
| 672 | // |
Chris Lattner | 4f8c18c | 2008-11-29 23:30:39 +0000 | [diff] [blame] | 673 | SmallVector<std::pair<Instruction*, Instruction*>, 8> ReverseDepsToAdd; |
Chris Lattner | 0655f73 | 2008-12-07 18:42:51 +0000 | [diff] [blame] | 674 | |
| 675 | // If we find RemInst as a clobber or Def in any of the maps for other values, |
| 676 | // we need to replace its entry with a dirty version of the instruction after |
| 677 | // it. If RemInst is a terminator, we use a null dirty value. |
| 678 | // |
| 679 | // Using a dirty version of the instruction after RemInst saves having to scan |
| 680 | // the entire block to get to this point. |
| 681 | MemDepResult NewDirtyVal; |
| 682 | if (!RemInst->isTerminator()) |
| 683 | NewDirtyVal = MemDepResult::getDirty(++BasicBlock::iterator(RemInst)); |
Chris Lattner | 4f8c18c | 2008-11-29 23:30:39 +0000 | [diff] [blame] | 684 | |
Chris Lattner | 8c46527 | 2008-11-29 09:20:15 +0000 | [diff] [blame] | 685 | ReverseDepMapType::iterator ReverseDepIt = ReverseLocalDeps.find(RemInst); |
| 686 | if (ReverseDepIt != ReverseLocalDeps.end()) { |
Chris Lattner | d3d12ec | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 687 | SmallPtrSet<Instruction*, 4> &ReverseDeps = ReverseDepIt->second; |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 688 | // RemInst can't be the terminator if it has local stuff depending on it. |
Chris Lattner | 125ce36 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 689 | assert(!ReverseDeps.empty() && !isa<TerminatorInst>(RemInst) && |
| 690 | "Nothing can locally depend on a terminator"); |
| 691 | |
Chris Lattner | d3d12ec | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 692 | for (SmallPtrSet<Instruction*, 4>::iterator I = ReverseDeps.begin(), |
| 693 | E = ReverseDeps.end(); I != E; ++I) { |
| 694 | Instruction *InstDependingOnRemInst = *I; |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 695 | assert(InstDependingOnRemInst != RemInst && |
| 696 | "Already removed our local dep info"); |
Chris Lattner | 125ce36 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 697 | |
Chris Lattner | 0655f73 | 2008-12-07 18:42:51 +0000 | [diff] [blame] | 698 | LocalDeps[InstDependingOnRemInst] = NewDirtyVal; |
Chris Lattner | d3d12ec | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 699 | |
Chris Lattner | 125ce36 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 700 | // Make sure to remember that new things depend on NewDepInst. |
Chris Lattner | 0655f73 | 2008-12-07 18:42:51 +0000 | [diff] [blame] | 701 | assert(NewDirtyVal.getInst() && "There is no way something else can have " |
| 702 | "a local dep on this if it is a terminator!"); |
| 703 | ReverseDepsToAdd.push_back(std::make_pair(NewDirtyVal.getInst(), |
Chris Lattner | 125ce36 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 704 | InstDependingOnRemInst)); |
Chris Lattner | d3d12ec | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 705 | } |
Chris Lattner | 4f8c18c | 2008-11-29 23:30:39 +0000 | [diff] [blame] | 706 | |
| 707 | ReverseLocalDeps.erase(ReverseDepIt); |
| 708 | |
| 709 | // Add new reverse deps after scanning the set, to avoid invalidating the |
| 710 | // 'ReverseDeps' reference. |
| 711 | while (!ReverseDepsToAdd.empty()) { |
| 712 | ReverseLocalDeps[ReverseDepsToAdd.back().first] |
| 713 | .insert(ReverseDepsToAdd.back().second); |
| 714 | ReverseDepsToAdd.pop_back(); |
| 715 | } |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 716 | } |
Owen Anderson | 4d13de4 | 2007-08-16 21:27:05 +0000 | [diff] [blame] | 717 | |
Chris Lattner | 8c46527 | 2008-11-29 09:20:15 +0000 | [diff] [blame] | 718 | ReverseDepIt = ReverseNonLocalDeps.find(RemInst); |
| 719 | if (ReverseDepIt != ReverseNonLocalDeps.end()) { |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 720 | SmallPtrSet<Instruction*, 4> &Set = ReverseDepIt->second; |
| 721 | for (SmallPtrSet<Instruction*, 4>::iterator I = Set.begin(), E = Set.end(); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 722 | I != E; ++I) { |
| 723 | assert(*I != RemInst && "Already removed NonLocalDep info for RemInst"); |
| 724 | |
Chris Lattner | 4a69bad | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 725 | PerInstNLInfo &INLD = NonLocalDeps[*I]; |
Chris Lattner | 4a69bad | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 726 | // The information is now dirty! |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 727 | INLD.second = true; |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 728 | |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 729 | for (NonLocalDepInfo::iterator DI = INLD.first.begin(), |
| 730 | DE = INLD.first.end(); DI != DE; ++DI) { |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 731 | if (DI->second.getInst() != RemInst) continue; |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 732 | |
| 733 | // Convert to a dirty entry for the subsequent instruction. |
Chris Lattner | 0655f73 | 2008-12-07 18:42:51 +0000 | [diff] [blame] | 734 | DI->second = NewDirtyVal; |
| 735 | |
| 736 | if (Instruction *NextI = NewDirtyVal.getInst()) |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 737 | ReverseDepsToAdd.push_back(std::make_pair(NextI, *I)); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 738 | } |
| 739 | } |
Chris Lattner | 4f8c18c | 2008-11-29 23:30:39 +0000 | [diff] [blame] | 740 | |
| 741 | ReverseNonLocalDeps.erase(ReverseDepIt); |
| 742 | |
Chris Lattner | 0ec48dd | 2008-11-29 22:02:15 +0000 | [diff] [blame] | 743 | // Add new reverse deps after scanning the set, to avoid invalidating 'Set' |
| 744 | while (!ReverseDepsToAdd.empty()) { |
| 745 | ReverseNonLocalDeps[ReverseDepsToAdd.back().first] |
| 746 | .insert(ReverseDepsToAdd.back().second); |
| 747 | ReverseDepsToAdd.pop_back(); |
| 748 | } |
Owen Anderson | 4d13de4 | 2007-08-16 21:27:05 +0000 | [diff] [blame] | 749 | } |
Owen Anderson | 5fc4aba | 2007-12-08 01:37:09 +0000 | [diff] [blame] | 750 | |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 751 | // If the instruction is in ReverseNonLocalPtrDeps then it appears as a |
| 752 | // value in the NonLocalPointerDeps info. |
| 753 | ReverseNonLocalPtrDepTy::iterator ReversePtrDepIt = |
| 754 | ReverseNonLocalPtrDeps.find(RemInst); |
| 755 | if (ReversePtrDepIt != ReverseNonLocalPtrDeps.end()) { |
| 756 | SmallPtrSet<void*, 4> &Set = ReversePtrDepIt->second; |
| 757 | SmallVector<std::pair<Instruction*, ValueIsLoadPair>,8> ReversePtrDepsToAdd; |
| 758 | |
| 759 | for (SmallPtrSet<void*, 4>::iterator I = Set.begin(), E = Set.end(); |
| 760 | I != E; ++I) { |
| 761 | ValueIsLoadPair P; |
| 762 | P.setFromOpaqueValue(*I); |
| 763 | assert(P.getPointer() != RemInst && |
| 764 | "Already removed NonLocalPointerDeps info for RemInst"); |
| 765 | |
Chris Lattner | 11dcd8d | 2008-12-08 07:31:50 +0000 | [diff] [blame^] | 766 | NonLocalDepInfo &NLPDI = NonLocalPointerDeps[P].second; |
| 767 | |
| 768 | // The cache is not valid for any specific block anymore. |
| 769 | NonLocalPointerDeps[P].first = 0; |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 770 | |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 771 | // Update any entries for RemInst to use the instruction after it. |
| 772 | for (NonLocalDepInfo::iterator DI = NLPDI.begin(), DE = NLPDI.end(); |
| 773 | DI != DE; ++DI) { |
| 774 | if (DI->second.getInst() != RemInst) continue; |
| 775 | |
| 776 | // Convert to a dirty entry for the subsequent instruction. |
| 777 | DI->second = NewDirtyVal; |
| 778 | |
| 779 | if (Instruction *NewDirtyInst = NewDirtyVal.getInst()) |
| 780 | ReversePtrDepsToAdd.push_back(std::make_pair(NewDirtyInst, P)); |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | ReverseNonLocalPtrDeps.erase(ReversePtrDepIt); |
| 785 | |
| 786 | while (!ReversePtrDepsToAdd.empty()) { |
| 787 | ReverseNonLocalPtrDeps[ReversePtrDepsToAdd.back().first] |
| 788 | .insert(ReversePtrDepsToAdd.back().second.getOpaqueValue()); |
| 789 | ReversePtrDepsToAdd.pop_back(); |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 794 | assert(!NonLocalDeps.count(RemInst) && "RemInst got reinserted?"); |
Chris Lattner | d777d40 | 2008-11-30 19:24:31 +0000 | [diff] [blame] | 795 | AA->deleteValue(RemInst); |
Chris Lattner | 5f589dc | 2008-11-28 22:04:47 +0000 | [diff] [blame] | 796 | DEBUG(verifyRemoved(RemInst)); |
Owen Anderson | 78e02f7 | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 797 | } |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 798 | |
| 799 | /// verifyRemoved - Verify that the specified instruction does not occur |
| 800 | /// in our internal data structures. |
| 801 | void MemoryDependenceAnalysis::verifyRemoved(Instruction *D) const { |
| 802 | for (LocalDepMapType::const_iterator I = LocalDeps.begin(), |
| 803 | E = LocalDeps.end(); I != E; ++I) { |
| 804 | assert(I->first != D && "Inst occurs in data structures"); |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 805 | assert(I->second.getInst() != D && |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 806 | "Inst occurs in data structures"); |
| 807 | } |
| 808 | |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 809 | for (CachedNonLocalPointerInfo::const_iterator I =NonLocalPointerDeps.begin(), |
| 810 | E = NonLocalPointerDeps.end(); I != E; ++I) { |
| 811 | assert(I->first.getPointer() != D && "Inst occurs in NLPD map key"); |
Chris Lattner | 11dcd8d | 2008-12-08 07:31:50 +0000 | [diff] [blame^] | 812 | const NonLocalDepInfo &Val = I->second.second; |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 813 | for (NonLocalDepInfo::const_iterator II = Val.begin(), E = Val.end(); |
| 814 | II != E; ++II) |
| 815 | assert(II->second.getInst() != D && "Inst occurs as NLPD value"); |
| 816 | } |
| 817 | |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 818 | for (NonLocalDepMapType::const_iterator I = NonLocalDeps.begin(), |
| 819 | E = NonLocalDeps.end(); I != E; ++I) { |
| 820 | assert(I->first != D && "Inst occurs in data structures"); |
Chris Lattner | 4a69bad | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 821 | const PerInstNLInfo &INLD = I->second; |
Chris Lattner | bf145d6 | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 822 | for (NonLocalDepInfo::const_iterator II = INLD.first.begin(), |
| 823 | EE = INLD.first.end(); II != EE; ++II) |
Chris Lattner | fd3dcbe | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 824 | assert(II->second.getInst() != D && "Inst occurs in data structures"); |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | for (ReverseDepMapType::const_iterator I = ReverseLocalDeps.begin(), |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 828 | E = ReverseLocalDeps.end(); I != E; ++I) { |
| 829 | assert(I->first != D && "Inst occurs in data structures"); |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 830 | for (SmallPtrSet<Instruction*, 4>::const_iterator II = I->second.begin(), |
| 831 | EE = I->second.end(); II != EE; ++II) |
| 832 | assert(*II != D && "Inst occurs in data structures"); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 833 | } |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 834 | |
| 835 | for (ReverseDepMapType::const_iterator I = ReverseNonLocalDeps.begin(), |
| 836 | E = ReverseNonLocalDeps.end(); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 837 | I != E; ++I) { |
| 838 | assert(I->first != D && "Inst occurs in data structures"); |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 839 | for (SmallPtrSet<Instruction*, 4>::const_iterator II = I->second.begin(), |
| 840 | EE = I->second.end(); II != EE; ++II) |
| 841 | assert(*II != D && "Inst occurs in data structures"); |
Chris Lattner | f68f310 | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 842 | } |
Chris Lattner | 6290f5c | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 843 | |
| 844 | for (ReverseNonLocalPtrDepTy::const_iterator |
| 845 | I = ReverseNonLocalPtrDeps.begin(), |
| 846 | E = ReverseNonLocalPtrDeps.end(); I != E; ++I) { |
| 847 | assert(I->first != D && "Inst occurs in rev NLPD map"); |
| 848 | |
| 849 | for (SmallPtrSet<void*, 4>::const_iterator II = I->second.begin(), |
| 850 | E = I->second.end(); II != E; ++II) |
| 851 | assert(*II != ValueIsLoadPair(D, false).getOpaqueValue() && |
| 852 | *II != ValueIsLoadPair(D, true).getOpaqueValue() && |
| 853 | "Inst occurs in ReverseNonLocalPtrDeps map"); |
| 854 | } |
| 855 | |
Chris Lattner | 729b237 | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 856 | } |