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> {
228 static bool isEqual(const AACacheLoc &LHS, const AACacheLoc &RHS) {
229 return LHS.Ptr == RHS.Ptr && LHS.Size == RHS.Size;
230 }
231};
232
233class AAResults;
234
235/// This class stores info we want to provide to or retain within an alias
236/// query. By default, the root query is stateless and starts with a freshly
237/// constructed info object. Specific alias analyses can use this query info to
238/// store per-query state that is important for recursive or nested queries to
239/// avoid recomputing. To enable preserving this state across multiple queries
240/// where safe (due to the IR not changing), use a `BatchAAResults` wrapper.
241/// The information stored in an `AAQueryInfo` is currently limitted to the
242/// caches used by BasicAA, but can further be extended to fit other AA needs.
244public:
245 using LocPair = std::pair<AACacheLoc, AACacheLoc>;
246 struct CacheEntry {
247 /// Cache entry is neither an assumption nor does it use a (non-definitive)
248 /// assumption.
249 static constexpr int Definitive = -2;
250 /// Cache entry is not an assumption itself, but may be using an assumption
251 /// from higher up the stack.
252 static constexpr int AssumptionBased = -1;
253
255 /// Number of times a NoAlias assumption has been used, 0 for assumptions
256 /// that have not been used. Can also take one of the Definitive or
257 /// AssumptionBased values documented above.
259
260 /// Whether this is a definitive (non-assumption) result.
261 bool isDefinitive() const { return NumAssumptionUses == Definitive; }
262 /// Whether this is an assumption that has not been proven yet.
263 bool isAssumption() const { return NumAssumptionUses >= 0; }
264 };
265
266 // Alias analysis result aggregration using which this query is performed.
267 // Can be used to perform recursive queries.
269
272
274
275 /// Query depth used to distinguish recursive queries.
276 unsigned Depth = 0;
277
278 /// How many active NoAlias assumption uses there are.
280
281 /// Location pairs for which an assumption based result is currently stored.
282 /// Used to remove all potentially incorrect results from the cache if an
283 /// assumption is disproven.
285
286 /// Tracks whether the accesses may be on different cycle iterations.
287 ///
288 /// When interpret "Value" pointer equality as value equality we need to make
289 /// sure that the "Value" is not part of a cycle. Otherwise, two uses could
290 /// come from different "iterations" of a cycle and see different values for
291 /// the same "Value" pointer.
292 ///
293 /// The following example shows the problem:
294 /// %p = phi(%alloca1, %addr2)
295 /// %l = load %ptr
296 /// %addr1 = gep, %alloca2, 0, %l
297 /// %addr2 = gep %alloca2, 0, (%l + 1)
298 /// alias(%p, %addr1) -> MayAlias !
299 /// store %l, ...
301
302 /// Whether alias analysis is allowed to use the dominator tree, for use by
303 /// passes that lazily update the DT while performing AA queries.
304 bool UseDominatorTree = true;
305
307};
308
309/// AAQueryInfo that uses SimpleCaptureAnalysis.
312
313public:
315};
316
317class BatchAAResults;
318
320public:
321 // Make these results default constructable and movable. We have to spell
322 // these out because MSVC won't synthesize them.
326
327 /// Register a specific AA result.
328 template <typename AAResultT> void addAAResult(AAResultT &AAResult) {
329 // FIXME: We should use a much lighter weight system than the usual
330 // polymorphic pattern because we don't own AAResult. It should
331 // ideally involve two pointers and no separate allocation.
332 AAs.emplace_back(new Model<AAResultT>(AAResult, *this));
333 }
334
335 /// Register a function analysis ID that the results aggregation depends on.
336 ///
337 /// This is used in the new pass manager to implement the invalidation logic
338 /// where we must invalidate the results aggregation if any of our component
339 /// analyses become invalid.
340 void addAADependencyID(AnalysisKey *ID) { AADeps.push_back(ID); }
341
342 /// Handle invalidation events in the new pass manager.
343 ///
344 /// The aggregation is invalidated if any of the underlying analyses is
345 /// invalidated.
347 FunctionAnalysisManager::Invalidator &Inv);
348
349 //===--------------------------------------------------------------------===//
350 /// \name Alias Queries
351 /// @{
352
353 /// The main low level interface to the alias analysis implementation.
354 /// Returns an AliasResult indicating whether the two pointers are aliased to
355 /// each other. This is the interface that must be implemented by specific
356 /// alias analysis implementations.
358 const MemoryLocation &LocB);
359
360 /// A convenience wrapper around the primary \c alias interface.
361 AliasResult alias(const Value *V1, LocationSize V1Size, const Value *V2,
362 LocationSize V2Size) {
363 return alias(MemoryLocation(V1, V1Size), MemoryLocation(V2, V2Size));
364 }
365
366 /// A convenience wrapper around the primary \c alias interface.
371
372 /// A trivial helper function to check to see if the specified pointers are
373 /// no-alias.
374 bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
375 return alias(LocA, LocB) == AliasResult::NoAlias;
376 }
377
378 /// A convenience wrapper around the \c isNoAlias helper interface.
379 bool isNoAlias(const Value *V1, LocationSize V1Size, const Value *V2,
380 LocationSize V2Size) {
381 return isNoAlias(MemoryLocation(V1, V1Size), MemoryLocation(V2, V2Size));
382 }
383
384 /// A convenience wrapper around the \c isNoAlias helper interface.
385 bool isNoAlias(const Value *V1, const Value *V2) {
388 }
389
390 /// A trivial helper function to check to see if the specified pointers are
391 /// must-alias.
392 bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
393 return alias(LocA, LocB) == AliasResult::MustAlias;
394 }
395
396 /// A convenience wrapper around the \c isMustAlias helper interface.
397 bool isMustAlias(const Value *V1, const Value *V2) {
398 return alias(V1, LocationSize::precise(1), V2, LocationSize::precise(1)) ==
400 }
401
402 /// Checks whether the given location points to constant memory, or if
403 /// \p OrLocal is true whether it points to a local alloca.
404 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal = false) {
405 return isNoModRef(getModRefInfoMask(Loc, OrLocal));
406 }
407
408 /// A convenience wrapper around the primary \c pointsToConstantMemory
409 /// interface.
410 bool pointsToConstantMemory(const Value *P, bool OrLocal = false) {
412 }
413
414 /// @}
415 //===--------------------------------------------------------------------===//
416 /// \name Simple mod/ref information
417 /// @{
418
419 /// Returns a bitmask that should be unconditionally applied to the ModRef
420 /// info of a memory location. This allows us to eliminate Mod and/or Ref
421 /// from the ModRef info based on the knowledge that the memory location
422 /// points to constant and/or locally-invariant memory.
423 ///
424 /// If IgnoreLocals is true, then this method returns NoModRef for memory
425 /// that points to a local alloca.
427 bool IgnoreLocals = false);
428
429 /// A convenience wrapper around the primary \c getModRefInfoMask
430 /// interface.
431 ModRefInfo getModRefInfoMask(const Value *P, bool IgnoreLocals = false) {
433 }
434
435 /// Get the ModRef info associated with a pointer argument of a call. The
436 /// result's bits are set to indicate the allowed aliasing ModRef kinds. Note
437 /// that these bits do not necessarily account for the overall behavior of
438 /// the function, but rather only provide additional per-argument
439 /// information.
440 LLVM_ABI ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx);
441
442 /// Return the behavior of the given call site.
444
445 /// Return the behavior when calling the given function.
447
448 /// Checks if the specified call is known to never read or write memory.
449 ///
450 /// Note that if the call only reads from known-constant memory, it is also
451 /// legal to return true. Also, calls that unwind the stack are legal for
452 /// this predicate.
453 ///
454 /// Many optimizations (such as CSE and LICM) can be performed on such calls
455 /// without worrying about aliasing properties, and many calls have this
456 /// property (e.g. calls to 'sin' and 'cos').
457 ///
458 /// This property corresponds to the GCC 'const' attribute.
462
463 /// Checks if the specified function is known to never read or write memory.
464 ///
465 /// Note that if the function only reads from known-constant memory, it is
466 /// also legal to return true. Also, function that unwind the stack are legal
467 /// for this predicate.
468 ///
469 /// Many optimizations (such as CSE and LICM) can be performed on such calls
470 /// to such functions without worrying about aliasing properties, and many
471 /// functions have this property (e.g. 'sin' and 'cos').
472 ///
473 /// This property corresponds to the GCC 'const' attribute.
477
478 /// Checks if the specified call is known to only read from non-volatile
479 /// memory (or not access memory at all).
480 ///
481 /// Calls that unwind the stack are legal for this predicate.
482 ///
483 /// This property allows many common optimizations to be performed in the
484 /// absence of interfering store instructions, such as CSE of strlen calls.
485 ///
486 /// This property corresponds to the GCC 'pure' attribute.
490
491 /// Checks if the specified function is known to only read from non-volatile
492 /// memory (or not access memory at all).
493 ///
494 /// Functions that unwind the stack are legal for this predicate.
495 ///
496 /// This property allows many common optimizations to be performed in the
497 /// absence of interfering store instructions, such as CSE of strlen calls.
498 ///
499 /// This property corresponds to the GCC 'pure' attribute.
502 }
503
504 /// Check whether or not an instruction may read or write the optionally
505 /// specified memory location.
506 ///
507 ///
508 /// An instruction that doesn't read or write memory may be trivially LICM'd
509 /// for example.
510 ///
511 /// For function calls, this delegates to the alias-analysis specific
512 /// call-site mod-ref behavior queries. Otherwise it delegates to the specific
513 /// helpers above.
515 const std::optional<MemoryLocation> &OptLoc) {
516 SimpleAAQueryInfo AAQIP(*this);
517 return getModRefInfo(I, OptLoc, AAQIP);
518 }
519
520 /// A convenience wrapper for constructing the memory location.
525
526 /// Return information about whether a call and an instruction may refer to
527 /// the same memory locations.
529
530 /// Return information about whether two instructions may refer to the same
531 /// memory locations.
533 const Instruction *I2);
534
535 /// Return information about whether a particular call site modifies
536 /// or reads the specified memory location \p MemLoc before instruction \p I
537 /// in a BasicBlock.
539 const MemoryLocation &MemLoc,
540 DominatorTree *DT) {
541 SimpleAAQueryInfo AAQIP(*this);
542 return callCapturesBefore(I, MemLoc, DT, AAQIP);
543 }
544
545 /// A convenience wrapper to synthesize a memory location.
550
551 /// @}
552 //===--------------------------------------------------------------------===//
553 /// \name Higher level methods for querying mod/ref information.
554 /// @{
555
556 /// Check if it is possible for execution of the specified basic block to
557 /// modify the location Loc.
559 const MemoryLocation &Loc);
560
561 /// A convenience wrapper synthesizing a memory location.
562 bool canBasicBlockModify(const BasicBlock &BB, const Value *P,
565 }
566
567 /// Check if it is possible for the execution of the specified instructions
568 /// to mod\ref (according to the mode) the location Loc.
569 ///
570 /// The instructions to consider are all of the instructions in the range of
571 /// [I1,I2] INCLUSIVE. I1 and I2 must be in the same basic block.
573 const Instruction &I2,
574 const MemoryLocation &Loc,
575 const ModRefInfo Mode);
576
577 /// A convenience wrapper synthesizing a memory location.
579 const Value *Ptr, LocationSize Size,
580 const ModRefInfo Mode) {
581 return canInstructionRangeModRef(I1, I2, MemoryLocation(Ptr, Size), Mode);
582 }
583
584 // CtxI can be nullptr, in which case the query is whether or not the aliasing
585 // relationship holds through the entire function.
587 const MemoryLocation &LocB, AAQueryInfo &AAQI,
588 const Instruction *CtxI = nullptr);
590
592 AAQueryInfo &AAQI,
593 bool IgnoreLocals = false);
595 AAQueryInfo &AAQIP);
597 const MemoryLocation &Loc,
598 AAQueryInfo &AAQI);
600 const CallBase *Call2, AAQueryInfo &AAQI);
602 const MemoryLocation &Loc,
603 AAQueryInfo &AAQI);
605 const MemoryLocation &Loc,
606 AAQueryInfo &AAQI);
608 const MemoryLocation &Loc,
609 AAQueryInfo &AAQI);
611 const MemoryLocation &Loc,
612 AAQueryInfo &AAQI);
614 const MemoryLocation &Loc,
615 AAQueryInfo &AAQI);
617 const MemoryLocation &Loc,
618 AAQueryInfo &AAQI);
620 const MemoryLocation &Loc,
621 AAQueryInfo &AAQI);
623 const MemoryLocation &Loc,
624 AAQueryInfo &AAQI);
626 const std::optional<MemoryLocation> &OptLoc,
627 AAQueryInfo &AAQIP);
629 const Instruction *I2, AAQueryInfo &AAQI);
631 const MemoryLocation &MemLoc,
632 DominatorTree *DT, AAQueryInfo &AAQIP);
634 AAQueryInfo &AAQI);
635
636private:
637 class Concept;
638
639 template <typename T> class Model;
640
641 friend class AAResultBase;
642
643 const TargetLibraryInfo &TLI;
644
645 std::vector<std::unique_ptr<Concept>> AAs;
646
647 std::vector<AnalysisKey *> AADeps;
648
649 friend class BatchAAResults;
650};
651
652/// This class is a wrapper over an AAResults, and it is intended to be used
653/// only when there are no IR changes inbetween queries. BatchAAResults is
654/// reusing the same `AAQueryInfo` to preserve the state across queries,
655/// esentially making AA work in "batch mode". The internal state cannot be
656/// cleared, so to go "out-of-batch-mode", the user must either use AAResults,
657/// or create a new BatchAAResults.
659 AAResults &AA;
660 AAQueryInfo AAQI;
661 SimpleCaptureAnalysis SimpleCA;
662
664
665public:
666 BatchAAResults(AAResults &AAR) : AA(AAR), AAQI(AAR, &SimpleCA) {}
668 : AA(AAR), AAQI(AAR, CA) {}
669
670 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
671 return AA.alias(LocA, LocB, AAQI);
672 }
673 bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal = false) {
674 return isNoModRef(AA.getModRefInfoMask(Loc, AAQI, OrLocal));
675 }
676 bool pointsToConstantMemory(const Value *P, bool OrLocal = false) {
678 }
680 bool IgnoreLocals = false) {
681 return AA.getModRefInfoMask(Loc, AAQI, IgnoreLocals);
682 }
684 const std::optional<MemoryLocation> &OptLoc) {
685 return AA.getModRefInfo(I, OptLoc, AAQI);
686 }
688 return AA.getModRefInfo(I, Call2, AAQI);
689 }
691 return AA.getModRefInfo(I, I2, AAQI);
692 }
693 ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) {
694 return AA.getArgModRefInfo(Call, ArgIdx);
695 }
697 return AA.getMemoryEffects(Call, AAQI);
698 }
699 bool isMustAlias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
700 return alias(LocA, LocB) == AliasResult::MustAlias;
701 }
702 bool isMustAlias(const Value *V1, const Value *V2) {
706 }
707 bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB) {
708 return alias(LocA, LocB) == AliasResult::NoAlias;
709 }
711 const MemoryLocation &MemLoc,
712 DominatorTree *DT) {
713 return AA.callCapturesBefore(I, MemLoc, DT, AAQI);
714 }
715
716 /// Assume that values may come from different cycle iterations.
718 AAQI.MayBeCrossIteration = true;
719 }
720
721 /// Disable the use of the dominator tree during alias analysis queries.
722 void disableDominatorTree() { AAQI.UseDominatorTree = false; }
723};
724
725/// Temporarily set the cross iteration mode on a BatchAA instance.
727 BatchAAResults &BAA;
728 bool OrigCrossIteration;
729
730public:
732 : BAA(BAA), OrigCrossIteration(BAA.AAQI.MayBeCrossIteration) {
733 BAA.AAQI.MayBeCrossIteration = CrossIteration;
734 }
736 BAA.AAQI.MayBeCrossIteration = OrigCrossIteration;
737 }
738};
739
740/// Temporary typedef for legacy code that uses a generic \c AliasAnalysis
741/// pointer or reference.
743
744/// A private abstract base class describing the concept of an individual alias
745/// analysis implementation.
746///
747/// This interface is implemented by any \c Model instantiation. It is also the
748/// interface which a type used to instantiate the model must provide.
749///
750/// All of these methods model methods by the same name in the \c
751/// AAResults class. Only differences and specifics to how the
752/// implementations are called are documented here.
754public:
755 virtual ~Concept() = 0;
756
757 //===--------------------------------------------------------------------===//
758 /// \name Alias Queries
759 /// @{
760
761 /// The main low level interface to the alias analysis implementation.
762 /// Returns an AliasResult indicating whether the two pointers are aliased to
763 /// each other. This is the interface that must be implemented by specific
764 /// alias analysis implementations.
765 virtual AliasResult alias(const MemoryLocation &LocA,
766 const MemoryLocation &LocB, AAQueryInfo &AAQI,
767 const Instruction *CtxI) = 0;
768
769 /// Returns an AliasResult indicating whether a specific memory location
770 /// aliases errno.
772 const Module *M) = 0;
773
774 /// @}
775 //===--------------------------------------------------------------------===//
776 /// \name Simple mod/ref information
777 /// @{
778
779 /// Returns a bitmask that should be unconditionally applied to the ModRef
780 /// info of a memory location. This allows us to eliminate Mod and/or Ref from
781 /// the ModRef info based on the knowledge that the memory location points to
782 /// constant and/or locally-invariant memory.
784 AAQueryInfo &AAQI,
785 bool IgnoreLocals) = 0;
786
787 /// Get the ModRef info associated with a pointer argument of a callsite. The
788 /// result's bits are set to indicate the allowed aliasing ModRef kinds. Note
789 /// that these bits do not necessarily account for the overall behavior of
790 /// the function, but rather only provide additional per-argument
791 /// information.
793 unsigned ArgIdx) = 0;
794
795 /// Return the behavior of the given call site.
797 AAQueryInfo &AAQI) = 0;
798
799 /// Return the behavior when calling the given function.
801
802 /// getModRefInfo (for call sites) - Return information about whether
803 /// a particular call site modifies or reads the specified memory location.
805 const MemoryLocation &Loc,
806 AAQueryInfo &AAQI) = 0;
807
808 /// Return information about whether two call sites may refer to the same set
809 /// of memory locations. See the AA documentation for details:
810 /// http://llvm.org/docs/AliasAnalysis.html#ModRefInfo
811 virtual ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
812 AAQueryInfo &AAQI) = 0;
813
814 /// getModRefInfo (for fences) - Return information about whether
815 /// a particular fence modifies or reads the specified memory location.
817 const MemoryLocation &Loc,
818 AAQueryInfo &AAQI) = 0;
819
820 /// @}
821};
822
823/// A private class template which derives from \c Concept and wraps some other
824/// type.
825///
826/// This models the concept by directly forwarding each interface point to the
827/// wrapped type which must implement a compatible interface. This provides
828/// a type erased binding.
829template <typename AAResultT> class AAResults::Model final : public Concept {
830 AAResultT &Result;
831
832public:
833 explicit Model(AAResultT &Result, AAResults &AAR) : Result(Result) {}
834 ~Model() override = default;
835
836 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
837 AAQueryInfo &AAQI, const Instruction *CtxI) override {
838 return Result.alias(LocA, LocB, AAQI, CtxI);
839 }
840
841 AliasResult aliasErrno(const MemoryLocation &Loc, const Module *M) override {
842 return Result.aliasErrno(Loc, M);
843 }
844
845 ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI,
846 bool IgnoreLocals) override {
847 return Result.getModRefInfoMask(Loc, AAQI, IgnoreLocals);
848 }
849
850 ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) override {
851 return Result.getArgModRefInfo(Call, ArgIdx);
852 }
853
854 MemoryEffects getMemoryEffects(const CallBase *Call,
855 AAQueryInfo &AAQI) override {
856 return Result.getMemoryEffects(Call, AAQI);
857 }
858
859 MemoryEffects getMemoryEffects(const Function *F) override {
860 return Result.getMemoryEffects(F);
861 }
862
863 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
864 AAQueryInfo &AAQI) override {
865 return Result.getModRefInfo(Call, Loc, AAQI);
866 }
867
868 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
869 AAQueryInfo &AAQI) override {
870 return Result.getModRefInfo(Call1, Call2, AAQI);
871 }
872
873 ModRefInfo getModRefInfo(const FenceInst *F, const MemoryLocation &Loc,
874 AAQueryInfo &AAQI) override {
875 return Result.getModRefInfo(F, Loc, AAQI);
876 }
877};
878
879/// A base class to help implement the function alias analysis results concept.
880///
881/// Because of the nature of many alias analysis implementations, they often
882/// only implement a subset of the interface. This base class will attempt to
883/// implement the remaining portions of the interface in terms of simpler forms
884/// of the interface where possible, and otherwise provide conservatively
885/// correct fallback implementations.
886///
887/// Implementors of an alias analysis should derive from this class, and then
888/// override specific methods that they wish to customize. There is no need to
889/// use virtual anywhere.
891protected:
892 explicit AAResultBase() = default;
893
894 // Provide all the copy and move constructors so that derived types aren't
895 // constrained.
896 AAResultBase(const AAResultBase &Arg) = default;
898
899public:
901 AAQueryInfo &AAQI, const Instruction *I) {
903 }
904
908
910 bool IgnoreLocals) {
911 return ModRefInfo::ModRef;
912 }
913
914 ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx) {
915 return ModRefInfo::ModRef;
916 }
917
921
925
930
931 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
932 AAQueryInfo &AAQI) {
933 return ModRefInfo::ModRef;
934 }
935
937 AAQueryInfo &AAQI) {
938 return ModRefInfo::ModRef;
939 }
940};
941
942/// Return true if this pointer is returned by a noalias function.
943LLVM_ABI bool isNoAliasCall(const Value *V);
944
945/// Return true if this pointer refers to a distinct and identifiable object.
946/// This returns true for:
947/// Global Variables and Functions (but not Global Aliases)
948/// Allocas
949/// ByVal and NoAlias Arguments
950/// NoAlias returns (e.g. calls to malloc)
951///
952LLVM_ABI bool isIdentifiedObject(const Value *V);
953
954/// Return true if V is umabigously identified at the function-level.
955/// Different IdentifiedFunctionLocals can't alias.
956/// Further, an IdentifiedFunctionLocal can not alias with any function
957/// arguments other than itself, which is not necessarily true for
958/// IdentifiedObjects.
959LLVM_ABI bool isIdentifiedFunctionLocal(const Value *V);
960
961/// Return true if we know V to the base address of the corresponding memory
962/// object. This implies that any address less than V must be out of bounds
963/// for the underlying object. Note that just being isIdentifiedObject() is
964/// not enough - For example, a negative offset from a noalias argument or call
965/// can be inbounds w.r.t the actual underlying object.
966LLVM_ABI bool isBaseOfObject(const Value *V);
967
968/// Returns true if the pointer is one which would have been considered an
969/// escape by isNotCapturedBefore.
970LLVM_ABI bool isEscapeSource(const Value *V);
971
972/// Return true if Object memory is not visible after an unwind, in the sense
973/// that program semantics cannot depend on Object containing any particular
974/// value on unwind. If the RequiresNoCaptureBeforeUnwind out parameter is set
975/// to true, then the memory is only not visible if the object has not been
976/// captured prior to the unwind. Otherwise it is not visible even if captured.
977LLVM_ABI bool isNotVisibleOnUnwind(const Value *Object,
978 bool &RequiresNoCaptureBeforeUnwind);
979
980/// Return true if the Object is writable, in the sense that any location based
981/// on this pointer that can be loaded can also be stored to without trapping.
982/// Additionally, at the point Object is declared, stores can be introduced
983/// without data races. At later points, this is only the case if the pointer
984/// can not escape to a different thread.
985///
986/// If ExplicitlyDereferenceableOnly is set to true, this property only holds
987/// for the part of Object that is explicitly marked as dereferenceable, e.g.
988/// using the dereferenceable(N) attribute. It does not necessarily hold for
989/// parts that are only known to be dereferenceable due to the presence of
990/// loads.
991LLVM_ABI bool isWritableObject(const Value *Object,
992 bool &ExplicitlyDereferenceableOnly);
993
994/// Get ModRefInfo for a synchronizing operation, such as a fence or stronger
995/// than monotonic atomic load/store.
996LLVM_ABI ModRefInfo getSyncEffects(AAResults *AA, const MemoryLocation &Loc,
997 AAQueryInfo &AAQI);
998
999/// A manager for alias analyses.
1000///
1001/// This class can have analyses registered with it and when run, it will run
1002/// all of them and aggregate their results into single AA results interface
1003/// that dispatches across all of the alias analysis results available.
1004///
1005/// Note that the order in which analyses are registered is very significant.
1006/// That is the order in which the results will be aggregated and queried.
1007///
1008/// This manager effectively wraps the AnalysisManager for registering alias
1009/// analyses. When you register your alias analysis with this manager, it will
1010/// ensure the analysis itself is registered with its AnalysisManager.
1011///
1012/// The result of this analysis is only invalidated if one of the particular
1013/// aggregated AA results end up being invalidated. This removes the need to
1014/// explicitly preserve the results of `AAManager`. Note that analyses should no
1015/// longer be registered once the `AAManager` is run.
1016class AAManager : public AnalysisInfoMixin<AAManager> {
1017public:
1019
1020 /// Register a specific AA result.
1021 template <typename AnalysisT> void registerFunctionAnalysis() {
1022 ResultGetters.push_back(&getFunctionAAResultImpl<AnalysisT>);
1023 }
1024
1025 /// Register a specific AA result.
1026 template <typename AnalysisT> void registerModuleAnalysis() {
1027 ResultGetters.push_back(&getModuleAAResultImpl<AnalysisT>);
1028 }
1029
1031
1032private:
1034
1035 LLVM_ABI static AnalysisKey Key;
1036
1039 4> ResultGetters;
1040
1041 template <typename AnalysisT>
1042 static void getFunctionAAResultImpl(Function &F,
1045 AAResults.addAAResult(AM.template getResult<AnalysisT>(F));
1046 AAResults.addAADependencyID(AnalysisT::ID());
1047 }
1048
1049 template <typename AnalysisT>
1050 static void getModuleAAResultImpl(Function &F, FunctionAnalysisManager &AM,
1051 AAResults &AAResults) {
1052 auto &MAMProxy = AM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
1053 if (auto *R =
1054 MAMProxy.template getCachedResult<AnalysisT>(*F.getParent())) {
1055 AAResults.addAAResult(*R);
1056 MAMProxy
1057 .template registerOuterAnalysisInvalidation<AnalysisT, AAManager>();
1058 }
1059 }
1060};
1061
1062/// A wrapper pass to provide the legacy pass manager access to a suitably
1063/// prepared AAResults object.
1065 std::unique_ptr<AAResults> AAR;
1066
1067public:
1068 static char ID;
1069
1071
1072 AAResults &getAAResults() { return *AAR; }
1073 const AAResults &getAAResults() const { return *AAR; }
1074
1075 bool runOnFunction(Function &F) override;
1076
1077 void getAnalysisUsage(AnalysisUsage &AU) const override;
1078};
1079
1080/// A wrapper pass for external alias analyses. This just squirrels away the
1081/// callback used to run any analyses and register their results.
1083 using CallbackT = std::function<void(Pass &, Function &, AAResults &)>;
1084
1086
1087 LLVM_ABI static char ID;
1088
1090
1091 LLVM_ABI explicit ExternalAAWrapperPass(CallbackT CB, bool RunEarly = false);
1092
1093 /// Flag indicating whether this external AA should run before Basic AA.
1094 ///
1095 /// This flag is for LegacyPassManager only. To run an external AA early
1096 /// with the NewPassManager, override the registerEarlyDefaultAliasAnalyses
1097 /// method on the target machine.
1098 ///
1099 /// By default, external AA passes are run after Basic AA. If this flag is
1100 /// set to true, the external AA will be run before Basic AA during alias
1101 /// analysis.
1102 ///
1103 /// For some targets, we prefer to run the external AA early to improve
1104 /// compile time as it has more target-specific information. This is
1105 /// particularly useful when the external AA can provide more precise results
1106 /// than Basic AA so that Basic AA does not need to spend time recomputing
1107 /// them.
1108 bool RunEarly = false;
1109
1110 void getAnalysisUsage(AnalysisUsage &AU) const override {
1111 AU.setPreservesAll();
1112 }
1113};
1114
1115/// A wrapper pass around a callback which can be used to populate the
1116/// AAResults in the AAResultsWrapperPass from an external AA.
1117///
1118/// The callback provided here will be used each time we prepare an AAResults
1119/// object, and will receive a reference to the function wrapper pass, the
1120/// function, and the AAResults object to populate. This should be used when
1121/// setting up a custom pass pipeline to inject a hook into the AA results.
1123 std::function<void(Pass &, Function &, AAResults &)> Callback);
1124
1125} // end namespace llvm
1126
1127#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:155
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:68
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)
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.