blob: 015ded18d900a0626f567e8b80bb08f5371e8a7a [file] [log] [blame]
Nick Lewycky7ed1dbf2013-06-10 23:10:59 +00001//===- MemoryDependenceAnalysis.cpp - Mem Deps Implementation -------------===//
Owen Andersonc0daf5f2007-07-06 23:14:35 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Owen Andersonc0daf5f2007-07-06 23:14:35 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements an analysis that determines, for a given memory
Jakub Staszakb0a7eed2013-03-20 21:47:51 +000011// operation, what preceding memory operations it depends on. It builds on
Owen Andersonfa788352007-08-08 22:01:54 +000012// alias analysis information, and tries to provide a lazy, caching interface to
Owen Andersonc0daf5f2007-07-06 23:14:35 +000013// a common kind of alias information query.
14//
15//===----------------------------------------------------------------------===//
16
Chris Lattner554d1222008-11-28 21:45:17 +000017#define DEBUG_TYPE "memdep"
Owen Andersonc0daf5f2007-07-06 23:14:35 +000018#include "llvm/Analysis/MemoryDependenceAnalysis.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000019#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/Statistic.h"
Owen Andersonc0daf5f2007-07-06 23:14:35 +000021#include "llvm/Analysis/AliasAnalysis.h"
Chris Lattner5030c6a2009-11-27 00:34:38 +000022#include "llvm/Analysis/InstructionSimplify.h"
Victor Hernandezf390e042009-10-27 20:05:49 +000023#include "llvm/Analysis/MemoryBuiltins.h"
Chris Lattner972e6d82009-12-09 01:59:31 +000024#include "llvm/Analysis/PHITransAddr.h"
Dan Gohmana4fcd242010-12-15 20:02:24 +000025#include "llvm/Analysis/ValueTracking.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000026#include "llvm/IR/DataLayout.h"
Chandler Carruth5ad5f152014-01-13 09:26:24 +000027#include "llvm/IR/Dominators.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000028#include "llvm/IR/Function.h"
29#include "llvm/IR/Instructions.h"
30#include "llvm/IR/IntrinsicInst.h"
31#include "llvm/IR/LLVMContext.h"
Chandler Carruthaa0ab632014-03-04 12:09:19 +000032#include "llvm/IR/PredIteratorCache.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000033#include "llvm/Support/Debug.h"
Owen Andersonc0daf5f2007-07-06 23:14:35 +000034using namespace llvm;
35
Chris Lattner7e61daf2008-12-01 01:15:42 +000036STATISTIC(NumCacheNonLocal, "Number of fully cached non-local responses");
37STATISTIC(NumCacheDirtyNonLocal, "Number of dirty cached non-local responses");
Chris Lattnere7d7e132008-11-29 22:02:15 +000038STATISTIC(NumUncacheNonLocal, "Number of uncached non-local responses");
Chris Lattnera28355d2008-12-07 08:50:20 +000039
40STATISTIC(NumCacheNonLocalPtr,
41 "Number of fully cached non-local ptr responses");
42STATISTIC(NumCacheDirtyNonLocalPtr,
43 "Number of cached, but dirty, non-local ptr responses");
44STATISTIC(NumUncacheNonLocalPtr,
45 "Number of uncached non-local ptr responses");
Chris Lattner5ed409e2008-12-08 07:31:50 +000046STATISTIC(NumCacheCompleteNonLocalPtr,
47 "Number of block queries that were completely cached");
Chris Lattnera28355d2008-12-07 08:50:20 +000048
Eli Friedman8b098b02011-06-15 23:59:25 +000049// Limit for the number of instructions to scan in a block.
Bill Wendling9ca12c12013-04-17 20:02:32 +000050static const int BlockScanLimit = 100;
Eli Friedman8b098b02011-06-15 23:59:25 +000051
Owen Andersonc0daf5f2007-07-06 23:14:35 +000052char MemoryDependenceAnalysis::ID = 0;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +000053
Owen Andersonc0daf5f2007-07-06 23:14:35 +000054// Register this pass...
Owen Anderson8ac477f2010-10-12 19:48:12 +000055INITIALIZE_PASS_BEGIN(MemoryDependenceAnalysis, "memdep",
Owen Andersondf7a4f22010-10-07 22:25:06 +000056 "Memory Dependence Analysis", false, true)
Owen Anderson8ac477f2010-10-12 19:48:12 +000057INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
58INITIALIZE_PASS_END(MemoryDependenceAnalysis, "memdep",
59 "Memory Dependence Analysis", false, true)
Owen Andersonc0daf5f2007-07-06 23:14:35 +000060
Chris Lattner768e5bc2008-12-09 06:28:49 +000061MemoryDependenceAnalysis::MemoryDependenceAnalysis()
Ahmed Charles56440fd2014-03-06 05:51:42 +000062 : FunctionPass(ID), PredCache() {
Owen Anderson6c18d1a2010-10-19 17:21:58 +000063 initializeMemoryDependenceAnalysisPass(*PassRegistry::getPassRegistry());
Chris Lattner768e5bc2008-12-09 06:28:49 +000064}
65MemoryDependenceAnalysis::~MemoryDependenceAnalysis() {
66}
67
68/// Clean up memory in between runs
69void MemoryDependenceAnalysis::releaseMemory() {
70 LocalDeps.clear();
71 NonLocalDeps.clear();
72 NonLocalPointerDeps.clear();
73 ReverseLocalDeps.clear();
74 ReverseNonLocalDeps.clear();
75 ReverseNonLocalPtrDeps.clear();
76 PredCache->clear();
77}
78
79
80
Owen Andersonc0daf5f2007-07-06 23:14:35 +000081/// getAnalysisUsage - Does not modify anything. It uses Alias Analysis.
82///
83void MemoryDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
84 AU.setPreservesAll();
85 AU.addRequiredTransitive<AliasAnalysis>();
Owen Andersonc0daf5f2007-07-06 23:14:35 +000086}
87
Chris Lattner13cae612008-11-30 19:24:31 +000088bool MemoryDependenceAnalysis::runOnFunction(Function &) {
89 AA = &getAnalysis<AliasAnalysis>();
Rafael Espindola93512512014-02-25 17:30:31 +000090 DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
91 DL = DLP ? &DLP->getDataLayout() : 0;
Chandler Carruth73523022014-01-13 13:07:17 +000092 DominatorTreeWrapperPass *DTWP =
93 getAnalysisIfAvailable<DominatorTreeWrapperPass>();
94 DT = DTWP ? &DTWP->getDomTree() : 0;
David Blaikie041f1aa2013-05-15 07:36:59 +000095 if (!PredCache)
Chris Lattner768e5bc2008-12-09 06:28:49 +000096 PredCache.reset(new PredIteratorCache());
Chris Lattner13cae612008-11-30 19:24:31 +000097 return false;
98}
99
Chris Lattnerde4440c2008-12-07 18:39:13 +0000100/// RemoveFromReverseMap - This is a helper function that removes Val from
101/// 'Inst's set in ReverseMap. If the set becomes empty, remove Inst's entry.
102template <typename KeyTy>
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000103static void RemoveFromReverseMap(DenseMap<Instruction*,
Chris Lattner8eda11b2009-03-29 00:24:04 +0000104 SmallPtrSet<KeyTy, 4> > &ReverseMap,
105 Instruction *Inst, KeyTy Val) {
106 typename DenseMap<Instruction*, SmallPtrSet<KeyTy, 4> >::iterator
Chris Lattnerde4440c2008-12-07 18:39:13 +0000107 InstIt = ReverseMap.find(Inst);
108 assert(InstIt != ReverseMap.end() && "Reverse map out of sync?");
109 bool Found = InstIt->second.erase(Val);
Jeffrey Yasskin9b43f332010-12-23 00:58:24 +0000110 assert(Found && "Invalid reverse map!"); (void)Found;
Chris Lattnerde4440c2008-12-07 18:39:13 +0000111 if (InstIt->second.empty())
112 ReverseMap.erase(InstIt);
113}
114
Dan Gohman1d760ce2010-11-10 21:51:35 +0000115/// GetLocation - If the given instruction references a specific memory
116/// location, fill in Loc with the details, otherwise set Loc.Ptr to null.
117/// Return a ModRefInfo value describing the general behavior of the
118/// instruction.
119static
120AliasAnalysis::ModRefResult GetLocation(const Instruction *Inst,
121 AliasAnalysis::Location &Loc,
122 AliasAnalysis *AA) {
123 if (const LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
Eli Friedman5494ada2011-08-15 20:54:19 +0000124 if (LI->isUnordered()) {
125 Loc = AA->getLocation(LI);
126 return AliasAnalysis::Ref;
Jakub Staszakfa41def2013-03-20 23:53:45 +0000127 }
128 if (LI->getOrdering() == Monotonic) {
Eli Friedman5494ada2011-08-15 20:54:19 +0000129 Loc = AA->getLocation(LI);
Dan Gohman1d760ce2010-11-10 21:51:35 +0000130 return AliasAnalysis::ModRef;
131 }
Eli Friedman5494ada2011-08-15 20:54:19 +0000132 Loc = AliasAnalysis::Location();
133 return AliasAnalysis::ModRef;
Dan Gohman1d760ce2010-11-10 21:51:35 +0000134 }
135
136 if (const StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
Eli Friedman5494ada2011-08-15 20:54:19 +0000137 if (SI->isUnordered()) {
138 Loc = AA->getLocation(SI);
139 return AliasAnalysis::Mod;
Jakub Staszakfa41def2013-03-20 23:53:45 +0000140 }
141 if (SI->getOrdering() == Monotonic) {
Eli Friedman5494ada2011-08-15 20:54:19 +0000142 Loc = AA->getLocation(SI);
Dan Gohman1d760ce2010-11-10 21:51:35 +0000143 return AliasAnalysis::ModRef;
144 }
Eli Friedman5494ada2011-08-15 20:54:19 +0000145 Loc = AliasAnalysis::Location();
146 return AliasAnalysis::ModRef;
Dan Gohman1d760ce2010-11-10 21:51:35 +0000147 }
148
149 if (const VAArgInst *V = dyn_cast<VAArgInst>(Inst)) {
Dan Gohman65316d62010-11-11 21:50:19 +0000150 Loc = AA->getLocation(V);
Dan Gohman1d760ce2010-11-10 21:51:35 +0000151 return AliasAnalysis::ModRef;
152 }
153
Benjamin Kramer8bcc9712012-08-29 15:32:21 +0000154 if (const CallInst *CI = isFreeCall(Inst, AA->getTargetLibraryInfo())) {
Dan Gohman1d760ce2010-11-10 21:51:35 +0000155 // calls to free() deallocate the entire structure
156 Loc = AliasAnalysis::Location(CI->getArgOperand(0));
157 return AliasAnalysis::Mod;
158 }
159
160 if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst))
161 switch (II->getIntrinsicID()) {
162 case Intrinsic::lifetime_start:
163 case Intrinsic::lifetime_end:
164 case Intrinsic::invariant_start:
165 Loc = AliasAnalysis::Location(II->getArgOperand(1),
166 cast<ConstantInt>(II->getArgOperand(0))
167 ->getZExtValue(),
168 II->getMetadata(LLVMContext::MD_tbaa));
169 // These intrinsics don't really modify the memory, but returning Mod
170 // will allow them to be handled conservatively.
171 return AliasAnalysis::Mod;
172 case Intrinsic::invariant_end:
173 Loc = AliasAnalysis::Location(II->getArgOperand(2),
174 cast<ConstantInt>(II->getArgOperand(1))
175 ->getZExtValue(),
176 II->getMetadata(LLVMContext::MD_tbaa));
177 // These intrinsics don't really modify the memory, but returning Mod
178 // will allow them to be handled conservatively.
179 return AliasAnalysis::Mod;
180 default:
181 break;
182 }
183
184 // Otherwise, just do the coarse-grained thing that always works.
185 if (Inst->mayWriteToMemory())
186 return AliasAnalysis::ModRef;
187 if (Inst->mayReadFromMemory())
188 return AliasAnalysis::Ref;
189 return AliasAnalysis::NoModRef;
190}
Chris Lattner7e61daf2008-12-01 01:15:42 +0000191
Chris Lattner056c0902008-12-07 00:35:51 +0000192/// getCallSiteDependencyFrom - Private helper for finding the local
193/// dependencies of a call site.
Chris Lattner47e81d02008-11-30 23:17:19 +0000194MemDepResult MemoryDependenceAnalysis::
Chris Lattner702e46e2008-12-09 21:19:42 +0000195getCallSiteDependencyFrom(CallSite CS, bool isReadOnlyCall,
196 BasicBlock::iterator ScanIt, BasicBlock *BB) {
Eli Friedman8b098b02011-06-15 23:59:25 +0000197 unsigned Limit = BlockScanLimit;
198
Owen Anderson2b21c3c2007-08-08 22:26:03 +0000199 // Walk backwards through the block, looking for dependencies
Chris Lattner51ba8d02008-11-29 03:47:00 +0000200 while (ScanIt != BB->begin()) {
Eli Friedman8b098b02011-06-15 23:59:25 +0000201 // Limit the amount of scanning we do so we don't end up with quadratic
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000202 // running time on extreme testcases.
Eli Friedman8b098b02011-06-15 23:59:25 +0000203 --Limit;
204 if (!Limit)
205 return MemDepResult::getUnknown();
206
Chris Lattner51ba8d02008-11-29 03:47:00 +0000207 Instruction *Inst = --ScanIt;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000208
Owen Anderson9c884572007-07-10 17:59:22 +0000209 // If this inst is a memory op, get the pointer it accessed
Dan Gohman23483932010-09-22 21:41:02 +0000210 AliasAnalysis::Location Loc;
Dan Gohman1d760ce2010-11-10 21:51:35 +0000211 AliasAnalysis::ModRefResult MR = GetLocation(Inst, Loc, AA);
212 if (Loc.Ptr) {
213 // A simple instruction.
214 if (AA->getModRefInfo(CS, Loc) != AliasAnalysis::NoModRef)
215 return MemDepResult::getClobber(Inst);
216 continue;
217 }
218
219 if (CallSite InstCS = cast<Value>(Inst)) {
Owen Andersonf9a9cf92009-03-09 05:12:38 +0000220 // Debug intrinsics don't cause dependences.
Dale Johannesenf61c8e82009-03-11 21:13:01 +0000221 if (isa<DbgInfoIntrinsic>(Inst)) continue;
Chris Lattner0e3d6332008-12-05 21:04:20 +0000222 // If these two calls do not interfere, look past it.
Chris Lattner702e46e2008-12-09 21:19:42 +0000223 switch (AA->getModRefInfo(CS, InstCS)) {
224 case AliasAnalysis::NoModRef:
Dan Gohman26ef7c72010-08-05 22:09:15 +0000225 // If the two calls are the same, return InstCS as a Def, so that
226 // CS can be found redundant and eliminated.
Dan Gohman1d760ce2010-11-10 21:51:35 +0000227 if (isReadOnlyCall && !(MR & AliasAnalysis::Mod) &&
Dan Gohman26ef7c72010-08-05 22:09:15 +0000228 CS.getInstruction()->isIdenticalToWhenDefined(Inst))
229 return MemDepResult::getDef(Inst);
230
231 // Otherwise if the two calls don't interact (e.g. InstCS is readnone)
232 // keep scanning.
Nadav Rotem5d4e2052012-08-13 23:03:43 +0000233 continue;
Chris Lattner702e46e2008-12-09 21:19:42 +0000234 default:
Chris Lattner0e3d6332008-12-05 21:04:20 +0000235 return MemDepResult::getClobber(Inst);
Chris Lattner702e46e2008-12-09 21:19:42 +0000236 }
Chris Lattnerff862c42008-11-30 01:44:00 +0000237 }
Nadav Rotem5d4e2052012-08-13 23:03:43 +0000238
239 // If we could not obtain a pointer for the instruction and the instruction
240 // touches memory then assume that this is a dependency.
241 if (MR != AliasAnalysis::NoModRef)
242 return MemDepResult::getClobber(Inst);
Owen Anderson9c884572007-07-10 17:59:22 +0000243 }
Nadav Rotem5d4e2052012-08-13 23:03:43 +0000244
Eli Friedman7d58bc72011-06-15 00:47:34 +0000245 // No dependence found. If this is the entry block of the function, it is
246 // unknown, otherwise it is non-local.
Chris Lattner2faa2c72008-12-07 02:15:47 +0000247 if (BB != &BB->getParent()->getEntryBlock())
248 return MemDepResult::getNonLocal();
Eli Friedmanc1702c82011-10-13 22:14:57 +0000249 return MemDepResult::getNonFuncLocal();
Owen Anderson9c884572007-07-10 17:59:22 +0000250}
251
Chris Lattner7aab2792011-04-26 22:42:01 +0000252/// isLoadLoadClobberIfExtendedToFullWidth - Return true if LI is a load that
253/// would fully overlap MemLoc if done as a wider legal integer load.
254///
255/// MemLocBase, MemLocOffset are lazily computed here the first time the
256/// base/offs of memloc is needed.
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000257static bool
Chris Lattner7aab2792011-04-26 22:42:01 +0000258isLoadLoadClobberIfExtendedToFullWidth(const AliasAnalysis::Location &MemLoc,
259 const Value *&MemLocBase,
260 int64_t &MemLocOffs,
Chris Lattner827a2702011-04-28 07:29:08 +0000261 const LoadInst *LI,
Rafael Espindola7c68beb2014-02-18 15:33:12 +0000262 const DataLayout *DL) {
Chris Lattner7aab2792011-04-26 22:42:01 +0000263 // If we have no target data, we can't do this.
Rafael Espindola7c68beb2014-02-18 15:33:12 +0000264 if (DL == 0) return false;
Chris Lattner7aab2792011-04-26 22:42:01 +0000265
266 // If we haven't already computed the base/offset of MemLoc, do so now.
267 if (MemLocBase == 0)
Rafael Espindola7c68beb2014-02-18 15:33:12 +0000268 MemLocBase = GetPointerBaseWithConstantOffset(MemLoc.Ptr, MemLocOffs, DL);
Chris Lattner7aab2792011-04-26 22:42:01 +0000269
Chris Lattner827a2702011-04-28 07:29:08 +0000270 unsigned Size = MemoryDependenceAnalysis::
271 getLoadLoadClobberFullWidthSize(MemLocBase, MemLocOffs, MemLoc.Size,
Rafael Espindola7c68beb2014-02-18 15:33:12 +0000272 LI, *DL);
Chris Lattner827a2702011-04-28 07:29:08 +0000273 return Size != 0;
274}
275
276/// getLoadLoadClobberFullWidthSize - This is a little bit of analysis that
277/// looks at a memory location for a load (specified by MemLocBase, Offs,
278/// and Size) and compares it against a load. If the specified load could
279/// be safely widened to a larger integer load that is 1) still efficient,
280/// 2) safe for the target, and 3) would provide the specified memory
281/// location value, then this function returns the size in bytes of the
282/// load width to use. If not, this returns zero.
283unsigned MemoryDependenceAnalysis::
284getLoadLoadClobberFullWidthSize(const Value *MemLocBase, int64_t MemLocOffs,
285 unsigned MemLocSize, const LoadInst *LI,
Rafael Espindola7c68beb2014-02-18 15:33:12 +0000286 const DataLayout &DL) {
Eli Friedman5494ada2011-08-15 20:54:19 +0000287 // We can only extend simple integer loads.
288 if (!isa<IntegerType>(LI->getType()) || !LI->isSimple()) return 0;
Kostya Serebryany3838f272013-02-13 05:59:45 +0000289
290 // Load widening is hostile to ThreadSanitizer: it may cause false positives
291 // or make the reports more cryptic (access sizes are wrong).
292 if (LI->getParent()->getParent()->getAttributes().
Kostya Serebryanycf880b92013-02-26 06:58:09 +0000293 hasAttribute(AttributeSet::FunctionIndex, Attribute::SanitizeThread))
Kostya Serebryany3838f272013-02-13 05:59:45 +0000294 return 0;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000295
Chris Lattner7aab2792011-04-26 22:42:01 +0000296 // Get the base of this load.
297 int64_t LIOffs = 0;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000298 const Value *LIBase =
Rafael Espindola7c68beb2014-02-18 15:33:12 +0000299 GetPointerBaseWithConstantOffset(LI->getPointerOperand(), LIOffs, &DL);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000300
Chris Lattner7aab2792011-04-26 22:42:01 +0000301 // If the two pointers are not based on the same pointer, we can't tell that
302 // they are related.
Chris Lattner827a2702011-04-28 07:29:08 +0000303 if (LIBase != MemLocBase) return 0;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000304
Chris Lattner7aab2792011-04-26 22:42:01 +0000305 // Okay, the two values are based on the same pointer, but returned as
306 // no-alias. This happens when we have things like two byte loads at "P+1"
307 // and "P+3". Check to see if increasing the size of the "LI" load up to its
308 // alignment (or the largest native integer type) will allow us to load all
309 // the bits required by MemLoc.
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000310
Chris Lattner7aab2792011-04-26 22:42:01 +0000311 // If MemLoc is before LI, then no widening of LI will help us out.
Chris Lattner827a2702011-04-28 07:29:08 +0000312 if (MemLocOffs < LIOffs) return 0;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000313
Chris Lattner7aab2792011-04-26 22:42:01 +0000314 // Get the alignment of the load in bytes. We assume that it is safe to load
315 // any legal integer up to this size without a problem. For example, if we're
316 // looking at an i8 load on x86-32 that is known 1024 byte aligned, we can
317 // widen it up to an i32 load. If it is known 2-byte aligned, we can widen it
318 // to i16.
319 unsigned LoadAlign = LI->getAlignment();
320
Chris Lattner827a2702011-04-28 07:29:08 +0000321 int64_t MemLocEnd = MemLocOffs+MemLocSize;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000322
Chris Lattner7aab2792011-04-26 22:42:01 +0000323 // If no amount of rounding up will let MemLoc fit into LI, then bail out.
Chris Lattner827a2702011-04-28 07:29:08 +0000324 if (LIOffs+LoadAlign < MemLocEnd) return 0;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000325
Chris Lattner7aab2792011-04-26 22:42:01 +0000326 // This is the size of the load to try. Start with the next larger power of
327 // two.
328 unsigned NewLoadByteSize = LI->getType()->getPrimitiveSizeInBits()/8U;
329 NewLoadByteSize = NextPowerOf2(NewLoadByteSize);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000330
Chris Lattner7aab2792011-04-26 22:42:01 +0000331 while (1) {
332 // If this load size is bigger than our known alignment or would not fit
333 // into a native integer register, then we fail.
334 if (NewLoadByteSize > LoadAlign ||
Rafael Espindola7c68beb2014-02-18 15:33:12 +0000335 !DL.fitsInLegalInteger(NewLoadByteSize*8))
Chris Lattner827a2702011-04-28 07:29:08 +0000336 return 0;
Chris Lattner7aab2792011-04-26 22:42:01 +0000337
Kostya Serebryany9e0d3772012-02-06 22:48:56 +0000338 if (LIOffs+NewLoadByteSize > MemLocEnd &&
Bill Wendling698e84f2012-12-30 10:32:01 +0000339 LI->getParent()->getParent()->getAttributes().
Kostya Serebryanycf880b92013-02-26 06:58:09 +0000340 hasAttribute(AttributeSet::FunctionIndex, Attribute::SanitizeAddress))
Kostya Serebryany9e0d3772012-02-06 22:48:56 +0000341 // We will be reading past the location accessed by the original program.
342 // While this is safe in a regular build, Address Safety analysis tools
343 // may start reporting false warnings. So, don't do widening.
344 return 0;
Kostya Serebryany9e0d3772012-02-06 22:48:56 +0000345
Chris Lattner7aab2792011-04-26 22:42:01 +0000346 // If a load of this width would include all of MemLoc, then we succeed.
347 if (LIOffs+NewLoadByteSize >= MemLocEnd)
Chris Lattner827a2702011-04-28 07:29:08 +0000348 return NewLoadByteSize;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000349
Chris Lattner7aab2792011-04-26 22:42:01 +0000350 NewLoadByteSize <<= 1;
351 }
Chris Lattner7aab2792011-04-26 22:42:01 +0000352}
353
Chris Lattner5a786042008-12-07 01:50:16 +0000354/// getPointerDependencyFrom - Return the instruction on which a memory
Dan Gohman15a43962010-10-29 01:14:04 +0000355/// location depends. If isLoad is true, this routine ignores may-aliases with
356/// read-only operations. If isLoad is false, this routine ignores may-aliases
Shuxin Yang408bdad2013-03-06 17:48:48 +0000357/// with reads from read-only locations. If possible, pass the query
358/// instruction as well; this function may take advantage of the metadata
359/// annotated to the query instruction to refine the result.
Chris Lattner47e81d02008-11-30 23:17:19 +0000360MemDepResult MemoryDependenceAnalysis::
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000361getPointerDependencyFrom(const AliasAnalysis::Location &MemLoc, bool isLoad,
Shuxin Yang408bdad2013-03-06 17:48:48 +0000362 BasicBlock::iterator ScanIt, BasicBlock *BB,
363 Instruction *QueryInst) {
Chris Lattner2faa2c72008-12-07 02:15:47 +0000364
Chris Lattner7aab2792011-04-26 22:42:01 +0000365 const Value *MemLocBase = 0;
366 int64_t MemLocOffset = 0;
Eli Friedman8b098b02011-06-15 23:59:25 +0000367 unsigned Limit = BlockScanLimit;
Shuxin Yang408bdad2013-03-06 17:48:48 +0000368 bool isInvariantLoad = false;
369 if (isLoad && QueryInst) {
370 LoadInst *LI = dyn_cast<LoadInst>(QueryInst);
371 if (LI && LI->getMetadata(LLVMContext::MD_invariant_load) != 0)
372 isInvariantLoad = true;
373 }
Eli Friedman8b098b02011-06-15 23:59:25 +0000374
Chris Lattnera28355d2008-12-07 08:50:20 +0000375 // Walk backwards through the basic block, looking for dependencies.
Chris Lattner51ba8d02008-11-29 03:47:00 +0000376 while (ScanIt != BB->begin()) {
Yunzhong Gao5cbcf562013-11-14 01:10:52 +0000377 Instruction *Inst = --ScanIt;
378
379 if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst))
380 // Debug intrinsics don't (and can't) cause dependencies.
381 if (isa<DbgInfoIntrinsic>(II)) continue;
382
Eli Friedman8b098b02011-06-15 23:59:25 +0000383 // Limit the amount of scanning we do so we don't end up with quadratic
384 // running time on extreme testcases.
385 --Limit;
386 if (!Limit)
387 return MemDepResult::getUnknown();
388
Chris Lattner506b8582009-12-01 21:15:15 +0000389 if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
Owen Anderson2b2bd282009-10-28 07:05:35 +0000390 // If we reach a lifetime begin or end marker, then the query ends here
391 // because the value is undefined.
Chris Lattnera58edd12010-09-06 03:58:04 +0000392 if (II->getIntrinsicID() == Intrinsic::lifetime_start) {
Owen Andersonb9878ee2009-12-02 07:35:19 +0000393 // FIXME: This only considers queries directly on the invariant-tagged
394 // pointer, not on query pointers that are indexed off of them. It'd
Chris Lattner7aab2792011-04-26 22:42:01 +0000395 // be nice to handle that at some point (the right approach is to use
396 // GetPointerBaseWithConstantOffset).
Chris Lattner32dc9bd2011-04-26 21:53:34 +0000397 if (AA->isMustAlias(AliasAnalysis::Location(II->getArgOperand(1)),
398 MemLoc))
Owen Anderson2b2bd282009-10-28 07:05:35 +0000399 return MemDepResult::getDef(II);
Chris Lattnera58edd12010-09-06 03:58:04 +0000400 continue;
Owen Andersond0e86d52009-10-28 06:18:42 +0000401 }
402 }
403
Chris Lattnerff862c42008-11-30 01:44:00 +0000404 // Values depend on loads if the pointers are must aliased. This means that
405 // a load depends on another must aliased load from the same value.
Chris Lattner0e3d6332008-12-05 21:04:20 +0000406 if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
Eli Friedman5494ada2011-08-15 20:54:19 +0000407 // Atomic loads have complications involved.
408 // FIXME: This is overly conservative.
409 if (!LI->isUnordered())
410 return MemDepResult::getClobber(LI);
411
Dan Gohman65316d62010-11-11 21:50:19 +0000412 AliasAnalysis::Location LoadLoc = AA->getLocation(LI);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000413
Chris Lattner0e3d6332008-12-05 21:04:20 +0000414 // If we found a pointer, check if it could be the same as our pointer.
Dan Gohman15a43962010-10-29 01:14:04 +0000415 AliasAnalysis::AliasResult R = AA->alias(LoadLoc, MemLoc);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000416
Chris Lattner6f83d062011-04-26 01:21:15 +0000417 if (isLoad) {
Chris Lattner7aab2792011-04-26 22:42:01 +0000418 if (R == AliasAnalysis::NoAlias) {
419 // If this is an over-aligned integer load (for example,
420 // "load i8* %P, align 4") see if it would obviously overlap with the
421 // queried location if widened to a larger load (e.g. if the queried
422 // location is 1 byte at P+1). If so, return it as a load/load
423 // clobber result, allowing the client to decide to widen the load if
424 // it wants to.
Chris Lattner229907c2011-07-18 04:54:35 +0000425 if (IntegerType *ITy = dyn_cast<IntegerType>(LI->getType()))
Chris Lattner7aab2792011-04-26 22:42:01 +0000426 if (LI->getAlignment()*8 > ITy->getPrimitiveSizeInBits() &&
427 isLoadLoadClobberIfExtendedToFullWidth(MemLoc, MemLocBase,
Rafael Espindola7c68beb2014-02-18 15:33:12 +0000428 MemLocOffset, LI, DL))
Chris Lattner7aab2792011-04-26 22:42:01 +0000429 return MemDepResult::getClobber(Inst);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000430
Chris Lattner7aab2792011-04-26 22:42:01 +0000431 continue;
432 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000433
Chris Lattner6f83d062011-04-26 01:21:15 +0000434 // Must aliased loads are defs of each other.
435 if (R == AliasAnalysis::MustAlias)
436 return MemDepResult::getDef(Inst);
437
Dan Gohmana4717512011-06-04 06:48:50 +0000438#if 0 // FIXME: Temporarily disabled. GVN is cleverly rewriting loads
439 // in terms of clobbering loads, but since it does this by looking
440 // at the clobbering load directly, it doesn't know about any
441 // phi translation that may have happened along the way.
442
Chris Lattner6f83d062011-04-26 01:21:15 +0000443 // If we have a partial alias, then return this as a clobber for the
444 // client to handle.
445 if (R == AliasAnalysis::PartialAlias)
446 return MemDepResult::getClobber(Inst);
Dan Gohmana4717512011-06-04 06:48:50 +0000447#endif
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000448
Chris Lattner6f83d062011-04-26 01:21:15 +0000449 // Random may-alias loads don't depend on each other without a
450 // dependence.
Chris Lattner80c08182008-11-29 09:09:48 +0000451 continue;
Chris Lattner6f83d062011-04-26 01:21:15 +0000452 }
Dan Gohman15a43962010-10-29 01:14:04 +0000453
Chris Lattner7aab2792011-04-26 22:42:01 +0000454 // Stores don't depend on other no-aliased accesses.
455 if (R == AliasAnalysis::NoAlias)
456 continue;
457
Dan Gohman15a43962010-10-29 01:14:04 +0000458 // Stores don't alias loads from read-only memory.
Chris Lattner6f83d062011-04-26 01:21:15 +0000459 if (AA->pointsToConstantMemory(LoadLoc))
Dan Gohman15a43962010-10-29 01:14:04 +0000460 continue;
461
Chris Lattner6f83d062011-04-26 01:21:15 +0000462 // Stores depend on may/must aliased loads.
Chris Lattner0e3d6332008-12-05 21:04:20 +0000463 return MemDepResult::getDef(Inst);
464 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000465
Chris Lattner0e3d6332008-12-05 21:04:20 +0000466 if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
Eli Friedman5494ada2011-08-15 20:54:19 +0000467 // Atomic stores have complications involved.
468 // FIXME: This is overly conservative.
469 if (!SI->isUnordered())
470 return MemDepResult::getClobber(SI);
471
Chris Lattner02274a72009-05-25 21:28:56 +0000472 // If alias analysis can tell that this store is guaranteed to not modify
473 // the query pointer, ignore it. Use getModRefInfo to handle cases where
474 // the query pointer points to constant memory etc.
Dan Gohman23483932010-09-22 21:41:02 +0000475 if (AA->getModRefInfo(SI, MemLoc) == AliasAnalysis::NoModRef)
Chris Lattner02274a72009-05-25 21:28:56 +0000476 continue;
477
478 // Ok, this store might clobber the query pointer. Check to see if it is
479 // a must alias: in this case, we want to return this as a def.
Dan Gohman65316d62010-11-11 21:50:19 +0000480 AliasAnalysis::Location StoreLoc = AA->getLocation(SI);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000481
Chris Lattner0e3d6332008-12-05 21:04:20 +0000482 // If we found a pointer, check if it could be the same as our pointer.
Dan Gohman65316d62010-11-11 21:50:19 +0000483 AliasAnalysis::AliasResult R = AA->alias(StoreLoc, MemLoc);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000484
Chris Lattner0e3d6332008-12-05 21:04:20 +0000485 if (R == AliasAnalysis::NoAlias)
486 continue;
Dan Gohmanba5d0ab2010-12-13 22:47:57 +0000487 if (R == AliasAnalysis::MustAlias)
488 return MemDepResult::getDef(Inst);
Shuxin Yang408bdad2013-03-06 17:48:48 +0000489 if (isInvariantLoad)
490 continue;
Dan Gohmanba5d0ab2010-12-13 22:47:57 +0000491 return MemDepResult::getClobber(Inst);
Owen Andersonc0daf5f2007-07-06 23:14:35 +0000492 }
Chris Lattner3ff6d012008-11-30 01:39:32 +0000493
494 // If this is an allocation, and if we know that the accessed pointer is to
Chris Lattner0e3d6332008-12-05 21:04:20 +0000495 // the allocation, return Def. This means that there is no dependence and
Chris Lattner3ff6d012008-11-30 01:39:32 +0000496 // the access can be optimized based on that. For example, a load could
497 // turn into undef.
Victor Hernandez70e85052009-10-13 01:42:53 +0000498 // Note: Only determine this to be a malloc if Inst is the malloc call, not
499 // a subsequent bitcast of the malloc call result. There can be stores to
500 // the malloced memory between the malloc call and its bitcast uses, and we
501 // need to continue scanning until the malloc call.
Bob Wilsondcc54de2012-09-03 05:15:15 +0000502 const TargetLibraryInfo *TLI = AA->getTargetLibraryInfo();
503 if (isa<AllocaInst>(Inst) || isNoAliasFn(Inst, TLI)) {
Rafael Espindola7c68beb2014-02-18 15:33:12 +0000504 const Value *AccessPtr = GetUnderlyingObject(MemLoc.Ptr, DL);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000505
Chris Lattner32dc9bd2011-04-26 21:53:34 +0000506 if (AccessPtr == Inst || AA->isMustAlias(Inst, AccessPtr))
Victor Hernandez537d8d92009-09-18 21:34:51 +0000507 return MemDepResult::getDef(Inst);
Bob Wilson01cfbfe2012-09-04 03:30:13 +0000508 // Be conservative if the accessed pointer may alias the allocation.
509 if (AA->alias(Inst, AccessPtr) != AliasAnalysis::NoAlias)
510 return MemDepResult::getClobber(Inst);
Bob Wilsondcc54de2012-09-03 05:15:15 +0000511 // If the allocation is not aliased and does not read memory (like
512 // strdup), it is safe to ignore.
513 if (isa<AllocaInst>(Inst) ||
514 isMallocLikeFn(Inst, TLI) || isCallocLikeFn(Inst, TLI))
515 continue;
Victor Hernandez537d8d92009-09-18 21:34:51 +0000516 }
517
Chris Lattner0e3d6332008-12-05 21:04:20 +0000518 // See if this instruction (e.g. a call or vaarg) mod/ref's the pointer.
Chad Rosiera968caf2012-05-14 20:35:04 +0000519 AliasAnalysis::ModRefResult MR = AA->getModRefInfo(Inst, MemLoc);
520 // If necessary, perform additional analysis.
521 if (MR == AliasAnalysis::ModRef)
522 MR = AA->callCapturesBefore(Inst, MemLoc, DT);
523 switch (MR) {
Chris Lattner41efb682008-12-09 19:47:40 +0000524 case AliasAnalysis::NoModRef:
525 // If the call has no effect on the queried pointer, just ignore it.
Chris Lattner81f19e92008-11-29 08:51:16 +0000526 continue;
Owen Andersonfc16e5a2009-10-28 06:30:52 +0000527 case AliasAnalysis::Mod:
Owen Andersonfc16e5a2009-10-28 06:30:52 +0000528 return MemDepResult::getClobber(Inst);
Chris Lattner41efb682008-12-09 19:47:40 +0000529 case AliasAnalysis::Ref:
530 // If the call is known to never store to the pointer, and if this is a
531 // load query, we can safely ignore it (scan past it).
532 if (isLoad)
533 continue;
Chris Lattner41efb682008-12-09 19:47:40 +0000534 default:
535 // Otherwise, there is a potential dependence. Return a clobber.
536 return MemDepResult::getClobber(Inst);
537 }
Owen Andersonc0daf5f2007-07-06 23:14:35 +0000538 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000539
Eli Friedman7d58bc72011-06-15 00:47:34 +0000540 // No dependence found. If this is the entry block of the function, it is
541 // unknown, otherwise it is non-local.
Chris Lattner2faa2c72008-12-07 02:15:47 +0000542 if (BB != &BB->getParent()->getEntryBlock())
543 return MemDepResult::getNonLocal();
Eli Friedmanc1702c82011-10-13 22:14:57 +0000544 return MemDepResult::getNonFuncLocal();
Owen Andersonc0daf5f2007-07-06 23:14:35 +0000545}
546
Chris Lattner51ba8d02008-11-29 03:47:00 +0000547/// getDependency - Return the instruction on which a memory operation
548/// depends.
549MemDepResult MemoryDependenceAnalysis::getDependency(Instruction *QueryInst) {
550 Instruction *ScanPos = QueryInst;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000551
Chris Lattner51ba8d02008-11-29 03:47:00 +0000552 // Check for a cached result
Chris Lattner47e81d02008-11-30 23:17:19 +0000553 MemDepResult &LocalCache = LocalDeps[QueryInst];
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000554
Chris Lattnere7d7e132008-11-29 22:02:15 +0000555 // If the cached entry is non-dirty, just return it. Note that this depends
Chris Lattner47e81d02008-11-30 23:17:19 +0000556 // on MemDepResult's default constructing to 'dirty'.
557 if (!LocalCache.isDirty())
558 return LocalCache;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000559
Chris Lattner51ba8d02008-11-29 03:47:00 +0000560 // Otherwise, if we have a dirty entry, we know we can start the scan at that
561 // instruction, which may save us some work.
Chris Lattner47e81d02008-11-30 23:17:19 +0000562 if (Instruction *Inst = LocalCache.getInst()) {
Chris Lattner51ba8d02008-11-29 03:47:00 +0000563 ScanPos = Inst;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000564
Chris Lattnerde4440c2008-12-07 18:39:13 +0000565 RemoveFromReverseMap(ReverseLocalDeps, Inst, QueryInst);
Chris Lattner44104272008-11-30 02:52:26 +0000566 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000567
Chris Lattner5a786042008-12-07 01:50:16 +0000568 BasicBlock *QueryParent = QueryInst->getParent();
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000569
Chris Lattner51ba8d02008-11-29 03:47:00 +0000570 // Do the scan.
Chris Lattner5a786042008-12-07 01:50:16 +0000571 if (BasicBlock::iterator(QueryInst) == QueryParent->begin()) {
Eli Friedman7d58bc72011-06-15 00:47:34 +0000572 // No dependence found. If this is the entry block of the function, it is
573 // unknown, otherwise it is non-local.
Chris Lattner2faa2c72008-12-07 02:15:47 +0000574 if (QueryParent != &QueryParent->getParent()->getEntryBlock())
575 LocalCache = MemDepResult::getNonLocal();
576 else
Eli Friedmanc1702c82011-10-13 22:14:57 +0000577 LocalCache = MemDepResult::getNonFuncLocal();
Dan Gohman1d760ce2010-11-10 21:51:35 +0000578 } else {
579 AliasAnalysis::Location MemLoc;
580 AliasAnalysis::ModRefResult MR = GetLocation(QueryInst, MemLoc, AA);
581 if (MemLoc.Ptr) {
582 // If we can do a pointer scan, make it happen.
583 bool isLoad = !(MR & AliasAnalysis::Mod);
Chris Lattnerd540a5d2010-11-30 01:56:13 +0000584 if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(QueryInst))
Owen Anderson97f0cf32011-05-17 00:05:49 +0000585 isLoad |= II->getIntrinsicID() == Intrinsic::lifetime_start;
Chris Lattnere48c31c2010-11-21 07:34:32 +0000586
Dan Gohman1d760ce2010-11-10 21:51:35 +0000587 LocalCache = getPointerDependencyFrom(MemLoc, isLoad, ScanPos,
Shuxin Yang408bdad2013-03-06 17:48:48 +0000588 QueryParent, QueryInst);
Dan Gohman1d760ce2010-11-10 21:51:35 +0000589 } else if (isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)) {
Gabor Greifef1ca242010-07-27 22:02:00 +0000590 CallSite QueryCS(QueryInst);
Nick Lewyckye91765f2009-12-05 06:37:24 +0000591 bool isReadOnly = AA->onlyReadsMemory(QueryCS);
592 LocalCache = getCallSiteDependencyFrom(QueryCS, isReadOnly, ScanPos,
593 QueryParent);
Dan Gohman1d760ce2010-11-10 21:51:35 +0000594 } else
595 // Non-memory instruction.
Eli Friedman7d58bc72011-06-15 00:47:34 +0000596 LocalCache = MemDepResult::getUnknown();
Nick Lewycky218a3392009-11-28 21:27:49 +0000597 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000598
Chris Lattner51ba8d02008-11-29 03:47:00 +0000599 // Remember the result!
Chris Lattner47e81d02008-11-30 23:17:19 +0000600 if (Instruction *I = LocalCache.getInst())
Chris Lattner9f1988ab2008-11-29 09:20:15 +0000601 ReverseLocalDeps[I].insert(QueryInst);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000602
Chris Lattner47e81d02008-11-30 23:17:19 +0000603 return LocalCache;
Chris Lattner51ba8d02008-11-29 03:47:00 +0000604}
605
Chris Lattnerf09619d2009-01-22 07:04:01 +0000606#ifndef NDEBUG
607/// AssertSorted - This method is used when -debug is specified to verify that
608/// cache arrays are properly kept sorted.
609static void AssertSorted(MemoryDependenceAnalysis::NonLocalDepInfo &Cache,
610 int Count = -1) {
611 if (Count == -1) Count = Cache.size();
612 if (Count == 0) return;
613
614 for (unsigned i = 1; i != unsigned(Count); ++i)
Chris Lattner0c315472009-12-09 07:08:01 +0000615 assert(!(Cache[i] < Cache[i-1]) && "Cache isn't sorted!");
Chris Lattnerf09619d2009-01-22 07:04:01 +0000616}
617#endif
618
Chris Lattner254314e2008-12-09 19:38:05 +0000619/// getNonLocalCallDependency - Perform a full dependency query for the
620/// specified call, returning the set of blocks that the value is
Chris Lattner20597532008-11-30 01:18:27 +0000621/// potentially live across. The returned set of results will include a
622/// "NonLocal" result for all blocks where the value is live across.
623///
Chris Lattner254314e2008-12-09 19:38:05 +0000624/// This method assumes the instruction returns a "NonLocal" dependency
Chris Lattner20597532008-11-30 01:18:27 +0000625/// within its own block.
626///
Chris Lattner254314e2008-12-09 19:38:05 +0000627/// This returns a reference to an internal data structure that may be
628/// invalidated on the next non-local query or when an instruction is
629/// removed. Clients must copy this data if they want it around longer than
630/// that.
Chris Lattner7e61daf2008-12-01 01:15:42 +0000631const MemoryDependenceAnalysis::NonLocalDepInfo &
Chris Lattner254314e2008-12-09 19:38:05 +0000632MemoryDependenceAnalysis::getNonLocalCallDependency(CallSite QueryCS) {
633 assert(getDependency(QueryCS.getInstruction()).isNonLocal() &&
634 "getNonLocalCallDependency should only be used on calls with non-local deps!");
635 PerInstNLInfo &CacheP = NonLocalDeps[QueryCS.getInstruction()];
Chris Lattner7e61daf2008-12-01 01:15:42 +0000636 NonLocalDepInfo &Cache = CacheP.first;
Chris Lattner20597532008-11-30 01:18:27 +0000637
638 /// DirtyBlocks - This is the set of blocks that need to be recomputed. In
639 /// the cached case, this can happen due to instructions being deleted etc. In
640 /// the uncached case, this starts out as the set of predecessors we care
641 /// about.
642 SmallVector<BasicBlock*, 32> DirtyBlocks;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000643
Chris Lattner20597532008-11-30 01:18:27 +0000644 if (!Cache.empty()) {
Chris Lattner7e61daf2008-12-01 01:15:42 +0000645 // Okay, we have a cache entry. If we know it is not dirty, just return it
646 // with no computation.
647 if (!CacheP.second) {
Dan Gohmand2d1ae12010-06-22 15:08:57 +0000648 ++NumCacheNonLocal;
Chris Lattner7e61daf2008-12-01 01:15:42 +0000649 return Cache;
650 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000651
Chris Lattner20597532008-11-30 01:18:27 +0000652 // If we already have a partially computed set of results, scan them to
Chris Lattner7e61daf2008-12-01 01:15:42 +0000653 // determine what is dirty, seeding our initial DirtyBlocks worklist.
654 for (NonLocalDepInfo::iterator I = Cache.begin(), E = Cache.end();
655 I != E; ++I)
Chris Lattner0c315472009-12-09 07:08:01 +0000656 if (I->getResult().isDirty())
657 DirtyBlocks.push_back(I->getBB());
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000658
Chris Lattner7e61daf2008-12-01 01:15:42 +0000659 // Sort the cache so that we can do fast binary search lookups below.
660 std::sort(Cache.begin(), Cache.end());
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000661
Chris Lattner7e61daf2008-12-01 01:15:42 +0000662 ++NumCacheDirtyNonLocal;
Chris Lattner20597532008-11-30 01:18:27 +0000663 //cerr << "CACHED CASE: " << DirtyBlocks.size() << " dirty: "
664 // << Cache.size() << " cached: " << *QueryInst;
665 } else {
666 // Seed DirtyBlocks with each of the preds of QueryInst's block.
Chris Lattner254314e2008-12-09 19:38:05 +0000667 BasicBlock *QueryBB = QueryCS.getInstruction()->getParent();
Chris Lattnere8113a72008-12-09 06:44:17 +0000668 for (BasicBlock **PI = PredCache->GetPreds(QueryBB); *PI; ++PI)
669 DirtyBlocks.push_back(*PI);
Dan Gohmand2d1ae12010-06-22 15:08:57 +0000670 ++NumUncacheNonLocal;
Chris Lattner20597532008-11-30 01:18:27 +0000671 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000672
Chris Lattner702e46e2008-12-09 21:19:42 +0000673 // isReadonlyCall - If this is a read-only call, we can be more aggressive.
674 bool isReadonlyCall = AA->onlyReadsMemory(QueryCS);
Chris Lattnerff9f3db2008-12-15 03:35:32 +0000675
Chris Lattner7e61daf2008-12-01 01:15:42 +0000676 SmallPtrSet<BasicBlock*, 64> Visited;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000677
Chris Lattner7e61daf2008-12-01 01:15:42 +0000678 unsigned NumSortedEntries = Cache.size();
Chris Lattnerf09619d2009-01-22 07:04:01 +0000679 DEBUG(AssertSorted(Cache));
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000680
Chris Lattner20597532008-11-30 01:18:27 +0000681 // Iterate while we still have blocks to update.
682 while (!DirtyBlocks.empty()) {
683 BasicBlock *DirtyBB = DirtyBlocks.back();
684 DirtyBlocks.pop_back();
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000685
Chris Lattner7e61daf2008-12-01 01:15:42 +0000686 // Already processed this block?
687 if (!Visited.insert(DirtyBB))
688 continue;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000689
Chris Lattner7e61daf2008-12-01 01:15:42 +0000690 // Do a binary search to see if we already have an entry for this block in
691 // the cache set. If so, find it.
Chris Lattnerf09619d2009-01-22 07:04:01 +0000692 DEBUG(AssertSorted(Cache, NumSortedEntries));
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000693 NonLocalDepInfo::iterator Entry =
Chris Lattner7e61daf2008-12-01 01:15:42 +0000694 std::upper_bound(Cache.begin(), Cache.begin()+NumSortedEntries,
Chris Lattnereea0f582009-12-09 07:31:04 +0000695 NonLocalDepEntry(DirtyBB));
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000696 if (Entry != Cache.begin() && std::prev(Entry)->getBB() == DirtyBB)
Chris Lattner7e61daf2008-12-01 01:15:42 +0000697 --Entry;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000698
Chris Lattner0c315472009-12-09 07:08:01 +0000699 NonLocalDepEntry *ExistingResult = 0;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000700 if (Entry != Cache.begin()+NumSortedEntries &&
Chris Lattner0c315472009-12-09 07:08:01 +0000701 Entry->getBB() == DirtyBB) {
Chris Lattner7e61daf2008-12-01 01:15:42 +0000702 // If we already have an entry, and if it isn't already dirty, the block
703 // is done.
Chris Lattner0c315472009-12-09 07:08:01 +0000704 if (!Entry->getResult().isDirty())
Chris Lattner7e61daf2008-12-01 01:15:42 +0000705 continue;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000706
Chris Lattner7e61daf2008-12-01 01:15:42 +0000707 // Otherwise, remember this slot so we can update the value.
Chris Lattner0c315472009-12-09 07:08:01 +0000708 ExistingResult = &*Entry;
Chris Lattner7e61daf2008-12-01 01:15:42 +0000709 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000710
Chris Lattner20597532008-11-30 01:18:27 +0000711 // If the dirty entry has a pointer, start scanning from it so we don't have
712 // to rescan the entire block.
713 BasicBlock::iterator ScanPos = DirtyBB->end();
Chris Lattner7e61daf2008-12-01 01:15:42 +0000714 if (ExistingResult) {
Chris Lattner0c315472009-12-09 07:08:01 +0000715 if (Instruction *Inst = ExistingResult->getResult().getInst()) {
Chris Lattner7e61daf2008-12-01 01:15:42 +0000716 ScanPos = Inst;
Chris Lattner7e61daf2008-12-01 01:15:42 +0000717 // We're removing QueryInst's use of Inst.
Chris Lattner254314e2008-12-09 19:38:05 +0000718 RemoveFromReverseMap(ReverseNonLocalDeps, Inst,
719 QueryCS.getInstruction());
Chris Lattner7e61daf2008-12-01 01:15:42 +0000720 }
Chris Lattner1b810bd2008-11-30 02:28:25 +0000721 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000722
Chris Lattner60444f82008-11-30 01:26:32 +0000723 // Find out if this block has a local dependency for QueryInst.
Chris Lattnered494f72008-12-07 01:21:14 +0000724 MemDepResult Dep;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000725
Chris Lattner254314e2008-12-09 19:38:05 +0000726 if (ScanPos != DirtyBB->begin()) {
Chris Lattner702e46e2008-12-09 21:19:42 +0000727 Dep = getCallSiteDependencyFrom(QueryCS, isReadonlyCall,ScanPos, DirtyBB);
Chris Lattner254314e2008-12-09 19:38:05 +0000728 } else if (DirtyBB != &DirtyBB->getParent()->getEntryBlock()) {
729 // No dependence found. If this is the entry block of the function, it is
Eli Friedman7d58bc72011-06-15 00:47:34 +0000730 // a clobber, otherwise it is unknown.
Chris Lattner254314e2008-12-09 19:38:05 +0000731 Dep = MemDepResult::getNonLocal();
Chris Lattner5a786042008-12-07 01:50:16 +0000732 } else {
Eli Friedmanc1702c82011-10-13 22:14:57 +0000733 Dep = MemDepResult::getNonFuncLocal();
Chris Lattner5a786042008-12-07 01:50:16 +0000734 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000735
Chris Lattner7e61daf2008-12-01 01:15:42 +0000736 // If we had a dirty entry for the block, update it. Otherwise, just add
737 // a new entry.
738 if (ExistingResult)
Chris Lattner9b7d99e2009-12-22 04:25:02 +0000739 ExistingResult->setResult(Dep);
Chris Lattner7e61daf2008-12-01 01:15:42 +0000740 else
Chris Lattner9b7d99e2009-12-22 04:25:02 +0000741 Cache.push_back(NonLocalDepEntry(DirtyBB, Dep));
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000742
Chris Lattner20597532008-11-30 01:18:27 +0000743 // If the block has a dependency (i.e. it isn't completely transparent to
Chris Lattner7e61daf2008-12-01 01:15:42 +0000744 // the value), remember the association!
745 if (!Dep.isNonLocal()) {
Chris Lattner20597532008-11-30 01:18:27 +0000746 // Keep the ReverseNonLocalDeps map up to date so we can efficiently
747 // update this when we remove instructions.
Chris Lattner7e61daf2008-12-01 01:15:42 +0000748 if (Instruction *Inst = Dep.getInst())
Chris Lattner254314e2008-12-09 19:38:05 +0000749 ReverseNonLocalDeps[Inst].insert(QueryCS.getInstruction());
Chris Lattner7e61daf2008-12-01 01:15:42 +0000750 } else {
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000751
Chris Lattner7e61daf2008-12-01 01:15:42 +0000752 // If the block *is* completely transparent to the load, we need to check
753 // the predecessors of this block. Add them to our worklist.
Chris Lattnere8113a72008-12-09 06:44:17 +0000754 for (BasicBlock **PI = PredCache->GetPreds(DirtyBB); *PI; ++PI)
755 DirtyBlocks.push_back(*PI);
Chris Lattner7e61daf2008-12-01 01:15:42 +0000756 }
Chris Lattner20597532008-11-30 01:18:27 +0000757 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000758
Chris Lattner7e61daf2008-12-01 01:15:42 +0000759 return Cache;
Chris Lattner20597532008-11-30 01:18:27 +0000760}
761
Chris Lattner2faa2c72008-12-07 02:15:47 +0000762/// getNonLocalPointerDependency - Perform a full dependency query for an
763/// access to the specified (non-volatile) memory location, returning the
764/// set of instructions that either define or clobber the value.
765///
766/// This method assumes the pointer has a "NonLocal" dependency within its
767/// own block.
768///
769void MemoryDependenceAnalysis::
Dan Gohman23483932010-09-22 21:41:02 +0000770getNonLocalPointerDependency(const AliasAnalysis::Location &Loc, bool isLoad,
771 BasicBlock *FromBB,
Chris Lattner9b7d99e2009-12-22 04:25:02 +0000772 SmallVectorImpl<NonLocalDepResult> &Result) {
Dan Gohman23483932010-09-22 21:41:02 +0000773 assert(Loc.Ptr->getType()->isPointerTy() &&
Chris Lattnerfdb88432008-12-07 18:45:15 +0000774 "Can't get pointer deps of a non-pointer!");
Chris Lattner7564a3b2008-12-07 02:56:57 +0000775 Result.clear();
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000776
Rafael Espindola7c68beb2014-02-18 15:33:12 +0000777 PHITransAddr Address(const_cast<Value *>(Loc.Ptr), DL);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000778
Chris Lattnerff9f3db2008-12-15 03:35:32 +0000779 // This is the set of blocks we've inspected, and the pointer we consider in
780 // each block. Because of critical edges, we currently bail out if querying
781 // a block with multiple different pointers. This can happen during PHI
782 // translation.
783 DenseMap<BasicBlock*, Value*> Visited;
Dan Gohman23483932010-09-22 21:41:02 +0000784 if (!getNonLocalPointerDepFromBB(Address, Loc, isLoad, FromBB,
Chris Lattnerff9f3db2008-12-15 03:35:32 +0000785 Result, Visited, true))
786 return;
Chris Lattner7ed5ccc2008-12-15 04:58:29 +0000787 Result.clear();
Chris Lattner9b7d99e2009-12-22 04:25:02 +0000788 Result.push_back(NonLocalDepResult(FromBB,
Eli Friedman7d58bc72011-06-15 00:47:34 +0000789 MemDepResult::getUnknown(),
Dan Gohman23483932010-09-22 21:41:02 +0000790 const_cast<Value *>(Loc.Ptr)));
Chris Lattner7564a3b2008-12-07 02:56:57 +0000791}
792
Chris Lattnerf903fe12008-12-09 07:47:11 +0000793/// GetNonLocalInfoForBlock - Compute the memdep value for BB with
794/// Pointer/PointeeSize using either cached information in Cache or by doing a
795/// lookup (which may use dirty cache info if available). If we do a lookup,
796/// add the result to the cache.
797MemDepResult MemoryDependenceAnalysis::
Dan Gohman23483932010-09-22 21:41:02 +0000798GetNonLocalInfoForBlock(const AliasAnalysis::Location &Loc,
Chris Lattnerf903fe12008-12-09 07:47:11 +0000799 bool isLoad, BasicBlock *BB,
800 NonLocalDepInfo *Cache, unsigned NumSortedEntries) {
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000801
Chris Lattnerf903fe12008-12-09 07:47:11 +0000802 // Do a binary search to see if we already have an entry for this block in
803 // the cache set. If so, find it.
804 NonLocalDepInfo::iterator Entry =
805 std::upper_bound(Cache->begin(), Cache->begin()+NumSortedEntries,
Chris Lattnereea0f582009-12-09 07:31:04 +0000806 NonLocalDepEntry(BB));
Chris Lattner0c315472009-12-09 07:08:01 +0000807 if (Entry != Cache->begin() && (Entry-1)->getBB() == BB)
Chris Lattnerf903fe12008-12-09 07:47:11 +0000808 --Entry;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000809
Chris Lattner0c315472009-12-09 07:08:01 +0000810 NonLocalDepEntry *ExistingResult = 0;
811 if (Entry != Cache->begin()+NumSortedEntries && Entry->getBB() == BB)
812 ExistingResult = &*Entry;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000813
Chris Lattnerf903fe12008-12-09 07:47:11 +0000814 // If we have a cached entry, and it is non-dirty, use it as the value for
815 // this dependency.
Chris Lattner0c315472009-12-09 07:08:01 +0000816 if (ExistingResult && !ExistingResult->getResult().isDirty()) {
Chris Lattnerf903fe12008-12-09 07:47:11 +0000817 ++NumCacheNonLocalPtr;
Chris Lattner0c315472009-12-09 07:08:01 +0000818 return ExistingResult->getResult();
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000819 }
820
Chris Lattnerf903fe12008-12-09 07:47:11 +0000821 // Otherwise, we have to scan for the value. If we have a dirty cache
822 // entry, start scanning from its position, otherwise we scan from the end
823 // of the block.
824 BasicBlock::iterator ScanPos = BB->end();
Chris Lattner0c315472009-12-09 07:08:01 +0000825 if (ExistingResult && ExistingResult->getResult().getInst()) {
826 assert(ExistingResult->getResult().getInst()->getParent() == BB &&
Chris Lattnerf903fe12008-12-09 07:47:11 +0000827 "Instruction invalidated?");
828 ++NumCacheDirtyNonLocalPtr;
Chris Lattner0c315472009-12-09 07:08:01 +0000829 ScanPos = ExistingResult->getResult().getInst();
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000830
Chris Lattnerf903fe12008-12-09 07:47:11 +0000831 // Eliminating the dirty entry from 'Cache', so update the reverse info.
Dan Gohman23483932010-09-22 21:41:02 +0000832 ValueIsLoadPair CacheKey(Loc.Ptr, isLoad);
Chris Lattner8eda11b2009-03-29 00:24:04 +0000833 RemoveFromReverseMap(ReverseNonLocalPtrDeps, ScanPos, CacheKey);
Chris Lattnerf903fe12008-12-09 07:47:11 +0000834 } else {
835 ++NumUncacheNonLocalPtr;
836 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000837
Chris Lattnerf903fe12008-12-09 07:47:11 +0000838 // Scan the block for the dependency.
Dan Gohman23483932010-09-22 21:41:02 +0000839 MemDepResult Dep = getPointerDependencyFrom(Loc, isLoad, ScanPos, BB);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000840
Chris Lattnerf903fe12008-12-09 07:47:11 +0000841 // If we had a dirty entry for the block, update it. Otherwise, just add
842 // a new entry.
843 if (ExistingResult)
Chris Lattner9b7d99e2009-12-22 04:25:02 +0000844 ExistingResult->setResult(Dep);
Chris Lattnerf903fe12008-12-09 07:47:11 +0000845 else
Chris Lattner9b7d99e2009-12-22 04:25:02 +0000846 Cache->push_back(NonLocalDepEntry(BB, Dep));
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000847
Chris Lattnerf903fe12008-12-09 07:47:11 +0000848 // If the block has a dependency (i.e. it isn't completely transparent to
849 // the value), remember the reverse association because we just added it
850 // to Cache!
Eli Friedmanc1702c82011-10-13 22:14:57 +0000851 if (!Dep.isDef() && !Dep.isClobber())
Chris Lattnerf903fe12008-12-09 07:47:11 +0000852 return Dep;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000853
Chris Lattnerf903fe12008-12-09 07:47:11 +0000854 // Keep the ReverseNonLocalPtrDeps map up to date so we can efficiently
855 // update MemDep when we remove instructions.
856 Instruction *Inst = Dep.getInst();
857 assert(Inst && "Didn't depend on anything?");
Dan Gohman23483932010-09-22 21:41:02 +0000858 ValueIsLoadPair CacheKey(Loc.Ptr, isLoad);
Chris Lattner8eda11b2009-03-29 00:24:04 +0000859 ReverseNonLocalPtrDeps[Inst].insert(CacheKey);
Chris Lattnerf903fe12008-12-09 07:47:11 +0000860 return Dep;
861}
862
Chris Lattner370aada2009-07-13 17:20:05 +0000863/// SortNonLocalDepInfoCache - Sort the a NonLocalDepInfo cache, given a certain
864/// number of elements in the array that are already properly ordered. This is
865/// optimized for the case when only a few entries are added.
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000866static void
Chris Lattner370aada2009-07-13 17:20:05 +0000867SortNonLocalDepInfoCache(MemoryDependenceAnalysis::NonLocalDepInfo &Cache,
868 unsigned NumSortedEntries) {
869 switch (Cache.size() - NumSortedEntries) {
870 case 0:
871 // done, no new entries.
872 break;
873 case 2: {
874 // Two new entries, insert the last one into place.
Chris Lattner0c315472009-12-09 07:08:01 +0000875 NonLocalDepEntry Val = Cache.back();
Chris Lattner370aada2009-07-13 17:20:05 +0000876 Cache.pop_back();
877 MemoryDependenceAnalysis::NonLocalDepInfo::iterator Entry =
878 std::upper_bound(Cache.begin(), Cache.end()-1, Val);
879 Cache.insert(Entry, Val);
880 // FALL THROUGH.
881 }
882 case 1:
883 // One new entry, Just insert the new value at the appropriate position.
884 if (Cache.size() != 1) {
Chris Lattner0c315472009-12-09 07:08:01 +0000885 NonLocalDepEntry Val = Cache.back();
Chris Lattner370aada2009-07-13 17:20:05 +0000886 Cache.pop_back();
887 MemoryDependenceAnalysis::NonLocalDepInfo::iterator Entry =
888 std::upper_bound(Cache.begin(), Cache.end(), Val);
889 Cache.insert(Entry, Val);
890 }
891 break;
892 default:
893 // Added many values, do a full scale sort.
894 std::sort(Cache.begin(), Cache.end());
895 break;
896 }
897}
898
Chris Lattnerff9f3db2008-12-15 03:35:32 +0000899/// getNonLocalPointerDepFromBB - Perform a dependency query based on
900/// pointer/pointeesize starting at the end of StartBB. Add any clobber/def
901/// results to the results vector and keep track of which blocks are visited in
902/// 'Visited'.
903///
904/// This has special behavior for the first block queries (when SkipFirstBlock
905/// is true). In this special case, it ignores the contents of the specified
906/// block and starts returning dependence info for its predecessors.
907///
908/// This function returns false on success, or true to indicate that it could
909/// not compute dependence information for some reason. This should be treated
910/// as a clobber dependence on the first instruction in the predecessor block.
911bool MemoryDependenceAnalysis::
Dan Gohman23483932010-09-22 21:41:02 +0000912getNonLocalPointerDepFromBB(const PHITransAddr &Pointer,
913 const AliasAnalysis::Location &Loc,
Chris Lattnerf903fe12008-12-09 07:47:11 +0000914 bool isLoad, BasicBlock *StartBB,
Chris Lattner9b7d99e2009-12-22 04:25:02 +0000915 SmallVectorImpl<NonLocalDepResult> &Result,
Chris Lattnerff9f3db2008-12-15 03:35:32 +0000916 DenseMap<BasicBlock*, Value*> &Visited,
917 bool SkipFirstBlock) {
Chris Lattnera28355d2008-12-07 08:50:20 +0000918 // Look up the cached info for Pointer.
Chris Lattner972e6d82009-12-09 01:59:31 +0000919 ValueIsLoadPair CacheKey(Pointer.getAddr(), isLoad);
Dan Gohman23483932010-09-22 21:41:02 +0000920
Dan Gohman0a6021a2010-11-10 20:37:15 +0000921 // Set up a temporary NLPI value. If the map doesn't yet have an entry for
922 // CacheKey, this value will be inserted as the associated value. Otherwise,
923 // it'll be ignored, and we'll have to check to see if the cached size and
924 // tbaa tag are consistent with the current query.
925 NonLocalPointerInfo InitialNLPI;
926 InitialNLPI.Size = Loc.Size;
927 InitialNLPI.TBAATag = Loc.TBAATag;
928
929 // Get the NLPI for CacheKey, inserting one into the map if it doesn't
930 // already have one.
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000931 std::pair<CachedNonLocalPointerInfo::iterator, bool> Pair =
Dan Gohman0a6021a2010-11-10 20:37:15 +0000932 NonLocalPointerDeps.insert(std::make_pair(CacheKey, InitialNLPI));
933 NonLocalPointerInfo *CacheInfo = &Pair.first->second;
934
Dan Gohman2e8ca442010-11-10 21:45:11 +0000935 // If we already have a cache entry for this CacheKey, we may need to do some
936 // work to reconcile the cache entry and the current query.
Dan Gohman0a6021a2010-11-10 20:37:15 +0000937 if (!Pair.second) {
Dan Gohman2e8ca442010-11-10 21:45:11 +0000938 if (CacheInfo->Size < Loc.Size) {
939 // The query's Size is greater than the cached one. Throw out the
Benjamin Kramerbde91762012-06-02 10:20:22 +0000940 // cached data and proceed with the query at the greater size.
Dan Gohman2e8ca442010-11-10 21:45:11 +0000941 CacheInfo->Pair = BBSkipFirstBlockPair();
942 CacheInfo->Size = Loc.Size;
Dan Gohman67919362010-11-10 22:35:02 +0000943 for (NonLocalDepInfo::iterator DI = CacheInfo->NonLocalDeps.begin(),
944 DE = CacheInfo->NonLocalDeps.end(); DI != DE; ++DI)
945 if (Instruction *Inst = DI->getResult().getInst())
946 RemoveFromReverseMap(ReverseNonLocalPtrDeps, Inst, CacheKey);
Dan Gohman2e8ca442010-11-10 21:45:11 +0000947 CacheInfo->NonLocalDeps.clear();
948 } else if (CacheInfo->Size > Loc.Size) {
949 // This query's Size is less than the cached one. Conservatively restart
950 // the query using the greater size.
Dan Gohman0a6021a2010-11-10 20:37:15 +0000951 return getNonLocalPointerDepFromBB(Pointer,
952 Loc.getWithNewSize(CacheInfo->Size),
953 isLoad, StartBB, Result, Visited,
954 SkipFirstBlock);
955 }
956
Dan Gohman2e8ca442010-11-10 21:45:11 +0000957 // If the query's TBAATag is inconsistent with the cached one,
958 // conservatively throw out the cached data and restart the query with
959 // no tag if needed.
Dan Gohman0a6021a2010-11-10 20:37:15 +0000960 if (CacheInfo->TBAATag != Loc.TBAATag) {
Dan Gohman2e8ca442010-11-10 21:45:11 +0000961 if (CacheInfo->TBAATag) {
962 CacheInfo->Pair = BBSkipFirstBlockPair();
963 CacheInfo->TBAATag = 0;
Dan Gohman67919362010-11-10 22:35:02 +0000964 for (NonLocalDepInfo::iterator DI = CacheInfo->NonLocalDeps.begin(),
965 DE = CacheInfo->NonLocalDeps.end(); DI != DE; ++DI)
966 if (Instruction *Inst = DI->getResult().getInst())
967 RemoveFromReverseMap(ReverseNonLocalPtrDeps, Inst, CacheKey);
Dan Gohman2e8ca442010-11-10 21:45:11 +0000968 CacheInfo->NonLocalDeps.clear();
969 }
970 if (Loc.TBAATag)
971 return getNonLocalPointerDepFromBB(Pointer, Loc.getWithoutTBAATag(),
972 isLoad, StartBB, Result, Visited,
973 SkipFirstBlock);
Dan Gohman0a6021a2010-11-10 20:37:15 +0000974 }
Dan Gohman23483932010-09-22 21:41:02 +0000975 }
976
977 NonLocalDepInfo *Cache = &CacheInfo->NonLocalDeps;
Chris Lattner5ed409e2008-12-08 07:31:50 +0000978
979 // If we have valid cached information for exactly the block we are
980 // investigating, just return it with no recomputation.
Dan Gohman23483932010-09-22 21:41:02 +0000981 if (CacheInfo->Pair == BBSkipFirstBlockPair(StartBB, SkipFirstBlock)) {
Chris Lattner8b4be372008-12-16 07:10:09 +0000982 // We have a fully cached result for this query then we can just return the
983 // cached results and populate the visited set. However, we have to verify
984 // that we don't already have conflicting results for these blocks. Check
985 // to ensure that if a block in the results set is in the visited set that
986 // it was for the same pointer query.
987 if (!Visited.empty()) {
988 for (NonLocalDepInfo::iterator I = Cache->begin(), E = Cache->end();
989 I != E; ++I) {
Chris Lattner0c315472009-12-09 07:08:01 +0000990 DenseMap<BasicBlock*, Value*>::iterator VI = Visited.find(I->getBB());
Chris Lattner972e6d82009-12-09 01:59:31 +0000991 if (VI == Visited.end() || VI->second == Pointer.getAddr())
992 continue;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +0000993
Chris Lattner8b4be372008-12-16 07:10:09 +0000994 // We have a pointer mismatch in a block. Just return clobber, saying
995 // that something was clobbered in this result. We could also do a
996 // non-fully cached query, but there is little point in doing this.
997 return true;
998 }
999 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001000
Chris Lattner9b7d99e2009-12-22 04:25:02 +00001001 Value *Addr = Pointer.getAddr();
Chris Lattner5ed409e2008-12-08 07:31:50 +00001002 for (NonLocalDepInfo::iterator I = Cache->begin(), E = Cache->end();
Chris Lattner8b4be372008-12-16 07:10:09 +00001003 I != E; ++I) {
Chris Lattner9b7d99e2009-12-22 04:25:02 +00001004 Visited.insert(std::make_pair(I->getBB(), Addr));
Matt Arsenaultc23753a2013-05-06 02:07:24 +00001005 if (I->getResult().isNonLocal()) {
1006 continue;
1007 }
1008
1009 if (!DT) {
1010 Result.push_back(NonLocalDepResult(I->getBB(),
1011 MemDepResult::getUnknown(),
1012 Addr));
1013 } else if (DT->isReachableFromEntry(I->getBB())) {
Chris Lattner9b7d99e2009-12-22 04:25:02 +00001014 Result.push_back(NonLocalDepResult(I->getBB(), I->getResult(), Addr));
Matt Arsenaultc23753a2013-05-06 02:07:24 +00001015 }
Chris Lattner8b4be372008-12-16 07:10:09 +00001016 }
Chris Lattner5ed409e2008-12-08 07:31:50 +00001017 ++NumCacheCompleteNonLocalPtr;
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001018 return false;
Chris Lattner5ed409e2008-12-08 07:31:50 +00001019 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001020
Chris Lattner5ed409e2008-12-08 07:31:50 +00001021 // Otherwise, either this is a new block, a block with an invalid cache
1022 // pointer or one that we're about to invalidate by putting more info into it
1023 // than its valid cache info. If empty, the result will be valid cache info,
1024 // otherwise it isn't.
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001025 if (Cache->empty())
Dan Gohman23483932010-09-22 21:41:02 +00001026 CacheInfo->Pair = BBSkipFirstBlockPair(StartBB, SkipFirstBlock);
Dan Gohmanc87c8432010-11-11 00:42:22 +00001027 else
Dan Gohman23483932010-09-22 21:41:02 +00001028 CacheInfo->Pair = BBSkipFirstBlockPair();
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001029
Chris Lattner5ed409e2008-12-08 07:31:50 +00001030 SmallVector<BasicBlock*, 32> Worklist;
1031 Worklist.push_back(StartBB);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001032
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001033 // PredList used inside loop.
1034 SmallVector<std::pair<BasicBlock*, PHITransAddr>, 16> PredList;
1035
Chris Lattnera28355d2008-12-07 08:50:20 +00001036 // Keep track of the entries that we know are sorted. Previously cached
1037 // entries will all be sorted. The entries we add we only sort on demand (we
1038 // don't insert every element into its sorted position). We know that we
1039 // won't get any reuse from currently inserted values, because we don't
1040 // revisit blocks after we insert info for them.
1041 unsigned NumSortedEntries = Cache->size();
Chris Lattnerf09619d2009-01-22 07:04:01 +00001042 DEBUG(AssertSorted(*Cache));
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001043
Chris Lattner2faa2c72008-12-07 02:15:47 +00001044 while (!Worklist.empty()) {
Chris Lattner7564a3b2008-12-07 02:56:57 +00001045 BasicBlock *BB = Worklist.pop_back_val();
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001046
Chris Lattner75510d82008-12-09 07:52:59 +00001047 // Skip the first block if we have it.
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001048 if (!SkipFirstBlock) {
Chris Lattner75510d82008-12-09 07:52:59 +00001049 // Analyze the dependency of *Pointer in FromBB. See if we already have
1050 // been here.
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001051 assert(Visited.count(BB) && "Should check 'visited' before adding to WL");
Chris Lattnera28355d2008-12-07 08:50:20 +00001052
Chris Lattner75510d82008-12-09 07:52:59 +00001053 // Get the dependency info for Pointer in BB. If we have cached
1054 // information, we will use it, otherwise we compute it.
Chris Lattnerf09619d2009-01-22 07:04:01 +00001055 DEBUG(AssertSorted(*Cache, NumSortedEntries));
Dan Gohman23483932010-09-22 21:41:02 +00001056 MemDepResult Dep = GetNonLocalInfoForBlock(Loc, isLoad, BB, Cache,
Chris Lattner972e6d82009-12-09 01:59:31 +00001057 NumSortedEntries);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001058
Chris Lattner75510d82008-12-09 07:52:59 +00001059 // If we got a Def or Clobber, add this to the list of results.
Matt Arsenaultc23753a2013-05-06 02:07:24 +00001060 if (!Dep.isNonLocal()) {
1061 if (!DT) {
1062 Result.push_back(NonLocalDepResult(BB,
1063 MemDepResult::getUnknown(),
1064 Pointer.getAddr()));
1065 continue;
1066 } else if (DT->isReachableFromEntry(BB)) {
1067 Result.push_back(NonLocalDepResult(BB, Dep, Pointer.getAddr()));
1068 continue;
1069 }
Chris Lattner75510d82008-12-09 07:52:59 +00001070 }
Chris Lattner2faa2c72008-12-07 02:15:47 +00001071 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001072
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001073 // If 'Pointer' is an instruction defined in this block, then we need to do
1074 // phi translation to change it into a value live in the predecessor block.
Chris Lattner972e6d82009-12-09 01:59:31 +00001075 // If not, we just add the predecessors to the worklist and scan them with
1076 // the same Pointer.
1077 if (!Pointer.NeedsPHITranslationFromBlock(BB)) {
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001078 SkipFirstBlock = false;
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001079 SmallVector<BasicBlock*, 16> NewBlocks;
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001080 for (BasicBlock **PI = PredCache->GetPreds(BB); *PI; ++PI) {
1081 // Verify that we haven't looked at this block yet.
1082 std::pair<DenseMap<BasicBlock*,Value*>::iterator, bool>
Chris Lattner972e6d82009-12-09 01:59:31 +00001083 InsertRes = Visited.insert(std::make_pair(*PI, Pointer.getAddr()));
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001084 if (InsertRes.second) {
1085 // First time we've looked at *PI.
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001086 NewBlocks.push_back(*PI);
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001087 continue;
1088 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001089
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001090 // If we have seen this block before, but it was with a different
1091 // pointer then we have a phi translation failure and we have to treat
1092 // this as a clobber.
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001093 if (InsertRes.first->second != Pointer.getAddr()) {
1094 // Make sure to clean up the Visited map before continuing on to
1095 // PredTranslationFailure.
1096 for (unsigned i = 0; i < NewBlocks.size(); i++)
1097 Visited.erase(NewBlocks[i]);
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001098 goto PredTranslationFailure;
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001099 }
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001100 }
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001101 Worklist.append(NewBlocks.begin(), NewBlocks.end());
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001102 continue;
1103 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001104
Chris Lattner972e6d82009-12-09 01:59:31 +00001105 // We do need to do phi translation, if we know ahead of time we can't phi
1106 // translate this value, don't even try.
1107 if (!Pointer.IsPotentiallyPHITranslatable())
1108 goto PredTranslationFailure;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001109
Chris Lattner2f0c1c42009-07-13 17:14:23 +00001110 // We may have added values to the cache list before this PHI translation.
1111 // If so, we haven't done anything to ensure that the cache remains sorted.
1112 // Sort it now (if needed) so that recursive invocations of
1113 // getNonLocalPointerDepFromBB and other routines that could reuse the cache
1114 // value will only see properly sorted cache arrays.
1115 if (Cache && NumSortedEntries != Cache->size()) {
Chris Lattner370aada2009-07-13 17:20:05 +00001116 SortNonLocalDepInfoCache(*Cache, NumSortedEntries);
Chris Lattner2f0c1c42009-07-13 17:14:23 +00001117 NumSortedEntries = Cache->size();
1118 }
Chris Lattnerac323292009-11-27 08:37:22 +00001119 Cache = 0;
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001120
1121 PredList.clear();
Chris Lattnerac323292009-11-27 08:37:22 +00001122 for (BasicBlock **PI = PredCache->GetPreds(BB); *PI; ++PI) {
1123 BasicBlock *Pred = *PI;
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001124 PredList.push_back(std::make_pair(Pred, Pointer));
1125
Chris Lattner972e6d82009-12-09 01:59:31 +00001126 // Get the PHI translated pointer in this predecessor. This can fail if
1127 // not translatable, in which case the getAddr() returns null.
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001128 PHITransAddr &PredPointer = PredList.back().second;
Daniel Dunbar693ea892010-02-24 08:48:04 +00001129 PredPointer.PHITranslateValue(BB, Pred, 0);
Chris Lattner972e6d82009-12-09 01:59:31 +00001130
1131 Value *PredPtrVal = PredPointer.getAddr();
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001132
Chris Lattnerac323292009-11-27 08:37:22 +00001133 // Check to see if we have already visited this pred block with another
1134 // pointer. If so, we can't do this lookup. This failure can occur
1135 // with PHI translation when a critical edge exists and the PHI node in
1136 // the successor translates to a pointer value different than the
1137 // pointer the block was first analyzed with.
1138 std::pair<DenseMap<BasicBlock*,Value*>::iterator, bool>
Chris Lattner972e6d82009-12-09 01:59:31 +00001139 InsertRes = Visited.insert(std::make_pair(Pred, PredPtrVal));
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001140
Chris Lattnerac323292009-11-27 08:37:22 +00001141 if (!InsertRes.second) {
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001142 // We found the pred; take it off the list of preds to visit.
1143 PredList.pop_back();
1144
Chris Lattnerac323292009-11-27 08:37:22 +00001145 // If the predecessor was visited with PredPtr, then we already did
1146 // the analysis and can ignore it.
Chris Lattner972e6d82009-12-09 01:59:31 +00001147 if (InsertRes.first->second == PredPtrVal)
Chris Lattnerac323292009-11-27 08:37:22 +00001148 continue;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001149
Chris Lattnerac323292009-11-27 08:37:22 +00001150 // Otherwise, the block was previously analyzed with a different
1151 // pointer. We can't represent the result of this case, so we just
1152 // treat this as a phi translation failure.
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001153
1154 // Make sure to clean up the Visited map before continuing on to
1155 // PredTranslationFailure.
Matt Arsenault2080ecd2013-03-29 18:48:42 +00001156 for (unsigned i = 0, n = PredList.size(); i < n; ++i)
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001157 Visited.erase(PredList[i].first);
1158
Chris Lattnerac323292009-11-27 08:37:22 +00001159 goto PredTranslationFailure;
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001160 }
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001161 }
1162
1163 // Actually process results here; this need to be a separate loop to avoid
1164 // calling getNonLocalPointerDepFromBB for blocks we don't want to return
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001165 // any results for. (getNonLocalPointerDepFromBB will modify our
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001166 // datastructures in ways the code after the PredTranslationFailure label
1167 // doesn't expect.)
Matt Arsenault2080ecd2013-03-29 18:48:42 +00001168 for (unsigned i = 0, n = PredList.size(); i < n; ++i) {
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001169 BasicBlock *Pred = PredList[i].first;
1170 PHITransAddr &PredPointer = PredList[i].second;
1171 Value *PredPtrVal = PredPointer.getAddr();
1172
1173 bool CanTranslate = true;
Chris Lattner2be52e72009-11-27 22:05:15 +00001174 // If PHI translation was unable to find an available pointer in this
1175 // predecessor, then we have to assume that the pointer is clobbered in
1176 // that predecessor. We can still do PRE of the load, which would insert
1177 // a computation of the pointer in this predecessor.
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001178 if (PredPtrVal == 0)
1179 CanTranslate = false;
1180
1181 // FIXME: it is entirely possible that PHI translating will end up with
1182 // the same value. Consider PHI translating something like:
1183 // X = phi [x, bb1], [y, bb2]. PHI translating for bb1 doesn't *need*
1184 // to recurse here, pedantically speaking.
1185
1186 // If getNonLocalPointerDepFromBB fails here, that means the cached
1187 // result conflicted with the Visited list; we have to conservatively
Eli Friedman7d58bc72011-06-15 00:47:34 +00001188 // assume it is unknown, but this also does not block PRE of the load.
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001189 if (!CanTranslate ||
1190 getNonLocalPointerDepFromBB(PredPointer,
1191 Loc.getWithNewPtr(PredPtrVal),
1192 isLoad, Pred,
1193 Result, Visited)) {
Chris Lattner9c2053b2009-12-01 07:33:32 +00001194 // Add the entry to the Result list.
Eli Friedman7d58bc72011-06-15 00:47:34 +00001195 NonLocalDepResult Entry(Pred, MemDepResult::getUnknown(), PredPtrVal);
Chris Lattner9c2053b2009-12-01 07:33:32 +00001196 Result.push_back(Entry);
1197
Chris Lattner25bf6f82009-12-19 21:29:22 +00001198 // Since we had a phi translation failure, the cache for CacheKey won't
1199 // include all of the entries that we need to immediately satisfy future
1200 // queries. Mark this in NonLocalPointerDeps by setting the
1201 // BBSkipFirstBlockPair pointer to null. This requires reuse of the
1202 // cached value to do more work but not miss the phi trans failure.
Dan Gohman23483932010-09-22 21:41:02 +00001203 NonLocalPointerInfo &NLPI = NonLocalPointerDeps[CacheKey];
1204 NLPI.Pair = BBSkipFirstBlockPair();
Chris Lattner2be52e72009-11-27 22:05:15 +00001205 continue;
Chris Lattner2be52e72009-11-27 22:05:15 +00001206 }
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001207 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001208
Chris Lattnerac323292009-11-27 08:37:22 +00001209 // Refresh the CacheInfo/Cache pointer so that it isn't invalidated.
1210 CacheInfo = &NonLocalPointerDeps[CacheKey];
Dan Gohman23483932010-09-22 21:41:02 +00001211 Cache = &CacheInfo->NonLocalDeps;
Chris Lattnerac323292009-11-27 08:37:22 +00001212 NumSortedEntries = Cache->size();
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001213
Chris Lattnerac323292009-11-27 08:37:22 +00001214 // Since we did phi translation, the "Cache" set won't contain all of the
1215 // results for the query. This is ok (we can still use it to accelerate
1216 // specific block queries) but we can't do the fastpath "return all
1217 // results from the set" Clear out the indicator for this.
Dan Gohman23483932010-09-22 21:41:02 +00001218 CacheInfo->Pair = BBSkipFirstBlockPair();
Chris Lattnerac323292009-11-27 08:37:22 +00001219 SkipFirstBlock = false;
1220 continue;
Chris Lattnerc49f5ac2009-11-26 23:18:49 +00001221
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001222 PredTranslationFailure:
Eli Friedman4b6eeb92011-06-01 23:16:53 +00001223 // The following code is "failure"; we can't produce a sane translation
1224 // for the given block. It assumes that we haven't modified any of
1225 // our datastructures while processing the current block.
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001226
Chris Lattner3f4591c2009-01-23 07:12:16 +00001227 if (Cache == 0) {
1228 // Refresh the CacheInfo/Cache pointer if it got invalidated.
1229 CacheInfo = &NonLocalPointerDeps[CacheKey];
Dan Gohman23483932010-09-22 21:41:02 +00001230 Cache = &CacheInfo->NonLocalDeps;
Chris Lattner3f4591c2009-01-23 07:12:16 +00001231 NumSortedEntries = Cache->size();
Chris Lattner3f4591c2009-01-23 07:12:16 +00001232 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001233
Chris Lattner25bf6f82009-12-19 21:29:22 +00001234 // Since we failed phi translation, the "Cache" set won't contain all of the
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001235 // results for the query. This is ok (we can still use it to accelerate
1236 // specific block queries) but we can't do the fastpath "return all
Chris Lattner25bf6f82009-12-19 21:29:22 +00001237 // results from the set". Clear out the indicator for this.
Dan Gohman23483932010-09-22 21:41:02 +00001238 CacheInfo->Pair = BBSkipFirstBlockPair();
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001239
Eli Friedman7d58bc72011-06-15 00:47:34 +00001240 // If *nothing* works, mark the pointer as unknown.
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001241 //
1242 // If this is the magic first block, return this as a clobber of the whole
1243 // incoming value. Since we can't phi translate to one of the predecessors,
1244 // we have to bail out.
1245 if (SkipFirstBlock)
1246 return true;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001247
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001248 for (NonLocalDepInfo::reverse_iterator I = Cache->rbegin(); ; ++I) {
1249 assert(I != Cache->rend() && "Didn't find current block??");
Chris Lattner0c315472009-12-09 07:08:01 +00001250 if (I->getBB() != BB)
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001251 continue;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001252
Chris Lattner0c315472009-12-09 07:08:01 +00001253 assert(I->getResult().isNonLocal() &&
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001254 "Should only be here with transparent block");
Eli Friedman7d58bc72011-06-15 00:47:34 +00001255 I->setResult(MemDepResult::getUnknown());
Chris Lattner9b7d99e2009-12-22 04:25:02 +00001256 Result.push_back(NonLocalDepResult(I->getBB(), I->getResult(),
1257 Pointer.getAddr()));
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001258 break;
Chris Lattner7564a3b2008-12-07 02:56:57 +00001259 }
Chris Lattner2faa2c72008-12-07 02:15:47 +00001260 }
Chris Lattner3f4591c2009-01-23 07:12:16 +00001261
Chris Lattnerf903fe12008-12-09 07:47:11 +00001262 // Okay, we're done now. If we added new values to the cache, re-sort it.
Chris Lattner370aada2009-07-13 17:20:05 +00001263 SortNonLocalDepInfoCache(*Cache, NumSortedEntries);
Chris Lattnerf09619d2009-01-22 07:04:01 +00001264 DEBUG(AssertSorted(*Cache));
Chris Lattnerff9f3db2008-12-15 03:35:32 +00001265 return false;
Chris Lattnera28355d2008-12-07 08:50:20 +00001266}
1267
1268/// RemoveCachedNonLocalPointerDependencies - If P exists in
1269/// CachedNonLocalPointerInfo, remove it.
1270void MemoryDependenceAnalysis::
1271RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair P) {
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001272 CachedNonLocalPointerInfo::iterator It =
Chris Lattnera28355d2008-12-07 08:50:20 +00001273 NonLocalPointerDeps.find(P);
1274 if (It == NonLocalPointerDeps.end()) return;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001275
Chris Lattnera28355d2008-12-07 08:50:20 +00001276 // Remove all of the entries in the BB->val map. This involves removing
1277 // instructions from the reverse map.
Dan Gohman23483932010-09-22 21:41:02 +00001278 NonLocalDepInfo &PInfo = It->second.NonLocalDeps;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001279
Chris Lattnera28355d2008-12-07 08:50:20 +00001280 for (unsigned i = 0, e = PInfo.size(); i != e; ++i) {
Chris Lattner0c315472009-12-09 07:08:01 +00001281 Instruction *Target = PInfo[i].getResult().getInst();
Chris Lattnera28355d2008-12-07 08:50:20 +00001282 if (Target == 0) continue; // Ignore non-local dep results.
Chris Lattner0c315472009-12-09 07:08:01 +00001283 assert(Target->getParent() == PInfo[i].getBB());
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001284
Chris Lattnera28355d2008-12-07 08:50:20 +00001285 // Eliminating the dirty entry from 'Cache', so update the reverse info.
Chris Lattner8eda11b2009-03-29 00:24:04 +00001286 RemoveFromReverseMap(ReverseNonLocalPtrDeps, Target, P);
Chris Lattnera28355d2008-12-07 08:50:20 +00001287 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001288
Chris Lattnera28355d2008-12-07 08:50:20 +00001289 // Remove P from NonLocalPointerDeps (which deletes NonLocalDepInfo).
1290 NonLocalPointerDeps.erase(It);
Chris Lattner2faa2c72008-12-07 02:15:47 +00001291}
1292
1293
Chris Lattnerfa9f99a2008-12-09 22:06:23 +00001294/// invalidateCachedPointerInfo - This method is used to invalidate cached
1295/// information about the specified pointer, because it may be too
1296/// conservative in memdep. This is an optional call that can be used when
1297/// the client detects an equivalence between the pointer and some other
1298/// value and replaces the other value with ptr. This can make Ptr available
1299/// in more places that cached info does not necessarily keep.
1300void MemoryDependenceAnalysis::invalidateCachedPointerInfo(Value *Ptr) {
1301 // If Ptr isn't really a pointer, just ignore it.
Duncan Sands19d0b472010-02-16 11:11:14 +00001302 if (!Ptr->getType()->isPointerTy()) return;
Chris Lattnerfa9f99a2008-12-09 22:06:23 +00001303 // Flush store info for the pointer.
1304 RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr, false));
1305 // Flush load info for the pointer.
1306 RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr, true));
1307}
1308
Bob Wilson92cdb6e2010-02-16 19:51:59 +00001309/// invalidateCachedPredecessors - Clear the PredIteratorCache info.
1310/// This needs to be done when the CFG changes, e.g., due to splitting
1311/// critical edges.
1312void MemoryDependenceAnalysis::invalidateCachedPredecessors() {
1313 PredCache->clear();
1314}
1315
Owen Andersonc0daf5f2007-07-06 23:14:35 +00001316/// removeInstruction - Remove an instruction from the dependence analysis,
1317/// updating the dependence of instructions that previously depended on it.
Owen Anderson2b21c3c2007-08-08 22:26:03 +00001318/// This method attempts to keep the cache coherent using the reverse map.
Chris Lattnera25d39522008-11-28 22:04:47 +00001319void MemoryDependenceAnalysis::removeInstruction(Instruction *RemInst) {
Chris Lattnera25d39522008-11-28 22:04:47 +00001320 // Walk through the Non-local dependencies, removing this one as the value
1321 // for any cached queries.
Chris Lattner1b810bd2008-11-30 02:28:25 +00001322 NonLocalDepMapType::iterator NLDI = NonLocalDeps.find(RemInst);
1323 if (NLDI != NonLocalDeps.end()) {
Chris Lattner7e61daf2008-12-01 01:15:42 +00001324 NonLocalDepInfo &BlockMap = NLDI->second.first;
Chris Lattnerfc678e22008-11-30 02:30:50 +00001325 for (NonLocalDepInfo::iterator DI = BlockMap.begin(), DE = BlockMap.end();
1326 DI != DE; ++DI)
Chris Lattner0c315472009-12-09 07:08:01 +00001327 if (Instruction *Inst = DI->getResult().getInst())
Chris Lattnerde4440c2008-12-07 18:39:13 +00001328 RemoveFromReverseMap(ReverseNonLocalDeps, Inst, RemInst);
Chris Lattner1b810bd2008-11-30 02:28:25 +00001329 NonLocalDeps.erase(NLDI);
1330 }
Owen Anderson086b2c42007-12-08 01:37:09 +00001331
Chris Lattnera25d39522008-11-28 22:04:47 +00001332 // If we have a cached local dependence query for this instruction, remove it.
Chris Lattner73c25452008-11-28 22:28:27 +00001333 //
Chris Lattnerde04e112008-11-29 01:43:36 +00001334 LocalDepMapType::iterator LocalDepEntry = LocalDeps.find(RemInst);
1335 if (LocalDepEntry != LocalDeps.end()) {
Chris Lattnerada1f872008-11-30 01:09:30 +00001336 // Remove us from DepInst's reverse set now that the local dep info is gone.
Chris Lattnerde4440c2008-12-07 18:39:13 +00001337 if (Instruction *Inst = LocalDepEntry->second.getInst())
1338 RemoveFromReverseMap(ReverseLocalDeps, Inst, RemInst);
Chris Lattnerada1f872008-11-30 01:09:30 +00001339
Chris Lattner73c25452008-11-28 22:28:27 +00001340 // Remove this local dependency info.
Chris Lattnerde04e112008-11-29 01:43:36 +00001341 LocalDeps.erase(LocalDepEntry);
Chris Lattnera28355d2008-12-07 08:50:20 +00001342 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001343
Chris Lattnera28355d2008-12-07 08:50:20 +00001344 // If we have any cached pointer dependencies on this instruction, remove
1345 // them. If the instruction has non-pointer type, then it can't be a pointer
1346 // base.
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001347
Chris Lattnera28355d2008-12-07 08:50:20 +00001348 // Remove it from both the load info and the store info. The instruction
1349 // can't be in either of these maps if it is non-pointer.
Duncan Sands19d0b472010-02-16 11:11:14 +00001350 if (RemInst->getType()->isPointerTy()) {
Chris Lattnera28355d2008-12-07 08:50:20 +00001351 RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst, false));
1352 RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst, true));
1353 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001354
Chris Lattnerd3d91112008-11-28 22:51:08 +00001355 // Loop over all of the things that depend on the instruction we're removing.
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001356 //
Chris Lattner63bd5862008-11-29 23:30:39 +00001357 SmallVector<std::pair<Instruction*, Instruction*>, 8> ReverseDepsToAdd;
Chris Lattner82b70342008-12-07 18:42:51 +00001358
1359 // If we find RemInst as a clobber or Def in any of the maps for other values,
1360 // we need to replace its entry with a dirty version of the instruction after
1361 // it. If RemInst is a terminator, we use a null dirty value.
1362 //
1363 // Using a dirty version of the instruction after RemInst saves having to scan
1364 // the entire block to get to this point.
1365 MemDepResult NewDirtyVal;
1366 if (!RemInst->isTerminator())
1367 NewDirtyVal = MemDepResult::getDirty(++BasicBlock::iterator(RemInst));
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001368
Chris Lattner9f1988ab2008-11-29 09:20:15 +00001369 ReverseDepMapType::iterator ReverseDepIt = ReverseLocalDeps.find(RemInst);
1370 if (ReverseDepIt != ReverseLocalDeps.end()) {
Chris Lattnerd3d91112008-11-28 22:51:08 +00001371 SmallPtrSet<Instruction*, 4> &ReverseDeps = ReverseDepIt->second;
Chris Lattnera28355d2008-12-07 08:50:20 +00001372 // RemInst can't be the terminator if it has local stuff depending on it.
Chris Lattnerada1f872008-11-30 01:09:30 +00001373 assert(!ReverseDeps.empty() && !isa<TerminatorInst>(RemInst) &&
1374 "Nothing can locally depend on a terminator");
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001375
Chris Lattnerd3d91112008-11-28 22:51:08 +00001376 for (SmallPtrSet<Instruction*, 4>::iterator I = ReverseDeps.begin(),
1377 E = ReverseDeps.end(); I != E; ++I) {
1378 Instruction *InstDependingOnRemInst = *I;
Chris Lattner1b810bd2008-11-30 02:28:25 +00001379 assert(InstDependingOnRemInst != RemInst &&
1380 "Already removed our local dep info");
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001381
Chris Lattner82b70342008-12-07 18:42:51 +00001382 LocalDeps[InstDependingOnRemInst] = NewDirtyVal;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001383
Chris Lattnerada1f872008-11-30 01:09:30 +00001384 // Make sure to remember that new things depend on NewDepInst.
Chris Lattner82b70342008-12-07 18:42:51 +00001385 assert(NewDirtyVal.getInst() && "There is no way something else can have "
1386 "a local dep on this if it is a terminator!");
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001387 ReverseDepsToAdd.push_back(std::make_pair(NewDirtyVal.getInst(),
Chris Lattnerada1f872008-11-30 01:09:30 +00001388 InstDependingOnRemInst));
Chris Lattnerd3d91112008-11-28 22:51:08 +00001389 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001390
Chris Lattner63bd5862008-11-29 23:30:39 +00001391 ReverseLocalDeps.erase(ReverseDepIt);
1392
1393 // Add new reverse deps after scanning the set, to avoid invalidating the
1394 // 'ReverseDeps' reference.
1395 while (!ReverseDepsToAdd.empty()) {
1396 ReverseLocalDeps[ReverseDepsToAdd.back().first]
1397 .insert(ReverseDepsToAdd.back().second);
1398 ReverseDepsToAdd.pop_back();
1399 }
Owen Andersonc0daf5f2007-07-06 23:14:35 +00001400 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001401
Chris Lattner9f1988ab2008-11-29 09:20:15 +00001402 ReverseDepIt = ReverseNonLocalDeps.find(RemInst);
1403 if (ReverseDepIt != ReverseNonLocalDeps.end()) {
Chris Lattnera28355d2008-12-07 08:50:20 +00001404 SmallPtrSet<Instruction*, 4> &Set = ReverseDepIt->second;
1405 for (SmallPtrSet<Instruction*, 4>::iterator I = Set.begin(), E = Set.end();
Chris Lattner1b810bd2008-11-30 02:28:25 +00001406 I != E; ++I) {
1407 assert(*I != RemInst && "Already removed NonLocalDep info for RemInst");
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001408
Chris Lattner44104272008-11-30 02:52:26 +00001409 PerInstNLInfo &INLD = NonLocalDeps[*I];
Chris Lattner44104272008-11-30 02:52:26 +00001410 // The information is now dirty!
Chris Lattner7e61daf2008-12-01 01:15:42 +00001411 INLD.second = true;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001412
1413 for (NonLocalDepInfo::iterator DI = INLD.first.begin(),
Chris Lattner7e61daf2008-12-01 01:15:42 +00001414 DE = INLD.first.end(); DI != DE; ++DI) {
Chris Lattner0c315472009-12-09 07:08:01 +00001415 if (DI->getResult().getInst() != RemInst) continue;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001416
Chris Lattner1b810bd2008-11-30 02:28:25 +00001417 // Convert to a dirty entry for the subsequent instruction.
Chris Lattner9b7d99e2009-12-22 04:25:02 +00001418 DI->setResult(NewDirtyVal);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001419
Chris Lattner82b70342008-12-07 18:42:51 +00001420 if (Instruction *NextI = NewDirtyVal.getInst())
Chris Lattner1b810bd2008-11-30 02:28:25 +00001421 ReverseDepsToAdd.push_back(std::make_pair(NextI, *I));
Chris Lattner1b810bd2008-11-30 02:28:25 +00001422 }
1423 }
Chris Lattner63bd5862008-11-29 23:30:39 +00001424
1425 ReverseNonLocalDeps.erase(ReverseDepIt);
1426
Chris Lattnere7d7e132008-11-29 22:02:15 +00001427 // Add new reverse deps after scanning the set, to avoid invalidating 'Set'
1428 while (!ReverseDepsToAdd.empty()) {
1429 ReverseNonLocalDeps[ReverseDepsToAdd.back().first]
1430 .insert(ReverseDepsToAdd.back().second);
1431 ReverseDepsToAdd.pop_back();
1432 }
Owen Anderson5f208be2007-08-16 21:27:05 +00001433 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001434
Chris Lattnera28355d2008-12-07 08:50:20 +00001435 // If the instruction is in ReverseNonLocalPtrDeps then it appears as a
1436 // value in the NonLocalPointerDeps info.
1437 ReverseNonLocalPtrDepTy::iterator ReversePtrDepIt =
1438 ReverseNonLocalPtrDeps.find(RemInst);
1439 if (ReversePtrDepIt != ReverseNonLocalPtrDeps.end()) {
Chris Lattner8eda11b2009-03-29 00:24:04 +00001440 SmallPtrSet<ValueIsLoadPair, 4> &Set = ReversePtrDepIt->second;
Chris Lattnera28355d2008-12-07 08:50:20 +00001441 SmallVector<std::pair<Instruction*, ValueIsLoadPair>,8> ReversePtrDepsToAdd;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001442
Chris Lattner8eda11b2009-03-29 00:24:04 +00001443 for (SmallPtrSet<ValueIsLoadPair, 4>::iterator I = Set.begin(),
1444 E = Set.end(); I != E; ++I) {
1445 ValueIsLoadPair P = *I;
Chris Lattnera28355d2008-12-07 08:50:20 +00001446 assert(P.getPointer() != RemInst &&
1447 "Already removed NonLocalPointerDeps info for RemInst");
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001448
Dan Gohman23483932010-09-22 21:41:02 +00001449 NonLocalDepInfo &NLPDI = NonLocalPointerDeps[P].NonLocalDeps;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001450
Chris Lattner5ed409e2008-12-08 07:31:50 +00001451 // The cache is not valid for any specific block anymore.
Dan Gohman23483932010-09-22 21:41:02 +00001452 NonLocalPointerDeps[P].Pair = BBSkipFirstBlockPair();
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001453
Chris Lattnera28355d2008-12-07 08:50:20 +00001454 // Update any entries for RemInst to use the instruction after it.
1455 for (NonLocalDepInfo::iterator DI = NLPDI.begin(), DE = NLPDI.end();
1456 DI != DE; ++DI) {
Chris Lattner0c315472009-12-09 07:08:01 +00001457 if (DI->getResult().getInst() != RemInst) continue;
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001458
Chris Lattnera28355d2008-12-07 08:50:20 +00001459 // Convert to a dirty entry for the subsequent instruction.
Chris Lattner9b7d99e2009-12-22 04:25:02 +00001460 DI->setResult(NewDirtyVal);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001461
Chris Lattnera28355d2008-12-07 08:50:20 +00001462 if (Instruction *NewDirtyInst = NewDirtyVal.getInst())
1463 ReversePtrDepsToAdd.push_back(std::make_pair(NewDirtyInst, P));
1464 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001465
Chris Lattner3f4591c2009-01-23 07:12:16 +00001466 // Re-sort the NonLocalDepInfo. Changing the dirty entry to its
1467 // subsequent value may invalidate the sortedness.
1468 std::sort(NLPDI.begin(), NLPDI.end());
Chris Lattnera28355d2008-12-07 08:50:20 +00001469 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001470
Chris Lattnera28355d2008-12-07 08:50:20 +00001471 ReverseNonLocalPtrDeps.erase(ReversePtrDepIt);
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001472
Chris Lattnera28355d2008-12-07 08:50:20 +00001473 while (!ReversePtrDepsToAdd.empty()) {
1474 ReverseNonLocalPtrDeps[ReversePtrDepsToAdd.back().first]
Chris Lattner8eda11b2009-03-29 00:24:04 +00001475 .insert(ReversePtrDepsToAdd.back().second);
Chris Lattnera28355d2008-12-07 08:50:20 +00001476 ReversePtrDepsToAdd.pop_back();
1477 }
1478 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001479
1480
Chris Lattner1b810bd2008-11-30 02:28:25 +00001481 assert(!NonLocalDeps.count(RemInst) && "RemInst got reinserted?");
Chris Lattner13cae612008-11-30 19:24:31 +00001482 AA->deleteValue(RemInst);
Jakob Stoklund Olesen087f2072011-01-11 04:05:39 +00001483 DEBUG(verifyRemoved(RemInst));
Owen Andersonc0daf5f2007-07-06 23:14:35 +00001484}
Chris Lattnerb8ec75b2008-11-29 21:25:10 +00001485/// verifyRemoved - Verify that the specified instruction does not occur
1486/// in our internal data structures.
1487void MemoryDependenceAnalysis::verifyRemoved(Instruction *D) const {
1488 for (LocalDepMapType::const_iterator I = LocalDeps.begin(),
1489 E = LocalDeps.end(); I != E; ++I) {
1490 assert(I->first != D && "Inst occurs in data structures");
Chris Lattner47e81d02008-11-30 23:17:19 +00001491 assert(I->second.getInst() != D &&
Chris Lattnerb8ec75b2008-11-29 21:25:10 +00001492 "Inst occurs in data structures");
1493 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001494
Chris Lattnera28355d2008-12-07 08:50:20 +00001495 for (CachedNonLocalPointerInfo::const_iterator I =NonLocalPointerDeps.begin(),
1496 E = NonLocalPointerDeps.end(); I != E; ++I) {
1497 assert(I->first.getPointer() != D && "Inst occurs in NLPD map key");
Dan Gohman23483932010-09-22 21:41:02 +00001498 const NonLocalDepInfo &Val = I->second.NonLocalDeps;
Chris Lattnera28355d2008-12-07 08:50:20 +00001499 for (NonLocalDepInfo::const_iterator II = Val.begin(), E = Val.end();
1500 II != E; ++II)
Chris Lattner0c315472009-12-09 07:08:01 +00001501 assert(II->getResult().getInst() != D && "Inst occurs as NLPD value");
Chris Lattnera28355d2008-12-07 08:50:20 +00001502 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001503
Chris Lattnerb8ec75b2008-11-29 21:25:10 +00001504 for (NonLocalDepMapType::const_iterator I = NonLocalDeps.begin(),
1505 E = NonLocalDeps.end(); I != E; ++I) {
1506 assert(I->first != D && "Inst occurs in data structures");
Chris Lattner44104272008-11-30 02:52:26 +00001507 const PerInstNLInfo &INLD = I->second;
Chris Lattner7e61daf2008-12-01 01:15:42 +00001508 for (NonLocalDepInfo::const_iterator II = INLD.first.begin(),
1509 EE = INLD.first.end(); II != EE; ++II)
Chris Lattner0c315472009-12-09 07:08:01 +00001510 assert(II->getResult().getInst() != D && "Inst occurs in data structures");
Chris Lattnerb8ec75b2008-11-29 21:25:10 +00001511 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001512
Chris Lattnerb8ec75b2008-11-29 21:25:10 +00001513 for (ReverseDepMapType::const_iterator I = ReverseLocalDeps.begin(),
Chris Lattner1b810bd2008-11-30 02:28:25 +00001514 E = ReverseLocalDeps.end(); I != E; ++I) {
1515 assert(I->first != D && "Inst occurs in data structures");
Chris Lattnerb8ec75b2008-11-29 21:25:10 +00001516 for (SmallPtrSet<Instruction*, 4>::const_iterator II = I->second.begin(),
1517 EE = I->second.end(); II != EE; ++II)
1518 assert(*II != D && "Inst occurs in data structures");
Chris Lattner1b810bd2008-11-30 02:28:25 +00001519 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001520
Chris Lattnerb8ec75b2008-11-29 21:25:10 +00001521 for (ReverseDepMapType::const_iterator I = ReverseNonLocalDeps.begin(),
1522 E = ReverseNonLocalDeps.end();
Chris Lattner1b810bd2008-11-30 02:28:25 +00001523 I != E; ++I) {
1524 assert(I->first != D && "Inst occurs in data structures");
Chris Lattnerb8ec75b2008-11-29 21:25:10 +00001525 for (SmallPtrSet<Instruction*, 4>::const_iterator II = I->second.begin(),
1526 EE = I->second.end(); II != EE; ++II)
1527 assert(*II != D && "Inst occurs in data structures");
Chris Lattner1b810bd2008-11-30 02:28:25 +00001528 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001529
Chris Lattnera28355d2008-12-07 08:50:20 +00001530 for (ReverseNonLocalPtrDepTy::const_iterator
1531 I = ReverseNonLocalPtrDeps.begin(),
1532 E = ReverseNonLocalPtrDeps.end(); I != E; ++I) {
1533 assert(I->first != D && "Inst occurs in rev NLPD map");
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001534
Chris Lattner8eda11b2009-03-29 00:24:04 +00001535 for (SmallPtrSet<ValueIsLoadPair, 4>::const_iterator II = I->second.begin(),
Chris Lattnera28355d2008-12-07 08:50:20 +00001536 E = I->second.end(); II != E; ++II)
Chris Lattner8eda11b2009-03-29 00:24:04 +00001537 assert(*II != ValueIsLoadPair(D, false) &&
1538 *II != ValueIsLoadPair(D, true) &&
Chris Lattnera28355d2008-12-07 08:50:20 +00001539 "Inst occurs in ReverseNonLocalPtrDeps map");
1540 }
Jakub Staszakb0a7eed2013-03-20 21:47:51 +00001541
Chris Lattnerb8ec75b2008-11-29 21:25:10 +00001542}