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