blob: 3072a5c5737729243bd5a2fc73a6a46b1e2886cc [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- MemoryDependenceAnalysis.cpp - Mem Deps Implementation --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the Owen Anderson and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
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 Andersonafe840e2007-08-08 22:01:54 +000012// alias analysis information, and tries to provide a lazy, caching interface to
Dan Gohmanf17a25c2007-07-18 16:29:46 +000013// a common kind of alias information query.
14//
15//===----------------------------------------------------------------------===//
16
17#include "llvm/Analysis/MemoryDependenceAnalysis.h"
18#include "llvm/Constants.h"
19#include "llvm/Instructions.h"
20#include "llvm/Function.h"
21#include "llvm/Analysis/AliasAnalysis.h"
Owen Anderson4c295472007-07-24 21:52:37 +000022#include "llvm/Support/CFG.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000023#include "llvm/Target/TargetData.h"
Owen Andersond6c7fea2007-09-09 21:43:49 +000024#include "llvm/ADT/Statistic.h"
25
26#define DEBUG_TYPE "memdep"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000027
28using namespace llvm;
29
Owen Andersond6c7fea2007-09-09 21:43:49 +000030STATISTIC(NumCacheNonlocal, "Number of cached non-local responses");
31STATISTIC(NumUncacheNonlocal, "Number of uncached non-local responses");
32
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033char MemoryDependenceAnalysis::ID = 0;
34
Owen Anderson935e39b2007-08-09 04:42:44 +000035Instruction* const MemoryDependenceAnalysis::NonLocal = (Instruction*)-3;
36Instruction* const MemoryDependenceAnalysis::None = (Instruction*)-4;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037
38// Register this pass...
39static RegisterPass<MemoryDependenceAnalysis> X("memdep",
40 "Memory Dependence Analysis");
41
42/// getAnalysisUsage - Does not modify anything. It uses Alias Analysis.
43///
44void MemoryDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
45 AU.setPreservesAll();
46 AU.addRequiredTransitive<AliasAnalysis>();
47 AU.addRequiredTransitive<TargetData>();
48}
49
Owen Anderson3de3c532007-08-08 22:26:03 +000050/// getCallSiteDependency - Private helper for finding the local dependencies
51/// of a call site.
Owen Anderson935e39b2007-08-09 04:42:44 +000052Instruction* MemoryDependenceAnalysis::getCallSiteDependency(CallSite C,
Owen Andersonafe840e2007-08-08 22:01:54 +000053 Instruction* start,
54 BasicBlock* block) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000055
56 AliasAnalysis& AA = getAnalysis<AliasAnalysis>();
57 TargetData& TD = getAnalysis<TargetData>();
58 BasicBlock::iterator blockBegin = C.getInstruction()->getParent()->begin();
59 BasicBlock::iterator QI = C.getInstruction();
60
Owen Anderson3de3c532007-08-08 22:26:03 +000061 // If the starting point was specifiy, use it
Owen Andersone84f4bc2007-08-07 00:33:45 +000062 if (start) {
63 QI = start;
64 blockBegin = start->getParent()->end();
Owen Anderson3de3c532007-08-08 22:26:03 +000065 // If the starting point wasn't specified, but the block was, use it
Owen Andersone84f4bc2007-08-07 00:33:45 +000066 } else if (!start && block) {
67 QI = block->end();
68 blockBegin = block->end();
69 }
70
Owen Anderson3de3c532007-08-08 22:26:03 +000071 // Walk backwards through the block, looking for dependencies
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072 while (QI != blockBegin) {
73 --QI;
74
75 // If this inst is a memory op, get the pointer it accessed
76 Value* pointer = 0;
77 uint64_t pointerSize = 0;
78 if (StoreInst* S = dyn_cast<StoreInst>(QI)) {
79 pointer = S->getPointerOperand();
80 pointerSize = TD.getTypeSize(S->getOperand(0)->getType());
81 } else if (LoadInst* L = dyn_cast<LoadInst>(QI)) {
82 pointer = L->getPointerOperand();
83 pointerSize = TD.getTypeSize(L->getType());
84 } else if (AllocationInst* AI = dyn_cast<AllocationInst>(QI)) {
85 pointer = AI;
86 if (ConstantInt* C = dyn_cast<ConstantInt>(AI->getArraySize()))
Owen Andersonafe840e2007-08-08 22:01:54 +000087 pointerSize = C->getZExtValue() * \
88 TD.getTypeSize(AI->getAllocatedType());
Dan Gohmanf17a25c2007-07-18 16:29:46 +000089 else
90 pointerSize = ~0UL;
91 } else if (VAArgInst* V = dyn_cast<VAArgInst>(QI)) {
92 pointer = V->getOperand(0);
93 pointerSize = TD.getTypeSize(V->getType());
94 } else if (FreeInst* F = dyn_cast<FreeInst>(QI)) {
95 pointer = F->getPointerOperand();
96
97 // FreeInsts erase the entire structure
98 pointerSize = ~0UL;
99 } else if (CallSite::get(QI).getInstruction() != 0) {
100 if (AA.getModRefInfo(C, CallSite::get(QI)) != AliasAnalysis::NoModRef) {
Owen Andersone84f4bc2007-08-07 00:33:45 +0000101 if (!start && !block) {
102 depGraphLocal.insert(std::make_pair(C.getInstruction(),
103 std::make_pair(QI, true)));
104 reverseDep[QI].insert(C.getInstruction());
105 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000106 return QI;
107 } else {
108 continue;
109 }
110 } else
111 continue;
112
113 if (AA.getModRefInfo(C, pointer, pointerSize) != AliasAnalysis::NoModRef) {
Owen Andersone84f4bc2007-08-07 00:33:45 +0000114 if (!start && !block) {
115 depGraphLocal.insert(std::make_pair(C.getInstruction(),
116 std::make_pair(QI, true)));
117 reverseDep[QI].insert(C.getInstruction());
118 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000119 return QI;
120 }
121 }
122
123 // No dependence found
Owen Andersonafe840e2007-08-08 22:01:54 +0000124 depGraphLocal.insert(std::make_pair(C.getInstruction(),
125 std::make_pair(NonLocal, true)));
Owen Andersone84f4bc2007-08-07 00:33:45 +0000126 reverseDep[NonLocal].insert(C.getInstruction());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000127 return NonLocal;
128}
129
Owen Anderson3de3c532007-08-08 22:26:03 +0000130/// nonLocalHelper - Private helper used to calculate non-local dependencies
131/// by doing DFS on the predecessors of a block to find its dependencies
Owen Anderson3f75d122007-08-01 22:01:54 +0000132void MemoryDependenceAnalysis::nonLocalHelper(Instruction* query,
Owen Anderson5d72a422007-07-25 19:57:03 +0000133 BasicBlock* block,
Owen Andersonafe840e2007-08-08 22:01:54 +0000134 DenseMap<BasicBlock*, Value*>& resp) {
Owen Anderson3de3c532007-08-08 22:26:03 +0000135 // Set of blocks that we've already visited in our DFS
Owen Anderson3f75d122007-08-01 22:01:54 +0000136 SmallPtrSet<BasicBlock*, 4> visited;
Owen Anderson3de3c532007-08-08 22:26:03 +0000137 // Current stack of the DFS
Owen Anderson3f75d122007-08-01 22:01:54 +0000138 SmallVector<BasicBlock*, 4> stack;
139 stack.push_back(block);
Owen Anderson4c295472007-07-24 21:52:37 +0000140
Owen Anderson3de3c532007-08-08 22:26:03 +0000141 // Do a basic DFS
Owen Anderson3f75d122007-08-01 22:01:54 +0000142 while (!stack.empty()) {
143 BasicBlock* BB = stack.back();
144
Owen Anderson3de3c532007-08-08 22:26:03 +0000145 // If we've already visited this block, no need to revist
Owen Andersonc6a31b92007-08-02 17:56:05 +0000146 if (visited.count(BB)) {
Owen Anderson3f75d122007-08-01 22:01:54 +0000147 stack.pop_back();
148 continue;
149 }
150
Owen Anderson3de3c532007-08-08 22:26:03 +0000151 // If we find a new block with a local dependency for query,
152 // then we insert the new dependency and backtrack.
Owen Anderson3f75d122007-08-01 22:01:54 +0000153 if (BB != block) {
Owen Andersonc6a31b92007-08-02 17:56:05 +0000154 visited.insert(BB);
155
Owen Anderson935e39b2007-08-09 04:42:44 +0000156 Instruction* localDep = getDependency(query, 0, BB);
Owen Anderson3f75d122007-08-01 22:01:54 +0000157 if (localDep != NonLocal) {
Owen Anderson935e39b2007-08-09 04:42:44 +0000158 resp.insert(std::make_pair(BB, localDep));
Owen Andersonc6a31b92007-08-02 17:56:05 +0000159 stack.pop_back();
160
Owen Anderson3f75d122007-08-01 22:01:54 +0000161 continue;
162 }
Owen Anderson3de3c532007-08-08 22:26:03 +0000163 // If we re-encounter the starting block, we still need to search it
164 // because there might be a dependency in the starting block AFTER
165 // the position of the query. This is necessary to get loops right.
Owen Andersonc6a31b92007-08-02 17:56:05 +0000166 } else if (BB == block && stack.size() > 1) {
167 visited.insert(BB);
168
Owen Anderson935e39b2007-08-09 04:42:44 +0000169 Instruction* localDep = getDependency(query, 0, BB);
Owen Andersonc6a31b92007-08-02 17:56:05 +0000170 if (localDep != query)
Owen Anderson935e39b2007-08-09 04:42:44 +0000171 resp.insert(std::make_pair(BB, localDep));
Owen Andersonc6a31b92007-08-02 17:56:05 +0000172
173 stack.pop_back();
174
175 continue;
Owen Anderson3f75d122007-08-01 22:01:54 +0000176 }
177
Owen Anderson3de3c532007-08-08 22:26:03 +0000178 // If we didn't find anything, recurse on the precessors of this block
Owen Anderson3f75d122007-08-01 22:01:54 +0000179 bool predOnStack = false;
180 bool inserted = false;
181 for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
182 PI != PE; ++PI)
183 if (!visited.count(*PI)) {
184 stack.push_back(*PI);
185 inserted = true;
186 } else
187 predOnStack = true;
188
Owen Anderson3de3c532007-08-08 22:26:03 +0000189 // If we inserted a new predecessor, then we'll come back to this block
Owen Anderson3f75d122007-08-01 22:01:54 +0000190 if (inserted)
191 continue;
Owen Anderson3de3c532007-08-08 22:26:03 +0000192 // If we didn't insert because we have no predecessors, then this
193 // query has no dependency at all.
Owen Anderson3f75d122007-08-01 22:01:54 +0000194 else if (!inserted && !predOnStack) {
Owen Anderson935e39b2007-08-09 04:42:44 +0000195 resp.insert(std::make_pair(BB, None));
Owen Anderson3de3c532007-08-08 22:26:03 +0000196 // If we didn't insert because our predecessors are already on the stack,
197 // then we might still have a dependency, but it will be discovered during
198 // backtracking.
Owen Anderson3f75d122007-08-01 22:01:54 +0000199 } else if (!inserted && predOnStack){
Owen Anderson935e39b2007-08-09 04:42:44 +0000200 resp.insert(std::make_pair(BB, NonLocal));
Owen Anderson3f75d122007-08-01 22:01:54 +0000201 }
202
203 stack.pop_back();
Owen Anderson4c295472007-07-24 21:52:37 +0000204 }
Owen Anderson4c295472007-07-24 21:52:37 +0000205}
206
Owen Andersonafe840e2007-08-08 22:01:54 +0000207/// getNonLocalDependency - Fills the passed-in map with the non-local
208/// dependencies of the queries. The map will contain NonLocal for
209/// blocks between the query and its dependencies.
Owen Anderson3f75d122007-08-01 22:01:54 +0000210void MemoryDependenceAnalysis::getNonLocalDependency(Instruction* query,
Owen Andersonafe840e2007-08-08 22:01:54 +0000211 DenseMap<BasicBlock*, Value*>& resp) {
Owen Anderson2bd46a52007-08-16 21:27:05 +0000212 if (depGraphNonLocal.count(query)) {
213 resp = depGraphNonLocal[query];
Owen Andersond6c7fea2007-09-09 21:43:49 +0000214 NumCacheNonlocal++;
Owen Anderson2bd46a52007-08-16 21:27:05 +0000215 return;
Owen Andersond6c7fea2007-09-09 21:43:49 +0000216 } else
217 NumUncacheNonlocal++;
Owen Anderson2bd46a52007-08-16 21:27:05 +0000218
Owen Andersond6c7fea2007-09-09 21:43:49 +0000219 // If not, go ahead and search for non-local deps.
Owen Anderson3f75d122007-08-01 22:01:54 +0000220 nonLocalHelper(query, query->getParent(), resp);
Owen Anderson2bd46a52007-08-16 21:27:05 +0000221
222 // Update the non-local dependency cache
223 for (DenseMap<BasicBlock*, Value*>::iterator I = resp.begin(), E = resp.end();
224 I != E; ++I) {
225 depGraphNonLocal[query].insert(*I);
226 reverseDepNonLocal[I->second].insert(query);
227 }
Owen Anderson4c295472007-07-24 21:52:37 +0000228}
229
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000230/// getDependency - Return the instruction on which a memory operation
231/// depends. The local paramter indicates if the query should only
232/// evaluate dependencies within the same basic block.
Owen Anderson935e39b2007-08-09 04:42:44 +0000233Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234 Instruction* start,
Owen Anderson4c295472007-07-24 21:52:37 +0000235 BasicBlock* block) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000236 // Start looking for dependencies with the queried inst
237 BasicBlock::iterator QI = query;
238
239 // Check for a cached result
Owen Anderson935e39b2007-08-09 04:42:44 +0000240 std::pair<Instruction*, bool> cachedResult = depGraphLocal[query];
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000241 // If we have a _confirmed_ cached entry, return it
242 if (cachedResult.second)
243 return cachedResult.first;
Owen Anderson5d72a422007-07-25 19:57:03 +0000244 else if (cachedResult.first && cachedResult.first != NonLocal)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000245 // If we have an unconfirmed cached entry, we can start our search from there
Owen Anderson935e39b2007-08-09 04:42:44 +0000246 QI = cachedResult.first;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247
248 if (start)
249 QI = start;
Owen Anderson5d72a422007-07-25 19:57:03 +0000250 else if (!start && block)
251 QI = block->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000252
253 AliasAnalysis& AA = getAnalysis<AliasAnalysis>();
254 TargetData& TD = getAnalysis<TargetData>();
255
256 // Get the pointer value for which dependence will be determined
257 Value* dependee = 0;
258 uint64_t dependeeSize = 0;
259 bool queryIsVolatile = false;
260 if (StoreInst* S = dyn_cast<StoreInst>(query)) {
261 dependee = S->getPointerOperand();
262 dependeeSize = TD.getTypeSize(S->getOperand(0)->getType());
263 queryIsVolatile = S->isVolatile();
264 } else if (LoadInst* L = dyn_cast<LoadInst>(query)) {
265 dependee = L->getPointerOperand();
266 dependeeSize = TD.getTypeSize(L->getType());
267 queryIsVolatile = L->isVolatile();
268 } else if (VAArgInst* V = dyn_cast<VAArgInst>(query)) {
269 dependee = V->getOperand(0);
270 dependeeSize = TD.getTypeSize(V->getType());
271 } else if (FreeInst* F = dyn_cast<FreeInst>(query)) {
272 dependee = F->getPointerOperand();
273
274 // FreeInsts erase the entire structure, not just a field
275 dependeeSize = ~0UL;
276 } else if (CallSite::get(query).getInstruction() != 0)
Owen Andersone84f4bc2007-08-07 00:33:45 +0000277 return getCallSiteDependency(CallSite::get(query), start, block);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000278 else if (isa<AllocationInst>(query))
279 return None;
280 else
281 return None;
282
Owen Anderson4c295472007-07-24 21:52:37 +0000283 BasicBlock::iterator blockBegin = block ? block->begin()
284 : query->getParent()->begin();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000285
Owen Anderson3de3c532007-08-08 22:26:03 +0000286 // Walk backwards through the basic block, looking for dependencies
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000287 while (QI != blockBegin) {
288 --QI;
289
290 // If this inst is a memory op, get the pointer it accessed
291 Value* pointer = 0;
292 uint64_t pointerSize = 0;
293 if (StoreInst* S = dyn_cast<StoreInst>(QI)) {
294 // All volatile loads/stores depend on each other
295 if (queryIsVolatile && S->isVolatile()) {
Owen Andersone84f4bc2007-08-07 00:33:45 +0000296 if (!start && !block) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000297 depGraphLocal.insert(std::make_pair(query, std::make_pair(S, true)));
Owen Andersone84f4bc2007-08-07 00:33:45 +0000298 reverseDep[S].insert(query);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000299 }
300
301 return S;
302 }
303
304 pointer = S->getPointerOperand();
305 pointerSize = TD.getTypeSize(S->getOperand(0)->getType());
306 } else if (LoadInst* L = dyn_cast<LoadInst>(QI)) {
307 // All volatile loads/stores depend on each other
308 if (queryIsVolatile && L->isVolatile()) {
Owen Andersone84f4bc2007-08-07 00:33:45 +0000309 if (!start && !block) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000310 depGraphLocal.insert(std::make_pair(query, std::make_pair(L, true)));
Owen Andersone84f4bc2007-08-07 00:33:45 +0000311 reverseDep[L].insert(query);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000312 }
313
314 return L;
315 }
316
317 pointer = L->getPointerOperand();
318 pointerSize = TD.getTypeSize(L->getType());
319 } else if (AllocationInst* AI = dyn_cast<AllocationInst>(QI)) {
320 pointer = AI;
321 if (ConstantInt* C = dyn_cast<ConstantInt>(AI->getArraySize()))
Owen Andersonafe840e2007-08-08 22:01:54 +0000322 pointerSize = C->getZExtValue() * \
323 TD.getTypeSize(AI->getAllocatedType());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000324 else
325 pointerSize = ~0UL;
326 } else if (VAArgInst* V = dyn_cast<VAArgInst>(QI)) {
327 pointer = V->getOperand(0);
328 pointerSize = TD.getTypeSize(V->getType());
329 } else if (FreeInst* F = dyn_cast<FreeInst>(QI)) {
330 pointer = F->getPointerOperand();
331
332 // FreeInsts erase the entire structure
333 pointerSize = ~0UL;
334 } else if (CallSite::get(QI).getInstruction() != 0) {
Owen Andersonafe840e2007-08-08 22:01:54 +0000335 // Call insts need special handling. Check if they can modify our pointer
Owen Anderson151f7692007-08-06 23:26:03 +0000336 AliasAnalysis::ModRefResult MR = AA.getModRefInfo(CallSite::get(QI),
337 dependee, dependeeSize);
338
339 if (MR != AliasAnalysis::NoModRef) {
340 // Loads don't depend on read-only calls
341 if (isa<LoadInst>(query) && MR == AliasAnalysis::Ref)
342 continue;
343
Owen Andersone84f4bc2007-08-07 00:33:45 +0000344 if (!start && !block) {
Owen Andersonafe840e2007-08-08 22:01:54 +0000345 depGraphLocal.insert(std::make_pair(query,
346 std::make_pair(QI, true)));
Owen Andersone84f4bc2007-08-07 00:33:45 +0000347 reverseDep[QI].insert(query);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000348 }
349
350 return QI;
351 } else {
352 continue;
353 }
354 }
355
356 // If we found a pointer, check if it could be the same as our pointer
357 if (pointer) {
358 AliasAnalysis::AliasResult R = AA.alias(pointer, pointerSize,
359 dependee, dependeeSize);
360
361 if (R != AliasAnalysis::NoAlias) {
Owen Anderson151f7692007-08-06 23:26:03 +0000362 // May-alias loads don't depend on each other
363 if (isa<LoadInst>(query) && isa<LoadInst>(QI) &&
364 R == AliasAnalysis::MayAlias)
365 continue;
366
Owen Andersone84f4bc2007-08-07 00:33:45 +0000367 if (!start && !block) {
Owen Andersonafe840e2007-08-08 22:01:54 +0000368 depGraphLocal.insert(std::make_pair(query,
369 std::make_pair(QI, true)));
Owen Andersone84f4bc2007-08-07 00:33:45 +0000370 reverseDep[QI].insert(query);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000371 }
372
373 return QI;
374 }
375 }
376 }
377
378 // If we found nothing, return the non-local flag
Owen Andersone84f4bc2007-08-07 00:33:45 +0000379 if (!start && !block) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000380 depGraphLocal.insert(std::make_pair(query,
381 std::make_pair(NonLocal, true)));
Owen Andersone84f4bc2007-08-07 00:33:45 +0000382 reverseDep[NonLocal].insert(query);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000383 }
384
385 return NonLocal;
386}
387
388/// removeInstruction - Remove an instruction from the dependence analysis,
389/// updating the dependence of instructions that previously depended on it.
Owen Anderson3de3c532007-08-08 22:26:03 +0000390/// This method attempts to keep the cache coherent using the reverse map.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000391void MemoryDependenceAnalysis::removeInstruction(Instruction* rem) {
392 // Figure out the new dep for things that currently depend on rem
Owen Anderson935e39b2007-08-09 04:42:44 +0000393 Instruction* newDep = NonLocal;
David Greene701171c2007-07-31 20:01:27 +0000394
395 depMapType::iterator depGraphEntry = depGraphLocal.find(rem);
David Greene701171c2007-07-31 20:01:27 +0000396
397 if (depGraphEntry != depGraphLocal.end()) {
398 if (depGraphEntry->second.first != NonLocal &&
399 depGraphEntry->second.second) {
400 // If we have dep info for rem, set them to it
Owen Anderson935e39b2007-08-09 04:42:44 +0000401 BasicBlock::iterator RI = depGraphEntry->second.first;
David Greene701171c2007-07-31 20:01:27 +0000402 RI++;
403 newDep = RI;
404 } else if (depGraphEntry->second.first == NonLocal &&
405 depGraphEntry->second.second ) {
406 // If we have a confirmed non-local flag, use it
407 newDep = NonLocal;
408 } else {
409 // Otherwise, use the immediate successor of rem
Owen Andersonafe840e2007-08-08 22:01:54 +0000410 // NOTE: This is because, when getDependence is called, it will first
411 // check the immediate predecessor of what is in the cache.
David Greene701171c2007-07-31 20:01:27 +0000412 BasicBlock::iterator RI = rem;
413 RI++;
414 newDep = RI;
415 }
416
Owen Andersone84f4bc2007-08-07 00:33:45 +0000417 SmallPtrSet<Instruction*, 4>& set = reverseDep[rem];
418 for (SmallPtrSet<Instruction*, 4>::iterator I = set.begin(), E = set.end();
419 I != E; ++I) {
David Greene701171c2007-07-31 20:01:27 +0000420 // Insert the new dependencies
421 // Mark it as unconfirmed as long as it is not the non-local flag
Owen Andersone84f4bc2007-08-07 00:33:45 +0000422 depGraphLocal[*I] = std::make_pair(newDep, !newDep);
David Greene701171c2007-07-31 20:01:27 +0000423 }
Owen Anderson2bd46a52007-08-16 21:27:05 +0000424
Owen Andersone84f4bc2007-08-07 00:33:45 +0000425 reverseDep.erase(rem);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426 }
Owen Anderson2bd46a52007-08-16 21:27:05 +0000427
428 if (depGraphNonLocal.count(rem)) {
429 SmallPtrSet<Instruction*, 4>& set = reverseDepNonLocal[rem];
430 for (SmallPtrSet<Instruction*, 4>::iterator I = set.begin(), E = set.end();
431 I != E; ++I)
432 depGraphNonLocal.erase(*I);
433
434 reverseDepNonLocal.erase(rem);
435 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000436
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000437 getAnalysis<AliasAnalysis>().deleteValue(rem);
438}