llvm.org GIT mirror llvm / 5bfa50e
[AliasAnalysis] Second prototype to cache BasicAA / anyAA state. Summary: Adding contained caching to AliasAnalysis. BasicAA is currently the only one using it. AA changes: - This patch is pulling the caches from BasicAAResults to AAResults, meaning the getModRefInfo call benefits from the IsCapturedCache as well when in "batch mode". - All AAResultBase implementations add the QueryInfo member to all APIs. AAResults APIs maintain wrapper APIs such that all alias()/getModRefInfo call sites are unchanged. - AA now provides a BatchAAResults type as a wrapper to AAResults. It keeps the AAResults instance and a QueryInfo instantiated to batch mode. It delegates all work to the AAResults instance with the batched QueryInfo. More API wrappers may be needed in BatchAAResults; only the minimum needed is currently added. MemorySSA changes: - All walkers are now templated on the AA used (AliasAnalysis=AAResults or BatchAAResults). - At build time, we optimize uses; now we create a local walker (lives only as long as OptimizeUses does) using BatchAAResults. - All Walkers have an internal AA and only use that now, never the AA in MemorySSA. The Walkers receive the AA they will use when built. - The walker we use for queries after the build is instantiated on AliasAnalysis and is built after building MemorySSA and setting AA. - All static methods doing walking are now templated on AliasAnalysisType if they are used both during build and after. If used only during build, the method now only takes a BatchAAResults. If used only after build, the method now takes an AliasAnalysis. Subscribers: sanjoy, arsenm, jvesely, nhaehnle, jlebar, george.burgess.iv, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59315 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356783 91177308-0d34-0410-b5e6-96231b3b80d8 Alina Sbirlea 5 months ago
23 changed file(s) with 595 addition(s) and 335 deletion(s). Raw diff Collapse all Expand all
3636 #ifndef LLVM_ANALYSIS_ALIASANALYSIS_H
3737 #define LLVM_ANALYSIS_ALIASANALYSIS_H
3838
39 #include "llvm/ADT/DenseMap.h"
3940 #include "llvm/ADT/None.h"
4041 #include "llvm/ADT/Optional.h"
4142 #include "llvm/ADT/SmallVector.h"
284285 return ModRefInfo(FMRB & static_cast(ModRefInfo::ModRef));
285286 }
286287
288 /// This class stores info we want to provide to or retain within an alias
289 /// query. By default, the root query is stateless and starts with a freshly
290 /// constructed info object. Specific alias analyses can use this query info to
291 /// store per-query state that is important for recursive or nested queries to
292 /// avoid recomputing. To enable preserving this state across multiple queries
293 /// where safe (due to the IR not changing), use a `BatchAAResults` wrapper.
294 /// The information stored in an `AAQueryInfo` is currently limitted to the
295 /// caches used by BasicAA, but can further be extended to fit other AA needs.
296 class AAQueryInfo {
297 public:
298 using LocPair = std::pair;
299 using AliasCacheT = SmallDenseMap;
300 AliasCacheT AliasCache;
301
302 using IsCapturedCacheT = SmallDenseMap;
303 IsCapturedCacheT IsCapturedCache;
304
305 AAQueryInfo() : AliasCache(), IsCapturedCache() {}
306 };
307
308 class BatchAAResults;
309
287310 class AAResults {
288311 public:
289312 // Make these results default constructable and movable. We have to spell
598621 /// helpers above.
599622 ModRefInfo getModRefInfo(const Instruction *I,
600623 const Optional &OptLoc) {
601 if (OptLoc == None) {
602 if (const auto *Call = dyn_cast(I)) {
603 return createModRefInfo(getModRefBehavior(Call));
604 }
605 }
606
607 const MemoryLocation &Loc = OptLoc.getValueOr(MemoryLocation());
608
609 switch (I->getOpcode()) {
610 case Instruction::VAArg: return getModRefInfo((const VAArgInst*)I, Loc);
611 case Instruction::Load: return getModRefInfo((const LoadInst*)I, Loc);
612 case Instruction::Store: return getModRefInfo((const StoreInst*)I, Loc);
613 case Instruction::Fence: return getModRefInfo((const FenceInst*)I, Loc);
614 case Instruction::AtomicCmpXchg:
615 return getModRefInfo((const AtomicCmpXchgInst*)I, Loc);
616 case Instruction::AtomicRMW:
617 return getModRefInfo((const AtomicRMWInst*)I, Loc);
618 case Instruction::Call: return getModRefInfo((const CallInst*)I, Loc);
619 case Instruction::Invoke: return getModRefInfo((const InvokeInst*)I,Loc);
620 case Instruction::CatchPad:
621 return getModRefInfo((const CatchPadInst *)I, Loc);
622 case Instruction::CatchRet:
623 return getModRefInfo((const CatchReturnInst *)I, Loc);
624 default:
625 return ModRefInfo::NoModRef;
626 }
624 AAQueryInfo AAQIP;
625 return getModRefInfo(I, OptLoc, AAQIP);
627626 }
628627
629628 /// A convenience wrapper for constructing the memory location.
690689 }
691690
692691 private:
692 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
693 AAQueryInfo &AAQI);
694 bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
695 bool OrLocal = false);
696 ModRefInfo getModRefInfo(Instruction *I, const CallBase *Call2,
697 AAQueryInfo &AAQIP);
698 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
699 AAQueryInfo &AAQI);
700 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
701 AAQueryInfo &AAQI);
702 ModRefInfo getModRefInfo(const VAArgInst *V, const MemoryLocation &Loc,
703 AAQueryInfo &AAQI);
704 ModRefInfo getModRefInfo(const LoadInst *L, const MemoryLocation &Loc,
705 AAQueryInfo &AAQI);
706 ModRefInfo getModRefInfo(const StoreInst *S, const MemoryLocation &Loc,
707 AAQueryInfo &AAQI);
708 ModRefInfo getModRefInfo(const FenceInst *S, const MemoryLocation &Loc,
709 AAQueryInfo &AAQI);
710 ModRefInfo getModRefInfo(const AtomicCmpXchgInst *CX,
711 const MemoryLocation &Loc, AAQueryInfo &AAQI);
712 ModRefInfo getModRefInfo(const AtomicRMWInst *RMW, const MemoryLocation &Loc,
713 AAQueryInfo &AAQI);
714 ModRefInfo getModRefInfo(const CatchPadInst *I, const MemoryLocation &Loc,
715 AAQueryInfo &AAQI);
716 ModRefInfo getModRefInfo(const CatchReturnInst *I, const MemoryLocation &Loc,
717 AAQueryInfo &AAQI);
718 ModRefInfo getModRefInfo(const Instruction *I,
719 const Optional &OptLoc,
720 AAQueryInfo &AAQIP) {
721 if (OptLoc == None) {
722 if (const auto *Call = dyn_cast(I)) {
723 return createModRefInfo(getModRefBehavior(Call));
724 }
725 }
726
727 const MemoryLocation &Loc = OptLoc.getValueOr(MemoryLocation());
728
729 switch (I->getOpcode()) {
730 case Instruction::VAArg:
731 return getModRefInfo((const VAArgInst *)I, Loc, AAQIP);
732 case Instruction::Load:
733 return getModRefInfo((const LoadInst *)I, Loc, AAQIP);
734 case Instruction::Store:
735 return getModRefInfo((const StoreInst *)I, Loc, AAQIP);
736 case Instruction::Fence:
737 return getModRefInfo((const FenceInst *)I, Loc, AAQIP);
738 case Instruction::AtomicCmpXchg:
739 return getModRefInfo((const AtomicCmpXchgInst *)I, Loc, AAQIP);
740 case Instruction::AtomicRMW:
741 return getModRefInfo((const AtomicRMWInst *)I, Loc, AAQIP);
742 case Instruction::Call:
743 return getModRefInfo((const CallInst *)I, Loc, AAQIP);
744 case Instruction::Invoke:
745 return getModRefInfo((const InvokeInst *)I, Loc, AAQIP);
746 case Instruction::CatchPad:
747 return getModRefInfo((const CatchPadInst *)I, Loc, AAQIP);
748 case Instruction::CatchRet:
749 return getModRefInfo((const CatchReturnInst *)I, Loc, AAQIP);
750 default:
751 return ModRefInfo::NoModRef;
752 }
753 }
754
693755 class Concept;
694756
695757 template class Model;
701763 std::vector> AAs;
702764
703765 std::vector AADeps;
766
767 friend class BatchAAResults;
768 };
769
770 /// This class is a wrapper over an AAResults, and it is intended to be used
771 /// only when there are no IR changes inbetween queries. BatchAAResults is
772 /// reusing the same `AAQueryInfo` to preserve the state across queries,
773 /// esentially making AA work in "batch mode". The internal state cannot be
774 /// cleared, so to go "out-of-batch-mode", the user must either use AAResults,
775 /// or create a new BatchAAResults.
776 class BatchAAResults {
777 AAResults &AA;
778 AAQueryInfo AAQI;
779
780 public:
781 BatchAAResults(AAResults &AAR) : AA(AAR), AAQI() {}
782 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
783 return AA.alias(LocA, LocB, AAQI);
784 }
785 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal = false) {
786 return AA.pointsToConstantMemory(Loc, AAQI, OrLocal);
787 }
788 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc) {
789 return AA.getModRefInfo(Call, Loc, AAQI);
790 }
791 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2) {
792 return AA.getModRefInfo(Call1, Call2, AAQI);
793 }
794 ModRefInfo getModRefInfo(const Instruction *I,
795 const Optional &OptLoc) {
796 return AA.getModRefInfo(I, OptLoc, AAQI);
797 }
798 ModRefInfo getModRefInfo(Instruction *I, const CallBase *Call2) {
799 return AA.getModRefInfo(I, Call2, AAQI);
800 }
801 ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) {
802 return AA.getArgModRefInfo(Call, ArgIdx);
803 }
804 FunctionModRefBehavior getModRefBehavior(const CallBase *Call) {
805 return AA.getModRefBehavior(Call);
806 }
704807 };
705808
706809 /// Temporary typedef for legacy code that uses a generic \c AliasAnalysis
733836 /// each other. This is the interface that must be implemented by specific
734837 /// alias analysis implementations.
735838 virtual AliasResult alias(const MemoryLocation &LocA,
736 const MemoryLocation &LocB) = 0;
839 const MemoryLocation &LocB, AAQueryInfo &AAQI) = 0;
737840
738841 /// Checks whether the given location points to constant memory, or if
739842 /// \p OrLocal is true whether it points to a local alloca.
740843 virtual bool pointsToConstantMemory(const MemoryLocation &Loc,
741 bool OrLocal) = 0;
844 AAQueryInfo &AAQI, bool OrLocal) = 0;
742845
743846 /// @}
744847 //===--------------------------------------------------------------------===//
762865 /// getModRefInfo (for call sites) - Return information about whether
763866 /// a particular call site modifies or reads the specified memory location.
764867 virtual ModRefInfo getModRefInfo(const CallBase *Call,
765 const MemoryLocation &Loc) = 0;
868 const MemoryLocation &Loc,
869 AAQueryInfo &AAQI) = 0;
766870
767871 /// Return information about whether two call sites may refer to the same set
768872 /// of memory locations. See the AA documentation for details:
769873 /// http://llvm.org/docs/AliasAnalysis.html#ModRefInfo
770 virtual ModRefInfo getModRefInfo(const CallBase *Call1,
771 const CallBase *Call2) = 0;
874 virtual ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
875 AAQueryInfo &AAQI) = 0;
772876
773877 /// @}
774878 };
790894
791895 void setAAResults(AAResults *NewAAR) override { Result.setAAResults(NewAAR); }
792896
793 AliasResult alias(const MemoryLocation &LocA,
794 const MemoryLocation &LocB) override {
795 return Result.alias(LocA, LocB);
796 }
797
798 bool pointsToConstantMemory(const MemoryLocation &Loc,
897 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
898 AAQueryInfo &AAQI) override {
899 return Result.alias(LocA, LocB, AAQI);
900 }
901
902 bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
799903 bool OrLocal) override {
800 return Result.pointsToConstantMemory(Loc, OrLocal);
904 return Result.pointsToConstantMemory(Loc, AAQI, OrLocal);
801905 }
802906
803907 ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) override {
812916 return Result.getModRefBehavior(F);
813917 }
814918
815 ModRefInfo getModRefInfo(const CallBase *Call,
816 const MemoryLocation &Loc) override {
817 return Result.getModRefInfo(Call, Loc);
818 }
819
820 ModRefInfo getModRefInfo(const CallBase *Call1,
821 const CallBase *Call2) override {
822 return Result.getModRefInfo(Call1, Call2);
919 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
920 AAQueryInfo &AAQI) override {
921 return Result.getModRefInfo(Call, Loc, AAQI);
922 }
923
924 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
925 AAQueryInfo &AAQI) override {
926 return Result.getModRefInfo(Call1, Call2, AAQI);
823927 }
824928 };
825929
865969 AAResultsProxy(AAResults *AAR, DerivedT &CurrentResult)
866970 : AAR(AAR), CurrentResult(CurrentResult) {}
867971
868 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
869 return AAR ? AAR->alias(LocA, LocB) : CurrentResult.alias(LocA, LocB);
972 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
973 AAQueryInfo &AAQI) {
974 return AAR ? AAR->alias(LocA, LocB, AAQI)
975 : CurrentResult.alias(LocA, LocB, AAQI);
870976 }
871977
872 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal) {
873 return AAR ? AAR->pointsToConstantMemory(Loc, OrLocal)
874 : CurrentResult.pointsToConstantMemory(Loc, OrLocal);
978 bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
979 bool OrLocal) {
980 return AAR ? AAR->pointsToConstantMemory(Loc, AAQI, OrLocal)
981 : CurrentResult.pointsToConstantMemory(Loc, AAQI, OrLocal);
875982 }
876983
877984 ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) {
888995 return AAR ? AAR->getModRefBehavior(F) : CurrentResult.getModRefBehavior(F);
889996 }
890997
891 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc) {
892 return AAR ? AAR->getModRefInfo(Call, Loc)
893 : CurrentResult.getModRefInfo(Call, Loc);
998 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
999 AAQueryInfo &AAQI) {
1000 return AAR ? AAR->getModRefInfo(Call, Loc, AAQI)
1001 : CurrentResult.getModRefInfo(Call, Loc, AAQI);
8941002 }
8951003
896 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2) {
897 return AAR ? AAR->getModRefInfo(Call1, Call2)
898 : CurrentResult.getModRefInfo(Call1, Call2);
1004 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
1005 AAQueryInfo &AAQI) {
1006 return AAR ? AAR->getModRefInfo(Call1, Call2, AAQI)
1007 : CurrentResult.getModRefInfo(Call1, Call2, AAQI);
8991008 }
9001009 };
9011010
9191028 AAResultsProxy getBestAAResults() { return AAResultsProxy(AAR, derived()); }
9201029
9211030 public:
922 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
1031 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
1032 AAQueryInfo &AAQI) {
9231033 return MayAlias;
9241034 }
9251035
926 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal) {
1036 bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
1037 bool OrLocal) {
9271038 return false;
9281039 }
9291040
9391050 return FMRB_UnknownModRefBehavior;
9401051 }
9411052
942 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc) {
1053 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
1054 AAQueryInfo &AAQI) {
9431055 return ModRefInfo::ModRef;
9441056 }
9451057
946 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2) {
1058 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
1059 AAQueryInfo &AAQI) {
9471060 return ModRefInfo::ModRef;
9481061 }
9491062 };
8080 bool invalidate(Function &Fn, const PreservedAnalyses &PA,
8181 FunctionAnalysisManager::Invalidator &Inv);
8282
83 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
84
85 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc);
86
87 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2);
83 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
84 AAQueryInfo &AAQI);
85
86 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
87 AAQueryInfo &AAQI);
88
89 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
90 AAQueryInfo &AAQI);
8891
8992 /// Chases pointers until we find a (constant global) or not.
90 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal);
93 bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
94 bool OrLocal);
9195
9296 /// Get the location associated with a pointer argument of a callsite.
9397 ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx);
138142 // Scaled variable (non-constant) indices.
139143 SmallVector VarIndices;
140144 };
141
142 /// Track alias queries to guard against recursion.
143 using LocPair = std::pair;
144 using AliasCacheTy = SmallDenseMap;
145 AliasCacheTy AliasCache;
146 using IsCapturedCacheTy = SmallDenseMap;
147 IsCapturedCacheTy IsCapturedCache;
148145
149146 /// Tracks phi nodes we have visited.
150147 ///
200197 AliasResult aliasGEP(const GEPOperator *V1, LocationSize V1Size,
201198 const AAMDNodes &V1AAInfo, const Value *V2,
202199 LocationSize V2Size, const AAMDNodes &V2AAInfo,
203 const Value *UnderlyingV1, const Value *UnderlyingV2);
200 const Value *UnderlyingV1, const Value *UnderlyingV2,
201 AAQueryInfo &AAQI);
204202
205203 AliasResult aliasPHI(const PHINode *PN, LocationSize PNSize,
206204 const AAMDNodes &PNAAInfo, const Value *V2,
207205 LocationSize V2Size, const AAMDNodes &V2AAInfo,
208 const Value *UnderV2);
206 const Value *UnderV2, AAQueryInfo &AAQI);
209207
210208 AliasResult aliasSelect(const SelectInst *SI, LocationSize SISize,
211209 const AAMDNodes &SIAAInfo, const Value *V2,
212210 LocationSize V2Size, const AAMDNodes &V2AAInfo,
213 const Value *UnderV2);
211 const Value *UnderV2, AAQueryInfo &AAQI);
214212
215213 AliasResult aliasCheck(const Value *V1, LocationSize V1Size,
216214 AAMDNodes V1AATag, const Value *V2,
217215 LocationSize V2Size, AAMDNodes V2AATag,
218 const Value *O1 = nullptr, const Value *O2 = nullptr);
216 AAQueryInfo &AAQI, const Value *O1 = nullptr,
217 const Value *O2 = nullptr);
219218 };
220219
221220 /// Analysis pass providing a never-invalidated alias analysis result.
5959 const cflaa::AliasSummary *getAliasSummary(const Function &);
6060
6161 AliasResult query(const MemoryLocation &, const MemoryLocation &);
62 AliasResult alias(const MemoryLocation &, const MemoryLocation &);
62 AliasResult alias(const MemoryLocation &, const MemoryLocation &,
63 AAQueryInfo &);
6364
6465 private:
6566 /// Ensures that the given function is available in the cache.
6868
6969 AliasResult query(const MemoryLocation &LocA, const MemoryLocation &LocB);
7070
71 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
71 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
72 AAQueryInfo &AAQI) {
7273 if (LocA.Ptr == LocB.Ptr)
7374 return MustAlias;
7475
7879 // ConstantExpr, but every query needs to have at least one Value tied to a
7980 // Function, and neither GlobalValues nor ConstantExprs are.
8081 if (isa(LocA.Ptr) && isa(LocB.Ptr))
81 return AAResultBase::alias(LocA, LocB);
82 return AAResultBase::alias(LocA, LocB, AAQI);
8283
8384 AliasResult QueryResult = query(LocA, LocB);
8485 if (QueryResult == MayAlias)
85 return AAResultBase::alias(LocA, LocB);
86 return AAResultBase::alias(LocA, LocB, AAQI);
8687
8788 return QueryResult;
8889 }
8383 //------------------------------------------------
8484 // Implement the AliasAnalysis API
8585 //
86 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
86 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
87 AAQueryInfo &AAQI);
8788
8889 using AAResultBase::getModRefInfo;
89 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc);
90 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
91 AAQueryInfo &AAQI);
9092
9193 /// getModRefBehavior - Return the behavior of the specified function if
9294 /// called from the specified call site. The call site may be null in which
112114
113115 bool isNonEscapingGlobalNoAlias(const GlobalValue *GV, const Value *V);
114116 ModRefInfo getModRefInfoForArgument(const CallBase *Call,
115 const GlobalValue *GV);
117 const GlobalValue *GV, AAQueryInfo &AAQI);
116118 };
117119
118120 /// Analysis pass providing a never-invalidated alias analysis result.
829829 const MemoryUseOrDef *Template = nullptr);
830830
831831 private:
832 class ClobberWalkerBase;
833 class CachingWalker;
834 class SkipSelfWalker;
832 template class ClobberWalkerBase;
833 template class CachingWalker;
834 template class SkipSelfWalker;
835835 class OptimizeUses;
836836
837 CachingWalker *getWalkerImpl();
838 void buildMemorySSA();
837 CachingWalker *getWalkerImpl();
838 void buildMemorySSA(BatchAAResults &BAA);
839839 void optimizeUses();
840840
841841 void prepareForMoveTo(MemoryAccess *, BasicBlock *);
849849 void markUnreachableAsLiveOnEntry(BasicBlock *BB);
850850 bool dominatesUse(const MemoryAccess *, const MemoryAccess *) const;
851851 MemoryPhi *createMemoryPhi(BasicBlock *BB);
852 MemoryUseOrDef *createNewAccess(Instruction *,
852 template
853 MemoryUseOrDef *createNewAccess(Instruction *, AliasAnalysisType *,
853854 const MemoryUseOrDef *Template = nullptr);
854855 MemoryAccess *findDominatingDef(BasicBlock *, enum InsertionPlace);
855856 void placePHINodes(const SmallPtrSetImpl &);
885886 mutable DenseMap BlockNumbering;
886887
887888 // Memory SSA building info
888 std::unique_ptr WalkerBase;
889 std::unique_ptr Walker;
890 std::unique_ptr<SkipSelfWalker> SkipWalker;
889 std::unique_ptr<ClobberWalkerBase> WalkerBase;
890 std::unique_ptr> Walker;
891 std::unique_ptr> SkipWalker;
891892 unsigned NextID;
892893 };
893894
5151 return false;
5252 }
5353
54 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
55 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal);
54 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
55 AAQueryInfo &AAQI);
56 bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
57 bool OrLocal);
5658
5759 using AAResultBase::getModRefBehavior;
5860 FunctionModRefBehavior getModRefBehavior(const Function *F);
5961
6062 using AAResultBase::getModRefInfo;
61 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc);
63 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
64 AAQueryInfo &AAQI);
6265 };
6366
6467 /// Analysis pass providing a never-invalidated alias analysis result.
2929 explicit SCEVAAResult(ScalarEvolution &SE) : AAResultBase(), SE(SE) {}
3030 SCEVAAResult(SCEVAAResult &&Arg) : AAResultBase(std::move(Arg)), SE(Arg.SE) {}
3131
32 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
32 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
33 AAQueryInfo &AAQI);
3334
3435 private:
3536 Value *GetBaseValue(const SCEV *S);
3838 return false;
3939 }
4040
41 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
42 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc);
43 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2);
41 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
42 AAQueryInfo &AAQI);
43 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
44 AAQueryInfo &AAQI);
45 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
46 AAQueryInfo &AAQI);
4447
4548 private:
4649 bool mayAliasInScopes(const MDNode *Scopes, const MDNode *NoAlias) const;
3939 return false;
4040 }
4141
42 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
43 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal);
42 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
43 AAQueryInfo &AAQI);
44 bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
45 bool OrLocal);
4446 FunctionModRefBehavior getModRefBehavior(const CallBase *Call);
4547 FunctionModRefBehavior getModRefBehavior(const Function *F);
46 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc);
47 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2);
48 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
49 AAQueryInfo &AAQI);
50 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
51 AAQueryInfo &AAQI);
4852
4953 private:
5054 bool Aliases(const MDNode *A, const MDNode *B) const;
9898
9999 AliasResult AAResults::alias(const MemoryLocation &LocA,
100100 const MemoryLocation &LocB) {
101 AAQueryInfo AAQIP;
102 return alias(LocA, LocB, AAQIP);
103 }
104
105 AliasResult AAResults::alias(const MemoryLocation &LocA,
106 const MemoryLocation &LocB, AAQueryInfo &AAQI) {
101107 for (const auto &AA : AAs) {
102 auto Result = AA->alias(LocA, LocB);
108 auto Result = AA->alias(LocA, LocB, AAQI);
103109 if (Result != MayAlias)
104110 return Result;
105111 }
108114
109115 bool AAResults::pointsToConstantMemory(const MemoryLocation &Loc,
110116 bool OrLocal) {
117 AAQueryInfo AAQIP;
118 return pointsToConstantMemory(Loc, AAQIP, OrLocal);
119 }
120
121 bool AAResults::pointsToConstantMemory(const MemoryLocation &Loc,
122 AAQueryInfo &AAQI, bool OrLocal) {
111123 for (const auto &AA : AAs)
112 if (AA->pointsToConstantMemory(Loc, OrLocal))
124 if (AA->pointsToConstantMemory(Loc, AAQI, OrLocal))
113125 return true;
114126
115127 return false;
130142 }
131143
132144 ModRefInfo AAResults::getModRefInfo(Instruction *I, const CallBase *Call2) {
145 AAQueryInfo AAQIP;
146 return getModRefInfo(I, Call2, AAQIP);
147 }
148
149 ModRefInfo AAResults::getModRefInfo(Instruction *I, const CallBase *Call2,
150 AAQueryInfo &AAQI) {
133151 // We may have two calls.
134152 if (const auto *Call1 = dyn_cast(I)) {
135153 // Check if the two calls modify the same memory.
136 return getModRefInfo(Call1, Call2);
154 return getModRefInfo(Call1, Call2, AAQI);
137155 } else if (I->isFenceLike()) {
138156 // If this is a fence, just return ModRef.
139157 return ModRefInfo::ModRef;
143161 // is that if the call references what this instruction
144162 // defines, it must be clobbered by this location.
145163 const MemoryLocation DefLoc = MemoryLocation::get(I);
146 ModRefInfo MR = getModRefInfo(Call2, DefLoc);
164 ModRefInfo MR = getModRefInfo(Call2, DefLoc, AAQI);
147165 if (isModOrRefSet(MR))
148166 return setModAndRef(MR);
149167 }
152170
153171 ModRefInfo AAResults::getModRefInfo(const CallBase *Call,
154172 const MemoryLocation &Loc) {
173 AAQueryInfo AAQIP;
174 return getModRefInfo(Call, Loc, AAQIP);
175 }
176
177 ModRefInfo AAResults::getModRefInfo(const CallBase *Call,
178 const MemoryLocation &Loc,
179 AAQueryInfo &AAQI) {
155180 ModRefInfo Result = ModRefInfo::ModRef;
156181
157182 for (const auto &AA : AAs) {
158 Result = intersectModRef(Result, AA->getModRefInfo(Call, Loc));
183 Result = intersectModRef(Result, AA->getModRefInfo(Call, Loc, AAQI));
159184
160185 // Early-exit the moment we reach the bottom of the lattice.
161186 if (isNoModRef(Result))
213238
214239 ModRefInfo AAResults::getModRefInfo(const CallBase *Call1,
215240 const CallBase *Call2) {
241 AAQueryInfo AAQIP;
242 return getModRefInfo(Call1, Call2, AAQIP);
243 }
244
245 ModRefInfo AAResults::getModRefInfo(const CallBase *Call1,
246 const CallBase *Call2, AAQueryInfo &AAQI) {
216247 ModRefInfo Result = ModRefInfo::ModRef;
217248
218249 for (const auto &AA : AAs) {
219 Result = intersectModRef(Result, AA->getModRefInfo(Call1, Call2));
250 Result = intersectModRef(Result, AA->getModRefInfo(Call1, Call2, AAQI));
220251
221252 // Early-exit the moment we reach the bottom of the lattice.
222253 if (isNoModRef(Result))
395426
396427 ModRefInfo AAResults::getModRefInfo(const LoadInst *L,
397428 const MemoryLocation &Loc) {
429 AAQueryInfo AAQIP;
430 return getModRefInfo(L, Loc, AAQIP);
431 }
432 ModRefInfo AAResults::getModRefInfo(const LoadInst *L,
433 const MemoryLocation &Loc,
434 AAQueryInfo &AAQI) {
398435 // Be conservative in the face of atomic.
399436 if (isStrongerThan(L->getOrdering(), AtomicOrdering::Unordered))
400437 return ModRefInfo::ModRef;
402439 // If the load address doesn't alias the given address, it doesn't read
403440 // or write the specified memory.
404441 if (Loc.Ptr) {
405 AliasResult AR = alias(MemoryLocation::get(L), Loc);
442 AliasResult AR = alias(MemoryLocation::get(L), Loc, AAQI);
406443 if (AR == NoAlias)
407444 return ModRefInfo::NoModRef;
408445 if (AR == MustAlias)
414451
415452 ModRefInfo AAResults::getModRefInfo(const StoreInst *S,
416453 const MemoryLocation &Loc) {
454 AAQueryInfo AAQIP;
455 return getModRefInfo(S, Loc, AAQIP);
456 }
457 ModRefInfo AAResults::getModRefInfo(const StoreInst *S,
458 const MemoryLocation &Loc,
459 AAQueryInfo &AAQI) {
417460 // Be conservative in the face of atomic.
418461 if (isStrongerThan(S->getOrdering(), AtomicOrdering::Unordered))
419462 return ModRefInfo::ModRef;
420463
421464 if (Loc.Ptr) {
422 AliasResult AR = alias(MemoryLocation::get(S), Loc);
465 AliasResult AR = alias(MemoryLocation::get(S), Loc, AAQI);
423466 // If the store address cannot alias the pointer in question, then the
424467 // specified memory cannot be modified by the store.
425468 if (AR == NoAlias)
427470
428471 // If the pointer is a pointer to constant memory, then it could not have
429472 // been modified by this store.
430 if (pointsToConstantMemory(Loc))
473 if (pointsToConstantMemory(Loc, AAQI))
431474 return ModRefInfo::NoModRef;
432475
433476 // If the store address aliases the pointer as must alias, set Must.
440483 }
441484
442485 ModRefInfo AAResults::getModRefInfo(const FenceInst *S, const MemoryLocation &Loc) {
486 AAQueryInfo AAQIP;
487 return getModRefInfo(S, Loc, AAQIP);
488 }
489
490 ModRefInfo AAResults::getModRefInfo(const FenceInst *S,
491 const MemoryLocation &Loc,
492 AAQueryInfo &AAQI) {
443493 // If we know that the location is a constant memory location, the fence
444494 // cannot modify this location.
445 if (Loc.Ptr && pointsToConstantMemory(Loc))
495 if (Loc.Ptr && pointsToConstantMemory(Loc, AAQI))
446496 return ModRefInfo::Ref;
447497 return ModRefInfo::ModRef;
448498 }
449499
450500 ModRefInfo AAResults::getModRefInfo(const VAArgInst *V,
451501 const MemoryLocation &Loc) {
502 AAQueryInfo AAQIP;
503 return getModRefInfo(V, Loc, AAQIP);
504 }
505
506 ModRefInfo AAResults::getModRefInfo(const VAArgInst *V,
507 const MemoryLocation &Loc,
508 AAQueryInfo &AAQI) {
452509 if (Loc.Ptr) {
453 AliasResult AR = alias(MemoryLocation::get(V), Loc);
510 AliasResult AR = alias(MemoryLocation::get(V), Loc, AAQI);
454511 // If the va_arg address cannot alias the pointer in question, then the
455512 // specified memory cannot be accessed by the va_arg.
456513 if (AR == NoAlias)
458515
459516 // If the pointer is a pointer to constant memory, then it could not have
460517 // been modified by this va_arg.
461 if (pointsToConstantMemory(Loc))
518 if (pointsToConstantMemory(Loc, AAQI))
462519 return ModRefInfo::NoModRef;
463520
464521 // If the va_arg aliases the pointer as must alias, set Must.
472529
473530 ModRefInfo AAResults::getModRefInfo(const CatchPadInst *CatchPad,
474531 const MemoryLocation &Loc) {
532 AAQueryInfo AAQIP;
533 return getModRefInfo(CatchPad, Loc, AAQIP);
534 }
535
536 ModRefInfo AAResults::getModRefInfo(const CatchPadInst *CatchPad,
537 const MemoryLocation &Loc,
538 AAQueryInfo &AAQI) {
475539 if (Loc.Ptr) {
476540 // If the pointer is a pointer to constant memory,
477541 // then it could not have been modified by this catchpad.
478 if (pointsToConstantMemory(Loc))
542 if (pointsToConstantMemory(Loc, AAQI))
479543 return ModRefInfo::NoModRef;
480544 }
481545
485549
486550 ModRefInfo AAResults::getModRefInfo(const CatchReturnInst *CatchRet,
487551 const MemoryLocation &Loc) {
552 AAQueryInfo AAQIP;
553 return getModRefInfo(CatchRet, Loc, AAQIP);
554 }
555
556 ModRefInfo AAResults::getModRefInfo(const CatchReturnInst *CatchRet,
557 const MemoryLocation &Loc,
558 AAQueryInfo &AAQI) {
488559 if (Loc.Ptr) {
489560 // If the pointer is a pointer to constant memory,
490561 // then it could not have been modified by this catchpad.
491 if (pointsToConstantMemory(Loc))
562 if (pointsToConstantMemory(Loc, AAQI))
492563 return ModRefInfo::NoModRef;
493564 }
494565
498569
499570 ModRefInfo AAResults::getModRefInfo(const AtomicCmpXchgInst *CX,
500571 const MemoryLocation &Loc) {
572 AAQueryInfo AAQIP;
573 return getModRefInfo(CX, Loc, AAQIP);
574 }
575
576 ModRefInfo AAResults::getModRefInfo(const AtomicCmpXchgInst *CX,
577 const MemoryLocation &Loc,
578 AAQueryInfo &AAQI) {
501579 // Acquire/Release cmpxchg has properties that matter for arbitrary addresses.
502580 if (isStrongerThanMonotonic(CX->getSuccessOrdering()))
503581 return ModRefInfo::ModRef;
504582
505583 if (Loc.Ptr) {
506 AliasResult AR = alias(MemoryLocation::get(CX), Loc);
584 AliasResult AR = alias(MemoryLocation::get(CX), Loc, AAQI);
507585 // If the cmpxchg address does not alias the location, it does not access
508586 // it.
509587 if (AR == NoAlias)
519597
520598 ModRefInfo AAResults::getModRefInfo(const AtomicRMWInst *RMW,
521599 const MemoryLocation &Loc) {
600 AAQueryInfo AAQIP;
601 return getModRefInfo(RMW, Loc, AAQIP);
602 }
603
604 ModRefInfo AAResults::getModRefInfo(const AtomicRMWInst *RMW,
605 const MemoryLocation &Loc,
606 AAQueryInfo &AAQI) {
522607 // Acquire/Release atomicrmw has properties that matter for arbitrary addresses.
523608 if (isStrongerThanMonotonic(RMW->getOrdering()))
524609 return ModRefInfo::ModRef;
525610
526611 if (Loc.Ptr) {
527 AliasResult AR = alias(MemoryLocation::get(RMW), Loc);
612 AliasResult AR = alias(MemoryLocation::get(RMW), Loc, AAQI);
528613 // If the atomicrmw address does not alias the location, it does not access
529614 // it.
530615 if (AR == NoAlias)
630630 /// the function, with global constants being considered local to all
631631 /// functions.
632632 bool BasicAAResult::pointsToConstantMemory(const MemoryLocation &Loc,
633 bool OrLocal) {
633 AAQueryInfo &AAQI, bool OrLocal) {
634634 assert(Visited.empty() && "Visited must be cleared after use!");
635635
636636 unsigned MaxLookup = 8;
640640 const Value *V = GetUnderlyingObject(Worklist.pop_back_val(), DL);
641641 if (!Visited.insert(V).second) {
642642 Visited.clear();
643 return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
643 return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
644644 }
645645
646646 // An alloca instruction defines local memory.
654654 // others. GV may even be a declaration, not a definition.
655655 if (!GV->isConstant()) {
656656 Visited.clear();
657 return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
657 return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
658658 }
659659 continue;
660660 }
672672 // Don't bother inspecting phi nodes with many operands.
673673 if (PN->getNumIncomingValues() > MaxLookup) {
674674 Visited.clear();
675 return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
675 return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
676676 }
677677 for (Value *IncValue : PN->incoming_values())
678678 Worklist.push_back(IncValue);
681681
682682 // Otherwise be conservative.
683683 Visited.clear();
684 return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
684 return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
685685 } while (!Worklist.empty() && --MaxLookup);
686686
687687 Visited.clear();
816816 #endif
817817
818818 AliasResult BasicAAResult::alias(const MemoryLocation &LocA,
819 const MemoryLocation &LocB) {
819 const MemoryLocation &LocB,
820 AAQueryInfo &AAQI) {
820821 assert(notDifferentParent(LocA.Ptr, LocB.Ptr) &&
821822 "BasicAliasAnalysis doesn't support interprocedural queries.");
822823
823824 // If we have a directly cached entry for these locations, we have recursed
824825 // through this once, so just return the cached results. Notably, when this
825826 // happens, we don't clear the cache.
826 auto CacheIt = AliasCache.find(LocPair(LocA, LocB));
827 if (CacheIt != AliasCache.end())
827 auto CacheIt = AAQI.AliasCache.find(AAQueryInfo::LocPair(LocA, LocB));
828 if (CacheIt != AAQI.AliasCache.end())
828829 return CacheIt->second;
829830
831 CacheIt = AAQI.AliasCache.find(AAQueryInfo::LocPair(LocB, LocA));
832 if (CacheIt != AAQI.AliasCache.end())
833 return CacheIt->second;
834
830835 AliasResult Alias = aliasCheck(LocA.Ptr, LocA.Size, LocA.AATags, LocB.Ptr,
831 LocB.Size, LocB.AATags);
832 // AliasCache rarely has more than 1 or 2 elements, always use
833 // shrink_and_clear so it quickly returns to the inline capacity of the
834 // SmallDenseMap if it ever grows larger.
835 // FIXME: This should really be shrink_to_inline_capacity_and_clear().
836 AliasCache.shrink_and_clear();
837 IsCapturedCache.shrink_and_clear();
836 LocB.Size, LocB.AATags, AAQI);
837
838838 VisitedPhiBBs.clear();
839839 return Alias;
840840 }
846846 /// say much about this query. We do, however, use simple "address taken"
847847 /// analysis on local objects.
848848 ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call,
849 const MemoryLocation &Loc) {
849 const MemoryLocation &Loc,
850 AAQueryInfo &AAQI) {
850851 assert(notDifferentParent(Call, Loc.Ptr) &&
851852 "AliasAnalysis query involving multiple functions!");
852853
873874 // then the call can not mod/ref the pointer unless the call takes the pointer
874875 // as an argument, and itself doesn't capture it.
875876 if (!isa(Object) && Call != Object &&
876 isNonEscapingLocalObject(Object)) {
877 isNonEscapingLocalObject(Object, &AAQI.IsCapturedCache)) {
877878
878879 // Optimistically assume that call doesn't touch Object and check this
879880 // assumption in the following loop.
899900
900901 // If this is a no-capture pointer argument, see if we can tell that it
901902 // is impossible to alias the pointer we're checking.
902 AliasResult AR =
903 getBestAAResults().alias(MemoryLocation(*CI), MemoryLocation(Object));
903 AliasResult AR = getBestAAResults().alias(MemoryLocation(*CI),
904 MemoryLocation(Object), AAQI);
904905 if (AR != MustAlias)
905906 IsMustAlias = false;
906907 // Operand doesn't alias 'Object', continue looking for other aliases
946947 if (isMallocOrCallocLikeFn(Call, &TLI)) {
947948 // Be conservative if the accessed pointer may alias the allocation -
948949 // fallback to the generic handling below.
949 if (getBestAAResults().alias(MemoryLocation(Call), Loc) == NoAlias)
950 if (getBestAAResults().alias(MemoryLocation(Call), Loc, AAQI) == NoAlias)
950951 return ModRefInfo::NoModRef;
951952 }
952953
958959 AliasResult SrcAA, DestAA;
959960
960961 if ((SrcAA = getBestAAResults().alias(MemoryLocation::getForSource(Inst),
961 Loc)) == MustAlias)
962 Loc, AAQI)) == MustAlias)
962963 // Loc is exactly the memcpy source thus disjoint from memcpy dest.
963964 return ModRefInfo::Ref;
964965 if ((DestAA = getBestAAResults().alias(MemoryLocation::getForDest(Inst),
965 Loc)) == MustAlias)
966 Loc, AAQI)) == MustAlias)
966967 // The converse case.
967968 return ModRefInfo::Mod;
968969
10181019 return ModRefInfo::Ref;
10191020
10201021 // The AAResultBase base class has some smarts, lets use them.
1021 return AAResultBase::getModRefInfo(Call, Loc);
1022 return AAResultBase::getModRefInfo(Call, Loc, AAQI);
10221023 }
10231024
10241025 ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call1,
1025 const CallBase *Call2) {
1026 const CallBase *Call2,
1027 AAQueryInfo &AAQI) {
10261028 // While the assume intrinsic is marked as arbitrarily writing so that
10271029 // proper control dependencies will be maintained, it never aliases any
10281030 // particular memory location.
10521054 : ModRefInfo::NoModRef;
10531055
10541056 // The AAResultBase base class has some smarts, lets use them.
1055 return AAResultBase::getModRefInfo(Call1, Call2);
1057 return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
10561058 }
10571059
10581060 /// Provide ad-hoc rules to disambiguate accesses through two GEP operators,
12841286 /// We know that V1 is a GEP, but we don't know anything about V2.
12851287 /// UnderlyingV1 is GetUnderlyingObject(GEP1, DL), UnderlyingV2 is the same for
12861288 /// V2.
1287 AliasResult
1288 BasicAAResult::aliasGEP(const GEPOperator *GEP1, LocationSize V1Size,
1289 const AAMDNodes &V1AAInfo, const Value *V2,
1290 LocationSize V2Size, const AAMDNodes &V2AAInfo,
1291 const Value *UnderlyingV1, const Value *UnderlyingV2) {
1289 AliasResult BasicAAResult::aliasGEP(
1290 const GEPOperator *GEP1, LocationSize V1Size, const AAMDNodes &V1AAInfo,
1291 const Value *V2, LocationSize V2Size, const AAMDNodes &V2AAInfo,
1292 const Value *UnderlyingV1, const Value *UnderlyingV2, AAQueryInfo &AAQI) {
12921293 DecomposedGEP DecompGEP1, DecompGEP2;
12931294 unsigned MaxPointerSize = getMaxPointerSize(DL);
12941295 DecompGEP1.StructOffset = DecompGEP1.OtherOffset = APInt(MaxPointerSize, 0);
13241325 // Do the base pointers alias?
13251326 AliasResult BaseAlias =
13261327 aliasCheck(UnderlyingV1, LocationSize::unknown(), AAMDNodes(),
1327 UnderlyingV2, LocationSize::unknown(), AAMDNodes());
1328 UnderlyingV2, LocationSize::unknown(), AAMDNodes(), AAQI);
13281329
13291330 // Check for geps of non-aliasing underlying pointers where the offsets are
13301331 // identical.
13311332 if ((BaseAlias == MayAlias) && V1Size == V2Size) {
13321333 // Do the base pointers alias assuming type and size.
1333 AliasResult PreciseBaseAlias = aliasCheck(UnderlyingV1, V1Size, V1AAInfo,
1334 UnderlyingV2, V2Size, V2AAInfo);
1334 AliasResult PreciseBaseAlias = aliasCheck(
1335 UnderlyingV1, V1Size, V1AAInfo, UnderlyingV2, V2Size, V2AAInfo, AAQI);
13351336 if (PreciseBaseAlias == NoAlias) {
13361337 // See if the computed offset from the common pointer tells us about the
13371338 // relation of the resulting pointer.
13861387 if (V1Size == LocationSize::unknown() && V2Size == LocationSize::unknown())
13871388 return MayAlias;
13881389
1389 AliasResult R =
1390 aliasCheck(UnderlyingV1, LocationSize::unknown(), AAMDNodes(), V2,
1391 LocationSize::unknown(), V2AAInfo, nullptr, UnderlyingV2);
1390 AliasResult R = aliasCheck(UnderlyingV1, LocationSize::unknown(),
1391 AAMDNodes(), V2, LocationSize::unknown(),
1392 V2AAInfo, AAQI, nullptr, UnderlyingV2);
13921393 if (R != MustAlias) {
13931394 // If V2 may alias GEP base pointer, conservatively returns MayAlias.
13941395 // If V2 is known not to alias GEP base pointer, then the two values
15221523
15231524 /// Provides a bunch of ad-hoc rules to disambiguate a Select instruction
15241525 /// against another.
1525 AliasResult BasicAAResult::aliasSelect(const SelectInst *SI,
1526 LocationSize SISize,
1527 const AAMDNodes &SIAAInfo,
1528 const Value *V2, LocationSize V2Size,
1529 const AAMDNodes &V2AAInfo,
1530 const Value *UnderV2) {
1526 AliasResult
1527 BasicAAResult::aliasSelect(const SelectInst *SI, LocationSize SISize,
1528 const AAMDNodes &SIAAInfo, const Value *V2,
1529 LocationSize V2Size, const AAMDNodes &V2AAInfo,
1530 const Value *UnderV2, AAQueryInfo &AAQI) {
15311531 // If the values are Selects with the same condition, we can do a more precise
15321532 // check: just check for aliases between the values on corresponding arms.
15331533 if (const SelectInst *SI2 = dyn_cast(V2))
15341534 if (SI->getCondition() == SI2->getCondition()) {
1535 AliasResult Alias = aliasCheck(SI->getTrueValue(), SISize, SIAAInfo,
1536 SI2->getTrueValue(), V2Size, V2AAInfo);
1535 AliasResult Alias =
1536 aliasCheck(SI->getTrueValue(), SISize, SIAAInfo, SI2->getTrueValue(),
1537 V2Size, V2AAInfo, AAQI);
15371538 if (Alias == MayAlias)
15381539 return MayAlias;
15391540 AliasResult ThisAlias =
15401541 aliasCheck(SI->getFalseValue(), SISize, SIAAInfo,
1541 SI2->getFalseValue(), V2Size, V2AAInfo);
1542 SI2->getFalseValue(), V2Size, V2AAInfo, AAQI);
15421543 return MergeAliasResults(ThisAlias, Alias);
15431544 }
15441545
15451546 // If both arms of the Select node NoAlias or MustAlias V2, then returns
15461547 // NoAlias / MustAlias. Otherwise, returns MayAlias.
1547 AliasResult Alias =
1548 aliasCheck(V2, V2Size, V2AAInfo, SI->getTrueValue(),
1549 SISize, SIAAInfo, UnderV2);
1548 AliasResult Alias = aliasCheck(V2, V2Size, V2AAInfo, SI->getTrueValue(),
1549 SISize, SIAAInfo, AAQI, UnderV2);
15501550 if (Alias == MayAlias)
15511551 return MayAlias;
15521552
1553 AliasResult ThisAlias =
1554 aliasCheck(V2, V2Size, V2AAInfo, SI->getFalseValue(), SISize, SIAAInfo,
1555 UnderV2);
1553 AliasResult ThisAlias = aliasCheck(V2, V2Size, V2AAInfo, SI->getFalseValue(),
1554 SISize, SIAAInfo, AAQI, UnderV2);
15561555 return MergeAliasResults(ThisAlias, Alias);
15571556 }
15581557
15621561 const AAMDNodes &PNAAInfo, const Value *V2,
15631562 LocationSize V2Size,
15641563 const AAMDNodes &V2AAInfo,
1565 const Value *UnderV2) {
1564 const Value *UnderV2, AAQueryInfo &AAQI) {
15661565 // Track phi nodes we have visited. We use this information when we determine
15671566 // value equivalence.
15681567 VisitedPhiBBs.insert(PN->getParent());
15721571 // on corresponding edges.
15731572 if (const PHINode *PN2 = dyn_cast(V2))
15741573 if (PN2->getParent() == PN->getParent()) {
1575 LocPair Locs(MemoryLocation(PN, PNSize, PNAAInfo),
1576 MemoryLocation(V2, V2Size, V2AAInfo));
1574 AAQueryInfo::LocPair Locs(MemoryLocation(PN, PNSize, PNAAInfo),
1575 MemoryLocation(V2, V2Size, V2AAInfo));
15771576 if (PN > V2)
15781577 std::swap(Locs.first, Locs.second);
15791578 // Analyse the PHIs' inputs under the assumption that the PHIs are
15871586 AliasResult OrigAliasResult;
15881587 {
15891588 // Limited lifetime iterator invalidated by the aliasCheck call below.
1590 auto CacheIt = AliasCache.find(Locs);
1591 assert((CacheIt != AliasCache.end()) &&
1589 auto CacheIt = AAQI.AliasCache.find(Locs);
1590 assert((CacheIt != AAQI.AliasCache.end()) &&
15921591 "There must exist an entry for the phi node");
15931592 OrigAliasResult = CacheIt->second;
15941593 CacheIt->second = NoAlias;
15981597 AliasResult ThisAlias =
15991598 aliasCheck(PN->getIncomingValue(i), PNSize, PNAAInfo,
16001599 PN2->getIncomingValueForBlock(PN->getIncomingBlock(i)),
1601 V2Size, V2AAInfo);
1600 V2Size, V2AAInfo, AAQI);
16021601 Alias = MergeAliasResults(ThisAlias, Alias);
16031602 if (Alias == MayAlias)
16041603 break;
16061605
16071606 // Reset if speculation failed.
16081607 if (Alias != NoAlias) {
1609 auto Pair = AliasCache.insert(std::make_pair(Locs, OrigAliasResult));
1608 auto Pair =
1609 AAQI.AliasCache.insert(std::make_pair(Locs, OrigAliasResult));
16101610 assert(!Pair.second && "Entry must have existed");
16111611 Pair.first->second = OrigAliasResult;
16121612 }
16831683 if (isRecursive)
16841684 PNSize = LocationSize::unknown();
16851685
1686 AliasResult Alias =
1687 aliasCheck(V2, V2Size, V2AAInfo, V1Srcs[0],
1688 PNSize, PNAAInfo, UnderV2);
1686 AliasResult Alias = aliasCheck(V2, V2Size, V2AAInfo, V1Srcs[0], PNSize,
1687 PNAAInfo, AAQI, UnderV2);
16891688
16901689 // Early exit if the check of the first PHI source against V2 is MayAlias.
16911690 // Other results are not possible.
16981697 Value *V = V1Srcs[i];
16991698
17001699 AliasResult ThisAlias =
1701 aliasCheck(V2, V2Size, V2AAInfo, V, PNSize, PNAAInfo, UnderV2);
1700 aliasCheck(V2, V2Size, V2AAInfo, V, PNSize, PNAAInfo, AAQI, UnderV2);
17021701 Alias = MergeAliasResults(ThisAlias, Alias);
17031702 if (Alias == MayAlias)
17041703 break;
17121711 AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
17131712 AAMDNodes V1AAInfo, const Value *V2,
17141713 LocationSize V2Size, AAMDNodes V2AAInfo,
1715 const Value *O1, const Value *O2) {
1714 AAQueryInfo &AAQI, const Value *O1,
1715 const Value *O2) {
17161716 // If either of the memory references is empty, it doesn't matter what the
17171717 // pointer values are.
17181718 if (V1Size.isZero() || V2Size.isZero())
17801780 // temporary store the nocapture argument's value in a temporary memory
17811781 // location if that memory location doesn't escape. Or it may pass a
17821782 // nocapture value to other functions as long as they don't capture it.
1783 if (isEscapeSource(O1) && isNonEscapingLocalObject(O2, &IsCapturedCache))
1783 if (isEscapeSource(O1) &&
1784 isNonEscapingLocalObject(O2, &AAQI.IsCapturedCache))
17841785 return NoAlias;
1785 if (isEscapeSource(O2) && isNonEscapingLocalObject(O1, &IsCapturedCache))
1786 if (isEscapeSource(O2) &&
1787 isNonEscapingLocalObject(O1, &AAQI.IsCapturedCache))
17861788 return NoAlias;
17871789 }
17881790
17971799
17981800 // Check the cache before climbing up use-def chains. This also terminates
17991801 // otherwise infinitely recursive queries.
1800 LocPair Locs(MemoryLocation(V1, V1Size, V1AAInfo),
1801 MemoryLocation(V2, V2Size, V2AAInfo));
1802 AAQueryInfo::LocPair Locs(MemoryLocation(V1, V1Size, V1AAInfo),
1803 MemoryLocation(V2, V2Size, V2AAInfo));
18021804 if (V1 > V2)
18031805 std::swap(Locs.first, Locs.second);
1804 std::pair Pair =
1805 AliasCache.try_emplace(Locs, MayAlias);
1806 std::pair Pair =
1807 AAQI.AliasCache.try_emplace(Locs, MayAlias);
18061808 if (!Pair.second)
18071809 return Pair.first->second;
18081810
18161818 }
18171819 if (const GEPOperator *GV1 = dyn_cast(V1)) {
18181820 AliasResult Result =
1819 aliasGEP(GV1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O1, O2);
1820 if (Result != MayAlias)
1821 return AliasCache[Locs] = Result;
1821 aliasGEP(GV1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O1, O2, AAQI);
1822 if (Result != MayAlias) {
1823 auto ItInsPair = AAQI.AliasCache.insert(std::make_pair(Locs, Result));
1824 assert(!ItInsPair.second && "Entry must have existed");
1825 ItInsPair.first->second = Result;
1826 return Result;
1827 }
18221828 }
18231829
18241830 if (isa(V2) && !isa(V1)) {
18281834 std::swap(V1AAInfo, V2AAInfo);
18291835 }
18301836 if (const PHINode *PN = dyn_cast(V1)) {
1831 AliasResult Result = aliasPHI(PN, V1Size, V1AAInfo,
1832 V2, V2Size, V2AAInfo, O2);
1837 AliasResult Result =
1838 aliasPHI(PN, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O2, AAQI);
18331839 if (Result != MayAlias) {
1834 Pair = AliasCache.try_emplace(Locs, Result);
1840 Pair = AAQI.AliasCache.try_emplace(Locs, Result);
18351841 assert(!Pair.second && "Entry must have existed");
18361842 return Pair.first->second = Result;
18371843 }
18451851 }
18461852 if (const SelectInst *S1 = dyn_cast(V1)) {
18471853 AliasResult Result =
1848 aliasSelect(S1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O2);
1854 aliasSelect(S1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O2, AAQI);
18491855 if (Result != MayAlias) {
1850 Pair = AliasCache.try_emplace(Locs, Result);
1856 Pair = AAQI.AliasCache.try_emplace(Locs, Result);
18511857 assert(!Pair.second && "Entry must have existed");
18521858 return Pair.first->second = Result;
18531859 }
18591865 if (V1Size.isPrecise() && V2Size.isPrecise() &&
18601866 (isObjectSize(O1, V1Size.getValue(), DL, TLI, NullIsValidLocation) ||
18611867 isObjectSize(O2, V2Size.getValue(), DL, TLI, NullIsValidLocation))) {
1862 Pair = AliasCache.try_emplace(Locs, PartialAlias);
1868 Pair = AAQI.AliasCache.try_emplace(Locs, PartialAlias);
18631869 assert(!Pair.second && "Entry must have existed");
18641870 return Pair.first->second = PartialAlias;
18651871 }
18671873 // Recurse back into the best AA results we have, potentially with refined
18681874 // memory locations. We have already ensured that BasicAA has a MayAlias
18691875 // cache result for these, so any recursion back into BasicAA won't loop.
1870 AliasResult Result = getBestAAResults().alias(Locs.first, Locs.second);
1871 Pair = AliasCache.try_emplace(Locs, Result);
1876 AliasResult Result = getBestAAResults().alias(Locs.first, Locs.second, AAQI);
1877 Pair = AAQI.AliasCache.try_emplace(Locs, Result);
18721878 assert(!Pair.second && "Entry must have existed");
18731879 return Pair.first->second = Result;
18741880 }
874874 }
875875
876876 AliasResult CFLAndersAAResult::alias(const MemoryLocation &LocA,
877 const MemoryLocation &LocB) {
877 const MemoryLocation &LocB,
878 AAQueryInfo &AAQI) {
878879 if (LocA.Ptr == LocB.Ptr)
879880 return MustAlias;
880881
884885 // ConstantExpr, but every query needs to have at least one Value tied to a
885886 // Function, and neither GlobalValues nor ConstantExprs are.
886887 if (isa(LocA.Ptr) && isa(LocB.Ptr))
887 return AAResultBase::alias(LocA, LocB);
888 return AAResultBase::alias(LocA, LocB, AAQI);
888889
889890 AliasResult QueryResult = query(LocA, LocB);
890891 if (QueryResult == MayAlias)
891 return AAResultBase::alias(LocA, LocB);
892 return AAResultBase::alias(LocA, LocB, AAQI);
892893
893894 return QueryResult;
894895 }
805805 /// other is some random pointer, we know there cannot be an alias, because the
806806 /// address of the global isn't taken.
807807 AliasResult GlobalsAAResult::alias(const MemoryLocation &LocA,
808 const MemoryLocation &LocB) {
808 const MemoryLocation &LocB,
809 AAQueryInfo &AAQI) {
809810 // Get the base object these pointers point to.
810811 const Value *UV1 = GetUnderlyingObject(LocA.Ptr, DL);
811812 const Value *UV2 = GetUnderlyingObject(LocB.Ptr, DL);
880881 if ((GV1 || GV2) && GV1 != GV2)
881882 return NoAlias;
882883
883 return AAResultBase::alias(LocA, LocB);
884 return AAResultBase::alias(LocA, LocB, AAQI);
884885 }
885886
886887 ModRefInfo GlobalsAAResult::getModRefInfoForArgument(const CallBase *Call,
887 const GlobalValue *GV) {
888 const GlobalValue *GV,
889 AAQueryInfo &AAQI) {
888890 if (Call->doesNotAccessMemory())
889891 return ModRefInfo::NoModRef;
890892 ModRefInfo ConservativeResult =
900902 if (!all_of(Objects, isIdentifiedObject) &&
901903 // Try ::alias to see if all objects are known not to alias GV.
902904 !all_of(Objects, [&](Value *V) {
903 return this->alias(MemoryLocation(V), MemoryLocation(GV)) == NoAlias;
905 return this->alias(MemoryLocation(V), MemoryLocation(GV), AAQI) ==
906 NoAlias;
904907 }))
905908 return ConservativeResult;
906909
913916 }
914917
915918 ModRefInfo GlobalsAAResult::getModRefInfo(const CallBase *Call,
916 const MemoryLocation &Loc) {
919 const MemoryLocation &Loc,
920 AAQueryInfo &AAQI) {
917921 ModRefInfo Known = ModRefInfo::ModRef;
918922
919923 // If we are asking for mod/ref info of a direct call with a pointer to a
925929 if (NonAddressTakenGlobals.count(GV))
926930 if (const FunctionInfo *FI = getFunctionInfo(F))
927931 Known = unionModRef(FI->getModRefInfoForGlobal(*GV),
928 getModRefInfoForArgument(Call, GV));
932 getModRefInfoForArgument(Call, GV, AAQI));
929933
930934 if (!isModOrRefSet(Known))
931935 return ModRefInfo::NoModRef; // No need to query other mod/ref analyses
932 return intersectModRef(Known, AAResultBase::getModRefInfo(Call, Loc));
936 return intersectModRef(Known, AAResultBase::getModRefInfo(Call, Loc, AAQI));
933937 }
934938
935939 GlobalsAAResult::GlobalsAAResult(const DataLayout &DL,
250250
251251 // Return a pair of {IsClobber (bool), AR (AliasResult)}. It relies on AR being
252252 // ignored if IsClobber = false.
253 static ClobberAlias instructionClobbersQuery(const MemoryDef *MD,
254 const MemoryLocation &UseLoc,
255 const Instruction *UseInst,
256 AliasAnalysis &AA) {
253 template
254 static ClobberAlias
255 instructionClobbersQuery(const MemoryDef *MD, const MemoryLocation &UseLoc,
256 const Instruction *UseInst, AliasAnalysisType &AA) {
257257 Instruction *DefInst = MD->getMemoryInst();
258258 assert(DefInst && "Defining instruction not actually an instruction");
259259 const auto *UseCall = dyn_cast(UseInst);
298298 return {isModSet(I), AR};
299299 }
300300
301 template
301302 static ClobberAlias instructionClobbersQuery(MemoryDef *MD,
302303 const MemoryUseOrDef *MU,
303304 const MemoryLocOrCall &UseMLOC,
304 AliasAnalysis &AA) {
305 AliasAnalysisType &AA) {
305306 // FIXME: This is a temporary hack to allow a single instructionClobbersQuery
306307 // to exist while MemoryLocOrCall is pushed through places.
307308 if (UseMLOC.IsCall)
344345 } // end anonymous namespace
345346
346347 static bool lifetimeEndsAt(MemoryDef *MD, const MemoryLocation &Loc,
347 AliasAnalysis &AA) {
348 BatchAAResults &AA) {
348349 Instruction *Inst = MD->getMemoryInst();
349350 if (IntrinsicInst *II = dyn_cast(Inst)) {
350351 switch (II->getIntrinsicID()) {
351352 case Intrinsic::lifetime_end:
352 return AA.isMustAlias(MemoryLocation(II->getArgOperand(1)), Loc);
353 return AA.alias(MemoryLocation(II->getArgOperand(1)), Loc) == MustAlias;
353354 default:
354355 return false;
355356 }
357358 return false;
358359 }
359360
360 static bool isUseTriviallyOptimizableToLiveOnEntry(AliasAnalysis &AA,
361 template
362 static bool isUseTriviallyOptimizableToLiveOnEntry(AliasAnalysisType &AA,
361363 const Instruction *I) {
362364 // If the memory can't be changed, then loads of the memory can't be
363365 // clobbered.
364366 return isa(I) && (I->getMetadata(LLVMContext::MD_invariant_load) ||
365 AA.pointsToConstantMemory(cast(I)->
366 getPointerOperand()));
367 AA.pointsToConstantMemory(MemoryLocation(
368 cast(I)->getPointerOperand())));
367369 }
368370
369371 /// Verifies that `Start` is clobbered by `ClobberAt`, and that nothing
379381 /// \param Query The UpwardsMemoryQuery we used for our search.
380382 /// \param AA The AliasAnalysis we used for our search.
381383 /// \param AllowImpreciseClobber Always false, unless we do relaxed verify.
384
385 template
382386 LLVM_ATTRIBUTE_UNUSED static void
383387 checkClobberSanity(const MemoryAccess *Start, MemoryAccess *ClobberAt,
384388 const MemoryLocation &StartLoc, const MemorySSA &MSSA,
385 const UpwardsMemoryQuery &Query, AliasAnalysis &AA,
389 const UpwardsMemoryQuery &Query, AliasAnalysisType &AA,
386390 bool AllowImpreciseClobber = false) {
387391 assert(MSSA.dominates(ClobberAt, Start) && "Clobber doesn't dominate start?");
388392
472476
473477 /// Our algorithm for walking (and trying to optimize) clobbers, all wrapped up
474478 /// in one class.
475 class ClobberWalker {
479 template class ClobberWalker {
476480 /// Save a few bytes by using unsigned instead of size_t.
477481 using ListIndex = unsigned;
478482
496500 };
497501
498502 const MemorySSA &MSSA;
499 AliasAnalysis &AA;
503 AliasAnalysisType &AA;
500504 DominatorTree &DT;
501505 UpwardsMemoryQuery *Query;
502506
885889 }
886890
887891 public:
888 ClobberWalker(const MemorySSA &MSSA, AliasAnalysis &AA, DominatorTree &DT)
892 ClobberWalker(const MemorySSA &MSSA, AliasAnalysisType &AA, DominatorTree &DT)
889893 : MSSA(MSSA), AA(AA), DT(DT) {}
890894
895 AliasAnalysisType *getAA() { return &AA; }
891896 /// Finds the nearest clobber for the given query, optimizing phis if
892897 /// possible.
893898 MemoryAccess *findClobber(MemoryAccess *Start, UpwardsMemoryQuery &Q) {
943948
944949 namespace llvm {
945950
946 class MemorySSA::ClobberWalkerBase {
947 ClobberWalker Walker;
951 template class MemorySSA::ClobberWalkerBase {
952 ClobberWalker Walker;
948953 MemorySSA *MSSA;
949954
950955 public:
951 ClobberWalkerBase(MemorySSA *M, AliasAnalysis *A, DominatorTree *D)
956 ClobberWalkerBase(MemorySSA *M, AliasAnalysisType *A, DominatorTree *D)
952957 : Walker(*M, *A, *D), MSSA(M) {}
953958
954959 MemoryAccess *getClobberingMemoryAccessBase(MemoryAccess *,
965970 /// A MemorySSAWalker that does AA walks to disambiguate accesses. It no
966971 /// longer does caching on its own, but the name has been retained for the
967972 /// moment.
973 template
968974 class MemorySSA::CachingWalker final : public MemorySSAWalker {
969 ClobberWalkerBase *Walker;
975 ClobberWalkerBase *Walker;
970976
971977 public:
972 CachingWalker(MemorySSA *M, ClobberWalkerBase *W)
978 CachingWalker(MemorySSA *M, ClobberWalkerBase *W)
973979 : MemorySSAWalker(M), Walker(W) {}
974980 ~CachingWalker() override = default;
975981
976982 using MemorySSAWalker::getClobberingMemoryAccess;
977983
978 MemoryAccess *getClobberingMemoryAccess(MemoryAccess *MA) override;
984 MemoryAccess *getClobberingMemoryAccess(MemoryAccess *MA) override {
985 return Walker->getClobberingMemoryAccessBase(MA, false);
986 }
979987 MemoryAccess *getClobberingMemoryAccess(MemoryAccess *MA,
980 const MemoryLocation &Loc) override;
988 const MemoryLocation &Loc) override {
989 return Walker->getClobberingMemoryAccessBase(MA, Loc);
990 }
981991
982992 void invalidateInfo(MemoryAccess *MA) override {
983993 if (auto *MUD = dyn_cast(MA))
985995 }
986996 };
987997
998 template
988999 class MemorySSA::SkipSelfWalker final : public MemorySSAWalker {
989 ClobberWalkerBase *Walker;
1000 ClobberWalkerBase *Walker;
9901001
9911002 public:
992 SkipSelfWalker(MemorySSA *M, ClobberWalkerBase *W)
1003 SkipSelfWalker(MemorySSA *M, ClobberWalkerBase *W)
9931004 : MemorySSAWalker(M), Walker(W) {}
9941005 ~SkipSelfWalker() override = default;
9951006
9961007 using MemorySSAWalker::getClobberingMemoryAccess;
9971008
998 MemoryAccess *getClobberingMemoryAccess(MemoryAccess *MA) override;
1009 MemoryAccess *getClobberingMemoryAccess(MemoryAccess *MA) override {
1010 return Walker->getClobberingMemoryAccessBase(MA, true);
1011 }
9991012 MemoryAccess *getClobberingMemoryAccess(MemoryAccess *MA,
1000 const MemoryLocation &Loc) override;
1013 const MemoryLocation &Loc) override {
1014 return Walker->getClobberingMemoryAccessBase(MA, Loc);
1015 }
10011016
10021017 void invalidateInfo(MemoryAccess *MA) override {
10031018 if (auto *MUD = dyn_cast(MA))
11391154 }
11401155
11411156 MemorySSA::MemorySSA(Function &Func, AliasAnalysis *AA, DominatorTree *DT)
1142 : AA(AA), DT(DT), F(Func), LiveOnEntryDef(nullptr), Walker(nullptr),
1157 : AA(nullptr), DT(DT), F(Func), LiveOnEntryDef(nullptr), Walker(nullptr),
11431158 SkipWalker(nullptr), NextID(0) {
1144 buildMemorySSA();
1159 // Build MemorySSA using a batch alias analysis. This reuses the internal
1160 // state that AA collects during an alias()/getModRefInfo() call. This is
1161 // safe because there are no CFG changes while building MemorySSA and can
1162 // significantly reduce the time spent by the compiler in AA, because we will
1163 // make queries about all the instructions in the Function.
1164 BatchAAResults BatchAA(*AA);
1165 buildMemorySSA(BatchAA);
1166 // Intentionally leave AA to nullptr while building so we don't accidently
1167 // use non-batch AliasAnalysis.
1168 this->AA = AA;
1169 // Also create the walker here.
1170 getWalker();
11451171 }
11461172
11471173 MemorySSA::~MemorySSA() {
11781204 /// which is walking bottom-up.
11791205 class MemorySSA::OptimizeUses {
11801206 public:
1181 OptimizeUses(MemorySSA *MSSA, MemorySSAWalker *Walker, AliasAnalysis *AA,
1207 OptimizeUses(MemorySSA *MSSA, MemorySSAWalker *Walker, BatchAAResults *BAA,
11821208 DominatorTree *DT)
1183 : MSSA(MSSA), Walker(Walker), AA(AA), DT(DT) {}
1209 : MSSA(MSSA), Walker(Walker), AA(BAA), DT(DT) {}
11841210
11851211 void optimizeUses();
11861212
12091235
12101236 MemorySSA *MSSA;
12111237 MemorySSAWalker *Walker;
1212 AliasAnalysis *AA;
1238 BatchAAResults *AA;
12131239 DominatorTree *DT;
12141240 };
12151241
14061432 createMemoryPhi(BB);
14071433 }
14081434
1409 void MemorySSA::buildMemorySSA() {
1435 void MemorySSA::buildMemorySSA(BatchAAResults &BAA) {
14101436 // We create an access to represent "live on entry", for things like
14111437 // arguments or users of globals, where the memory they use is defined before
14121438 // the beginning of the function. We do not actually insert it into the IR.
14281454 AccessList *Accesses = nullptr;
14291455 DefsList *Defs = nullptr;
14301456 for (Instruction &I : B) {
1431 MemoryUseOrDef *MUD = createNewAccess(&I);
1457 MemoryUseOrDef *MUD = createNewAccess(&I, &BAA);
14321458 if (!MUD)
14331459 continue;
14341460
14521478 SmallPtrSet Visited;
14531479 renamePass(DT->getRootNode(), LiveOnEntryDef.get(), Visited);
14541480
1455 CachingWalker *Walker = getWalkerImpl();
1456
1457 OptimizeUses(this, Walker, AA, DT).optimizeUses();
1481 ClobberWalkerBase WalkerBase(this, &BAA, DT);
1482 CachingWalker WalkerLocal(this, &WalkerBase);
1483 OptimizeUses(this, &WalkerLocal, &BAA, DT).optimizeUses();
14581484
14591485 // Mark the uses in unreachable blocks as live on entry, so that they go
14601486 // somewhere.
14651491
14661492 MemorySSAWalker *MemorySSA::getWalker() { return getWalkerImpl(); }
14671493
1468 MemorySSA::CachingWalker *MemorySSA::getWalkerImpl() {
1494 MemorySSA::CachingWalker *MemorySSA::getWalkerImpl() {
14691495 if (Walker)
14701496 return Walker.get();
14711497
14721498 if (!WalkerBase)
1473 WalkerBase = llvm::make_unique(this, AA, DT);
1474
1475 Walker = llvm::make_unique(this, WalkerBase.get());
1499 WalkerBase =
1500 llvm::make_unique>(this, AA, DT);
1501
1502 Walker =
1503 llvm::make_unique>(this, WalkerBase.get());
14761504 return Walker.get();
14771505 }
14781506
14811509 return SkipWalker.get();
14821510
14831511 if (!WalkerBase)
1484 WalkerBase = llvm::make_unique(this, AA, DT);
1485
1486 SkipWalker = llvm::make_unique(this, WalkerBase.get());
1512 WalkerBase =
1513 llvm::make_unique>(this, AA, DT);
1514
1515 SkipWalker =
1516 llvm::make_unique>(this, WalkerBase.get());
14871517 return SkipWalker.get();
14881518 }
14891519
16021632 MemoryAccess *Definition,
16031633 const MemoryUseOrDef *Template) {
16041634 assert(!isa(I) && "Cannot create a defined access for a PHI");
1605 MemoryUseOrDef *NewAccess = createNewAccess(I, Template);
1635 MemoryUseOrDef *NewAccess = createNewAccess(I, AA, Template);
16061636 assert(
16071637 NewAccess != nullptr &&
16081638 "Tried to create a memory access for a non-memory touching instruction");
16251655 }
16261656
16271657 /// Helper function to create new memory accesses
1658 template
16281659 MemoryUseOrDef *MemorySSA::createNewAccess(Instruction *I,
1660 AliasAnalysisType *AAP,
16291661 const MemoryUseOrDef *Template) {
16301662 // The assume intrinsic has a control dependency which we model by claiming
16311663 // that it writes arbitrarily. Ignore that fake memory dependency here.
16401672 Def = dyn_cast_or_null(Template) != nullptr;
16411673 Use = dyn_cast_or_null(Template) != nullptr;
16421674 #if !defined(NDEBUG)
1643 ModRefInfo ModRef = AA->getModRefInfo(I, None);
1675 ModRefInfo ModRef = AAP->getModRefInfo(I, None);
16441676 bool DefCheck, UseCheck;
16451677 DefCheck = isModSet(ModRef) || isOrdered(I);
16461678 UseCheck = isRefSet(ModRef);
16481680 #endif
16491681 } else {
16501682 // Find out what affect this instruction has on memory.
1651 ModRefInfo ModRef = AA->getModRefInfo(I, None);
1683 ModRefInfo ModRef = AAP->getModRefInfo(I, None);
16521684 // The isOrdered check is used to ensure that volatiles end up as defs
16531685 // (atomics end up as ModRef right now anyway). Until we separate the
16541686 // ordering chain from the memory chain, this enables people to see at least
17011733 MUD->setDefiningAccess(nullptr);
17021734 // Invalidate our walker's cache if necessary
17031735 if (!isa(MA))
1704 Walker->invalidateInfo(MA);
1736 getWalker()->invalidateInfo(MA);
17051737
17061738 Value *MemoryInst;
17071739 if (const auto *MUD = dyn_cast(MA))
21742206 /// the MemoryAccess that actually clobbers Loc.
21752207 ///
21762208 /// \returns our clobbering memory access
2177 MemoryAccess *MemorySSA::ClobberWalkerBase::getClobberingMemoryAccessBase(
2209 template
2210 MemoryAccess *
2211 MemorySSA::ClobberWalkerBase::getClobberingMemoryAccessBase(
21782212 MemoryAccess *StartingAccess, const MemoryLocation &Loc) {
21792213 if (isa(StartingAccess))
21802214 return StartingAccess;
22112245 return Clobber;
22122246 }
22132247
2248 template
22142249 MemoryAccess *
2215 MemorySSA::ClobberWalkerBase::getClobberingMemoryAccessBase(MemoryAccess *MA,
2216 bool SkipSelf) {
2250 MemorySSA::ClobberWalkerBase::getClobberingMemoryAccessBase(
2251 MemoryAccess *MA, bool SkipSelf) {
22172252 auto *StartingAccess = dyn_cast(MA);
22182253 // If this is a MemoryPhi, we can't do anything.
22192254 if (!StartingAccess)
22392274
22402275 UpwardsMemoryQuery Q(I, StartingAccess);
22412276
2242 if (isUseTriviallyOptimizableToLiveOnEntry(*MSSA->AA, I)) {
2277 if (isUseTriviallyOptimizableToLiveOnEntry(*Walker.getAA(), I)) {
22432278 MemoryAccess *LiveOnEntry = MSSA->getLiveOnEntryDef();
22442279 StartingAccess->setOptimized(LiveOnEntry);
22452280 StartingAccess->setOptimizedAccessType(None);
22892324 }
22902325
22912326 MemoryAccess *
2292 MemorySSA::CachingWalker::getClobberingMemoryAccess(MemoryAccess *MA) {
2293 return Walker->getClobberingMemoryAccessBase(MA, false);
2294 }
2295
2296 MemoryAccess *
2297 MemorySSA::CachingWalker::getClobberingMemoryAccess(MemoryAccess *MA,
2298 const MemoryLocation &Loc) {
2299 return Walker->getClobberingMemoryAccessBase(MA, Loc);
2300 }
2301
2302 MemoryAccess *
2303 MemorySSA::SkipSelfWalker::getClobberingMemoryAccess(MemoryAccess *MA) {
2304 return Walker->getClobberingMemoryAccessBase(MA, true);
2305 }
2306
2307 MemoryAccess *
2308 MemorySSA::SkipSelfWalker::getClobberingMemoryAccess(MemoryAccess *MA,
2309 const MemoryLocation &Loc) {
2310 return Walker->getClobberingMemoryAccessBase(MA, Loc);
2311 }
2312
2313 MemoryAccess *
23142327 DoNothingMemorySSAWalker::getClobberingMemoryAccess(MemoryAccess *MA) {
23152328 if (auto *Use = dyn_cast(MA))
23162329 return Use->getDefiningAccess();
3636 using namespace llvm::objcarc;
3737
3838 AliasResult ObjCARCAAResult::alias(const MemoryLocation &LocA,
39 const MemoryLocation &LocB) {
39 const MemoryLocation &LocB,
40 AAQueryInfo &AAQI) {
4041 if (!EnableARCOpts)
41 return AAResultBase::alias(LocA, LocB);
42 return AAResultBase::alias(LocA, LocB, AAQI);
4243
4344 // First, strip off no-ops, including ObjC-specific no-ops, and try making a
4445 // precise alias query.
4647 const Value *SB = GetRCIdentityRoot(LocB.Ptr);
4748 AliasResult Result =
4849 AAResultBase::alias(MemoryLocation(SA, LocA.Size, LocA.AATags),
49 MemoryLocation(SB, LocB.Size, LocB.AATags));
50 MemoryLocation(SB, LocB.Size, LocB.AATags), AAQI);
5051 if (Result != MayAlias)
5152 return Result;
5253
5556 const Value *UA = GetUnderlyingObjCPtr(SA, DL);
5657 const Value *UB = GetUnderlyingObjCPtr(SB, DL);
5758 if (UA != SA || UB != SB) {
58 Result = AAResultBase::alias(MemoryLocation(UA), MemoryLocation(UB));
59 Result = AAResultBase::alias(MemoryLocation(UA), MemoryLocation(UB), AAQI);
5960 // We can't use MustAlias or PartialAlias results here because
6061 // GetUnderlyingObjCPtr may return an offsetted pointer value.
6162 if (Result == NoAlias)
6869 }
6970
7071 bool ObjCARCAAResult::pointsToConstantMemory(const MemoryLocation &Loc,
71 bool OrLocal) {
72 AAQueryInfo &AAQI, bool OrLocal) {
7273 if (!EnableARCOpts)
73 return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
74 return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
7475
7576 // First, strip off no-ops, including ObjC-specific no-ops, and try making
7677 // a precise alias query.
7778 const Value *S = GetRCIdentityRoot(Loc.Ptr);
7879 if (AAResultBase::pointsToConstantMemory(
79 MemoryLocation(S, Loc.Size, Loc.AATags), OrLocal))
80 MemoryLocation(S, Loc.Size, Loc.AATags), AAQI, OrLocal))
8081 return true;
8182
8283 // If that failed, climb to the underlying object, including climbing through
8384 // ObjC-specific no-ops, and try making an imprecise alias query.
8485 const Value *U = GetUnderlyingObjCPtr(S, DL);
8586 if (U != S)
86 return AAResultBase::pointsToConstantMemory(MemoryLocation(U), OrLocal);
87 return AAResultBase::pointsToConstantMemory(MemoryLocation(U), AAQI,
88 OrLocal);
8789
8890 // If that failed, fail. We don't need to chain here, since that's covered
8991 // by the earlier precise query.
105107 }
106108
107109 ModRefInfo ObjCARCAAResult::getModRefInfo(const CallBase *Call,
108 const MemoryLocation &Loc) {
110 const MemoryLocation &Loc,
111 AAQueryInfo &AAQI) {
109112 if (!EnableARCOpts)
110 return AAResultBase::getModRefInfo(Call, Loc);
113 return AAResultBase::getModRefInfo(Call, Loc, AAQI);
111114
112115 switch (GetBasicARCInstKind(Call)) {
113116 case ARCInstKind::Retain:
126129 break;
127130 }
128131
129 return AAResultBase::getModRefInfo(Call, Loc);
132 return AAResultBase::getModRefInfo(Call, Loc, AAQI);
130133 }
131134
132135 ObjCARCAAResult ObjCARCAA::run(Function &F, FunctionAnalysisManager &AM) {
2121 using namespace llvm;
2222
2323 AliasResult SCEVAAResult::alias(const MemoryLocation &LocA,
24 const MemoryLocation &LocB) {
24 const MemoryLocation &LocB, AAQueryInfo &AAQI) {
2525 // If either of the memory references is empty, it doesn't matter what the
2626 // pointer values are. This allows the code below to ignore this special
2727 // case.
8484 AO ? AAMDNodes() : LocA.AATags),
8585 MemoryLocation(BO ? BO : LocB.Ptr,
8686 BO ? LocationSize::unknown() : LocB.Size,
87 BO ? AAMDNodes() : LocB.AATags)) == NoAlias)
87 BO ? AAMDNodes() : LocB.AATags),
88 AAQI) == NoAlias)
8889 return NoAlias;
8990
9091 // Forward the query to the next analysis.
91 return AAResultBase::alias(LocA, LocB);
92 return AAResultBase::alias(LocA, LocB, AAQI);
9293 }
9394
9495 /// Given an expression, try to find a base value.
7474 } // end anonymous namespace
7575
7676 AliasResult ScopedNoAliasAAResult::alias(const MemoryLocation &LocA,
77 const MemoryLocation &LocB) {
77 const MemoryLocation &LocB,
78 AAQueryInfo &AAQI) {
7879 if (!EnableScopedNoAlias)
79 return AAResultBase::alias(LocA, LocB);
80 return AAResultBase::alias(LocA, LocB, AAQI);
8081
8182 // Get the attached MDNodes.
8283 const MDNode *AScopes = LocA.AATags.Scope, *BScopes = LocB.AATags.Scope;
9091 return NoAlias;
9192
9293 // If they may alias, chain to the next AliasAnalysis.
93 return AAResultBase::alias(LocA, LocB);
94 return AAResultBase::alias(LocA, LocB, AAQI);
9495 }
9596
9697 ModRefInfo ScopedNoAliasAAResult::getModRefInfo(const CallBase *Call,
97 const MemoryLocation &Loc) {
98 const MemoryLocation &Loc,
99 AAQueryInfo &AAQI) {
98100 if (!EnableScopedNoAlias)
99 return AAResultBase::getModRefInfo(Call, Loc);
101 return AAResultBase::getModRefInfo(Call, Loc, AAQI);
100102
101103 if (!mayAliasInScopes(Loc.AATags.Scope,
102104 Call->getMetadata(LLVMContext::MD_noalias)))
106108 Loc.AATags.NoAlias))
107109 return ModRefInfo::NoModRef;
108110
109 return AAResultBase::getModRefInfo(Call, Loc);
111 return AAResultBase::getModRefInfo(Call, Loc, AAQI);
110112 }
111113
112114 ModRefInfo ScopedNoAliasAAResult::getModRefInfo(const CallBase *Call1,
113 const CallBase *Call2) {
115 const CallBase *Call2,
116 AAQueryInfo &AAQI) {
114117 if (!EnableScopedNoAlias)
115 return AAResultBase::getModRefInfo(Call1, Call2);
118 return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
116119
117120 if (!mayAliasInScopes(Call1->getMetadata(LLVMContext::MD_alias_scope),
118121 Call2->getMetadata(LLVMContext::MD_noalias)))
122125 Call1->getMetadata(LLVMContext::MD_noalias)))
123126 return ModRefInfo::NoModRef;
124127
125 return AAResultBase::getModRefInfo(Call1, Call2);
128 return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
126129 }
127130
128131 static void collectMDInDomain(const MDNode *List, const MDNode *Domain,
366366 }
367367
368368 AliasResult TypeBasedAAResult::alias(const MemoryLocation &LocA,
369 const MemoryLocation &LocB) {
369 const MemoryLocation &LocB,
370 AAQueryInfo &AAQI) {
370371 if (!EnableTBAA)
371 return AAResultBase::alias(LocA, LocB);
372 return AAResultBase::alias(LocA, LocB, AAQI);
372373
373374 // If accesses may alias, chain to the next AliasAnalysis.
374375 if (Aliases(LocA.AATags.TBAA, LocB.AATags.TBAA))
375 return AAResultBase::alias(LocA, LocB);
376 return AAResultBase::alias(LocA, LocB, AAQI);
376377
377378 // Otherwise return a definitive result.
378379 return NoAlias;
379380 }
380381
381382 bool TypeBasedAAResult::pointsToConstantMemory(const MemoryLocation &Loc,
383 AAQueryInfo &AAQI,
382384 bool OrLocal) {
383385 if (!EnableTBAA)
384 return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
386 return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
385387
386388 const MDNode *M = Loc.AATags.TBAA;
387389 if (!M)
388 return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
390 return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
389391
390392 // If this is an "immutable" type, we can assume the pointer is pointing
391393 // to constant memory.
393395 (isStructPathTBAA(M) && TBAAStructTagNode(M).isTypeImmutable()))
394396 return true;
395397
396 return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
398 return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
397399 }
398400
399401 FunctionModRefBehavior
419421 }
420422
421423 ModRefInfo TypeBasedAAResult::getModRefInfo(const CallBase *Call,
422 const MemoryLocation &Loc) {
424 const MemoryLocation &Loc,
425 AAQueryInfo &AAQI) {
423426 if (!EnableTBAA)
424 return AAResultBase::getModRefInfo(Call, Loc);
427 return AAResultBase::getModRefInfo(Call, Loc, AAQI);
425428
426429 if (const MDNode *L = Loc.AATags.TBAA)
427430 if (const MDNode *M = Call->getMetadata(LLVMContext::MD_tbaa))
428431 if (!Aliases(L, M))
429432 return ModRefInfo::NoModRef;
430433
431 return AAResultBase::getModRefInfo(Call, Loc);
434 return AAResultBase::getModRefInfo(Call, Loc, AAQI);
432435 }
433436
434437 ModRefInfo TypeBasedAAResult::getModRefInfo(const CallBase *Call1,
435 const CallBase *Call2) {
438 const CallBase *Call2,
439 AAQueryInfo &AAQI) {
436440 if (!EnableTBAA)
437 return AAResultBase::getModRefInfo(Call1, Call2);
441 return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
438442
439443 if (const MDNode *M1 = Call1->getMetadata(LLVMContext::MD_tbaa))
440444 if (const MDNode *M2 = Call2->getMetadata(LLVMContext::MD_tbaa))
441445 if (!Aliases(M1, M2))
442446 return ModRefInfo::NoModRef;
443447
444 return AAResultBase::getModRefInfo(Call1, Call2);
448 return AAResultBase::getModRefInfo(Call1, Call2, AAQI);
445449 }
446450
447451 bool MDNode::isTBAAVtableAccess() const {
7575 }
7676
7777 AliasResult AMDGPUAAResult::alias(const MemoryLocation &LocA,
78 const MemoryLocation &LocB) {
78 const MemoryLocation &LocB,
79 AAQueryInfo &AAQI) {
7980 unsigned asA = LocA.Ptr->getType()->getPointerAddressSpace();
8081 unsigned asB = LocB.Ptr->getType()->getPointerAddressSpace();
8182
8485 return Result;
8586
8687 // Forward the query to the next alias analysis.
87 return AAResultBase::alias(LocA, LocB);
88 return AAResultBase::alias(LocA, LocB, AAQI);
8889 }
8990
9091 bool AMDGPUAAResult::pointsToConstantMemory(const MemoryLocation &Loc,
91 bool OrLocal) {
92 AAQueryInfo &AAQI, bool OrLocal) {
9293 const Value *Base = GetUnderlyingObject(Loc.Ptr, DL);
9394 unsigned AS = Base->getType()->getPointerAddressSpace();
9495 if (AS == AMDGPUAS::CONSTANT_ADDRESS ||
105106 // Only assume constant memory for arguments on kernels.
106107 switch (F->getCallingConv()) {
107108 default:
108 return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
109 return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
109110 case CallingConv::AMDGPU_LS:
110111 case CallingConv::AMDGPU_HS:
111112 case CallingConv::AMDGPU_ES:
132133 return true;
133134 }
134135 }
135 return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
136 return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
136137 }
4343 /// By definition, this result is stateless and so remains valid.
4444 bool invalidate(Function &, const PreservedAnalyses &) { return false; }
4545
46 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
47 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal);
46 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
47 AAQueryInfo &AAQI);
48 bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
49 bool OrLocal);
4850
4951 private:
5052 bool Aliases(const MDNode *A, const MDNode *B) const;
8484
8585 bool invalidate(Function &, const PreservedAnalyses &) { return false; }
8686
87 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
87 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
88 AAQueryInfo &AAQI) {
8889 CB();
8990 return MayAlias;
9091 }
4343 DominatorTree DT;
4444 AssumptionCache AC;
4545 BasicAAResult BAA;
46 AAQueryInfo AAQI;
4647
4748 TestAnalyses(BasicAATest &Test)
48 : DT(*Test.F), AC(*Test.F), BAA(Test.DL, *Test.F, Test.TLI, AC, &DT) {}
49 : DT(*Test.F), AC(*Test.F), BAA(Test.DL, *Test.F, Test.TLI, AC, &DT),
50 AAQI() {}
4951 };
5052
5153 llvm::Optional Analyses;
5254
53 BasicAAResult &setupAnalyses() {
55 TestAnalyses &setupAnalyses() {
5456 assert(F);
5557 Analyses.emplace(*this);
56 return Analyses->BAA;
58 return Analyses.getValue();
5759 }
5860
5961 public:
8284 GlobalPtr->setLinkage(GlobalValue::LinkageTypes::InternalLinkage);
8385 GlobalPtr->setInitializer(B.getInt8(0));
8486
85 BasicAAResult &BasicAA = setupAnalyses();
87 auto &AllAnalyses = setupAnalyses();
88 BasicAAResult &BasicAA = AllAnalyses.BAA;
89 AAQueryInfo &AAQI = AllAnalyses.AAQI;
8690 ASSERT_EQ(
8791 BasicAA.alias(MemoryLocation(IncomingI32Ptr, LocationSize::precise(4)),
88 MemoryLocation(GlobalPtr, LocationSize::precise(1))),
92 MemoryLocation(GlobalPtr, LocationSize::precise(1)), AAQI),
8993 AliasResult::NoAlias);
9094
9195 ASSERT_EQ(
9296 BasicAA.alias(MemoryLocation(IncomingI32Ptr, LocationSize::upperBound(4)),
93 MemoryLocation(GlobalPtr, LocationSize::precise(1))),
97 MemoryLocation(GlobalPtr, LocationSize::precise(1)), AAQI),
9498 AliasResult::MayAlias);
9599 }
96100
109113 auto *I8AtUncertainOffset =
110114 cast(B.CreateGEP(B.getInt8Ty(), I8, ArbitraryI32));
111115
112 BasicAAResult &BasicAA = setupAnalyses();
116 auto &AllAnalyses = setupAnalyses();
117 BasicAAResult &BasicAA = AllAnalyses.BAA;
118 AAQueryInfo &AAQI = AllAnalyses.AAQI;
113119 ASSERT_EQ(BasicAA.alias(
114120 MemoryLocation(I8, LocationSize::precise(2)),
115 MemoryLocation(I8AtUncertainOffset, LocationSize::precise(1))),
121 MemoryLocation(I8AtUncertainOffset, LocationSize::precise(1)),
122 AAQI),
116123 AliasResult::PartialAlias);
117124
118125 ASSERT_EQ(BasicAA.alias(
119126 MemoryLocation(I8, LocationSize::upperBound(2)),
120 MemoryLocation(I8AtUncertainOffset, LocationSize::precise(1))),
127 MemoryLocation(I8AtUncertainOffset, LocationSize::precise(1)),
128 AAQI),
121129 AliasResult::MayAlias);
122130 }