LLVM API Documentation

MemoryDependenceAnalysis.cpp
Go to the documentation of this file.
00001 //===- MemoryDependenceAnalysis.cpp - Mem Deps Implementation -------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements an analysis that determines, for a given memory
00011 // operation, what preceding memory operations it depends on.  It builds on
00012 // alias analysis information, and tries to provide a lazy, caching interface to
00013 // a common kind of alias information query.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
00018 #include "llvm/ADT/STLExtras.h"
00019 #include "llvm/ADT/Statistic.h"
00020 #include "llvm/Analysis/AliasAnalysis.h"
00021 #include "llvm/Analysis/InstructionSimplify.h"
00022 #include "llvm/Analysis/MemoryBuiltins.h"
00023 #include "llvm/Analysis/PHITransAddr.h"
00024 #include "llvm/Analysis/ValueTracking.h"
00025 #include "llvm/IR/DataLayout.h"
00026 #include "llvm/IR/Dominators.h"
00027 #include "llvm/IR/Function.h"
00028 #include "llvm/IR/Instructions.h"
00029 #include "llvm/IR/IntrinsicInst.h"
00030 #include "llvm/IR/LLVMContext.h"
00031 #include "llvm/IR/PredIteratorCache.h"
00032 #include "llvm/Support/Debug.h"
00033 using namespace llvm;
00034 
00035 #define DEBUG_TYPE "memdep"
00036 
00037 STATISTIC(NumCacheNonLocal, "Number of fully cached non-local responses");
00038 STATISTIC(NumCacheDirtyNonLocal, "Number of dirty cached non-local responses");
00039 STATISTIC(NumUncacheNonLocal, "Number of uncached non-local responses");
00040 
00041 STATISTIC(NumCacheNonLocalPtr,
00042           "Number of fully cached non-local ptr responses");
00043 STATISTIC(NumCacheDirtyNonLocalPtr,
00044           "Number of cached, but dirty, non-local ptr responses");
00045 STATISTIC(NumUncacheNonLocalPtr,
00046           "Number of uncached non-local ptr responses");
00047 STATISTIC(NumCacheCompleteNonLocalPtr,
00048           "Number of block queries that were completely cached");
00049 
00050 // Limit for the number of instructions to scan in a block.
00051 static const int BlockScanLimit = 100;
00052 
00053 char MemoryDependenceAnalysis::ID = 0;
00054 
00055 // Register this pass...
00056 INITIALIZE_PASS_BEGIN(MemoryDependenceAnalysis, "memdep",
00057                 "Memory Dependence Analysis", false, true)
00058 INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
00059 INITIALIZE_PASS_END(MemoryDependenceAnalysis, "memdep",
00060                       "Memory Dependence Analysis", false, true)
00061 
00062 MemoryDependenceAnalysis::MemoryDependenceAnalysis()
00063     : FunctionPass(ID), PredCache() {
00064   initializeMemoryDependenceAnalysisPass(*PassRegistry::getPassRegistry());
00065 }
00066 MemoryDependenceAnalysis::~MemoryDependenceAnalysis() {
00067 }
00068 
00069 /// Clean up memory in between runs
00070 void MemoryDependenceAnalysis::releaseMemory() {
00071   LocalDeps.clear();
00072   NonLocalDeps.clear();
00073   NonLocalPointerDeps.clear();
00074   ReverseLocalDeps.clear();
00075   ReverseNonLocalDeps.clear();
00076   ReverseNonLocalPtrDeps.clear();
00077   PredCache->clear();
00078 }
00079 
00080 
00081 
00082 /// getAnalysisUsage - Does not modify anything.  It uses Alias Analysis.
00083 ///
00084 void MemoryDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
00085   AU.setPreservesAll();
00086   AU.addRequiredTransitive<AliasAnalysis>();
00087 }
00088 
00089 bool MemoryDependenceAnalysis::runOnFunction(Function &) {
00090   AA = &getAnalysis<AliasAnalysis>();
00091   DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
00092   DL = DLP ? &DLP->getDataLayout() : nullptr;
00093   DominatorTreeWrapperPass *DTWP =
00094       getAnalysisIfAvailable<DominatorTreeWrapperPass>();
00095   DT = DTWP ? &DTWP->getDomTree() : nullptr;
00096   if (!PredCache)
00097     PredCache.reset(new PredIteratorCache());
00098   return false;
00099 }
00100 
00101 /// RemoveFromReverseMap - This is a helper function that removes Val from
00102 /// 'Inst's set in ReverseMap.  If the set becomes empty, remove Inst's entry.
00103 template <typename KeyTy>
00104 static void RemoveFromReverseMap(DenseMap<Instruction*,
00105                                  SmallPtrSet<KeyTy, 4> > &ReverseMap,
00106                                  Instruction *Inst, KeyTy Val) {
00107   typename DenseMap<Instruction*, SmallPtrSet<KeyTy, 4> >::iterator
00108   InstIt = ReverseMap.find(Inst);
00109   assert(InstIt != ReverseMap.end() && "Reverse map out of sync?");
00110   bool Found = InstIt->second.erase(Val);
00111   assert(Found && "Invalid reverse map!"); (void)Found;
00112   if (InstIt->second.empty())
00113     ReverseMap.erase(InstIt);
00114 }
00115 
00116 /// GetLocation - If the given instruction references a specific memory
00117 /// location, fill in Loc with the details, otherwise set Loc.Ptr to null.
00118 /// Return a ModRefInfo value describing the general behavior of the
00119 /// instruction.
00120 static
00121 AliasAnalysis::ModRefResult GetLocation(const Instruction *Inst,
00122                                         AliasAnalysis::Location &Loc,
00123                                         AliasAnalysis *AA) {
00124   if (const LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
00125     if (LI->isUnordered()) {
00126       Loc = AA->getLocation(LI);
00127       return AliasAnalysis::Ref;
00128     }
00129     if (LI->getOrdering() == Monotonic) {
00130       Loc = AA->getLocation(LI);
00131       return AliasAnalysis::ModRef;
00132     }
00133     Loc = AliasAnalysis::Location();
00134     return AliasAnalysis::ModRef;
00135   }
00136 
00137   if (const StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
00138     if (SI->isUnordered()) {
00139       Loc = AA->getLocation(SI);
00140       return AliasAnalysis::Mod;
00141     }
00142     if (SI->getOrdering() == Monotonic) {
00143       Loc = AA->getLocation(SI);
00144       return AliasAnalysis::ModRef;
00145     }
00146     Loc = AliasAnalysis::Location();
00147     return AliasAnalysis::ModRef;
00148   }
00149 
00150   if (const VAArgInst *V = dyn_cast<VAArgInst>(Inst)) {
00151     Loc = AA->getLocation(V);
00152     return AliasAnalysis::ModRef;
00153   }
00154 
00155   if (const CallInst *CI = isFreeCall(Inst, AA->getTargetLibraryInfo())) {
00156     // calls to free() deallocate the entire structure
00157     Loc = AliasAnalysis::Location(CI->getArgOperand(0));
00158     return AliasAnalysis::Mod;
00159   }
00160 
00161   if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
00162     AAMDNodes AAInfo;
00163 
00164     switch (II->getIntrinsicID()) {
00165     case Intrinsic::lifetime_start:
00166     case Intrinsic::lifetime_end:
00167     case Intrinsic::invariant_start:
00168       II->getAAMetadata(AAInfo);
00169       Loc = AliasAnalysis::Location(II->getArgOperand(1),
00170                                     cast<ConstantInt>(II->getArgOperand(0))
00171                                       ->getZExtValue(), AAInfo);
00172       // These intrinsics don't really modify the memory, but returning Mod
00173       // will allow them to be handled conservatively.
00174       return AliasAnalysis::Mod;
00175     case Intrinsic::invariant_end:
00176       II->getAAMetadata(AAInfo);
00177       Loc = AliasAnalysis::Location(II->getArgOperand(2),
00178                                     cast<ConstantInt>(II->getArgOperand(1))
00179                                       ->getZExtValue(), AAInfo);
00180       // These intrinsics don't really modify the memory, but returning Mod
00181       // will allow them to be handled conservatively.
00182       return AliasAnalysis::Mod;
00183     default:
00184       break;
00185     }
00186   }
00187 
00188   // Otherwise, just do the coarse-grained thing that always works.
00189   if (Inst->mayWriteToMemory())
00190     return AliasAnalysis::ModRef;
00191   if (Inst->mayReadFromMemory())
00192     return AliasAnalysis::Ref;
00193   return AliasAnalysis::NoModRef;
00194 }
00195 
00196 /// getCallSiteDependencyFrom - Private helper for finding the local
00197 /// dependencies of a call site.
00198 MemDepResult MemoryDependenceAnalysis::
00199 getCallSiteDependencyFrom(CallSite CS, bool isReadOnlyCall,
00200                           BasicBlock::iterator ScanIt, BasicBlock *BB) {
00201   unsigned Limit = BlockScanLimit;
00202 
00203   // Walk backwards through the block, looking for dependencies
00204   while (ScanIt != BB->begin()) {
00205     // Limit the amount of scanning we do so we don't end up with quadratic
00206     // running time on extreme testcases.
00207     --Limit;
00208     if (!Limit)
00209       return MemDepResult::getUnknown();
00210 
00211     Instruction *Inst = --ScanIt;
00212 
00213     // If this inst is a memory op, get the pointer it accessed
00214     AliasAnalysis::Location Loc;
00215     AliasAnalysis::ModRefResult MR = GetLocation(Inst, Loc, AA);
00216     if (Loc.Ptr) {
00217       // A simple instruction.
00218       if (AA->getModRefInfo(CS, Loc) != AliasAnalysis::NoModRef)
00219         return MemDepResult::getClobber(Inst);
00220       continue;
00221     }
00222 
00223     if (CallSite InstCS = cast<Value>(Inst)) {
00224       // Debug intrinsics don't cause dependences.
00225       if (isa<DbgInfoIntrinsic>(Inst)) continue;
00226       // If these two calls do not interfere, look past it.
00227       switch (AA->getModRefInfo(CS, InstCS)) {
00228       case AliasAnalysis::NoModRef:
00229         // If the two calls are the same, return InstCS as a Def, so that
00230         // CS can be found redundant and eliminated.
00231         if (isReadOnlyCall && !(MR & AliasAnalysis::Mod) &&
00232             CS.getInstruction()->isIdenticalToWhenDefined(Inst))
00233           return MemDepResult::getDef(Inst);
00234 
00235         // Otherwise if the two calls don't interact (e.g. InstCS is readnone)
00236         // keep scanning.
00237         continue;
00238       default:
00239         return MemDepResult::getClobber(Inst);
00240       }
00241     }
00242 
00243     // If we could not obtain a pointer for the instruction and the instruction
00244     // touches memory then assume that this is a dependency.
00245     if (MR != AliasAnalysis::NoModRef)
00246       return MemDepResult::getClobber(Inst);
00247   }
00248 
00249   // No dependence found.  If this is the entry block of the function, it is
00250   // unknown, otherwise it is non-local.
00251   if (BB != &BB->getParent()->getEntryBlock())
00252     return MemDepResult::getNonLocal();
00253   return MemDepResult::getNonFuncLocal();
00254 }
00255 
00256 /// isLoadLoadClobberIfExtendedToFullWidth - Return true if LI is a load that
00257 /// would fully overlap MemLoc if done as a wider legal integer load.
00258 ///
00259 /// MemLocBase, MemLocOffset are lazily computed here the first time the
00260 /// base/offs of memloc is needed.
00261 static bool
00262 isLoadLoadClobberIfExtendedToFullWidth(const AliasAnalysis::Location &MemLoc,
00263                                        const Value *&MemLocBase,
00264                                        int64_t &MemLocOffs,
00265                                        const LoadInst *LI,
00266                                        const DataLayout *DL) {
00267   // If we have no target data, we can't do this.
00268   if (!DL) return false;
00269 
00270   // If we haven't already computed the base/offset of MemLoc, do so now.
00271   if (!MemLocBase)
00272     MemLocBase = GetPointerBaseWithConstantOffset(MemLoc.Ptr, MemLocOffs, DL);
00273 
00274   unsigned Size = MemoryDependenceAnalysis::
00275     getLoadLoadClobberFullWidthSize(MemLocBase, MemLocOffs, MemLoc.Size,
00276                                     LI, *DL);
00277   return Size != 0;
00278 }
00279 
00280 /// getLoadLoadClobberFullWidthSize - This is a little bit of analysis that
00281 /// looks at a memory location for a load (specified by MemLocBase, Offs,
00282 /// and Size) and compares it against a load.  If the specified load could
00283 /// be safely widened to a larger integer load that is 1) still efficient,
00284 /// 2) safe for the target, and 3) would provide the specified memory
00285 /// location value, then this function returns the size in bytes of the
00286 /// load width to use.  If not, this returns zero.
00287 unsigned MemoryDependenceAnalysis::
00288 getLoadLoadClobberFullWidthSize(const Value *MemLocBase, int64_t MemLocOffs,
00289                                 unsigned MemLocSize, const LoadInst *LI,
00290                                 const DataLayout &DL) {
00291   // We can only extend simple integer loads.
00292   if (!isa<IntegerType>(LI->getType()) || !LI->isSimple()) return 0;
00293 
00294   // Load widening is hostile to ThreadSanitizer: it may cause false positives
00295   // or make the reports more cryptic (access sizes are wrong).
00296   if (LI->getParent()->getParent()->getAttributes().
00297       hasAttribute(AttributeSet::FunctionIndex, Attribute::SanitizeThread))
00298     return 0;
00299 
00300   // Get the base of this load.
00301   int64_t LIOffs = 0;
00302   const Value *LIBase =
00303     GetPointerBaseWithConstantOffset(LI->getPointerOperand(), LIOffs, &DL);
00304 
00305   // If the two pointers are not based on the same pointer, we can't tell that
00306   // they are related.
00307   if (LIBase != MemLocBase) return 0;
00308 
00309   // Okay, the two values are based on the same pointer, but returned as
00310   // no-alias.  This happens when we have things like two byte loads at "P+1"
00311   // and "P+3".  Check to see if increasing the size of the "LI" load up to its
00312   // alignment (or the largest native integer type) will allow us to load all
00313   // the bits required by MemLoc.
00314 
00315   // If MemLoc is before LI, then no widening of LI will help us out.
00316   if (MemLocOffs < LIOffs) return 0;
00317 
00318   // Get the alignment of the load in bytes.  We assume that it is safe to load
00319   // any legal integer up to this size without a problem.  For example, if we're
00320   // looking at an i8 load on x86-32 that is known 1024 byte aligned, we can
00321   // widen it up to an i32 load.  If it is known 2-byte aligned, we can widen it
00322   // to i16.
00323   unsigned LoadAlign = LI->getAlignment();
00324 
00325   int64_t MemLocEnd = MemLocOffs+MemLocSize;
00326 
00327   // If no amount of rounding up will let MemLoc fit into LI, then bail out.
00328   if (LIOffs+LoadAlign < MemLocEnd) return 0;
00329 
00330   // This is the size of the load to try.  Start with the next larger power of
00331   // two.
00332   unsigned NewLoadByteSize = LI->getType()->getPrimitiveSizeInBits()/8U;
00333   NewLoadByteSize = NextPowerOf2(NewLoadByteSize);
00334 
00335   while (1) {
00336     // If this load size is bigger than our known alignment or would not fit
00337     // into a native integer register, then we fail.
00338     if (NewLoadByteSize > LoadAlign ||
00339         !DL.fitsInLegalInteger(NewLoadByteSize*8))
00340       return 0;
00341 
00342     if (LIOffs+NewLoadByteSize > MemLocEnd &&
00343         LI->getParent()->getParent()->getAttributes().
00344           hasAttribute(AttributeSet::FunctionIndex, Attribute::SanitizeAddress))
00345       // We will be reading past the location accessed by the original program.
00346       // While this is safe in a regular build, Address Safety analysis tools
00347       // may start reporting false warnings. So, don't do widening.
00348       return 0;
00349 
00350     // If a load of this width would include all of MemLoc, then we succeed.
00351     if (LIOffs+NewLoadByteSize >= MemLocEnd)
00352       return NewLoadByteSize;
00353 
00354     NewLoadByteSize <<= 1;
00355   }
00356 }
00357 
00358 /// getPointerDependencyFrom - Return the instruction on which a memory
00359 /// location depends.  If isLoad is true, this routine ignores may-aliases with
00360 /// read-only operations.  If isLoad is false, this routine ignores may-aliases
00361 /// with reads from read-only locations.  If possible, pass the query
00362 /// instruction as well; this function may take advantage of the metadata
00363 /// annotated to the query instruction to refine the result.
00364 MemDepResult MemoryDependenceAnalysis::
00365 getPointerDependencyFrom(const AliasAnalysis::Location &MemLoc, bool isLoad,
00366                          BasicBlock::iterator ScanIt, BasicBlock *BB,
00367                          Instruction *QueryInst) {
00368 
00369   const Value *MemLocBase = nullptr;
00370   int64_t MemLocOffset = 0;
00371   unsigned Limit = BlockScanLimit;
00372   bool isInvariantLoad = false;
00373   if (isLoad && QueryInst) {
00374     LoadInst *LI = dyn_cast<LoadInst>(QueryInst);
00375     if (LI && LI->getMetadata(LLVMContext::MD_invariant_load) != nullptr)
00376       isInvariantLoad = true;
00377   }
00378 
00379   // Walk backwards through the basic block, looking for dependencies.
00380   while (ScanIt != BB->begin()) {
00381     Instruction *Inst = --ScanIt;
00382 
00383     if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst))
00384       // Debug intrinsics don't (and can't) cause dependencies.
00385       if (isa<DbgInfoIntrinsic>(II)) continue;
00386 
00387     // Limit the amount of scanning we do so we don't end up with quadratic
00388     // running time on extreme testcases.
00389     --Limit;
00390     if (!Limit)
00391       return MemDepResult::getUnknown();
00392 
00393     if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
00394       // If we reach a lifetime begin or end marker, then the query ends here
00395       // because the value is undefined.
00396       if (II->getIntrinsicID() == Intrinsic::lifetime_start) {
00397         // FIXME: This only considers queries directly on the invariant-tagged
00398         // pointer, not on query pointers that are indexed off of them.  It'd
00399         // be nice to handle that at some point (the right approach is to use
00400         // GetPointerBaseWithConstantOffset).
00401         if (AA->isMustAlias(AliasAnalysis::Location(II->getArgOperand(1)),
00402                             MemLoc))
00403           return MemDepResult::getDef(II);
00404         continue;
00405       }
00406     }
00407 
00408     // Values depend on loads if the pointers are must aliased.  This means that
00409     // a load depends on another must aliased load from the same value.
00410     if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
00411       // Atomic loads have complications involved.
00412       // FIXME: This is overly conservative.
00413       if (!LI->isUnordered())
00414         return MemDepResult::getClobber(LI);
00415 
00416       AliasAnalysis::Location LoadLoc = AA->getLocation(LI);
00417 
00418       // If we found a pointer, check if it could be the same as our pointer.
00419       AliasAnalysis::AliasResult R = AA->alias(LoadLoc, MemLoc);
00420 
00421       if (isLoad) {
00422         if (R == AliasAnalysis::NoAlias) {
00423           // If this is an over-aligned integer load (for example,
00424           // "load i8* %P, align 4") see if it would obviously overlap with the
00425           // queried location if widened to a larger load (e.g. if the queried
00426           // location is 1 byte at P+1).  If so, return it as a load/load
00427           // clobber result, allowing the client to decide to widen the load if
00428           // it wants to.
00429           if (IntegerType *ITy = dyn_cast<IntegerType>(LI->getType()))
00430             if (LI->getAlignment()*8 > ITy->getPrimitiveSizeInBits() &&
00431                 isLoadLoadClobberIfExtendedToFullWidth(MemLoc, MemLocBase,
00432                                                        MemLocOffset, LI, DL))
00433               return MemDepResult::getClobber(Inst);
00434 
00435           continue;
00436         }
00437 
00438         // Must aliased loads are defs of each other.
00439         if (R == AliasAnalysis::MustAlias)
00440           return MemDepResult::getDef(Inst);
00441 
00442 #if 0 // FIXME: Temporarily disabled. GVN is cleverly rewriting loads
00443       // in terms of clobbering loads, but since it does this by looking
00444       // at the clobbering load directly, it doesn't know about any
00445       // phi translation that may have happened along the way.
00446 
00447         // If we have a partial alias, then return this as a clobber for the
00448         // client to handle.
00449         if (R == AliasAnalysis::PartialAlias)
00450           return MemDepResult::getClobber(Inst);
00451 #endif
00452 
00453         // Random may-alias loads don't depend on each other without a
00454         // dependence.
00455         continue;
00456       }
00457 
00458       // Stores don't depend on other no-aliased accesses.
00459       if (R == AliasAnalysis::NoAlias)
00460         continue;
00461 
00462       // Stores don't alias loads from read-only memory.
00463       if (AA->pointsToConstantMemory(LoadLoc))
00464         continue;
00465 
00466       // Stores depend on may/must aliased loads.
00467       return MemDepResult::getDef(Inst);
00468     }
00469 
00470     if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
00471       // Atomic stores have complications involved.
00472       // FIXME: This is overly conservative.
00473       if (!SI->isUnordered())
00474         return MemDepResult::getClobber(SI);
00475 
00476       // If alias analysis can tell that this store is guaranteed to not modify
00477       // the query pointer, ignore it.  Use getModRefInfo to handle cases where
00478       // the query pointer points to constant memory etc.
00479       if (AA->getModRefInfo(SI, MemLoc) == AliasAnalysis::NoModRef)
00480         continue;
00481 
00482       // Ok, this store might clobber the query pointer.  Check to see if it is
00483       // a must alias: in this case, we want to return this as a def.
00484       AliasAnalysis::Location StoreLoc = AA->getLocation(SI);
00485 
00486       // If we found a pointer, check if it could be the same as our pointer.
00487       AliasAnalysis::AliasResult R = AA->alias(StoreLoc, MemLoc);
00488 
00489       if (R == AliasAnalysis::NoAlias)
00490         continue;
00491       if (R == AliasAnalysis::MustAlias)
00492         return MemDepResult::getDef(Inst);
00493       if (isInvariantLoad)
00494        continue;
00495       return MemDepResult::getClobber(Inst);
00496     }
00497 
00498     // If this is an allocation, and if we know that the accessed pointer is to
00499     // the allocation, return Def.  This means that there is no dependence and
00500     // the access can be optimized based on that.  For example, a load could
00501     // turn into undef.
00502     // Note: Only determine this to be a malloc if Inst is the malloc call, not
00503     // a subsequent bitcast of the malloc call result.  There can be stores to
00504     // the malloced memory between the malloc call and its bitcast uses, and we
00505     // need to continue scanning until the malloc call.
00506     const TargetLibraryInfo *TLI = AA->getTargetLibraryInfo();
00507     if (isa<AllocaInst>(Inst) || isNoAliasFn(Inst, TLI)) {
00508       const Value *AccessPtr = GetUnderlyingObject(MemLoc.Ptr, DL);
00509 
00510       if (AccessPtr == Inst || AA->isMustAlias(Inst, AccessPtr))
00511         return MemDepResult::getDef(Inst);
00512       // Be conservative if the accessed pointer may alias the allocation.
00513       if (AA->alias(Inst, AccessPtr) != AliasAnalysis::NoAlias)
00514         return MemDepResult::getClobber(Inst);
00515       // If the allocation is not aliased and does not read memory (like
00516       // strdup), it is safe to ignore.
00517       if (isa<AllocaInst>(Inst) ||
00518           isMallocLikeFn(Inst, TLI) || isCallocLikeFn(Inst, TLI))
00519         continue;
00520     }
00521 
00522     // See if this instruction (e.g. a call or vaarg) mod/ref's the pointer.
00523     AliasAnalysis::ModRefResult MR = AA->getModRefInfo(Inst, MemLoc);
00524     // If necessary, perform additional analysis.
00525     if (MR == AliasAnalysis::ModRef)
00526       MR = AA->callCapturesBefore(Inst, MemLoc, DT);
00527     switch (MR) {
00528     case AliasAnalysis::NoModRef:
00529       // If the call has no effect on the queried pointer, just ignore it.
00530       continue;
00531     case AliasAnalysis::Mod:
00532       return MemDepResult::getClobber(Inst);
00533     case AliasAnalysis::Ref:
00534       // If the call is known to never store to the pointer, and if this is a
00535       // load query, we can safely ignore it (scan past it).
00536       if (isLoad)
00537         continue;
00538     default:
00539       // Otherwise, there is a potential dependence.  Return a clobber.
00540       return MemDepResult::getClobber(Inst);
00541     }
00542   }
00543 
00544   // No dependence found.  If this is the entry block of the function, it is
00545   // unknown, otherwise it is non-local.
00546   if (BB != &BB->getParent()->getEntryBlock())
00547     return MemDepResult::getNonLocal();
00548   return MemDepResult::getNonFuncLocal();
00549 }
00550 
00551 /// getDependency - Return the instruction on which a memory operation
00552 /// depends.
00553 MemDepResult MemoryDependenceAnalysis::getDependency(Instruction *QueryInst) {
00554   Instruction *ScanPos = QueryInst;
00555 
00556   // Check for a cached result
00557   MemDepResult &LocalCache = LocalDeps[QueryInst];
00558 
00559   // If the cached entry is non-dirty, just return it.  Note that this depends
00560   // on MemDepResult's default constructing to 'dirty'.
00561   if (!LocalCache.isDirty())
00562     return LocalCache;
00563 
00564   // Otherwise, if we have a dirty entry, we know we can start the scan at that
00565   // instruction, which may save us some work.
00566   if (Instruction *Inst = LocalCache.getInst()) {
00567     ScanPos = Inst;
00568 
00569     RemoveFromReverseMap(ReverseLocalDeps, Inst, QueryInst);
00570   }
00571 
00572   BasicBlock *QueryParent = QueryInst->getParent();
00573 
00574   // Do the scan.
00575   if (BasicBlock::iterator(QueryInst) == QueryParent->begin()) {
00576     // No dependence found.  If this is the entry block of the function, it is
00577     // unknown, otherwise it is non-local.
00578     if (QueryParent != &QueryParent->getParent()->getEntryBlock())
00579       LocalCache = MemDepResult::getNonLocal();
00580     else
00581       LocalCache = MemDepResult::getNonFuncLocal();
00582   } else {
00583     AliasAnalysis::Location MemLoc;
00584     AliasAnalysis::ModRefResult MR = GetLocation(QueryInst, MemLoc, AA);
00585     if (MemLoc.Ptr) {
00586       // If we can do a pointer scan, make it happen.
00587       bool isLoad = !(MR & AliasAnalysis::Mod);
00588       if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(QueryInst))
00589         isLoad |= II->getIntrinsicID() == Intrinsic::lifetime_start;
00590 
00591       LocalCache = getPointerDependencyFrom(MemLoc, isLoad, ScanPos,
00592                                             QueryParent, QueryInst);
00593     } else if (isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)) {
00594       CallSite QueryCS(QueryInst);
00595       bool isReadOnly = AA->onlyReadsMemory(QueryCS);
00596       LocalCache = getCallSiteDependencyFrom(QueryCS, isReadOnly, ScanPos,
00597                                              QueryParent);
00598     } else
00599       // Non-memory instruction.
00600       LocalCache = MemDepResult::getUnknown();
00601   }
00602 
00603   // Remember the result!
00604   if (Instruction *I = LocalCache.getInst())
00605     ReverseLocalDeps[I].insert(QueryInst);
00606 
00607   return LocalCache;
00608 }
00609 
00610 #ifndef NDEBUG
00611 /// AssertSorted - This method is used when -debug is specified to verify that
00612 /// cache arrays are properly kept sorted.
00613 static void AssertSorted(MemoryDependenceAnalysis::NonLocalDepInfo &Cache,
00614                          int Count = -1) {
00615   if (Count == -1) Count = Cache.size();
00616   if (Count == 0) return;
00617 
00618   for (unsigned i = 1; i != unsigned(Count); ++i)
00619     assert(!(Cache[i] < Cache[i-1]) && "Cache isn't sorted!");
00620 }
00621 #endif
00622 
00623 /// getNonLocalCallDependency - Perform a full dependency query for the
00624 /// specified call, returning the set of blocks that the value is
00625 /// potentially live across.  The returned set of results will include a
00626 /// "NonLocal" result for all blocks where the value is live across.
00627 ///
00628 /// This method assumes the instruction returns a "NonLocal" dependency
00629 /// within its own block.
00630 ///
00631 /// This returns a reference to an internal data structure that may be
00632 /// invalidated on the next non-local query or when an instruction is
00633 /// removed.  Clients must copy this data if they want it around longer than
00634 /// that.
00635 const MemoryDependenceAnalysis::NonLocalDepInfo &
00636 MemoryDependenceAnalysis::getNonLocalCallDependency(CallSite QueryCS) {
00637   assert(getDependency(QueryCS.getInstruction()).isNonLocal() &&
00638  "getNonLocalCallDependency should only be used on calls with non-local deps!");
00639   PerInstNLInfo &CacheP = NonLocalDeps[QueryCS.getInstruction()];
00640   NonLocalDepInfo &Cache = CacheP.first;
00641 
00642   /// DirtyBlocks - This is the set of blocks that need to be recomputed.  In
00643   /// the cached case, this can happen due to instructions being deleted etc. In
00644   /// the uncached case, this starts out as the set of predecessors we care
00645   /// about.
00646   SmallVector<BasicBlock*, 32> DirtyBlocks;
00647 
00648   if (!Cache.empty()) {
00649     // Okay, we have a cache entry.  If we know it is not dirty, just return it
00650     // with no computation.
00651     if (!CacheP.second) {
00652       ++NumCacheNonLocal;
00653       return Cache;
00654     }
00655 
00656     // If we already have a partially computed set of results, scan them to
00657     // determine what is dirty, seeding our initial DirtyBlocks worklist.
00658     for (NonLocalDepInfo::iterator I = Cache.begin(), E = Cache.end();
00659        I != E; ++I)
00660       if (I->getResult().isDirty())
00661         DirtyBlocks.push_back(I->getBB());
00662 
00663     // Sort the cache so that we can do fast binary search lookups below.
00664     std::sort(Cache.begin(), Cache.end());
00665 
00666     ++NumCacheDirtyNonLocal;
00667     //cerr << "CACHED CASE: " << DirtyBlocks.size() << " dirty: "
00668     //     << Cache.size() << " cached: " << *QueryInst;
00669   } else {
00670     // Seed DirtyBlocks with each of the preds of QueryInst's block.
00671     BasicBlock *QueryBB = QueryCS.getInstruction()->getParent();
00672     for (BasicBlock **PI = PredCache->GetPreds(QueryBB); *PI; ++PI)
00673       DirtyBlocks.push_back(*PI);
00674     ++NumUncacheNonLocal;
00675   }
00676 
00677   // isReadonlyCall - If this is a read-only call, we can be more aggressive.
00678   bool isReadonlyCall = AA->onlyReadsMemory(QueryCS);
00679 
00680   SmallPtrSet<BasicBlock*, 64> Visited;
00681 
00682   unsigned NumSortedEntries = Cache.size();
00683   DEBUG(AssertSorted(Cache));
00684 
00685   // Iterate while we still have blocks to update.
00686   while (!DirtyBlocks.empty()) {
00687     BasicBlock *DirtyBB = DirtyBlocks.back();
00688     DirtyBlocks.pop_back();
00689 
00690     // Already processed this block?
00691     if (!Visited.insert(DirtyBB))
00692       continue;
00693 
00694     // Do a binary search to see if we already have an entry for this block in
00695     // the cache set.  If so, find it.
00696     DEBUG(AssertSorted(Cache, NumSortedEntries));
00697     NonLocalDepInfo::iterator Entry =
00698       std::upper_bound(Cache.begin(), Cache.begin()+NumSortedEntries,
00699                        NonLocalDepEntry(DirtyBB));
00700     if (Entry != Cache.begin() && std::prev(Entry)->getBB() == DirtyBB)
00701       --Entry;
00702 
00703     NonLocalDepEntry *ExistingResult = nullptr;
00704     if (Entry != Cache.begin()+NumSortedEntries &&
00705         Entry->getBB() == DirtyBB) {
00706       // If we already have an entry, and if it isn't already dirty, the block
00707       // is done.
00708       if (!Entry->getResult().isDirty())
00709         continue;
00710 
00711       // Otherwise, remember this slot so we can update the value.
00712       ExistingResult = &*Entry;
00713     }
00714 
00715     // If the dirty entry has a pointer, start scanning from it so we don't have
00716     // to rescan the entire block.
00717     BasicBlock::iterator ScanPos = DirtyBB->end();
00718     if (ExistingResult) {
00719       if (Instruction *Inst = ExistingResult->getResult().getInst()) {
00720         ScanPos = Inst;
00721         // We're removing QueryInst's use of Inst.
00722         RemoveFromReverseMap(ReverseNonLocalDeps, Inst,
00723                              QueryCS.getInstruction());
00724       }
00725     }
00726 
00727     // Find out if this block has a local dependency for QueryInst.
00728     MemDepResult Dep;
00729 
00730     if (ScanPos != DirtyBB->begin()) {
00731       Dep = getCallSiteDependencyFrom(QueryCS, isReadonlyCall,ScanPos, DirtyBB);
00732     } else if (DirtyBB != &DirtyBB->getParent()->getEntryBlock()) {
00733       // No dependence found.  If this is the entry block of the function, it is
00734       // a clobber, otherwise it is unknown.
00735       Dep = MemDepResult::getNonLocal();
00736     } else {
00737       Dep = MemDepResult::getNonFuncLocal();
00738     }
00739 
00740     // If we had a dirty entry for the block, update it.  Otherwise, just add
00741     // a new entry.
00742     if (ExistingResult)
00743       ExistingResult->setResult(Dep);
00744     else
00745       Cache.push_back(NonLocalDepEntry(DirtyBB, Dep));
00746 
00747     // If the block has a dependency (i.e. it isn't completely transparent to
00748     // the value), remember the association!
00749     if (!Dep.isNonLocal()) {
00750       // Keep the ReverseNonLocalDeps map up to date so we can efficiently
00751       // update this when we remove instructions.
00752       if (Instruction *Inst = Dep.getInst())
00753         ReverseNonLocalDeps[Inst].insert(QueryCS.getInstruction());
00754     } else {
00755 
00756       // If the block *is* completely transparent to the load, we need to check
00757       // the predecessors of this block.  Add them to our worklist.
00758       for (BasicBlock **PI = PredCache->GetPreds(DirtyBB); *PI; ++PI)
00759         DirtyBlocks.push_back(*PI);
00760     }
00761   }
00762 
00763   return Cache;
00764 }
00765 
00766 /// getNonLocalPointerDependency - Perform a full dependency query for an
00767 /// access to the specified (non-volatile) memory location, returning the
00768 /// set of instructions that either define or clobber the value.
00769 ///
00770 /// This method assumes the pointer has a "NonLocal" dependency within its
00771 /// own block.
00772 ///
00773 void MemoryDependenceAnalysis::
00774 getNonLocalPointerDependency(const AliasAnalysis::Location &Loc, bool isLoad,
00775                              BasicBlock *FromBB,
00776                              SmallVectorImpl<NonLocalDepResult> &Result) {
00777   assert(Loc.Ptr->getType()->isPointerTy() &&
00778          "Can't get pointer deps of a non-pointer!");
00779   Result.clear();
00780 
00781   PHITransAddr Address(const_cast<Value *>(Loc.Ptr), DL);
00782 
00783   // This is the set of blocks we've inspected, and the pointer we consider in
00784   // each block.  Because of critical edges, we currently bail out if querying
00785   // a block with multiple different pointers.  This can happen during PHI
00786   // translation.
00787   DenseMap<BasicBlock*, Value*> Visited;
00788   if (!getNonLocalPointerDepFromBB(Address, Loc, isLoad, FromBB,
00789                                    Result, Visited, true))
00790     return;
00791   Result.clear();
00792   Result.push_back(NonLocalDepResult(FromBB,
00793                                      MemDepResult::getUnknown(),
00794                                      const_cast<Value *>(Loc.Ptr)));
00795 }
00796 
00797 /// GetNonLocalInfoForBlock - Compute the memdep value for BB with
00798 /// Pointer/PointeeSize using either cached information in Cache or by doing a
00799 /// lookup (which may use dirty cache info if available).  If we do a lookup,
00800 /// add the result to the cache.
00801 MemDepResult MemoryDependenceAnalysis::
00802 GetNonLocalInfoForBlock(const AliasAnalysis::Location &Loc,
00803                         bool isLoad, BasicBlock *BB,
00804                         NonLocalDepInfo *Cache, unsigned NumSortedEntries) {
00805 
00806   // Do a binary search to see if we already have an entry for this block in
00807   // the cache set.  If so, find it.
00808   NonLocalDepInfo::iterator Entry =
00809     std::upper_bound(Cache->begin(), Cache->begin()+NumSortedEntries,
00810                      NonLocalDepEntry(BB));
00811   if (Entry != Cache->begin() && (Entry-1)->getBB() == BB)
00812     --Entry;
00813 
00814   NonLocalDepEntry *ExistingResult = nullptr;
00815   if (Entry != Cache->begin()+NumSortedEntries && Entry->getBB() == BB)
00816     ExistingResult = &*Entry;
00817 
00818   // If we have a cached entry, and it is non-dirty, use it as the value for
00819   // this dependency.
00820   if (ExistingResult && !ExistingResult->getResult().isDirty()) {
00821     ++NumCacheNonLocalPtr;
00822     return ExistingResult->getResult();
00823   }
00824 
00825   // Otherwise, we have to scan for the value.  If we have a dirty cache
00826   // entry, start scanning from its position, otherwise we scan from the end
00827   // of the block.
00828   BasicBlock::iterator ScanPos = BB->end();
00829   if (ExistingResult && ExistingResult->getResult().getInst()) {
00830     assert(ExistingResult->getResult().getInst()->getParent() == BB &&
00831            "Instruction invalidated?");
00832     ++NumCacheDirtyNonLocalPtr;
00833     ScanPos = ExistingResult->getResult().getInst();
00834 
00835     // Eliminating the dirty entry from 'Cache', so update the reverse info.
00836     ValueIsLoadPair CacheKey(Loc.Ptr, isLoad);
00837     RemoveFromReverseMap(ReverseNonLocalPtrDeps, ScanPos, CacheKey);
00838   } else {
00839     ++NumUncacheNonLocalPtr;
00840   }
00841 
00842   // Scan the block for the dependency.
00843   MemDepResult Dep = getPointerDependencyFrom(Loc, isLoad, ScanPos, BB);
00844 
00845   // If we had a dirty entry for the block, update it.  Otherwise, just add
00846   // a new entry.
00847   if (ExistingResult)
00848     ExistingResult->setResult(Dep);
00849   else
00850     Cache->push_back(NonLocalDepEntry(BB, Dep));
00851 
00852   // If the block has a dependency (i.e. it isn't completely transparent to
00853   // the value), remember the reverse association because we just added it
00854   // to Cache!
00855   if (!Dep.isDef() && !Dep.isClobber())
00856     return Dep;
00857 
00858   // Keep the ReverseNonLocalPtrDeps map up to date so we can efficiently
00859   // update MemDep when we remove instructions.
00860   Instruction *Inst = Dep.getInst();
00861   assert(Inst && "Didn't depend on anything?");
00862   ValueIsLoadPair CacheKey(Loc.Ptr, isLoad);
00863   ReverseNonLocalPtrDeps[Inst].insert(CacheKey);
00864   return Dep;
00865 }
00866 
00867 /// SortNonLocalDepInfoCache - Sort the a NonLocalDepInfo cache, given a certain
00868 /// number of elements in the array that are already properly ordered.  This is
00869 /// optimized for the case when only a few entries are added.
00870 static void
00871 SortNonLocalDepInfoCache(MemoryDependenceAnalysis::NonLocalDepInfo &Cache,
00872                          unsigned NumSortedEntries) {
00873   switch (Cache.size() - NumSortedEntries) {
00874   case 0:
00875     // done, no new entries.
00876     break;
00877   case 2: {
00878     // Two new entries, insert the last one into place.
00879     NonLocalDepEntry Val = Cache.back();
00880     Cache.pop_back();
00881     MemoryDependenceAnalysis::NonLocalDepInfo::iterator Entry =
00882       std::upper_bound(Cache.begin(), Cache.end()-1, Val);
00883     Cache.insert(Entry, Val);
00884     // FALL THROUGH.
00885   }
00886   case 1:
00887     // One new entry, Just insert the new value at the appropriate position.
00888     if (Cache.size() != 1) {
00889       NonLocalDepEntry Val = Cache.back();
00890       Cache.pop_back();
00891       MemoryDependenceAnalysis::NonLocalDepInfo::iterator Entry =
00892         std::upper_bound(Cache.begin(), Cache.end(), Val);
00893       Cache.insert(Entry, Val);
00894     }
00895     break;
00896   default:
00897     // Added many values, do a full scale sort.
00898     std::sort(Cache.begin(), Cache.end());
00899     break;
00900   }
00901 }
00902 
00903 /// getNonLocalPointerDepFromBB - Perform a dependency query based on
00904 /// pointer/pointeesize starting at the end of StartBB.  Add any clobber/def
00905 /// results to the results vector and keep track of which blocks are visited in
00906 /// 'Visited'.
00907 ///
00908 /// This has special behavior for the first block queries (when SkipFirstBlock
00909 /// is true).  In this special case, it ignores the contents of the specified
00910 /// block and starts returning dependence info for its predecessors.
00911 ///
00912 /// This function returns false on success, or true to indicate that it could
00913 /// not compute dependence information for some reason.  This should be treated
00914 /// as a clobber dependence on the first instruction in the predecessor block.
00915 bool MemoryDependenceAnalysis::
00916 getNonLocalPointerDepFromBB(const PHITransAddr &Pointer,
00917                             const AliasAnalysis::Location &Loc,
00918                             bool isLoad, BasicBlock *StartBB,
00919                             SmallVectorImpl<NonLocalDepResult> &Result,
00920                             DenseMap<BasicBlock*, Value*> &Visited,
00921                             bool SkipFirstBlock) {
00922   // Look up the cached info for Pointer.
00923   ValueIsLoadPair CacheKey(Pointer.getAddr(), isLoad);
00924 
00925   // Set up a temporary NLPI value. If the map doesn't yet have an entry for
00926   // CacheKey, this value will be inserted as the associated value. Otherwise,
00927   // it'll be ignored, and we'll have to check to see if the cached size and
00928   // aa tags are consistent with the current query.
00929   NonLocalPointerInfo InitialNLPI;
00930   InitialNLPI.Size = Loc.Size;
00931   InitialNLPI.AATags = Loc.AATags;
00932 
00933   // Get the NLPI for CacheKey, inserting one into the map if it doesn't
00934   // already have one.
00935   std::pair<CachedNonLocalPointerInfo::iterator, bool> Pair =
00936     NonLocalPointerDeps.insert(std::make_pair(CacheKey, InitialNLPI));
00937   NonLocalPointerInfo *CacheInfo = &Pair.first->second;
00938 
00939   // If we already have a cache entry for this CacheKey, we may need to do some
00940   // work to reconcile the cache entry and the current query.
00941   if (!Pair.second) {
00942     if (CacheInfo->Size < Loc.Size) {
00943       // The query's Size is greater than the cached one. Throw out the
00944       // cached data and proceed with the query at the greater size.
00945       CacheInfo->Pair = BBSkipFirstBlockPair();
00946       CacheInfo->Size = Loc.Size;
00947       for (NonLocalDepInfo::iterator DI = CacheInfo->NonLocalDeps.begin(),
00948            DE = CacheInfo->NonLocalDeps.end(); DI != DE; ++DI)
00949         if (Instruction *Inst = DI->getResult().getInst())
00950           RemoveFromReverseMap(ReverseNonLocalPtrDeps, Inst, CacheKey);
00951       CacheInfo->NonLocalDeps.clear();
00952     } else if (CacheInfo->Size > Loc.Size) {
00953       // This query's Size is less than the cached one. Conservatively restart
00954       // the query using the greater size.
00955       return getNonLocalPointerDepFromBB(Pointer,
00956                                          Loc.getWithNewSize(CacheInfo->Size),
00957                                          isLoad, StartBB, Result, Visited,
00958                                          SkipFirstBlock);
00959     }
00960 
00961     // If the query's AATags are inconsistent with the cached one,
00962     // conservatively throw out the cached data and restart the query with
00963     // no tag if needed.
00964     if (CacheInfo->AATags != Loc.AATags) {
00965       if (CacheInfo->AATags) {
00966         CacheInfo->Pair = BBSkipFirstBlockPair();
00967         CacheInfo->AATags = AAMDNodes();
00968         for (NonLocalDepInfo::iterator DI = CacheInfo->NonLocalDeps.begin(),
00969              DE = CacheInfo->NonLocalDeps.end(); DI != DE; ++DI)
00970           if (Instruction *Inst = DI->getResult().getInst())
00971             RemoveFromReverseMap(ReverseNonLocalPtrDeps, Inst, CacheKey);
00972         CacheInfo->NonLocalDeps.clear();
00973       }
00974       if (Loc.AATags)
00975         return getNonLocalPointerDepFromBB(Pointer, Loc.getWithoutAATags(),
00976                                            isLoad, StartBB, Result, Visited,
00977                                            SkipFirstBlock);
00978     }
00979   }
00980 
00981   NonLocalDepInfo *Cache = &CacheInfo->NonLocalDeps;
00982 
00983   // If we have valid cached information for exactly the block we are
00984   // investigating, just return it with no recomputation.
00985   if (CacheInfo->Pair == BBSkipFirstBlockPair(StartBB, SkipFirstBlock)) {
00986     // We have a fully cached result for this query then we can just return the
00987     // cached results and populate the visited set.  However, we have to verify
00988     // that we don't already have conflicting results for these blocks.  Check
00989     // to ensure that if a block in the results set is in the visited set that
00990     // it was for the same pointer query.
00991     if (!Visited.empty()) {
00992       for (NonLocalDepInfo::iterator I = Cache->begin(), E = Cache->end();
00993            I != E; ++I) {
00994         DenseMap<BasicBlock*, Value*>::iterator VI = Visited.find(I->getBB());
00995         if (VI == Visited.end() || VI->second == Pointer.getAddr())
00996           continue;
00997 
00998         // We have a pointer mismatch in a block.  Just return clobber, saying
00999         // that something was clobbered in this result.  We could also do a
01000         // non-fully cached query, but there is little point in doing this.
01001         return true;
01002       }
01003     }
01004 
01005     Value *Addr = Pointer.getAddr();
01006     for (NonLocalDepInfo::iterator I = Cache->begin(), E = Cache->end();
01007          I != E; ++I) {
01008       Visited.insert(std::make_pair(I->getBB(), Addr));
01009       if (I->getResult().isNonLocal()) {
01010         continue;
01011       }
01012 
01013       if (!DT) {
01014         Result.push_back(NonLocalDepResult(I->getBB(),
01015                                            MemDepResult::getUnknown(),
01016                                            Addr));
01017       } else if (DT->isReachableFromEntry(I->getBB())) {
01018         Result.push_back(NonLocalDepResult(I->getBB(), I->getResult(), Addr));
01019       }
01020     }
01021     ++NumCacheCompleteNonLocalPtr;
01022     return false;
01023   }
01024 
01025   // Otherwise, either this is a new block, a block with an invalid cache
01026   // pointer or one that we're about to invalidate by putting more info into it
01027   // than its valid cache info.  If empty, the result will be valid cache info,
01028   // otherwise it isn't.
01029   if (Cache->empty())
01030     CacheInfo->Pair = BBSkipFirstBlockPair(StartBB, SkipFirstBlock);
01031   else
01032     CacheInfo->Pair = BBSkipFirstBlockPair();
01033 
01034   SmallVector<BasicBlock*, 32> Worklist;
01035   Worklist.push_back(StartBB);
01036 
01037   // PredList used inside loop.
01038   SmallVector<std::pair<BasicBlock*, PHITransAddr>, 16> PredList;
01039 
01040   // Keep track of the entries that we know are sorted.  Previously cached
01041   // entries will all be sorted.  The entries we add we only sort on demand (we
01042   // don't insert every element into its sorted position).  We know that we
01043   // won't get any reuse from currently inserted values, because we don't
01044   // revisit blocks after we insert info for them.
01045   unsigned NumSortedEntries = Cache->size();
01046   DEBUG(AssertSorted(*Cache));
01047 
01048   while (!Worklist.empty()) {
01049     BasicBlock *BB = Worklist.pop_back_val();
01050 
01051     // Skip the first block if we have it.
01052     if (!SkipFirstBlock) {
01053       // Analyze the dependency of *Pointer in FromBB.  See if we already have
01054       // been here.
01055       assert(Visited.count(BB) && "Should check 'visited' before adding to WL");
01056 
01057       // Get the dependency info for Pointer in BB.  If we have cached
01058       // information, we will use it, otherwise we compute it.
01059       DEBUG(AssertSorted(*Cache, NumSortedEntries));
01060       MemDepResult Dep = GetNonLocalInfoForBlock(Loc, isLoad, BB, Cache,
01061                                                  NumSortedEntries);
01062 
01063       // If we got a Def or Clobber, add this to the list of results.
01064       if (!Dep.isNonLocal()) {
01065         if (!DT) {
01066           Result.push_back(NonLocalDepResult(BB,
01067                                              MemDepResult::getUnknown(),
01068                                              Pointer.getAddr()));
01069           continue;
01070         } else if (DT->isReachableFromEntry(BB)) {
01071           Result.push_back(NonLocalDepResult(BB, Dep, Pointer.getAddr()));
01072           continue;
01073         }
01074       }
01075     }
01076 
01077     // If 'Pointer' is an instruction defined in this block, then we need to do
01078     // phi translation to change it into a value live in the predecessor block.
01079     // If not, we just add the predecessors to the worklist and scan them with
01080     // the same Pointer.
01081     if (!Pointer.NeedsPHITranslationFromBlock(BB)) {
01082       SkipFirstBlock = false;
01083       SmallVector<BasicBlock*, 16> NewBlocks;
01084       for (BasicBlock **PI = PredCache->GetPreds(BB); *PI; ++PI) {
01085         // Verify that we haven't looked at this block yet.
01086         std::pair<DenseMap<BasicBlock*,Value*>::iterator, bool>
01087           InsertRes = Visited.insert(std::make_pair(*PI, Pointer.getAddr()));
01088         if (InsertRes.second) {
01089           // First time we've looked at *PI.
01090           NewBlocks.push_back(*PI);
01091           continue;
01092         }
01093 
01094         // If we have seen this block before, but it was with a different
01095         // pointer then we have a phi translation failure and we have to treat
01096         // this as a clobber.
01097         if (InsertRes.first->second != Pointer.getAddr()) {
01098           // Make sure to clean up the Visited map before continuing on to
01099           // PredTranslationFailure.
01100           for (unsigned i = 0; i < NewBlocks.size(); i++)
01101             Visited.erase(NewBlocks[i]);
01102           goto PredTranslationFailure;
01103         }
01104       }
01105       Worklist.append(NewBlocks.begin(), NewBlocks.end());
01106       continue;
01107     }
01108 
01109     // We do need to do phi translation, if we know ahead of time we can't phi
01110     // translate this value, don't even try.
01111     if (!Pointer.IsPotentiallyPHITranslatable())
01112       goto PredTranslationFailure;
01113 
01114     // We may have added values to the cache list before this PHI translation.
01115     // If so, we haven't done anything to ensure that the cache remains sorted.
01116     // Sort it now (if needed) so that recursive invocations of
01117     // getNonLocalPointerDepFromBB and other routines that could reuse the cache
01118     // value will only see properly sorted cache arrays.
01119     if (Cache && NumSortedEntries != Cache->size()) {
01120       SortNonLocalDepInfoCache(*Cache, NumSortedEntries);
01121       NumSortedEntries = Cache->size();
01122     }
01123     Cache = nullptr;
01124 
01125     PredList.clear();
01126     for (BasicBlock **PI = PredCache->GetPreds(BB); *PI; ++PI) {
01127       BasicBlock *Pred = *PI;
01128       PredList.push_back(std::make_pair(Pred, Pointer));
01129 
01130       // Get the PHI translated pointer in this predecessor.  This can fail if
01131       // not translatable, in which case the getAddr() returns null.
01132       PHITransAddr &PredPointer = PredList.back().second;
01133       PredPointer.PHITranslateValue(BB, Pred, nullptr);
01134 
01135       Value *PredPtrVal = PredPointer.getAddr();
01136 
01137       // Check to see if we have already visited this pred block with another
01138       // pointer.  If so, we can't do this lookup.  This failure can occur
01139       // with PHI translation when a critical edge exists and the PHI node in
01140       // the successor translates to a pointer value different than the
01141       // pointer the block was first analyzed with.
01142       std::pair<DenseMap<BasicBlock*,Value*>::iterator, bool>
01143         InsertRes = Visited.insert(std::make_pair(Pred, PredPtrVal));
01144 
01145       if (!InsertRes.second) {
01146         // We found the pred; take it off the list of preds to visit.
01147         PredList.pop_back();
01148 
01149         // If the predecessor was visited with PredPtr, then we already did
01150         // the analysis and can ignore it.
01151         if (InsertRes.first->second == PredPtrVal)
01152           continue;
01153 
01154         // Otherwise, the block was previously analyzed with a different
01155         // pointer.  We can't represent the result of this case, so we just
01156         // treat this as a phi translation failure.
01157 
01158         // Make sure to clean up the Visited map before continuing on to
01159         // PredTranslationFailure.
01160         for (unsigned i = 0, n = PredList.size(); i < n; ++i)
01161           Visited.erase(PredList[i].first);
01162 
01163         goto PredTranslationFailure;
01164       }
01165     }
01166 
01167     // Actually process results here; this need to be a separate loop to avoid
01168     // calling getNonLocalPointerDepFromBB for blocks we don't want to return
01169     // any results for.  (getNonLocalPointerDepFromBB will modify our
01170     // datastructures in ways the code after the PredTranslationFailure label
01171     // doesn't expect.)
01172     for (unsigned i = 0, n = PredList.size(); i < n; ++i) {
01173       BasicBlock *Pred = PredList[i].first;
01174       PHITransAddr &PredPointer = PredList[i].second;
01175       Value *PredPtrVal = PredPointer.getAddr();
01176 
01177       bool CanTranslate = true;
01178       // If PHI translation was unable to find an available pointer in this
01179       // predecessor, then we have to assume that the pointer is clobbered in
01180       // that predecessor.  We can still do PRE of the load, which would insert
01181       // a computation of the pointer in this predecessor.
01182       if (!PredPtrVal)
01183         CanTranslate = false;
01184 
01185       // FIXME: it is entirely possible that PHI translating will end up with
01186       // the same value.  Consider PHI translating something like:
01187       // X = phi [x, bb1], [y, bb2].  PHI translating for bb1 doesn't *need*
01188       // to recurse here, pedantically speaking.
01189 
01190       // If getNonLocalPointerDepFromBB fails here, that means the cached
01191       // result conflicted with the Visited list; we have to conservatively
01192       // assume it is unknown, but this also does not block PRE of the load.
01193       if (!CanTranslate ||
01194           getNonLocalPointerDepFromBB(PredPointer,
01195                                       Loc.getWithNewPtr(PredPtrVal),
01196                                       isLoad, Pred,
01197                                       Result, Visited)) {
01198         // Add the entry to the Result list.
01199         NonLocalDepResult Entry(Pred, MemDepResult::getUnknown(), PredPtrVal);
01200         Result.push_back(Entry);
01201 
01202         // Since we had a phi translation failure, the cache for CacheKey won't
01203         // include all of the entries that we need to immediately satisfy future
01204         // queries.  Mark this in NonLocalPointerDeps by setting the
01205         // BBSkipFirstBlockPair pointer to null.  This requires reuse of the
01206         // cached value to do more work but not miss the phi trans failure.
01207         NonLocalPointerInfo &NLPI = NonLocalPointerDeps[CacheKey];
01208         NLPI.Pair = BBSkipFirstBlockPair();
01209         continue;
01210       }
01211     }
01212 
01213     // Refresh the CacheInfo/Cache pointer so that it isn't invalidated.
01214     CacheInfo = &NonLocalPointerDeps[CacheKey];
01215     Cache = &CacheInfo->NonLocalDeps;
01216     NumSortedEntries = Cache->size();
01217 
01218     // Since we did phi translation, the "Cache" set won't contain all of the
01219     // results for the query.  This is ok (we can still use it to accelerate
01220     // specific block queries) but we can't do the fastpath "return all
01221     // results from the set"  Clear out the indicator for this.
01222     CacheInfo->Pair = BBSkipFirstBlockPair();
01223     SkipFirstBlock = false;
01224     continue;
01225 
01226   PredTranslationFailure:
01227     // The following code is "failure"; we can't produce a sane translation
01228     // for the given block.  It assumes that we haven't modified any of
01229     // our datastructures while processing the current block.
01230 
01231     if (!Cache) {
01232       // Refresh the CacheInfo/Cache pointer if it got invalidated.
01233       CacheInfo = &NonLocalPointerDeps[CacheKey];
01234       Cache = &CacheInfo->NonLocalDeps;
01235       NumSortedEntries = Cache->size();
01236     }
01237 
01238     // Since we failed phi translation, the "Cache" set won't contain all of the
01239     // results for the query.  This is ok (we can still use it to accelerate
01240     // specific block queries) but we can't do the fastpath "return all
01241     // results from the set".  Clear out the indicator for this.
01242     CacheInfo->Pair = BBSkipFirstBlockPair();
01243 
01244     // If *nothing* works, mark the pointer as unknown.
01245     //
01246     // If this is the magic first block, return this as a clobber of the whole
01247     // incoming value.  Since we can't phi translate to one of the predecessors,
01248     // we have to bail out.
01249     if (SkipFirstBlock)
01250       return true;
01251 
01252     for (NonLocalDepInfo::reverse_iterator I = Cache->rbegin(); ; ++I) {
01253       assert(I != Cache->rend() && "Didn't find current block??");
01254       if (I->getBB() != BB)
01255         continue;
01256 
01257       assert(I->getResult().isNonLocal() &&
01258              "Should only be here with transparent block");
01259       I->setResult(MemDepResult::getUnknown());
01260       Result.push_back(NonLocalDepResult(I->getBB(), I->getResult(),
01261                                          Pointer.getAddr()));
01262       break;
01263     }
01264   }
01265 
01266   // Okay, we're done now.  If we added new values to the cache, re-sort it.
01267   SortNonLocalDepInfoCache(*Cache, NumSortedEntries);
01268   DEBUG(AssertSorted(*Cache));
01269   return false;
01270 }
01271 
01272 /// RemoveCachedNonLocalPointerDependencies - If P exists in
01273 /// CachedNonLocalPointerInfo, remove it.
01274 void MemoryDependenceAnalysis::
01275 RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair P) {
01276   CachedNonLocalPointerInfo::iterator It =
01277     NonLocalPointerDeps.find(P);
01278   if (It == NonLocalPointerDeps.end()) return;
01279 
01280   // Remove all of the entries in the BB->val map.  This involves removing
01281   // instructions from the reverse map.
01282   NonLocalDepInfo &PInfo = It->second.NonLocalDeps;
01283 
01284   for (unsigned i = 0, e = PInfo.size(); i != e; ++i) {
01285     Instruction *Target = PInfo[i].getResult().getInst();
01286     if (!Target) continue;  // Ignore non-local dep results.
01287     assert(Target->getParent() == PInfo[i].getBB());
01288 
01289     // Eliminating the dirty entry from 'Cache', so update the reverse info.
01290     RemoveFromReverseMap(ReverseNonLocalPtrDeps, Target, P);
01291   }
01292 
01293   // Remove P from NonLocalPointerDeps (which deletes NonLocalDepInfo).
01294   NonLocalPointerDeps.erase(It);
01295 }
01296 
01297 
01298 /// invalidateCachedPointerInfo - This method is used to invalidate cached
01299 /// information about the specified pointer, because it may be too
01300 /// conservative in memdep.  This is an optional call that can be used when
01301 /// the client detects an equivalence between the pointer and some other
01302 /// value and replaces the other value with ptr. This can make Ptr available
01303 /// in more places that cached info does not necessarily keep.
01304 void MemoryDependenceAnalysis::invalidateCachedPointerInfo(Value *Ptr) {
01305   // If Ptr isn't really a pointer, just ignore it.
01306   if (!Ptr->getType()->isPointerTy()) return;
01307   // Flush store info for the pointer.
01308   RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr, false));
01309   // Flush load info for the pointer.
01310   RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr, true));
01311 }
01312 
01313 /// invalidateCachedPredecessors - Clear the PredIteratorCache info.
01314 /// This needs to be done when the CFG changes, e.g., due to splitting
01315 /// critical edges.
01316 void MemoryDependenceAnalysis::invalidateCachedPredecessors() {
01317   PredCache->clear();
01318 }
01319 
01320 /// removeInstruction - Remove an instruction from the dependence analysis,
01321 /// updating the dependence of instructions that previously depended on it.
01322 /// This method attempts to keep the cache coherent using the reverse map.
01323 void MemoryDependenceAnalysis::removeInstruction(Instruction *RemInst) {
01324   // Walk through the Non-local dependencies, removing this one as the value
01325   // for any cached queries.
01326   NonLocalDepMapType::iterator NLDI = NonLocalDeps.find(RemInst);
01327   if (NLDI != NonLocalDeps.end()) {
01328     NonLocalDepInfo &BlockMap = NLDI->second.first;
01329     for (NonLocalDepInfo::iterator DI = BlockMap.begin(), DE = BlockMap.end();
01330          DI != DE; ++DI)
01331       if (Instruction *Inst = DI->getResult().getInst())
01332         RemoveFromReverseMap(ReverseNonLocalDeps, Inst, RemInst);
01333     NonLocalDeps.erase(NLDI);
01334   }
01335 
01336   // If we have a cached local dependence query for this instruction, remove it.
01337   //
01338   LocalDepMapType::iterator LocalDepEntry = LocalDeps.find(RemInst);
01339   if (LocalDepEntry != LocalDeps.end()) {
01340     // Remove us from DepInst's reverse set now that the local dep info is gone.
01341     if (Instruction *Inst = LocalDepEntry->second.getInst())
01342       RemoveFromReverseMap(ReverseLocalDeps, Inst, RemInst);
01343 
01344     // Remove this local dependency info.
01345     LocalDeps.erase(LocalDepEntry);
01346   }
01347 
01348   // If we have any cached pointer dependencies on this instruction, remove
01349   // them.  If the instruction has non-pointer type, then it can't be a pointer
01350   // base.
01351 
01352   // Remove it from both the load info and the store info.  The instruction
01353   // can't be in either of these maps if it is non-pointer.
01354   if (RemInst->getType()->isPointerTy()) {
01355     RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst, false));
01356     RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst, true));
01357   }
01358 
01359   // Loop over all of the things that depend on the instruction we're removing.
01360   //
01361   SmallVector<std::pair<Instruction*, Instruction*>, 8> ReverseDepsToAdd;
01362 
01363   // If we find RemInst as a clobber or Def in any of the maps for other values,
01364   // we need to replace its entry with a dirty version of the instruction after
01365   // it.  If RemInst is a terminator, we use a null dirty value.
01366   //
01367   // Using a dirty version of the instruction after RemInst saves having to scan
01368   // the entire block to get to this point.
01369   MemDepResult NewDirtyVal;
01370   if (!RemInst->isTerminator())
01371     NewDirtyVal = MemDepResult::getDirty(++BasicBlock::iterator(RemInst));
01372 
01373   ReverseDepMapType::iterator ReverseDepIt = ReverseLocalDeps.find(RemInst);
01374   if (ReverseDepIt != ReverseLocalDeps.end()) {
01375     SmallPtrSet<Instruction*, 4> &ReverseDeps = ReverseDepIt->second;
01376     // RemInst can't be the terminator if it has local stuff depending on it.
01377     assert(!ReverseDeps.empty() && !isa<TerminatorInst>(RemInst) &&
01378            "Nothing can locally depend on a terminator");
01379 
01380     for (SmallPtrSet<Instruction*, 4>::iterator I = ReverseDeps.begin(),
01381          E = ReverseDeps.end(); I != E; ++I) {
01382       Instruction *InstDependingOnRemInst = *I;
01383       assert(InstDependingOnRemInst != RemInst &&
01384              "Already removed our local dep info");
01385 
01386       LocalDeps[InstDependingOnRemInst] = NewDirtyVal;
01387 
01388       // Make sure to remember that new things depend on NewDepInst.
01389       assert(NewDirtyVal.getInst() && "There is no way something else can have "
01390              "a local dep on this if it is a terminator!");
01391       ReverseDepsToAdd.push_back(std::make_pair(NewDirtyVal.getInst(),
01392                                                 InstDependingOnRemInst));
01393     }
01394 
01395     ReverseLocalDeps.erase(ReverseDepIt);
01396 
01397     // Add new reverse deps after scanning the set, to avoid invalidating the
01398     // 'ReverseDeps' reference.
01399     while (!ReverseDepsToAdd.empty()) {
01400       ReverseLocalDeps[ReverseDepsToAdd.back().first]
01401         .insert(ReverseDepsToAdd.back().second);
01402       ReverseDepsToAdd.pop_back();
01403     }
01404   }
01405 
01406   ReverseDepIt = ReverseNonLocalDeps.find(RemInst);
01407   if (ReverseDepIt != ReverseNonLocalDeps.end()) {
01408     SmallPtrSet<Instruction*, 4> &Set = ReverseDepIt->second;
01409     for (SmallPtrSet<Instruction*, 4>::iterator I = Set.begin(), E = Set.end();
01410          I != E; ++I) {
01411       assert(*I != RemInst && "Already removed NonLocalDep info for RemInst");
01412 
01413       PerInstNLInfo &INLD = NonLocalDeps[*I];
01414       // The information is now dirty!
01415       INLD.second = true;
01416 
01417       for (NonLocalDepInfo::iterator DI = INLD.first.begin(),
01418            DE = INLD.first.end(); DI != DE; ++DI) {
01419         if (DI->getResult().getInst() != RemInst) continue;
01420 
01421         // Convert to a dirty entry for the subsequent instruction.
01422         DI->setResult(NewDirtyVal);
01423 
01424         if (Instruction *NextI = NewDirtyVal.getInst())
01425           ReverseDepsToAdd.push_back(std::make_pair(NextI, *I));
01426       }
01427     }
01428 
01429     ReverseNonLocalDeps.erase(ReverseDepIt);
01430 
01431     // Add new reverse deps after scanning the set, to avoid invalidating 'Set'
01432     while (!ReverseDepsToAdd.empty()) {
01433       ReverseNonLocalDeps[ReverseDepsToAdd.back().first]
01434         .insert(ReverseDepsToAdd.back().second);
01435       ReverseDepsToAdd.pop_back();
01436     }
01437   }
01438 
01439   // If the instruction is in ReverseNonLocalPtrDeps then it appears as a
01440   // value in the NonLocalPointerDeps info.
01441   ReverseNonLocalPtrDepTy::iterator ReversePtrDepIt =
01442     ReverseNonLocalPtrDeps.find(RemInst);
01443   if (ReversePtrDepIt != ReverseNonLocalPtrDeps.end()) {
01444     SmallPtrSet<ValueIsLoadPair, 4> &Set = ReversePtrDepIt->second;
01445     SmallVector<std::pair<Instruction*, ValueIsLoadPair>,8> ReversePtrDepsToAdd;
01446 
01447     for (SmallPtrSet<ValueIsLoadPair, 4>::iterator I = Set.begin(),
01448          E = Set.end(); I != E; ++I) {
01449       ValueIsLoadPair P = *I;
01450       assert(P.getPointer() != RemInst &&
01451              "Already removed NonLocalPointerDeps info for RemInst");
01452 
01453       NonLocalDepInfo &NLPDI = NonLocalPointerDeps[P].NonLocalDeps;
01454 
01455       // The cache is not valid for any specific block anymore.
01456       NonLocalPointerDeps[P].Pair = BBSkipFirstBlockPair();
01457 
01458       // Update any entries for RemInst to use the instruction after it.
01459       for (NonLocalDepInfo::iterator DI = NLPDI.begin(), DE = NLPDI.end();
01460            DI != DE; ++DI) {
01461         if (DI->getResult().getInst() != RemInst) continue;
01462 
01463         // Convert to a dirty entry for the subsequent instruction.
01464         DI->setResult(NewDirtyVal);
01465 
01466         if (Instruction *NewDirtyInst = NewDirtyVal.getInst())
01467           ReversePtrDepsToAdd.push_back(std::make_pair(NewDirtyInst, P));
01468       }
01469 
01470       // Re-sort the NonLocalDepInfo.  Changing the dirty entry to its
01471       // subsequent value may invalidate the sortedness.
01472       std::sort(NLPDI.begin(), NLPDI.end());
01473     }
01474 
01475     ReverseNonLocalPtrDeps.erase(ReversePtrDepIt);
01476 
01477     while (!ReversePtrDepsToAdd.empty()) {
01478       ReverseNonLocalPtrDeps[ReversePtrDepsToAdd.back().first]
01479         .insert(ReversePtrDepsToAdd.back().second);
01480       ReversePtrDepsToAdd.pop_back();
01481     }
01482   }
01483 
01484 
01485   assert(!NonLocalDeps.count(RemInst) && "RemInst got reinserted?");
01486   AA->deleteValue(RemInst);
01487   DEBUG(verifyRemoved(RemInst));
01488 }
01489 /// verifyRemoved - Verify that the specified instruction does not occur
01490 /// in our internal data structures.
01491 void MemoryDependenceAnalysis::verifyRemoved(Instruction *D) const {
01492   for (LocalDepMapType::const_iterator I = LocalDeps.begin(),
01493        E = LocalDeps.end(); I != E; ++I) {
01494     assert(I->first != D && "Inst occurs in data structures");
01495     assert(I->second.getInst() != D &&
01496            "Inst occurs in data structures");
01497   }
01498 
01499   for (CachedNonLocalPointerInfo::const_iterator I =NonLocalPointerDeps.begin(),
01500        E = NonLocalPointerDeps.end(); I != E; ++I) {
01501     assert(I->first.getPointer() != D && "Inst occurs in NLPD map key");
01502     const NonLocalDepInfo &Val = I->second.NonLocalDeps;
01503     for (NonLocalDepInfo::const_iterator II = Val.begin(), E = Val.end();
01504          II != E; ++II)
01505       assert(II->getResult().getInst() != D && "Inst occurs as NLPD value");
01506   }
01507 
01508   for (NonLocalDepMapType::const_iterator I = NonLocalDeps.begin(),
01509        E = NonLocalDeps.end(); I != E; ++I) {
01510     assert(I->first != D && "Inst occurs in data structures");
01511     const PerInstNLInfo &INLD = I->second;
01512     for (NonLocalDepInfo::const_iterator II = INLD.first.begin(),
01513          EE = INLD.first.end(); II  != EE; ++II)
01514       assert(II->getResult().getInst() != D && "Inst occurs in data structures");
01515   }
01516 
01517   for (ReverseDepMapType::const_iterator I = ReverseLocalDeps.begin(),
01518        E = ReverseLocalDeps.end(); I != E; ++I) {
01519     assert(I->first != D && "Inst occurs in data structures");
01520     for (SmallPtrSet<Instruction*, 4>::const_iterator II = I->second.begin(),
01521          EE = I->second.end(); II != EE; ++II)
01522       assert(*II != D && "Inst occurs in data structures");
01523   }
01524 
01525   for (ReverseDepMapType::const_iterator I = ReverseNonLocalDeps.begin(),
01526        E = ReverseNonLocalDeps.end();
01527        I != E; ++I) {
01528     assert(I->first != D && "Inst occurs in data structures");
01529     for (SmallPtrSet<Instruction*, 4>::const_iterator II = I->second.begin(),
01530          EE = I->second.end(); II != EE; ++II)
01531       assert(*II != D && "Inst occurs in data structures");
01532   }
01533 
01534   for (ReverseNonLocalPtrDepTy::const_iterator
01535        I = ReverseNonLocalPtrDeps.begin(),
01536        E = ReverseNonLocalPtrDeps.end(); I != E; ++I) {
01537     assert(I->first != D && "Inst occurs in rev NLPD map");
01538 
01539     for (SmallPtrSet<ValueIsLoadPair, 4>::const_iterator II = I->second.begin(),
01540          E = I->second.end(); II != E; ++II)
01541       assert(*II != ValueIsLoadPair(D, false) &&
01542              *II != ValueIsLoadPair(D, true) &&
01543              "Inst occurs in ReverseNonLocalPtrDeps map");
01544   }
01545 
01546 }