LLVM 22.0.0git
Attributor.h
Go to the documentation of this file.
1//===- Attributor.h --- Module-wide attribute deduction ---------*- 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// Attributor: An inter procedural (abstract) "attribute" deduction framework.
10//
11// The Attributor framework is an inter procedural abstract analysis (fixpoint
12// iteration analysis). The goal is to allow easy deduction of new attributes as
13// well as information exchange between abstract attributes in-flight.
14//
15// The Attributor class is the driver and the link between the various abstract
16// attributes. The Attributor will iterate until a fixpoint state is reached by
17// all abstract attributes in-flight, or until it will enforce a pessimistic fix
18// point because an iteration limit is reached.
19//
20// Abstract attributes, derived from the AbstractAttribute class, actually
21// describe properties of the code. They can correspond to actual LLVM-IR
22// attributes, or they can be more general, ultimately unrelated to LLVM-IR
23// attributes. The latter is useful when an abstract attributes provides
24// information to other abstract attributes in-flight but we might not want to
25// manifest the information. The Attributor allows to query in-flight abstract
26// attributes through the `Attributor::getAAFor` method (see the method
27// description for an example). If the method is used by an abstract attribute
28// P, and it results in an abstract attribute Q, the Attributor will
29// automatically capture a potential dependence from Q to P. This dependence
30// will cause P to be reevaluated whenever Q changes in the future.
31//
32// The Attributor will only reevaluate abstract attributes that might have
33// changed since the last iteration. That means that the Attribute will not
34// revisit all instructions/blocks/functions in the module but only query
35// an update from a subset of the abstract attributes.
36//
37// The update method `AbstractAttribute::updateImpl` is implemented by the
38// specific "abstract attribute" subclasses. The method is invoked whenever the
39// currently assumed state (see the AbstractState class) might not be valid
40// anymore. This can, for example, happen if the state was dependent on another
41// abstract attribute that changed. In every invocation, the update method has
42// to adjust the internal state of an abstract attribute to a point that is
43// justifiable by the underlying IR and the current state of abstract attributes
44// in-flight. Since the IR is given and assumed to be valid, the information
45// derived from it can be assumed to hold. However, information derived from
46// other abstract attributes is conditional on various things. If the justifying
47// state changed, the `updateImpl` has to revisit the situation and potentially
48// find another justification or limit the optimistic assumes made.
49//
50// Change is the key in this framework. Until a state of no-change, thus a
51// fixpoint, is reached, the Attributor will query the abstract attributes
52// in-flight to re-evaluate their state. If the (current) state is too
53// optimistic, hence it cannot be justified anymore through other abstract
54// attributes or the state of the IR, the state of the abstract attribute will
55// have to change. Generally, we assume abstract attribute state to be a finite
56// height lattice and the update function to be monotone. However, these
57// conditions are not enforced because the iteration limit will guarantee
58// termination. If an optimistic fixpoint is reached, or a pessimistic fix
59// point is enforced after a timeout, the abstract attributes are tasked to
60// manifest their result in the IR for passes to come.
61//
62// Attribute manifestation is not mandatory. If desired, there is support to
63// generate a single or multiple LLVM-IR attributes already in the helper struct
64// IRAttribute. In the simplest case, a subclass inherits from IRAttribute with
65// a proper Attribute::AttrKind as template parameter. The Attributor
66// manifestation framework will then create and place a new attribute if it is
67// allowed to do so (based on the abstract state). Other use cases can be
68// achieved by overloading AbstractAttribute or IRAttribute methods.
69//
70//
71// The "mechanics" of adding a new "abstract attribute":
72// - Define a class (transitively) inheriting from AbstractAttribute and one
73// (which could be the same) that (transitively) inherits from AbstractState.
74// For the latter, consider the already available BooleanState and
75// {Inc,Dec,Bit}IntegerState if they fit your needs, e.g., you require only a
76// number tracking or bit-encoding.
77// - Implement all pure methods. Also use overloading if the attribute is not
78// conforming with the "default" behavior: A (set of) LLVM-IR attribute(s) for
79// an argument, call site argument, function return value, or function. See
80// the class and method descriptions for more information on the two
81// "Abstract" classes and their respective methods.
82// - Register opportunities for the new abstract attribute in the
83// `Attributor::identifyDefaultAbstractAttributes` method if it should be
84// counted as a 'default' attribute.
85// - Add sufficient tests.
86// - Add a Statistics object for bookkeeping. If it is a simple (set of)
87// attribute(s) manifested through the Attributor manifestation framework, see
88// the bookkeeping function in Attributor.cpp.
89// - If instructions with a certain opcode are interesting to the attribute, add
90// that opcode to the switch in `Attributor::identifyAbstractAttributes`. This
91// will make it possible to query all those instructions through the
92// `InformationCache::getOpcodeInstMapForFunction` interface and eliminate the
93// need to traverse the IR repeatedly.
94//
95//===----------------------------------------------------------------------===//
96
97#ifndef LLVM_TRANSFORMS_IPO_ATTRIBUTOR_H
98#define LLVM_TRANSFORMS_IPO_ATTRIBUTOR_H
99
100#include "llvm/ADT/DenseSet.h"
101#include "llvm/ADT/GraphTraits.h"
102#include "llvm/ADT/IntervalMap.h"
103#include "llvm/ADT/MapVector.h"
104#include "llvm/ADT/STLExtras.h"
106#include "llvm/ADT/SetVector.h"
107#include "llvm/ADT/SmallSet.h"
108#include "llvm/ADT/iterator.h"
110#include "llvm/Analysis/CFG.h"
120#include "llvm/IR/Attributes.h"
122#include "llvm/IR/Constants.h"
123#include "llvm/IR/GlobalValue.h"
124#include "llvm/IR/InstIterator.h"
125#include "llvm/IR/Instruction.h"
126#include "llvm/IR/Instructions.h"
127#include "llvm/IR/Module.h"
128#include "llvm/IR/PassManager.h"
129#include "llvm/IR/Value.h"
132#include "llvm/Support/Casting.h"
137#include "llvm/Support/ModRef.h"
142
143#include <limits>
144#include <map>
145#include <optional>
146
147namespace llvm {
148
149class DataLayout;
150class LLVMContext;
151class Pass;
152template <typename Fn> class function_ref;
153struct AADepGraphNode;
154struct AADepGraph;
155struct Attributor;
156struct AbstractAttribute;
157struct InformationCache;
158struct AAIsDead;
159struct AttributorCallGraph;
160struct IRPosition;
161
162class Function;
163
164/// Abstract Attribute helper functions.
165namespace AA {
167
168enum class GPUAddressSpace : unsigned {
169 Generic = 0,
170 Global = 1,
171 Shared = 3,
172 Constant = 4,
173 Local = 5,
174};
175
176/// Return true iff \p M target a GPU (and we can use GPU AS reasoning).
177LLVM_ABI bool isGPU(const Module &M);
178
179/// Flags to distinguish intra-procedural queries from *potentially*
180/// inter-procedural queries. Not that information can be valid for both and
181/// therefore both bits might be set.
186};
187
188struct ValueAndContext : public std::pair<Value *, const Instruction *> {
189 using Base = std::pair<Value *, const Instruction *>;
191 ValueAndContext(Value &V, const Instruction *CtxI) : Base(&V, CtxI) {}
192 ValueAndContext(Value &V, const Instruction &CtxI) : Base(&V, &CtxI) {}
193
194 Value *getValue() const { return this->first; }
195 const Instruction *getCtxI() const { return this->second; }
196};
197
198/// Return true if \p I is a `nosync` instruction. Use generic reasoning and
199/// potentially the corresponding AANoSync.
201 const AbstractAttribute &QueryingAA);
202
203/// Return true if \p V is dynamically unique, that is, there are no two
204/// "instances" of \p V at runtime with different values.
205/// Note: If \p ForAnalysisOnly is set we only check that the Attributor will
206/// never use \p V to represent two "instances" not that \p V could not
207/// technically represent them.
209 const AbstractAttribute &QueryingAA,
210 const Value &V, bool ForAnalysisOnly = true);
211
212/// Return true if \p V is a valid value in \p Scope, that is a constant or an
213/// instruction/argument of \p Scope.
214LLVM_ABI bool isValidInScope(const Value &V, const Function *Scope);
215
216/// Return true if the value of \p VAC is a valid at the position of \p VAC,
217/// that is a constant, an argument of the same function, or an instruction in
218/// that function that dominates the position.
219LLVM_ABI bool isValidAtPosition(const ValueAndContext &VAC,
220 InformationCache &InfoCache);
221
222/// Try to convert \p V to type \p Ty without introducing new instructions. If
223/// this is not possible return `nullptr`. Note: this function basically knows
224/// how to cast various constants.
226
227/// Return the combination of \p A and \p B such that the result is a possible
228/// value of both. \p B is potentially casted to match the type \p Ty or the
229/// type of \p A if \p Ty is null.
230///
231/// Examples:
232/// X + none => X
233/// not_none + undef => not_none
234/// V1 + V2 => nullptr
235LLVM_ABI std::optional<Value *>
236combineOptionalValuesInAAValueLatice(const std::optional<Value *> &A,
237 const std::optional<Value *> &B, Type *Ty);
238
239/// Helper to represent an access offset and size, with logic to deal with
240/// uncertainty and check for overlapping accesses.
241struct RangeTy {
243 int64_t Size = Unassigned;
244
245 RangeTy(int64_t Offset, int64_t Size) : Offset(Offset), Size(Size) {}
246 RangeTy() = default;
247 static RangeTy getUnknown() { return RangeTy{Unknown, Unknown}; }
248
249 /// Return true if offset or size are unknown.
252 }
253
254 /// Return true if offset and size are unknown, thus this is the default
255 /// unknown object.
258 }
259
260 /// Return true if the offset and size are unassigned.
261 bool isUnassigned() const {
263 "Inconsistent state!");
264 return Offset == RangeTy::Unassigned;
265 }
266
267 /// Return true if this offset and size pair might describe an address that
268 /// overlaps with \p Range.
269 bool mayOverlap(const RangeTy &Range) const {
270 // Any unknown value and we are giving up -> overlap.
271 if (offsetOrSizeAreUnknown() || Range.offsetOrSizeAreUnknown())
272 return true;
273
274 // Check if one offset point is in the other interval [offset,
275 // offset+size].
276 return Range.Offset + Range.Size > Offset && Range.Offset < Offset + Size;
277 }
278
280 if (R.isUnassigned())
281 return *this;
282 if (isUnassigned())
283 return *this = R;
284 if (Offset == Unknown || R.Offset == Unknown)
285 Offset = Unknown;
286 if (Size == Unknown || R.Size == Unknown)
287 Size = Unknown;
289 return *this;
290 if (Offset == Unknown) {
291 Size = std::max(Size, R.Size);
292 } else if (Size == Unknown) {
293 Offset = std::min(Offset, R.Offset);
294 } else {
295 Offset = std::min(Offset, R.Offset);
296 Size = std::max(Offset + Size, R.Offset + R.Size) - Offset;
297 }
298 return *this;
299 }
300
301 /// Comparison for sorting ranges.
302 ///
303 /// Returns true if the offset of \p L is less than that of \p R. If the two
304 /// offsets are same, compare the sizes instead.
305 inline static bool LessThan(const RangeTy &L, const RangeTy &R) {
306 if (L.Offset < R.Offset)
307 return true;
308 if (L.Offset == R.Offset)
309 return L.Size < R.Size;
310 return false;
311 }
312
313 /// Constants used to represent special offsets or sizes.
314 /// - We cannot assume that Offsets and Size are non-negative.
315 /// - The constants should not clash with DenseMapInfo, such as EmptyKey
316 /// (INT64_MAX) and TombstoneKey (INT64_MIN).
317 /// We use values "in the middle" of the 64 bit range to represent these
318 /// special cases.
319 static constexpr int64_t Unassigned = std::numeric_limits<int32_t>::min();
320 static constexpr int64_t Unknown = std::numeric_limits<int32_t>::max();
321};
322
324 OS << "[" << R.Offset << ", " << R.Size << "]";
325 return OS;
326}
327
328inline bool operator==(const RangeTy &A, const RangeTy &B) {
329 return A.Offset == B.Offset && A.Size == B.Size;
330}
331
332inline bool operator!=(const RangeTy &A, const RangeTy &B) { return !(A == B); }
333
334/// Return the initial value of \p Obj with type \p Ty if that is a constant.
337 Value &Obj, Type &Ty, const TargetLibraryInfo *TLI,
338 const DataLayout &DL, RangeTy *RangePtr = nullptr);
339
340/// Collect all potential values \p LI could read into \p PotentialValues. That
341/// is, the only values read by \p LI are assumed to be known and all are in
342/// \p PotentialValues. \p PotentialValueOrigins will contain all the
343/// instructions that might have put a potential value into \p PotentialValues.
344/// Dependences onto \p QueryingAA are properly tracked, \p
345/// UsedAssumedInformation will inform the caller if assumed information was
346/// used.
347///
348/// \returns True if the assumed potential copies are all in \p PotentialValues,
349/// false if something went wrong and the copies could not be
350/// determined.
352 Attributor &A, LoadInst &LI, SmallSetVector<Value *, 4> &PotentialValues,
353 SmallSetVector<Instruction *, 4> &PotentialValueOrigins,
354 const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation,
355 bool OnlyExact = false);
356
357/// Collect all potential values of the one stored by \p SI into
358/// \p PotentialCopies. That is, the only copies that were made via the
359/// store are assumed to be known and all are in \p PotentialCopies. Dependences
360/// onto \p QueryingAA are properly tracked, \p UsedAssumedInformation will
361/// inform the caller if assumed information was used.
362///
363/// \returns True if the assumed potential copies are all in \p PotentialCopies,
364/// false if something went wrong and the copies could not be
365/// determined.
367 Attributor &A, StoreInst &SI, SmallSetVector<Value *, 4> &PotentialCopies,
368 const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation,
369 bool OnlyExact = false);
370
371/// Return true if \p IRP is readonly. This will query respective AAs that
372/// deduce the information and introduce dependences for \p QueryingAA.
374 const AbstractAttribute &QueryingAA,
375 bool &IsKnown);
376
377/// Return true if \p IRP is readnone. This will query respective AAs that
378/// deduce the information and introduce dependences for \p QueryingAA.
380 const AbstractAttribute &QueryingAA,
381 bool &IsKnown);
382
383/// Return true if \p ToI is potentially reachable from \p FromI without running
384/// into any instruction in \p ExclusionSet The two instructions do not need to
385/// be in the same function. \p GoBackwardsCB can be provided to convey domain
386/// knowledge about the "lifespan" the user is interested in. By default, the
387/// callers of \p FromI are checked as well to determine if \p ToI can be
388/// reached. If the query is not interested in callers beyond a certain point,
389/// e.g., a GPU kernel entry or the function containing an alloca, the
390/// \p GoBackwardsCB should return false.
392 Attributor &A, const Instruction &FromI, const Instruction &ToI,
393 const AbstractAttribute &QueryingAA,
394 const AA::InstExclusionSetTy *ExclusionSet = nullptr,
395 std::function<bool(const Function &F)> GoBackwardsCB = nullptr);
396
397/// Same as above but it is sufficient to reach any instruction in \p ToFn.
399 Attributor &A, const Instruction &FromI, const Function &ToFn,
400 const AbstractAttribute &QueryingAA,
401 const AA::InstExclusionSetTy *ExclusionSet = nullptr,
402 std::function<bool(const Function &F)> GoBackwardsCB = nullptr);
403
404/// Return true if \p Obj is assumed to be a thread local object.
406 const AbstractAttribute &QueryingAA);
407
408/// Return true if \p I is potentially affected by a barrier.
409LLVM_ABI bool
411 const AbstractAttribute &QueryingAA);
412LLVM_ABI bool
414 const AbstractAttribute &QueryingAA,
415 const Instruction *CtxI);
416} // namespace AA
417
418template <>
419struct DenseMapInfo<AA::ValueAndContext>
420 : public DenseMapInfo<AA::ValueAndContext::Base> {
423 return Base::getEmptyKey();
424 }
426 return Base::getTombstoneKey();
427 }
428 static unsigned getHashValue(const AA::ValueAndContext &VAC) {
429 return Base::getHashValue(VAC);
430 }
431
432 static bool isEqual(const AA::ValueAndContext &LHS,
433 const AA::ValueAndContext &RHS) {
434 return Base::isEqual(LHS, RHS);
435 }
436};
437
438template <>
439struct DenseMapInfo<AA::ValueScope> : public DenseMapInfo<unsigned char> {
441 static inline AA::ValueScope getEmptyKey() {
442 return AA::ValueScope(Base::getEmptyKey());
443 }
445 return AA::ValueScope(Base::getTombstoneKey());
446 }
447 static unsigned getHashValue(const AA::ValueScope &S) {
448 return Base::getHashValue(S);
449 }
450
451 static bool isEqual(const AA::ValueScope &LHS, const AA::ValueScope &RHS) {
452 return Base::isEqual(LHS, RHS);
453 }
454};
455
456template <>
457struct DenseMapInfo<const AA::InstExclusionSetTy *>
458 : public DenseMapInfo<void *> {
460 static inline const AA::InstExclusionSetTy *getEmptyKey() {
461 return static_cast<const AA::InstExclusionSetTy *>(super::getEmptyKey());
462 }
464 return static_cast<const AA::InstExclusionSetTy *>(
465 super::getTombstoneKey());
466 }
467 static unsigned getHashValue(const AA::InstExclusionSetTy *BES) {
468 unsigned H = 0;
469 if (BES)
470 for (const auto *II : *BES)
472 return H;
473 }
476 if (LHS == RHS)
477 return true;
478 if (LHS == getEmptyKey() || RHS == getEmptyKey() ||
479 LHS == getTombstoneKey() || RHS == getTombstoneKey())
480 return false;
481 auto SizeLHS = LHS ? LHS->size() : 0;
482 auto SizeRHS = RHS ? RHS->size() : 0;
483 if (SizeLHS != SizeRHS)
484 return false;
485 if (SizeRHS == 0)
486 return true;
487 return llvm::set_is_subset(*LHS, *RHS);
488 }
489};
490
491/// The value passed to the line option that defines the maximal initialization
492/// chain length.
494
495///{
496enum class ChangeStatus {
497 CHANGED,
498 UNCHANGED,
499};
500
505
506enum class DepClassTy {
507 REQUIRED, ///< The target cannot be valid if the source is not.
508 OPTIONAL, ///< The target may be valid if the source is not.
509 NONE, ///< Do not track a dependence between source and target.
510};
511///}
512
513/// The data structure for the nodes of a dependency graph
515public:
516 virtual ~AADepGraphNode() = default;
519
520protected:
521 /// Set of dependency graph nodes which should be updated if this one
522 /// is updated. The bit encodes if it is optional.
524
525 static AADepGraphNode *DepGetVal(const DepTy &DT) { return DT.getPointer(); }
527 return cast<AbstractAttribute>(DT.getPointer());
528 }
529
530 operator AbstractAttribute *() { return cast<AbstractAttribute>(this); }
531
532public:
536
541
542 void print(raw_ostream &OS) const { print(nullptr, OS); }
543 virtual void print(Attributor *, raw_ostream &OS) const {
544 OS << "AADepNode Impl\n";
545 }
546 DepSetTy &getDeps() { return Deps; }
547
548 friend struct Attributor;
549 friend struct AADepGraph;
550};
551
552/// The data structure for the dependency graph
553///
554/// Note that in this graph if there is an edge from A to B (A -> B),
555/// then it means that B depends on A, and when the state of A is
556/// updated, node B should also be updated
558 AADepGraph() = default;
559 ~AADepGraph() = default;
560
562 static AADepGraphNode *DepGetVal(const DepTy &DT) { return DT.getPointer(); }
563 using iterator =
565
566 /// There is no root node for the dependency graph. But the SCCIterator
567 /// requires a single entry point, so we maintain a fake("synthetic") root
568 /// node that depends on every node.
571
574
575 LLVM_ABI void viewGraph();
576
577 /// Dump graph to file
578 LLVM_ABI void dumpGraph();
579
580 /// Print dependency graph
581 LLVM_ABI void print();
582};
583
584/// Helper to describe and deal with positions in the LLVM-IR.
585///
586/// A position in the IR is described by an anchor value and an "offset" that
587/// could be the argument number, for call sites and arguments, or an indicator
588/// of the "position kind". The kinds, specified in the Kind enum below, include
589/// the locations in the attribute list, i.a., function scope and return value,
590/// as well as a distinction between call sites and functions. Finally, there
591/// are floating values that do not have a corresponding attribute list
592/// position.
594 // NOTE: In the future this definition can be changed to support recursive
595 // functions.
597
598 /// The positions we distinguish in the IR.
599 enum Kind : char {
600 IRP_INVALID, ///< An invalid position.
601 IRP_FLOAT, ///< A position that is not associated with a spot suitable
602 ///< for attributes. This could be any value or instruction.
603 IRP_RETURNED, ///< An attribute for the function return value.
604 IRP_CALL_SITE_RETURNED, ///< An attribute for a call site return value.
605 IRP_FUNCTION, ///< An attribute for a function (scope).
606 IRP_CALL_SITE, ///< An attribute for a call site (function scope).
607 IRP_ARGUMENT, ///< An attribute for a function argument.
608 IRP_CALL_SITE_ARGUMENT, ///< An attribute for a call site argument.
609 };
610
611 /// Default constructor available to create invalid positions implicitly. All
612 /// other positions need to be created explicitly through the appropriate
613 /// static member function.
614 IRPosition() : Enc(nullptr, ENC_VALUE) { verify(); }
615
616 /// Create a position describing the value of \p V.
617 static const IRPosition value(const Value &V,
618 const CallBaseContext *CBContext = nullptr) {
619 if (auto *Arg = dyn_cast<Argument>(&V))
620 return IRPosition::argument(*Arg, CBContext);
621 if (auto *CB = dyn_cast<CallBase>(&V))
623 return IRPosition(const_cast<Value &>(V), IRP_FLOAT, CBContext);
624 }
625
626 /// Create a position describing the instruction \p I. This is different from
627 /// the value version because call sites are treated as intrusctions rather
628 /// than their return value in this function.
629 static const IRPosition inst(const Instruction &I,
630 const CallBaseContext *CBContext = nullptr) {
631 return IRPosition(const_cast<Instruction &>(I), IRP_FLOAT, CBContext);
632 }
633
634 /// Create a position describing the function scope of \p F.
635 /// \p CBContext is used for call base specific analysis.
636 static const IRPosition function(const Function &F,
637 const CallBaseContext *CBContext = nullptr) {
638 return IRPosition(const_cast<Function &>(F), IRP_FUNCTION, CBContext);
639 }
640
641 /// Create a position describing the returned value of \p F.
642 /// \p CBContext is used for call base specific analysis.
643 static const IRPosition returned(const Function &F,
644 const CallBaseContext *CBContext = nullptr) {
645 return IRPosition(const_cast<Function &>(F), IRP_RETURNED, CBContext);
646 }
647
648 /// Create a position describing the argument \p Arg.
649 /// \p CBContext is used for call base specific analysis.
650 static const IRPosition argument(const Argument &Arg,
651 const CallBaseContext *CBContext = nullptr) {
652 return IRPosition(const_cast<Argument &>(Arg), IRP_ARGUMENT, CBContext);
653 }
654
655 /// Create a position describing the function scope of \p CB.
656 static const IRPosition callsite_function(const CallBase &CB) {
657 return IRPosition(const_cast<CallBase &>(CB), IRP_CALL_SITE);
658 }
659
660 /// Create a position describing the returned value of \p CB.
661 static const IRPosition callsite_returned(const CallBase &CB) {
662 return IRPosition(const_cast<CallBase &>(CB), IRP_CALL_SITE_RETURNED);
663 }
664
665 /// Create a position describing the argument of \p CB at position \p ArgNo.
666 static const IRPosition callsite_argument(const CallBase &CB,
667 unsigned ArgNo) {
668 return IRPosition(const_cast<Use &>(CB.getArgOperandUse(ArgNo)),
670 }
671
672 /// Create a position describing the argument of \p ACS at position \p ArgNo.
674 unsigned ArgNo) {
675 if (ACS.getNumArgOperands() <= ArgNo)
676 return IRPosition();
677 int CSArgNo = ACS.getCallArgOperandNo(ArgNo);
678 if (CSArgNo >= 0)
680 cast<CallBase>(*ACS.getInstruction()), CSArgNo);
681 return IRPosition();
682 }
683
684 /// Create a position with function scope matching the "context" of \p IRP.
685 /// If \p IRP is a call site (see isAnyCallSitePosition()) then the result
686 /// will be a call site position, otherwise the function position of the
687 /// associated function.
688 static const IRPosition
690 const CallBaseContext *CBContext = nullptr) {
691 if (IRP.isAnyCallSitePosition()) {
693 cast<CallBase>(IRP.getAnchorValue()));
694 }
696 return IRPosition::function(*IRP.getAssociatedFunction(), CBContext);
697 }
698
699 bool operator==(const IRPosition &RHS) const {
700 return Enc == RHS.Enc && RHS.CBContext == CBContext;
701 }
702 bool operator!=(const IRPosition &RHS) const { return !(*this == RHS); }
703
704 /// Return the value this abstract attribute is anchored with.
705 ///
706 /// The anchor value might not be the associated value if the latter is not
707 /// sufficient to determine where arguments will be manifested. This is, so
708 /// far, only the case for call site arguments as the value is not sufficient
709 /// to pinpoint them. Instead, we can use the call site as an anchor.
711 switch (getEncodingBits()) {
712 case ENC_VALUE:
713 case ENC_RETURNED_VALUE:
714 case ENC_FLOATING_FUNCTION:
715 return *getAsValuePtr();
716 case ENC_CALL_SITE_ARGUMENT_USE:
717 return *(getAsUsePtr()->getUser());
718 default:
719 llvm_unreachable("Unkown encoding!");
720 };
721 }
722
723 /// Return the associated function, if any.
725 if (auto *CB = dyn_cast<CallBase>(&getAnchorValue())) {
726 // We reuse the logic that associates callback calles to arguments of a
727 // call site here to identify the callback callee as the associated
728 // function.
729 if (Argument *Arg = getAssociatedArgument())
730 return Arg->getParent();
731 return dyn_cast_if_present<Function>(
732 CB->getCalledOperand()->stripPointerCasts());
733 }
734 return getAnchorScope();
735 }
736
737 /// Return the associated argument, if any.
739
740 /// Return true if the position refers to a function interface, that is the
741 /// function scope, the function return, or an argument.
742 bool isFnInterfaceKind() const {
743 switch (getPositionKind()) {
747 return true;
748 default:
749 return false;
750 }
751 }
752
753 /// Return true if this is a function or call site position.
754 bool isFunctionScope() const {
755 switch (getPositionKind()) {
758 return true;
759 default:
760 return false;
761 };
762 }
763
764 /// Return the Function surrounding the anchor value.
766 Value &V = getAnchorValue();
767 if (isa<Function>(V))
768 return &cast<Function>(V);
769 if (isa<Argument>(V))
770 return cast<Argument>(V).getParent();
771 if (isa<Instruction>(V))
772 return cast<Instruction>(V).getFunction();
773 return nullptr;
774 }
775
776 /// Return the context instruction, if any.
778 Value &V = getAnchorValue();
779 if (auto *I = dyn_cast<Instruction>(&V))
780 return I;
781 if (auto *Arg = dyn_cast<Argument>(&V))
782 if (!Arg->getParent()->isDeclaration())
783 return &Arg->getParent()->getEntryBlock().front();
784 if (auto *F = dyn_cast<Function>(&V))
785 if (!F->isDeclaration())
786 return &(F->getEntryBlock().front());
787 return nullptr;
788 }
789
790 /// Return the value this abstract attribute is associated with.
792 if (getCallSiteArgNo() < 0 || isa<Argument>(&getAnchorValue()))
793 return getAnchorValue();
794 assert(isa<CallBase>(&getAnchorValue()) && "Expected a call base!");
795 return *cast<CallBase>(&getAnchorValue())
796 ->getArgOperand(getCallSiteArgNo());
797 }
798
799 /// Return the type this abstract attribute is associated with.
803 return getAssociatedValue().getType();
804 }
805
806 /// Return the callee argument number of the associated value if it is an
807 /// argument or call site argument, otherwise a negative value. In contrast to
808 /// `getCallSiteArgNo` this method will always return the "argument number"
809 /// from the perspective of the callee. This may not the same as the call site
810 /// if this is a callback call.
811 int getCalleeArgNo() const {
812 return getArgNo(/* CallbackCalleeArgIfApplicable */ true);
813 }
814
815 /// Return the call site argument number of the associated value if it is an
816 /// argument or call site argument, otherwise a negative value. In contrast to
817 /// `getCalleArgNo` this method will always return the "operand number" from
818 /// the perspective of the call site. This may not the same as the callee
819 /// perspective if this is a callback call.
820 int getCallSiteArgNo() const {
821 return getArgNo(/* CallbackCalleeArgIfApplicable */ false);
822 }
823
824 /// Return the index in the attribute list for this position.
825 unsigned getAttrIdx() const {
826 switch (getPositionKind()) {
829 break;
840 }
842 "There is no attribute index for a floating or invalid position!");
843 }
844
845 /// Return the value attributes are attached to.
847 if (auto *CB = dyn_cast<CallBase>(&getAnchorValue()))
848 return CB;
849 return getAssociatedFunction();
850 }
851
852 /// Return the attributes associated with this function or call site scope.
854 if (auto *CB = dyn_cast<CallBase>(&getAnchorValue()))
855 return CB->getAttributes();
857 }
858
859 /// Update the attributes associated with this function or call site scope.
860 void setAttrList(const AttributeList &AttrList) const {
861 if (auto *CB = dyn_cast<CallBase>(&getAnchorValue()))
862 return CB->setAttributes(AttrList);
863 return getAssociatedFunction()->setAttributes(AttrList);
864 }
865
866 /// Return the number of arguments associated with this function or call site
867 /// scope.
868 unsigned getNumArgs() const {
871 "Only valid for function/call site positions!");
872 if (auto *CB = dyn_cast<CallBase>(&getAnchorValue()))
873 return CB->arg_size();
875 }
876
877 /// Return theargument \p ArgNo associated with this function or call site
878 /// scope.
879 Value *getArg(unsigned ArgNo) const {
882 "Only valid for function/call site positions!");
883 if (auto *CB = dyn_cast<CallBase>(&getAnchorValue()))
884 return CB->getArgOperand(ArgNo);
885 return getAssociatedFunction()->getArg(ArgNo);
886 }
887
888 /// Return the associated position kind.
890 char EncodingBits = getEncodingBits();
891 if (EncodingBits == ENC_CALL_SITE_ARGUMENT_USE)
893 if (EncodingBits == ENC_FLOATING_FUNCTION)
894 return IRP_FLOAT;
895
896 Value *V = getAsValuePtr();
897 if (!V)
898 return IRP_INVALID;
899 if (isa<Argument>(V))
900 return IRP_ARGUMENT;
901 if (isa<Function>(V))
902 return isReturnPosition(EncodingBits) ? IRP_RETURNED : IRP_FUNCTION;
903 if (isa<CallBase>(V))
904 return isReturnPosition(EncodingBits) ? IRP_CALL_SITE_RETURNED
906 return IRP_FLOAT;
907 }
908
910 switch (getPositionKind()) {
914 return true;
915 default:
916 return false;
917 }
918 }
919
920 /// Return true if the position is an argument or call site argument.
921 bool isArgumentPosition() const {
922 switch (getPositionKind()) {
925 return true;
926 default:
927 return false;
928 }
929 }
930
931 /// Return the same position without the call base context.
933 IRPosition Result = *this;
934 Result.CBContext = nullptr;
935 return Result;
936 }
937
938 /// Get the call base context from the position.
939 const CallBaseContext *getCallBaseContext() const { return CBContext; }
940
941 /// Check if the position has any call base context.
942 bool hasCallBaseContext() const { return CBContext != nullptr; }
943
944 /// Special DenseMap key values.
945 ///
946 ///{
949 ///}
950
951 /// Conversion into a void * to allow reuse of pointer hashing.
952 operator void *() const { return Enc.getOpaqueValue(); }
953
954private:
955 /// Private constructor for special values only!
956 explicit IRPosition(void *Ptr, const CallBaseContext *CBContext = nullptr)
957 : CBContext(CBContext) {
959 }
960
961 /// IRPosition anchored at \p AnchorVal with kind/argument numbet \p PK.
962 explicit IRPosition(Value &AnchorVal, Kind PK,
963 const CallBaseContext *CBContext = nullptr)
964 : CBContext(CBContext) {
965 switch (PK) {
967 llvm_unreachable("Cannot create invalid IRP with an anchor value!");
968 break;
970 // Special case for floating functions.
971 if (isa<Function>(AnchorVal) || isa<CallBase>(AnchorVal))
972 Enc = {&AnchorVal, ENC_FLOATING_FUNCTION};
973 else
974 Enc = {&AnchorVal, ENC_VALUE};
975 break;
978 Enc = {&AnchorVal, ENC_VALUE};
979 break;
982 Enc = {&AnchorVal, ENC_RETURNED_VALUE};
983 break;
985 Enc = {&AnchorVal, ENC_VALUE};
986 break;
989 "Cannot create call site argument IRP with an anchor value!");
990 break;
991 }
992 verify();
993 }
994
995 /// Return the callee argument number of the associated value if it is an
996 /// argument or call site argument. See also `getCalleeArgNo` and
997 /// `getCallSiteArgNo`.
998 int getArgNo(bool CallbackCalleeArgIfApplicable) const {
999 if (CallbackCalleeArgIfApplicable)
1000 if (Argument *Arg = getAssociatedArgument())
1001 return Arg->getArgNo();
1002 switch (getPositionKind()) {
1004 return cast<Argument>(getAsValuePtr())->getArgNo();
1006 Use &U = *getAsUsePtr();
1007 return cast<CallBase>(U.getUser())->getArgOperandNo(&U);
1008 }
1009 default:
1010 return -1;
1011 }
1012 }
1013
1014 /// IRPosition for the use \p U. The position kind \p PK needs to be
1015 /// IRP_CALL_SITE_ARGUMENT, the anchor value is the user, the associated value
1016 /// the used value.
1017 explicit IRPosition(Use &U, Kind PK) {
1019 "Use constructor is for call site arguments only!");
1020 Enc = {&U, ENC_CALL_SITE_ARGUMENT_USE};
1021 verify();
1022 }
1023
1024 /// Verify internal invariants.
1025 LLVM_ABI void verify();
1026
1027 /// Return the underlying pointer as Value *, valid for all positions but
1028 /// IRP_CALL_SITE_ARGUMENT.
1029 Value *getAsValuePtr() const {
1030 assert(getEncodingBits() != ENC_CALL_SITE_ARGUMENT_USE &&
1031 "Not a value pointer!");
1032 return reinterpret_cast<Value *>(Enc.getPointer());
1033 }
1034
1035 /// Return the underlying pointer as Use *, valid only for
1036 /// IRP_CALL_SITE_ARGUMENT positions.
1037 Use *getAsUsePtr() const {
1038 assert(getEncodingBits() == ENC_CALL_SITE_ARGUMENT_USE &&
1039 "Not a value pointer!");
1040 return reinterpret_cast<Use *>(Enc.getPointer());
1041 }
1042
1043 /// Return true if \p EncodingBits describe a returned or call site returned
1044 /// position.
1045 static bool isReturnPosition(char EncodingBits) {
1046 return EncodingBits == ENC_RETURNED_VALUE;
1047 }
1048
1049 /// Return true if the encoding bits describe a returned or call site returned
1050 /// position.
1051 bool isReturnPosition() const { return isReturnPosition(getEncodingBits()); }
1052
1053 /// The encoding of the IRPosition is a combination of a pointer and two
1054 /// encoding bits. The values of the encoding bits are defined in the enum
1055 /// below. The pointer is either a Value* (for the first three encoding bit
1056 /// combinations) or Use* (for ENC_CALL_SITE_ARGUMENT_USE).
1057 ///
1058 ///{
1059 enum {
1060 ENC_VALUE = 0b00,
1061 ENC_RETURNED_VALUE = 0b01,
1062 ENC_FLOATING_FUNCTION = 0b10,
1063 ENC_CALL_SITE_ARGUMENT_USE = 0b11,
1064 };
1065
1066 // Reserve the maximal amount of bits so there is no need to mask out the
1067 // remaining ones. We will not encode anything else in the pointer anyway.
1068 static constexpr int NumEncodingBits =
1069 PointerLikeTypeTraits<void *>::NumLowBitsAvailable;
1070 static_assert(NumEncodingBits >= 2, "At least two bits are required!");
1071
1072 /// The pointer with the encoding bits.
1073 PointerIntPair<void *, NumEncodingBits, char> Enc;
1074 ///}
1075
1076 /// Call base context. Used for callsite specific analysis.
1077 const CallBaseContext *CBContext = nullptr;
1078
1079 /// Return the encoding bits.
1080 char getEncodingBits() const { return Enc.getInt(); }
1081};
1082
1083/// Helper that allows IRPosition as a key in a DenseMap.
1084template <> struct DenseMapInfo<IRPosition> {
1085 static inline IRPosition getEmptyKey() { return IRPosition::EmptyKey; }
1086 static inline IRPosition getTombstoneKey() {
1088 }
1089 static unsigned getHashValue(const IRPosition &IRP) {
1090 return (DenseMapInfo<void *>::getHashValue(IRP) << 4) ^
1092 }
1093
1094 static bool isEqual(const IRPosition &a, const IRPosition &b) {
1095 return a == b;
1096 }
1097};
1098
1099/// A visitor class for IR positions.
1100///
1101/// Given a position P, the SubsumingPositionIterator allows to visit "subsuming
1102/// positions" wrt. attributes/information. Thus, if a piece of information
1103/// holds for a subsuming position, it also holds for the position P.
1104///
1105/// The subsuming positions always include the initial position and then,
1106/// depending on the position kind, additionally the following ones:
1107/// - for IRP_RETURNED:
1108/// - the function (IRP_FUNCTION)
1109/// - for IRP_ARGUMENT:
1110/// - the function (IRP_FUNCTION)
1111/// - for IRP_CALL_SITE:
1112/// - the callee (IRP_FUNCTION), if known
1113/// - for IRP_CALL_SITE_RETURNED:
1114/// - the callee (IRP_RETURNED), if known
1115/// - the call site (IRP_FUNCTION)
1116/// - the callee (IRP_FUNCTION), if known
1117/// - for IRP_CALL_SITE_ARGUMENT:
1118/// - the argument of the callee (IRP_ARGUMENT), if known
1119/// - the callee (IRP_FUNCTION), if known
1120/// - the position the call site argument is associated with if it is not
1121/// anchored to the call site, e.g., if it is an argument then the argument
1122/// (IRP_ARGUMENT)
1124 SmallVector<IRPosition, 4> IRPositions;
1125 using iterator = decltype(IRPositions)::iterator;
1126
1127public:
1129 iterator begin() { return IRPositions.begin(); }
1130 iterator end() { return IRPositions.end(); }
1131};
1132
1133/// Wrapper for FunctionAnalysisManager.
1135 // The client may be running the old pass manager, in which case, we need to
1136 // map the requested Analysis to its equivalent wrapper in the old pass
1137 // manager. The scheme implemented here does not require every Analysis to be
1138 // updated. Only those new analyses that the client cares about in the old
1139 // pass manager need to expose a LegacyWrapper type, and that wrapper should
1140 // support a getResult() method that matches the new Analysis.
1141 //
1142 // We need SFINAE to check for the LegacyWrapper, but function templates don't
1143 // allow partial specialization, which is needed in this case. So instead, we
1144 // use a constexpr bool to perform the SFINAE, and then use this information
1145 // inside the function template.
1146 template <typename, typename = void>
1147 static constexpr bool HasLegacyWrapper = false;
1148
1149 template <typename Analysis>
1150 typename Analysis::Result *getAnalysis(const Function &F,
1151 bool RequestCachedOnly = false) {
1152 if (!LegacyPass && !FAM)
1153 return nullptr;
1154 if (FAM) {
1155 if (CachedOnly || RequestCachedOnly)
1156 return FAM->getCachedResult<Analysis>(const_cast<Function &>(F));
1157 return &FAM->getResult<Analysis>(const_cast<Function &>(F));
1158 }
1159 if constexpr (HasLegacyWrapper<Analysis>) {
1160 if (!CachedOnly && !RequestCachedOnly)
1161 return &LegacyPass
1162 ->getAnalysis<typename Analysis::LegacyWrapper>(
1163 const_cast<Function &>(F))
1164 .getResult();
1165 if (auto *P =
1166 LegacyPass
1167 ->getAnalysisIfAvailable<typename Analysis::LegacyWrapper>())
1168 return &P->getResult();
1169 }
1170 return nullptr;
1171 }
1172
1173 /// Invalidates the analyses. Valid only when using the new pass manager.
1175 assert(FAM && "Can only be used from the new PM!");
1176 FAM->clear();
1177 }
1178
1179 AnalysisGetter(FunctionAnalysisManager &FAM, bool CachedOnly = false)
1180 : FAM(&FAM), CachedOnly(CachedOnly) {}
1181 AnalysisGetter(Pass *P, bool CachedOnly = false)
1182 : LegacyPass(P), CachedOnly(CachedOnly) {}
1183 AnalysisGetter() = default;
1184
1185private:
1186 FunctionAnalysisManager *FAM = nullptr;
1187 Pass *LegacyPass = nullptr;
1188
1189 /// If \p CachedOnly is true, no pass is created, just existing results are
1190 /// used. Also available per request.
1191 bool CachedOnly = false;
1192};
1193
1194template <typename Analysis>
1196 Analysis, std::void_t<typename Analysis::LegacyWrapper>> = true;
1197
1198/// Data structure to hold cached (LLVM-IR) information.
1199///
1200/// All attributes are given an InformationCache object at creation time to
1201/// avoid inspection of the IR by all of them individually. This default
1202/// InformationCache will hold information required by 'default' attributes,
1203/// thus the ones deduced when Attributor::identifyDefaultAbstractAttributes(..)
1204/// is called.
1205///
1206/// If custom abstract attributes, registered manually through
1207/// Attributor::registerAA(...), need more information, especially if it is not
1208/// reusable, it is advised to inherit from the InformationCache and cast the
1209/// instance down in the abstract attributes.
1213 bool UseExplorer = true)
1214 : CGSCC(CGSCC), DL(M.getDataLayout()), Allocator(Allocator), AG(AG),
1215 TargetTriple(M.getTargetTriple()) {
1216 if (UseExplorer)
1218 /* ExploreInterBlock */
1219 true, /* ExploreCFGForward */ true,
1220 /* ExploreCFGBackward */ true,
1221 /* LIGetter */
1222 [&](const Function &F) { return AG.getAnalysis<LoopAnalysis>(F); },
1223 /* DTGetter */
1224 [&](const Function &F) {
1226 },
1227 /* PDTGetter */
1228 [&](const Function &F) {
1230 });
1231 }
1232
1234 // The FunctionInfo objects are allocated via a BumpPtrAllocator, we call
1235 // the destructor manually.
1236 for (auto &It : FuncInfoMap)
1237 It.getSecond()->~FunctionInfo();
1238 // Same is true for the instruction exclusions sets.
1240 for (auto *BES : BESets)
1241 BES->~InstExclusionSetTy();
1242 if (Explorer)
1243 Explorer->~MustBeExecutedContextExplorer();
1244 }
1245
1246 /// Apply \p CB to all uses of \p F. If \p LookThroughConstantExprUses is
1247 /// true, constant expression users are not given to \p CB but their uses are
1248 /// traversed transitively.
1249 template <typename CBTy>
1250 static void foreachUse(Function &F, CBTy CB,
1251 bool LookThroughConstantExprUses = true) {
1252 SmallVector<Use *, 8> Worklist(make_pointer_range(F.uses()));
1253
1254 for (unsigned Idx = 0; Idx < Worklist.size(); ++Idx) {
1255 Use &U = *Worklist[Idx];
1256
1257 // Allow use in constant bitcasts and simply look through them.
1258 if (LookThroughConstantExprUses && isa<ConstantExpr>(U.getUser())) {
1259 for (Use &CEU : cast<ConstantExpr>(U.getUser())->uses())
1260 Worklist.push_back(&CEU);
1261 continue;
1262 }
1263
1264 CB(U);
1265 }
1266 }
1267
1268 /// The CG-SCC the pass is run on, or nullptr if it is a module pass.
1269 const SetVector<Function *> *const CGSCC = nullptr;
1270
1271 /// A vector type to hold instructions.
1273
1274 /// A map type from opcodes to instructions with this opcode.
1276
1277 /// Return the map that relates "interesting" opcodes with all instructions
1278 /// with that opcode in \p F.
1280 return getFunctionInfo(F).OpcodeInstMap;
1281 }
1282
1283 /// Return the instructions in \p F that may read or write memory.
1285 return getFunctionInfo(F).RWInsts;
1286 }
1287
1288 /// Return MustBeExecutedContextExplorer
1290 return Explorer;
1291 }
1292
1293 /// Return TargetLibraryInfo for function \p F.
1296 }
1297
1298 /// Return true if \p F has the "kernel" function attribute
1299 bool isKernel(const Function &F) {
1300 FunctionInfo &FI = getFunctionInfo(F);
1301 return FI.IsKernel;
1302 }
1303
1304 /// Return true if \p Arg is involved in a must-tail call, thus the argument
1305 /// of the caller or callee.
1307 FunctionInfo &FI = getFunctionInfo(*Arg.getParent());
1308 return FI.CalledViaMustTail || FI.ContainsMustTailCall;
1309 }
1310
1311 bool isOnlyUsedByAssume(const Instruction &I) const {
1312 return AssumeOnlyValues.contains(&I);
1313 }
1314
1315 /// Invalidates the cached analyses. Valid only when using the new pass
1316 /// manager.
1318
1319 /// Return the analysis result from a pass \p AP for function \p F.
1320 template <typename AP>
1321 typename AP::Result *getAnalysisResultForFunction(const Function &F,
1322 bool CachedOnly = false) {
1323 return AG.getAnalysis<AP>(F, CachedOnly);
1324 }
1325
1326 /// Return datalayout used in the module.
1327 const DataLayout &getDL() { return DL; }
1328
1329 /// Return the map conaining all the knowledge we have from `llvm.assume`s.
1330 const RetainedKnowledgeMap &getKnowledgeMap() const { return KnowledgeMap; }
1331
1332 /// Given \p BES, return a uniqued version.
1335 auto It = BESets.find(BES);
1336 if (It != BESets.end())
1337 return *It;
1338 auto *UniqueBES = new (Allocator) AA::InstExclusionSetTy(*BES);
1339 bool Success = BESets.insert(UniqueBES).second;
1340 (void)Success;
1341 assert(Success && "Expected only new entries to be added");
1342 return UniqueBES;
1343 }
1344
1345 /// Return true if the stack (llvm::Alloca) can be accessed by other threads.
1347
1348 /// Return true if the target is a GPU.
1349 bool targetIsGPU() { return TargetTriple.isGPU(); }
1350
1351 /// Return all functions that might be called indirectly, only valid for
1352 /// closed world modules (see isClosedWorldModule).
1355
1356 /// Return the flat address space if the associated target has.
1357 LLVM_ABI std::optional<unsigned> getFlatAddressSpace() const;
1358
1359 virtual unsigned getMaxAddrSpace() const { return ~0U; }
1360
1361private:
1362 struct FunctionInfo {
1363 LLVM_ABI ~FunctionInfo();
1364
1365 /// A nested map that remembers all instructions in a function with a
1366 /// certain instruction opcode (Instruction::getOpcode()).
1367 OpcodeInstMapTy OpcodeInstMap;
1368
1369 /// A map from functions to their instructions that may read or write
1370 /// memory.
1371 InstructionVectorTy RWInsts;
1372
1373 /// Function is called by a `musttail` call.
1374 bool CalledViaMustTail;
1375
1376 /// Function contains a `musttail` call.
1377 bool ContainsMustTailCall;
1378
1379 /// Function has the `"kernel"` attribute
1380 bool IsKernel;
1381 };
1382
1383 /// A map type from functions to informatio about it.
1384 DenseMap<const Function *, FunctionInfo *> FuncInfoMap;
1385
1386 /// Return information about the function \p F, potentially by creating it.
1387 FunctionInfo &getFunctionInfo(const Function &F) {
1388 FunctionInfo *&FI = FuncInfoMap[&F];
1389 if (!FI) {
1390 FI = new (Allocator) FunctionInfo();
1391 initializeInformationCache(F, *FI);
1392 }
1393 return *FI;
1394 }
1395
1396 /// Vector of functions that might be callable indirectly, i.a., via a
1397 /// function pointer.
1398 SmallVector<Function *> IndirectlyCallableFunctions;
1399
1400 /// Initialize the function information cache \p FI for the function \p F.
1401 ///
1402 /// This method needs to be called for all function that might be looked at
1403 /// through the information cache interface *prior* to looking at them.
1404 LLVM_ABI void initializeInformationCache(const Function &F, FunctionInfo &FI);
1405
1406 /// The datalayout used in the module.
1407 const DataLayout &DL;
1408
1409 /// The allocator used to allocate memory, e.g. for `FunctionInfo`s.
1410 BumpPtrAllocator &Allocator;
1411
1412 /// MustBeExecutedContextExplorer
1413 MustBeExecutedContextExplorer *Explorer = nullptr;
1414
1415 /// A map with knowledge retained in `llvm.assume` instructions.
1416 RetainedKnowledgeMap KnowledgeMap;
1417
1418 /// A container for all instructions that are only used by `llvm.assume`.
1419 SetVector<const Instruction *> AssumeOnlyValues;
1420
1421 /// Cache for block sets to allow reuse.
1422 DenseSet<const AA::InstExclusionSetTy *> BESets;
1423
1424 /// Getters for analysis.
1425 AnalysisGetter &AG;
1426
1427 /// Set of inlineable functions
1428 SmallPtrSet<const Function *, 8> InlineableFunctions;
1429
1430 /// The triple describing the target machine.
1431 Triple TargetTriple;
1432
1433 /// Give the Attributor access to the members so
1434 /// Attributor::identifyDefaultAbstractAttributes(...) can initialize them.
1435 friend struct Attributor;
1436};
1437
1438/// Configuration for the Attributor.
1440
1442
1443 /// Is the user of the Attributor a module pass or not. This determines what
1444 /// IR we can look at and modify. If it is a module pass we might deduce facts
1445 /// outside the initial function set and modify functions outside that set,
1446 /// but only as part of the optimization of the functions in the initial
1447 /// function set. For CGSCC passes we can look at the IR of the module slice
1448 /// but never run any deduction, or perform any modification, outside the
1449 /// initial function set (which we assume is the SCC).
1450 bool IsModulePass = true;
1451
1452 /// Flag to determine if we can delete functions or keep dead ones around.
1453 bool DeleteFns = true;
1454
1455 /// Flag to determine if we rewrite function signatures.
1457
1458 /// Flag to determine if we want to initialize all default AAs for an internal
1459 /// function marked live. See also: InitializationCallback>
1461
1462 /// Flag to determine if we should skip all liveness checks early on.
1463 bool UseLiveness = true;
1464
1465 /// Flag to indicate if the entire world is contained in this module, that
1466 /// is, no outside functions exist.
1468
1469 /// Callback function to be invoked on internal functions marked live.
1470 std::function<void(Attributor &A, const Function &F)> InitializationCallback =
1471 nullptr;
1472
1473 /// Callback function to determine if an indirect call targets should be made
1474 /// direct call targets (with an if-cascade).
1475 std::function<bool(Attributor &A, const AbstractAttribute &AA, CallBase &CB,
1476 Function &AssumedCallee, unsigned NumAssumedCallees)>
1478
1479 /// Helper to update an underlying call graph and to delete functions.
1481
1482 /// If not null, a set limiting the attribute opportunities.
1484
1485 /// Maximum number of iterations to run until fixpoint.
1486 std::optional<unsigned> MaxFixpointIterations;
1487
1488 /// A callback function that returns an ORE object from a Function pointer.
1489 ///{
1493 ///}
1494
1495 /// The name of the pass running the attributor, used to emit remarks.
1496 const char *PassName = nullptr;
1497
1498 using IPOAmendableCBTy = std::function<bool(const Function &F)>;
1500};
1501
1502/// A debug counter to limit the number of AAs created.
1503DEBUG_COUNTER(NumAbstractAttributes, "num-abstract-attributes",
1504 "How many AAs should be initialized");
1505
1506/// The fixpoint analysis framework that orchestrates the attribute deduction.
1507///
1508/// The Attributor provides a general abstract analysis framework (guided
1509/// fixpoint iteration) as well as helper functions for the deduction of
1510/// (LLVM-IR) attributes. However, also other code properties can be deduced,
1511/// propagated, and ultimately manifested through the Attributor framework. This
1512/// is particularly useful if these properties interact with attributes and a
1513/// co-scheduled deduction allows to improve the solution. Even if not, thus if
1514/// attributes/properties are completely isolated, they should use the
1515/// Attributor framework to reduce the number of fixpoint iteration frameworks
1516/// in the code base. Note that the Attributor design makes sure that isolated
1517/// attributes are not impacted, in any way, by others derived at the same time
1518/// if there is no cross-reasoning performed.
1519///
1520/// The public facing interface of the Attributor is kept simple and basically
1521/// allows abstract attributes to one thing, query abstract attributes
1522/// in-flight. There are two reasons to do this:
1523/// a) The optimistic state of one abstract attribute can justify an
1524/// optimistic state of another, allowing to framework to end up with an
1525/// optimistic (=best possible) fixpoint instead of one based solely on
1526/// information in the IR.
1527/// b) This avoids reimplementing various kinds of lookups, e.g., to check
1528/// for existing IR attributes, in favor of a single lookups interface
1529/// provided by an abstract attribute subclass.
1530///
1531/// NOTE: The mechanics of adding a new "concrete" abstract attribute are
1532/// described in the file comment.
1534
1535 /// Constructor
1536 ///
1537 /// \param Functions The set of functions we are deriving attributes for.
1538 /// \param InfoCache Cache to hold various information accessible for
1539 /// the abstract attributes.
1540 /// \param Configuration The Attributor configuration which determines what
1541 /// generic features to use.
1543 InformationCache &InfoCache,
1544 AttributorConfig Configuration);
1545
1547
1548 /// Run the analyses until a fixpoint is reached or enforced (timeout).
1549 ///
1550 /// The attributes registered with this Attributor can be used after as long
1551 /// as the Attributor is not destroyed (it owns the attributes now).
1552 ///
1553 /// \Returns CHANGED if the IR was changed, otherwise UNCHANGED.
1555
1556 /// Lookup an abstract attribute of type \p AAType at position \p IRP. While
1557 /// no abstract attribute is found equivalent positions are checked, see
1558 /// SubsumingPositionIterator. Thus, the returned abstract attribute
1559 /// might be anchored at a different position, e.g., the callee if \p IRP is a
1560 /// call base.
1561 ///
1562 /// This method is the only (supported) way an abstract attribute can retrieve
1563 /// information from another abstract attribute. As an example, take an
1564 /// abstract attribute that determines the memory access behavior for a
1565 /// argument (readnone, readonly, ...). It should use `getAAFor` to get the
1566 /// most optimistic information for other abstract attributes in-flight, e.g.
1567 /// the one reasoning about the "captured" state for the argument or the one
1568 /// reasoning on the memory access behavior of the function as a whole.
1569 ///
1570 /// If the DepClass enum is set to `DepClassTy::None` the dependence from
1571 /// \p QueryingAA to the return abstract attribute is not automatically
1572 /// recorded. This should only be used if the caller will record the
1573 /// dependence explicitly if necessary, thus if it the returned abstract
1574 /// attribute is used for reasoning. To record the dependences explicitly use
1575 /// the `Attributor::recordDependence` method.
1576 template <typename AAType>
1577 const AAType *getAAFor(const AbstractAttribute &QueryingAA,
1578 const IRPosition &IRP, DepClassTy DepClass) {
1579 return getOrCreateAAFor<AAType>(IRP, &QueryingAA, DepClass,
1580 /* ForceUpdate */ false);
1581 }
1582
1583 /// The version of getAAFor that allows to omit a querying abstract
1584 /// attribute. Using this after Attributor started running is restricted to
1585 /// only the Attributor itself. Initial seeding of AAs can be done via this
1586 /// function.
1587 /// NOTE: ForceUpdate is ignored in any stage other than the update stage.
1588 template <typename AAType>
1589 const AAType *getOrCreateAAFor(IRPosition IRP,
1590 const AbstractAttribute *QueryingAA,
1591 DepClassTy DepClass, bool ForceUpdate = false,
1592 bool UpdateAfterInit = true) {
1593 if (!shouldPropagateCallBaseContext(IRP))
1594 IRP = IRP.stripCallBaseContext();
1595
1596 if (AAType *AAPtr = lookupAAFor<AAType>(IRP, QueryingAA, DepClass,
1597 /* AllowInvalidState */ true)) {
1598 if (ForceUpdate && Phase == AttributorPhase::UPDATE)
1599 updateAA(*AAPtr);
1600 return AAPtr;
1601 }
1602
1603 bool ShouldUpdateAA;
1604 if (!shouldInitialize<AAType>(IRP, ShouldUpdateAA))
1605 return nullptr;
1606
1607 if (!DebugCounter::shouldExecute(NumAbstractAttributes))
1608 return nullptr;
1609
1610 // No matching attribute found, create one.
1611 // Use the static create method.
1612 auto &AA = AAType::createForPosition(IRP, *this);
1613
1614 // Always register a new attribute to make sure we clean up the allocated
1615 // memory properly.
1616 registerAA(AA);
1617
1618 // If we are currenty seeding attributes, enforce seeding rules.
1619 if (Phase == AttributorPhase::SEEDING && !shouldSeedAttribute(AA)) {
1620 AA.getState().indicatePessimisticFixpoint();
1621 return &AA;
1622 }
1623
1624 // Bootstrap the new attribute with an initial update to propagate
1625 // information, e.g., function -> call site.
1626 {
1627 TimeTraceScope TimeScope("initialize", [&]() {
1628 return AA.getName().str() +
1629 std::to_string(AA.getIRPosition().getPositionKind());
1630 });
1631 ++InitializationChainLength;
1632 AA.initialize(*this);
1633 --InitializationChainLength;
1634 }
1635
1636 if (!ShouldUpdateAA) {
1637 AA.getState().indicatePessimisticFixpoint();
1638 return &AA;
1639 }
1640
1641 // Allow seeded attributes to declare dependencies.
1642 // Remember the seeding state.
1643 if (UpdateAfterInit) {
1644 AttributorPhase OldPhase = Phase;
1645 Phase = AttributorPhase::UPDATE;
1646
1647 updateAA(AA);
1648
1649 Phase = OldPhase;
1650 }
1651
1652 if (QueryingAA && AA.getState().isValidState())
1653 recordDependence(AA, const_cast<AbstractAttribute &>(*QueryingAA),
1654 DepClass);
1655 return &AA;
1656 }
1657
1658 template <typename AAType>
1659 const AAType *getOrCreateAAFor(const IRPosition &IRP) {
1660 return getOrCreateAAFor<AAType>(IRP, /* QueryingAA */ nullptr,
1662 }
1663
1664 /// Return the attribute of \p AAType for \p IRP if existing and valid. This
1665 /// also allows non-AA users lookup.
1666 template <typename AAType>
1667 AAType *lookupAAFor(const IRPosition &IRP,
1668 const AbstractAttribute *QueryingAA = nullptr,
1670 bool AllowInvalidState = false) {
1671 static_assert(std::is_base_of<AbstractAttribute, AAType>::value,
1672 "Cannot query an attribute with a type not derived from "
1673 "'AbstractAttribute'!");
1674 // Lookup the abstract attribute of type AAType. If found, return it after
1675 // registering a dependence of QueryingAA on the one returned attribute.
1676 AbstractAttribute *AAPtr = AAMap.lookup({&AAType::ID, IRP});
1677 if (!AAPtr)
1678 return nullptr;
1679
1680 AAType *AA = static_cast<AAType *>(AAPtr);
1681
1682 // Do not register a dependence on an attribute with an invalid state.
1683 if (DepClass != DepClassTy::NONE && QueryingAA &&
1684 AA->getState().isValidState())
1685 recordDependence(*AA, const_cast<AbstractAttribute &>(*QueryingAA),
1686 DepClass);
1687
1688 // Return nullptr if this attribute has an invalid state.
1689 if (!AllowInvalidState && !AA->getState().isValidState())
1690 return nullptr;
1691 return AA;
1692 }
1693
1694 /// Allows a query AA to request an update if a new query was received.
1696
1697 /// Explicitly record a dependence from \p FromAA to \p ToAA, that is if
1698 /// \p FromAA changes \p ToAA should be updated as well.
1699 ///
1700 /// This method should be used in conjunction with the `getAAFor` method and
1701 /// with the DepClass enum passed to the method set to None. This can
1702 /// be beneficial to avoid false dependences but it requires the users of
1703 /// `getAAFor` to explicitly record true dependences through this method.
1704 /// The \p DepClass flag indicates if the dependence is striclty necessary.
1705 /// That means for required dependences, if \p FromAA changes to an invalid
1706 /// state, \p ToAA can be moved to a pessimistic fixpoint because it required
1707 /// information from \p FromAA but none are available anymore.
1708 LLVM_ABI void recordDependence(const AbstractAttribute &FromAA,
1709 const AbstractAttribute &ToAA,
1710 DepClassTy DepClass);
1711
1712 /// Introduce a new abstract attribute into the fixpoint analysis.
1713 ///
1714 /// Note that ownership of the attribute is given to the Attributor. It will
1715 /// invoke delete for the Attributor on destruction of the Attributor.
1716 ///
1717 /// Attributes are identified by their IR position (AAType::getIRPosition())
1718 /// and the address of their static member (see AAType::ID).
1719 template <typename AAType> AAType &registerAA(AAType &AA) {
1720 static_assert(std::is_base_of<AbstractAttribute, AAType>::value,
1721 "Cannot register an attribute with a type not derived from "
1722 "'AbstractAttribute'!");
1723 // Put the attribute in the lookup map structure and the container we use to
1724 // keep track of all attributes.
1725 const IRPosition &IRP = AA.getIRPosition();
1726 AbstractAttribute *&AAPtr = AAMap[{&AAType::ID, IRP}];
1727
1728 assert(!AAPtr && "Attribute already in map!");
1729 AAPtr = &AA;
1730
1731 // Register AA with the synthetic root only before the manifest stage.
1732 if (Phase == AttributorPhase::SEEDING || Phase == AttributorPhase::UPDATE)
1735
1736 return AA;
1737 }
1738
1739 /// Return the internal information cache.
1740 InformationCache &getInfoCache() { return InfoCache; }
1741
1742 /// Return true if this is a module pass, false otherwise.
1743 bool isModulePass() const { return Configuration.IsModulePass; }
1744
1745 /// Return true if we should specialize the call site \b CB for the potential
1746 /// callee \p Fn.
1748 CallBase &CB, Function &Callee,
1749 unsigned NumAssumedCallees) {
1750 return Configuration.IndirectCalleeSpecializationCallback
1752 *this, AA, CB, Callee, NumAssumedCallees)
1753 : true;
1754 }
1755
1756 /// Return true if the module contains the whole world, thus, no outside
1757 /// functions exist.
1758 LLVM_ABI bool isClosedWorldModule() const;
1759
1760 /// Return true if we derive attributes for \p Fn
1761 bool isRunOn(Function &Fn) const { return isRunOn(&Fn); }
1762 bool isRunOn(Function *Fn) const {
1763 return Functions.empty() || Functions.count(Fn);
1764 }
1765
1766 template <typename AAType> bool shouldUpdateAA(const IRPosition &IRP) {
1767 // If this is queried in the manifest stage, we force the AA to indicate
1768 // pessimistic fixpoint immediately.
1769 if (Phase == AttributorPhase::MANIFEST || Phase == AttributorPhase::CLEANUP)
1770 return false;
1771
1772 Function *AssociatedFn = IRP.getAssociatedFunction();
1773
1774 if (IRP.isAnyCallSitePosition()) {
1775 // Check if we require a callee but there is none.
1776 if (!AssociatedFn && AAType::requiresCalleeForCallBase())
1777 return false;
1778
1779 // Check if we require non-asm but it is inline asm.
1780 if (AAType::requiresNonAsmForCallBase() &&
1781 cast<CallBase>(IRP.getAnchorValue()).isInlineAsm())
1782 return false;
1783 }
1784
1785 // Check if we require a calles but we can't see all.
1786 if (AAType::requiresCallersForArgOrFunction())
1789 if (!AssociatedFn->hasLocalLinkage())
1790 return false;
1791
1792 if (!AAType::isValidIRPositionForUpdate(*this, IRP))
1793 return false;
1794
1795 // We update only AAs associated with functions in the Functions set or
1796 // call sites of them.
1797 return (!AssociatedFn || isModulePass() || isRunOn(AssociatedFn) ||
1798 isRunOn(IRP.getAnchorScope()));
1799 }
1800
1801 template <typename AAType>
1802 bool shouldInitialize(const IRPosition &IRP, bool &ShouldUpdateAA) {
1803 if (!AAType::isValidIRPositionForInit(*this, IRP))
1804 return false;
1805
1806 if (Configuration.Allowed && !Configuration.Allowed->count(&AAType::ID))
1807 return false;
1808
1809 // For now we skip anything in naked and optnone functions.
1810 const Function *AnchorFn = IRP.getAnchorScope();
1811 if (AnchorFn && (AnchorFn->hasFnAttribute(Attribute::Naked) ||
1812 AnchorFn->hasFnAttribute(Attribute::OptimizeNone)))
1813 return false;
1814
1815 // Avoid too many nested initializations to prevent a stack overflow.
1816 if (InitializationChainLength > MaxInitializationChainLength)
1817 return false;
1818
1819 ShouldUpdateAA = shouldUpdateAA<AAType>(IRP);
1820
1821 return !AAType::hasTrivialInitializer() || ShouldUpdateAA;
1822 }
1823
1824 /// Determine opportunities to derive 'default' attributes in \p F and create
1825 /// abstract attribute objects for them.
1826 ///
1827 /// \param F The function that is checked for attribute opportunities.
1828 ///
1829 /// Note that abstract attribute instances are generally created even if the
1830 /// IR already contains the information they would deduce. The most important
1831 /// reason for this is the single interface, the one of the abstract attribute
1832 /// instance, which can be queried without the need to look at the IR in
1833 /// various places.
1835
1836 /// Determine whether the function \p F is IPO amendable
1837 ///
1838 /// If a function is exactly defined or it has alwaysinline attribute
1839 /// and is viable to be inlined, we say it is IPO amendable
1841 return F.hasExactDefinition() || InfoCache.InlineableFunctions.count(&F) ||
1842 (Configuration.IPOAmendableCB && Configuration.IPOAmendableCB(F));
1843 }
1844
1845 /// Mark the internal function \p F as live.
1846 ///
1847 /// This will trigger the identification and initialization of attributes for
1848 /// \p F.
1850 assert(F.hasLocalLinkage() &&
1851 "Only local linkage is assumed dead initially.");
1852
1853 if (Configuration.DefaultInitializeLiveInternals)
1855 if (Configuration.InitializationCallback)
1856 Configuration.InitializationCallback(*this, F);
1857 }
1858
1859 /// Record that \p U is to be replaces with \p NV after information was
1860 /// manifested. This also triggers deletion of trivially dead istructions.
1862 Value *&V = ToBeChangedUses[&U];
1863 if (V && (V->stripPointerCasts() == NV.stripPointerCasts() ||
1864 isa_and_nonnull<UndefValue>(V)))
1865 return false;
1866 assert((!V || V == &NV || isa<UndefValue>(NV)) &&
1867 "Use was registered twice for replacement with different values!");
1868 V = &NV;
1869 return true;
1870 }
1871
1872 /// Helper function to replace all uses associated with \p IRP with \p NV.
1873 /// Return true if there is any change. The flag \p ChangeDroppable indicates
1874 /// if dropppable uses should be changed too.
1876 bool ChangeDroppable = true) {
1878 auto *CB = cast<CallBase>(IRP.getCtxI());
1880 CB->getArgOperandUse(IRP.getCallSiteArgNo()), NV);
1881 }
1882 Value &V = IRP.getAssociatedValue();
1883 auto &Entry = ToBeChangedValues[&V];
1884 Value *CurNV = get<0>(Entry);
1885 if (CurNV && (CurNV->stripPointerCasts() == NV.stripPointerCasts() ||
1886 isa<UndefValue>(CurNV)))
1887 return false;
1888 assert((!CurNV || CurNV == &NV || isa<UndefValue>(NV)) &&
1889 "Value replacement was registered twice with different values!");
1890 Entry = {&NV, ChangeDroppable};
1891 return true;
1892 }
1893
1894 /// Record that \p I is to be replaced with `unreachable` after information
1895 /// was manifested.
1897 ToBeChangedToUnreachableInsts.insert(I);
1898 }
1899
1900 /// Record that \p II has at least one dead successor block. This information
1901 /// is used, e.g., to replace \p II with a call, after information was
1902 /// manifested.
1904 InvokeWithDeadSuccessor.insert(&II);
1905 }
1906
1907 /// Record that \p I is deleted after information was manifested. This also
1908 /// triggers deletion of trivially dead istructions.
1909 void deleteAfterManifest(Instruction &I) { ToBeDeletedInsts.insert(&I); }
1910
1911 /// Record that \p BB is deleted after information was manifested. This also
1912 /// triggers deletion of trivially dead istructions.
1913 void deleteAfterManifest(BasicBlock &BB) { ToBeDeletedBlocks.insert(&BB); }
1914
1915 // Record that \p BB is added during the manifest of an AA. Added basic blocks
1916 // are preserved in the IR.
1918 ManifestAddedBlocks.insert(&BB);
1919 }
1920
1921 /// Record that \p F is deleted after information was manifested.
1923 if (Configuration.DeleteFns)
1924 ToBeDeletedFunctions.insert(&F);
1925 }
1926
1927 /// Return the attributes of kind \p AK existing in the IR as operand bundles
1928 /// of an llvm.assume.
1929 LLVM_ABI bool getAttrsFromAssumes(const IRPosition &IRP,
1932
1933 /// Return true if any kind in \p AKs existing in the IR at a position that
1934 /// will affect this one. See also getAttrs(...).
1935 /// \param IgnoreSubsumingPositions Flag to determine if subsuming positions,
1936 /// e.g., the function position if this is an
1937 /// argument position, should be ignored.
1938 LLVM_ABI bool
1940 bool IgnoreSubsumingPositions = false,
1941 Attribute::AttrKind ImpliedAttributeKind = Attribute::None);
1942
1943 /// Return the attributes of any kind in \p AKs existing in the IR at a
1944 /// position that will affect this one. While each position can only have a
1945 /// single attribute of any kind in \p AKs, there are "subsuming" positions
1946 /// that could have an attribute as well. This method returns all attributes
1947 /// found in \p Attrs.
1948 /// \param IgnoreSubsumingPositions Flag to determine if subsuming positions,
1949 /// e.g., the function position if this is an
1950 /// argument position, should be ignored.
1951 LLVM_ABI void getAttrs(const IRPosition &IRP,
1954 bool IgnoreSubsumingPositions = false);
1955
1956 /// Remove all \p AttrKinds attached to \p IRP.
1960 ArrayRef<StringRef> Attrs);
1961
1962 /// Attach \p DeducedAttrs to \p IRP, if \p ForceReplace is set we do this
1963 /// even if the same attribute kind was already present.
1965 ArrayRef<Attribute> DeducedAttrs,
1966 bool ForceReplace = false);
1967
1968private:
1969 /// Helper to check \p Attrs for \p AK, if not found, check if \p
1970 /// AAType::isImpliedByIR is true, and if not, create AAType for \p IRP.
1971 /// If \p SkipHasAttrCheck is true, don't check whether the attribute is set
1972 /// first. This should be used if only some values of a complex IR attribute
1973 /// imply the AAType.
1974 template <Attribute::AttrKind AK, typename AAType>
1975 void checkAndQueryIRAttr(const IRPosition &IRP, AttributeSet Attrs,
1976 bool SkipHasAttrCheck = false);
1977
1978 /// Helper to apply \p CB on all attributes of type \p AttrDescs of \p IRP.
1979 template <typename DescTy>
1980 ChangeStatus updateAttrMap(const IRPosition &IRP, ArrayRef<DescTy> AttrDescs,
1981 function_ref<bool(const DescTy &, AttributeSet,
1983 CB);
1984
1985 /// Mapping from functions/call sites to their attributes.
1987
1988public:
1989 /// If \p IRP is assumed to be a constant, return it, if it is unclear yet,
1990 /// return std::nullopt, otherwise return `nullptr`.
1991 LLVM_ABI std::optional<Constant *>
1992 getAssumedConstant(const IRPosition &IRP, const AbstractAttribute &AA,
1993 bool &UsedAssumedInformation);
1994 std::optional<Constant *> getAssumedConstant(const Value &V,
1995 const AbstractAttribute &AA,
1996 bool &UsedAssumedInformation) {
1997 return getAssumedConstant(IRPosition::value(V), AA, UsedAssumedInformation);
1998 }
1999
2000 /// If \p V is assumed simplified, return it, if it is unclear yet,
2001 /// return std::nullopt, otherwise return `nullptr`.
2002 std::optional<Value *> getAssumedSimplified(const IRPosition &IRP,
2003 const AbstractAttribute &AA,
2004 bool &UsedAssumedInformation,
2005 AA::ValueScope S) {
2006 return getAssumedSimplified(IRP, &AA, UsedAssumedInformation, S);
2007 }
2008 std::optional<Value *> getAssumedSimplified(const Value &V,
2009 const AbstractAttribute &AA,
2010 bool &UsedAssumedInformation,
2011 AA::ValueScope S) {
2013 UsedAssumedInformation, S);
2014 }
2015
2016 /// If \p V is assumed simplified, return it, if it is unclear yet,
2017 /// return std::nullopt, otherwise return `nullptr`. Same as the public
2018 /// version except that it can be used without recording dependences on any \p
2019 /// AA.
2020 LLVM_ABI std::optional<Value *>
2022 bool &UsedAssumedInformation, AA::ValueScope S);
2023
2024 /// Try to simplify \p IRP and in the scope \p S. If successful, true is
2025 /// returned and all potential values \p IRP can take are put into \p Values.
2026 /// If the result in \p Values contains select or PHI instructions it means
2027 /// those could not be simplified to a single value. Recursive calls with
2028 /// these instructions will yield their respective potential values. If false
2029 /// is returned no other information is valid.
2030 LLVM_ABI bool
2033 AA::ValueScope S, bool &UsedAssumedInformation,
2034 bool RecurseForSelectAndPHI = true);
2035
2036 /// Register \p CB as a simplification callback.
2037 /// `Attributor::getAssumedSimplified` will use these callbacks before
2038 /// we it will ask `AAValueSimplify`. It is important to ensure this
2039 /// is called before `identifyDefaultAbstractAttributes`, assuming the
2040 /// latter is called at all.
2041 using SimplifictionCallbackTy = std::function<std::optional<Value *>(
2042 const IRPosition &, const AbstractAttribute *, bool &)>;
2044 const SimplifictionCallbackTy &CB) {
2045 SimplificationCallbacks[IRP].emplace_back(CB);
2046 }
2047
2048 /// Return true if there is a simplification callback for \p IRP.
2050 return SimplificationCallbacks.count(IRP);
2051 }
2052
2053 /// Register \p CB as a simplification callback.
2054 /// Similar to \p registerSimplificationCallback, the call back will be called
2055 /// first when we simplify a global variable \p GV.
2057 std::function<std::optional<Constant *>(
2058 const GlobalVariable &, const AbstractAttribute *, bool &)>;
2060 const GlobalVariable &GV,
2062 GlobalVariableSimplificationCallbacks[&GV].emplace_back(CB);
2063 }
2064
2065 /// Return true if there is a simplification callback for \p GV.
2067 return GlobalVariableSimplificationCallbacks.count(&GV);
2068 }
2069
2070 /// Return \p std::nullopt if there is no call back registered for \p GV or
2071 /// the call back is still not sure if \p GV can be simplified. Return \p
2072 /// nullptr if \p GV can't be simplified.
2073 std::optional<Constant *>
2075 const AbstractAttribute *AA,
2076 bool &UsedAssumedInformation) {
2077 assert(GlobalVariableSimplificationCallbacks.contains(&GV));
2078 for (auto &CB : GlobalVariableSimplificationCallbacks.lookup(&GV)) {
2079 auto SimplifiedGV = CB(GV, AA, UsedAssumedInformation);
2080 // For now we assume the call back will not return a std::nullopt.
2081 assert(SimplifiedGV.has_value() && "SimplifiedGV has not value");
2082 return *SimplifiedGV;
2083 }
2084 llvm_unreachable("there must be a callback registered");
2085 }
2086
2088 std::function<bool(Attributor &, const AbstractAttribute *)>;
2090 const VirtualUseCallbackTy &CB) {
2091 VirtualUseCallbacks[&V].emplace_back(CB);
2092 }
2093
2094private:
2095 /// The vector with all simplification callbacks registered by outside AAs.
2097 SimplificationCallbacks;
2098
2099 /// The vector with all simplification callbacks for global variables
2100 /// registered by outside AAs.
2101 DenseMap<const GlobalVariable *,
2103 GlobalVariableSimplificationCallbacks;
2104
2106 VirtualUseCallbacks;
2107
2108public:
2109 /// Translate \p V from the callee context into the call site context.
2110 LLVM_ABI std::optional<Value *>
2111 translateArgumentToCallSiteContent(std::optional<Value *> V, CallBase &CB,
2112 const AbstractAttribute &AA,
2113 bool &UsedAssumedInformation);
2114
2115 /// Return true if \p AA (or its context instruction) is assumed dead.
2116 ///
2117 /// If \p LivenessAA is not provided it is queried.
2119 const AAIsDead *LivenessAA,
2120 bool &UsedAssumedInformation,
2121 bool CheckBBLivenessOnly = false,
2122 DepClassTy DepClass = DepClassTy::OPTIONAL);
2123
2124 /// Return true if \p I is assumed dead.
2125 ///
2126 /// If \p LivenessAA is not provided it is queried.
2127 LLVM_ABI bool isAssumedDead(const Instruction &I,
2128 const AbstractAttribute *QueryingAA,
2129 const AAIsDead *LivenessAA,
2130 bool &UsedAssumedInformation,
2131 bool CheckBBLivenessOnly = false,
2133 bool CheckForDeadStore = false);
2134
2135 /// Return true if \p U is assumed dead.
2136 ///
2137 /// If \p FnLivenessAA is not provided it is queried.
2138 LLVM_ABI bool isAssumedDead(const Use &U, const AbstractAttribute *QueryingAA,
2139 const AAIsDead *FnLivenessAA,
2140 bool &UsedAssumedInformation,
2141 bool CheckBBLivenessOnly = false,
2142 DepClassTy DepClass = DepClassTy::OPTIONAL);
2143
2144 /// Return true if \p IRP is assumed dead.
2145 ///
2146 /// If \p FnLivenessAA is not provided it is queried.
2147 LLVM_ABI bool isAssumedDead(const IRPosition &IRP,
2148 const AbstractAttribute *QueryingAA,
2149 const AAIsDead *FnLivenessAA,
2150 bool &UsedAssumedInformation,
2151 bool CheckBBLivenessOnly = false,
2152 DepClassTy DepClass = DepClassTy::OPTIONAL);
2153
2154 /// Return true if \p BB is assumed dead.
2155 ///
2156 /// If \p LivenessAA is not provided it is queried.
2157 LLVM_ABI bool isAssumedDead(const BasicBlock &BB,
2158 const AbstractAttribute *QueryingAA,
2159 const AAIsDead *FnLivenessAA,
2160 DepClassTy DepClass = DepClassTy::OPTIONAL);
2161
2162 /// Check \p Pred on all potential Callees of \p CB.
2163 ///
2164 /// This method will evaluate \p Pred with all potential callees of \p CB as
2165 /// input and return true if \p Pred does. If some callees might be unknown
2166 /// this function will return false.
2168 function_ref<bool(ArrayRef<const Function *> Callees)> Pred,
2169 const AbstractAttribute &QueryingAA, const CallBase &CB);
2170
2171 /// Check \p Pred on all (transitive) uses of \p V.
2172 ///
2173 /// This method will evaluate \p Pred on all (transitive) uses of the
2174 /// associated value and return true if \p Pred holds every time.
2175 /// If uses are skipped in favor of equivalent ones, e.g., if we look through
2176 /// memory, the \p EquivalentUseCB will be used to give the caller an idea
2177 /// what original used was replaced by a new one (or new ones). The visit is
2178 /// cut short if \p EquivalentUseCB returns false and the function will return
2179 /// false as well.
2181 function_ref<bool(const Use &, bool &)> Pred,
2182 const AbstractAttribute &QueryingAA, const Value &V,
2183 bool CheckBBLivenessOnly = false,
2184 DepClassTy LivenessDepClass = DepClassTy::OPTIONAL,
2185 bool IgnoreDroppableUses = true,
2186 function_ref<bool(const Use &OldU, const Use &NewU)> EquivalentUseCB =
2187 nullptr);
2188
2189 /// Emit a remark generically.
2190 ///
2191 /// This template function can be used to generically emit a remark. The
2192 /// RemarkKind should be one of the following:
2193 /// - OptimizationRemark to indicate a successful optimization attempt
2194 /// - OptimizationRemarkMissed to report a failed optimization attempt
2195 /// - OptimizationRemarkAnalysis to provide additional information about an
2196 /// optimization attempt
2197 ///
2198 /// The remark is built using a callback function \p RemarkCB that takes a
2199 /// RemarkKind as input and returns a RemarkKind.
2200 template <typename RemarkKind, typename RemarkCallBack>
2202 RemarkCallBack &&RemarkCB) const {
2203 if (!Configuration.OREGetter)
2204 return;
2205
2206 Function *F = I->getFunction();
2207 auto &ORE = Configuration.OREGetter(F);
2208
2209 if (RemarkName.starts_with("OMP"))
2210 ORE.emit([&]() {
2211 return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, I))
2212 << " [" << RemarkName << "]";
2213 });
2214 else
2215 ORE.emit([&]() {
2216 return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, I));
2217 });
2218 }
2219
2220 /// Emit a remark on a function.
2221 template <typename RemarkKind, typename RemarkCallBack>
2222 void emitRemark(Function *F, StringRef RemarkName,
2223 RemarkCallBack &&RemarkCB) const {
2224 if (!Configuration.OREGetter)
2225 return;
2226
2227 auto &ORE = Configuration.OREGetter(F);
2228
2229 if (RemarkName.starts_with("OMP"))
2230 ORE.emit([&]() {
2231 return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, F))
2232 << " [" << RemarkName << "]";
2233 });
2234 else
2235 ORE.emit([&]() {
2236 return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, F));
2237 });
2238 }
2239
2240 /// Helper struct used in the communication between an abstract attribute (AA)
2241 /// that wants to change the signature of a function and the Attributor which
2242 /// applies the changes. The struct is partially initialized with the
2243 /// information from the AA (see the constructor). All other members are
2244 /// provided by the Attributor prior to invoking any callbacks.
2246 /// Callee repair callback type
2247 ///
2248 /// The function repair callback is invoked once to rewire the replacement
2249 /// arguments in the body of the new function. The argument replacement info
2250 /// is passed, as build from the registerFunctionSignatureRewrite call, as
2251 /// well as the replacement function and an iteratore to the first
2252 /// replacement argument.
2253 using CalleeRepairCBTy = std::function<void(
2255
2256 /// Abstract call site (ACS) repair callback type
2257 ///
2258 /// The abstract call site repair callback is invoked once on every abstract
2259 /// call site of the replaced function (\see ReplacedFn). The callback needs
2260 /// to provide the operands for the call to the new replacement function.
2261 /// The number and type of the operands appended to the provided vector
2262 /// (second argument) is defined by the number and types determined through
2263 /// the replacement type vector (\see ReplacementTypes). The first argument
2264 /// is the ArgumentReplacementInfo object registered with the Attributor
2265 /// through the registerFunctionSignatureRewrite call.
2267 std::function<void(const ArgumentReplacementInfo &, AbstractCallSite,
2269
2270 /// Simple getters, see the corresponding members for details.
2271 ///{
2272
2273 Attributor &getAttributor() const { return A; }
2274 const Function &getReplacedFn() const { return ReplacedFn; }
2275 const Argument &getReplacedArg() const { return ReplacedArg; }
2276 unsigned getNumReplacementArgs() const { return ReplacementTypes.size(); }
2278 return ReplacementTypes;
2279 }
2280
2281 ///}
2282
2283 private:
2284 /// Constructor that takes the argument to be replaced, the types of
2285 /// the replacement arguments, as well as callbacks to repair the call sites
2286 /// and new function after the replacement happened.
2288 ArrayRef<Type *> ReplacementTypes,
2289 CalleeRepairCBTy &&CalleeRepairCB,
2290 ACSRepairCBTy &&ACSRepairCB)
2291 : A(A), ReplacedFn(*Arg.getParent()), ReplacedArg(Arg),
2292 ReplacementTypes(ReplacementTypes),
2293 CalleeRepairCB(std::move(CalleeRepairCB)),
2294 ACSRepairCB(std::move(ACSRepairCB)) {}
2295
2296 /// Reference to the attributor to allow access from the callbacks.
2297 Attributor &A;
2298
2299 /// The "old" function replaced by ReplacementFn.
2300 const Function &ReplacedFn;
2301
2302 /// The "old" argument replaced by new ones defined via ReplacementTypes.
2303 const Argument &ReplacedArg;
2304
2305 /// The types of the arguments replacing ReplacedArg.
2306 const SmallVector<Type *, 8> ReplacementTypes;
2307
2308 /// Callee repair callback, see CalleeRepairCBTy.
2309 const CalleeRepairCBTy CalleeRepairCB;
2310
2311 /// Abstract call site (ACS) repair callback, see ACSRepairCBTy.
2312 const ACSRepairCBTy ACSRepairCB;
2313
2314 /// Allow access to the private members from the Attributor.
2315 friend struct Attributor;
2316 };
2317
2318 /// Check if we can rewrite a function signature.
2319 ///
2320 /// The argument \p Arg is replaced with new ones defined by the number,
2321 /// order, and types in \p ReplacementTypes.
2322 ///
2323 /// \returns True, if the replacement can be registered, via
2324 /// registerFunctionSignatureRewrite, false otherwise.
2325 LLVM_ABI bool
2327 ArrayRef<Type *> ReplacementTypes);
2328
2329 /// Register a rewrite for a function signature.
2330 ///
2331 /// The argument \p Arg is replaced with new ones defined by the number,
2332 /// order, and types in \p ReplacementTypes. The rewiring at the call sites is
2333 /// done through \p ACSRepairCB and at the callee site through
2334 /// \p CalleeRepairCB.
2335 ///
2336 /// \returns True, if the replacement was registered, false otherwise.
2338 Argument &Arg, ArrayRef<Type *> ReplacementTypes,
2341
2342 /// Check \p Pred on all function call sites.
2343 ///
2344 /// This method will evaluate \p Pred on call sites and return
2345 /// true if \p Pred holds in every call sites. However, this is only possible
2346 /// all call sites are known, hence the function has internal linkage.
2347 /// If true is returned, \p UsedAssumedInformation is set if assumed
2348 /// information was used to skip or simplify potential call sites.
2350 const AbstractAttribute &QueryingAA,
2351 bool RequireAllCallSites,
2352 bool &UsedAssumedInformation);
2353
2354 /// Check \p Pred on all call sites of \p Fn.
2355 ///
2356 /// This method will evaluate \p Pred on call sites and return
2357 /// true if \p Pred holds in every call sites. However, this is only possible
2358 /// all call sites are known, hence the function has internal linkage.
2359 /// If true is returned, \p UsedAssumedInformation is set if assumed
2360 /// information was used to skip or simplify potential call sites.
2362 const Function &Fn,
2363 bool RequireAllCallSites,
2364 const AbstractAttribute *QueryingAA,
2365 bool &UsedAssumedInformation,
2366 bool CheckPotentiallyDead = false);
2367
2368 /// Check \p Pred on all values potentially returned by the function
2369 /// associated with \p QueryingAA.
2370 ///
2371 /// This is the context insensitive version of the method above.
2372 LLVM_ABI bool
2374 const AbstractAttribute &QueryingAA,
2376 bool RecurseForSelectAndPHI = true);
2377
2378 /// Check \p Pred on all instructions in \p Fn with an opcode present in
2379 /// \p Opcodes.
2380 ///
2381 /// This method will evaluate \p Pred on all instructions with an opcode
2382 /// present in \p Opcode and return true if \p Pred holds on all of them.
2384 const Function *Fn,
2385 const AbstractAttribute *QueryingAA,
2386 ArrayRef<unsigned> Opcodes,
2387 bool &UsedAssumedInformation,
2388 bool CheckBBLivenessOnly = false,
2389 bool CheckPotentiallyDead = false);
2390
2391 /// Check \p Pred on all instructions with an opcode present in \p Opcodes.
2392 ///
2393 /// This method will evaluate \p Pred on all instructions with an opcode
2394 /// present in \p Opcode and return true if \p Pred holds on all of them.
2396 const AbstractAttribute &QueryingAA,
2397 ArrayRef<unsigned> Opcodes,
2398 bool &UsedAssumedInformation,
2399 bool CheckBBLivenessOnly = false,
2400 bool CheckPotentiallyDead = false);
2401
2402 /// Check \p Pred on all call-like instructions (=CallBased derived).
2403 ///
2404 /// See checkForAllCallLikeInstructions(...) for more information.
2406 const AbstractAttribute &QueryingAA,
2407 bool &UsedAssumedInformation,
2408 bool CheckBBLivenessOnly = false,
2409 bool CheckPotentiallyDead = false) {
2411 Pred, QueryingAA,
2412 {(unsigned)Instruction::Invoke, (unsigned)Instruction::CallBr,
2413 (unsigned)Instruction::Call},
2414 UsedAssumedInformation, CheckBBLivenessOnly, CheckPotentiallyDead);
2415 }
2416
2417 /// Check \p Pred on all Read/Write instructions.
2418 ///
2419 /// This method will evaluate \p Pred on all instructions that read or write
2420 /// to memory present in the information cache and return true if \p Pred
2421 /// holds on all of them.
2422 LLVM_ABI bool
2424 AbstractAttribute &QueryingAA,
2425 bool &UsedAssumedInformation);
2426
2427 /// Create a shallow wrapper for \p F such that \p F has internal linkage
2428 /// afterwards. It also sets the original \p F 's name to anonymous
2429 ///
2430 /// A wrapper is a function with the same type (and attributes) as \p F
2431 /// that will only call \p F and return the result, if any.
2432 ///
2433 /// Assuming the declaration of looks like:
2434 /// rty F(aty0 arg0, ..., atyN argN);
2435 ///
2436 /// The wrapper will then look as follows:
2437 /// rty wrapper(aty0 arg0, ..., atyN argN) {
2438 /// return F(arg0, ..., argN);
2439 /// }
2440 ///
2442
2443 /// Returns true if the function \p F can be internalized. i.e. it has a
2444 /// compatible linkage.
2445 LLVM_ABI static bool isInternalizable(Function &F);
2446
2447 /// Make another copy of the function \p F such that the copied version has
2448 /// internal linkage afterwards and can be analysed. Then we replace all uses
2449 /// of the original function to the copied one
2450 ///
2451 /// Only non-locally linked functions that have `linkonce_odr` or `weak_odr`
2452 /// linkage can be internalized because these linkages guarantee that other
2453 /// definitions with the same name have the same semantics as this one.
2454 ///
2455 /// This will only be run if the `attributor-allow-deep-wrappers` option is
2456 /// set, or if the function is called with \p Force set to true.
2457 ///
2458 /// If the function \p F failed to be internalized the return value will be a
2459 /// null pointer.
2461 bool Force = false);
2462
2463 /// Make copies of each function in the set \p FnSet such that the copied
2464 /// version has internal linkage afterwards and can be analysed. Then we
2465 /// replace all uses of the original function to the copied one. The map
2466 /// \p FnMap contains a mapping of functions to their internalized versions.
2467 ///
2468 /// Only non-locally linked functions that have `linkonce_odr` or `weak_odr`
2469 /// linkage can be internalized because these linkages guarantee that other
2470 /// definitions with the same name have the same semantics as this one.
2471 ///
2472 /// This version will internalize all the functions in the set \p FnSet at
2473 /// once and then replace the uses. This prevents internalized functions being
2474 /// called by external functions when there is an internalized version in the
2475 /// module.
2476 LLVM_ABI static bool
2479
2480 /// Return the data layout associated with the anchor scope.
2481 const DataLayout &getDataLayout() const { return InfoCache.DL; }
2482
2483 /// The allocator used to allocate memory, e.g. for `AbstractAttribute`s.
2485
2487 return CGModifiedFunctions;
2488 }
2489
2490private:
2491 /// This method will do fixpoint iteration until fixpoint or the
2492 /// maximum iteration count is reached.
2493 ///
2494 /// If the maximum iteration count is reached, This method will
2495 /// indicate pessimistic fixpoint on attributes that transitively depend
2496 /// on attributes that were scheduled for an update.
2497 void runTillFixpoint();
2498
2499 /// Gets called after scheduling, manifests attributes to the LLVM IR.
2500 ChangeStatus manifestAttributes();
2501
2502 /// Gets called after attributes have been manifested, cleans up the IR.
2503 /// Deletes dead functions, blocks and instructions.
2504 /// Rewrites function signitures and updates the call graph.
2505 ChangeStatus cleanupIR();
2506
2507 /// Identify internal functions that are effectively dead, thus not reachable
2508 /// from a live entry point. The functions are added to ToBeDeletedFunctions.
2509 void identifyDeadInternalFunctions();
2510
2511 /// Run `::update` on \p AA and track the dependences queried while doing so.
2512 /// Also adjust the state if we know further updates are not necessary.
2514
2515 /// Remember the dependences on the top of the dependence stack such that they
2516 /// may trigger further updates. (\see DependenceStack)
2517 void rememberDependences();
2518
2519 /// Determine if CallBase context in \p IRP should be propagated.
2520 LLVM_ABI bool shouldPropagateCallBaseContext(const IRPosition &IRP);
2521
2522 /// Apply all requested function signature rewrites
2523 /// (\see registerFunctionSignatureRewrite) and return Changed if the module
2524 /// was altered.
2526 rewriteFunctionSignatures(SmallSetVector<Function *, 8> &ModifiedFns);
2527
2528 /// Check if the Attribute \p AA should be seeded.
2529 /// See getOrCreateAAFor.
2530 LLVM_ABI bool shouldSeedAttribute(AbstractAttribute &AA);
2531
2532 /// A nested map to lookup abstract attributes based on the argument position
2533 /// on the outer level, and the addresses of the static member (AAType::ID) on
2534 /// the inner level.
2535 ///{
2536 using AAMapKeyTy = std::pair<const char *, IRPosition>;
2538 ///}
2539
2540 /// Map to remember all requested signature changes (= argument replacements).
2542 ArgumentReplacementMap;
2543
2544 /// The set of functions we are deriving attributes for.
2545 SetVector<Function *> &Functions;
2546
2547 /// The information cache that holds pre-processed (LLVM-IR) information.
2548 InformationCache &InfoCache;
2549
2550 /// Abstract Attribute dependency graph
2551 AADepGraph DG;
2552
2553 /// Set of functions for which we modified the content such that it might
2554 /// impact the call graph.
2555 SmallSetVector<Function *, 8> CGModifiedFunctions;
2556
2557 /// Information about a dependence. If FromAA is changed ToAA needs to be
2558 /// updated as well.
2559 struct DepInfo {
2560 const AbstractAttribute *FromAA;
2561 const AbstractAttribute *ToAA;
2562 DepClassTy DepClass;
2563 };
2564
2565 /// The dependence stack is used to track dependences during an
2566 /// `AbstractAttribute::update` call. As `AbstractAttribute::update` can be
2567 /// recursive we might have multiple vectors of dependences in here. The stack
2568 /// size, should be adjusted according to the expected recursion depth and the
2569 /// inner dependence vector size to the expected number of dependences per
2570 /// abstract attribute. Since the inner vectors are actually allocated on the
2571 /// stack we can be generous with their size.
2572 using DependenceVector = SmallVector<DepInfo, 8>;
2573 SmallVector<DependenceVector *, 16> DependenceStack;
2574
2575 /// A set to remember the functions we already assume to be live and visited.
2576 DenseSet<const Function *> VisitedFunctions;
2577
2578 /// Uses we replace with a new value after manifest is done. We will remove
2579 /// then trivially dead instructions as well.
2580 SmallMapVector<Use *, Value *, 32> ToBeChangedUses;
2581
2582 /// Values we replace with a new value after manifest is done. We will remove
2583 /// then trivially dead instructions as well.
2584 SmallMapVector<Value *, PointerIntPair<Value *, 1, bool>, 32>
2585 ToBeChangedValues;
2586
2587 /// Instructions we replace with `unreachable` insts after manifest is done.
2588 SmallSetVector<WeakVH, 16> ToBeChangedToUnreachableInsts;
2589
2590 /// Invoke instructions with at least a single dead successor block.
2591 SmallSetVector<WeakVH, 16> InvokeWithDeadSuccessor;
2592
2593 /// A flag that indicates which stage of the process we are in. Initially, the
2594 /// phase is SEEDING. Phase is changed in `Attributor::run()`
2595 enum class AttributorPhase {
2596 SEEDING,
2597 UPDATE,
2598 MANIFEST,
2599 CLEANUP,
2600 } Phase = AttributorPhase::SEEDING;
2601
2602 /// The current initialization chain length. Tracked to avoid stack overflows.
2603 unsigned InitializationChainLength = 0;
2604
2605 /// Functions, blocks, and instructions we delete after manifest is done.
2606 ///
2607 ///{
2608 SmallPtrSet<BasicBlock *, 8> ManifestAddedBlocks;
2609 SmallSetVector<Function *, 8> ToBeDeletedFunctions;
2610 SmallSetVector<BasicBlock *, 8> ToBeDeletedBlocks;
2611 SmallSetVector<WeakVH, 8> ToBeDeletedInsts;
2612 ///}
2613
2614 /// Container with all the query AAs that requested an update via
2615 /// registerForUpdate.
2616 SmallSetVector<AbstractAttribute *, 16> QueryAAsAwaitingUpdate;
2617
2618 /// User provided configuration for this Attributor instance.
2619 const AttributorConfig Configuration;
2620
2621 friend AADepGraph;
2622 friend AttributorCallGraph;
2623};
2624
2625/// An interface to query the internal state of an abstract attribute.
2626///
2627/// The abstract state is a minimal interface that allows the Attributor to
2628/// communicate with the abstract attributes about their internal state without
2629/// enforcing or exposing implementation details, e.g., the (existence of an)
2630/// underlying lattice.
2631///
2632/// It is sufficient to be able to query if a state is (1) valid or invalid, (2)
2633/// at a fixpoint, and to indicate to the state that (3) an optimistic fixpoint
2634/// was reached or (4) a pessimistic fixpoint was enforced.
2635///
2636/// All methods need to be implemented by the subclass. For the common use case,
2637/// a single boolean state or a bit-encoded state, the BooleanState and
2638/// {Inc,Dec,Bit}IntegerState classes are already provided. An abstract
2639/// attribute can inherit from them to get the abstract state interface and
2640/// additional methods to directly modify the state based if needed. See the
2641/// class comments for help.
2643 virtual ~AbstractState() = default;
2644
2645 /// Return if this abstract state is in a valid state. If false, no
2646 /// information provided should be used.
2647 virtual bool isValidState() const = 0;
2648
2649 /// Return if this abstract state is fixed, thus does not need to be updated
2650 /// if information changes as it cannot change itself.
2651 virtual bool isAtFixpoint() const = 0;
2652
2653 /// Indicate that the abstract state should converge to the optimistic state.
2654 ///
2655 /// This will usually make the optimistically assumed state the known to be
2656 /// true state.
2657 ///
2658 /// \returns ChangeStatus::UNCHANGED as the assumed value should not change.
2660
2661 /// Indicate that the abstract state should converge to the pessimistic state.
2662 ///
2663 /// This will usually revert the optimistically assumed state to the known to
2664 /// be true state.
2665 ///
2666 /// \returns ChangeStatus::CHANGED as the assumed value may change.
2668};
2669
2670/// Simple state with integers encoding.
2671///
2672/// The interface ensures that the assumed bits are always a subset of the known
2673/// bits. Users can only add known bits and, except through adding known bits,
2674/// they can only remove assumed bits. This should guarantee monotonicity and
2675/// thereby the existence of a fixpoint (if used correctly). The fixpoint is
2676/// reached when the assumed and known state/bits are equal. Users can
2677/// force/inidicate a fixpoint. If an optimistic one is indicated, the known
2678/// state will catch up with the assumed one, for a pessimistic fixpoint it is
2679/// the other way around.
2680template <typename base_ty, base_ty BestState, base_ty WorstState>
2682 using base_t = base_ty;
2683
2684 IntegerStateBase() = default;
2686
2687 /// Return the best possible representable state.
2688 static constexpr base_t getBestState() { return BestState; }
2689 static constexpr base_t getBestState(const IntegerStateBase &) {
2690 return getBestState();
2691 }
2692
2693 /// Return the worst possible representable state.
2694 static constexpr base_t getWorstState() { return WorstState; }
2695 static constexpr base_t getWorstState(const IntegerStateBase &) {
2696 return getWorstState();
2697 }
2698
2699 /// See AbstractState::isValidState()
2700 /// NOTE: For now we simply pretend that the worst possible state is invalid.
2701 bool isValidState() const override { return Assumed != getWorstState(); }
2702
2703 /// See AbstractState::isAtFixpoint()
2704 bool isAtFixpoint() const override { return Assumed == Known; }
2705
2706 /// See AbstractState::indicateOptimisticFixpoint(...)
2708 Known = Assumed;
2710 }
2711
2712 /// See AbstractState::indicatePessimisticFixpoint(...)
2714 Assumed = Known;
2715 return ChangeStatus::CHANGED;
2716 }
2717
2718 /// Return the known state encoding
2719 base_t getKnown() const { return Known; }
2720
2721 /// Return the assumed state encoding.
2722 base_t getAssumed() const { return Assumed; }
2723
2724 /// Equality for IntegerStateBase.
2725 bool
2727 return this->getAssumed() == R.getAssumed() &&
2728 this->getKnown() == R.getKnown();
2729 }
2730
2731 /// Inequality for IntegerStateBase.
2732 bool
2734 return !(*this == R);
2735 }
2736
2737 /// "Clamp" this state with \p R. The result is subtype dependent but it is
2738 /// intended that only information assumed in both states will be assumed in
2739 /// this one afterwards.
2741 handleNewAssumedValue(R.getAssumed());
2742 }
2743
2744 /// "Clamp" this state with \p R. The result is subtype dependent but it is
2745 /// intended that information known in either state will be known in
2746 /// this one afterwards.
2748 handleNewKnownValue(R.getKnown());
2749 }
2750
2752 joinOR(R.getAssumed(), R.getKnown());
2753 }
2754
2756 joinAND(R.getAssumed(), R.getKnown());
2757 }
2758
2759protected:
2760 /// Handle a new assumed value \p Value. Subtype dependent.
2762
2763 /// Handle a new known value \p Value. Subtype dependent.
2765
2766 /// Handle a value \p Value. Subtype dependent.
2767 virtual void joinOR(base_t AssumedValue, base_t KnownValue) = 0;
2768
2769 /// Handle a new assumed value \p Value. Subtype dependent.
2770 virtual void joinAND(base_t AssumedValue, base_t KnownValue) = 0;
2771
2772 /// The known state encoding in an integer of type base_t.
2774
2775 /// The assumed state encoding in an integer of type base_t.
2777};
2778
2779/// Specialization of the integer state for a bit-wise encoding.
2780template <typename base_ty = uint32_t, base_ty BestState = ~base_ty(0),
2781 base_ty WorstState = 0>
2783 : public IntegerStateBase<base_ty, BestState, WorstState> {
2785 using base_t = base_ty;
2786 BitIntegerState() = default;
2788
2789 /// Return true if the bits set in \p BitsEncoding are "known bits".
2790 bool isKnown(base_t BitsEncoding = BestState) const {
2791 return (this->Known & BitsEncoding) == BitsEncoding;
2792 }
2793
2794 /// Return true if the bits set in \p BitsEncoding are "assumed bits".
2795 bool isAssumed(base_t BitsEncoding = BestState) const {
2796 return (this->Assumed & BitsEncoding) == BitsEncoding;
2797 }
2798
2799 /// Add the bits in \p BitsEncoding to the "known bits".
2801 // Make sure we never miss any "known bits".
2802 this->Assumed |= Bits;
2803 this->Known |= Bits;
2804 return *this;
2805 }
2806
2807 /// Remove the bits in \p BitsEncoding from the "assumed bits" if not known.
2809 return intersectAssumedBits(~BitsEncoding);
2810 }
2811
2812 /// Remove the bits in \p BitsEncoding from the "known bits".
2814 this->Known = (this->Known & ~BitsEncoding);
2815 return *this;
2816 }
2817
2818 /// Keep only "assumed bits" also set in \p BitsEncoding but all known ones.
2820 // Make sure we never lose any "known bits".
2821 this->Assumed = (this->Assumed & BitsEncoding) | this->Known;
2822 return *this;
2823 }
2824
2825private:
2826 void handleNewAssumedValue(base_t Value) override {
2828 }
2829 void handleNewKnownValue(base_t Value) override { addKnownBits(Value); }
2830 void joinOR(base_t AssumedValue, base_t KnownValue) override {
2831 this->Known |= KnownValue;
2832 this->Assumed |= AssumedValue;
2833 }
2834 void joinAND(base_t AssumedValue, base_t KnownValue) override {
2835 this->Known &= KnownValue;
2836 this->Assumed &= AssumedValue;
2837 }
2838};
2839
2840/// Specialization of the integer state for an increasing value, hence ~0u is
2841/// the best state and 0 the worst.
2842template <typename base_ty = uint32_t, base_ty BestState = ~base_ty(0),
2843 base_ty WorstState = 0>
2845 : public IntegerStateBase<base_ty, BestState, WorstState> {
2847 using base_t = base_ty;
2848
2851
2852 /// Return the best possible representable state.
2853 static constexpr base_t getBestState() { return BestState; }
2854 static constexpr base_t
2856 return getBestState();
2857 }
2858
2859 /// Take minimum of assumed and \p Value.
2861 // Make sure we never lose "known value".
2862 this->Assumed = std::max(std::min(this->Assumed, Value), this->Known);
2863 return *this;
2864 }
2865
2866 /// Take maximum of known and \p Value.
2868 // Make sure we never lose "known value".
2869 this->Assumed = std::max(Value, this->Assumed);
2870 this->Known = std::max(Value, this->Known);
2871 return *this;
2872 }
2873
2874private:
2875 void handleNewAssumedValue(base_t Value) override {
2877 }
2878 void handleNewKnownValue(base_t Value) override { takeKnownMaximum(Value); }
2879 void joinOR(base_t AssumedValue, base_t KnownValue) override {
2880 this->Known = std::max(this->Known, KnownValue);
2881 this->Assumed = std::max(this->Assumed, AssumedValue);
2882 }
2883 void joinAND(base_t AssumedValue, base_t KnownValue) override {
2884 this->Known = std::min(this->Known, KnownValue);
2885 this->Assumed = std::min(this->Assumed, AssumedValue);
2886 }
2887};
2888
2889/// Specialization of the integer state for a decreasing value, hence 0 is the
2890/// best state and ~0u the worst.
2891template <typename base_ty = uint32_t>
2892struct DecIntegerState : public IntegerStateBase<base_ty, 0, ~base_ty(0)> {
2893 using base_t = base_ty;
2894
2895 /// Take maximum of assumed and \p Value.
2897 // Make sure we never lose "known value".
2898 this->Assumed = std::min(std::max(this->Assumed, Value), this->Known);
2899 return *this;
2900 }
2901
2902 /// Take minimum of known and \p Value.
2904 // Make sure we never lose "known value".
2905 this->Assumed = std::min(Value, this->Assumed);
2906 this->Known = std::min(Value, this->Known);
2907 return *this;
2908 }
2909
2910private:
2911 void handleNewAssumedValue(base_t Value) override {
2913 }
2914 void handleNewKnownValue(base_t Value) override { takeKnownMinimum(Value); }
2915 void joinOR(base_t AssumedValue, base_t KnownValue) override {
2916 this->Assumed = std::min(this->Assumed, KnownValue);
2917 this->Assumed = std::min(this->Assumed, AssumedValue);
2918 }
2919 void joinAND(base_t AssumedValue, base_t KnownValue) override {
2920 this->Assumed = std::max(this->Assumed, KnownValue);
2921 this->Assumed = std::max(this->Assumed, AssumedValue);
2922 }
2923};
2924
2925/// Simple wrapper for a single bit (boolean) state.
2926struct BooleanState : public IntegerStateBase<bool, true, false> {
2929
2930 BooleanState() = default;
2932
2933 /// Set the assumed value to \p Value but never below the known one.
2934 void setAssumed(bool Value) { Assumed &= (Known | Value); }
2935
2936 /// Set the known and asssumed value to \p Value.
2937 void setKnown(bool Value) {
2938 Known |= Value;
2939 Assumed |= Value;
2940 }
2941
2942 /// Return true if the state is assumed to hold.
2943 bool isAssumed() const { return getAssumed(); }
2944
2945 /// Return true if the state is known to hold.
2946 bool isKnown() const { return getKnown(); }
2947
2948private:
2949 void handleNewAssumedValue(base_t Value) override {
2950 if (!Value)
2951 Assumed = Known;
2952 }
2953 void handleNewKnownValue(base_t Value) override {
2954 if (Value)
2955 Known = (Assumed = Value);
2956 }
2957 void joinOR(base_t AssumedValue, base_t KnownValue) override {
2958 Known |= KnownValue;
2959 Assumed |= AssumedValue;
2960 }
2961 void joinAND(base_t AssumedValue, base_t KnownValue) override {
2962 Known &= KnownValue;
2963 Assumed &= AssumedValue;
2964 }
2965};
2966
2967/// State for an integer range.
2969
2970 /// Bitwidth of the associated value.
2972
2973 /// State representing assumed range, initially set to empty.
2975
2976 /// State representing known range, initially set to [-inf, inf].
2978
2981 Known(ConstantRange::getFull(BitWidth)) {}
2982
2984 : BitWidth(CR.getBitWidth()), Assumed(CR),
2986
2987 /// Return the worst possible representable state.
2989 return ConstantRange::getFull(BitWidth);
2990 }
2991
2992 /// Return the best possible representable state.
2994 return ConstantRange::getEmpty(BitWidth);
2995 }
2997 return getBestState(IRS.getBitWidth());
2998 }
2999
3000 /// Return associated values' bit width.
3001 uint32_t getBitWidth() const { return BitWidth; }
3002
3003 /// See AbstractState::isValidState()
3004 bool isValidState() const override {
3005 return BitWidth > 0 && !Assumed.isFullSet();
3006 }
3007
3008 /// See AbstractState::isAtFixpoint()
3009 bool isAtFixpoint() const override { return Assumed == Known; }
3010
3011 /// See AbstractState::indicateOptimisticFixpoint(...)
3013 Known = Assumed;
3014 return ChangeStatus::CHANGED;
3015 }
3016
3017 /// See AbstractState::indicatePessimisticFixpoint(...)
3019 Assumed = Known;
3020 return ChangeStatus::CHANGED;
3021 }
3022
3023 /// Return the known state encoding
3024 ConstantRange getKnown() const { return Known; }
3025
3026 /// Return the assumed state encoding.
3028
3029 /// Unite assumed range with the passed state.
3031 // Don't lose a known range.
3033 }
3034
3035 /// See IntegerRangeState::unionAssumed(..).
3037 unionAssumed(R.getAssumed());
3038 }
3039
3040 /// Intersect known range with the passed state.
3044 }
3045
3046 /// See IntegerRangeState::intersectKnown(..).
3048 intersectKnown(R.getKnown());
3049 }
3050
3051 /// Equality for IntegerRangeState.
3052 bool operator==(const IntegerRangeState &R) const {
3053 return getAssumed() == R.getAssumed() && getKnown() == R.getKnown();
3054 }
3055
3056 /// "Clamp" this state with \p R. The result is subtype dependent but it is
3057 /// intended that only information assumed in both states will be assumed in
3058 /// this one afterwards.
3060 // NOTE: `^=` operator seems like `intersect` but in this case, we need to
3061 // take `union`.
3062 unionAssumed(R);
3063 return *this;
3064 }
3065
3067 // NOTE: `&=` operator seems like `intersect` but in this case, we need to
3068 // take `union`.
3069 Known = Known.unionWith(R.getKnown());
3070 Assumed = Assumed.unionWith(R.getAssumed());
3071 return *this;
3072 }
3073};
3074
3075/// Simple state for a set.
3076///
3077/// This represents a state containing a set of values. The interface supports
3078/// modelling sets that contain all possible elements. The state's internal
3079/// value is modified using union or intersection operations.
3080template <typename BaseTy> struct SetState : public AbstractState {
3081 /// A wrapper around a set that has semantics for handling unions and
3082 /// intersections with a "universal" set that contains all elements.
3084 /// Creates a universal set with no concrete elements or an empty set.
3085 SetContents(bool Universal) : Universal(Universal) {}
3086
3087 /// Creates a non-universal set with concrete values.
3088 SetContents(const DenseSet<BaseTy> &Assumptions)
3089 : Universal(false), Set(Assumptions) {}
3090
3091 SetContents(bool Universal, const DenseSet<BaseTy> &Assumptions)
3092 : Universal(Universal), Set(Assumptions) {}
3093
3094 const DenseSet<BaseTy> &getSet() const { return Set; }
3095
3096 bool isUniversal() const { return Universal; }
3097
3098 bool empty() const { return Set.empty() && !Universal; }
3099
3100 /// Finds A := A ^ B where A or B could be the "Universal" set which
3101 /// contains every possible attribute. Returns true if changes were made.
3103 bool IsUniversal = Universal;
3104 unsigned Size = Set.size();
3105
3106 // A := A ^ U = A
3107 if (RHS.isUniversal())
3108 return false;
3109
3110 // A := U ^ B = B
3111 if (Universal)
3112 Set = RHS.getSet();
3113 else
3114 set_intersect(Set, RHS.getSet());
3115
3116 Universal &= RHS.isUniversal();
3117 return IsUniversal != Universal || Size != Set.size();
3118 }
3119
3120 /// Finds A := A u B where A or B could be the "Universal" set which
3121 /// contains every possible attribute. returns true if changes were made.
3122 bool getUnion(const SetContents &RHS) {
3123 bool IsUniversal = Universal;
3124 unsigned Size = Set.size();
3125
3126 // A := A u U = U = U u B
3127 if (!RHS.isUniversal() && !Universal)
3128 set_union(Set, RHS.getSet());
3129
3130 Universal |= RHS.isUniversal();
3131 return IsUniversal != Universal || Size != Set.size();
3132 }
3133
3134 private:
3135 /// Indicates if this set is "universal", containing every possible element.
3136 bool Universal;
3137
3138 /// The set of currently active assumptions.
3139 DenseSet<BaseTy> Set;
3140 };
3141
3142 SetState() : Known(false), Assumed(true), IsAtFixedpoint(false) {}
3143
3144 /// Initializes the known state with an initial set and initializes the
3145 /// assumed state as universal.
3147 : Known(Known), Assumed(true), IsAtFixedpoint(false) {}
3148
3149 /// See AbstractState::isValidState()
3150 bool isValidState() const override { return !Assumed.empty(); }
3151
3152 /// See AbstractState::isAtFixpoint()
3153 bool isAtFixpoint() const override { return IsAtFixedpoint; }
3154
3155 /// See AbstractState::indicateOptimisticFixpoint(...)
3157 IsAtFixedpoint = true;
3158 Known = Assumed;
3160 }
3161
3162 /// See AbstractState::indicatePessimisticFixpoint(...)
3164 IsAtFixedpoint = true;
3165 Assumed = Known;
3166 return ChangeStatus::CHANGED;
3167 }
3168
3169 /// Return the known state encoding.
3170 const SetContents &getKnown() const { return Known; }
3171
3172 /// Return the assumed state encoding.
3173 const SetContents &getAssumed() const { return Assumed; }
3174
3175 /// Returns if the set state contains the element.
3176 bool setContains(const BaseTy &Elem) const {
3177 return Assumed.getSet().contains(Elem) || Known.getSet().contains(Elem);
3178 }
3179
3180 /// Performs the set intersection between this set and \p RHS. Returns true if
3181 /// changes were made.
3183 bool IsUniversal = Assumed.isUniversal();
3184 unsigned SizeBefore = Assumed.getSet().size();
3185
3186 // Get intersection and make sure that the known set is still a proper
3187 // subset of the assumed set. A := K u (A ^ R).
3188 Assumed.getIntersection(RHS);
3189 Assumed.getUnion(Known);
3190
3191 return SizeBefore != Assumed.getSet().size() ||
3192 IsUniversal != Assumed.isUniversal();
3193 }
3194
3195 /// Performs the set union between this set and \p RHS. Returns true if
3196 /// changes were made.
3197 bool getUnion(const SetContents &RHS) { return Assumed.getUnion(RHS); }
3198
3199private:
3200 /// The set of values known for this state.
3201 SetContents Known;
3202
3203 /// The set of assumed values for this state.
3204 SetContents Assumed;
3205
3206 bool IsAtFixedpoint;
3207};
3208
3209/// Helper to tie a abstract state implementation to an abstract attribute.
3210template <typename StateTy, typename BaseType, class... Ts>
3211struct StateWrapper : public BaseType, public StateTy {
3212 /// Provide static access to the type of the state.
3214
3215 StateWrapper(const IRPosition &IRP, Ts... Args)
3216 : BaseType(IRP), StateTy(Args...) {}
3217
3218 /// See AbstractAttribute::getState(...).
3219 StateType &getState() override { return *this; }
3220
3221 /// See AbstractAttribute::getState(...).
3222 const StateType &getState() const override { return *this; }
3223};
3224
3225/// Helper class that provides common functionality to manifest IR attributes.
3226template <Attribute::AttrKind AK, typename BaseType, typename AAType>
3227struct IRAttribute : public BaseType {
3228 IRAttribute(const IRPosition &IRP) : BaseType(IRP) {}
3229
3230 /// Most boolean IRAttribute AAs don't do anything non-trivial
3231 /// in their initializers while non-boolean ones often do. Subclasses can
3232 /// change this.
3234
3235 /// Compile time access to the IR attribute kind.
3237
3238 /// Return true if the IR attribute(s) associated with this AA are implied for
3239 /// an undef value.
3240 static bool isImpliedByUndef() { return true; }
3241
3242 /// Return true if the IR attribute(s) associated with this AA are implied for
3243 /// an poison value.
3244 static bool isImpliedByPoison() { return true; }
3245
3246 static bool isImpliedByIR(Attributor &A, const IRPosition &IRP,
3247 Attribute::AttrKind ImpliedAttributeKind = AK,
3248 bool IgnoreSubsumingPositions = false) {
3249 if (AAType::isImpliedByUndef() && isa<UndefValue>(IRP.getAssociatedValue()))
3250 return true;
3251 if (AAType::isImpliedByPoison() &&
3252 isa<PoisonValue>(IRP.getAssociatedValue()))
3253 return true;
3254 return A.hasAttr(IRP, {ImpliedAttributeKind}, IgnoreSubsumingPositions,
3255 ImpliedAttributeKind);
3256 }
3257
3258 /// See AbstractAttribute::manifest(...).
3260 if (isa<UndefValue>(this->getIRPosition().getAssociatedValue()))
3262 SmallVector<Attribute, 4> DeducedAttrs;
3263 getDeducedAttributes(A, this->getAnchorValue().getContext(), DeducedAttrs);
3264 if (DeducedAttrs.empty())
3266 return A.manifestAttrs(this->getIRPosition(), DeducedAttrs);
3267 }
3268
3269 /// Return the kind that identifies the abstract attribute implementation.
3270 Attribute::AttrKind getAttrKind() const { return AK; }
3271
3272 /// Return the deduced attributes in \p Attrs.
3274 SmallVectorImpl<Attribute> &Attrs) const {
3275 Attrs.emplace_back(Attribute::get(Ctx, getAttrKind()));
3276 }
3277};
3278
3279/// Base struct for all "concrete attribute" deductions.
3280///
3281/// The abstract attribute is a minimal interface that allows the Attributor to
3282/// orchestrate the abstract/fixpoint analysis. The design allows to hide away
3283/// implementation choices made for the subclasses but also to structure their
3284/// implementation and simplify the use of other abstract attributes in-flight.
3285///
3286/// To allow easy creation of new attributes, most methods have default
3287/// implementations. The ones that do not are generally straight forward, except
3288/// `AbstractAttribute::updateImpl` which is the location of most reasoning
3289/// associated with the abstract attribute. The update is invoked by the
3290/// Attributor in case the situation used to justify the current optimistic
3291/// state might have changed. The Attributor determines this automatically
3292/// by monitoring the `Attributor::getAAFor` calls made by abstract attributes.
3293///
3294/// The `updateImpl` method should inspect the IR and other abstract attributes
3295/// in-flight to justify the best possible (=optimistic) state. The actual
3296/// implementation is, similar to the underlying abstract state encoding, not
3297/// exposed. In the most common case, the `updateImpl` will go through a list of
3298/// reasons why its optimistic state is valid given the current information. If
3299/// any combination of them holds and is sufficient to justify the current
3300/// optimistic state, the method shall return UNCHAGED. If not, the optimistic
3301/// state is adjusted to the situation and the method shall return CHANGED.
3302///
3303/// If the manifestation of the "concrete attribute" deduced by the subclass
3304/// differs from the "default" behavior, which is a (set of) LLVM-IR
3305/// attribute(s) for an argument, call site argument, function return value, or
3306/// function, the `AbstractAttribute::manifest` method should be overloaded.
3307///
3308/// NOTE: If the state obtained via getState() is INVALID, thus if
3309/// AbstractAttribute::getState().isValidState() returns false, no
3310/// information provided by the methods of this class should be used.
3311/// NOTE: The Attributor currently has certain limitations to what we can do.
3312/// As a general rule of thumb, "concrete" abstract attributes should *for
3313/// now* only perform "backward" information propagation. That means
3314/// optimistic information obtained through abstract attributes should
3315/// only be used at positions that precede the origin of the information
3316/// with regards to the program flow. More practically, information can
3317/// *now* be propagated from instructions to their enclosing function, but
3318/// *not* from call sites to the called function. The mechanisms to allow
3319/// both directions will be added in the future.
3320/// NOTE: The mechanics of adding a new "concrete" abstract attribute are
3321/// described in the file comment.
3324
3326
3327 /// Virtual destructor.
3328 virtual ~AbstractAttribute() = default;
3329
3330 /// Compile time access to the IR attribute kind.
3331 static constexpr Attribute::AttrKind IRAttributeKind = Attribute::None;
3332
3333 /// This function is used to identify if an \p DGN is of type
3334 /// AbstractAttribute so that the dyn_cast and cast can use such information
3335 /// to cast an AADepGraphNode to an AbstractAttribute.
3336 ///
3337 /// We eagerly return true here because all AADepGraphNodes except for the
3338 /// Synthethis Node are of type AbstractAttribute
3339 static bool classof(const AADepGraphNode *DGN) { return true; }
3340
3341 /// Return false if this AA does anything non-trivial (hence not done by
3342 /// default) in its initializer.
3343 static bool hasTrivialInitializer() { return false; }
3344
3345 /// Return true if this AA requires a "callee" (or an associted function) for
3346 /// a call site positon. Default is optimistic to minimize AAs.
3347 static bool requiresCalleeForCallBase() { return false; }
3348
3349 /// Return true if this AA requires non-asm "callee" for a call site positon.
3350 static bool requiresNonAsmForCallBase() { return true; }
3351
3352 /// Return true if this AA requires all callees for an argument or function
3353 /// positon.
3354 static bool requiresCallersForArgOrFunction() { return false; }
3355
3356 /// Return false if an AA should not be created for \p IRP.
3358 return true;
3359 }
3360
3361 /// Return false if an AA should not be updated for \p IRP.
3363 Function *AssociatedFn = IRP.getAssociatedFunction();
3364 bool IsFnInterface = IRP.isFnInterfaceKind();
3365 assert((!IsFnInterface || AssociatedFn) &&
3366 "Function interface without a function?");
3367
3368 // TODO: Not all attributes require an exact definition. Find a way to
3369 // enable deduction for some but not all attributes in case the
3370 // definition might be changed at runtime, see also
3371 // http://lists.llvm.org/pipermail/llvm-dev/2018-February/121275.html.
3372 // TODO: We could always determine abstract attributes and if sufficient
3373 // information was found we could duplicate the functions that do not
3374 // have an exact definition.
3375 return !IsFnInterface || A.isFunctionIPOAmendable(*AssociatedFn);
3376 }
3377
3378 /// Initialize the state with the information in the Attributor \p A.
3379 ///
3380 /// This function is called by the Attributor once all abstract attributes
3381 /// have been identified. It can and shall be used for task like:
3382 /// - identify existing knowledge in the IR and use it for the "known state"
3383 /// - perform any work that is not going to change over time, e.g., determine
3384 /// a subset of the IR, or attributes in-flight, that have to be looked at
3385 /// in the `updateImpl` method.
3386 virtual void initialize(Attributor &A) {}
3387
3388 /// A query AA is always scheduled as long as we do updates because it does
3389 /// lazy computation that cannot be determined to be done from the outside.
3390 /// However, while query AAs will not be fixed if they do not have outstanding
3391 /// dependences, we will only schedule them like other AAs. If a query AA that
3392 /// received a new query it needs to request an update via
3393 /// `Attributor::requestUpdateForAA`.
3394 virtual bool isQueryAA() const { return false; }
3395
3396 /// Return the internal abstract state for inspection.
3397 virtual StateType &getState() = 0;
3398 virtual const StateType &getState() const = 0;
3399
3400 /// Return an IR position, see struct IRPosition.
3401 const IRPosition &getIRPosition() const { return *this; };
3402 IRPosition &getIRPosition() { return *this; };
3403
3404 /// Helper functions, for debug purposes only.
3405 ///{
3406 void print(raw_ostream &OS) const { print(nullptr, OS); }
3407 void print(Attributor *, raw_ostream &OS) const override;
3408 virtual void printWithDeps(raw_ostream &OS) const;
3409 void dump() const { this->print(dbgs()); }
3410
3411 /// This function should return the "summarized" assumed state as string.
3412 virtual const std::string getAsStr(Attributor *A) const = 0;
3413
3414 /// This function should return the name of the AbstractAttribute
3415 virtual StringRef getName() const = 0;
3416
3417 /// This function should return the address of the ID of the AbstractAttribute
3418 virtual const char *getIdAddr() const = 0;
3419 ///}
3420
3421 /// Allow the Attributor access to the protected methods.
3422 friend struct Attributor;
3423
3424protected:
3425 /// Hook for the Attributor to trigger an update of the internal state.
3426 ///
3427 /// If this attribute is already fixed, this method will return UNCHANGED,
3428 /// otherwise it delegates to `AbstractAttribute::updateImpl`.
3429 ///
3430 /// \Return CHANGED if the internal state changed, otherwise UNCHANGED.
3431 ChangeStatus update(Attributor &A);
3432
3433 /// Hook for the Attributor to trigger the manifestation of the information
3434 /// represented by the abstract attribute in the LLVM-IR.
3435 ///
3436 /// \Return CHANGED if the IR was altered, otherwise UNCHANGED.
3438 return ChangeStatus::UNCHANGED;
3439 }
3440
3441 /// Hook to enable custom statistic tracking, called after manifest that
3442 /// resulted in a change if statistics are enabled.
3443 ///
3444 /// We require subclasses to provide an implementation so we remember to
3445 /// add statistics for them.
3446 virtual void trackStatistics() const = 0;
3447
3448 /// The actual update/transfer function which has to be implemented by the
3449 /// derived classes.
3450 ///
3451 /// If it is called, the environment has changed and we have to determine if
3452 /// the current information is still valid or adjust it otherwise.
3453 ///
3454 /// \Return CHANGED if the internal state changed, otherwise UNCHANGED.
3456};
3457
3458/// Forward declarations of output streams for debug purposes.
3459///
3460///{
3466template <typename base_ty, base_ty BestState, base_ty WorstState>
3470 return OS << "(" << S.getKnown() << "-" << S.getAssumed() << ")"
3471 << static_cast<const AbstractState &>(S);
3472}
3473LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
3474 const IntegerRangeState &State);
3475///}
3476
3477struct AttributorPass : public PassInfoMixin<AttributorPass> {
3479};
3480struct AttributorCGSCCPass : public PassInfoMixin<AttributorCGSCCPass> {
3483 CGSCCUpdateResult &UR);
3484};
3485
3486/// A more lightweight version of the Attributor which only runs attribute
3487/// inference but no simplifications.
3488struct AttributorLightPass : public PassInfoMixin<AttributorLightPass> {
3490};
3491
3492/// A more lightweight version of the Attributor which only runs attribute
3493/// inference but no simplifications.
3495 : public PassInfoMixin<AttributorLightCGSCCPass> {
3498 CGSCCUpdateResult &UR);
3499};
3500
3501/// Helper function to clamp a state \p S of type \p StateType with the
3502/// information in \p R and indicate/return if \p S did change (as-in update is
3503/// required to be run again).
3504template <typename StateType>
3505ChangeStatus clampStateAndIndicateChange(StateType &S, const StateType &R) {
3506 auto Assumed = S.getAssumed();
3507 S ^= R;
3508 return Assumed == S.getAssumed() ? ChangeStatus::UNCHANGED
3510}
3511
3512/// ----------------------------------------------------------------------------
3513/// Abstract Attribute Classes
3514/// ----------------------------------------------------------------------------
3515
3517 : public IRAttribute<Attribute::NoUnwind,
3518 StateWrapper<BooleanState, AbstractAttribute>,
3519 AANoUnwind> {
3521
3522 /// Returns true if nounwind is assumed.
3523 bool isAssumedNoUnwind() const { return getAssumed(); }
3524
3525 /// Returns true if nounwind is known.
3526 bool isKnownNoUnwind() const { return getKnown(); }
3527
3528 /// Create an abstract attribute view for the position \p IRP.
3530 Attributor &A);
3531
3532 /// See AbstractAttribute::getName()
3533 StringRef getName() const override { return "AANoUnwind"; }
3534
3535 /// See AbstractAttribute::getIdAddr()
3536 const char *getIdAddr() const override { return &ID; }
3537
3538 /// This function should return true if the type of the \p AA is AANoUnwind
3539 static bool classof(const AbstractAttribute *AA) {
3540 return (AA->getIdAddr() == &ID);
3541 }
3542
3543 /// Unique ID (due to the unique address)
3544 LLVM_ABI static const char ID;
3545};
3546
3548 : public IRAttribute<Attribute::NoSync,
3549 StateWrapper<BooleanState, AbstractAttribute>,
3550 AANoSync> {
3552
3553 static bool isImpliedByIR(Attributor &A, const IRPosition &IRP,
3554 Attribute::AttrKind ImpliedAttributeKind,
3555 bool IgnoreSubsumingPositions = false) {
3556 // Note: This is also run for non-IPO amendable functions.
3557 assert(ImpliedAttributeKind == Attribute::NoSync);
3558 if (A.hasAttr(IRP, {Attribute::NoSync}, IgnoreSubsumingPositions,
3559 Attribute::NoSync))
3560 return true;
3561
3562 // Check for readonly + non-convergent.
3563 // TODO: We should be able to use hasAttr for Attributes, not only
3564 // AttrKinds.
3566 if (!F || F->isConvergent())
3567 return false;
3568
3570 A.getAttrs(IRP, {Attribute::Memory}, Attrs, IgnoreSubsumingPositions);
3571
3573 for (const Attribute &Attr : Attrs)
3574 ME &= Attr.getMemoryEffects();
3575
3576 if (!ME.onlyReadsMemory())
3577 return false;
3578
3579 A.manifestAttrs(IRP, Attribute::get(F->getContext(), Attribute::NoSync));
3580 return true;
3581 }
3582
3583 /// See AbstractAttribute::isValidIRPositionForInit
3585 if (!IRP.isFunctionScope() &&
3587 return false;
3588 return IRAttribute::isValidIRPositionForInit(A, IRP);
3589 }
3590
3591 /// Returns true if "nosync" is assumed.
3592 bool isAssumedNoSync() const { return getAssumed(); }
3593
3594 /// Returns true if "nosync" is known.
3595 bool isKnownNoSync() const { return getKnown(); }
3596
3597 /// Helper function used to determine whether an instruction is non-relaxed
3598 /// atomic. In other words, if an atomic instruction does not have unordered
3599 /// or monotonic ordering
3600 LLVM_ABI static bool isNonRelaxedAtomic(const Instruction *I);
3601
3602 /// Helper function specific for intrinsics which are potentially volatile.
3603 LLVM_ABI static bool isNoSyncIntrinsic(const Instruction *I);
3604
3605 /// Helper function to determine if \p CB is an aligned (GPU) barrier. Aligned
3606 /// barriers have to be executed by all threads. The flag \p ExecutedAligned
3607 /// indicates if the call is executed by all threads in a (thread) block in an
3608 /// aligned way. If that is the case, non-aligned barriers are effectively
3609 /// aligned barriers.
3610 LLVM_ABI static bool isAlignedBarrier(const CallBase &CB,
3611 bool ExecutedAligned);
3612
3613 /// Create an abstract attribute view for the position \p IRP.
3615 Attributor &A);
3616
3617 /// See AbstractAttribute::getName()
3618 StringRef getName() const override { return "AANoSync"; }
3619
3620 /// See AbstractAttribute::getIdAddr()
3621 const char *getIdAddr() const override { return &ID; }
3622
3623 /// This function should return true if the type of the \p AA is AANoSync
3624 static bool classof(const AbstractAttribute *AA) {
3625 return (AA->getIdAddr() == &ID);
3626 }
3627
3628 /// Unique ID (due to the unique address)
3629 LLVM_ABI static const char ID;
3630};
3631
3632/// An abstract interface for all nonnull attributes.
3634 : public IRAttribute<Attribute::MustProgress,
3635 StateWrapper<BooleanState, AbstractAttribute>,
3636 AAMustProgress> {
3638
3639 static bool isImpliedByIR(Attributor &A, const IRPosition &IRP,
3640 Attribute::AttrKind ImpliedAttributeKind,
3641 bool IgnoreSubsumingPositions = false) {
3642 // Note: This is also run for non-IPO amendable functions.
3643 assert(ImpliedAttributeKind == Attribute::MustProgress);
3644 return A.hasAttr(IRP, {Attribute::MustProgress, Attribute::WillReturn},
3645 IgnoreSubsumingPositions, Attribute::MustProgress);
3646 }
3647
3648 /// Return true if we assume that the underlying value is nonnull.
3649 bool isAssumedMustProgress() const { return getAssumed(); }
3650
3651 /// Return true if we know that underlying value is nonnull.
3652 bool isKnownMustProgress() const { return getKnown(); }
3653
3654 /// Create an abstract attribute view for the position \p IRP.
3656 Attributor &A);
3657
3658 /// See AbstractAttribute::getName()
3659 StringRef getName() const override { return "AAMustProgress"; }
3660
3661 /// See AbstractAttribute::getIdAddr()
3662 const char *getIdAddr() const override { return &ID; }
3663
3664 /// This function should return true if the type of the \p AA is
3665 /// AAMustProgress
3666 static bool classof(const AbstractAttribute *AA) {
3667 return (AA->getIdAddr() == &ID);
3668 }
3669
3670 /// Unique ID (due to the unique address)
3671 LLVM_ABI static const char ID;
3672};
3673
3674/// An abstract interface for all nonnull attributes.
3676 : public IRAttribute<Attribute::NonNull,
3677 StateWrapper<BooleanState, AbstractAttribute>,
3678 AANonNull> {
3680
3681 /// See AbstractAttribute::hasTrivialInitializer.
3682 static bool hasTrivialInitializer() { return false; }
3683
3684 /// See IRAttribute::isImpliedByUndef.
3685 /// Undef is not necessarily nonnull as nonnull + noundef would cause poison.
3686 /// Poison implies nonnull though.
3687 static bool isImpliedByUndef() { return false; }
3688
3689 /// See AbstractAttribute::isValidIRPositionForInit
3692 return false;
3693 return IRAttribute::isValidIRPositionForInit(A, IRP);
3694 }
3695
3696 /// See AbstractAttribute::isImpliedByIR(...).
3697 LLVM_ABI static bool isImpliedByIR(Attributor &A, const IRPosition &IRP,
3698 Attribute::AttrKind ImpliedAttributeKind,
3699 bool IgnoreSubsumingPositions = false);
3700
3701 /// Return true if we assume that the underlying value is nonnull.
3702 bool isAssumedNonNull() const { return getAssumed(); }
3703
3704 /// Return true if we know that underlying value is nonnull.
3705 bool isKnownNonNull() const { return getKnown(); }
3706
3707 /// Create an abstract attribute view for the position \p IRP.
3709 Attributor &A);
3710
3711 /// See AbstractAttribute::getName()
3712 StringRef getName() const override { return "AANonNull"; }
3713
3714 /// See AbstractAttribute::getIdAddr()
3715 const char *getIdAddr() const override { return &ID; }
3716
3717 /// This function should return true if the type of the \p AA is AANonNull
3718 static bool classof(const AbstractAttribute *AA) {
3719 return (AA->getIdAddr() == &ID);
3720 }
3721
3722 /// Unique ID (due to the unique address)
3723 LLVM_ABI static const char ID;
3724};
3725
3726/// An abstract attribute for norecurse.
3728 : public IRAttribute<Attribute::NoRecurse,
3729 StateWrapper<BooleanState, AbstractAttribute>,
3730 AANoRecurse> {
3732
3733 /// Return true if "norecurse" is assumed.
3734 bool isAssumedNoRecurse() const { return getAssumed(); }
3735
3736 /// Return true if "norecurse" is known.
3737 bool isKnownNoRecurse() const { return getKnown(); }
3738
3739 /// Create an abstract attribute view for the position \p IRP.
3741 Attributor &A);
3742
3743 /// See AbstractAttribute::getName()
3744 StringRef getName() const override { return "AANoRecurse"; }
3745
3746 /// See AbstractAttribute::getIdAddr()
3747 const char *getIdAddr() const override { return &ID; }
3748
3749 /// This function should return true if the type of the \p AA is AANoRecurse
3750 static bool classof(const AbstractAttribute *AA) {
3751 return (AA->getIdAddr() == &ID);
3752 }
3753
3754 /// Unique ID (due to the unique address)
3755 LLVM_ABI static const char ID;
3756};
3757
3758/// An abstract attribute for willreturn.
3760 : public IRAttribute<Attribute::WillReturn,
3761 StateWrapper<BooleanState, AbstractAttribute>,
3762 AAWillReturn> {
3764
3765 static bool isImpliedByIR(Attributor &A, const IRPosition &IRP,
3766 Attribute::AttrKind ImpliedAttributeKind,
3767 bool IgnoreSubsumingPositions = false) {
3768 // Note: This is also run for non-IPO amendable functions.
3769 assert(ImpliedAttributeKind == Attribute::WillReturn);
3770 if (IRAttribute::isImpliedByIR(A, IRP, ImpliedAttributeKind,
3771 IgnoreSubsumingPositions))
3772 return true;
3774 return false;
3775 A.manifestAttrs(IRP, Attribute::get(IRP.getAnchorValue().getContext(),
3776 Attribute::WillReturn));
3777 return true;
3778 }
3779
3780 /// Check for `mustprogress` and `readonly` as they imply `willreturn`.
3782 const IRPosition &IRP) {
3783 // Check for `mustprogress` in the scope and the associated function which
3784 // might be different if this is a call site.
3785 if (!A.hasAttr(IRP, {Attribute::MustProgress}))
3786 return false;
3787
3789 A.getAttrs(IRP, {Attribute::Memory}, Attrs,
3790 /* IgnoreSubsumingPositions */ false);
3791
3793 for (const Attribute &Attr : Attrs)
3794 ME &= Attr.getMemoryEffects();
3795 return ME.onlyReadsMemory();
3796 }
3797
3798 /// Return true if "willreturn" is assumed.
3799 bool isAssumedWillReturn() const { return getAssumed(); }
3800
3801 /// Return true if "willreturn" is known.
3802 bool isKnownWillReturn() const { return getKnown(); }
3803
3804 /// Create an abstract attribute view for the position \p IRP.
3806 Attributor &A);
3807
3808 /// See AbstractAttribute::getName()
3809 StringRef getName() const override { return "AAWillReturn"; }
3810
3811 /// See AbstractAttribute::getIdAddr()
3812 const char *getIdAddr() const override { return &ID; }
3813
3814 /// This function should return true if the type of the \p AA is AAWillReturn
3815 static bool classof(const AbstractAttribute *AA) {
3816 return (AA->getIdAddr() == &ID);
3817 }
3818
3819 /// Unique ID (due to the unique address)
3820 LLVM_ABI static const char ID;
3821};
3822
3823/// An abstract attribute for undefined behavior.
3825 : public StateWrapper<BooleanState, AbstractAttribute> {
3828
3829 /// Return true if "undefined behavior" is assumed.
3830 bool isAssumedToCauseUB() const { return getAssumed(); }
3831
3832 /// Return true if "undefined behavior" is assumed for a specific instruction.
3833 virtual bool isAssumedToCauseUB(Instruction *I) const = 0;
3834
3835 /// Return true if "undefined behavior" is known.
3836 bool isKnownToCauseUB() const { return getKnown(); }
3837
3838 /// Return true if "undefined behavior" is known for a specific instruction.
3839 virtual bool isKnownToCauseUB(Instruction *I) const = 0;
3840
3841 /// Create an abstract attribute view for the position \p IRP.
3843 Attributor &A);
3844
3845 /// See AbstractAttribute::getName()
3846 StringRef getName() const override { return "AAUndefinedBehavior"; }
3847
3848 /// See AbstractAttribute::getIdAddr()
3849 const char *getIdAddr() const override { return &ID; }
3850
3851 /// This function should return true if the type of the \p AA is
3852 /// AAUndefineBehavior
3853 static bool classof(const AbstractAttribute *AA) {
3854 return (AA->getIdAddr() == &ID);
3855 }
3856
3857 /// Unique ID (due to the unique address)
3858 LLVM_ABI static const char ID;
3859};
3860
3861/// An abstract interface to determine reachability of point A to B.
3863 : public StateWrapper<BooleanState, AbstractAttribute> {
3866
3867 /// Returns true if 'From' instruction is assumed to reach, 'To' instruction.
3868 /// Users should provide two positions they are interested in, and the class
3869 /// determines (and caches) reachability.
3871 Attributor &A, const Instruction &From, const Instruction &To,
3872 const AA::InstExclusionSetTy *ExclusionSet = nullptr) const = 0;
3873
3874 /// Create an abstract attribute view for the position \p IRP.
3877
3878 /// See AbstractAttribute::getName()
3879 StringRef getName() const override { return "AAIntraFnReachability"; }
3880
3881 /// See AbstractAttribute::getIdAddr()
3882 const char *getIdAddr() const override { return &ID; }
3883
3884 /// This function should return true if the type of the \p AA is
3885 /// AAIntraFnReachability
3886 static bool classof(const AbstractAttribute *AA) {
3887 return (AA->getIdAddr() == &ID);
3888 }
3889
3890 /// Unique ID (due to the unique address)
3891 LLVM_ABI static const char ID;
3892};
3893
3894/// An abstract interface for all noalias attributes.
3896 : public IRAttribute<Attribute::NoAlias,
3897 StateWrapper<BooleanState, AbstractAttribute>,
3898 AANoAlias> {
3900
3901 /// See AbstractAttribute::isValidIRPositionForInit
3903 if (!IRP.getAssociatedType()->isPointerTy())
3904 return false;
3905 return IRAttribute::isValidIRPositionForInit(A, IRP);
3906 }
3907
3908 /// See IRAttribute::isImpliedByIR
3909 LLVM_ABI static bool isImpliedByIR(Attributor &A, const IRPosition &IRP,
3910 Attribute::AttrKind ImpliedAttributeKind,
3911 bool IgnoreSubsumingPositions = false);
3912
3913 /// See AbstractAttribute::requiresCallersForArgOrFunction
3914 static bool requiresCallersForArgOrFunction() { return true; }
3915
3916 /// Return true if we assume that the underlying value is alias.
3917 bool isAssumedNoAlias() const { return getAssumed(); }
3918
3919 /// Return true if we know that underlying value is noalias.
3920 bool isKnownNoAlias() const { return getKnown(); }
3921
3922 /// Create an abstract attribute view for the position \p IRP.
3924 Attributor &A);
3925
3926 /// See AbstractAttribute::getName()
3927 StringRef getName() const override { return "AANoAlias"; }
3928
3929 /// See AbstractAttribute::getIdAddr()
3930 const char *getIdAddr() const override { return &ID; }
3931
3932 /// This function should return true if the type of the \p AA is AANoAlias
3933 static bool classof(const AbstractAttribute *AA) {
3934 return (AA->getIdAddr() == &ID);
3935 }
3936
3937 /// Unique ID (due to the unique address)
3938 LLVM_ABI static const char ID;
3939};
3940
3941/// An AbstractAttribute for nofree.
3943 : public IRAttribute<Attribute::NoFree,
3944 StateWrapper<BooleanState, AbstractAttribute>,
3945 AANoFree> {
3947
3948 /// See IRAttribute::isImpliedByIR
3949 static bool isImpliedByIR(Attributor &A, const IRPosition &IRP,
3950 Attribute::AttrKind ImpliedAttributeKind,
3951 bool IgnoreSubsumingPositions = false) {
3952 // Note: This is also run for non-IPO amendable functions.
3953 assert(ImpliedAttributeKind == Attribute::NoFree);
3954 return A.hasAttr(
3955 IRP, {Attribute::ReadNone, Attribute::ReadOnly, Attribute::NoFree},
3956 IgnoreSubsumingPositions, Attribute::NoFree);
3957 }
3958
3959 /// See AbstractAttribute::isValidIRPositionForInit
3961 if (!IRP.isFunctionScope() &&
3963 return false;
3964 return IRAttribute::isValidIRPositionForInit(A, IRP);
3965 }
3966
3967 /// Return true if "nofree" is assumed.
3968 bool isAssumedNoFree() const { return getAssumed(); }
3969
3970 /// Return true if "nofree" is known.
3971 bool isKnownNoFree() const { return getKnown(); }
3972
3973 /// Create an abstract attribute view for the position \p IRP.
3975 Attributor &A);
3976
3977 /// See AbstractAttribute::getName()
3978 StringRef getName() const override { return "AANoFree"; }
3979
3980 /// See AbstractAttribute::getIdAddr()
3981 const char *getIdAddr() const override { return &ID; }
3982
3983 /// This function should return true if the type of the \p AA is AANoFree
3984 static bool classof(const AbstractAttribute *AA) {
3985 return (AA->getIdAddr() == &ID);
3986 }
3987
3988 /// Unique ID (due to the unique address)
3989 LLVM_ABI static const char ID;
3990};
3991
3992/// An AbstractAttribute for noreturn.
3994 : public IRAttribute<Attribute::NoReturn,
3995 StateWrapper<BooleanState, AbstractAttribute>,
3996 AANoReturn> {
3998
3999 /// Return true if the underlying object is assumed to never return.
4000 bool isAssumedNoReturn() const { return getAssumed(); }
4001
4002 /// Return true if the underlying object is known to never return.
4003 bool isKnownNoReturn() const { return getKnown(); }
4004
4005 /// Create an abstract attribute view for the position \p IRP.
4007 Attributor &A);
4008
4009 /// See AbstractAttribute::getName()
4010 StringRef getName() const override { return "AANoReturn"; }
4011
4012 /// See AbstractAttribute::getIdAddr()
4013 const char *getIdAddr() const override { return &ID; }
4014
4015 /// This function should return true if the type of the \p AA is AANoReturn
4016 static bool classof(const AbstractAttribute *AA) {
4017 return (AA->getIdAddr() == &ID);
4018 }
4019
4020 /// Unique ID (due to the unique address)
4021 LLVM_ABI static const char ID;
4022};
4023
4024/// An abstract interface for liveness abstract attribute.
4026 : public StateWrapper<BitIntegerState<uint8_t, 3, 0>, AbstractAttribute> {
4028 AAIsDead(const IRPosition &IRP, Attributor &A) : Base(IRP) {}
4029
4030 /// See AbstractAttribute::isValidIRPositionForInit
4033 return isa<Function>(IRP.getAnchorValue()) &&
4034 !cast<Function>(IRP.getAnchorValue()).isDeclaration();
4035 return true;
4036 }
4037
4038 /// State encoding bits. A set bit in the state means the property holds.
4039 enum {
4042
4044 };
4045 static_assert(IS_DEAD == getBestState(), "Unexpected BEST_STATE value");
4046
4047protected:
4048 /// The query functions are protected such that other attributes need to go
4049 /// through the Attributor interfaces: `Attributor::isAssumedDead(...)`
4050
4051 /// Returns true if the underlying value is assumed dead.
4052 virtual bool isAssumedDead() const = 0;
4053
4054 /// Returns true if the underlying value is known dead.
4055 virtual bool isKnownDead() const = 0;
4056
4057 /// Returns true if \p BB is known dead.
4058 virtual bool isKnownDead(const BasicBlock *BB) const = 0;
4059
4060 /// Returns true if \p I is assumed dead.
4061 virtual bool isAssumedDead(const Instruction *I) const = 0;
4062
4063 /// Returns true if \p I is known dead.
4064 virtual bool isKnownDead(const Instruction *I) const = 0;
4065
4066 /// Return true if the underlying value is a store that is known to be
4067 /// removable. This is different from dead stores as the removable store
4068 /// can have an effect on live values, especially loads, but that effect
4069 /// is propagated which allows us to remove the store in turn.
4070 virtual bool isRemovableStore() const { return false; }
4071
4072 /// This method is used to check if at least one instruction in a collection
4073 /// of instructions is live.
4074 template <typename T> bool isLiveInstSet(T begin, T end) const {
4075 for (const auto &I : llvm::make_range(begin, end)) {
4076 assert(I->getFunction() == getIRPosition().getAssociatedFunction() &&
4077 "Instruction must be in the same anchor scope function.");
4078
4079 if (!isAssumedDead(I))
4080 return true;
4081 }
4082
4083 return false;
4084 }
4085
4086public:
4087 /// Create an abstract attribute view for the position \p IRP.
4089 Attributor &A);
4090
4091 /// Determine if \p F might catch asynchronous exceptions.
4093 return F.hasPersonalityFn() && !canSimplifyInvokeNoUnwind(&F);
4094 }
4095
4096 /// Returns true if \p BB is assumed dead.
4097 virtual bool isAssumedDead(const BasicBlock *BB) const = 0;
4098
4099 /// Return if the edge from \p From BB to \p To BB is assumed dead.
4100 /// This is specifically useful in AAReachability.
4101 virtual bool isEdgeDead(const BasicBlock *From, const BasicBlock *To) const {
4102 return false;
4103 }
4104
4105 /// See AbstractAttribute::getName()
4106 StringRef getName() const override { return "AAIsDead"; }
4107
4108 /// See AbstractAttribute::getIdAddr()
4109 const char *getIdAddr() const override { return &ID; }
4110
4111 /// This function should return true if the type of the \p AA is AAIsDead
4112 static bool classof(const AbstractAttribute *AA) {
4113 return (AA->getIdAddr() == &ID);
4114 }
4115
4116 /// Unique ID (due to the unique address)
4117 LLVM_ABI static const char ID;
4118
4119 friend struct Attributor;
4120};
4121
4122/// State for dereferenceable attribute
4124
4125 static DerefState getBestState() { return DerefState(); }
4126 static DerefState getBestState(const DerefState &) { return getBestState(); }
4127
4128 /// Return the worst possible representable state.
4130 DerefState DS;
4131 DS.indicatePessimisticFixpoint();
4132 return DS;
4133 }
4135 return getWorstState();
4136 }
4137
4138 /// State representing for dereferenceable bytes.
4140
4141 /// Map representing for accessed memory offsets and sizes.
4142 /// A key is Offset and a value is size.
4143 /// If there is a load/store instruction something like,
4144 /// p[offset] = v;
4145 /// (offset, sizeof(v)) will be inserted to this map.
4146 /// std::map is used because we want to iterate keys in ascending order.
4147 std::map<int64_t, uint64_t> AccessedBytesMap;
4148
4149 /// Helper function to calculate dereferenceable bytes from current known
4150 /// bytes and accessed bytes.
4151 ///
4152 /// int f(int *A){
4153 /// *A = 0;
4154 /// *(A+2) = 2;
4155 /// *(A+1) = 1;
4156 /// *(A+10) = 10;
4157 /// }
4158 /// ```
4159 /// In that case, AccessedBytesMap is `{0:4, 4:4, 8:4, 40:4}`.
4160 /// AccessedBytesMap is std::map so it is iterated in accending order on
4161 /// key(Offset). So KnownBytes will be updated like this:
4162 ///
4163 /// |Access | KnownBytes
4164 /// |(0, 4)| 0 -> 4
4165 /// |(4, 4)| 4 -> 8
4166 /// |(8, 4)| 8 -> 12
4167 /// |(40, 4) | 12 (break)
4168 void computeKnownDerefBytesFromAccessedMap() {
4169 int64_t KnownBytes = DerefBytesState.getKnown();
4170 for (auto &Access : AccessedBytesMap) {
4171 if (KnownBytes < Access.first)
4172 break;
4173 KnownBytes = std::max(KnownBytes, Access.first + (int64_t)Access.second);
4174 }
4175
4177 }
4178
4179 /// State representing that whether the value is globaly dereferenceable.
4180 BooleanState GlobalState;
4181
4182 /// See AbstractState::isValidState()
4183 bool isValidState() const override { return DerefBytesState.isValidState(); }
4184
4185 /// See AbstractState::isAtFixpoint()
4186 bool isAtFixpoint() const override {
4187 return !isValidState() ||
4188 (DerefBytesState.isAtFixpoint() && GlobalState.isAtFixpoint());
4189 }
4190
4191 /// See AbstractState::indicateOptimisticFixpoint(...)
4194 GlobalState.indicateOptimisticFixpoint();
4196 }
4197
4198 /// See AbstractState::indicatePessimisticFixpoint(...)
4201 GlobalState.indicatePessimisticFixpoint();
4202 return ChangeStatus::CHANGED;
4203 }
4204
4205 /// Update known dereferenceable bytes.
4206 void takeKnownDerefBytesMaximum(uint64_t Bytes) {
4208
4209 // Known bytes might increase.
4210 computeKnownDerefBytesFromAccessedMap();
4211 }
4212
4213 /// Update assumed dereferenceable bytes.
4214 void takeAssumedDerefBytesMinimum(uint64_t Bytes) {
4216 }
4217
4218 /// Add accessed bytes to the map.
4219 void addAccessedBytes(int64_t Offset, uint64_t Size) {
4220 uint64_t &AccessedBytes = AccessedBytesMap[Offset];
4221 AccessedBytes = std::max(AccessedBytes, Size);
4222
4223 // Known bytes might increase.
4224 computeKnownDerefBytesFromAccessedMap();
4225 }
4226
4227 /// Equality for DerefState.
4228 bool operator==(const DerefState &R) const {
4229 return this->DerefBytesState == R.DerefBytesState &&
4230 this->GlobalState == R.GlobalState;
4231 }
4232
4233 /// Inequality for DerefState.
4234 bool operator!=(const DerefState &R) const { return !(*this == R); }
4235
4236 /// See IntegerStateBase::operator^=
4237 DerefState operator^=(const DerefState &R) {
4238 DerefBytesState ^= R.DerefBytesState;
4239 GlobalState ^= R.GlobalState;
4240 return *this;
4241 }
4242
4243 /// See IntegerStateBase::operator+=
4244 DerefState operator+=(const DerefState &R) {
4245 DerefBytesState += R.DerefBytesState;
4246 GlobalState += R.GlobalState;
4247 return *this;
4248 }
4249
4250 /// See IntegerStateBase::operator&=
4251 DerefState operator&=(const DerefState &R) {
4252 DerefBytesState &= R.DerefBytesState;
4253 GlobalState &= R.GlobalState;
4254 return *this;
4255 }
4256
4257 /// See IntegerStateBase::operator|=
4258 DerefState operator|=(const DerefState &R) {
4259 DerefBytesState |= R.DerefBytesState;
4260 GlobalState |= R.GlobalState;
4261 return *this;
4262 }
4263};
4264
4265/// An abstract interface for all dereferenceable attribute.
4267 : public IRAttribute<Attribute::Dereferenceable,
4268 StateWrapper<DerefState, AbstractAttribute>,
4269 AADereferenceable> {
4271
4272 /// See AbstractAttribute::isValidIRPositionForInit
4274 if (!IRP.getAssociatedType()->isPointerTy())
4275 return false;
4276 return IRAttribute::isValidIRPositionForInit(A, IRP);
4277 }
4278
4279 /// Return true if we assume that underlying value is
4280 /// dereferenceable(_or_null) globally.
4281 bool isAssumedGlobal() const { return GlobalState.getAssumed(); }
4282
4283 /// Return true if we know that underlying value is
4284 /// dereferenceable(_or_null) globally.
4285 bool isKnownGlobal() const { return GlobalState.getKnown(); }
4286
4287 /// Return assumed dereferenceable bytes.
4289 return DerefBytesState.getAssumed();
4290 }
4291
4292 /// Return known dereferenceable bytes.
4294 return DerefBytesState.getKnown();
4295 }
4296
4297 /// Create an abstract attribute view for the position \p IRP.
4299 Attributor &A);
4300
4301 /// See AbstractAttribute::getName()
4302 StringRef getName() const override { return "AADereferenceable"; }
4303
4304 /// See AbstractAttribute::getIdAddr()
4305 const char *getIdAddr() const override { return &ID; }
4306
4307 /// This function should return true if the type of the \p AA is
4308 /// AADereferenceable
4309 static bool classof(const AbstractAttribute *AA) {
4310 return (AA->getIdAddr() == &ID);
4311 }
4312
4313 /// Unique ID (due to the unique address)
4314 LLVM_ABI static const char ID;
4315};
4316
4319/// An abstract interface for all align attributes.
4321 : public IRAttribute<Attribute::Alignment,
4322 StateWrapper<AAAlignmentStateType, AbstractAttribute>,
4323 AAAlign> {
4325
4326 /// See AbstractAttribute::isValidIRPositionForInit
4329 return false;
4330 return IRAttribute::isValidIRPositionForInit(A, IRP);
4331 }
4332
4333 /// Return assumed alignment.
4334 Align getAssumedAlign() const { return Align(getAssumed()); }
4335
4336 /// Return known alignment.
4337 Align getKnownAlign() const { return Align(getKnown()); }
4338
4339 /// See AbstractAttribute::getName()
4340 StringRef getName() const override { return "AAAlign"; }
4341
4342 /// See AbstractAttribute::getIdAddr()
4343 const char *getIdAddr() const override { return &ID; }
4344
4345 /// This function should return true if the type of the \p AA is AAAlign
4346 static bool classof(const AbstractAttribute *AA) {
4347 return (AA->getIdAddr() == &ID);
4348 }
4349
4350 /// Create an abstract attribute view for the position \p IRP.
4352 Attributor &A);
4353
4354 /// Unique ID (due to the unique address)
4355 LLVM_ABI static const char ID;
4356};
4357
4358/// An abstract interface to track if a value leaves it's defining function
4359/// instance.
4360/// TODO: We should make it a ternary AA tracking uniqueness, and uniqueness
4361/// wrt. the Attributor analysis separately.
4362struct AAInstanceInfo : public StateWrapper<BooleanState, AbstractAttribute> {
4365
4366 /// Return true if we know that the underlying value is unique in its scope
4367 /// wrt. the Attributor analysis. That means it might not be unique but we can
4368 /// still use pointer equality without risking to represent two instances with
4369 /// one `llvm::Value`.
4370 bool isKnownUniqueForAnalysis() const { return isKnown(); }
4371
4372 /// Return true if we assume that the underlying value is unique in its scope
4373 /// wrt. the Attributor analysis. That means it might not be unique but we can
4374 /// still use pointer equality without risking to represent two instances with
4375 /// one `llvm::Value`.
4376 bool isAssumedUniqueForAnalysis() const { return isAssumed(); }
4377
4378 /// Create an abstract attribute view for the position \p IRP.
4380 Attributor &A);
4381
4382 /// See AbstractAttribute::getName()
4383 StringRef getName() const override { return "AAInstanceInfo"; }
4384
4385 /// See AbstractAttribute::getIdAddr()
4386 const char *getIdAddr() const override { return &ID; }
4387
4388 /// This function should return true if the type of the \p AA is
4389 /// AAInstanceInfo
4390 static bool classof(const AbstractAttribute *AA) {
4391 return (AA->getIdAddr() == &ID);
4392 }
4393
4394 /// Unique ID (due to the unique address)
4395 LLVM_ABI static const char ID;
4396};
4397
4398/// An abstract interface for all nocapture attributes.
4400 : public IRAttribute<
4401 Attribute::Captures,
4402 StateWrapper<BitIntegerState<uint16_t, 7, 0>, AbstractAttribute>,
4403 AANoCapture> {
4405
4406 /// See IRAttribute::isImpliedByIR
4407 LLVM_ABI static bool isImpliedByIR(Attributor &A, const IRPosition &IRP,
4408 Attribute::AttrKind ImpliedAttributeKind,
4409 bool IgnoreSubsumingPositions = false);
4410
4411 /// Update \p State according to the capture capabilities of \p F for position
4412 /// \p IRP.
4413 LLVM_ABI static void
4415 BitIntegerState &State);
4416
4417 /// See AbstractAttribute::isValidIRPositionForInit
4419 if (!IRP.getAssociatedType()->isPointerTy())
4420 return false;
4421 return IRAttribute::isValidIRPositionForInit(A, IRP);
4422 }
4423
4424 /// State encoding bits. A set bit in the state means the property holds.
4425 /// NO_CAPTURE is the best possible state, 0 the worst possible state.
4426 enum {
4430
4431 /// If we do not capture the value in memory or through integers we can only
4432 /// communicate it back as a derived pointer.
4434
4435 /// If we do not capture the value in memory, through integers, or as a
4436 /// derived pointer we know it is not captured.
4437 NO_CAPTURE =
4439 };
4440
4441 /// Return true if we know that the underlying value is not captured in its
4442 /// respective scope.
4443 bool isKnownNoCapture() const { return isKnown(NO_CAPTURE); }
4444
4445 /// Return true if we assume that the underlying value is not captured in its
4446 /// respective scope.
4447 bool isAssumedNoCapture() const { return isAssumed(NO_CAPTURE); }
4448
4449 /// Return true if we know that the underlying value is not captured in its
4450 /// respective scope but we allow it to escape through a "return".
4453 }
4454
4455 /// Return true if we assume that the underlying value is not captured in its
4456 /// respective scope but we allow it to escape through a "return".
4459 }
4460
4461 /// Create an abstract attribute view for the position \p IRP.
4463 Attributor &A);
4464
4465 /// See AbstractAttribute::getName()
4466 StringRef getName() const override { return "AANoCapture"; }
4467
4468 /// See AbstractAttribute::getIdAddr()
4469 const char *getIdAddr() const override { return &ID; }
4470
4471 /// This function should return true if the type of the \p AA is AANoCapture
4472 static bool classof(const AbstractAttribute *AA) {
4473 return (AA->getIdAddr() == &ID);
4474 }
4475
4476 /// Unique ID (due to the unique address)
4477 LLVM_ABI static const char ID;
4478};
4479
4481
4483
4485 return ValueSimplifyStateType(Ty);
4486 }
4488 return getBestState(VS.Ty);
4489 }
4490
4491 /// Return the worst possible representable state.
4494 DS.indicatePessimisticFixpoint();
4495 return DS;
4496 }
4499 return getWorstState(VS.Ty);
4500 }
4501
4502 /// See AbstractState::isValidState(...)
4503 bool isValidState() const override { return BS.isValidState(); }
4504
4505 /// See AbstractState::isAtFixpoint(...)
4506 bool isAtFixpoint() const override { return BS.isAtFixpoint(); }
4507
4508 /// Return the assumed state encoding.
4510 const ValueSimplifyStateType &getAssumed() const { return *this; }
4511
4512 /// See AbstractState::indicatePessimisticFixpoint(...)
4515 }
4516
4517 /// See AbstractState::indicateOptimisticFixpoint(...)
4520 }
4521
4522 /// "Clamp" this state with \p PVS.
4524 BS ^= VS.BS;
4525 unionAssumed(VS.SimplifiedAssociatedValue);
4526 return *this;
4527 }
4528
4530 if (isValidState() != RHS.isValidState())
4531 return false;
4532 if (!isValidState() && !RHS.isValidState())
4533 return true;
4534 return SimplifiedAssociatedValue == RHS.SimplifiedAssociatedValue;
4535 }
4536
4537protected:
4538 /// The type of the original value.
4540
4541 /// Merge \p Other into the currently assumed simplified value
4542 LLVM_ABI bool unionAssumed(std::optional<Value *> Other);
4543
4544 /// Helper to track validity and fixpoint
4546
4547 /// An assumed simplified value. Initially, it is set to std::nullopt, which
4548 /// means that the value is not clear under current assumption. If in the
4549 /// pessimistic state, getAssumedSimplifiedValue doesn't return this value but
4550 /// returns orignal associated value.
4551 std::optional<Value *> SimplifiedAssociatedValue;
4552};
4553
4554/// An abstract interface for value simplify abstract attribute.
4556 : public StateWrapper<ValueSimplifyStateType, AbstractAttribute, Type *> {
4559 : Base(IRP, IRP.getAssociatedType()) {}
4560
4561 /// Create an abstract attribute view for the position \p IRP.
4563 Attributor &A);
4564
4565 /// See AbstractAttribute::getName()
4566 StringRef getName() const override { return "AAValueSimplify"; }
4567
4568 /// See AbstractAttribute::getIdAddr()
4569 const char *getIdAddr() const override { return &ID; }
4570
4571 /// This function should return true if the type of the \p AA is
4572 /// AAValueSimplify
4573 static bool classof(const AbstractAttribute *AA) {
4574 return (AA->getIdAddr() == &ID);
4575 }
4576
4577 /// Unique ID (due to the unique address)
4578 LLVM_ABI static const char ID;
4579
4580private:
4581 /// Return an assumed simplified value if a single candidate is found. If
4582 /// there cannot be one, return original value. If it is not clear yet, return
4583 /// std::nullopt.
4584 ///
4585 /// Use `Attributor::getAssumedSimplified` for value simplification.
4586 virtual std::optional<Value *>
4587 getAssumedSimplifiedValue(Attributor &A) const = 0;
4588
4589 friend struct Attributor;
4590};
4591
4592struct AAHeapToStack : public StateWrapper<BooleanState, AbstractAttribute> {
4594 AAHeapToStack(const IRPosition &IRP, Attributor &A) : Base(IRP) {}
4595
4596 /// Returns true if HeapToStack conversion is assumed to be possible.
4597 virtual bool isAssumedHeapToStack(const CallBase &CB) const = 0;
4598
4599 /// Returns true if HeapToStack conversion is assumed and the CB is a
4600 /// callsite to a free operation to be removed.
4601 virtual bool isAssumedHeapToStackRemovedFree(CallBase &CB) const = 0;
4602
4603 /// Create an abstract attribute view for the position \p IRP.
4605 Attributor &A);
4606
4607 /// See AbstractAttribute::getName()
4608 StringRef getName() const override { return "AAHeapToStack"; }
4609
4610 /// See AbstractAttribute::getIdAddr()
4611 const char *getIdAddr() const override { return &ID; }
4612
4613 /// This function should return true if the type of the \p AA is AAHeapToStack
4614 static bool classof(const AbstractAttribute *AA) {
4615 return (AA->getIdAddr() == &ID);
4616 }
4617
4618 /// Unique ID (due to the unique address)
4619 LLVM_ABI static const char ID;
4620};
4621
4622/// An abstract interface for privatizability.
4623///
4624/// A pointer is privatizable if it can be replaced by a new, private one.
4625/// Privatizing pointer reduces the use count, interaction between unrelated
4626/// code parts.
4627///
4628/// In order for a pointer to be privatizable its value cannot be observed
4629/// (=nocapture), it is (for now) not written (=readonly & noalias), we know
4630/// what values are necessary to make the private copy look like the original
4631/// one, and the values we need can be loaded (=dereferenceable).
4633 : public StateWrapper<BooleanState, AbstractAttribute> {
4636
4637 /// See AbstractAttribute::isValidIRPositionForInit
4640 return false;
4642 }
4643
4644 /// Returns true if pointer privatization is assumed to be possible.
4645 bool isAssumedPrivatizablePtr() const { return getAssumed(); }
4646
4647 /// Returns true if pointer privatization is known to be possible.
4648 bool isKnownPrivatizablePtr() const { return getKnown(); }
4649
4650 /// See AbstractAttribute::requiresCallersForArgOrFunction
4651 static bool requiresCallersForArgOrFunction() { return true; }
4652
4653 /// Return the type we can choose for a private copy of the underlying
4654 /// value. std::nullopt means it is not clear yet, nullptr means there is
4655 /// none.
4656 virtual std::optional<Type *> getPrivatizableType() const = 0;
4657
4658 /// Create an abstract attribute view for the position \p IRP.
4660 Attributor &A);
4661
4662 /// See AbstractAttribute::getName()
4663 StringRef getName() const override { return "AAPrivatizablePtr"; }
4664
4665 /// See AbstractAttribute::getIdAddr()
4666 const char *getIdAddr() const override { return &ID; }
4667
4668 /// This function should return true if the type of the \p AA is
4669 /// AAPricatizablePtr
4670 static bool classof(const AbstractAttribute *AA) {
4671 return (AA->getIdAddr() == &ID);
4672 }
4673
4674 /// Unique ID (due to the unique address)
4675 LLVM_ABI static const char ID;
4676};
4677
4678/// An abstract interface for memory access kind related attributes
4679/// (readnone/readonly/writeonly).
4681 : public IRAttribute<
4682 Attribute::None,
4683 StateWrapper<BitIntegerState<uint8_t, 3>, AbstractAttribute>,
4684 AAMemoryBehavior> {
4686
4687 /// See AbstractAttribute::hasTrivialInitializer.
4688 static bool hasTrivialInitializer() { return false; }
4689
4690 /// See AbstractAttribute::isValidIRPositionForInit
4692 if (!IRP.isFunctionScope() && !IRP.getAssociatedType()->isPointerTy())
4693 return false;
4694 return IRAttribute::isValidIRPositionForInit(A, IRP);
4695 }
4696
4697 /// State encoding bits. A set bit in the state means the property holds.
4698 /// BEST_STATE is the best possible state, 0 the worst possible state.
4699 enum {
4700 NO_READS = 1 << 0,
4701 NO_WRITES = 1 << 1,
4703
4705 };
4706 static_assert(BEST_STATE == getBestState(), "Unexpected BEST_STATE value");
4707
4708 /// Return true if we know that the underlying value is not read or accessed
4709 /// in its respective scope.
4710 bool isKnownReadNone() const { return isKnown(NO_ACCESSES); }
4711
4712 /// Return true if we assume that the underlying value is not read or accessed
4713 /// in its respective scope.
4714 bool isAssumedReadNone() const { return isAssumed(NO_ACCESSES); }
4715
4716 /// Return true if we know that the underlying value is not accessed
4717 /// (=written) in its respective scope.
4718 bool isKnownReadOnly() const { return isKnown(NO_WRITES); }
4719
4720 /// Return true if we assume that the underlying value is not accessed
4721 /// (=written) in its respective scope.
4722 bool isAssumedReadOnly() const { return isAssumed(NO_WRITES); }
4723
4724 /// Return true if we know that the underlying value is not read in its
4725 /// respective scope.
4726 bool isKnownWriteOnly() const { return isKnown(NO_READS); }
4727
4728 /// Return true if we assume that the underlying value is not read in its
4729 /// respective scope.
4730 bool isAssumedWriteOnly() const { return isAssumed(NO_READS); }
4731
4732 /// Create an abstract attribute view for the position \p IRP.
4734 Attributor &A);
4735
4736 /// See AbstractAttribute::getName()
4737 StringRef getName() const override { return "AAMemoryBehavior"; }
4738
4739 /// See AbstractAttribute::getIdAddr()
4740 const char *getIdAddr() const override { return &ID; }
4741
4742 /// This function should return true if the type of the \p AA is
4743 /// AAMemoryBehavior
4744 static bool classof(const AbstractAttribute *AA) {
4745 return (AA->getIdAddr() == &ID);
4746 }
4747
4748 /// Unique ID (due to the unique address)
4749 LLVM_ABI static const char ID;
4750};
4751
4752/// An abstract interface for all memory location attributes
4753/// (readnone/argmemonly/inaccessiblememonly/inaccessibleorargmemonly).
4755 : public IRAttribute<
4756 Attribute::None,
4757 StateWrapper<BitIntegerState<uint32_t, 511>, AbstractAttribute>,
4758 AAMemoryLocation> {
4760
4762
4763 /// See AbstractAttribute::requiresCalleeForCallBase.
4764 static bool requiresCalleeForCallBase() { return true; }
4765
4766 /// See AbstractAttribute::hasTrivialInitializer.
4767 static bool hasTrivialInitializer() { return false; }
4768
4769 /// See AbstractAttribute::isValidIRPositionForInit
4771 if (!IRP.isFunctionScope() &&
4773 return false;
4774 return IRAttribute::isValidIRPositionForInit(A, IRP);
4775 }
4776
4777 /// Encoding of different locations that could be accessed by a memory
4778 /// access.
4779 enum {
4793
4794 // Helper bit to track if we gave up or not.
4796
4798 };
4799 static_assert(BEST_STATE == getBestState(), "Unexpected BEST_STATE value");
4800
4801 /// Return true if we know that the associated functions has no observable
4802 /// accesses.
4803 bool isKnownReadNone() const { return isKnown(NO_LOCATIONS); }
4804
4805 /// Return true if we assume that the associated functions has no observable
4806 /// accesses.
4807 bool isAssumedReadNone() const {
4809 }
4810
4811 /// Return true if we know that the associated functions has at most
4812 /// local/stack accesses.
4813 bool isKnowStackOnly() const {
4814 return isKnown(inverseLocation(NO_LOCAL_MEM, true, true));
4815 }
4816
4817 /// Return true if we assume that the associated functions has at most
4818 /// local/stack accesses.
4819 bool isAssumedStackOnly() const {
4820 return isAssumed(inverseLocation(NO_LOCAL_MEM, true, true));
4821 }
4822
4823 /// Return true if we know that the underlying value will only access
4824 /// inaccesible memory only (see Attribute::InaccessibleMemOnly).
4826 return isKnown(inverseLocation(NO_INACCESSIBLE_MEM, true, true));
4827 }
4828
4829 /// Return true if we assume that the underlying value will only access
4830 /// inaccesible memory only (see Attribute::InaccessibleMemOnly).
4832 return isAssumed(inverseLocation(NO_INACCESSIBLE_MEM, true, true));
4833 }
4834
4835 /// Return true if we know that the underlying value will only access
4836 /// argument pointees (see Attribute::ArgMemOnly).
4837 bool isKnownArgMemOnly() const {
4838 return isKnown(inverseLocation(NO_ARGUMENT_MEM, true, true));
4839 }
4840
4841 /// Return true if we assume that the underlying value will only access
4842 /// argument pointees (see Attribute::ArgMemOnly).
4843 bool isAssumedArgMemOnly() const {
4844 return isAssumed(inverseLocation(NO_ARGUMENT_MEM, true, true));
4845 }
4846
4847 /// Return true if we know that the underlying value will only access
4848 /// inaccesible memory or argument pointees (see
4849 /// Attribute::InaccessibleOrArgMemOnly).
4851 return isKnown(
4853 }
4854
4855 /// Return true if we assume that the underlying value will only access
4856 /// inaccesible memory or argument pointees (see
4857 /// Attribute::InaccessibleOrArgMemOnly).
4859 return isAssumed(
4861 }
4862
4863 /// Return true if the underlying value may access memory through arguement
4864 /// pointers of the associated function, if any.
4865 bool mayAccessArgMem() const { return !isAssumed(NO_ARGUMENT_MEM); }
4866
4867 /// Return true if only the memory locations specififed by \p MLK are assumed
4868 /// to be accessed by the associated function.
4870 return isAssumed(MLK);
4871 }
4872
4873 /// Return the locations that are assumed to be not accessed by the associated
4874 /// function, if any.
4876 return getAssumed();
4877 }
4878
4879 /// Return the inverse of location \p Loc, thus for NO_XXX the return
4880 /// describes ONLY_XXX. The flags \p AndLocalMem and \p AndConstMem determine
4881 /// if local (=stack) and constant memory are allowed as well. Most of the
4882 /// time we do want them to be included, e.g., argmemonly allows accesses via
4883 /// argument pointers or local or constant memory accesses.
4884 static MemoryLocationsKind
4885 inverseLocation(MemoryLocationsKind Loc, bool AndLocalMem, bool AndConstMem) {
4886 return NO_LOCATIONS & ~(Loc | (AndLocalMem ? NO_LOCAL_MEM : 0) |
4887 (AndConstMem ? NO_CONST_MEM : 0));
4888 };
4889
4890 /// Return the locations encoded by \p MLK as a readable string.
4892
4893 /// Simple enum to distinguish read/write/read-write accesses.
4895 NONE = 0,
4896 READ = 1 << 0,
4897 WRITE = 1 << 1,
4899 };
4900
4901 /// Check \p Pred on all accesses to the memory kinds specified by \p MLK.
4902 ///
4903 /// This method will evaluate \p Pred on all accesses (access instruction +
4904 /// underlying accessed memory pointer) and it will return true if \p Pred
4905 /// holds every time.
4907 function_ref<bool(const Instruction *, const Value *, AccessKind,
4909 Pred,
4910 MemoryLocationsKind MLK) const = 0;
4911
4912 /// Create an abstract attribute view for the position \p IRP.
4914 Attributor &A);
4915
4916 /// See AbstractState::getAsStr(Attributor).
4917 const std::string getAsStr(Attributor *A) const override {
4919 }
4920
4921 /// See AbstractAttribute::getName()
4922 StringRef getName() const override { return "AAMemoryLocation"; }
4923
4924 /// See AbstractAttribute::getIdAddr()
4925 const char *getIdAddr() const override { return &ID; }
4926
4927 /// This function should return true if the type of the \p AA is
4928 /// AAMemoryLocation
4929 static bool classof(const AbstractAttribute *AA) {
4930 return (AA->getIdAddr() == &ID);
4931 }
4932
4933 /// Unique ID (due to the unique address)
4934 LLVM_ABI static const char ID;
4935};
4936
4937/// An abstract interface for range value analysis.
4939 : public StateWrapper<IntegerRangeState, AbstractAttribute, uint32_t> {
4942 : Base(IRP, IRP.getAssociatedType()->getIntegerBitWidth()) {}
4943
4944 /// See AbstractAttribute::isValidIRPositionForInit
4946 if (!IRP.getAssociatedType()->isIntegerTy())
4947 return false;
4949 }
4950
4951 /// See AbstractAttribute::requiresCallersForArgOrFunction
4952 static bool requiresCallersForArgOrFunction() { return true; }
4953
4954 /// See AbstractAttribute::getState(...).
4955 IntegerRangeState &getState() override { return *this; }
4956 const IntegerRangeState &getState() const override { return *this; }
4957
4958 /// Create an abstract attribute view for the position \p IRP.
4960 Attributor &A);
4961
4962 /// Return an assumed range for the associated value a program point \p CtxI.
4963 /// If \p I is nullptr, simply return an assumed range.
4964 virtual ConstantRange
4966 const Instruction *CtxI = nullptr) const = 0;
4967
4968 /// Return a known range for the associated value at a program point \p CtxI.
4969 /// If \p I is nullptr, simply return a known range.
4970 virtual ConstantRange
4972 const Instruction *CtxI = nullptr) const = 0;
4973
4974 /// Return an assumed constant for the associated value a program point \p
4975 /// CtxI.
4976 std::optional<Constant *>
4977 getAssumedConstant(Attributor &A, const Instruction *CtxI = nullptr) const {
4978 ConstantRange RangeV = getAssumedConstantRange(A, CtxI);
4979 if (auto *C = RangeV.getSingleElement()) {
4981 return cast_or_null<Constant>(
4982 AA::getWithType(*ConstantInt::get(Ty->getContext(), *C), *Ty));
4983 }
4984 if (RangeV.isEmptySet())
4985 return std::nullopt;
4986 return nullptr;
4987 }
4988
4989 /// See AbstractAttribute::getName()
4990 StringRef getName() const override { return "AAValueConstantRange"; }
4991
4992 /// See AbstractAttribute::getIdAddr()
4993 const char *getIdAddr() const override { return &ID; }
4994
4995 /// This function should return true if the type of the \p AA is
4996 /// AAValueConstantRange
4997 static bool classof(const AbstractAttribute *AA) {
4998 return (AA->getIdAddr() == &ID);
4999 }
5000
5001 /// Unique ID (due to the unique address)
5002 LLVM_ABI static const char ID;
5003};
5004
5005/// A class for a set state.
5006/// The assumed boolean state indicates whether the corresponding set is full
5007/// set or not. If the assumed state is false, this is the worst state. The
5008/// worst state (invalid state) of set of potential values is when the set
5009/// contains every possible value (i.e. we cannot in any way limit the value
5010/// that the target position can take). That never happens naturally, we only
5011/// force it. As for the conditions under which we force it, see
5012/// AAPotentialConstantValues.
5013template <typename MemberTy> struct PotentialValuesState : AbstractState {
5015
5016 PotentialValuesState() : IsValidState(true), UndefIsContained(false) {}
5017
5019 : IsValidState(IsValid), UndefIsContained(false) {}
5020
5021 /// See AbstractState::isValidState(...)
5022 bool isValidState() const override { return IsValidState.isValidState(); }
5023
5024 /// See AbstractState::isAtFixpoint(...)
5025 bool isAtFixpoint() const override { return IsValidState.isAtFixpoint(); }
5026
5027 /// See AbstractState::indicatePessimisticFixpoint(...)
5029 return IsValidState.indicatePessimisticFixpoint();
5030 }
5031
5032 /// See AbstractState::indicateOptimisticFixpoint(...)
5034 return IsValidState.indicateOptimisticFixpoint();
5035 }
5036
5037 /// Return the assumed state
5039 const PotentialValuesState &getAssumed() const { return *this; }
5040
5041 /// Return this set. We should check whether this set is valid or not by
5042 /// isValidState() before calling this function.
5043 const SetTy &getAssumedSet() const {
5044 assert(isValidState() && "This set shoud not be used when it is invalid!");
5045 return Set;
5046 }
5047
5048 /// Returns whether this state contains an undef value or not.
5049 bool undefIsContained() const {
5050 assert(isValidState() && "This flag shoud not be used when it is invalid!");
5051 return UndefIsContained;
5052 }
5053
5055 if (isValidState() != RHS.isValidState())
5056 return false;
5057 if (!isValidState() && !RHS.isValidState())
5058 return true;
5059 if (undefIsContained() != RHS.undefIsContained())
5060 return false;
5061 return Set == RHS.getAssumedSet();
5062 }
5063
5064 /// Maximum number of potential values to be tracked.
5065 /// This is set by -attributor-max-potential-values command line option
5066 static unsigned MaxPotentialValues;
5067
5068 /// Return empty set as the best state of potential values.
5070 return PotentialValuesState(true);
5071 }
5072
5074 return getBestState();
5075 }
5076
5077 /// Return full set as the worst state of potential values.
5079 return PotentialValuesState(false);
5080 }
5081
5082 /// Union assumed set with the passed value.
5083 void unionAssumed(const MemberTy &C) { insert(C); }
5084
5085 /// Union assumed set with assumed set of the passed state \p PVS.
5086 void unionAssumed(const PotentialValuesState &PVS) { unionWith(PVS); }
5087
5088 /// Union assumed set with an undef value.
5089 void unionAssumedWithUndef() { unionWithUndef(); }
5090
5091 /// "Clamp" this state with \p PVS.
5093 IsValidState ^= PVS.IsValidState;
5094 unionAssumed(PVS);
5095 return *this;
5096 }
5097
5099 IsValidState &= PVS.IsValidState;
5100 unionAssumed(PVS);
5101 return *this;
5102 }
5103
5104 bool contains(const MemberTy &V) const {
5105 return !isValidState() ? true : Set.contains(V);
5106 }
5107
5108protected:
5110 assert(isValidState() && "This set shoud not be used when it is invalid!");
5111 return Set;
5112 }
5113
5114private:
5115 /// Check the size of this set, and invalidate when the size is no
5116 /// less than \p MaxPotentialValues threshold.
5117 void checkAndInvalidate() {
5118 if (Set.size() >= MaxPotentialValues)
5120 else
5121 reduceUndefValue();
5122 }
5123
5124 /// If this state contains both undef and not undef, we can reduce
5125 /// undef to the not undef value.
5126 void reduceUndefValue() { UndefIsContained = UndefIsContained & Set.empty(); }
5127
5128 /// Insert an element into this set.
5129 void insert(const MemberTy &C) {
5130 if (!isValidState())
5131 return;
5132 Set.insert(C);
5133 checkAndInvalidate();
5134 }
5135
5136 /// Take union with R.
5137 void unionWith(const PotentialValuesState &R) {
5138 /// If this is a full set, do nothing.
5139 if (!isValidState())
5140 return;
5141 /// If R is full set, change L to a full set.
5142 if (!R.isValidState()) {
5144 return;
5145 }
5146 Set.insert_range(R.Set);
5147 UndefIsContained |= R.undefIsContained();
5148 checkAndInvalidate();
5149 }
5150
5151 /// Take union with an undef value.
5152 void unionWithUndef() {
5153 UndefIsContained = true;
5154 reduceUndefValue();
5155 }
5156
5157 /// Take intersection with R.
5158 void intersectWith(const PotentialValuesState &R) {
5159 /// If R is a full set, do nothing.
5160 if (!R.isValidState())
5161 return;
5162 /// If this is a full set, change this to R.
5163 if (!isValidState()) {
5164 *this = R;
5165 return;
5166 }
5167 SetTy IntersectSet;
5168 for (const MemberTy &C : Set) {
5169 if (R.Set.count(C))
5170 IntersectSet.insert(C);
5171 }
5172 Set = IntersectSet;
5173 UndefIsContained &= R.undefIsContained();
5174 reduceUndefValue();
5175 }
5176
5177 /// A helper state which indicate whether this state is valid or not.
5178 BooleanState IsValidState;
5179
5180 /// Container for potential values
5181 SetTy Set;
5182
5183 /// Flag for undef value
5184 bool UndefIsContained;
5185};
5186
5191
5192 bool operator==(const DenormalState Other) const {
5193 return Mode == Other.Mode && ModeF32 == Other.ModeF32;
5194 }
5195
5196 bool operator!=(const DenormalState Other) const {
5197 return Mode != Other.Mode || ModeF32 != Other.ModeF32;
5198 }
5199
5200 bool isValid() const { return Mode.isValid() && ModeF32.isValid(); }
5201
5205 if (Caller == Callee)
5206 return Caller;
5207 if (Callee == DenormalMode::Dynamic)
5208 return Caller;
5209 if (Caller == DenormalMode::Dynamic)
5210 return Callee;
5211 return DenormalMode::Invalid;
5212 }
5213
5215 return DenormalMode{unionDenormalKind(Callee.Output, Caller.Output),
5216 unionDenormalKind(Callee.Input, Caller.Input)};
5217 }
5218
5220 DenormalState Callee(*this);
5221 Callee.Mode = unionAssumed(Callee.Mode, Caller.Mode);
5222 Callee.ModeF32 = unionAssumed(Callee.ModeF32, Caller.ModeF32);
5223 return Callee;
5224 }
5225 };
5226
5228
5229 /// Explicitly track whether we've hit a fixed point.
5230 bool IsAtFixedpoint = false;
5231
5233
5234 DenormalState getKnown() const { return Known; }
5235
5236 // There's only really known or unknown, there's no speculatively assumable
5237 // state.
5238 DenormalState getAssumed() const { return Known; }
5239
5240 bool isValidState() const override { return Known.isValid(); }
5241
5242 /// Return true if there are no dynamic components to the denormal mode worth
5243 /// specializing.
5244 bool isModeFixed() const {
5249 }
5250
5251 bool isAtFixpoint() const override { return IsAtFixedpoint; }
5252
5254 bool Changed = !IsAtFixedpoint;
5255 IsAtFixedpoint = true;
5257 }
5258
5260 return indicateFixpoint();
5261 }
5262
5264 return indicateFixpoint();
5265 }
5266
5268 Known = Known.unionWith(Caller.getKnown());
5269 return *this;
5270 }
5271};
5272
5276
5280 const PotentialLLVMValuesState &R);
5281
5282/// An abstract interface for potential values analysis.
5283///
5284/// This AA collects potential values for each IR position.
5285/// An assumed set of potential values is initialized with the empty set (the
5286/// best state) and it will grow monotonically as we find more potential values
5287/// for this position.
5288/// The set might be forced to the worst state, that is, to contain every
5289/// possible value for this position in 2 cases.
5290/// 1. We surpassed the \p MaxPotentialValues threshold. This includes the
5291/// case that this position is affected (e.g. because of an operation) by a
5292/// Value that is in the worst state.
5293/// 2. We tried to initialize on a Value that we cannot handle (e.g. an
5294/// operator we do not currently handle).
5295///
5296/// For non constant integers see AAPotentialValues.
5298 : public StateWrapper<PotentialConstantIntValuesState, AbstractAttribute> {
5301
5302 /// See AbstractAttribute::isValidIRPositionForInit
5304 if (!IRP.getAssociatedType()->isIntegerTy())
5305 return false;
5307 }
5308
5309 /// See AbstractAttribute::requiresCallersForArgOrFunction
5310 static bool requiresCallersForArgOrFunction() { return true; }
5311
5312 /// See AbstractAttribute::getState(...).
5313 PotentialConstantIntValuesState &getState() override { return *this; }
5315 return *this;
5316 }
5317
5318 /// Create an abstract attribute view for the position \p IRP.
5321
5322 /// Return assumed constant for the associated value
5323 std::optional<Constant *>
5324 getAssumedConstant(Attributor &A, const Instruction *CtxI = nullptr) const {
5325 if (!isValidState())
5326 return nullptr;
5327 if (getAssumedSet().size() == 1) {
5329 return cast_or_null<Constant>(AA::getWithType(
5330 *ConstantInt::get(Ty->getContext(), *(getAssumedSet().begin())),
5331 *Ty));
5332 }
5333 if (getAssumedSet().size() == 0) {
5334 if (undefIsContained())
5336 return std::nullopt;
5337 }
5338
5339 return nullptr;
5340 }
5341
5342 /// See AbstractAttribute::getName()
5343 StringRef getName() const override { return "AAPotentialConstantValues"; }
5344
5345 /// See AbstractAttribute::getIdAddr()
5346 const char *getIdAddr() const override { return &ID; }
5347
5348 /// This function should return true if the type of the \p AA is
5349 /// AAPotentialConstantValues
5350 static bool classof(const AbstractAttribute *AA) {
5351 return (AA->getIdAddr() == &ID);
5352 }
5353
5354 /// Unique ID (due to the unique address)
5355 LLVM_ABI static const char ID;
5356};
5357
5359 : public StateWrapper<PotentialLLVMValuesState, AbstractAttribute> {
5362
5363 /// See AbstractAttribute::requiresCallersForArgOrFunction
5364 static bool requiresCallersForArgOrFunction() { return true; }
5365
5366 /// See AbstractAttribute::getState(...).
5367 PotentialLLVMValuesState &getState() override { return *this; }
5368 const PotentialLLVMValuesState &getState() const override { return *this; }
5369
5370 /// Create an abstract attribute view for the position \p IRP.
5372 Attributor &A);
5373
5374 /// Extract the single value in \p Values if any.
5375 LLVM_ABI static Value *
5377 const IRPosition &IRP,
5379
5380 /// See AbstractAttribute::getName()
5381 StringRef getName() const override { return "AAPotentialValues"; }
5382
5383 /// See AbstractAttribute::getIdAddr()
5384 const char *getIdAddr() const override { return &ID; }
5385
5386 /// This function should return true if the type of the \p AA is
5387 /// AAPotentialValues
5388 static bool classof(const AbstractAttribute *AA) {
5389 return (AA->getIdAddr() == &ID);
5390 }
5391
5392 /// Unique ID (due to the unique address)
5393 LLVM_ABI static const char ID;
5394
5395private:
5396 virtual bool getAssumedSimplifiedValues(
5398 AA::ValueScope, bool RecurseForSelectAndPHI = false) const = 0;
5399
5400 friend struct Attributor;
5401};
5402
5403/// An abstract interface for all noundef attributes.
5405 : public IRAttribute<Attribute::NoUndef,
5406 StateWrapper<BooleanState, AbstractAttribute>,
5407 AANoUndef> {
5409
5410 /// See IRAttribute::isImpliedByUndef
5411 static bool isImpliedByUndef() { return false; }
5412
5413 /// See IRAttribute::isImpliedByPoison
5414 static bool isImpliedByPoison() { return false; }
5415
5416 /// See IRAttribute::isImpliedByIR
5417 LLVM_ABI static bool isImpliedByIR(Attributor &A, const IRPosition &IRP,
5418 Attribute::AttrKind ImpliedAttributeKind,
5419 bool IgnoreSubsumingPositions = false);
5420
5421 /// Return true if we assume that the underlying value is noundef.
5422 bool isAssumedNoUndef() const { return getAssumed(); }
5423
5424 /// Return true if we know that underlying value is noundef.
5425 bool isKnownNoUndef() const { return getKnown(); }
5426
5427 /// Create an abstract attribute view for the position \p IRP.
5429 Attributor &A);
5430
5431 /// See AbstractAttribute::getName()
5432 StringRef getName() const override { return "AANoUndef"; }
5433
5434 /// See AbstractAttribute::getIdAddr()
5435 const char *getIdAddr() const override { return &ID; }
5436
5437 /// This function should return true if the type of the \p AA is AANoUndef
5438 static bool classof(const AbstractAttribute *AA) {
5439 return (AA->getIdAddr() == &ID);
5440 }
5441
5442 /// Unique ID (due to the unique address)
5443 LLVM_ABI static const char ID;
5444};
5445
5447 : public IRAttribute<
5448 Attribute::NoFPClass,
5449 StateWrapper<BitIntegerState<uint32_t, fcAllFlags, fcNone>,
5450 AbstractAttribute>,
5451 AANoFPClass> {
5454
5456
5457 /// See AbstractAttribute::isValidIRPositionForInit
5459 Type *Ty = IRP.getAssociatedType();
5460 do {
5461 if (Ty->isFPOrFPVectorTy())
5462 return IRAttribute::isValidIRPositionForInit(A, IRP);
5463 if (!Ty->isArrayTy())
5464 break;
5465 Ty = Ty->getArrayElementType();
5466 } while (true);
5467 return false;
5468 }
5469
5470 /// Return the underlying assumed nofpclass.
5472 return static_cast<FPClassTest>(getAssumed());
5473 }
5474 /// Return the underlying known nofpclass.
5476 return static_cast<FPClassTest>(getKnown());
5477 }
5478
5479 /// Create an abstract attribute view for the position \p IRP.
5481 Attributor &A);
5482
5483 /// See AbstractAttribute::getName()
5484 StringRef getName() const override { return "AANoFPClass"; }
5485
5486 /// See AbstractAttribute::getIdAddr()
5487 const char *getIdAddr() const override { return &ID; }
5488
5489 /// This function should return true if the type of the \p AA is AANoFPClass
5490 static bool classof(const AbstractAttribute *AA) {
5491 return (AA->getIdAddr() == &ID);
5492 }
5493
5494 /// Unique ID (due to the unique address)
5495 LLVM_ABI static const char ID;
5496};
5497
5498struct AACallGraphNode;
5499struct AACallEdges;
5500
5501/// An Iterator for call edges, creates AACallEdges attributes in a lazy way.
5502/// This iterator becomes invalid if the underlying edge list changes.
5503/// So This shouldn't outlive a iteration of Attributor.
5505 : public iterator_adaptor_base<AACallEdgeIterator,
5506 SetVector<Function *>::iterator> {
5508 : iterator_adaptor_base(Begin), A(A) {}
5509
5510public:
5512
5513private:
5514 Attributor &A;
5515 friend AACallEdges;
5516 friend AttributorCallGraph;
5517};
5518
5521 virtual ~AACallGraphNode() = default;
5522
5525
5526 /// Iterator range for exploring the call graph.
5530 }
5531
5532protected:
5533 /// Reference to Attributor needed for GraphTraits implementation.
5535};
5536
5537/// An abstract state for querying live call edges.
5538/// This interface uses the Attributor's optimistic liveness
5539/// information to compute the edges that are alive.
5540struct AACallEdges : public StateWrapper<BooleanState, AbstractAttribute>,
5543
5545 : Base(IRP), AACallGraphNode(A) {}
5546
5547 /// See AbstractAttribute::requiresNonAsmForCallBase.
5548 static bool requiresNonAsmForCallBase() { return false; }
5549
5550 /// Get the optimistic edges.
5551 virtual const SetVector<Function *> &getOptimisticEdges() const = 0;
5552
5553 /// Is there any call with a unknown callee.
5554 virtual bool hasUnknownCallee() const = 0;
5555
5556 /// Is there any call with a unknown callee, excluding any inline asm.
5557 virtual bool hasNonAsmUnknownCallee() const = 0;
5558
5559 /// Iterator for exploring the call graph.
5562 }
5563
5564 /// Iterator for exploring the call graph.
5567 }
5568
5569 /// Create an abstract attribute view for the position \p IRP.
5571 Attributor &A);
5572
5573 /// See AbstractAttribute::getName()
5574 StringRef getName() const override { return "AACallEdges"; }
5575
5576 /// See AbstractAttribute::getIdAddr()
5577 const char *getIdAddr() const override { return &ID; }
5578
5579 /// This function should return true if the type of the \p AA is AACallEdges.
5580 static bool classof(const AbstractAttribute *AA) {
5581 return (AA->getIdAddr() == &ID);
5582 }
5583
5584 /// Unique ID (due to the unique address)
5585 LLVM_ABI static const char ID;
5586};
5587
5588// Synthetic root node for the Attributor's internal call graph.
5591 virtual ~AttributorCallGraph() = default;
5592
5594 return AACallEdgeIterator(A, A.Functions.begin());
5595 }
5596
5598 return AACallEdgeIterator(A, A.Functions.end());
5599 }
5600
5601 /// Force populate the entire call graph.
5602 void populateAll() const {
5603 for (const AACallGraphNode *AA : optimisticEdgesRange()) {
5604 // Nothing else to do here.
5605 (void)AA;
5606 }
5607 }
5608
5609 LLVM_ABI void print();
5610};
5611
5612template <> struct GraphTraits<AACallGraphNode *> {
5615
5617 return Node->optimisticEdgesBegin();
5618 }
5619
5621 return Node->optimisticEdgesEnd();
5622 }
5623};
5624
5625template <>
5629
5631 return static_cast<AACallGraphNode *>(G);
5632 }
5633
5635 return G->optimisticEdgesBegin();
5636 }
5637
5639 return G->optimisticEdgesEnd();
5640 }
5641};
5642
5643template <>
5646
5648 const AttributorCallGraph *Graph) {
5649 const AACallEdges *AACE = static_cast<const AACallEdges *>(Node);
5650 return AACE->getAssociatedFunction()->getName().str();
5651 }
5652
5654 const AttributorCallGraph *Graph) {
5655 // Hide the synth root.
5656 return static_cast<const AACallGraphNode *>(Graph) == Node;
5657 }
5658};
5659
5661 : public StateWrapper<BooleanState, AbstractAttribute> {
5664
5665 /// Summary about the execution domain of a block or instruction.
5669
5672 }
5673
5676 }
5677
5681 }
5682
5689 };
5690
5691 /// Create an abstract attribute view for the position \p IRP.
5693 Attributor &A);
5694
5695 /// See AbstractAttribute::getName().
5696 StringRef getName() const override { return "AAExecutionDomain"; }
5697
5698 /// See AbstractAttribute::getIdAddr().
5699 const char *getIdAddr() const override { return &ID; }
5700
5701 /// Check if an instruction is executed only by the initial thread.
5703 return isExecutedByInitialThreadOnly(*I.getParent());
5704 }
5705
5706 /// Check if a basic block is executed only by the initial thread.
5707 virtual bool isExecutedByInitialThreadOnly(const BasicBlock &) const = 0;
5708
5709 /// Check if the instruction \p I is executed in an aligned region, that is,
5710 /// the synchronizing effects before and after \p I are both aligned barriers.
5711 /// This effectively means all threads execute \p I together.
5713 const Instruction &I) const = 0;
5714
5716 /// Return the execution domain with which the call \p CB is entered and the
5717 /// one with which it is left.
5718 virtual std::pair<ExecutionDomainTy, ExecutionDomainTy>
5719 getExecutionDomain(const CallBase &CB) const = 0;
5721
5722 /// Helper function to determine if \p FI is a no-op given the information
5723 /// about its execution from \p ExecDomainAA.
5724 virtual bool isNoOpFence(const FenceInst &FI) const = 0;
5725
5726 /// This function should return true if the type of the \p AA is
5727 /// AAExecutionDomain.
5728 static bool classof(const AbstractAttribute *AA) {
5729 return (AA->getIdAddr() == &ID);
5730 }
5731
5732 /// Unique ID (due to the unique address)
5733 LLVM_ABI static const char ID;
5734};
5735
5736/// An abstract Attribute for computing reachability between functions.
5738 : public StateWrapper<BooleanState, AbstractAttribute> {
5740
5742
5743 /// If the function represented by this possition can reach \p Fn.
5744 bool canReach(Attributor &A, const Function &Fn) const {
5745 Function *Scope = getAnchorScope();
5746 if (!Scope || Scope->isDeclaration())
5747 return true;
5748 return instructionCanReach(A, Scope->getEntryBlock().front(), Fn);
5749 }
5750
5751 /// Can \p Inst reach \p Fn.
5752 /// See also AA::isPotentiallyReachable.
5754 Attributor &A, const Instruction &Inst, const Function &Fn,
5755 const AA::InstExclusionSetTy *ExclusionSet = nullptr) const = 0;
5756
5757 /// Create an abstract attribute view for the position \p IRP.
5760
5761 /// See AbstractAttribute::getName()
5762 StringRef getName() const override { return "AAInterFnReachability"; }
5763
5764 /// See AbstractAttribute::getIdAddr()
5765 const char *getIdAddr() const override { return &ID; }
5766
5767 /// This function should return true if the type of the \p AA is AACallEdges.
5768 static bool classof(const AbstractAttribute *AA) {
5769 return (AA->getIdAddr() == &ID);
5770 }
5771
5772 /// Unique ID (due to the unique address)
5773 LLVM_ABI static const char ID;
5774};
5775
5776/// An abstract Attribute for determining the necessity of the convergent
5777/// attribute.
5778struct AANonConvergent : public StateWrapper<BooleanState, AbstractAttribute> {
5780
5782
5783 /// Create an abstract attribute view for the position \p IRP.
5785 Attributor &A);
5786
5787 /// Return true if "non-convergent" is assumed.
5788 bool isAssumedNotConvergent() const { return getAssumed(); }
5789
5790 /// Return true if "non-convergent" is known.
5791 bool isKnownNotConvergent() const { return getKnown(); }
5792
5793 /// See AbstractAttribute::getName()
5794 StringRef getName() const override { return "AANonConvergent"; }
5795
5796 /// See AbstractAttribute::getIdAddr()
5797 const char *getIdAddr() const override { return &ID; }
5798
5799 /// This function should return true if the type of the \p AA is
5800 /// AANonConvergent.
5801 static bool classof(const AbstractAttribute *AA) {
5802 return (AA->getIdAddr() == &ID);
5803 }
5804
5805 /// Unique ID (due to the unique address)
5806 LLVM_ABI static const char ID;
5807};
5808
5809/// An abstract interface for struct information.
5812
5813 /// See AbstractAttribute::isValidIRPositionForInit
5816 return false;
5818 }
5819
5821 // First two bits to distinguish may and must accesses.
5822 AK_MUST = 1 << 0,
5823 AK_MAY = 1 << 1,
5824
5825 // Then two bits for read and write. These are not exclusive.
5826 AK_R = 1 << 2,
5827 AK_W = 1 << 3,
5829
5830 // One special case for assumptions about memory content. These
5831 // are neither reads nor writes. They are however always modeled
5832 // as read to avoid using them for write removal.
5834
5835 // Helper for easy access.
5842 };
5843
5844 /// A helper containing a list of offsets computed for a Use. Ideally this
5845 /// list should be strictly ascending, but we ensure that only when we
5846 /// actually translate the list of offsets to a RangeList.
5847 struct OffsetInfo {
5851
5852 const_iterator begin() const { return Offsets.begin(); }
5853 const_iterator end() const { return Offsets.end(); }
5854
5855 bool operator==(const OffsetInfo &RHS) const {
5856 return Offsets == RHS.Offsets;
5857 }
5858
5859 bool operator!=(const OffsetInfo &RHS) const { return !(*this == RHS); }
5860
5861 bool insert(int64_t Offset) { return Offsets.insert(Offset).second; }
5862 bool isUnassigned() const { return Offsets.size() == 0; }
5863
5864 bool isUnknown() const {
5865 if (isUnassigned())
5866 return false;
5867 if (Offsets.size() == 1)
5868 return *Offsets.begin() == AA::RangeTy::Unknown;
5869 return false;
5870 }
5871
5872 void setUnknown() {
5873 Offsets.clear();
5875 }
5876
5877 void addToAll(int64_t Inc) {
5878 VecTy NewOffsets;
5879 for (auto &Offset : Offsets)
5880 NewOffsets.insert(Offset + Inc);
5881 Offsets = std::move(NewOffsets);
5882 }
5883
5884 /// Copy offsets from \p R into the current list.
5885 ///
5886 /// Ideally all lists should be strictly ascending, but we defer that to the
5887 /// actual use of the list. So we just blindly append here.
5888 bool merge(const OffsetInfo &R) { return set_union(Offsets, R.Offsets); }
5889 };
5890
5891 /// A container for a list of ranges.
5892 struct RangeList {
5893 // The set of ranges rarely contains more than one element, and is unlikely
5894 // to contain more than say four elements. So we find the middle-ground with
5895 // a sorted vector. This avoids hard-coding a rarely used number like "four"
5896 // into every instance of a SmallSet.
5902
5905 Ranges.reserve(Offsets.size());
5906 for (unsigned i = 0, e = Offsets.size(); i != e; ++i) {
5907 assert(((i + 1 == e) || Offsets[i] < Offsets[i + 1]) &&
5908 "Expected strictly ascending offsets.");
5909 Ranges.emplace_back(Offsets[i], Size);
5910 }
5911 }
5912 RangeList() = default;
5913
5914 iterator begin() { return Ranges.begin(); }
5915 iterator end() { return Ranges.end(); }
5916 const_iterator begin() const { return Ranges.begin(); }
5917 const_iterator end() const { return Ranges.end(); }
5918
5919 // Helpers required for std::set_difference
5921 void push_back(const RangeTy &R) {
5923 "Ensure the last element is the greatest.");
5924 Ranges.push_back(R);
5925 }
5926
5927 /// Copy ranges from \p L that are not in \p R, into \p D.
5928 static void set_difference(const RangeList &L, const RangeList &R,
5929 RangeList &D) {
5930 std::set_difference(L.begin(), L.end(), R.begin(), R.end(),
5931 std::back_inserter(D), RangeTy::LessThan);
5932 }
5933
5934 unsigned size() const { return Ranges.size(); }
5935
5936 bool operator==(const RangeList &OI) const { return Ranges == OI.Ranges; }
5937
5938 /// Merge the ranges in \p RHS into the current ranges.
5939 /// - Merging a list of unknown ranges makes the current list unknown.
5940 /// - Ranges with the same offset are merged according to RangeTy::operator&
5941 /// \return true if the current RangeList changed.
5942 bool merge(const RangeList &RHS) {
5943 if (isUnknown())
5944 return false;
5945 if (RHS.isUnknown()) {
5946 setUnknown();
5947 return true;
5948 }
5949
5950 if (Ranges.empty()) {
5951 Ranges = RHS.Ranges;
5952 return true;
5953 }
5954
5955 bool Changed = false;
5956 auto LPos = Ranges.begin();
5957 for (auto &R : RHS.Ranges) {
5958 auto Result = insert(LPos, R);
5959 if (isUnknown())
5960 return true;
5961 LPos = Result.first;
5962 Changed |= Result.second;
5963 }
5964 return Changed;
5965 }
5966
5967 /// Insert \p R at the given iterator \p Pos, and merge if necessary.
5968 ///
5969 /// This assumes that all ranges before \p Pos are LessThan \p R, and
5970 /// then maintains the sorted order for the suffix list.
5971 ///
5972 /// \return The place of insertion and true iff anything changed.
5973 std::pair<iterator, bool> insert(iterator Pos, const RangeTy &R) {
5974 if (isUnknown())
5975 return std::make_pair(Ranges.begin(), false);
5976 if (R.offsetOrSizeAreUnknown()) {
5977 return std::make_pair(setUnknown(), true);
5978 }
5979
5980 // Maintain this as a sorted vector of unique entries.
5981 auto LB = std::lower_bound(Pos, Ranges.end(), R, RangeTy::LessThan);
5982 if (LB == Ranges.end() || LB->Offset != R.Offset)
5983 return std::make_pair(Ranges.insert(LB, R), true);
5984 bool Changed = *LB != R;
5985 *LB &= R;
5986 if (LB->offsetOrSizeAreUnknown())
5987 return std::make_pair(setUnknown(), true);
5988 return std::make_pair(LB, Changed);
5989 }
5990
5991 /// Insert the given range \p R, maintaining sorted order.
5992 ///
5993 /// \return The place of insertion and true iff anything changed.
5994 std::pair<iterator, bool> insert(const RangeTy &R) {
5995 return insert(Ranges.begin(), R);
5996 }
5997
5998 /// Add the increment \p Inc to the offset of every range.
5999 void addToAllOffsets(int64_t Inc) {
6000 assert(!isUnassigned() &&
6001 "Cannot increment if the offset is not yet computed!");
6002 if (isUnknown())
6003 return;
6004 for (auto &R : Ranges) {
6005 R.Offset += Inc;
6006 }
6007 }
6008
6009 /// Return true iff there is exactly one range and it is known.
6010 bool isUnique() const {
6011 return Ranges.size() == 1 && !Ranges.front().offsetOrSizeAreUnknown();
6012 }
6013
6014 /// Return the unique range, assuming it exists.
6015 const RangeTy &getUnique() const {
6016 assert(isUnique() && "No unique range to return!");
6017 return Ranges.front();
6018 }
6019
6020 /// Return true iff the list contains an unknown range.
6021 bool isUnknown() const {
6022 if (isUnassigned())
6023 return false;
6024 if (Ranges.front().offsetOrSizeAreUnknown()) {
6025 assert(Ranges.size() == 1 && "Unknown is a singleton range.");
6026 return true;
6027 }
6028 return false;
6029 }
6030
6031 /// Discard all ranges and insert a single unknown range.
6033 Ranges.clear();
6035 return Ranges.begin();
6036 }
6037
6038 /// Return true if no ranges have been inserted.
6039 bool isUnassigned() const { return Ranges.size() == 0; }
6040 };
6041
6042 /// An access description.
6043 struct Access {
6044 Access(Instruction *I, int64_t Offset, int64_t Size,
6045 std::optional<Value *> Content, AccessKind Kind, Type *Ty)
6046 : LocalI(I), RemoteI(I), Content(Content), Ranges(Offset, Size),
6047 Kind(Kind), Ty(Ty) {
6048 verify();
6049 }
6050 Access(Instruction *LocalI, Instruction *RemoteI, const RangeList &Ranges,
6051 std::optional<Value *> Content, AccessKind K, Type *Ty)
6052 : LocalI(LocalI), RemoteI(RemoteI), Content(Content), Ranges(Ranges),
6053 Kind(K), Ty(Ty) {
6054 if (Ranges.size() > 1) {
6057 }
6058 verify();
6059 }
6060 Access(Instruction *LocalI, Instruction *RemoteI, int64_t Offset,
6061 int64_t Size, std::optional<Value *> Content, AccessKind Kind,
6062 Type *Ty)
6063 : LocalI(LocalI), RemoteI(RemoteI), Content(Content),
6064 Ranges(Offset, Size), Kind(Kind), Ty(Ty) {
6065 verify();
6066 }
6067 Access(const Access &Other) = default;
6068
6069 Access &operator=(const Access &Other) = default;
6070 bool operator==(const Access &R) const {
6071 return LocalI == R.LocalI && RemoteI == R.RemoteI && Ranges == R.Ranges &&
6072 Content == R.Content && Kind == R.Kind;
6073 }
6074 bool operator!=(const Access &R) const { return !(*this == R); }
6075
6077 assert(RemoteI == R.RemoteI && "Expected same instruction!");
6078 assert(LocalI == R.LocalI && "Expected same instruction!");
6079
6080 // Note that every Access object corresponds to a unique Value, and only
6081 // accesses to the same Value are merged. Hence we assume that all ranges
6082 // are the same size. If ranges can be different size, then the contents
6083 // must be dropped.
6084 Ranges.merge(R.Ranges);
6085 Content =
6086 AA::combineOptionalValuesInAAValueLatice(Content, R.Content, Ty);
6087
6088 // Combine the access kind, which results in a bitwise union.
6089 // If there is more than one range, then this must be a MAY.
6090 // If we combine a may and a must access we clear the must bit.
6091 Kind = AccessKind(Kind | R.Kind);
6092 if ((Kind & AK_MAY) || Ranges.size() > 1) {
6095 }
6096 verify();
6097 return *this;
6098 }
6099
6100 void verify() {
6101 assert(isMustAccess() + isMayAccess() == 1 &&
6102 "Expect must or may access, not both.");
6103 assert(isAssumption() + isWrite() <= 1 &&
6104 "Expect assumption access or write access, never both.");
6105 assert((isMayAccess() || Ranges.size() == 1) &&
6106 "Cannot be a must access if there are multiple ranges.");
6107 }
6108
6109 /// Return the access kind.
6110 AccessKind getKind() const { return Kind; }
6111
6112 /// Return true if this is a read access.
6113 bool isRead() const { return Kind & AK_R; }
6114
6115 /// Return true if this is a write access.
6116 bool isWrite() const { return Kind & AK_W; }
6117
6118 /// Return true if this is a write access.
6119 bool isWriteOrAssumption() const { return isWrite() || isAssumption(); }
6120
6121 /// Return true if this is an assumption access.
6122 bool isAssumption() const { return Kind == AK_ASSUMPTION; }
6123
6124 bool isMustAccess() const {
6125 bool MustAccess = Kind & AK_MUST;
6126 assert((!MustAccess || Ranges.size() < 2) &&
6127 "Cannot be a must access if there are multiple ranges.");
6128 return MustAccess;
6129 }
6130
6131 bool isMayAccess() const {
6132 bool MayAccess = Kind & AK_MAY;
6133 assert((MayAccess || Ranges.size() < 2) &&
6134 "Cannot be a must access if there are multiple ranges.");
6135 return MayAccess;
6136 }
6137
6138 /// Return the instruction that causes the access with respect to the local
6139 /// scope of the associated attribute.
6140 Instruction *getLocalInst() const { return LocalI; }
6141
6142 /// Return the actual instruction that causes the access.
6143 Instruction *getRemoteInst() const { return RemoteI; }
6144
6145 /// Return true if the value written is not known yet.
6146 bool isWrittenValueYetUndetermined() const { return !Content; }
6147
6148 /// Return true if the value written cannot be determined at all.
6150 return Content.has_value() && !*Content;
6151 }
6152
6153 /// Set the value written to nullptr, i.e., unknown.
6154 void setWrittenValueUnknown() { Content = nullptr; }
6155
6156 /// Return the type associated with the access, if known.
6157 Type *getType() const { return Ty; }
6158
6159 /// Return the value writen, if any.
6162 "Value needs to be determined before accessing it.");
6163 return *Content;
6164 }
6165
6166 /// Return the written value which can be `llvm::null` if it is not yet
6167 /// determined.
6168 std::optional<Value *> getContent() const { return Content; }
6169
6170 bool hasUniqueRange() const { return Ranges.isUnique(); }
6171 const AA::RangeTy &getUniqueRange() const { return Ranges.getUnique(); }
6172
6173 /// Add a range accessed by this Access.
6174 ///
6175 /// If there are multiple ranges, then this is a "may access".
6176 void addRange(int64_t Offset, int64_t Size) {
6177 Ranges.insert({Offset, Size});
6178 if (!hasUniqueRange()) {
6181 }
6182 }
6183
6184 const RangeList &getRanges() const { return Ranges; }
6185
6187 const_iterator begin() const { return Ranges.begin(); }
6188 const_iterator end() const { return Ranges.end(); }
6189
6190 private:
6191 /// The instruction responsible for the access with respect to the local
6192 /// scope of the associated attribute.
6193 Instruction *LocalI;
6194
6195 /// The instruction responsible for the access.
6196 Instruction *RemoteI;
6197
6198 /// The value written, if any. `std::nullopt` means "not known yet",
6199 /// `nullptr` cannot be determined.
6200 std::optional<Value *> Content;
6201
6202 /// Set of potential ranges accessed from the base pointer.
6203 RangeList Ranges;
6204
6205 /// The access kind, e.g., READ, as bitset (could be more than one).
6207
6208 /// The type of the content, thus the type read/written, can be null if not
6209 /// available.
6210 Type *Ty;
6211 };
6212
6213 /// Create an abstract attribute view for the position \p IRP.
6215 Attributor &A);
6216
6217 /// See AbstractAttribute::getName()
6218 StringRef getName() const override { return "AAPointerInfo"; }
6219
6220 /// See AbstractAttribute::getIdAddr()
6221 const char *getIdAddr() const override { return &ID; }
6222
6225 virtual const_bin_iterator begin() const = 0;
6226 virtual const_bin_iterator end() const = 0;
6227 virtual int64_t numOffsetBins() const = 0;
6228 virtual bool reachesReturn() const = 0;
6229 virtual void addReturnedOffsetsTo(OffsetInfo &) const = 0;
6230
6231 /// Call \p CB on all accesses that might interfere with \p Range and return
6232 /// true if all such accesses were known and the callback returned true for
6233 /// all of them, false otherwise. An access interferes with an offset-size
6234 /// pair if it might read or write that memory region.
6236 AA::RangeTy Range, function_ref<bool(const Access &, bool)> CB) const = 0;
6237
6238 /// Call \p CB on all accesses that might interfere with \p I and
6239 /// return true if all such accesses were known and the callback returned true
6240 /// for all of them, false otherwise. In contrast to forallInterferingAccesses
6241 /// this function will perform reasoning to exclude write accesses that cannot
6242 /// affect the load even if they on the surface look as if they would. The
6243 /// flag \p HasBeenWrittenTo will be set to true if we know that \p I does not
6244 /// read the initial value of the underlying memory. If \p SkipCB is given and
6245 /// returns false for a potentially interfering access, that access is not
6246 /// checked for actual interference.
6248 Attributor &A, const AbstractAttribute &QueryingAA, Instruction &I,
6249 bool FindInterferingWrites, bool FindInterferingReads,
6250 function_ref<bool(const Access &, bool)> CB, bool &HasBeenWrittenTo,
6252 function_ref<bool(const Access &)> SkipCB = nullptr) const = 0;
6253
6254 /// This function should return true if the type of the \p AA is AAPointerInfo
6255 static bool classof(const AbstractAttribute *AA) {
6256 return (AA->getIdAddr() == &ID);
6257 }
6258
6259 /// Unique ID (due to the unique address)
6260 LLVM_ABI static const char ID;
6261};
6262
6264
6265/// An abstract attribute for getting assumption information.
6267 : public StateWrapper<SetState<StringRef>, AbstractAttribute,
6268 DenseSet<StringRef>> {
6269 using Base =
6271
6273 const DenseSet<StringRef> &Known)
6274 : Base(IRP, Known) {}
6275
6276 /// Returns true if the assumption set contains the assumption \p Assumption.
6277 virtual bool hasAssumption(const StringRef Assumption) const = 0;
6278
6279 /// Create an abstract attribute view for the position \p IRP.
6281 Attributor &A);
6282
6283 /// See AbstractAttribute::getName()
6284 StringRef getName() const override { return "AAAssumptionInfo"; }
6285
6286 /// See AbstractAttribute::getIdAddr()
6287 const char *getIdAddr() const override { return &ID; }
6288
6289 /// This function should return true if the type of the \p AA is
6290 /// AAAssumptionInfo
6291 static bool classof(const AbstractAttribute *AA) {
6292 return (AA->getIdAddr() == &ID);
6293 }
6294
6295 /// Unique ID (due to the unique address)
6296 LLVM_ABI static const char ID;
6297};
6298
6299/// An abstract attribute for getting all assumption underlying objects.
6302
6303 /// See AbstractAttribute::isValidIRPositionForInit
6306 return false;
6308 }
6309
6310 /// See AbstractAttribute::requiresCallersForArgOrFunction
6311 static bool requiresCallersForArgOrFunction() { return true; }
6312
6313 /// Create an abstract attribute biew for the position \p IRP.
6315 Attributor &A);
6316
6317 /// See AbstractAttribute::getName()
6318 StringRef getName() const override { return "AAUnderlyingObjects"; }
6319
6320 /// See AbstractAttribute::getIdAddr()
6321 const char *getIdAddr() const override { return &ID; }
6322
6323 /// This function should return true if the type of the \p AA is
6324 /// AAUnderlyingObjects.
6325 static bool classof(const AbstractAttribute *AA) {
6326 return (AA->getIdAddr() == &ID);
6327 }
6328
6329 /// Unique ID (due to the unique address)
6330 LLVM_ABI static const char ID;
6331
6332 /// Check \p Pred on all underlying objects in \p Scope collected so far.
6333 ///
6334 /// This method will evaluate \p Pred on all underlying objects in \p Scope
6335 /// collected so far and return true if \p Pred holds on all of them.
6336 virtual bool
6338 AA::ValueScope Scope = AA::Interprocedural) const = 0;
6339};
6340
6341/// An abstract interface for identifying pointers from which loads can be
6342/// marked invariant.
6345
6346 /// See AbstractAttribute::isValidIRPositionForInit
6348 if (!IRP.getAssociatedType()->isPointerTy())
6349 return false;
6350
6352 }
6353
6354 /// Create an abstract attribute view for the position \p IRP.
6357
6358 /// Return true if the pointer's contents are known to remain invariant.
6359 virtual bool isKnownInvariant() const = 0;
6360 virtual bool isKnownLocallyInvariant() const = 0;
6361
6362 /// Return true if the pointer's contents are assumed to remain invariant.
6363 virtual bool isAssumedInvariant() const = 0;
6364 virtual bool isAssumedLocallyInvariant() const = 0;
6365
6366 /// See AbstractAttribute::getName().
6367 StringRef getName() const override { return "AAInvariantLoadPointer"; }
6368
6369 /// See AbstractAttribute::getIdAddr().
6370 const char *getIdAddr() const override { return &ID; }
6371
6372 /// This function should return true if the type of the \p AA is
6373 /// AAInvariantLoadPointer
6374 static bool classof(const AbstractAttribute *AA) {
6375 return (AA->getIdAddr() == &ID);
6376 }
6377
6378 /// Unique ID (due to the unique address).
6379 LLVM_ABI static const char ID;
6380};
6381
6382/// An abstract interface for address space information.
6383struct AAAddressSpace : public StateWrapper<BooleanState, AbstractAttribute> {
6386
6387 /// See AbstractAttribute::isValidIRPositionForInit
6390 return false;
6392 }
6393
6394 /// See AbstractAttribute::requiresCallersForArgOrFunction
6395 static bool requiresCallersForArgOrFunction() { return true; }
6396
6397 /// Return the address space of the associated value. \p NoAddressSpace is
6398 /// returned if the associated value is dead. This functions is not supposed
6399 /// to be called if the AA is invalid.
6400 virtual uint32_t getAddressSpace() const = 0;
6401
6402 /// Create an abstract attribute view for the position \p IRP.
6404 Attributor &A);
6405
6406 /// See AbstractAttribute::getName()
6407 StringRef getName() const override { return "AAAddressSpace"; }
6408
6409 /// See AbstractAttribute::getIdAddr()
6410 const char *getIdAddr() const override { return &ID; }
6411
6412 /// This function should return true if the type of the \p AA is
6413 /// AAAssumptionInfo
6414 static bool classof(const AbstractAttribute *AA) {
6415 return (AA->getIdAddr() == &ID);
6416 }
6417
6418 /// Unique ID (due to the unique address)
6419 LLVM_ABI static const char ID;
6420
6421protected:
6422 // Invalid address space which indicates the associated value is dead.
6423 static const uint32_t InvalidAddressSpace = ~0U;
6424};
6425
6426/// An abstract interface for potential address space information.
6428 : public StateWrapper<BooleanState, AbstractAttribute> {
6432 : Base(IRP), Map(Allocator) {}
6433
6434 /// See AbstractAttribute::isValidIRPositionForInit
6437 return false;
6439 }
6440
6441 /// See AbstractAttribute::requiresCallersForArgOrFunction
6442 static bool requiresCallersForArgOrFunction() { return true; }
6443
6444 /// Create an abstract attribute view for the position \p IRP.
6446 Attributor &A);
6447 /// See AbstractAttribute::getName()
6448 StringRef getName() const override { return "AANoAliasAddrSpace"; }
6449
6450 /// See AbstractAttribute::getIdAddr()
6451 const char *getIdAddr() const override { return &ID; }
6452
6453 /// This function should return true if the type of the \p AA is
6454 /// AAAssumptionInfo
6455 static bool classof(const AbstractAttribute *AA) {
6456 return (AA->getIdAddr() == &ID);
6457 }
6458
6459 /// Unique ID (due to the unique address)
6460 LLVM_ABI static const char ID;
6461
6462protected:
6465};
6466
6467struct AAAllocationInfo : public StateWrapper<BooleanState, AbstractAttribute> {
6470
6471 /// See AbstractAttribute::isValidIRPositionForInit
6474 return false;
6476 }
6477
6478 /// Create an abstract attribute view for the position \p IRP.
6480 Attributor &A);
6481
6482 virtual std::optional<TypeSize> getAllocatedSize() const = 0;
6483
6484 /// See AbstractAttribute::getName()
6485 StringRef getName() const override { return "AAAllocationInfo"; }
6486
6487 /// See AbstractAttribute::getIdAddr()
6488 const char *getIdAddr() const override { return &ID; }
6489
6490 /// This function should return true if the type of the \p AA is
6491 /// AAAllocationInfo
6492 static bool classof(const AbstractAttribute *AA) {
6493 return (AA->getIdAddr() == &ID);
6494 }
6495
6496 constexpr static const std::optional<TypeSize> HasNoAllocationSize =
6497 std::make_optional<TypeSize>(-1, true);
6498
6499 LLVM_ABI static const char ID;
6500};
6501
6502/// An abstract interface for llvm::GlobalValue information interference.
6504 : public StateWrapper<BooleanState, AbstractAttribute> {
6507
6508 /// See AbstractAttribute::isValidIRPositionForInit
6511 return false;
6512 auto *GV = dyn_cast<GlobalValue>(&IRP.getAnchorValue());
6513 if (!GV)
6514 return false;
6515 return GV->hasLocalLinkage();
6516 }
6517
6518 /// Create an abstract attribute view for the position \p IRP.
6520 Attributor &A);
6521
6522 /// Return true iff \p U is a potential use of the associated global value.
6523 virtual bool isPotentialUse(const Use &U) const = 0;
6524
6525 /// See AbstractAttribute::getName()
6526 StringRef getName() const override { return "AAGlobalValueInfo"; }
6527
6528 /// See AbstractAttribute::getIdAddr()
6529 const char *getIdAddr() const override { return &ID; }
6530
6531 /// This function should return true if the type of the \p AA is
6532 /// AAGlobalValueInfo
6533 static bool classof(const AbstractAttribute *AA) {
6534 return (AA->getIdAddr() == &ID);
6535 }
6536
6537 /// Unique ID (due to the unique address)
6538 LLVM_ABI static const char ID;
6539};
6540
6541/// An abstract interface for indirect call information interference.
6543 : public StateWrapper<BooleanState, AbstractAttribute> {
6546
6547 /// See AbstractAttribute::isValidIRPositionForInit
6550 return false;
6551 auto *CB = cast<CallBase>(IRP.getCtxI());
6552 return CB->getOpcode() == Instruction::Call && CB->isIndirectCall() &&
6553 !CB->isMustTailCall();
6554 }
6555
6556 /// Create an abstract attribute view for the position \p IRP.
6558 Attributor &A);
6559
6560 /// Call \CB on each potential callee value and return true if all were known
6561 /// and \p CB returned true on all of them. Otherwise, return false.
6562 virtual bool foreachCallee(function_ref<bool(Function *)> CB) const = 0;
6563
6564 /// See AbstractAttribute::getName()
6565 StringRef getName() const override { return "AAIndirectCallInfo"; }
6566
6567 /// See AbstractAttribute::getIdAddr()
6568 const char *getIdAddr() const override { return &ID; }
6569
6570 /// This function should return true if the type of the \p AA is
6571 /// AAIndirectCallInfo
6572 /// This function should return true if the type of the \p AA is
6573 /// AADenormalFPMath.
6574 static bool classof(const AbstractAttribute *AA) {
6575 return (AA->getIdAddr() == &ID);
6576 }
6577
6578 /// Unique ID (due to the unique address)
6579 LLVM_ABI static const char ID;
6580};
6581
6582/// An abstract Attribute for specializing "dynamic" components of
6583/// "denormal-fp-math" and "denormal-fp-math-f32" to a known denormal mode.
6585 : public StateWrapper<DenormalFPMathState, AbstractAttribute> {
6587
6589
6590 /// Create an abstract attribute view for the position \p IRP.
6592 Attributor &A);
6593
6594 /// See AbstractAttribute::getName()
6595 StringRef getName() const override { return "AADenormalFPMath"; }
6596
6597 /// See AbstractAttribute::getIdAddr()
6598 const char *getIdAddr() const override { return &ID; }
6599
6600 /// This function should return true if the type of the \p AA is
6601 /// AADenormalFPMath.
6602 static bool classof(const AbstractAttribute *AA) {
6603 return (AA->getIdAddr() == &ID);
6604 }
6605
6606 /// Unique ID (due to the unique address)
6607 LLVM_ABI static const char ID;
6608};
6609
6610/// Run options, used by the pass manager.
6612 NONE = 0,
6613 MODULE = 1 << 0,
6614 CGSCC = 1 << 1,
6615 ALL = MODULE | CGSCC
6617
6618namespace AA {
6619/// Helper to avoid creating an AA for IR Attributes that might already be set.
6620template <Attribute::AttrKind AK, typename AAType = AbstractAttribute>
6622 const IRPosition &IRP, DepClassTy DepClass, bool &IsKnown,
6623 bool IgnoreSubsumingPositions = false,
6624 const AAType **AAPtr = nullptr) {
6625 IsKnown = false;
6626 switch (AK) {
6627#define CASE(ATTRNAME, AANAME, ...) \
6628 case Attribute::ATTRNAME: { \
6629 if (AANAME::isImpliedByIR(A, IRP, AK, IgnoreSubsumingPositions)) \
6630 return IsKnown = true; \
6631 if (!QueryingAA) \
6632 return false; \
6633 const auto *AA = A.getAAFor<AANAME>(*QueryingAA, IRP, DepClass); \
6634 if (AAPtr) \
6635 *AAPtr = reinterpret_cast<const AAType *>(AA); \
6636 if (!AA || !AA->isAssumed(__VA_ARGS__)) \
6637 return false; \
6638 IsKnown = AA->isKnown(__VA_ARGS__); \
6639 return true; \
6640 }
6641 CASE(NoUnwind, AANoUnwind, );
6642 CASE(WillReturn, AAWillReturn, );
6643 CASE(NoFree, AANoFree, );
6644 CASE(Captures, AANoCapture, );
6645 CASE(NoRecurse, AANoRecurse, );
6646 CASE(NoReturn, AANoReturn, );
6647 CASE(NoSync, AANoSync, );
6648 CASE(NoAlias, AANoAlias, );
6649 CASE(NonNull, AANonNull, );
6650 CASE(MustProgress, AAMustProgress, );
6651 CASE(NoUndef, AANoUndef, );
6655#undef CASE
6656 default:
6657 llvm_unreachable("hasAssumedIRAttr not available for this attribute kind");
6658 };
6659}
6660} // namespace AA
6661
6662} // end namespace llvm
6663
6664#endif // LLVM_TRANSFORMS_IPO_ATTRIBUTOR_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the BumpPtrAllocator interface.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
This file contains the simple types necessary to represent the attributes associated with functions a...
#define CASE(ATTRNAME, AANAME,...)
static const Function * getParent(const Value *V)
block Block Frequency Analysis
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This header provides classes for managing passes over SCCs of the call graph.
This file provides interfaces used to manipulate a call graph, regardless if it is a "old style" Call...
#define LLVM_ABI
Definition: Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DXIL Resource Access
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file provides an implementation of debug counters.
#define DEBUG_COUNTER(VARNAME, COUNTERNAME, DESC)
Definition: DebugCounter.h:194
This file defines the DenseSet and SmallDenseSet classes.
T Content
uint64_t Size
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
This file implements a coalescing interval map for small objects.
Implements a lazy call graph analysis and related passes for the new pass manager.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
#define H(x, y, z)
Definition: MD5.cpp:57
This file implements a map that provides insertion order iteration.
This file provides utility analysis objects describing memory locations.
Contains a collection of routines for determining if a given instruction is guaranteed to execute if ...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
#define P(N)
FunctionAnalysisManager FAM
Basic Register Allocator
This file contains some templates that are useful if you are working with the STL at all.
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
raw_pwrite_stream & OS
This file defines generic set operations that may be used on set's of different types,...
This file implements a set that has insertion order iteration characteristics.
Shrink Wrap Pass
Definition: ShrinkWrap.cpp:301
This file defines the SmallSet class.
static SymbolRef::Type getType(const Symbol *Sym)
Definition: TapiFile.cpp:39
Value * RHS
Value * LHS
An Iterator for call edges, creates AACallEdges attributes in a lazy way.
Definition: Attributor.h:5506
LLVM_ABI AACallGraphNode * operator*() const
AbstractCallSite.
CallBase * getInstruction() const
Return the underlying instruction.
int getCallArgOperandNo(Argument &Arg) const
Return the operand index of the underlying instruction associated with Arg.
unsigned getNumArgOperands() const
Return the number of parameters of the callee.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:255
void clear(IRUnitT &IR, llvm::StringRef Name)
Clear any cached analysis results for a single unit of IR.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Definition: PassManager.h:431
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:412
This class represents an incoming formal argument to a Function.
Definition: Argument.h:32
const Function * getParent() const
Definition: Argument.h:44
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This represents the llvm.assume intrinsic.
LLVM_ABI AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:95
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:88
@ None
No attributes have been set.
Definition: Attributes.h:90
static bool isEnumAttrKind(AttrKind Kind)
Definition: Attributes.h:101
LLVM Basic Block Representation.
Definition: BasicBlock.h:62
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1116
const Use & getArgOperandUse(unsigned i) const
Wrappers for getting the Use of a call argument.
Definition: InstrTypes.h:1303
Wrapper to unify "old style" CallGraph and "new style" LazyCallGraph.
This class represents a range of values.
Definition: ConstantRange.h:47
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
LLVM_ABI bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type.
LLVM_ABI bool isEmptySet() const
Return true if this set contains no members.
LLVM_ABI ConstantRange unionWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the union of this range with another range.
LLVM_ABI ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the intersection of this range with another range.
This is an important base class in LLVM.
Definition: Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
static bool shouldExecute(unsigned CounterName)
Definition: DebugCounter.h:88
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Definition: DenseMap.h:76
Implements a dense probed hash-table based set.
Definition: DenseSet.h:263
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:284
An instruction for ordering other memory operations.
Definition: Instructions.h:429
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:352
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition: Function.h:355
size_t arg_size() const
Definition: Function.h:899
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:214
Argument * getArg(unsigned i) const
Definition: Function.h:884
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:727
bool hasLocalLinkage() const
Definition: GlobalValue.h:530
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:663
typename Sizer::Allocator Allocator
Definition: IntervalMap.h:963
Invoke instruction.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
An SCC of the call graph.
A lazily constructed view of the call graph of a module.
An instruction for reading from memory.
Definition: Instructions.h:180
Analysis pass that exposes the LoopInfo for a function.
Definition: LoopInfo.h:570
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
Definition: ModRef.h:218
static MemoryEffectsBase unknown()
Create MemoryEffectsBase that can read and write any memory.
Definition: ModRef.h:115
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
The optimization diagnostic interface.
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:99
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
PointerIntPair - This class implements a pair of a pointer and small integer.
void * getOpaqueValue() const
PointerTy getPointer() const
void setFromOpaqueValue(void *Val) &
Analysis pass which computes a PostDominatorTree.
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:112
A vector that has set insertion semantics.
Definition: SetVector.h:59
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:104
void insert_range(Range &&R)
Definition: SetVector.h:193
typename vector_type::const_iterator iterator
Definition: SetVector.h:71
iterator end()
Get an iterator to the end of the SetVector.
Definition: SetVector.h:119
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
Definition: SetVector.h:279
bool empty() const
Determine if the SetVector is empty or not.
Definition: SetVector.h:99
iterator begin()
Get an iterator to the beginning of the SetVector.
Definition: SetVector.h:109
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:168
bool contains(const key_type &key) const
Check if the SetVector contains the given key.
Definition: SetVector.h:269
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:380
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:401
SmallSetIterator - This class implements a const_iterator for SmallSet by delegating to the underlyin...
Definition: SmallSet.h:35
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:356
const_iterator begin() const
Definition: SmallSet.h:214
SmallSetIterator< int64_t, N, std::less< int64_t > > const_iterator
Definition: SmallSet.h:150
void clear()
Definition: SmallSet.h:209
const_iterator end() const
Definition: SmallSet.h:220
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:182
size_type size() const
Definition: SmallSet.h:171
bool empty() const
Definition: SmallVector.h:82
size_t size() const
Definition: SmallVector.h:79
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:938
void reserve(size_type N)
Definition: SmallVector.h:664
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:806
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
An instruction for storing to memory.
Definition: Instructions.h:296
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:233
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:269
A visitor class for IR positions.
Definition: Attributor.h:1123
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
Definition: TimeProfiler.h:182
bool isGPU() const
Test whether the target triple is for a GPU.
Definition: Triple.h:1267
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isArrayTy() const
True if this is an instance of ArrayType.
Definition: Type.h:264
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:267
Type * getArrayElementType() const
Definition: Type.h:408
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
Definition: Type.h:270
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:240
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition: Type.h:225
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1866
A Use represents the edge between a Value definition and its users.
Definition: Use.h:35
LLVM Value Representation.
Definition: Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:701
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1098
iterator_range< use_iterator > uses()
Definition: Value.h:380
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:322
size_type size() const
Definition: DenseSet.h:87
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition: DenseSet.h:169
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:174
CRTP base class for adapting an iterator to a different type.
Definition: iterator.h:237
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI bool isAssumedReadNone(Attributor &A, const IRPosition &IRP, const AbstractAttribute &QueryingAA, bool &IsKnown)
Return true if IRP is readnone.
Definition: Attributor.cpp:655
LLVM_ABI bool isAssumedReadOnly(Attributor &A, const IRPosition &IRP, const AbstractAttribute &QueryingAA, bool &IsKnown)
Return true if IRP is readonly.
Definition: Attributor.cpp:650
raw_ostream & operator<<(raw_ostream &OS, const RangeTy &R)
Definition: Attributor.h:323
LLVM_ABI std::optional< Value * > combineOptionalValuesInAAValueLatice(const std::optional< Value * > &A, const std::optional< Value * > &B, Type *Ty)
Return the combination of A and B such that the result is a possible value of both.
Definition: Attributor.cpp:341
LLVM_ABI bool isValidAtPosition(const ValueAndContext &VAC, InformationCache &InfoCache)
Return true if the value of VAC is a valid at the position of VAC, that is a constant,...
Definition: Attributor.cpp:292
LLVM_ABI bool isAssumedThreadLocalObject(Attributor &A, Value &Obj, const AbstractAttribute &QueryingAA)
Return true if Obj is assumed to be a thread local object.
Definition: Attributor.cpp:837
LLVM_ABI bool isDynamicallyUnique(Attributor &A, const AbstractAttribute &QueryingAA, const Value &V, bool ForAnalysisOnly=true)
Return true if V is dynamically unique, that is, there are no two "instances" of V at runtime with di...
Definition: Attributor.cpp:231
LLVM_ABI bool getPotentialCopiesOfStoredValue(Attributor &A, StoreInst &SI, SmallSetVector< Value *, 4 > &PotentialCopies, const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, bool OnlyExact=false)
Collect all potential values of the one stored by SI into PotentialCopies.
Definition: Attributor.cpp:601
bool operator!=(const RangeTy &A, const RangeTy &B)
Definition: Attributor.h:332
LLVM_ABI bool isPotentiallyAffectedByBarrier(Attributor &A, const Instruction &I, const AbstractAttribute &QueryingAA)
Return true if I is potentially affected by a barrier.
Definition: Attributor.cpp:891
LLVM_ABI bool isGPU(const Module &M)
Return true iff M target a GPU (and we can use GPU AS reasoning).
Definition: Attributor.cpp:200
LLVM_ABI Constant * getInitialValueForObj(Attributor &A, const AbstractAttribute &QueryingAA, Value &Obj, Type &Ty, const TargetLibraryInfo *TLI, const DataLayout &DL, RangeTy *RangePtr=nullptr)
Return the initial value of Obj with type Ty if that is a constant.
Definition: Attributor.cpp:242
ValueScope
Flags to distinguish intra-procedural queries from potentially inter-procedural queries.
Definition: Attributor.h:182
@ Intraprocedural
Definition: Attributor.h:183
@ Interprocedural
Definition: Attributor.h:184
LLVM_ABI bool isValidInScope(const Value &V, const Function *Scope)
Return true if V is a valid value in Scope, that is a constant or an instruction/argument of Scope.
Definition: Attributor.cpp:282
LLVM_ABI bool isPotentiallyReachable(Attributor &A, const Instruction &FromI, const Instruction &ToI, const AbstractAttribute &QueryingAA, const AA::InstExclusionSetTy *ExclusionSet=nullptr, std::function< bool(const Function &F)> GoBackwardsCB=nullptr)
Return true if ToI is potentially reachable from FromI without running into any instruction in Exclus...
Definition: Attributor.cpp:818
LLVM_ABI bool isNoSyncInst(Attributor &A, const Instruction &I, const AbstractAttribute &QueryingAA)
Return true if I is a nosync instruction.
Definition: Attributor.cpp:205
bool hasAssumedIRAttr(Attributor &A, const AbstractAttribute *QueryingAA, const IRPosition &IRP, DepClassTy DepClass, bool &IsKnown, bool IgnoreSubsumingPositions=false, const AAType **AAPtr=nullptr)
Helper to avoid creating an AA for IR Attributes that might already be set.
Definition: Attributor.h:6621
LLVM_ABI bool getPotentiallyLoadedValues(Attributor &A, LoadInst &LI, SmallSetVector< Value *, 4 > &PotentialValues, SmallSetVector< Instruction *, 4 > &PotentialValueOrigins, const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, bool OnlyExact=false)
Collect all potential values LI could read into PotentialValues.
Definition: Attributor.cpp:591
LLVM_ABI Value * getWithType(Value &V, Type &Ty)
Try to convert V to type Ty without introducing new instructions.
Definition: Attributor.cpp:318
E & operator^=(E &LHS, E RHS)
Definition: BitmaskEnum.h:201
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
NodeAddr< UseNode * > Use
Definition: RDFGraph.h:385
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
DenseMap< RetainedKnowledgeKey, Assume2KnowledgeMap > RetainedKnowledgeMap
@ Offset
Definition: DWP.cpp:477
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1702
LLVM_ABI unsigned MaxInitializationChainLength
The value passed to the line option that defines the maximal initialization chain length.
Definition: Attributor.cpp:109
APInt operator&(APInt a, const APInt &b)
Definition: APInt.h:2123
void set_intersect(S1Ty &S1, const S2Ty &S2)
set_intersect(A, B) - Compute A := A ^ B Identical to set_intersection, except that it works on set<>...
Definition: SetOperations.h:58
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:2113
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ATTRIBUTE_ALWAYS_INLINE DynamicAPInt & operator+=(DynamicAPInt &A, int64_t B)
Definition: DynamicAPInt.h:531
bool set_is_subset(const S1Ty &S1, const S2Ty &S2)
set_is_subset(A, B) - Return true iff A in B
@ NONE
Definition: Attributor.h:6612
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
AttributorRunOption
Run options, used by the pass manager.
Definition: Attributor.h:6611
@ MODULE
Definition: Attributor.h:6613
@ CGSCC
Definition: Attributor.h:6614
LLVM_ABI bool canSimplifyInvokeNoUnwind(const Function *F)
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:207
bool set_union(S1Ty &S1, const S2Ty &S2)
set_union(A, B) - Compute A := A u B, return whether A changed.
Definition: SetOperations.h:43
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition: Allocator.h:383
@ Success
The lock was released successfully.
@ Other
Any other memory.
bool operator&=(SparseBitVector< ElementSize > *LHS, const SparseBitVector< ElementSize > &RHS)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:312
ChangeStatus clampStateAndIndicateChange(StateType &S, const StateType &R)
Helper function to clamp a state S of type StateType with the information in R and indicate/return if...
Definition: Attributor.h:3505
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
Definition: iterator.h:363
ChangeStatus
{
Definition: Attributor.h:496
bool operator|=(SparseBitVector< ElementSize > &LHS, const SparseBitVector< ElementSize > *RHS)
DepClassTy
Definition: Attributor.h:506
@ OPTIONAL
The target may be valid if the source is not.
@ NONE
Do not track a dependence between source and target.
@ REQUIRED
The target cannot be valid if the source is not.
APInt operator|(APInt a, const APInt &b)
Definition: APInt.h:2143
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
An abstract interface for address space information.
Definition: Attributor.h:6383
static LLVM_ABI AAAddressSpace & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:6410
static bool requiresCallersForArgOrFunction()
See AbstractAttribute::requiresCallersForArgOrFunction.
Definition: Attributor.h:6395
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:6407
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAAssumptionInfo.
Definition: Attributor.h:6414
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:6388
virtual uint32_t getAddressSpace() const =0
Return the address space of the associated value.
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:6419
AAAddressSpace(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:6384
static const uint32_t InvalidAddressSpace
Definition: Attributor.h:6423
An abstract interface for all align attributes.
Definition: Attributor.h:4323
AAAlign(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:4324
static LLVM_ABI AAAlign & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:4355
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:4343
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:4327
Align getAssumedAlign() const
Return assumed alignment.
Definition: Attributor.h:4334
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAAlign.
Definition: Attributor.h:4346
Align getKnownAlign() const
Return known alignment.
Definition: Attributor.h:4337
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:4340
static LLVM_ABI const char ID
Definition: Attributor.h:6499
virtual std::optional< TypeSize > getAllocatedSize() const =0
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:6472
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:6488
static LLVM_ABI AAAllocationInfo & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:6485
AAAllocationInfo(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:6468
static constexpr const std::optional< TypeSize > HasNoAllocationSize
Definition: Attributor.h:6496
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAAllocationInfo.
Definition: Attributor.h:6492
An abstract attribute for getting assumption information.
Definition: Attributor.h:6268
AAAssumptionInfo(const IRPosition &IRP, Attributor &A, const DenseSet< StringRef > &Known)
Definition: Attributor.h:6272
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:6296
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:6284
static LLVM_ABI AAAssumptionInfo & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:6287
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAAssumptionInfo.
Definition: Attributor.h:6291
virtual bool hasAssumption(const StringRef Assumption) const =0
Returns true if the assumption set contains the assumption Assumption.
An abstract state for querying live call edges.
Definition: Attributor.h:5541
AACallEdges(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:5544
virtual const SetVector< Function * > & getOptimisticEdges() const =0
Get the optimistic edges.
static bool requiresNonAsmForCallBase()
See AbstractAttribute::requiresNonAsmForCallBase.
Definition: Attributor.h:5548
AACallEdgeIterator optimisticEdgesBegin() const override
Iterator for exploring the call graph.
Definition: Attributor.h:5560
virtual bool hasUnknownCallee() const =0
Is there any call with a unknown callee.
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:5585
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:5574
virtual bool hasNonAsmUnknownCallee() const =0
Is there any call with a unknown callee, excluding any inline asm.
AACallEdgeIterator optimisticEdgesEnd() const override
Iterator for exploring the call graph.
Definition: Attributor.h:5565
static LLVM_ABI AACallEdges & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AACallEdges.
Definition: Attributor.h:5580
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:5577
iterator_range< AACallEdgeIterator > optimisticEdgesRange() const
Iterator range for exploring the call graph.
Definition: Attributor.h:5527
virtual AACallEdgeIterator optimisticEdgesBegin() const =0
AACallGraphNode(Attributor &A)
Definition: Attributor.h:5520
virtual AACallEdgeIterator optimisticEdgesEnd() const =0
virtual ~AACallGraphNode()=default
Attributor & A
Reference to Attributor needed for GraphTraits implementation.
Definition: Attributor.h:5534
An abstract Attribute for specializing "dynamic" components of "denormal-fp-math" and "denormal-fp-ma...
Definition: Attributor.h:6585
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:6598
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:6595
AADenormalFPMath(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:6588
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:6607
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AADenormalFPMath.
Definition: Attributor.h:6602
static LLVM_ABI AADenormalFPMath & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static AbstractAttribute * DepGetValAA(const DepTy &DT)
Definition: Attributor.h:526
mapped_iterator< DepSetTy::iterator, decltype(&DepGetVal)> iterator
Definition: Attributor.h:533
virtual ~AADepGraphNode()=default
iterator child_end()
Definition: Attributor.h:540
mapped_iterator< DepSetTy::iterator, decltype(&DepGetValAA)> aaiterator
Definition: Attributor.h:535
static AADepGraphNode * DepGetVal(const DepTy &DT)
Definition: Attributor.h:525
DepSetTy & getDeps()
Definition: Attributor.h:546
iterator child_begin()
Definition: Attributor.h:539
DepSetTy Deps
Set of dependency graph nodes which should be updated if this one is updated.
Definition: Attributor.h:523
virtual void print(Attributor *, raw_ostream &OS) const
Definition: Attributor.h:543
aaiterator begin()
Definition: Attributor.h:537
aaiterator end()
Definition: Attributor.h:538
PointerIntPair< AADepGraphNode *, 1 > DepTy
Definition: Attributor.h:517
void print(raw_ostream &OS) const
Definition: Attributor.h:542
The data structure for the dependency graph.
Definition: Attributor.h:557
~AADepGraph()=default
iterator begin()
Definition: Attributor.h:572
LLVM_ABI void viewGraph()
AADepGraphNode SyntheticRoot
There is no root node for the dependency graph.
Definition: Attributor.h:569
LLVM_ABI void print()
Print dependency graph.
static AADepGraphNode * DepGetVal(const DepTy &DT)
Definition: Attributor.h:562
iterator end()
Definition: Attributor.h:573
LLVM_ABI void dumpGraph()
Dump graph to file.
AADepGraphNode * GetEntryNode()
Definition: Attributor.h:570
AADepGraph()=default
An abstract interface for all dereferenceable attribute.
Definition: Attributor.h:4269
uint32_t getKnownDereferenceableBytes() const
Return known dereferenceable bytes.
Definition: Attributor.h:4293
bool isAssumedGlobal() const
Return true if we assume that underlying value is dereferenceable(_or_null) globally.
Definition: Attributor.h:4281
bool isKnownGlobal() const
Return true if we know that underlying value is dereferenceable(_or_null) globally.
Definition: Attributor.h:4285
AADereferenceable(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:4270
uint32_t getAssumedDereferenceableBytes() const
Return assumed dereferenceable bytes.
Definition: Attributor.h:4288
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:4302
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:4314
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AADereferenceable.
Definition: Attributor.h:4309
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:4305
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:4273
static LLVM_ABI AADereferenceable & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
Summary about the execution domain of a block or instruction.
Definition: Attributor.h:5666
void addAssumeInst(Attributor &A, AssumeInst &AI)
Definition: Attributor.h:5670
void addAlignedBarrier(Attributor &A, CallBase &CB)
Definition: Attributor.h:5674
virtual bool isExecutedByInitialThreadOnly(const BasicBlock &) const =0
Check if a basic block is executed only by the initial thread.
bool isExecutedByInitialThreadOnly(const Instruction &I) const
Check if an instruction is executed only by the initial thread.
Definition: Attributor.h:5702
static LLVM_ABI AAExecutionDomain & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
Definition: OpenMPOpt.cpp:5635
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAExecutionDomain.
Definition: Attributor.h:5728
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr().
Definition: Attributor.h:5699
virtual ExecutionDomainTy getFunctionExecutionDomain() const =0
virtual ExecutionDomainTy getExecutionDomain(const BasicBlock &) const =0
virtual bool isExecutedInAlignedRegion(Attributor &A, const Instruction &I) const =0
Check if the instruction I is executed in an aligned region, that is, the synchronizing effects befor...
AAExecutionDomain(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:5663
virtual bool isNoOpFence(const FenceInst &FI) const =0
Helper function to determine if FI is a no-op given the information about its execution from ExecDoma...
StringRef getName() const override
See AbstractAttribute::getName().
Definition: Attributor.h:5696
virtual std::pair< ExecutionDomainTy, ExecutionDomainTy > getExecutionDomain(const CallBase &CB) const =0
Return the execution domain with which the call CB is entered and the one with which it is left.
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:5733
An abstract interface for llvm::GlobalValue information interference.
Definition: Attributor.h:6504
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAGlobalValueInfo.
Definition: Attributor.h:6533
AAGlobalValueInfo(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:6505
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:6526
static LLVM_ABI AAGlobalValueInfo & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:6509
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:6529
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:6538
virtual bool isPotentialUse(const Use &U) const =0
Return true iff U is a potential use of the associated global value.
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:4608
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:4611
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAHeapToStack.
Definition: Attributor.h:4614
virtual bool isAssumedHeapToStack(const CallBase &CB) const =0
Returns true if HeapToStack conversion is assumed to be possible.
virtual bool isAssumedHeapToStackRemovedFree(CallBase &CB) const =0
Returns true if HeapToStack conversion is assumed and the CB is a callsite to a free operation to be ...
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:4619
static LLVM_ABI AAHeapToStack & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
AAHeapToStack(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:4594
An abstract interface for indirect call information interference.
Definition: Attributor.h:6543
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:6565
virtual bool foreachCallee(function_ref< bool(Function *)> CB) const =0
Call \CB on each potential callee value and return true if all were known and CB returned true on all...
AAIndirectCallInfo(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:6544
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:6568
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAIndirectCallInfo This function should ret...
Definition: Attributor.h:6574
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:6579
static LLVM_ABI AAIndirectCallInfo & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:6548
An abstract interface to track if a value leaves it's defining function instance.
Definition: Attributor.h:4362
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:4395
bool isKnownUniqueForAnalysis() const
Return true if we know that the underlying value is unique in its scope wrt.
Definition: Attributor.h:4370
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:4383
AAInstanceInfo(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:4363
bool isAssumedUniqueForAnalysis() const
Return true if we assume that the underlying value is unique in its scope wrt.
Definition: Attributor.h:4376
static LLVM_ABI AAInstanceInfo & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAInstanceInfo.
Definition: Attributor.h:4390
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:4386
An abstract Attribute for computing reachability between functions.
Definition: Attributor.h:5738
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AACallEdges.
Definition: Attributor.h:5768
static LLVM_ABI AAInterFnReachability & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:5773
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:5765
bool canReach(Attributor &A, const Function &Fn) const
If the function represented by this possition can reach Fn.
Definition: Attributor.h:5744
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:5762
virtual bool instructionCanReach(Attributor &A, const Instruction &Inst, const Function &Fn, const AA::InstExclusionSetTy *ExclusionSet=nullptr) const =0
Can Inst reach Fn.
AAInterFnReachability(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:5741
An abstract interface to determine reachability of point A to B.
Definition: Attributor.h:3863
static LLVM_ABI AAIntraFnReachability & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAIntraFnReachability.
Definition: Attributor.h:3886
AAIntraFnReachability(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:3865
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:3879
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:3891
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:3882
virtual bool isAssumedReachable(Attributor &A, const Instruction &From, const Instruction &To, const AA::InstExclusionSetTy *ExclusionSet=nullptr) const =0
Returns true if 'From' instruction is assumed to reach, 'To' instruction.
An abstract interface for identifying pointers from which loads can be marked invariant.
Definition: Attributor.h:6343
virtual bool isAssumedInvariant() const =0
Return true if the pointer's contents are assumed to remain invariant.
static LLVM_ABI AAInvariantLoadPointer & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
virtual bool isAssumedLocallyInvariant() const =0
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAInvariantLoadPointer.
Definition: Attributor.h:6374
static LLVM_ABI const char ID
Unique ID (due to the unique address).
Definition: Attributor.h:6379
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr().
Definition: Attributor.h:6370
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:6347
StringRef getName() const override
See AbstractAttribute::getName().
Definition: Attributor.h:6367
virtual bool isKnownInvariant() const =0
Return true if the pointer's contents are known to remain invariant.
AAInvariantLoadPointer(const IRPosition &IRP)
Definition: Attributor.h:6344
virtual bool isKnownLocallyInvariant() const =0
An abstract interface for liveness abstract attribute.
Definition: Attributor.h:4026
virtual bool isKnownDead(const BasicBlock *BB) const =0
Returns true if BB is known dead.
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAIsDead.
Definition: Attributor.h:4112
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:4117
bool isLiveInstSet(T begin, T end) const
This method is used to check if at least one instruction in a collection of instructions is live.
Definition: Attributor.h:4074
virtual bool isKnownDead() const =0
Returns true if the underlying value is known dead.
virtual bool isEdgeDead(const BasicBlock *From, const BasicBlock *To) const
Return if the edge from From BB to To BB is assumed dead.
Definition: Attributor.h:4101
virtual bool isAssumedDead(const Instruction *I) const =0
Returns true if I is assumed dead.
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:4031
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:4106
virtual bool isAssumedDead() const =0
The query functions are protected such that other attributes need to go through the Attributor interf...
virtual bool isRemovableStore() const
Return true if the underlying value is a store that is known to be removable.
Definition: Attributor.h:4070
virtual bool isAssumedDead(const BasicBlock *BB) const =0
Returns true if BB is assumed dead.
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:4109
static LLVM_ABI AAIsDead & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static bool mayCatchAsynchronousExceptions(const Function &F)
Determine if F might catch asynchronous exceptions.
Definition: Attributor.h:4092
AAIsDead(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:4028
virtual bool isKnownDead(const Instruction *I) const =0
Returns true if I is known dead.
An abstract interface for memory access kind related attributes (readnone/readonly/writeonly).
Definition: Attributor.h:4684
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:4737
bool isAssumedReadOnly() const
Return true if we assume that the underlying value is not accessed (=written) in its respective scope...
Definition: Attributor.h:4722
static LLVM_ABI AAMemoryBehavior & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static bool hasTrivialInitializer()
See AbstractAttribute::hasTrivialInitializer.
Definition: Attributor.h:4688
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAMemoryBehavior.
Definition: Attributor.h:4744
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:4691
bool isKnownReadNone() const
Return true if we know that the underlying value is not read or accessed in its respective scope.
Definition: Attributor.h:4710
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:4749
bool isKnownWriteOnly() const
Return true if we know that the underlying value is not read in its respective scope.
Definition: Attributor.h:4726
bool isAssumedReadNone() const
Return true if we assume that the underlying value is not read or accessed in its respective scope.
Definition: Attributor.h:4714
bool isAssumedWriteOnly() const
Return true if we assume that the underlying value is not read in its respective scope.
Definition: Attributor.h:4730
AAMemoryBehavior(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:4685
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:4740
bool isKnownReadOnly() const
Return true if we know that the underlying value is not accessed (=written) in its respective scope.
Definition: Attributor.h:4718
An abstract interface for all memory location attributes (readnone/argmemonly/inaccessiblememonly/ina...
Definition: Attributor.h:4758
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:4922
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:4925
bool isAssumedStackOnly() const
Return true if we assume that the associated functions has at most local/stack accesses.
Definition: Attributor.h:4819
static LLVM_ABI std::string getMemoryLocationsAsStr(MemoryLocationsKind MLK)
Return the locations encoded by MLK as a readable string.
bool isKnownArgMemOnly() const
Return true if we know that the underlying value will only access argument pointees (see Attribute::A...
Definition: Attributor.h:4837
bool isKnownInaccessibleOrArgMemOnly() const
Return true if we know that the underlying value will only access inaccesible memory or argument poin...
Definition: Attributor.h:4850
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:4934
AAMemoryLocation(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:4761
bool isKnownReadNone() const
Return true if we know that the associated functions has no observable accesses.
Definition: Attributor.h:4803
bool isAssumedSpecifiedMemOnly(MemoryLocationsKind MLK) const
Return true if only the memory locations specififed by MLK are assumed to be accessed by the associat...
Definition: Attributor.h:4869
bool isAssumedInaccessibleMemOnly() const
Return true if we assume that the underlying value will only access inaccesible memory only (see Attr...
Definition: Attributor.h:4831
bool isKnownInaccessibleMemOnly() const
Return true if we know that the underlying value will only access inaccesible memory only (see Attrib...
Definition: Attributor.h:4825
static LLVM_ABI AAMemoryLocation & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
bool isAssumedInaccessibleOrArgMemOnly() const
Return true if we assume that the underlying value will only access inaccesible memory or argument po...
Definition: Attributor.h:4858
bool isKnowStackOnly() const
Return true if we know that the associated functions has at most local/stack accesses.
Definition: Attributor.h:4813
static bool requiresCalleeForCallBase()
See AbstractAttribute::requiresCalleeForCallBase.
Definition: Attributor.h:4764
AccessKind
Simple enum to distinguish read/write/read-write accesses.
Definition: Attributor.h:4894
StateType::base_t MemoryLocationsKind
Definition: Attributor.h:4759
MemoryLocationsKind getAssumedNotAccessedLocation() const
Return the locations that are assumed to be not accessed by the associated function,...
Definition: Attributor.h:4875
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAMemoryLocation.
Definition: Attributor.h:4929
static bool hasTrivialInitializer()
See AbstractAttribute::hasTrivialInitializer.
Definition: Attributor.h:4767
bool isAssumedReadNone() const
Return true if we assume that the associated functions has no observable accesses.
Definition: Attributor.h:4807
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:4770
virtual bool checkForAllAccessesToMemoryKind(function_ref< bool(const Instruction *, const Value *, AccessKind, MemoryLocationsKind)> Pred, MemoryLocationsKind MLK) const =0
Check Pred on all accesses to the memory kinds specified by MLK.
const std::string getAsStr(Attributor *A) const override
See AbstractState::getAsStr(Attributor).
Definition: Attributor.h:4917
bool mayAccessArgMem() const
Return true if the underlying value may access memory through arguement pointers of the associated fu...
Definition: Attributor.h:4865
bool isAssumedArgMemOnly() const
Return true if we assume that the underlying value will only access argument pointees (see Attribute:...
Definition: Attributor.h:4843
static MemoryLocationsKind inverseLocation(MemoryLocationsKind Loc, bool AndLocalMem, bool AndConstMem)
Return the inverse of location Loc, thus for NO_XXX the return describes ONLY_XXX.
Definition: Attributor.h:4885
An abstract interface for all nonnull attributes.
Definition: Attributor.h:3636
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:3659
bool isKnownMustProgress() const
Return true if we know that underlying value is nonnull.
Definition: Attributor.h:3652
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAMustProgress.
Definition: Attributor.h:3666
bool isAssumedMustProgress() const
Return true if we assume that the underlying value is nonnull.
Definition: Attributor.h:3649
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, Attribute::AttrKind ImpliedAttributeKind, bool IgnoreSubsumingPositions=false)
Definition: Attributor.h:3639
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:3662
static LLVM_ABI AAMustProgress & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:3671
AAMustProgress(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:3637
An abstract interface for potential address space information.
Definition: Attributor.h:6428
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAAssumptionInfo.
Definition: Attributor.h:6455
static bool requiresCallersForArgOrFunction()
See AbstractAttribute::requiresCallersForArgOrFunction.
Definition: Attributor.h:6442
static LLVM_ABI AANoAliasAddrSpace & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:6435
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:6460
AANoAliasAddrSpace(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:6431
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:6451
RangeMap::Allocator Allocator
Definition: Attributor.h:6463
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:6448
An abstract interface for all noalias attributes.
Definition: Attributor.h:3898
static LLVM_ABI bool isImpliedByIR(Attributor &A, const IRPosition &IRP, Attribute::AttrKind ImpliedAttributeKind, bool IgnoreSubsumingPositions=false)
See IRAttribute::isImpliedByIR.
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AANoAlias.
Definition: Attributor.h:3933
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:3927
static bool requiresCallersForArgOrFunction()
See AbstractAttribute::requiresCallersForArgOrFunction.
Definition: Attributor.h:3914
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:3930
bool isKnownNoAlias() const
Return true if we know that underlying value is noalias.
Definition: Attributor.h:3920
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:3938
bool isAssumedNoAlias() const
Return true if we assume that the underlying value is alias.
Definition: Attributor.h:3917
static LLVM_ABI AANoAlias & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
AANoAlias(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:3899
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:3902
An abstract interface for all nocapture attributes.
Definition: Attributor.h:4403
static LLVM_ABI AANoCapture & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:4418
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:4469
AANoCapture(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:4404
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:4466
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:4477
@ NO_CAPTURE_MAYBE_RETURNED
If we do not capture the value in memory or through integers we can only communicate it back as a der...
Definition: Attributor.h:4433
@ NO_CAPTURE
If we do not capture the value in memory, through integers, or as a derived pointer we know it is not...
Definition: Attributor.h:4437
bool isAssumedNoCaptureMaybeReturned() const
Return true if we assume that the underlying value is not captured in its respective scope but we all...
Definition: Attributor.h:4457
bool isKnownNoCapture() const
Return true if we know that the underlying value is not captured in its respective scope.
Definition: Attributor.h:4443
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AANoCapture.
Definition: Attributor.h:4472
bool isKnownNoCaptureMaybeReturned() const
Return true if we know that the underlying value is not captured in its respective scope but we allow...
Definition: Attributor.h:4451
static LLVM_ABI bool isImpliedByIR(Attributor &A, const IRPosition &IRP, Attribute::AttrKind ImpliedAttributeKind, bool IgnoreSubsumingPositions=false)
See IRAttribute::isImpliedByIR.
bool isAssumedNoCapture() const
Return true if we assume that the underlying value is not captured in its respective scope.
Definition: Attributor.h:4447
static LLVM_ABI void determineFunctionCaptureCapabilities(const IRPosition &IRP, const Function &F, BitIntegerState &State)
Update State according to the capture capabilities of F for position IRP.
FPClassTest getAssumedNoFPClass() const
Return the underlying assumed nofpclass.
Definition: Attributor.h:5471
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:5458
AANoFPClass(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:5455
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:5484
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AANoFPClass.
Definition: Attributor.h:5490
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:5495
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:5487
FPClassTest getKnownNoFPClass() const
Return the underlying known nofpclass.
Definition: Attributor.h:5475
static LLVM_ABI AANoFPClass & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
An AbstractAttribute for nofree.
Definition: Attributor.h:3945
bool isKnownNoFree() const
Return true if "nofree" is known.
Definition: Attributor.h:3971
static LLVM_ABI AANoFree & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
AANoFree(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:3946
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, Attribute::AttrKind ImpliedAttributeKind, bool IgnoreSubsumingPositions=false)
See IRAttribute::isImpliedByIR.
Definition: Attributor.h:3949
bool isAssumedNoFree() const
Return true if "nofree" is assumed.
Definition: Attributor.h:3968
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:3989
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:3960
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AANoFree.
Definition: Attributor.h:3984
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:3978
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:3981
An abstract attribute for norecurse.
Definition: Attributor.h:3730
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:3744
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AANoRecurse.
Definition: Attributor.h:3750
AANoRecurse(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:3731
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:3747
bool isAssumedNoRecurse() const
Return true if "norecurse" is assumed.
Definition: Attributor.h:3734
static LLVM_ABI AANoRecurse & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
bool isKnownNoRecurse() const
Return true if "norecurse" is known.
Definition: Attributor.h:3737
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:3755
An AbstractAttribute for noreturn.
Definition: Attributor.h:3996
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AANoReturn.
Definition: Attributor.h:4016
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:4021
bool isAssumedNoReturn() const
Return true if the underlying object is assumed to never return.
Definition: Attributor.h:4000
static LLVM_ABI AANoReturn & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:4010
AANoReturn(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:3997
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:4013
bool isKnownNoReturn() const
Return true if the underlying object is known to never return.
Definition: Attributor.h:4003
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:3584
AANoSync(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:3551
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:3621
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:3618
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, Attribute::AttrKind ImpliedAttributeKind, bool IgnoreSubsumingPositions=false)
Definition: Attributor.h:3553
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:3629
static LLVM_ABI bool isAlignedBarrier(const CallBase &CB, bool ExecutedAligned)
Helper function to determine if CB is an aligned (GPU) barrier.
bool isAssumedNoSync() const
Returns true if "nosync" is assumed.
Definition: Attributor.h:3592
static LLVM_ABI bool isNonRelaxedAtomic(const Instruction *I)
Helper function used to determine whether an instruction is non-relaxed atomic.
bool isKnownNoSync() const
Returns true if "nosync" is known.
Definition: Attributor.h:3595
static LLVM_ABI AANoSync & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static LLVM_ABI bool isNoSyncIntrinsic(const Instruction *I)
Helper function specific for intrinsics which are potentially volatile.
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AANoSync.
Definition: Attributor.h:3624
An abstract interface for all noundef attributes.
Definition: Attributor.h:5407
bool isKnownNoUndef() const
Return true if we know that underlying value is noundef.
Definition: Attributor.h:5425
static bool isImpliedByUndef()
See IRAttribute::isImpliedByUndef.
Definition: Attributor.h:5411
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:5432
bool isAssumedNoUndef() const
Return true if we assume that the underlying value is noundef.
Definition: Attributor.h:5422
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AANoUndef.
Definition: Attributor.h:5438
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:5435
static LLVM_ABI AANoUndef & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
AANoUndef(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:5408
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:5443
static bool isImpliedByPoison()
See IRAttribute::isImpliedByPoison.
Definition: Attributor.h:5414
static LLVM_ABI bool isImpliedByIR(Attributor &A, const IRPosition &IRP, Attribute::AttrKind ImpliedAttributeKind, bool IgnoreSubsumingPositions=false)
See IRAttribute::isImpliedByIR.
AANoUnwind(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:3520
bool isAssumedNoUnwind() const
Returns true if nounwind is assumed.
Definition: Attributor.h:3523
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AANoUnwind.
Definition: Attributor.h:3539
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:3533
static LLVM_ABI AANoUnwind & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:3544
bool isKnownNoUnwind() const
Returns true if nounwind is known.
Definition: Attributor.h:3526
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:3536
An abstract Attribute for determining the necessity of the convergent attribute.
Definition: Attributor.h:5778
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:5806
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:5797
static LLVM_ABI AANonConvergent & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:5794
bool isAssumedNotConvergent() const
Return true if "non-convergent" is assumed.
Definition: Attributor.h:5788
bool isKnownNotConvergent() const
Return true if "non-convergent" is known.
Definition: Attributor.h:5791
AANonConvergent(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:5781
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AANonConvergent.
Definition: Attributor.h:5801
An abstract interface for all nonnull attributes.
Definition: Attributor.h:3678
static bool isImpliedByUndef()
See IRAttribute::isImpliedByUndef.
Definition: Attributor.h:3687
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:3690
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:3723
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:3715
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AANonNull.
Definition: Attributor.h:3718
static LLVM_ABI AANonNull & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
AANonNull(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:3679
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:3712
static LLVM_ABI bool isImpliedByIR(Attributor &A, const IRPosition &IRP, Attribute::AttrKind ImpliedAttributeKind, bool IgnoreSubsumingPositions=false)
See AbstractAttribute::isImpliedByIR(...).
bool isAssumedNonNull() const
Return true if we assume that the underlying value is nonnull.
Definition: Attributor.h:3702
bool isKnownNonNull() const
Return true if we know that underlying value is nonnull.
Definition: Attributor.h:3705
static bool hasTrivialInitializer()
See AbstractAttribute::hasTrivialInitializer.
Definition: Attributor.h:3682
An access description.
Definition: Attributor.h:6043
bool isWrittenValueUnknown() const
Return true if the value written cannot be determined at all.
Definition: Attributor.h:6149
const_iterator end() const
Definition: Attributor.h:6188
bool operator!=(const Access &R) const
Definition: Attributor.h:6074
std::optional< Value * > getContent() const
Return the written value which can be llvm::null if it is not yet determined.
Definition: Attributor.h:6168
Access & operator=(const Access &Other)=default
bool isAssumption() const
Return true if this is an assumption access.
Definition: Attributor.h:6122
void setWrittenValueUnknown()
Set the value written to nullptr, i.e., unknown.
Definition: Attributor.h:6154
const RangeList & getRanges() const
Definition: Attributor.h:6184
bool isWriteOrAssumption() const
Return true if this is a write access.
Definition: Attributor.h:6119
bool isRead() const
Return true if this is a read access.
Definition: Attributor.h:6113
bool isWrite() const
Return true if this is a write access.
Definition: Attributor.h:6116
Value * getWrittenValue() const
Return the value writen, if any.
Definition: Attributor.h:6160
Instruction * getLocalInst() const
Return the instruction that causes the access with respect to the local scope of the associated attri...
Definition: Attributor.h:6140
Access(Instruction *LocalI, Instruction *RemoteI, const RangeList &Ranges, std::optional< Value * > Content, AccessKind K, Type *Ty)
Definition: Attributor.h:6050
Access(Instruction *LocalI, Instruction *RemoteI, int64_t Offset, int64_t Size, std::optional< Value * > Content, AccessKind Kind, Type *Ty)
Definition: Attributor.h:6060
Access(Instruction *I, int64_t Offset, int64_t Size, std::optional< Value * > Content, AccessKind Kind, Type *Ty)
Definition: Attributor.h:6044
Access(const Access &Other)=default
Type * getType() const
Return the type associated with the access, if known.
Definition: Attributor.h:6157
Access & operator&=(const Access &R)
Definition: Attributor.h:6076
const_iterator begin() const
Definition: Attributor.h:6187
void addRange(int64_t Offset, int64_t Size)
Add a range accessed by this Access.
Definition: Attributor.h:6176
Instruction * getRemoteInst() const
Return the actual instruction that causes the access.
Definition: Attributor.h:6143
const AA::RangeTy & getUniqueRange() const
Definition: Attributor.h:6171
bool operator==(const Access &R) const
Definition: Attributor.h:6070
bool isWrittenValueYetUndetermined() const
Return true if the value written is not known yet.
Definition: Attributor.h:6146
AccessKind getKind() const
Return the access kind.
Definition: Attributor.h:6110
A helper containing a list of offsets computed for a Use.
Definition: Attributor.h:5847
bool operator==(const OffsetInfo &RHS) const
Definition: Attributor.h:5855
bool insert(int64_t Offset)
Definition: Attributor.h:5861
bool operator!=(const OffsetInfo &RHS) const
Definition: Attributor.h:5859
const_iterator begin() const
Definition: Attributor.h:5852
const_iterator end() const
Definition: Attributor.h:5853
bool merge(const OffsetInfo &R)
Copy offsets from R into the current list.
Definition: Attributor.h:5888
A container for a list of ranges.
Definition: Attributor.h:5892
const_iterator end() const
Definition: Attributor.h:5917
void addToAllOffsets(int64_t Inc)
Add the increment Inc to the offset of every range.
Definition: Attributor.h:5999
bool operator==(const RangeList &OI) const
Definition: Attributor.h:5936
RangeList(ArrayRef< int64_t > Offsets, int64_t Size)
Definition: Attributor.h:5904
bool isUnique() const
Return true iff there is exactly one range and it is known.
Definition: Attributor.h:6010
std::pair< iterator, bool > insert(iterator Pos, const RangeTy &R)
Insert R at the given iterator Pos, and merge if necessary.
Definition: Attributor.h:5973
RangeList(const RangeTy &R)
Definition: Attributor.h:5903
bool isUnknown() const
Return true iff the list contains an unknown range.
Definition: Attributor.h:6021
VecTy::const_iterator const_iterator
Definition: Attributor.h:5900
const_iterator begin() const
Definition: Attributor.h:5916
bool isUnassigned() const
Return true if no ranges have been inserted.
Definition: Attributor.h:6039
static void set_difference(const RangeList &L, const RangeList &R, RangeList &D)
Copy ranges from L that are not in R, into D.
Definition: Attributor.h:5928
const RangeTy & getUnique() const
Return the unique range, assuming it exists.
Definition: Attributor.h:6015
bool merge(const RangeList &RHS)
Merge the ranges in RHS into the current ranges.
Definition: Attributor.h:5942
std::pair< iterator, bool > insert(const RangeTy &R)
Insert the given range R, maintaining sorted order.
Definition: Attributor.h:5994
iterator setUnknown()
Discard all ranges and insert a single unknown range.
Definition: Attributor.h:6032
void push_back(const RangeTy &R)
Definition: Attributor.h:5921
An abstract interface for struct information.
Definition: Attributor.h:5810
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:5814
virtual bool reachesReturn() const =0
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:6218
virtual bool forallInterferingAccesses(Attributor &A, const AbstractAttribute &QueryingAA, Instruction &I, bool FindInterferingWrites, bool FindInterferingReads, function_ref< bool(const Access &, bool)> CB, bool &HasBeenWrittenTo, AA::RangeTy &Range, function_ref< bool(const Access &)> SkipCB=nullptr) const =0
Call CB on all accesses that might interfere with I and return true if all such accesses were known a...
virtual void addReturnedOffsetsTo(OffsetInfo &) const =0
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAPointerInfo.
Definition: Attributor.h:6255
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:6221
virtual const_bin_iterator begin() const =0
virtual bool forallInterferingAccesses(AA::RangeTy Range, function_ref< bool(const Access &, bool)> CB) const =0
Call CB on all accesses that might interfere with Range and return true if all such accesses were kno...
virtual const_bin_iterator end() const =0
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:6260
static LLVM_ABI AAPointerInfo & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
AAPointerInfo(const IRPosition &IRP)
Definition: Attributor.h:5811
virtual int64_t numOffsetBins() const =0
An abstract interface for potential values analysis.
Definition: Attributor.h:5298
PotentialConstantIntValuesState & getState() override
See AbstractAttribute::getState(...).
Definition: Attributor.h:5313
const PotentialConstantIntValuesState & getState() const override
Definition: Attributor.h:5314
AAPotentialConstantValues(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:5300
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:5355
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAPotentialConstantValues.
Definition: Attributor.h:5350
static bool requiresCallersForArgOrFunction()
See AbstractAttribute::requiresCallersForArgOrFunction.
Definition: Attributor.h:5310
std::optional< Constant * > getAssumedConstant(Attributor &A, const Instruction *CtxI=nullptr) const
Return assumed constant for the associated value.
Definition: Attributor.h:5324
static LLVM_ABI AAPotentialConstantValues & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:5346
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:5343
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:5303
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAPotentialValues.
Definition: Attributor.h:5388
PotentialLLVMValuesState & getState() override
See AbstractAttribute::getState(...).
Definition: Attributor.h:5367
AAPotentialValues(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:5361
static LLVM_ABI AAPotentialValues & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
static bool requiresCallersForArgOrFunction()
See AbstractAttribute::requiresCallersForArgOrFunction.
Definition: Attributor.h:5364
const PotentialLLVMValuesState & getState() const override
Definition: Attributor.h:5368
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:5384
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:5393
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:5381
static LLVM_ABI Value * getSingleValue(Attributor &A, const AbstractAttribute &AA, const IRPosition &IRP, SmallVectorImpl< AA::ValueAndContext > &Values)
Extract the single value in Values if any.
An abstract interface for privatizability.
Definition: Attributor.h:4633
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:4638
bool isAssumedPrivatizablePtr() const
Returns true if pointer privatization is assumed to be possible.
Definition: Attributor.h:4645
virtual std::optional< Type * > getPrivatizableType() const =0
Return the type we can choose for a private copy of the underlying value.
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:4675
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:4663
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAPricatizablePtr.
Definition: Attributor.h:4670
static bool requiresCallersForArgOrFunction()
See AbstractAttribute::requiresCallersForArgOrFunction.
Definition: Attributor.h:4651
static LLVM_ABI AAPrivatizablePtr & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
AAPrivatizablePtr(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:4635
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:4666
bool isKnownPrivatizablePtr() const
Returns true if pointer privatization is known to be possible.
Definition: Attributor.h:4648
An abstract attribute for undefined behavior.
Definition: Attributor.h:3825
static LLVM_ABI AAUndefinedBehavior & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
bool isKnownToCauseUB() const
Return true if "undefined behavior" is known.
Definition: Attributor.h:3836
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:3849
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:3858
virtual bool isAssumedToCauseUB(Instruction *I) const =0
Return true if "undefined behavior" is assumed for a specific instruction.
AAUndefinedBehavior(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:3827
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAUndefineBehavior.
Definition: Attributor.h:3853
bool isAssumedToCauseUB() const
Return true if "undefined behavior" is assumed.
Definition: Attributor.h:3830
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:3846
virtual bool isKnownToCauseUB(Instruction *I) const =0
Return true if "undefined behavior" is known for a specific instruction.
An abstract attribute for getting all assumption underlying objects.
Definition: Attributor.h:6300
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:6304
virtual bool forallUnderlyingObjects(function_ref< bool(Value &)> Pred, AA::ValueScope Scope=AA::Interprocedural) const =0
Check Pred on all underlying objects in Scope collected so far.
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:6321
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAUnderlyingObjects.
Definition: Attributor.h:6325
static LLVM_ABI AAUnderlyingObjects & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute biew for the position IRP.
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:6330
AAUnderlyingObjects(const IRPosition &IRP)
Definition: Attributor.h:6301
static bool requiresCallersForArgOrFunction()
See AbstractAttribute::requiresCallersForArgOrFunction.
Definition: Attributor.h:6311
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:6318
An abstract interface for range value analysis.
Definition: Attributor.h:4939
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
See AbstractAttribute::isValidIRPositionForInit.
Definition: Attributor.h:4945
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:4990
std::optional< Constant * > getAssumedConstant(Attributor &A, const Instruction *CtxI=nullptr) const
Return an assumed constant for the associated value a program point CtxI.
Definition: Attributor.h:4977
virtual ConstantRange getAssumedConstantRange(Attributor &A, const Instruction *CtxI=nullptr) const =0
Return an assumed range for the associated value a program point CtxI.
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:5002
static bool requiresCallersForArgOrFunction()
See AbstractAttribute::requiresCallersForArgOrFunction.
Definition: Attributor.h:4952
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAValueConstantRange.
Definition: Attributor.h:4997
AAValueConstantRange(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:4941
static LLVM_ABI AAValueConstantRange & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:4993
IntegerRangeState & getState() override
See AbstractAttribute::getState(...).
Definition: Attributor.h:4955
const IntegerRangeState & getState() const override
Definition: Attributor.h:4956
virtual ConstantRange getKnownConstantRange(Attributor &A, const Instruction *CtxI=nullptr) const =0
Return a known range for the associated value at a program point CtxI.
An abstract interface for value simplify abstract attribute.
Definition: Attributor.h:4556
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAValueSimplify.
Definition: Attributor.h:4573
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:4566
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:4578
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:4569
static LLVM_ABI AAValueSimplify & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
AAValueSimplify(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:4558
An abstract attribute for willreturn.
Definition: Attributor.h:3762
bool isKnownWillReturn() const
Return true if "willreturn" is known.
Definition: Attributor.h:3802
const char * getIdAddr() const override
See AbstractAttribute::getIdAddr()
Definition: Attributor.h:3812
static LLVM_ABI const char ID
Unique ID (due to the unique address)
Definition: Attributor.h:3820
static LLVM_ABI AAWillReturn & createForPosition(const IRPosition &IRP, Attributor &A)
Create an abstract attribute view for the position IRP.
StringRef getName() const override
See AbstractAttribute::getName()
Definition: Attributor.h:3809
static bool classof(const AbstractAttribute *AA)
This function should return true if the type of the AA is AAWillReturn.
Definition: Attributor.h:3815
AAWillReturn(const IRPosition &IRP, Attributor &A)
Definition: Attributor.h:3763
static bool isImpliedByMustprogressAndReadonly(Attributor &A, const IRPosition &IRP)
Check for mustprogress and readonly as they imply willreturn.
Definition: Attributor.h:3781
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, Attribute::AttrKind ImpliedAttributeKind, bool IgnoreSubsumingPositions=false)
Definition: Attributor.h:3765
bool isAssumedWillReturn() const
Return true if "willreturn" is assumed.
Definition: Attributor.h:3799
Helper to represent an access offset and size, with logic to deal with uncertainty and check for over...
Definition: Attributor.h:241
bool offsetAndSizeAreUnknown() const
Return true if offset and size are unknown, thus this is the default unknown object.
Definition: Attributor.h:256
static constexpr int64_t Unknown
Definition: Attributor.h:320
bool offsetOrSizeAreUnknown() const
Return true if offset or size are unknown.
Definition: Attributor.h:250
static constexpr int64_t Unassigned
Constants used to represent special offsets or sizes.
Definition: Attributor.h:319
RangeTy & operator&=(const RangeTy &R)
Definition: Attributor.h:279
static RangeTy getUnknown()
Definition: Attributor.h:247
bool isUnassigned() const
Return true if the offset and size are unassigned.
Definition: Attributor.h:261
static bool LessThan(const RangeTy &L, const RangeTy &R)
Comparison for sorting ranges.
Definition: Attributor.h:305
bool mayOverlap(const RangeTy &Range) const
Return true if this offset and size pair might describe an address that overlaps with Range.
Definition: Attributor.h:269
RangeTy(int64_t Offset, int64_t Size)
Definition: Attributor.h:245
Value * getValue() const
Definition: Attributor.h:194
std::pair< Value *, const Instruction * > Base
Definition: Attributor.h:189
ValueAndContext(Value &V, const Instruction *CtxI)
Definition: Attributor.h:191
const Instruction * getCtxI() const
Definition: Attributor.h:195
ValueAndContext(Value &V, const Instruction &CtxI)
Definition: Attributor.h:192
ValueAndContext(const Base &B)
Definition: Attributor.h:190
Base struct for all "concrete attribute" deductions.
Definition: Attributor.h:3322
static bool isValidIRPositionForInit(Attributor &A, const IRPosition &IRP)
Return false if an AA should not be created for IRP.
Definition: Attributor.h:3357
virtual ChangeStatus manifest(Attributor &A)
Hook for the Attributor to trigger the manifestation of the information represented by the abstract a...
Definition: Attributor.h:3437
static bool classof(const AADepGraphNode *DGN)
This function is used to identify if an DGN is of type AbstractAttribute so that the dyn_cast and cas...
Definition: Attributor.h:3339
static bool requiresCalleeForCallBase()
Return true if this AA requires a "callee" (or an associted function) for a call site positon.
Definition: Attributor.h:3347
void print(raw_ostream &OS) const
Helper functions, for debug purposes only.
Definition: Attributor.h:3406
IRPosition & getIRPosition()
Definition: Attributor.h:3402
virtual StateType & getState()=0
Return the internal abstract state for inspection.
virtual void initialize(Attributor &A)
Initialize the state with the information in the Attributor A.
Definition: Attributor.h:3386
static bool isValidIRPositionForUpdate(Attributor &A, const IRPosition &IRP)
Return false if an AA should not be updated for IRP.
Definition: Attributor.h:3362
virtual ~AbstractAttribute()=default
Virtual destructor.
virtual const std::string getAsStr(Attributor *A) const =0
This function should return the "summarized" assumed state as string.
virtual bool isQueryAA() const
A query AA is always scheduled as long as we do updates because it does lazy computation that cannot ...
Definition: Attributor.h:3394
virtual const StateType & getState() const =0
AbstractAttribute(const IRPosition &IRP)
Definition: Attributor.h:3325
static bool requiresNonAsmForCallBase()
Return true if this AA requires non-asm "callee" for a call site positon.
Definition: Attributor.h:3350
virtual ChangeStatus updateImpl(Attributor &A)=0
The actual update/transfer function which has to be implemented by the derived classes.
virtual void trackStatistics() const =0
Hook to enable custom statistic tracking, called after manifest that resulted in a change if statisti...
static bool requiresCallersForArgOrFunction()
Return true if this AA requires all callees for an argument or function positon.
Definition: Attributor.h:3354
virtual StringRef getName() const =0
This function should return the name of the AbstractAttribute.
const IRPosition & getIRPosition() const
Return an IR position, see struct IRPosition.
Definition: Attributor.h:3401
virtual const char * getIdAddr() const =0
This function should return the address of the ID of the AbstractAttribute.
static bool hasTrivialInitializer()
Return false if this AA does anything non-trivial (hence not done by default) in its initializer.
Definition: Attributor.h:3343
An interface to query the internal state of an abstract attribute.
Definition: Attributor.h:2642
virtual ~AbstractState()=default
virtual ChangeStatus indicatePessimisticFixpoint()=0
Indicate that the abstract state should converge to the pessimistic state.
virtual bool isAtFixpoint() const =0
Return if this abstract state is fixed, thus does not need to be updated if information changes as it...
virtual bool isValidState() const =0
Return if this abstract state is in a valid state.
virtual ChangeStatus indicateOptimisticFixpoint()=0
Indicate that the abstract state should converge to the optimistic state.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Wrapper for FunctionAnalysisManager.
Definition: Attributor.h:1134
AnalysisGetter()=default
static constexpr bool HasLegacyWrapper
Definition: Attributor.h:1147
Analysis::Result * getAnalysis(const Function &F, bool RequestCachedOnly=false)
Definition: Attributor.h:1150
AnalysisGetter(FunctionAnalysisManager &FAM, bool CachedOnly=false)
Definition: Attributor.h:1179
void invalidateAnalyses()
Invalidates the analyses. Valid only when using the new pass manager.
Definition: Attributor.h:1174
AnalysisGetter(Pass *P, bool CachedOnly=false)
Definition: Attributor.h:1181
LLVM_ABI PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
AACallEdgeIterator optimisticEdgesEnd() const override
Definition: Attributor.h:5597
AttributorCallGraph(Attributor &A)
Definition: Attributor.h:5590
AACallEdgeIterator optimisticEdgesBegin() const override
Definition: Attributor.h:5593
virtual ~AttributorCallGraph()=default
void populateAll() const
Force populate the entire call graph.
Definition: Attributor.h:5602
Configuration for the Attributor.
Definition: Attributor.h:1439
bool UseLiveness
Flag to determine if we should skip all liveness checks early on.
Definition: Attributor.h:1463
std::function< void(Attributor &A, const Function &F)> InitializationCallback
Callback function to be invoked on internal functions marked live.
Definition: Attributor.h:1470
std::optional< unsigned > MaxFixpointIterations
Maximum number of iterations to run until fixpoint.
Definition: Attributor.h:1486
DenseSet< const char * > * Allowed
If not null, a set limiting the attribute opportunities.
Definition: Attributor.h:1483
bool RewriteSignatures
Flag to determine if we rewrite function signatures.
Definition: Attributor.h:1456
const char * PassName
}
Definition: Attributor.h:1496
OptimizationRemarkGetter OREGetter
Definition: Attributor.h:1492
bool DeleteFns
Flag to determine if we can delete functions or keep dead ones around.
Definition: Attributor.h:1453
std::function< bool(const Function &F)> IPOAmendableCBTy
Definition: Attributor.h:1498
bool IsClosedWorldModule
Flag to indicate if the entire world is contained in this module, that is, no outside functions exist...
Definition: Attributor.h:1467
CallGraphUpdater & CGUpdater
Helper to update an underlying call graph and to delete functions.
Definition: Attributor.h:1480
IPOAmendableCBTy IPOAmendableCB
Definition: Attributor.h:1499
bool IsModulePass
Is the user of the Attributor a module pass or not.
Definition: Attributor.h:1450
std::function< bool(Attributor &A, const AbstractAttribute &AA, CallBase &CB, Function &AssumedCallee, unsigned NumAssumedCallees)> IndirectCalleeSpecializationCallback
Callback function to determine if an indirect call targets should be made direct call targets (with a...
Definition: Attributor.h:1477
bool DefaultInitializeLiveInternals
Flag to determine if we want to initialize all default AAs for an internal function marked live.
Definition: Attributor.h:1460
AttributorConfig(CallGraphUpdater &CGUpdater)
Definition: Attributor.h:1441
A more lightweight version of the Attributor which only runs attribute inference but no simplificatio...
Definition: Attributor.h:3495
LLVM_ABI PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
A more lightweight version of the Attributor which only runs attribute inference but no simplificatio...
Definition: Attributor.h:3488
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Helper struct used in the communication between an abstract attribute (AA) that wants to change the s...
Definition: Attributor.h:2245
std::function< void(const ArgumentReplacementInfo &, AbstractCallSite, SmallVectorImpl< Value * > &)> ACSRepairCBTy
Abstract call site (ACS) repair callback type.
Definition: Attributor.h:2268
const SmallVectorImpl< Type * > & getReplacementTypes() const
Definition: Attributor.h:2277
const Argument & getReplacedArg() const
Definition: Attributor.h:2275
Attributor & getAttributor() const
Simple getters, see the corresponding members for details.
Definition: Attributor.h:2273
std::function< void(const ArgumentReplacementInfo &, Function &, Function::arg_iterator)> CalleeRepairCBTy
Callee repair callback type.
Definition: Attributor.h:2254
const Function & getReplacedFn() const
Definition: Attributor.h:2274
The fixpoint analysis framework that orchestrates the attribute deduction.
Definition: Attributor.h:1533
LLVM_ABI bool registerFunctionSignatureRewrite(Argument &Arg, ArrayRef< Type * > ReplacementTypes, ArgumentReplacementInfo::CalleeRepairCBTy &&CalleeRepairCB, ArgumentReplacementInfo::ACSRepairCBTy &&ACSRepairCB)
Register a rewrite for a function signature.
AAType & registerAA(AAType &AA)
Introduce a new abstract attribute into the fixpoint analysis.
Definition: Attributor.h:1719
LLVM_ABI ~Attributor()
LLVM_ABI bool checkForAllCallees(function_ref< bool(ArrayRef< const Function * > Callees)> Pred, const AbstractAttribute &QueryingAA, const CallBase &CB)
Check Pred on all potential Callees of CB.
bool isModulePass() const
Return true if this is a module pass, false otherwise.
Definition: Attributor.h:1743
void registerInvokeWithDeadSuccessor(InvokeInst &II)
Record that II has at least one dead successor block.
Definition: Attributor.h:1903
void registerSimplificationCallback(const IRPosition &IRP, const SimplifictionCallbackTy &CB)
Definition: Attributor.h:2043
bool changeAfterManifest(const IRPosition IRP, Value &NV, bool ChangeDroppable=true)
Helper function to replace all uses associated with IRP with NV.
Definition: Attributor.h:1875
LLVM_ABI bool isValidFunctionSignatureRewrite(Argument &Arg, ArrayRef< Type * > ReplacementTypes)
Check if we can rewrite a function signature.
static LLVM_ABI bool isInternalizable(Function &F)
Returns true if the function F can be internalized.
LLVM_ABI ChangeStatus removeAttrs(const IRPosition &IRP, ArrayRef< Attribute::AttrKind > AttrKinds)
Remove all AttrKinds attached to IRP.
void emitRemark(Instruction *I, StringRef RemarkName, RemarkCallBack &&RemarkCB) const
Emit a remark generically.
Definition: Attributor.h:2201
bool isRunOn(Function &Fn) const
Return true if we derive attributes for Fn.
Definition: Attributor.h:1761
LLVM_ABI bool isAssumedDead(const AbstractAttribute &AA, const AAIsDead *LivenessAA, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, DepClassTy DepClass=DepClassTy::OPTIONAL)
Return true if AA (or its context instruction) is assumed dead.
LLVM_ABI bool checkForAllInstructions(function_ref< bool(Instruction &)> Pred, const Function *Fn, const AbstractAttribute *QueryingAA, ArrayRef< unsigned > Opcodes, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, bool CheckPotentiallyDead=false)
Check Pred on all instructions in Fn with an opcode present in Opcodes.
LLVM_ABI void recordDependence(const AbstractAttribute &FromAA, const AbstractAttribute &ToAA, DepClassTy DepClass)
Explicitly record a dependence from FromAA to ToAA, that is if FromAA changes ToAA should be updated ...
static LLVM_ABI void createShallowWrapper(Function &F)
Create a shallow wrapper for F such that F has internal linkage afterwards.
bool isRunOn(Function *Fn) const
Definition: Attributor.h:1762
const AAType * getAAFor(const AbstractAttribute &QueryingAA, const IRPosition &IRP, DepClassTy DepClass)
Lookup an abstract attribute of type AAType at position IRP.
Definition: Attributor.h:1577
std::optional< Constant * > getAssumedInitializerFromCallBack(const GlobalVariable &GV, const AbstractAttribute *AA, bool &UsedAssumedInformation)
Return std::nullopt if there is no call back registered for GV or the call back is still not sure if ...
Definition: Attributor.h:2074
void deleteAfterManifest(Function &F)
Record that F is deleted after information was manifested.
Definition: Attributor.h:1922
std::optional< Value * > getAssumedSimplified(const IRPosition &IRP, const AbstractAttribute &AA, bool &UsedAssumedInformation, AA::ValueScope S)
If V is assumed simplified, return it, if it is unclear yet, return std::nullopt, otherwise return nu...
Definition: Attributor.h:2002
void emitRemark(Function *F, StringRef RemarkName, RemarkCallBack &&RemarkCB) const
Emit a remark on a function.
Definition: Attributor.h:2222
static LLVM_ABI Function * internalizeFunction(Function &F, bool Force=false)
Make another copy of the function F such that the copied version has internal linkage afterwards and ...
bool isFunctionIPOAmendable(const Function &F)
Determine whether the function F is IPO amendable.
Definition: Attributor.h:1840
const AAType * getOrCreateAAFor(IRPosition IRP, const AbstractAttribute *QueryingAA, DepClassTy DepClass, bool ForceUpdate=false, bool UpdateAfterInit=true)
The version of getAAFor that allows to omit a querying abstract attribute.
Definition: Attributor.h:1589
const SmallSetVector< Function *, 8 > & getModifiedFunctions()
Definition: Attributor.h:2486
LLVM_ABI bool checkForAllReadWriteInstructions(function_ref< bool(Instruction &)> Pred, AbstractAttribute &QueryingAA, bool &UsedAssumedInformation)
Check Pred on all Read/Write instructions.
void changeToUnreachableAfterManifest(Instruction *I)
Record that I is to be replaced with unreachable after information was manifested.
Definition: Attributor.h:1896
bool hasGlobalVariableSimplificationCallback(const GlobalVariable &GV)
Return true if there is a simplification callback for GV.
Definition: Attributor.h:2066
std::function< std::optional< Constant * >(const GlobalVariable &, const AbstractAttribute *, bool &)> GlobalVariableSimplifictionCallbackTy
Register CB as a simplification callback.
Definition: Attributor.h:2058
std::optional< Constant * > getAssumedConstant(const Value &V, const AbstractAttribute &AA, bool &UsedAssumedInformation)
Definition: Attributor.h:1994
LLVM_ABI bool checkForAllReturnedValues(function_ref< bool(Value &)> Pred, const AbstractAttribute &QueryingAA, AA::ValueScope S=AA::ValueScope::Intraprocedural, bool RecurseForSelectAndPHI=true)
Check Pred on all values potentially returned by the function associated with QueryingAA.
bool hasSimplificationCallback(const IRPosition &IRP)
Return true if there is a simplification callback for IRP.
Definition: Attributor.h:2049
LLVM_ABI bool isClosedWorldModule() const
Return true if the module contains the whole world, thus, no outside functions exist.
LLVM_ABI std::optional< Constant * > getAssumedConstant(const IRPosition &IRP, const AbstractAttribute &AA, bool &UsedAssumedInformation)
If IRP is assumed to be a constant, return it, if it is unclear yet, return std::nullopt,...
const AAType * getOrCreateAAFor(const IRPosition &IRP)
Definition: Attributor.h:1659
void registerGlobalVariableSimplificationCallback(const GlobalVariable &GV, const GlobalVariableSimplifictionCallbackTy &CB)
Definition: Attributor.h:2059
const DataLayout & getDataLayout() const
Return the data layout associated with the anchor scope.
Definition: Attributor.h:2481
LLVM_ABI void getAttrs(const IRPosition &IRP, ArrayRef< Attribute::AttrKind > AKs, SmallVectorImpl< Attribute > &Attrs, bool IgnoreSubsumingPositions=false)
Return the attributes of any kind in AKs existing in the IR at a position that will affect this one.
InformationCache & getInfoCache()
Return the internal information cache.
Definition: Attributor.h:1740
bool changeUseAfterManifest(Use &U, Value &NV)
Record that U is to be replaces with NV after information was manifested.
Definition: Attributor.h:1861
LLVM_ABI std::optional< Value * > translateArgumentToCallSiteContent(std::optional< Value * > V, CallBase &CB, const AbstractAttribute &AA, bool &UsedAssumedInformation)
Translate V from the callee context into the call site context.
AAType * lookupAAFor(const IRPosition &IRP, const AbstractAttribute *QueryingAA=nullptr, DepClassTy DepClass=DepClassTy::OPTIONAL, bool AllowInvalidState=false)
Return the attribute of AAType for IRP if existing and valid.
Definition: Attributor.h:1667
void markLiveInternalFunction(const Function &F)
Mark the internal function F as live.
Definition: Attributor.h:1849
void registerManifestAddedBasicBlock(BasicBlock &BB)
Definition: Attributor.h:1917
void registerVirtualUseCallback(const Value &V, const VirtualUseCallbackTy &CB)
Definition: Attributor.h:2089
LLVM_ABI bool checkForAllUses(function_ref< bool(const Use &, bool &)> Pred, const AbstractAttribute &QueryingAA, const Value &V, bool CheckBBLivenessOnly=false, DepClassTy LivenessDepClass=DepClassTy::OPTIONAL, bool IgnoreDroppableUses=true, function_ref< bool(const Use &OldU, const Use &NewU)> EquivalentUseCB=nullptr)
Check Pred on all (transitive) uses of V.
LLVM_ABI ChangeStatus manifestAttrs(const IRPosition &IRP, ArrayRef< Attribute > DeducedAttrs, bool ForceReplace=false)
Attach DeducedAttrs to IRP, if ForceReplace is set we do this even if the same attribute kind was alr...
LLVM_ABI bool hasAttr(const IRPosition &IRP, ArrayRef< Attribute::AttrKind > AKs, bool IgnoreSubsumingPositions=false, Attribute::AttrKind ImpliedAttributeKind=Attribute::None)
Return true if any kind in AKs existing in the IR at a position that will affect this one.
LLVM_ABI void registerForUpdate(AbstractAttribute &AA)
Allows a query AA to request an update if a new query was received.
void deleteAfterManifest(Instruction &I)
Record that I is deleted after information was manifested.
Definition: Attributor.h:1909
void deleteAfterManifest(BasicBlock &BB)
Record that BB is deleted after information was manifested.
Definition: Attributor.h:1913
LLVM_ABI void identifyDefaultAbstractAttributes(Function &F)
Determine opportunities to derive 'default' attributes in F and create abstract attribute objects for...
bool shouldInitialize(const IRPosition &IRP, bool &ShouldUpdateAA)
Definition: Attributor.h:1802
LLVM_ABI bool getAssumedSimplifiedValues(const IRPosition &IRP, const AbstractAttribute *AA, SmallVectorImpl< AA::ValueAndContext > &Values, AA::ValueScope S, bool &UsedAssumedInformation, bool RecurseForSelectAndPHI=true)
Try to simplify IRP and in the scope S.
BumpPtrAllocator & Allocator
The allocator used to allocate memory, e.g. for AbstractAttributes.
Definition: Attributor.h:2484
std::function< bool(Attributor &, const AbstractAttribute *)> VirtualUseCallbackTy
Definition: Attributor.h:2088
bool checkForAllCallLikeInstructions(function_ref< bool(Instruction &)> Pred, const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, bool CheckPotentiallyDead=false)
Check Pred on all call-like instructions (=CallBased derived).
Definition: Attributor.h:2405
bool shouldSpecializeCallSiteForCallee(const AbstractAttribute &AA, CallBase &CB, Function &Callee, unsigned NumAssumedCallees)
Return true if we should specialize the call site CB for the potential callee Fn.
Definition: Attributor.h:1747
LLVM_ABI ChangeStatus run()
Run the analyses until a fixpoint is reached or enforced (timeout).
static LLVM_ABI bool internalizeFunctions(SmallPtrSetImpl< Function * > &FnSet, DenseMap< Function *, Function * > &FnMap)
Make copies of each function in the set FnSet such that the copied version has internal linkage after...
std::optional< Value * > getAssumedSimplified(const Value &V, const AbstractAttribute &AA, bool &UsedAssumedInformation, AA::ValueScope S)
Definition: Attributor.h:2008
bool shouldUpdateAA(const IRPosition &IRP)
Definition: Attributor.h:1766
std::function< std::optional< Value * >(const IRPosition &, const AbstractAttribute *, bool &)> SimplifictionCallbackTy
Register CB as a simplification callback.
Definition: Attributor.h:2042
LLVM_ABI bool checkForAllCallSites(function_ref< bool(AbstractCallSite)> Pred, const AbstractAttribute &QueryingAA, bool RequireAllCallSites, bool &UsedAssumedInformation)
Check Pred on all function call sites.
LLVM_ABI bool getAttrsFromAssumes(const IRPosition &IRP, Attribute::AttrKind AK, SmallVectorImpl< Attribute > &Attrs)
Return the attributes of kind AK existing in the IR as operand bundles of an llvm....
Specialization of the integer state for a bit-wise encoding.
Definition: Attributor.h:2783
BitIntegerState & removeKnownBits(base_t BitsEncoding)
Remove the bits in BitsEncoding from the "known bits".
Definition: Attributor.h:2813
bool isAssumed(base_t BitsEncoding=BestState) const
Return true if the bits set in BitsEncoding are "assumed bits".
Definition: Attributor.h:2795
BitIntegerState(base_t Assumed)
Definition: Attributor.h:2787
BitIntegerState & removeAssumedBits(base_t BitsEncoding)
Remove the bits in BitsEncoding from the "assumed bits" if not known.
Definition: Attributor.h:2808
BitIntegerState & intersectAssumedBits(base_t BitsEncoding)
Keep only "assumed bits" also set in BitsEncoding but all known ones.
Definition: Attributor.h:2819
bool isKnown(base_t BitsEncoding=BestState) const
Return true if the bits set in BitsEncoding are "known bits".
Definition: Attributor.h:2790
BitIntegerState & addKnownBits(base_t Bits)
Add the bits in BitsEncoding to the "known bits".
Definition: Attributor.h:2800
Simple wrapper for a single bit (boolean) state.
Definition: Attributor.h:2926
bool isKnown() const
Return true if the state is known to hold.
Definition: Attributor.h:2946
void setKnown(bool Value)
Set the known and asssumed value to Value.
Definition: Attributor.h:2937
IntegerStateBase::base_t base_t
Definition: Attributor.h:2928
BooleanState(base_t Assumed)
Definition: Attributor.h:2931
void setAssumed(bool Value)
Set the assumed value to Value but never below the known one.
Definition: Attributor.h:2934
BooleanState()=default
bool isAssumed() const
Return true if the state is assumed to hold.
Definition: Attributor.h:2943
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
static bool isNodeHidden(const AACallGraphNode *Node, const AttributorCallGraph *Graph)
Definition: Attributor.h:5653
std::string getNodeLabel(const AACallGraphNode *Node, const AttributorCallGraph *Graph)
Definition: Attributor.h:5647
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
Specialization of the integer state for a decreasing value, hence 0 is the best state and ~0u the wor...
Definition: Attributor.h:2892
DecIntegerState & takeKnownMinimum(base_t Value)
Take minimum of known and Value.
Definition: Attributor.h:2903
DecIntegerState & takeAssumedMaximum(base_t Value)
Take maximum of assumed and Value.
Definition: Attributor.h:2896
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
static DenormalMode unionAssumed(DenormalMode Callee, DenormalMode Caller)
Definition: Attributor.h:5214
DenormalState unionWith(DenormalState Caller) const
Definition: Attributor.h:5219
bool operator!=(const DenormalState Other) const
Definition: Attributor.h:5196
bool operator==(const DenormalState Other) const
Definition: Attributor.h:5192
static DenormalMode::DenormalModeKind unionDenormalKind(DenormalMode::DenormalModeKind Callee, DenormalMode::DenormalModeKind Caller)
Definition: Attributor.h:5203
bool IsAtFixedpoint
Explicitly track whether we've hit a fixed point.
Definition: Attributor.h:5230
ChangeStatus indicateOptimisticFixpoint() override
Indicate that the abstract state should converge to the optimistic state.
Definition: Attributor.h:5259
DenormalState getKnown() const
Definition: Attributor.h:5234
DenormalState getAssumed() const
Definition: Attributor.h:5238
bool isValidState() const override
Return if this abstract state is in a valid state.
Definition: Attributor.h:5240
ChangeStatus indicatePessimisticFixpoint() override
Indicate that the abstract state should converge to the pessimistic state.
Definition: Attributor.h:5263
DenormalFPMathState operator^=(const DenormalFPMathState &Caller)
Definition: Attributor.h:5267
ChangeStatus indicateFixpoint()
Definition: Attributor.h:5253
bool isModeFixed() const
Return true if there are no dynamic components to the denormal mode worth specializing.
Definition: Attributor.h:5244
bool isAtFixpoint() const override
Return if this abstract state is fixed, thus does not need to be updated if information changes as it...
Definition: Attributor.h:5251
Represent subnormal handling kind for floating point instruction inputs and outputs.
DenormalModeKind Input
Denormal treatment kind for floating point instruction inputs in the default floating-point environme...
DenormalModeKind
Represent handled modes for denormal (aka subnormal) modes in the floating point environment.
@ Dynamic
Denormals have unknown treatment.
static constexpr DenormalMode getInvalid()
DenormalModeKind Output
Denormal flushing mode for floating point instruction results in the default floating point environme...
static bool isEqual(const AA::ValueAndContext &LHS, const AA::ValueAndContext &RHS)
Definition: Attributor.h:432
static AA::ValueAndContext getEmptyKey()
Definition: Attributor.h:422
static unsigned getHashValue(const AA::ValueAndContext &VAC)
Definition: Attributor.h:428
static AA::ValueAndContext getTombstoneKey()
Definition: Attributor.h:425
static AA::ValueScope getTombstoneKey()
Definition: Attributor.h:444
static AA::ValueScope getEmptyKey()
Definition: Attributor.h:441
static bool isEqual(const AA::ValueScope &LHS, const AA::ValueScope &RHS)
Definition: Attributor.h:451
static unsigned getHashValue(const AA::ValueScope &S)
Definition: Attributor.h:447
static IRPosition getEmptyKey()
Definition: Attributor.h:1085
static IRPosition getTombstoneKey()
Definition: Attributor.h:1086
static bool isEqual(const IRPosition &a, const IRPosition &b)
Definition: Attributor.h:1094
static unsigned getHashValue(const IRPosition &IRP)
Definition: Attributor.h:1089
static unsigned getHashValue(const AA::InstExclusionSetTy *BES)
Definition: Attributor.h:467
static bool isEqual(const AA::InstExclusionSetTy *LHS, const AA::InstExclusionSetTy *RHS)
Definition: Attributor.h:474
static const AA::InstExclusionSetTy * getTombstoneKey()
Definition: Attributor.h:463
static const AA::InstExclusionSetTy * getEmptyKey()
Definition: Attributor.h:460
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:54
State for dereferenceable attribute.
Definition: Attributor.h:4123
IncIntegerState DerefBytesState
State representing for dereferenceable bytes.
Definition: Attributor.h:4139
static DerefState getBestState(const DerefState &)
Definition: Attributor.h:4126
static DerefState getWorstState()
Return the worst possible representable state.
Definition: Attributor.h:4129
static DerefState getBestState()
Definition: Attributor.h:4125
static DerefState getWorstState(const DerefState &)
Definition: Attributor.h:4134
std::map< int64_t, uint64_t > AccessedBytesMap
Map representing for accessed memory offsets and sizes.
Definition: Attributor.h:4147
static AACallEdgeIterator child_end(AACallGraphNode *Node)
Definition: Attributor.h:5620
static AACallEdgeIterator child_begin(AACallGraphNode *Node)
Definition: Attributor.h:5616
static AACallGraphNode * getEntryNode(AttributorCallGraph *G)
Definition: Attributor.h:5630
static AACallEdgeIterator nodes_begin(const AttributorCallGraph *G)
Definition: Attributor.h:5634
static AACallEdgeIterator nodes_end(const AttributorCallGraph *G)
Definition: Attributor.h:5638
Helper class that provides common functionality to manifest IR attributes.
Definition: Attributor.h:3227
Attribute::AttrKind getAttrKind() const
Return the kind that identifies the abstract attribute implementation.
Definition: Attributor.h:3270
static constexpr Attribute::AttrKind IRAttributeKind
Compile time access to the IR attribute kind.
Definition: Attributor.h:3236
static bool hasTrivialInitializer()
Most boolean IRAttribute AAs don't do anything non-trivial in their initializers while non-boolean on...
Definition: Attributor.h:3233
static bool isImpliedByUndef()
Return true if the IR attribute(s) associated with this AA are implied for an undef value.
Definition: Attributor.h:3240
ChangeStatus manifest(Attributor &A) override
See AbstractAttribute::manifest(...).
Definition: Attributor.h:3259
static bool isImpliedByPoison()
Return true if the IR attribute(s) associated with this AA are implied for an poison value.
Definition: Attributor.h:3244
static bool isImpliedByIR(Attributor &A, const IRPosition &IRP, Attribute::AttrKind ImpliedAttributeKind=AK, bool IgnoreSubsumingPositions=false)
Definition: Attributor.h:3246
IRAttribute(const IRPosition &IRP)
Definition: Attributor.h:3228
virtual void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, SmallVectorImpl< Attribute > &Attrs) const
Return the deduced attributes in Attrs.
Definition: Attributor.h:3273
Helper to describe and deal with positions in the LLVM-IR.
Definition: Attributor.h:593
Function * getAssociatedFunction() const
Return the associated function, if any.
Definition: Attributor.h:724
void setAttrList(const AttributeList &AttrList) const
Update the attributes associated with this function or call site scope.
Definition: Attributor.h:860
unsigned getAttrIdx() const
Return the index in the attribute list for this position.
Definition: Attributor.h:825
bool hasCallBaseContext() const
Check if the position has any call base context.
Definition: Attributor.h:942
static const IRPosition callsite_returned(const CallBase &CB)
Create a position describing the returned value of CB.
Definition: Attributor.h:661
static const IRPosition returned(const Function &F, const CallBaseContext *CBContext=nullptr)
Create a position describing the returned value of F.
Definition: Attributor.h:643
LLVM_ABI Argument * getAssociatedArgument() const
Return the associated argument, if any.
bool isAnyCallSitePosition() const
Definition: Attributor.h:909
bool operator!=(const IRPosition &RHS) const
Definition: Attributor.h:702
static const IRPosition value(const Value &V, const CallBaseContext *CBContext=nullptr)
Create a position describing the value of V.
Definition: Attributor.h:617
CallBase CallBaseContext
Definition: Attributor.h:596
AttributeList getAttrList() const
Return the attributes associated with this function or call site scope.
Definition: Attributor.h:853
int getCalleeArgNo() const
Return the callee argument number of the associated value if it is an argument or call site argument,...
Definition: Attributor.h:811
static const IRPosition inst(const Instruction &I, const CallBaseContext *CBContext=nullptr)
Create a position describing the instruction I.
Definition: Attributor.h:629
static const IRPosition callsite_argument(const CallBase &CB, unsigned ArgNo)
Create a position describing the argument of CB at position ArgNo.
Definition: Attributor.h:666
static LLVM_ABI const IRPosition TombstoneKey
Definition: Attributor.h:948
Kind
The positions we distinguish in the IR.
Definition: Attributor.h:599
@ IRP_ARGUMENT
An attribute for a function argument.
Definition: Attributor.h:607
@ IRP_RETURNED
An attribute for the function return value.
Definition: Attributor.h:603
@ IRP_CALL_SITE
An attribute for a call site (function scope).
Definition: Attributor.h:606
@ IRP_CALL_SITE_RETURNED
An attribute for a call site return value.
Definition: Attributor.h:604
@ IRP_FUNCTION
An attribute for a function (scope).
Definition: Attributor.h:605
@ IRP_FLOAT
A position that is not associated with a spot suitable for attributes.
Definition: Attributor.h:601
@ IRP_CALL_SITE_ARGUMENT
An attribute for a call site argument.
Definition: Attributor.h:608
@ IRP_INVALID
An invalid position.
Definition: Attributor.h:600
Instruction * getCtxI() const
Return the context instruction, if any.
Definition: Attributor.h:777
static const IRPosition argument(const Argument &Arg, const CallBaseContext *CBContext=nullptr)
Create a position describing the argument Arg.
Definition: Attributor.h:650
Type * getAssociatedType() const
Return the type this abstract attribute is associated with.
Definition: Attributor.h:800
static LLVM_ABI const IRPosition EmptyKey
Special DenseMap key values.
Definition: Attributor.h:947
bool isFunctionScope() const
Return true if this is a function or call site position.
Definition: Attributor.h:754
bool operator==(const IRPosition &RHS) const
Definition: Attributor.h:699
static const IRPosition callsite_argument(AbstractCallSite ACS, unsigned ArgNo)
Create a position describing the argument of ACS at position ArgNo.
Definition: Attributor.h:673
static const IRPosition function(const Function &F, const CallBaseContext *CBContext=nullptr)
Create a position describing the function scope of F.
Definition: Attributor.h:636
const CallBaseContext * getCallBaseContext() const
Get the call base context from the position.
Definition: Attributor.h:939
Value & getAssociatedValue() const
Return the value this abstract attribute is associated with.
Definition: Attributor.h:791
Value * getArg(unsigned ArgNo) const
Return theargument ArgNo associated with this function or call site scope.
Definition: Attributor.h:879
Value & getAnchorValue() const
Return the value this abstract attribute is anchored with.
Definition: Attributor.h:710
Value * getAttrListAnchor() const
Return the value attributes are attached to.
Definition: Attributor.h:846
int getCallSiteArgNo() const
Return the call site argument number of the associated value if it is an argument or call site argume...
Definition: Attributor.h:820
bool isFnInterfaceKind() const
Return true if the position refers to a function interface, that is the function scope,...
Definition: Attributor.h:742
static const IRPosition function_scope(const IRPosition &IRP, const CallBaseContext *CBContext=nullptr)
Create a position with function scope matching the "context" of IRP.
Definition: Attributor.h:689
IRPosition stripCallBaseContext() const
Return the same position without the call base context.
Definition: Attributor.h:932
unsigned getNumArgs() const
Return the number of arguments associated with this function or call site scope.
Definition: Attributor.h:868
Kind getPositionKind() const
Return the associated position kind.
Definition: Attributor.h:889
bool isArgumentPosition() const
Return true if the position is an argument or call site argument.
Definition: Attributor.h:921
static const IRPosition callsite_function(const CallBase &CB)
Create a position describing the function scope of CB.
Definition: Attributor.h:656
IRPosition()
Default constructor available to create invalid positions implicitly.
Definition: Attributor.h:614
Function * getAnchorScope() const
Return the Function surrounding the anchor value.
Definition: Attributor.h:765
Specialization of the integer state for an increasing value, hence ~0u is the best state and 0 the wo...
Definition: Attributor.h:2845
static constexpr base_t getBestState(const IncIntegerState< base_ty, BestState, WorstState > &)
Definition: Attributor.h:2855
IncIntegerState(base_t Assumed)
Definition: Attributor.h:2850
static constexpr base_t getBestState()
Return the best possible representable state.
Definition: Attributor.h:2853
IncIntegerState & takeAssumedMinimum(base_t Value)
Take minimum of assumed and Value.
Definition: Attributor.h:2860
IncIntegerState & takeKnownMaximum(base_t Value)
Take maximum of known and Value.
Definition: Attributor.h:2867
Data structure to hold cached (LLVM-IR) information.
Definition: Attributor.h:1210
const SetVector< Function * > *const CGSCC
The CG-SCC the pass is run on, or nullptr if it is a module pass.
Definition: Attributor.h:1269
bool stackIsAccessibleByOtherThreads()
Return true if the stack (llvm::Alloca) can be accessed by other threads.
Definition: Attributor.h:1346
bool targetIsGPU()
Return true if the target is a GPU.
Definition: Attributor.h:1349
bool isInvolvedInMustTailCall(const Argument &Arg)
Return true if Arg is involved in a must-tail call, thus the argument of the caller or callee.
Definition: Attributor.h:1306
const DataLayout & getDL()
Return datalayout used in the module.
Definition: Attributor.h:1327
MustBeExecutedContextExplorer * getMustBeExecutedContextExplorer()
Return MustBeExecutedContextExplorer.
Definition: Attributor.h:1289
void invalidateAnalyses()
Invalidates the cached analyses.
Definition: Attributor.h:1317
virtual ~InformationCache()
Definition: Attributor.h:1233
virtual unsigned getMaxAddrSpace() const
Definition: Attributor.h:1359
const AA::InstExclusionSetTy * getOrCreateUniqueBlockExecutionSet(const AA::InstExclusionSetTy *BES)
Given BES, return a uniqued version.
Definition: Attributor.h:1334
static void foreachUse(Function &F, CBTy CB, bool LookThroughConstantExprUses=true)
Apply CB to all uses of F.
Definition: Attributor.h:1250
TargetLibraryInfo * getTargetLibraryInfoForFunction(const Function &F)
Return TargetLibraryInfo for function F.
Definition: Attributor.h:1294
InformationCache(const Module &M, AnalysisGetter &AG, BumpPtrAllocator &Allocator, SetVector< Function * > *CGSCC, bool UseExplorer=true)
Definition: Attributor.h:1211
LLVM_ABI std::optional< unsigned > getFlatAddressSpace() const
Return the flat address space if the associated target has.
OpcodeInstMapTy & getOpcodeInstMapForFunction(const Function &F)
Return the map that relates "interesting" opcodes with all instructions with that opcode in F.
Definition: Attributor.h:1279
DenseMap< unsigned, InstructionVectorTy * > OpcodeInstMapTy
A map type from opcodes to instructions with this opcode.
Definition: Attributor.h:1275
const RetainedKnowledgeMap & getKnowledgeMap() const
Return the map conaining all the knowledge we have from llvm.assumes.
Definition: Attributor.h:1330
LLVM_ABI ArrayRef< Function * > getIndirectlyCallableFunctions(Attributor &A) const
Return all functions that might be called indirectly, only valid for closed world modules (see isClos...
SmallVector< Instruction *, 8 > InstructionVectorTy
A vector type to hold instructions.
Definition: Attributor.h:1272
InstructionVectorTy & getReadOrWriteInstsForFunction(const Function &F)
Return the instructions in F that may read or write memory.
Definition: Attributor.h:1284
bool isOnlyUsedByAssume(const Instruction &I) const
Definition: Attributor.h:1311
bool isKernel(const Function &F)
Return true if F has the "kernel" function attribute.
Definition: Attributor.h:1299
AP::Result * getAnalysisResultForFunction(const Function &F, bool CachedOnly=false)
Return the analysis result from a pass AP for function F.
Definition: Attributor.h:1321
State for an integer range.
Definition: Attributor.h:2968
IntegerRangeState operator^=(const IntegerRangeState &R)
"Clamp" this state with R.
Definition: Attributor.h:3059
IntegerRangeState operator&=(const IntegerRangeState &R)
Definition: Attributor.h:3066
bool isAtFixpoint() const override
See AbstractState::isAtFixpoint()
Definition: Attributor.h:3009
void unionAssumed(const IntegerRangeState &R)
See IntegerRangeState::unionAssumed(..).
Definition: Attributor.h:3036
ConstantRange Assumed
State representing assumed range, initially set to empty.
Definition: Attributor.h:2974
IntegerRangeState(const ConstantRange &CR)
Definition: Attributor.h:2983
IntegerRangeState(uint32_t BitWidth)
Definition: Attributor.h:2979
bool operator==(const IntegerRangeState &R) const
Equality for IntegerRangeState.
Definition: Attributor.h:3052
void intersectKnown(const IntegerRangeState &R)
See IntegerRangeState::intersectKnown(..).
Definition: Attributor.h:3047
static ConstantRange getBestState(const IntegerRangeState &IRS)
Definition: Attributor.h:2996
bool isValidState() const override
See AbstractState::isValidState()
Definition: Attributor.h:3004
uint32_t BitWidth
Bitwidth of the associated value.
Definition: Attributor.h:2971
ConstantRange Known
State representing known range, initially set to [-inf, inf].
Definition: Attributor.h:2977
void unionAssumed(const ConstantRange &R)
Unite assumed range with the passed state.
Definition: Attributor.h:3030
ChangeStatus indicatePessimisticFixpoint() override
See AbstractState::indicatePessimisticFixpoint(...)
Definition: Attributor.h:3018
ConstantRange getKnown() const
Return the known state encoding.
Definition: Attributor.h:3024
void intersectKnown(const ConstantRange &R)
Intersect known range with the passed state.
Definition: Attributor.h:3041
ConstantRange getAssumed() const
Return the assumed state encoding.
Definition: Attributor.h:3027
uint32_t getBitWidth() const
Return associated values' bit width.
Definition: Attributor.h:3001
ChangeStatus indicateOptimisticFixpoint() override
See AbstractState::indicateOptimisticFixpoint(...)
Definition: Attributor.h:3012
static ConstantRange getWorstState(uint32_t BitWidth)
Return the worst possible representable state.
Definition: Attributor.h:2988
static ConstantRange getBestState(uint32_t BitWidth)
Return the best possible representable state.
Definition: Attributor.h:2993
Simple state with integers encoding.
Definition: Attributor.h:2681
bool isValidState() const override
See AbstractState::isValidState() NOTE: For now we simply pretend that the worst possible state is in...
Definition: Attributor.h:2701
virtual void handleNewAssumedValue(base_t Value)=0
Handle a new assumed value Value. Subtype dependent.
bool isAtFixpoint() const override
See AbstractState::isAtFixpoint()
Definition: Attributor.h:2704
void operator|=(const IntegerStateBase< base_t, BestState, WorstState > &R)
Definition: Attributor.h:2751
virtual void handleNewKnownValue(base_t Value)=0
Handle a new known value Value. Subtype dependent.
base_t getKnown() const
Return the known state encoding.
Definition: Attributor.h:2719
ChangeStatus indicateOptimisticFixpoint() override
See AbstractState::indicateOptimisticFixpoint(...)
Definition: Attributor.h:2707
void operator^=(const IntegerStateBase< base_t, BestState, WorstState > &R)
"Clamp" this state with R.
Definition: Attributor.h:2740
virtual void joinOR(base_t AssumedValue, base_t KnownValue)=0
Handle a value Value. Subtype dependent.
virtual void joinAND(base_t AssumedValue, base_t KnownValue)=0
Handle a new assumed value Value. Subtype dependent.
IntegerStateBase(base_t Assumed)
Definition: Attributor.h:2685
void operator+=(const IntegerStateBase< base_t, BestState, WorstState > &R)
"Clamp" this state with R.
Definition: Attributor.h:2747
base_t getAssumed() const
Return the assumed state encoding.
Definition: Attributor.h:2722
static constexpr base_t getWorstState()
Return the worst possible representable state.
Definition: Attributor.h:2694
static constexpr base_t getBestState()
Return the best possible representable state.
Definition: Attributor.h:2688
ChangeStatus indicatePessimisticFixpoint() override
See AbstractState::indicatePessimisticFixpoint(...)
Definition: Attributor.h:2713
base_t Known
The known state encoding in an integer of type base_t.
Definition: Attributor.h:2773
static constexpr base_t getWorstState(const IntegerStateBase &)
Definition: Attributor.h:2695
bool operator!=(const IntegerStateBase< base_t, BestState, WorstState > &R) const
Inequality for IntegerStateBase.
Definition: Attributor.h:2733
bool operator==(const IntegerStateBase< base_t, BestState, WorstState > &R) const
Equality for IntegerStateBase.
Definition: Attributor.h:2726
void operator&=(const IntegerStateBase< base_t, BestState, WorstState > &R)
Definition: Attributor.h:2755
base_t Assumed
The assumed state encoding in an integer of type base_t.
Definition: Attributor.h:2776
static constexpr base_t getBestState(const IntegerStateBase &)
Definition: Attributor.h:2689
A "must be executed context" for a given program point PP is the set of instructions,...
Definition: MustExecute.h:388
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:70
A class for a set state.
Definition: Attributor.h:5013
static PotentialValuesState getBestState(const PotentialValuesState &PVS)
Definition: Attributor.h:5073
PotentialValuesState & getAssumed()
Return the assumed state.
Definition: Attributor.h:5038
static unsigned MaxPotentialValues
Maximum number of potential values to be tracked.
Definition: Attributor.h:5066
bool undefIsContained() const
Returns whether this state contains an undef value or not.
Definition: Attributor.h:5049
bool contains(const MemberTy &V) const
Definition: Attributor.h:5104
bool isAtFixpoint() const override
See AbstractState::isAtFixpoint(...)
Definition: Attributor.h:5025
void unionAssumed(const MemberTy &C)
Union assumed set with the passed value.
Definition: Attributor.h:5083
static PotentialValuesState getBestState()
Return empty set as the best state of potential values.
Definition: Attributor.h:5069
SmallSetVector< MemberTy, 8 > SetTy
Definition: Attributor.h:5014
ChangeStatus indicatePessimisticFixpoint() override
See AbstractState::indicatePessimisticFixpoint(...)
Definition: Attributor.h:5028
void unionAssumed(const PotentialValuesState &PVS)
Union assumed set with assumed set of the passed state PVS.
Definition: Attributor.h:5086
PotentialValuesState(bool IsValid)
Definition: Attributor.h:5018
bool operator==(const PotentialValuesState &RHS) const
Definition: Attributor.h:5054
bool isValidState() const override
See AbstractState::isValidState(...)
Definition: Attributor.h:5022
PotentialValuesState operator&=(const PotentialValuesState &PVS)
Definition: Attributor.h:5098
static PotentialValuesState getWorstState()
Return full set as the worst state of potential values.
Definition: Attributor.h:5078
const PotentialValuesState & getAssumed() const
Definition: Attributor.h:5039
ChangeStatus indicateOptimisticFixpoint() override
See AbstractState::indicateOptimisticFixpoint(...)
Definition: Attributor.h:5033
PotentialValuesState operator^=(const PotentialValuesState &PVS)
"Clamp" this state with PVS.
Definition: Attributor.h:5092
void unionAssumedWithUndef()
Union assumed set with an undef value.
Definition: Attributor.h:5089
const SetTy & getAssumedSet() const
Return this set.
Definition: Attributor.h:5043
A wrapper around a set that has semantics for handling unions and intersections with a "universal" se...
Definition: Attributor.h:3083
SetContents(bool Universal)
Creates a universal set with no concrete elements or an empty set.
Definition: Attributor.h:3085
SetContents(bool Universal, const DenseSet< BaseTy > &Assumptions)
Definition: Attributor.h:3091
bool getIntersection(const SetContents &RHS)
Finds A := A ^ B where A or B could be the "Universal" set which contains every possible attribute.
Definition: Attributor.h:3102
bool getUnion(const SetContents &RHS)
Finds A := A u B where A or B could be the "Universal" set which contains every possible attribute.
Definition: Attributor.h:3122
const DenseSet< BaseTy > & getSet() const
Definition: Attributor.h:3094
SetContents(const DenseSet< BaseTy > &Assumptions)
Creates a non-universal set with concrete values.
Definition: Attributor.h:3088
Simple state for a set.
Definition: Attributor.h:3080
bool setContains(const BaseTy &Elem) const
Returns if the set state contains the element.
Definition: Attributor.h:3176
bool getIntersection(const SetContents &RHS)
Performs the set intersection between this set and RHS.
Definition: Attributor.h:3182
bool isValidState() const override
See AbstractState::isValidState()
Definition: Attributor.h:3150
bool isAtFixpoint() const override
See AbstractState::isAtFixpoint()
Definition: Attributor.h:3153
const SetContents & getAssumed() const
Return the assumed state encoding.
Definition: Attributor.h:3173
const SetContents & getKnown() const
Return the known state encoding.
Definition: Attributor.h:3170
ChangeStatus indicateOptimisticFixpoint() override
See AbstractState::indicateOptimisticFixpoint(...)
Definition: Attributor.h:3156
bool getUnion(const SetContents &RHS)
Performs the set union between this set and RHS.
Definition: Attributor.h:3197
SetState(const DenseSet< BaseTy > &Known)
Initializes the known state with an initial set and initializes the assumed state as universal.
Definition: Attributor.h:3146
ChangeStatus indicatePessimisticFixpoint() override
See AbstractState::indicatePessimisticFixpoint(...)
Definition: Attributor.h:3163
Helper to tie a abstract state implementation to an abstract attribute.
Definition: Attributor.h:3211
StateType & getState() override
See AbstractAttribute::getState(...).
Definition: Attributor.h:3219
StateWrapper(const IRPosition &IRP, Ts... Args)
Definition: Attributor.h:3215
const StateType & getState() const override
See AbstractAttribute::getState(...).
Definition: Attributor.h:3222
static ValueSimplifyStateType getWorstState(Type *Ty)
Return the worst possible representable state.
Definition: Attributor.h:4492
static ValueSimplifyStateType getBestState(const ValueSimplifyStateType &VS)
Definition: Attributor.h:4487
LLVM_ABI bool unionAssumed(std::optional< Value * > Other)
Merge Other into the currently assumed simplified value.
ChangeStatus indicateOptimisticFixpoint() override
See AbstractState::indicateOptimisticFixpoint(...)
Definition: Attributor.h:4518
ValueSimplifyStateType operator^=(const ValueSimplifyStateType &VS)
"Clamp" this state with PVS.
Definition: Attributor.h:4523
ChangeStatus indicatePessimisticFixpoint() override
See AbstractState::indicatePessimisticFixpoint(...)
Definition: Attributor.h:4513
static ValueSimplifyStateType getBestState(Type *Ty)
Definition: Attributor.h:4484
bool isAtFixpoint() const override
See AbstractState::isAtFixpoint(...)
Definition: Attributor.h:4506
bool isValidState() const override
See AbstractState::isValidState(...)
Definition: Attributor.h:4503
std::optional< Value * > SimplifiedAssociatedValue
An assumed simplified value.
Definition: Attributor.h:4551
static ValueSimplifyStateType getWorstState(const ValueSimplifyStateType &VS)
Definition: Attributor.h:4498
BooleanState BS
Helper to track validity and fixpoint.
Definition: Attributor.h:4545
Type * Ty
The type of the original value.
Definition: Attributor.h:4539
bool operator==(const ValueSimplifyStateType &RHS) const
Definition: Attributor.h:4529
ValueSimplifyStateType getAssumed()
Return the assumed state encoding.
Definition: Attributor.h:4509
const ValueSimplifyStateType & getAssumed() const
Definition: Attributor.h:4510