diff --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h --- a/llvm/include/llvm/Analysis/AliasAnalysis.h +++ b/llvm/include/llvm/Analysis/AliasAnalysis.h @@ -318,6 +318,13 @@ /// alias analysis implementations. AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB); + // facebook begin T130678741 + // I can be NULL, in which case we're querying as to whether an aliasing + // relationship holds through the entire function. + AliasResult aliasAt(const MemoryLocation &LocA, const MemoryLocation &LocB, + const Instruction *I); + // facebook end T130678741 + /// A convenience wrapper around the primary \c alias interface. AliasResult alias(const Value *V1, LocationSize V1Size, const Value *V2, LocationSize V2Size) { @@ -614,7 +621,12 @@ } AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, - AAQueryInfo &AAQI); + AAQueryInfo &AAQI); + // facebook begin T130678741 + AliasResult aliasAt(const MemoryLocation &LocA, const MemoryLocation &LocB, + const Instruction *I, AAQueryInfo &AAQI); + // facebook end T130678741 + bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal = false); ModRefInfo getModRefInfo(Instruction *I, const CallBase *Call2, @@ -746,6 +758,13 @@ virtual AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI) = 0; + // facebook begin T130678741 + // For flow-sensitive queries + virtual AliasResult aliasAt(const MemoryLocation &LocA, + const MemoryLocation &LocB, const Instruction *I, + AAQueryInfo &AAQI) = 0; + // facebook end T130678741 + /// Checks whether the given location points to constant memory, or if /// \p OrLocal is true whether it points to a local alloca. virtual bool pointsToConstantMemory(const MemoryLocation &Loc, @@ -804,6 +823,13 @@ return Result.alias(LocA, LocB, AAQI); } + // facebook begin T130678741 + AliasResult aliasAt(const MemoryLocation &LocA, const MemoryLocation &LocB, + const Instruction *I, AAQueryInfo &AAQI) override { + return Result.aliasAt(LocA, LocB, I, AAQI); + } + // facebook end T130678741 + bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal) override { return Result.pointsToConstantMemory(Loc, AAQI, OrLocal); @@ -859,6 +885,13 @@ return AliasResult::MayAlias; } + // facebook begin T130678741 + AliasResult aliasAt(const MemoryLocation &LocA, const MemoryLocation &LocB, + const Instruction *I, AAQueryInfo &AAQI) { + return AliasResult::MayAlias; + } + // facebook end T130678741 + bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal) { return false; diff --git a/llvm/include/llvm/Analysis/BasicAliasAnalysis.h b/llvm/include/llvm/Analysis/BasicAliasAnalysis.h --- a/llvm/include/llvm/Analysis/BasicAliasAnalysis.h +++ b/llvm/include/llvm/Analysis/BasicAliasAnalysis.h @@ -68,6 +68,12 @@ AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI); + // facebook begin T130678741 + AliasResult aliasAt(const MemoryLocation &LocA, const MemoryLocation &LocB, + const Instruction *, AAQueryInfo &AAQI) { + return alias(LocA, LocB, AAQI); + } + // facebook end T130678741 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI); diff --git a/llvm/include/llvm/Analysis/CFLAndersAliasAnalysis.h b/llvm/include/llvm/Analysis/CFLAndersAliasAnalysis.h --- a/llvm/include/llvm/Analysis/CFLAndersAliasAnalysis.h +++ b/llvm/include/llvm/Analysis/CFLAndersAliasAnalysis.h @@ -61,6 +61,12 @@ AliasResult query(const MemoryLocation &, const MemoryLocation &); AliasResult alias(const MemoryLocation &, const MemoryLocation &, AAQueryInfo &); + // facebook begin T130678741 + AliasResult aliasAt(const MemoryLocation &LocA, const MemoryLocation &LocB, + const Instruction *, AAQueryInfo &AAQI) { + return alias(LocA, LocB, AAQI); + } + // facebook end T130678741 private: /// Ensures that the given function is available in the cache. diff --git a/llvm/include/llvm/Analysis/CFLSteensAliasAnalysis.h b/llvm/include/llvm/Analysis/CFLSteensAliasAnalysis.h --- a/llvm/include/llvm/Analysis/CFLSteensAliasAnalysis.h +++ b/llvm/include/llvm/Analysis/CFLSteensAliasAnalysis.h @@ -86,6 +86,13 @@ return QueryResult; } + // facebook begin T130678741 + AliasResult aliasAt(const MemoryLocation &LocA, const MemoryLocation &LocB, + const Instruction *, AAQueryInfo &AAQI) { + return alias(LocA, LocB, AAQI); + } + // facebook end T130678741 + private: std::function GetTLI; diff --git a/llvm/include/llvm/Analysis/GlobalsModRef.h b/llvm/include/llvm/Analysis/GlobalsModRef.h --- a/llvm/include/llvm/Analysis/GlobalsModRef.h +++ b/llvm/include/llvm/Analysis/GlobalsModRef.h @@ -96,6 +96,13 @@ AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI); + // facebook begin T130678741 + AliasResult aliasAt(const MemoryLocation &LocA, const MemoryLocation &LocB, + const Instruction *, AAQueryInfo &AAQI) { + return alias(LocA, LocB, AAQI); + } + // facebook end T130678741 + using AAResultBase::getModRefInfo; ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI); diff --git a/llvm/include/llvm/Analysis/ObjCARCAliasAnalysis.h b/llvm/include/llvm/Analysis/ObjCARCAliasAnalysis.h --- a/llvm/include/llvm/Analysis/ObjCARCAliasAnalysis.h +++ b/llvm/include/llvm/Analysis/ObjCARCAliasAnalysis.h @@ -52,6 +52,12 @@ AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI); + // facebook begin T130678741 + AliasResult aliasAt(const MemoryLocation &LocA, const MemoryLocation &LocB, + const Instruction *, AAQueryInfo &AAQI) { + return alias(LocA, LocB, AAQI); + } + // facebook end T130678741 bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal); diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionAliasAnalysis.h b/llvm/include/llvm/Analysis/ScalarEvolutionAliasAnalysis.h --- a/llvm/include/llvm/Analysis/ScalarEvolutionAliasAnalysis.h +++ b/llvm/include/llvm/Analysis/ScalarEvolutionAliasAnalysis.h @@ -34,6 +34,13 @@ AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI); + // facebook begin T130678741 + AliasResult aliasAt(const MemoryLocation &LocA, const MemoryLocation &LocB, + const Instruction *, AAQueryInfo &AAQI) { + return alias(LocA, LocB, AAQI); + } + // facebook end T130678741 + bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv); diff --git a/llvm/include/llvm/Analysis/ScopedNoAliasAA.h b/llvm/include/llvm/Analysis/ScopedNoAliasAA.h --- a/llvm/include/llvm/Analysis/ScopedNoAliasAA.h +++ b/llvm/include/llvm/Analysis/ScopedNoAliasAA.h @@ -38,6 +38,12 @@ AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI); + // facebook begin T130678741 + AliasResult aliasAt(const MemoryLocation &LocA, const MemoryLocation &LocB, + const Instruction *, AAQueryInfo &AAQI) { + return alias(LocA, LocB, AAQI); + } + // facebook end T130678741 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI); ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2, diff --git a/llvm/include/llvm/Analysis/TypeBasedAliasAnalysis.h b/llvm/include/llvm/Analysis/TypeBasedAliasAnalysis.h --- a/llvm/include/llvm/Analysis/TypeBasedAliasAnalysis.h +++ b/llvm/include/llvm/Analysis/TypeBasedAliasAnalysis.h @@ -40,6 +40,13 @@ AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI); + // facebook begin T130678741 + AliasResult aliasAt(const MemoryLocation &LocA, const MemoryLocation &LocB, + const Instruction *, AAQueryInfo &AAQI) { + return alias(LocA, LocB, AAQI); + } + // facebook end T130678741 + bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal); MemoryEffects getMemoryEffects(const CallBase *Call, AAQueryInfo &AAQI); diff --git a/llvm/lib/Analysis/AliasAnalysis.cpp b/llvm/lib/Analysis/AliasAnalysis.cpp --- a/llvm/lib/Analysis/AliasAnalysis.cpp +++ b/llvm/lib/Analysis/AliasAnalysis.cpp @@ -112,6 +112,13 @@ AliasResult AAResults::alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI) { + return aliasAt(LocA, LocB, nullptr, AAQI); // facebook T130678741 +} + +// facebook begin T130678741 +AliasResult AAResults::aliasAt(const MemoryLocation &LocA, + const MemoryLocation &LocB, const Instruction *I, + AAQueryInfo &AAQI) { AliasResult Result = AliasResult::MayAlias; if (EnableAATrace) { @@ -123,7 +130,11 @@ AAQI.Depth++; for (const auto &AA : AAs) { - Result = AA->alias(LocA, LocB, AAQI); + if (I) { + Result = AA->aliasAt(LocA, LocB, I, AAQI); + } else { + Result = AA->alias(LocA, LocB, AAQI); + } if (Result != AliasResult::MayAlias) break; } @@ -146,6 +157,7 @@ } return Result; } +// facebook end T130678741 bool AAResults::pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal) { @@ -244,7 +256,7 @@ continue; unsigned ArgIdx = I.index(); MemoryLocation ArgLoc = MemoryLocation::getForArgument(Call, ArgIdx, TLI); - AliasResult ArgAlias = alias(ArgLoc, Loc, AAQI); + AliasResult ArgAlias = aliasAt(ArgLoc, Loc, Call, AAQI); if (ArgAlias != AliasResult::NoAlias) AllArgsMask |= getArgModRefInfo(Call, ArgIdx); } @@ -483,7 +495,10 @@ // If the load address doesn't alias the given address, it doesn't read // or write the specified memory. if (Loc.Ptr) { - AliasResult AR = alias(MemoryLocation::get(L), Loc, AAQI); + // facebook begin T130678741 + AliasResult AR = + aliasAt(MemoryLocation::get(L), Loc, L, AAQI); + // facebook end T130678741 if (AR == AliasResult::NoAlias) return ModRefInfo::NoModRef; } @@ -504,7 +519,9 @@ return ModRefInfo::ModRef; if (Loc.Ptr) { - AliasResult AR = alias(MemoryLocation::get(S), Loc, AAQI); + // facebook begin T130678741 + AliasResult AR = aliasAt(MemoryLocation::get(S), Loc, S, AAQI); + // facebook end T130678741 // If the store address cannot alias the pointer in question, then the // specified memory cannot be modified by the store. if (AR == AliasResult::NoAlias) @@ -546,7 +563,9 @@ const MemoryLocation &Loc, AAQueryInfo &AAQI) { if (Loc.Ptr) { - AliasResult AR = alias(MemoryLocation::get(V), Loc, AAQI); + // facebook begin T130678741 + AliasResult AR = aliasAt(MemoryLocation::get(V), Loc, V, AAQI); + // facebook end T130678741 // If the va_arg address cannot alias the pointer in question, then the // specified memory cannot be accessed by the va_arg. if (AR == AliasResult::NoAlias) @@ -616,7 +635,9 @@ return ModRefInfo::ModRef; if (Loc.Ptr) { - AliasResult AR = alias(MemoryLocation::get(CX), Loc, AAQI); + // facebook begin T130678741 + AliasResult AR = aliasAt(MemoryLocation::get(CX), Loc, CX, AAQI); + // facebook end T130678741 // If the cmpxchg address does not alias the location, it does not access // it. if (AR == AliasResult::NoAlias) @@ -640,7 +661,9 @@ return ModRefInfo::ModRef; if (Loc.Ptr) { - AliasResult AR = alias(MemoryLocation::get(RMW), Loc, AAQI); + // facebook begin T130678741 + AliasResult AR = aliasAt(MemoryLocation::get(RMW), Loc, RMW, AAQI); + // facebook end T130678741 // If the atomicrmw address does not alias the location, it does not access // it. if (AR == AliasResult::NoAlias) @@ -728,9 +751,11 @@ !Call->isByValArgument(ArgNo))) continue; - AliasResult AR = alias( + // facebook begin T130678741 + AliasResult AR = aliasAt( MemoryLocation::getBeforeOrAfter(*CI), - MemoryLocation::getBeforeOrAfter(Object), AAQI); + MemoryLocation::getBeforeOrAfter(Object), Call, AAQI); + // facebook end T130678741 // If this is a no-capture pointer argument, see if we can tell that it // is impossible to alias the pointer we're checking. If not, we have to // assume that the call could touch the pointer, even though it doesn't