LLVM 23.0.0git
AliasAnalysis.h
Go to the documentation of this file.
1//===- llvm/Analysis/AliasAnalysis.h - Alias Analysis Interface -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the generic AliasAnalysis interface, which is used as the
10// common interface used by all clients of alias analysis information, and
11// implemented by all alias analysis implementations. Mod/Ref information is
12// also captured by this interface.
13//
14// Implementations of this interface must implement the various virtual methods,
15// which automatically provides functionality for the entire suite of client
16// APIs.
17//
18// This API identifies memory regions with the MemoryLocation class. The pointer
19// component specifies the base memory address of the region. The Size specifies
20// the maximum size (in address units) of the memory region, or
21// MemoryLocation::UnknownSize if the size is not known. The TBAA tag
22// identifies the "type" of the memory reference; see the
23// TypeBasedAliasAnalysis class for details.
24//
25// Some non-obvious details include:
26// - Pointers that point to two completely different objects in memory never
27// alias, regardless of the value of the Size component.
28// - NoAlias doesn't imply inequal pointers. The most obvious example of this
29// is two pointers to constant memory. Even if they are equal, constant
30// memory is never stored to, so there will never be any dependencies.
31// In this and other situations, the pointers may be both NoAlias and
32// MustAlias at the same time. The current API can only return one result,
33// though this is rarely a problem in practice.
34//
35//===----------------------------------------------------------------------===//
36
37#ifndef LLVM_ANALYSIS_ALIASANALYSIS_H
38#define LLVM_ANALYSIS_ALIASANALYSIS_H
39
40#include "llvm/ADT/DenseMap.h"
44#include "llvm/IR/Function.h"
45#include "llvm/IR/PassManager.h"
46#include "llvm/Pass.h"
48#include "llvm/Support/ModRef.h"
49#include <cstdint>
50#include <functional>
51#include <memory>
52#include <optional>
53#include <vector>
54
55namespace llvm {
56
58class BasicBlock;
59class CatchPadInst;
60class CatchReturnInst;
61class CycleInfo;
62class DominatorTree;
63class FenceInst;
64class LoopInfo;
66
67/// The possible results of an alias query.
68///
69/// These results are always computed between two MemoryLocation objects as
70/// a query to some alias analysis.
71///
72/// Note that these are unscoped enumerations because we would like to support
73/// implicitly testing a result for the existence of any possible aliasing with
74/// a conversion to bool, but an "enum class" doesn't support this. The
75/// canonical names from the literature are suffixed and unique anyways, and so
76/// they serve as global constants in LLVM for these results.
77///
78/// See docs/AliasAnalysis.html for more information on the specific meanings
79/// of these values.
81private:
82 static const int OffsetBits = 23;
83 static const int AliasBits = 8;
84 static_assert(AliasBits + 1 + OffsetBits <= 32,
85 "AliasResult size is intended to be 4 bytes!");
86
87 unsigned int Alias : AliasBits;
88 unsigned int HasOffset : 1;
89 signed int Offset : OffsetBits;
90
91public:
92 enum Kind : uint8_t {
93 /// The two locations do not alias at all.
94 ///
95 /// This value is arranged to convert to false, while all other values
96 /// convert to true. This allows a boolean context to convert the result to
97 /// a binary flag indicating whether there is the possibility of aliasing.
99 /// The two locations may or may not alias. This is the least precise
100 /// result.
102 /// The two locations alias, but only due to a partial overlap.
104 /// The two locations precisely alias each other.
106 };
107 static_assert(MustAlias < (1 << AliasBits),
108 "Not enough bit field size for the enum!");
109
110 explicit AliasResult() = delete;
111 constexpr AliasResult(const Kind &Alias)
112 : Alias(Alias), HasOffset(false), Offset(0) {}
113
114 operator Kind() const { return static_cast<Kind>(Alias); }
115
116 bool operator==(const AliasResult &Other) const {
117 return Alias == Other.Alias && HasOffset == Other.HasOffset &&
118 Offset == Other.Offset;
119 }
120 bool operator!=(const AliasResult &Other) const { return !(*this == Other); }
121
122 bool operator==(Kind K) const { return Alias == K; }
123 bool operator!=(Kind K) const { return !(*this == K); }
124
125 constexpr bool hasOffset() const { return HasOffset; }
126 constexpr int32_t getOffset() const {
127 assert(HasOffset && "No offset!");
128 return Offset;
129 }
130 void setOffset(int32_t NewOffset) {
131 if (isInt<OffsetBits>(NewOffset)) {
132 HasOffset = true;
133 Offset = NewOffset;
134 }
135 }
136
137 /// Helper for processing AliasResult for swapped memory location pairs.
138 void swap(bool DoSwap = true) {
139 if (DoSwap && hasOffset())
141 }
142};
143
144static_assert(sizeof(AliasResult) == 4,
145 "AliasResult size is intended to be 4 bytes!");
146
147/// << operator for AliasResult.
148LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, AliasResult AR);
149
150/// Virtual base class for providers of capture analysis.
152 virtual ~CaptureAnalysis() = 0;
153
154 /// Return how Object may be captured before instruction I, considering only
155 /// provenance captures. If OrAt is true, captures by instruction I itself
156 /// are also considered.
157 ///
158 /// If I is nullptr, then captures at any point will be considered.
160 const Instruction *I, bool OrAt,
161 bool ReturnCaptures) = 0;
162};
163
164/// Context-free CaptureAnalysis provider, which computes and caches whether an
165/// object is captured in the function at all, but does not distinguish whether
166/// it was captured before or after the context instruction.
169
170public:
172 bool OrAt, bool ReturnCaptures) override;
173};
174
175/// Context-sensitive CaptureAnalysis provider, which computes and caches the
176/// earliest common dominator closure of all captures. It provides a good
177/// approximation to a precise "captures before" analysis.
179 DominatorTree &DT;
180 const LoopInfo *LI;
181 const CycleInfo *CI;
182
183 /// Map from identified local object to an instruction before which it does
184 /// not escape (or nullptr if it never escapes) and the possible components
185 /// that may be captured (by any instruction, not necessarily the earliest
186 /// one). The "earliest" instruction may be a conservative approximation,
187 /// e.g. the first instruction in the function is always a legal choice.
189 EarliestEscapes;
190
191 /// Reverse map from instruction to the objects it is the earliest escape for.
192 /// This is used for cache invalidation purposes.
194
195public:
197 const CycleInfo *CI = nullptr)
198 : DT(DT), LI(LI), CI(CI) {}
199
200 CaptureComponents getCapturesBefore(const Value *Object, const Instruction *I,
201 bool OrAt, bool ReturnCaptures) override;
202
203 void removeInstruction(Instruction *I);
204};
205
206/// Cache key for BasicAA results. It only includes the pointer and size from
207/// MemoryLocation, as BasicAA is AATags independent. Additionally, it includes
208/// the value of MayBeCrossIteration, which may affect BasicAA results.
213
215 AACacheLoc(const Value *Ptr, LocationSize Size, bool MayBeCrossIteration)
216 : Ptr(Ptr, MayBeCrossIteration), Size(Size) {}
217};
218
219template <> struct DenseMapInfo<AACacheLoc> {
232 static bool isEqual(const AACacheLoc &LHS, const AACacheLoc &RHS) {
233 return LHS.Ptr == RHS.Ptr && LHS.Size == RHS.Size;
234 }
235};
236
237class AAResults;
238
239/// This class stores info we want to provide to or retain within an alias
240/// query. By default, the root query is stateless and starts with a freshly
241/// constructed info object. Specific alias analyses can use this query info to
242/// store per-query state that is important for recursive or nested queries to
243/// avoid recomputing. To enable preserving this state across multiple queries
244/// where safe (due to the IR not changing), use a `BatchAAResults` wrapper.
245/// The information stored in an `AAQueryInfo` is currently limitted to the
246/// caches used by BasicAA, but can further be extended to fit other AA needs.
248public:
249 using LocPair = std::pair<AACacheLoc, AACacheLoc>;
250 struct CacheEntry {
251 /// Cache entry is neither an assumption nor does it use a (non-definitive)
252 /// assumption.
253 static constexpr int Definitive = -2;
254 /// Cache entry is not an assumption itself, but may be using an assumption
255 /// from higher up the stack.
256 static constexpr int AssumptionBased = -1;
257
259 /// Number of times a NoAlias assumption has been used, 0 for assumptions
260 /// that have not been used. Can also take one of the Definitive or
261 /// AssumptionBased values documented above.
263
264 /// Whether this is a definitive (non-assumption) result.
265 bool isDefinitive() const { return NumAssumptionUses == Definitive; }
266 /// Whether this is an assumption that has not been proven yet.
267 bool isAssumption() const { return NumAssumptionUses >= 0; }
268 };
269
270 // Alias analysis result aggregration using which this query is performed.
271 // Can be used to perform recursive queries.
273
276
278
279 /// Query depth used to distinguish recursive queries.
280 unsigned Depth = 0;
281
282 /// How many active NoAlias assumption uses there are.
284
285 /// Location pairs for which an assumption based result is currently stored.
286 /// Used to remove all potentially incorrect results from the cache if an
287 /// assumption is disproven.
289
290 /// Tracks whether the accesses may be on different cycle iterations.
291 ///
292 /// When interpret "Value" pointer equality as value equality we need to make
293 /// sure that the "Value" is not part of a cycle. Otherwise, two uses could
294 /// come from different "iterations" of a cycle and see different values for
295 /// the same "Value" pointer.
296 ///
297 /// The following example shows the problem:
298 /// %p = phi(%alloca1, %addr2)
299 /// %l = load %ptr
300 /// %addr1 = gep, %alloca2, 0, %l
301 /// %addr2 = gep %alloca2, 0, (%l + 1)
302 /// alias(%p, %addr1) -> MayAlias !
303 /// store %l, ...
305
306 /// Whether alias analysis is allowed to use the dominator tree, for use by
307 /// passes that lazily update the DT while performing AA queries.
308 bool UseDominatorTree = true;
309
311};
312
313/// AAQueryInfo that uses SimpleCaptureAnalysis.
316
317public:
319};
320
321class BatchAAResults;
322
324public:
325 // Make these results default constructable and movable. We have to spell
326 // these out because MSVC won't synthesize them.
330
331 /// Register a specific AA result.
332 template <typename AAResultT> void addAAResult(AAResultT &AAResult) {
333 // FIXME: We should use a much lighter weight system than the usual
334 // polymorphic pattern because we don't own AAResult. It should
335 // ideally involve two pointers and no separate allocation.
336 AAs.emplace_back(new Model<AAResultT>(AAResult, *this));
337 }
338
339 /// Register a function analysis ID that the results aggregation depends on.
340 ///
341 /// This is used in the new pass manager to implement the invalidation logic
342 /// where we must invalidate the results aggregation if any of our component
343 /// analyses become invalid.
344 void addAADependencyID(AnalysisKey *ID) { AADeps.push_back(ID); }
345
346 /// Handle invalidation events in the new pass manager.
347 ///
348 /// The aggregation is invalidated if any of the underlying analyses is
349 /// invalidated.
351 FunctionAnalysisManager::Invalidator &Inv);
352
353 //===--------------------------------------------------------------------===//
354 /// \name Alias Queries
355 /// @{
356
357 /// The main low level interface to the alias analysis implementation.
358 /// Returns an AliasResult indicating whether the two pointers are aliased to
359 /// each other. This is the interface that must be implemented by specific
360 /// alias analysis implementations.
362 const MemoryLocation &LocB);
363
364 /// A convenience wrapper around the primary \c alias interface.
365 AliasResult alias(const Value *V1, LocationSize V1Size, const Value *V2,
366 LocationSize V2Size) {
367 return alias(MemoryLocation(V1, V1Size), MemoryLocation(V2, V2Size));
368 }
369
370 /// A convenience wrapper around the primary \c alias interface.
375
376 /// A trivial helper function to check to see if the specified pointers are
377 /// no-alias.
378 bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
379 return alias(LocA, LocB) == AliasResult::NoAlias;
380 }
381
382 /// A convenience wrapper around the \c isNoAlias helper interface.
383 bool isNoAlias(const Value *V1, LocationSize V1Size, const Value *V2,
384 LocationSize V2Size) {
385 return isNoAlias(MemoryLocation(V1, V1Size), MemoryLocation(V2, V2Size));
386 }
387
388 /// A convenience wrapper around the \c isNoAlias helper interface.
389 bool isNoAlias(const Value *V1, const Value *V2) {
392 }
393
394 /// A trivial helper function to check to see if the specified pointers are
395 /// must-alias.
396 bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
397 return alias(LocA, LocB) == AliasResult::MustAlias;
398 }
399
400 /// A convenience wrapper around the \c isMustAlias helper interface.
401 bool isMustAlias(const Value *V1, const Value *V2) {
402 return alias(V1, LocationSize::precise(1), V2, LocationSize::precise(1)) ==
404 }
405
406 /// Checks whether the given location points to constant memory, or if
407 /// \p OrLocal is true whether it points to a local alloca.
408 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal = false) {
409 return isNoModRef(getModRefInfoMask(Loc, OrLocal));
410 }
411
412 /// A convenience wrapper around the primary \c pointsToConstantMemory
413 /// interface.
414 bool pointsToConstantMemory(const Value *P, bool OrLocal = false) {
416 }
417
418 /// @}
419 //===--------------------------------------------------------------------===//
420 /// \name Simple mod/ref information
421 /// @{
422
423 /// Returns a bitmask that should be unconditionally applied to the ModRef
424 /// info of a memory location. This allows us to eliminate Mod and/or Ref
425 /// from the ModRef info based on the knowledge that the memory location
426 /// points to constant and/or locally-invariant memory.
427 ///
428 /// If IgnoreLocals is true, then this method returns NoModRef for memory
429 /// that points to a local alloca.
431 bool IgnoreLocals = false);
432
433 /// A convenience wrapper around the primary \c getModRefInfoMask
434 /// interface.
435 ModRefInfo getModRefInfoMask(const Value *P, bool IgnoreLocals = false) {
437 }
438
439 /// Get the ModRef info associated with a pointer argument of a call. The
440 /// result's bits are set to indicate the allowed aliasing ModRef kinds. Note
441 /// that these bits do not necessarily account for the overall behavior of
442 /// the function, but rather only provide additional per-argument
443 /// information.
444 LLVM_ABI ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx);
445
446 /// Return the behavior of the given call site.
448
449 /// Return the behavior when calling the given function.
451
452 /// Checks if the specified call is known to never read or write memory.
453 ///
454 /// Note that if the call only reads from known-constant memory, it is also
455 /// legal to return true. Also, calls that unwind the stack are legal for
456 /// this predicate.
457 ///
458 /// Many optimizations (such as CSE and LICM) can be performed on such calls
459 /// without worrying about aliasing properties, and many calls have this
460 /// property (e.g. calls to 'sin' and 'cos').
461 ///
462 /// This property corresponds to the GCC 'const' attribute.
466
467 /// Checks if the specified function is known to never read or write memory.
468 ///
469 /// Note that if the function only reads from known-constant memory, it is
470 /// also legal to return true. Also, function that unwind the stack are legal
471 /// for this predicate.
472 ///
473 /// Many optimizations (such as CSE and LICM) can be performed on such calls
474 /// to such functions without worrying about aliasing properties, and many
475 /// functions have this property (e.g. 'sin' and 'cos').
476 ///
477 /// This property corresponds to the GCC 'const' attribute.
481
482 /// Checks if the specified call is known to only read from non-volatile
483 /// memory (or not access memory at all).
484 ///
485 /// Calls that unwind the stack are legal for this predicate.
486 ///
487 /// This property allows many common optimizations to be performed in the
488 /// absence of interfering store instructions, such as CSE of strlen calls.
489 ///
490 /// This property corresponds to the GCC 'pure' attribute.
494
495 /// Checks if the specified function is known to only read from non-volatile
496 /// memory (or not access memory at all).
497 ///
498 /// Functions that unwind the stack are legal for this predicate.
499 ///
500 /// This property allows many common optimizations to be performed in the
501 /// absence of interfering store instructions, such as CSE of strlen calls.
502 ///
503 /// This property corresponds to the GCC 'pure' attribute.
506 }
507
508 /// Check whether or not an instruction may read or write the optionally
509 /// specified memory location.
510 ///
511 ///
512 /// An instruction that doesn't read or write memory may be trivially LICM'd
513 /// for example.
514 ///
515 /// For function calls, this delegates to the alias-analysis specific
516 /// call-site mod-ref behavior queries. Otherwise it delegates to the specific
517 /// helpers above.
519 const std::optional<MemoryLocation> &OptLoc) {
520 SimpleAAQueryInfo AAQIP(*this);
521 return getModRefInfo(I, OptLoc, AAQIP);
522 }
523
524 /// A convenience wrapper for constructing the memory location.
529
530 /// Return information about whether a call and an instruction may refer to
531 /// the same memory locations.
533
534 /// Return information about whether two instructions may refer to the same
535 /// memory locations.
537 const Instruction *I2);
538
539 /// Return information about whether a particular call site modifies
540 /// or reads the specified memory location \p MemLoc before instruction \p I
541 /// in a BasicBlock.
543 const MemoryLocation &MemLoc,
544 DominatorTree *DT) {
545 SimpleAAQueryInfo AAQIP(*this);
546 return callCapturesBefore(I, MemLoc, DT, AAQIP);
547 }
548
549 /// A convenience wrapper to synthesize a memory location.
554
555 /// @}
556 //===--------------------------------------------------------------------===//
557 /// \name Higher level methods for querying mod/ref information.
558 /// @{
559
560 /// Check if it is possible for execution of the specified basic block to
561 /// modify the location Loc.
563 const MemoryLocation &Loc);
564
565 /// A convenience wrapper synthesizing a memory location.
566 bool canBasicBlockModify(const BasicBlock &BB, const Value *P,
569 }
570
571 /// Check if it is possible for the execution of the specified instructions
572 /// to mod\ref (according to the mode) the location Loc.
573 ///
574 /// The instructions to consider are all of the instructions in the range of
575 /// [I1,I2] INCLUSIVE. I1 and I2 must be in the same basic block.
577 const Instruction &I2,
578 const MemoryLocation &Loc,
579 const ModRefInfo Mode);
580
581 /// A convenience wrapper synthesizing a memory location.
583 const Value *Ptr, LocationSize Size,
584 const ModRefInfo Mode) {
585 return canInstructionRangeModRef(I1, I2, MemoryLocation(Ptr, Size), Mode);
586 }
587
588 // CtxI can be nullptr, in which case the query is whether or not the aliasing
589 // relationship holds through the entire function.
591 const MemoryLocation &LocB, AAQueryInfo &AAQI,
592 const Instruction *CtxI = nullptr);
594
596 AAQueryInfo &AAQI,
597 bool IgnoreLocals = false);
599 AAQueryInfo &AAQIP);
601 const MemoryLocation &Loc,
602 AAQueryInfo &AAQI);
604 const CallBase *Call2, AAQueryInfo &AAQI);
606 const MemoryLocation &Loc,
607 AAQueryInfo &AAQI);
609 const MemoryLocation &Loc,
610 AAQueryInfo &AAQI);
612 const MemoryLocation &Loc,
613 AAQueryInfo &AAQI);
615 const MemoryLocation &Loc,
616 AAQueryInfo &AAQI);
618 const MemoryLocation &Loc,
619 AAQueryInfo &AAQI);
621 const MemoryLocation &Loc,
622 AAQueryInfo &AAQI);
624 const MemoryLocation &Loc,
625 AAQueryInfo &AAQI);
627 const MemoryLocation &Loc,
628 AAQueryInfo &AAQI);
630 const std::optional<MemoryLocation> &OptLoc,
631 AAQueryInfo &AAQIP);
633 const Instruction *I2, AAQueryInfo &AAQI);
635 const MemoryLocation &MemLoc,
636 DominatorTree *DT, AAQueryInfo &AAQIP);
638 AAQueryInfo &AAQI);
639
640private:
641 class Concept;
642
643 template <typename T> class Model;
644
645 friend class AAResultBase;
646
647 const TargetLibraryInfo &TLI;
648
649 std::vector<std::unique_ptr<Concept>> AAs;
650
651 std::vector<AnalysisKey *> AADeps;
652
653 friend class BatchAAResults;
654};
655
656/// This class is a wrapper over an AAResults, and it is intended to be used
657/// only when there are no IR changes inbetween queries. BatchAAResults is
658/// reusing the same `AAQueryInfo` to preserve the state across queries,
659/// esentially making AA work in "batch mode". The internal state cannot be
660/// cleared, so to go "out-of-batch-mode", the user must either use AAResults,
661/// or create a new BatchAAResults.
663 AAResults &AA;
664 AAQueryInfo AAQI;
665 SimpleCaptureAnalysis SimpleCA;
666
668
669public:
670 BatchAAResults(AAResults &AAR) : AA(AAR), AAQI(AAR, &SimpleCA) {}
672 : AA(AAR), AAQI(AAR, CA) {}
673
674 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
675 return AA.alias(LocA, LocB, AAQI);
676 }
677 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal = false) {
678 return isNoModRef(AA.getModRefInfoMask(Loc, AAQI, OrLocal));
679 }
680 bool pointsToConstantMemory(const Value *P, bool OrLocal = false) {
682 }
684 bool IgnoreLocals = false) {
685 return AA.getModRefInfoMask(Loc, AAQI, IgnoreLocals);
686 }
688 const std::optional<MemoryLocation> &OptLoc) {
689 return AA.getModRefInfo(I, OptLoc, AAQI);
690 }
692 return AA.getModRefInfo(I, Call2, AAQI);
693 }
695 return AA.getModRefInfo(I, I2, AAQI);
696 }
697 ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) {
698 return AA.getArgModRefInfo(Call, ArgIdx);
699 }
701 return AA.getMemoryEffects(Call, AAQI);
702 }
703 bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
704 return alias(LocA, LocB) == AliasResult::MustAlias;
705 }
706 bool isMustAlias(const Value *V1, const Value *V2) {
710 }
711 bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
712 return alias(LocA, LocB) == AliasResult::NoAlias;
713 }
715 const MemoryLocation &MemLoc,
716 DominatorTree *DT) {
717 return AA.callCapturesBefore(I, MemLoc, DT, AAQI);
718 }
719
720 /// Assume that values may come from different cycle iterations.
722 AAQI.MayBeCrossIteration = true;
723 }
724
725 /// Disable the use of the dominator tree during alias analysis queries.
726 void disableDominatorTree() { AAQI.UseDominatorTree = false; }
727};
728
729/// Temporarily set the cross iteration mode on a BatchAA instance.
731 BatchAAResults &BAA;
732 bool OrigCrossIteration;
733
734public:
736 : BAA(BAA), OrigCrossIteration(BAA.AAQI.MayBeCrossIteration) {
737 BAA.AAQI.MayBeCrossIteration = CrossIteration;
738 }
740 BAA.AAQI.MayBeCrossIteration = OrigCrossIteration;
741 }
742};
743
744/// Temporary typedef for legacy code that uses a generic \c AliasAnalysis
745/// pointer or reference.
747
748/// A private abstract base class describing the concept of an individual alias
749/// analysis implementation.
750///
751/// This interface is implemented by any \c Model instantiation. It is also the
752/// interface which a type used to instantiate the model must provide.
753///
754/// All of these methods model methods by the same name in the \c
755/// AAResults class. Only differences and specifics to how the
756/// implementations are called are documented here.
758public:
759 virtual ~Concept() = 0;
760
761 //===--------------------------------------------------------------------===//
762 /// \name Alias Queries
763 /// @{
764
765 /// The main low level interface to the alias analysis implementation.
766 /// Returns an AliasResult indicating whether the two pointers are aliased to
767 /// each other. This is the interface that must be implemented by specific
768 /// alias analysis implementations.
769 virtual AliasResult alias(const MemoryLocation &LocA,
770 const MemoryLocation &LocB, AAQueryInfo &AAQI,
771 const Instruction *CtxI) = 0;
772
773 /// Returns an AliasResult indicating whether a specific memory location
774 /// aliases errno.
776 const Module *M) = 0;
777
778 /// @}
779 //===--------------------------------------------------------------------===//
780 /// \name Simple mod/ref information
781 /// @{
782
783 /// Returns a bitmask that should be unconditionally applied to the ModRef
784 /// info of a memory location. This allows us to eliminate Mod and/or Ref from
785 /// the ModRef info based on the knowledge that the memory location points to
786 /// constant and/or locally-invariant memory.
788 AAQueryInfo &AAQI,
789 bool IgnoreLocals) = 0;
790
791 /// Get the ModRef info associated with a pointer argument of a callsite. The
792 /// result's bits are set to indicate the allowed aliasing ModRef kinds. Note
793 /// that these bits do not necessarily account for the overall behavior of
794 /// the function, but rather only provide additional per-argument
795 /// information.
797 unsigned ArgIdx) = 0;
798
799 /// Return the behavior of the given call site.
801 AAQueryInfo &AAQI) = 0;
802
803 /// Return the behavior when calling the given function.
805
806 /// getModRefInfo (for call sites) - Return information about whether
807 /// a particular call site modifies or reads the specified memory location.
809 const MemoryLocation &Loc,
810 AAQueryInfo &AAQI) = 0;
811
812 /// Return information about whether two call sites may refer to the same set
813 /// of memory locations. See the AA documentation for details:
814 /// http://llvm.org/docs/AliasAnalysis.html#ModRefInfo
815 virtual ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
816 AAQueryInfo &AAQI) = 0;
817
818 /// getModRefInfo (for fences) - Return information about whether
819 /// a particular fence modifies or reads the specified memory location.
821 const MemoryLocation &Loc,
822 AAQueryInfo &AAQI) = 0;
823
824 /// @}
825};
826
827/// A private class template which derives from \c Concept and wraps some other
828/// type.
829///
830/// This models the concept by directly forwarding each interface point to the
831/// wrapped type which must implement a compatible interface. This provides
832/// a type erased binding.
833template <typename AAResultT> class AAResults::Model final : public Concept {
834 AAResultT &Result;
835
836public:
837 explicit Model(AAResultT &Result, AAResults &AAR) : Result(Result) {}
838 ~Model() override = default;
839
840 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
841 AAQueryInfo &AAQI, const Instruction *CtxI) override {
842 return Result.alias(LocA, LocB, AAQI, CtxI);
843 }
844
845 AliasResult aliasErrno(const MemoryLocation &Loc, const Module *M) override {
846 return Result.aliasErrno(Loc, M);
847 }
848
849 ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI,
850 bool IgnoreLocals) override {
851 return Result.getModRefInfoMask(Loc, AAQI, IgnoreLocals);
852 }
853
854 ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) override {
855 return Result.getArgModRefInfo(Call, ArgIdx);
856 }
857
858 MemoryEffects getMemoryEffects(const CallBase *Call,
859 AAQueryInfo &AAQI) override {
860 return Result.getMemoryEffects(Call, AAQI);
861 }
862
863 MemoryEffects getMemoryEffects(const Function *F) override {
864 return Result.getMemoryEffects(F);
865 }
866
867 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
868 AAQueryInfo &AAQI) override {
869 return Result.getModRefInfo(Call, Loc, AAQI);
870 }
871
872 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
873 AAQueryInfo &AAQI) override {
874 return Result.getModRefInfo(Call1, Call2, AAQI);
875 }
876
877 ModRefInfo getModRefInfo(const FenceInst *F, const MemoryLocation &Loc,
878 AAQueryInfo &AAQI) override {
879 return Result.getModRefInfo(F, Loc, AAQI);
880 }
881};
882
883/// A base class to help implement the function alias analysis results concept.
884///
885/// Because of the nature of many alias analysis implementations, they often
886/// only implement a subset of the interface. This base class will attempt to
887/// implement the remaining portions of the interface in terms of simpler forms
888/// of the interface where possible, and otherwise provide conservatively
889/// correct fallback implementations.
890///
891/// Implementors of an alias analysis should derive from this class, and then
892/// override specific methods that they wish to customize. There is no need to
893/// use virtual anywhere.
895protected:
896 explicit AAResultBase() = default;
897
898 // Provide all the copy and move constructors so that derived types aren't
899 // constrained.
900 AAResultBase(const AAResultBase &Arg) = default;
902
903public:
905 AAQueryInfo &AAQI, const Instruction *I) {
907 }
908
912
914 bool IgnoreLocals) {
915 return ModRefInfo::ModRef;
916 }
917
918 ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) {
919 return ModRefInfo::ModRef;
920 }
921
925
929
934
935 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
936 AAQueryInfo &AAQI) {
937 return ModRefInfo::ModRef;
938 }
939
941 AAQueryInfo &AAQI) {
942 return ModRefInfo::ModRef;
943 }
944};
945
946/// Return true if this pointer is returned by a noalias function.
947LLVM_ABI bool isNoAliasCall(const Value *V);
948
949/// Return true if this pointer refers to a distinct and identifiable object.
950/// This returns true for:
951/// Global Variables and Functions (but not Global Aliases)
952/// Allocas
953/// ByVal and NoAlias Arguments
954/// NoAlias returns (e.g. calls to malloc)
955///
956LLVM_ABI bool isIdentifiedObject(const Value *V);
957
958/// Return true if V is umabigously identified at the function-level.
959/// Different IdentifiedFunctionLocals can't alias.
960/// Further, an IdentifiedFunctionLocal can not alias with any function
961/// arguments other than itself, which is not necessarily true for
962/// IdentifiedObjects.
963LLVM_ABI bool isIdentifiedFunctionLocal(const Value *V);
964
965/// Return true if we know V to the base address of the corresponding memory
966/// object. This implies that any address less than V must be out of bounds
967/// for the underlying object. Note that just being isIdentifiedObject() is
968/// not enough - For example, a negative offset from a noalias argument or call
969/// can be inbounds w.r.t the actual underlying object.
970LLVM_ABI bool isBaseOfObject(const Value *V);
971
972/// Returns true if the pointer is one which would have been considered an
973/// escape by isNotCapturedBefore.
974LLVM_ABI bool isEscapeSource(const Value *V);
975
976/// Return true if Object memory is not visible after an unwind, in the sense
977/// that program semantics cannot depend on Object containing any particular
978/// value on unwind. If the RequiresNoCaptureBeforeUnwind out parameter is set
979/// to true, then the memory is only not visible if the object has not been
980/// captured prior to the unwind. Otherwise it is not visible even if captured.
981LLVM_ABI bool isNotVisibleOnUnwind(const Value *Object,
982 bool &RequiresNoCaptureBeforeUnwind);
983
984/// Return true if the Object is writable, in the sense that any location based
985/// on this pointer that can be loaded can also be stored to without trapping.
986/// Additionally, at the point Object is declared, stores can be introduced
987/// without data races. At later points, this is only the case if the pointer
988/// can not escape to a different thread.
989///
990/// If ExplicitlyDereferenceableOnly is set to true, this property only holds
991/// for the part of Object that is explicitly marked as dereferenceable, e.g.
992/// using the dereferenceable(N) attribute. It does not necessarily hold for
993/// parts that are only known to be dereferenceable due to the presence of
994/// loads.
995LLVM_ABI bool isWritableObject(const Value *Object,
996 bool &ExplicitlyDereferenceableOnly);
997
998/// Get ModRefInfo for a synchronizing operation, such as a fence or stronger
999/// than monotonic atomic load/store.
1000LLVM_ABI ModRefInfo getSyncEffects(AAResults *AA, const MemoryLocation &Loc,
1001 AAQueryInfo &AAQI);
1002
1003/// A manager for alias analyses.
1004///
1005/// This class can have analyses registered with it and when run, it will run
1006/// all of them and aggregate their results into single AA results interface
1007/// that dispatches across all of the alias analysis results available.
1008///
1009/// Note that the order in which analyses are registered is very significant.
1010/// That is the order in which the results will be aggregated and queried.
1011///
1012/// This manager effectively wraps the AnalysisManager for registering alias
1013/// analyses. When you register your alias analysis with this manager, it will
1014/// ensure the analysis itself is registered with its AnalysisManager.
1015///
1016/// The result of this analysis is only invalidated if one of the particular
1017/// aggregated AA results end up being invalidated. This removes the need to
1018/// explicitly preserve the results of `AAManager`. Note that analyses should no
1019/// longer be registered once the `AAManager` is run.
1020class AAManager : public AnalysisInfoMixin<AAManager> {
1021public:
1023
1024 /// Register a specific AA result.
1025 template <typename AnalysisT> void registerFunctionAnalysis() {
1026 ResultGetters.push_back(&getFunctionAAResultImpl<AnalysisT>);
1027 }
1028
1029 /// Register a specific AA result.
1030 template <typename AnalysisT> void registerModuleAnalysis() {
1031 ResultGetters.push_back(&getModuleAAResultImpl<AnalysisT>);
1032 }
1033
1035
1036private:
1038
1039 LLVM_ABI static AnalysisKey Key;
1040
1043 4> ResultGetters;
1044
1045 template <typename AnalysisT>
1046 static void getFunctionAAResultImpl(Function &F,
1049 AAResults.addAAResult(AM.template getResult<AnalysisT>(F));
1050 AAResults.addAADependencyID(AnalysisT::ID());
1051 }
1052
1053 template <typename AnalysisT>
1054 static void getModuleAAResultImpl(Function &F, FunctionAnalysisManager &AM,
1055 AAResults &AAResults) {
1056 auto &MAMProxy = AM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
1057 if (auto *R =
1058 MAMProxy.template getCachedResult<AnalysisT>(*F.getParent())) {
1059 AAResults.addAAResult(*R);
1060 MAMProxy
1061 .template registerOuterAnalysisInvalidation<AnalysisT, AAManager>();
1062 }
1063 }
1064};
1065
1066/// A wrapper pass to provide the legacy pass manager access to a suitably
1067/// prepared AAResults object.
1069 std::unique_ptr<AAResults> AAR;
1070
1071public:
1072 static char ID;
1073
1075
1076 AAResults &getAAResults() { return *AAR; }
1077 const AAResults &getAAResults() const { return *AAR; }
1078
1079 bool runOnFunction(Function &F) override;
1080
1081 void getAnalysisUsage(AnalysisUsage &AU) const override;
1082};
1083
1084/// A wrapper pass for external alias analyses. This just squirrels away the
1085/// callback used to run any analyses and register their results.
1087 using CallbackT = std::function<void(Pass &, Function &, AAResults &)>;
1088
1090
1091 LLVM_ABI static char ID;
1092
1094
1095 LLVM_ABI explicit ExternalAAWrapperPass(CallbackT CB, bool RunEarly = false);
1096
1097 /// Flag indicating whether this external AA should run before Basic AA.
1098 ///
1099 /// This flag is for LegacyPassManager only. To run an external AA early
1100 /// with the NewPassManager, override the registerEarlyDefaultAliasAnalyses
1101 /// method on the target machine.
1102 ///
1103 /// By default, external AA passes are run after Basic AA. If this flag is
1104 /// set to true, the external AA will be run before Basic AA during alias
1105 /// analysis.
1106 ///
1107 /// For some targets, we prefer to run the external AA early to improve
1108 /// compile time as it has more target-specific information. This is
1109 /// particularly useful when the external AA can provide more precise results
1110 /// than Basic AA so that Basic AA does not need to spend time recomputing
1111 /// them.
1112 bool RunEarly = false;
1113
1114 void getAnalysisUsage(AnalysisUsage &AU) const override {
1115 AU.setPreservesAll();
1116 }
1117};
1118
1119/// A wrapper pass around a callback which can be used to populate the
1120/// AAResults in the AAResultsWrapperPass from an external AA.
1121///
1122/// The callback provided here will be used each time we prepare an AAResults
1123/// object, and will receive a reference to the function wrapper pass, the
1124/// function, and the AAResults object to populate. This should be used when
1125/// setting up a custom pass pipeline to inject a hook into the AA results.
1127 std::function<void(Pass &, Function &, AAResults &)> Callback);
1128
1129} // end namespace llvm
1130
1131#endif // LLVM_ANALYSIS_ALIASANALYSIS_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseMap class.
static bool runOnFunction(Function &F, bool PostInlining)
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Machine Check Debug Module
This file provides utility analysis objects describing memory locations.
#define P(N)
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallVector class.
Value * RHS
Value * LHS
A manager for alias analyses.
void registerFunctionAnalysis()
Register a specific AA result.
LLVM_ABI Result run(Function &F, FunctionAnalysisManager &AM)
void registerModuleAnalysis()
Register a specific AA result.
This class stores info we want to provide to or retain within an alias query.
AAQueryInfo(AAResults &AAR, CaptureAnalysis *CA)
SmallVector< AAQueryInfo::LocPair, 4 > AssumptionBasedResults
Location pairs for which an assumption based result is currently stored.
unsigned Depth
Query depth used to distinguish recursive queries.
bool UseDominatorTree
Whether alias analysis is allowed to use the dominator tree, for use by passes that lazily update the...
int NumAssumptionUses
How many active NoAlias assumption uses there are.
std::pair< AACacheLoc, AACacheLoc > LocPair
AliasCacheT AliasCache
SmallDenseMap< LocPair, CacheEntry, 8 > AliasCacheT
bool MayBeCrossIteration
Tracks whether the accesses may be on different cycle iterations.
CaptureAnalysis * CA
ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2, AAQueryInfo &AAQI)
ModRefInfo getModRefInfo(const FenceInst *F, const MemoryLocation &Loc, AAQueryInfo &AAQI)
AAResultBase(const AAResultBase &Arg)=default
MemoryEffects getMemoryEffects(const CallBase *Call, AAQueryInfo &AAQI)
ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool IgnoreLocals)
MemoryEffects getMemoryEffects(const Function *F)
AliasResult aliasErrno(const MemoryLocation &Loc, const Module *M)
AAResultBase(AAResultBase &&Arg)
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
AAResultBase()=default
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI, const Instruction *I)
const AAResults & getAAResults() const
A private abstract base class describing the concept of an individual alias analysis implementation.
virtual AliasResult aliasErrno(const MemoryLocation &Loc, const Module *M)=0
Returns an AliasResult indicating whether a specific memory location aliases errno.
virtual ModRefInfo getModRefInfo(const FenceInst *F, const MemoryLocation &Loc, AAQueryInfo &AAQI)=0
getModRefInfo (for fences) - Return information about whether a particular fence modifies or reads th...
virtual AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI, const Instruction *CtxI)=0
The main low level interface to the alias analysis implementation.
virtual MemoryEffects getMemoryEffects(const CallBase *Call, AAQueryInfo &AAQI)=0
Return the behavior of the given call site.
virtual ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2, AAQueryInfo &AAQI)=0
Return information about whether two call sites may refer to the same set of memory locations.
virtual ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool IgnoreLocals)=0
Returns a bitmask that should be unconditionally applied to the ModRef info of a memory location.
virtual ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)=0
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
virtual ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)=0
Get the ModRef info associated with a pointer argument of a callsite.
virtual MemoryEffects getMemoryEffects(const Function *F)=0
Return the behavior when calling the given function.
bool canInstructionRangeModRef(const Instruction &I1, const Instruction &I2, const Value *Ptr, LocationSize Size, const ModRefInfo Mode)
A convenience wrapper synthesizing a memory location.
bool pointsToConstantMemory(const Value *P, bool OrLocal=false)
A convenience wrapper around the primary pointsToConstantMemory interface.
friend class AAResultBase
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal=false)
Checks whether the given location points to constant memory, or if OrLocal is true whether it points ...
ModRefInfo getModRefInfo(const Instruction *I, const std::optional< MemoryLocation > &OptLoc)
Check whether or not an instruction may read or write the optionally specified memory location.
bool doesNotAccessMemory(const Function *F)
Checks if the specified function is known to never read or write memory.
AliasResult alias(const Value *V1, const Value *V2)
A convenience wrapper around the primary alias interface.
AliasResult alias(const Value *V1, LocationSize V1Size, const Value *V2, LocationSize V2Size)
A convenience wrapper around the primary alias interface.
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are must-alias.
bool doesNotAccessMemory(const CallBase *Call)
Checks if the specified call is known to never read or write memory.
bool isNoAlias(const Value *V1, LocationSize V1Size, const Value *V2, LocationSize V2Size)
A convenience wrapper around the isNoAlias helper interface.
LLVM_ABI AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
friend class BatchAAResults
ModRefInfo getModRefInfo(const Instruction *I, const Value *P, LocationSize Size)
A convenience wrapper for constructing the memory location.
bool canBasicBlockModify(const BasicBlock &BB, const Value *P, LocationSize Size)
A convenience wrapper synthesizing a memory location.
LLVM_ABI ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, bool IgnoreLocals=false)
Returns a bitmask that should be unconditionally applied to the ModRef info of a memory location.
bool isNoAlias(const Value *V1, const Value *V2)
A convenience wrapper around the isNoAlias helper interface.
bool onlyReadsMemory(const Function *F)
Checks if the specified function is known to only read from non-volatile memory (or not access memory...
ModRefInfo callCapturesBefore(const Instruction *I, const MemoryLocation &MemLoc, DominatorTree *DT)
Return information about whether a particular call site modifies or reads the specified memory locati...
LLVM_ABI AAResults(const TargetLibraryInfo &TLI)
LLVM_ABI MemoryEffects getMemoryEffects(const CallBase *Call)
Return the behavior of the given call site.
bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are no-alias.
ModRefInfo getModRefInfoMask(const Value *P, bool IgnoreLocals=false)
A convenience wrapper around the primary getModRefInfoMask interface.
LLVM_ABI bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
LLVM_ABI ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
Get the ModRef info associated with a pointer argument of a call.
bool onlyReadsMemory(const CallBase *Call)
Checks if the specified call is known to only read from non-volatile memory (or not access memory at ...
LLVM_ABI bool canInstructionRangeModRef(const Instruction &I1, const Instruction &I2, const MemoryLocation &Loc, const ModRefInfo Mode)
Check if it is possible for the execution of the specified instructions to mod(according to the mode)...
bool isMustAlias(const Value *V1, const Value *V2)
A convenience wrapper around the isMustAlias helper interface.
LLVM_ABI AliasResult aliasErrno(const MemoryLocation &Loc, const Module *M)
void addAAResult(AAResultT &AAResult)
Register a specific AA result.
void addAADependencyID(AnalysisKey *ID)
Register a function analysis ID that the results aggregation depends on.
LLVM_ABI ~AAResults()
ModRefInfo callCapturesBefore(const Instruction *I, const Value *P, LocationSize Size, DominatorTree *DT)
A convenience wrapper to synthesize a memory location.
LLVM_ABI bool canBasicBlockModify(const BasicBlock &BB, const MemoryLocation &Loc)
Check if it is possible for execution of the specified basic block to modify the location Loc.
The possible results of an alias query.
constexpr AliasResult(const Kind &Alias)
bool operator==(const AliasResult &Other) const
bool operator!=(Kind K) const
AliasResult()=delete
void swap(bool DoSwap=true)
Helper for processing AliasResult for swapped memory location pairs.
bool operator==(Kind K) const
@ MayAlias
The two locations may or may not alias.
@ NoAlias
The two locations do not alias at all.
@ PartialAlias
The two locations alias, but only due to a partial overlap.
@ MustAlias
The two locations precisely alias each other.
void setOffset(int32_t NewOffset)
bool operator!=(const AliasResult &Other) const
constexpr int32_t getOffset() const
constexpr bool hasOffset() const
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
LLVM Basic Block Representation.
Definition BasicBlock.h:62
BatchAACrossIterationScope(BatchAAResults &BAA, bool CrossIteration)
This class is a wrapper over an AAResults, and it is intended to be used only when there are no IR ch...
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
BatchAAResults(AAResults &AAR)
friend class BatchAACrossIterationScope
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
void disableDominatorTree()
Disable the use of the dominator tree during alias analysis queries.
BatchAAResults(AAResults &AAR, CaptureAnalysis *CA)
void enableCrossIterationMode()
Assume that values may come from different cycle iterations.
bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
ModRefInfo getModRefInfo(const Instruction *I, const CallBase *Call2)
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal=false)
bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
MemoryEffects getMemoryEffects(const CallBase *Call)
bool isMustAlias(const Value *V1, const Value *V2)
ModRefInfo getModRefInfo(const Instruction *I, const std::optional< MemoryLocation > &OptLoc)
bool pointsToConstantMemory(const Value *P, bool OrLocal=false)
ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, bool IgnoreLocals=false)
ModRefInfo callCapturesBefore(const Instruction *I, const MemoryLocation &MemLoc, DominatorTree *DT)
ModRefInfo getModRefInfo(const Instruction *I, const Instruction *I2)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:159
EarliestEscapeAnalysis(DominatorTree &DT, const LoopInfo *LI=nullptr, const CycleInfo *CI=nullptr)
An instruction for ordering other memory operations.
FunctionPass(char &pid)
Definition Pass.h:316
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition Pass.h:285
ImmutablePass(char &pid)
Definition Pass.h:287
An instruction for reading from memory.
static LocationSize precise(uint64_t Value)
bool doesNotAccessMemory() const
Whether this function accesses no memory.
Definition ModRef.h:246
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
Definition ModRef.h:249
static MemoryEffectsBase unknown()
Definition ModRef.h:123
Representation for a specific memory location.
static MemoryLocation getBeforeOrAfter(const Value *Ptr, const AAMDNodes &AATags=AAMDNodes())
Return a location that may access any location before or after Ptr, while remaining within the underl...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
Pass interface - Implemented by all 'passes'.
Definition Pass.h:99
PointerIntPair - This class implements a pair of a pointer and small integer.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
AAQueryInfo that uses SimpleCaptureAnalysis.
SimpleAAQueryInfo(AAResults &AAR)
Context-free CaptureAnalysis provider, which computes and caches whether an object is captured in the...
CaptureComponents getCapturesBefore(const Value *Object, const Instruction *I, bool OrAt, bool ReturnCaptures) override
Return how Object may be captured before instruction I, considering only provenance captures.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
Provides information about what library functions are available for the current target.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM Value Representation.
Definition Value.h:75
CallInst * Call
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:165
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
LLVM_ABI bool isBaseOfObject(const Value *V)
Return true if we know V to the base address of the corresponding memory object.
LLVM_ABI bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:356
LLVM_ABI ModRefInfo getSyncEffects(AAResults *AA, const MemoryLocation &Loc, AAQueryInfo &AAQI)
Get ModRefInfo for a synchronizing operation, such as a fence or stronger than monotonic atomic load/...
LLVM_ABI bool isNotVisibleOnUnwind(const Value *Object, bool &RequiresNoCaptureBeforeUnwind)
Return true if Object memory is not visible after an unwind, in the sense that program semantics cann...
CaptureComponents
Components of the pointer that may be captured.
Definition ModRef.h:365
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
Definition ModRef.h:28
@ ModRef
The access may reference and may modify the value stored in memory.
Definition ModRef.h:36
@ Other
Any other memory.
Definition ModRef.h:68
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
LLVM_ABI bool isIdentifiedFunctionLocal(const Value *V)
Return true if V is umabigously identified at the function-level.
LLVM_ABI bool isEscapeSource(const Value *V)
Returns true if the pointer is one which would have been considered an escape by isNotCapturedBefore.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
AAResults AliasAnalysis
Temporary typedef for legacy code that uses a generic AliasAnalysis pointer or reference.
bool isNoModRef(const ModRefInfo MRI)
Definition ModRef.h:40
LLVM_ABI bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
LLVM_ABI bool isWritableObject(const Value *Object, bool &ExplicitlyDereferenceableOnly)
Return true if the Object is writable, in the sense that any location based on this pointer that can ...
LLVM_ABI ImmutablePass * createExternalAAWrapperPass(std::function< void(Pass &, Function &, AAResults &)> Callback)
A wrapper pass around a callback which can be used to populate the AAResults in the AAResultsWrapperP...
Cache key for BasicAA results.
PointerIntPair< const Value *, 1, bool > PtrTy
AACacheLoc(const Value *Ptr, LocationSize Size, bool MayBeCrossIteration)
LocationSize Size
AACacheLoc(PtrTy Ptr, LocationSize Size)
bool isAssumption() const
Whether this is an assumption that has not been proven yet.
bool isDefinitive() const
Whether this is a definitive (non-assumption) result.
static constexpr int Definitive
Cache entry is neither an assumption nor does it use a (non-definitive) assumption.
static constexpr int AssumptionBased
Cache entry is not an assumption itself, but may be using an assumption from higher up the stack.
int NumAssumptionUses
Number of times a NoAlias assumption has been used, 0 for assumptions that have not been used.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
Virtual base class for providers of capture analysis.
virtual CaptureComponents getCapturesBefore(const Value *Object, const Instruction *I, bool OrAt, bool ReturnCaptures)=0
Return how Object may be captured before instruction I, considering only provenance captures.
virtual ~CaptureAnalysis()=0
static bool isEqual(const AACacheLoc &LHS, const AACacheLoc &RHS)
static unsigned getHashValue(const AACacheLoc &Val)
static AACacheLoc getTombstoneKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
std::function< void(Pass &, Function &, AAResults &)> CallbackT
static LLVM_ABI char ID
bool RunEarly
Flag indicating whether this external AA should run before Basic AA.