LLVM 17.0.0git
Metadata.h
Go to the documentation of this file.
1//===- llvm/IR/Metadata.h - Metadata definitions ----------------*- 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/// @file
10/// This file contains the declarations for metadata subclasses.
11/// They represent the different flavors of metadata that live in LLVM.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_IR_METADATA_H
16#define LLVM_IR_METADATA_H
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/DenseMap.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/ADT/ilist_node.h"
26#include "llvm/IR/Constant.h"
27#include "llvm/IR/LLVMContext.h"
28#include "llvm/IR/Value.h"
32#include <cassert>
33#include <cstddef>
34#include <cstdint>
35#include <iterator>
36#include <memory>
37#include <string>
38#include <type_traits>
39#include <utility>
40
41namespace llvm {
42
43class Module;
44class ModuleSlotTracker;
45class raw_ostream;
46template <typename T> class StringMapEntry;
47template <typename ValueTy> class StringMapEntryStorage;
48class Type;
49
51 DEBUG_METADATA_VERSION = 3 // Current debug info version number.
52};
53
54/// Magic number in the value profile metadata showing a target has been
55/// promoted for the instruction and shouldn't be promoted again.
57
58/// Root of the metadata hierarchy.
59///
60/// This is a root class for typeless data in the IR.
61class Metadata {
63
64 /// RTTI.
65 const unsigned char SubclassID;
66
67protected:
68 /// Active type of storage.
70
71 /// Storage flag for non-uniqued, otherwise unowned, metadata.
72 unsigned char Storage : 7;
73
74 unsigned char SubclassData1 : 1;
75 unsigned short SubclassData16 = 0;
76 unsigned SubclassData32 = 0;
77
78public:
80#define HANDLE_METADATA_LEAF(CLASS) CLASS##Kind,
81#include "llvm/IR/Metadata.def"
82 };
83
84protected:
86 : SubclassID(ID), Storage(Storage), SubclassData1(false) {
87 static_assert(sizeof(*this) == 8, "Metadata fields poorly packed");
88 }
89
90 ~Metadata() = default;
91
92 /// Default handling of a changed operand, which asserts.
93 ///
94 /// If subclasses pass themselves in as owners to a tracking node reference,
95 /// they must provide an implementation of this method.
97 llvm_unreachable("Unimplemented in Metadata subclass");
98 }
99
100public:
101 unsigned getMetadataID() const { return SubclassID; }
102
103 /// User-friendly dump.
104 ///
105 /// If \c M is provided, metadata nodes will be numbered canonically;
106 /// otherwise, pointer addresses are substituted.
107 ///
108 /// Note: this uses an explicit overload instead of default arguments so that
109 /// the nullptr version is easy to call from a debugger.
110 ///
111 /// @{
112 void dump() const;
113 void dump(const Module *M) const;
114 /// @}
115
116 /// Print.
117 ///
118 /// Prints definition of \c this.
119 ///
120 /// If \c M is provided, metadata nodes will be numbered canonically;
121 /// otherwise, pointer addresses are substituted.
122 /// @{
123 void print(raw_ostream &OS, const Module *M = nullptr,
124 bool IsForDebug = false) const;
125 void print(raw_ostream &OS, ModuleSlotTracker &MST, const Module *M = nullptr,
126 bool IsForDebug = false) const;
127 /// @}
128
129 /// Print as operand.
130 ///
131 /// Prints reference of \c this.
132 ///
133 /// If \c M is provided, metadata nodes will be numbered canonically;
134 /// otherwise, pointer addresses are substituted.
135 /// @{
136 void printAsOperand(raw_ostream &OS, const Module *M = nullptr) const;
138 const Module *M = nullptr) const;
139 /// @}
140};
141
142// Create wrappers for C Binding types (see CBindingWrapping.h).
144
145// Specialized opaque metadata conversions.
147 return reinterpret_cast<Metadata**>(MDs);
148}
149
150#define HANDLE_METADATA(CLASS) class CLASS;
151#include "llvm/IR/Metadata.def"
152
153// Provide specializations of isa so that we don't need definitions of
154// subclasses to see if the metadata is a subclass.
155#define HANDLE_METADATA_LEAF(CLASS) \
156 template <> struct isa_impl<CLASS, Metadata> { \
157 static inline bool doit(const Metadata &MD) { \
158 return MD.getMetadataID() == Metadata::CLASS##Kind; \
159 } \
160 };
161#include "llvm/IR/Metadata.def"
162
164 MD.print(OS);
165 return OS;
166}
167
168/// Metadata wrapper in the Value hierarchy.
169///
170/// A member of the \a Value hierarchy to represent a reference to metadata.
171/// This allows, e.g., intrinsics to have metadata as operands.
172///
173/// Notably, this is the only thing in either hierarchy that is allowed to
174/// reference \a LocalAsMetadata.
175class MetadataAsValue : public Value {
177 friend class LLVMContextImpl;
178
179 Metadata *MD;
180
181 MetadataAsValue(Type *Ty, Metadata *MD);
182
183 /// Drop use of metadata (during teardown).
184 void dropUse() { MD = nullptr; }
185
186public:
188
189 static MetadataAsValue *get(LLVMContext &Context, Metadata *MD);
190 static MetadataAsValue *getIfExists(LLVMContext &Context, Metadata *MD);
191
192 Metadata *getMetadata() const { return MD; }
193
194 static bool classof(const Value *V) {
195 return V->getValueID() == MetadataAsValueVal;
196 }
197
198private:
199 void handleChangedMetadata(Metadata *MD);
200 void track();
201 void untrack();
202};
203
204/// API for tracking metadata references through RAUW and deletion.
205///
206/// Shared API for updating \a Metadata pointers in subclasses that support
207/// RAUW.
208///
209/// This API is not meant to be used directly. See \a TrackingMDRef for a
210/// user-friendly tracking reference.
212public:
213 /// Track the reference to metadata.
214 ///
215 /// Register \c MD with \c *MD, if the subclass supports tracking. If \c *MD
216 /// gets RAUW'ed, \c MD will be updated to the new address. If \c *MD gets
217 /// deleted, \c MD will be set to \c nullptr.
218 ///
219 /// If tracking isn't supported, \c *MD will not change.
220 ///
221 /// \return true iff tracking is supported by \c MD.
222 static bool track(Metadata *&MD) {
223 return track(&MD, *MD, static_cast<Metadata *>(nullptr));
224 }
225
226 /// Track the reference to metadata for \a Metadata.
227 ///
228 /// As \a track(Metadata*&), but with support for calling back to \c Owner to
229 /// tell it that its operand changed. This could trigger \c Owner being
230 /// re-uniqued.
231 static bool track(void *Ref, Metadata &MD, Metadata &Owner) {
232 return track(Ref, MD, &Owner);
233 }
234
235 /// Track the reference to metadata for \a MetadataAsValue.
236 ///
237 /// As \a track(Metadata*&), but with support for calling back to \c Owner to
238 /// tell it that its operand changed. This could trigger \c Owner being
239 /// re-uniqued.
240 static bool track(void *Ref, Metadata &MD, MetadataAsValue &Owner) {
241 return track(Ref, MD, &Owner);
242 }
243
244 /// Stop tracking a reference to metadata.
245 ///
246 /// Stops \c *MD from tracking \c MD.
247 static void untrack(Metadata *&MD) { untrack(&MD, *MD); }
248 static void untrack(void *Ref, Metadata &MD);
249
250 /// Move tracking from one reference to another.
251 ///
252 /// Semantically equivalent to \c untrack(MD) followed by \c track(New),
253 /// except that ownership callbacks are maintained.
254 ///
255 /// Note: it is an error if \c *MD does not equal \c New.
256 ///
257 /// \return true iff tracking is supported by \c MD.
258 static bool retrack(Metadata *&MD, Metadata *&New) {
259 return retrack(&MD, *MD, &New);
260 }
261 static bool retrack(void *Ref, Metadata &MD, void *New);
262
263 /// Check whether metadata is replaceable.
264 static bool isReplaceable(const Metadata &MD);
265
267
268private:
269 /// Track a reference to metadata for an owner.
270 ///
271 /// Generalized version of tracking.
272 static bool track(void *Ref, Metadata &MD, OwnerTy Owner);
273};
274
275/// Shared implementation of use-lists for replaceable metadata.
276///
277/// Most metadata cannot be RAUW'ed. This is a shared implementation of
278/// use-lists and associated API for the two that support it (\a ValueAsMetadata
279/// and \a TempMDNode).
281 friend class MetadataTracking;
282
283public:
285
286private:
287 LLVMContext &Context;
288 uint64_t NextIndex = 0;
290
291public:
293
295 assert(UseMap.empty() && "Cannot destroy in-use replaceable metadata");
296 }
297
298 LLVMContext &getContext() const { return Context; }
299
300 /// Replace all uses of this with MD.
301 ///
302 /// Replace all uses of this with \c MD, which is allowed to be null.
304 /// Replace all uses of the constant with Undef in debug info metadata
305 static void SalvageDebugInfo(const Constant &C);
306 /// Returns the list of all DIArgList users of this.
308
309 /// Resolve all uses of this.
310 ///
311 /// Resolve all uses of this, turning off RAUW permanently. If \c
312 /// ResolveUsers, call \a MDNode::resolve() on any users whose last operand
313 /// is resolved.
314 void resolveAllUses(bool ResolveUsers = true);
315
316private:
317 void addRef(void *Ref, OwnerTy Owner);
318 void dropRef(void *Ref);
319 void moveRef(void *Ref, void *New, const Metadata &MD);
320
321 /// Lazily construct RAUW support on MD.
322 ///
323 /// If this is an unresolved MDNode, RAUW support will be created on-demand.
324 /// ValueAsMetadata always has RAUW support.
325 static ReplaceableMetadataImpl *getOrCreate(Metadata &MD);
326
327 /// Get RAUW support on MD, if it exists.
328 static ReplaceableMetadataImpl *getIfExists(Metadata &MD);
329
330 /// Check whether this node will support RAUW.
331 ///
332 /// Returns \c true unless getOrCreate() would return null.
333 static bool isReplaceable(const Metadata &MD);
334};
335
336/// Value wrapper in the Metadata hierarchy.
337///
338/// This is a custom value handle that allows other metadata to refer to
339/// classes in the Value hierarchy.
340///
341/// Because of full uniquing support, each value is only wrapped by a single \a
342/// ValueAsMetadata object, so the lookup maps are far more efficient than
343/// those using ValueHandleBase.
346 friend class LLVMContextImpl;
347
348 Value *V;
349
350 /// Drop users without RAUW (during teardown).
351 void dropUsers() {
352 ReplaceableMetadataImpl::resolveAllUses(/* ResolveUsers */ false);
353 }
354
355protected:
358 assert(V && "Expected valid value");
359 }
360
361 ~ValueAsMetadata() = default;
362
363public:
364 static ValueAsMetadata *get(Value *V);
365
367 return cast<ConstantAsMetadata>(get(C));
368 }
369
371 return cast<LocalAsMetadata>(get(Local));
372 }
373
375
377 return cast_or_null<ConstantAsMetadata>(getIfExists(C));
378 }
379
381 return cast_or_null<LocalAsMetadata>(getIfExists(Local));
382 }
383
384 Value *getValue() const { return V; }
385 Type *getType() const { return V->getType(); }
386 LLVMContext &getContext() const { return V->getContext(); }
387
390 }
391
392 static void handleDeletion(Value *V);
393 static void handleRAUW(Value *From, Value *To);
394
395protected:
396 /// Handle collisions after \a Value::replaceAllUsesWith().
397 ///
398 /// RAUW isn't supported directly for \a ValueAsMetadata, but if the wrapped
399 /// \a Value gets RAUW'ed and the target already exists, this is used to
400 /// merge the two metadata nodes.
403 }
404
405public:
406 static bool classof(const Metadata *MD) {
407 return MD->getMetadataID() == LocalAsMetadataKind ||
408 MD->getMetadataID() == ConstantAsMetadataKind;
409 }
410};
411
413 friend class ValueAsMetadata;
414
416 : ValueAsMetadata(ConstantAsMetadataKind, C) {}
417
418public:
421 }
422
425 }
426
428 return cast<Constant>(ValueAsMetadata::getValue());
429 }
430
431 static bool classof(const Metadata *MD) {
432 return MD->getMetadataID() == ConstantAsMetadataKind;
433 }
434};
435
437 friend class ValueAsMetadata;
438
439 LocalAsMetadata(Value *Local)
440 : ValueAsMetadata(LocalAsMetadataKind, Local) {
441 assert(!isa<Constant>(Local) && "Expected local value");
442 }
443
444public:
445 static LocalAsMetadata *get(Value *Local) {
446 return ValueAsMetadata::getLocal(Local);
447 }
448
451 }
452
453 static bool classof(const Metadata *MD) {
454 return MD->getMetadataID() == LocalAsMetadataKind;
455 }
456};
457
458/// Transitional API for extracting constants from Metadata.
459///
460/// This namespace contains transitional functions for metadata that points to
461/// \a Constants.
462///
463/// In prehistory -- when metadata was a subclass of \a Value -- \a MDNode
464/// operands could refer to any \a Value. There's was a lot of code like this:
465///
466/// \code
467/// MDNode *N = ...;
468/// auto *CI = dyn_cast<ConstantInt>(N->getOperand(2));
469/// \endcode
470///
471/// Now that \a Value and \a Metadata are in separate hierarchies, maintaining
472/// the semantics for \a isa(), \a cast(), \a dyn_cast() (etc.) requires three
473/// steps: cast in the \a Metadata hierarchy, extraction of the \a Value, and
474/// cast in the \a Value hierarchy. Besides creating boiler-plate, this
475/// requires subtle control flow changes.
476///
477/// The end-goal is to create a new type of metadata, called (e.g.) \a MDInt,
478/// so that metadata can refer to numbers without traversing a bridge to the \a
479/// Value hierarchy. In this final state, the code above would look like this:
480///
481/// \code
482/// MDNode *N = ...;
483/// auto *MI = dyn_cast<MDInt>(N->getOperand(2));
484/// \endcode
485///
486/// The API in this namespace supports the transition. \a MDInt doesn't exist
487/// yet, and even once it does, changing each metadata schema to use it is its
488/// own mini-project. In the meantime this API prevents us from introducing
489/// complex and bug-prone control flow that will disappear in the end. In
490/// particular, the above code looks like this:
491///
492/// \code
493/// MDNode *N = ...;
494/// auto *CI = mdconst::dyn_extract<ConstantInt>(N->getOperand(2));
495/// \endcode
496///
497/// The full set of provided functions includes:
498///
499/// mdconst::hasa <=> isa
500/// mdconst::extract <=> cast
501/// mdconst::extract_or_null <=> cast_or_null
502/// mdconst::dyn_extract <=> dyn_cast
503/// mdconst::dyn_extract_or_null <=> dyn_cast_or_null
504///
505/// The target of the cast must be a subclass of \a Constant.
506namespace mdconst {
507
508namespace detail {
509
510template <class T> T &make();
511template <class T, class Result> struct HasDereference {
512 using Yes = char[1];
513 using No = char[2];
514 template <size_t N> struct SFINAE {};
515
516 template <class U, class V>
517 static Yes &hasDereference(SFINAE<sizeof(static_cast<V>(*make<U>()))> * = 0);
518 template <class U, class V> static No &hasDereference(...);
519
520 static const bool value =
521 sizeof(hasDereference<T, Result>(nullptr)) == sizeof(Yes);
522};
523template <class V, class M> struct IsValidPointer {
524 static const bool value = std::is_base_of<Constant, V>::value &&
526};
527template <class V, class M> struct IsValidReference {
528 static const bool value = std::is_base_of<Constant, V>::value &&
529 std::is_convertible<M, const Metadata &>::value;
530};
531
532} // end namespace detail
533
534/// Check whether Metadata has a Value.
535///
536/// As an analogue to \a isa(), check whether \c MD has an \a Value inside of
537/// type \c X.
538template <class X, class Y>
539inline std::enable_if_t<detail::IsValidPointer<X, Y>::value, bool>
540hasa(Y &&MD) {
541 assert(MD && "Null pointer sent into hasa");
542 if (auto *V = dyn_cast<ConstantAsMetadata>(MD))
543 return isa<X>(V->getValue());
544 return false;
545}
546template <class X, class Y>
547inline std::enable_if_t<detail::IsValidReference<X, Y &>::value, bool>
548hasa(Y &MD) {
549 return hasa(&MD);
550}
551
552/// Extract a Value from Metadata.
553///
554/// As an analogue to \a cast(), extract the \a Value subclass \c X from \c MD.
555template <class X, class Y>
556inline std::enable_if_t<detail::IsValidPointer<X, Y>::value, X *>
557extract(Y &&MD) {
558 return cast<X>(cast<ConstantAsMetadata>(MD)->getValue());
559}
560template <class X, class Y>
561inline std::enable_if_t<detail::IsValidReference<X, Y &>::value, X *>
562extract(Y &MD) {
563 return extract(&MD);
564}
565
566/// Extract a Value from Metadata, allowing null.
567///
568/// As an analogue to \a cast_or_null(), extract the \a Value subclass \c X
569/// from \c MD, allowing \c MD to be null.
570template <class X, class Y>
571inline std::enable_if_t<detail::IsValidPointer<X, Y>::value, X *>
573 if (auto *V = cast_or_null<ConstantAsMetadata>(MD))
574 return cast<X>(V->getValue());
575 return nullptr;
576}
577
578/// Extract a Value from Metadata, if any.
579///
580/// As an analogue to \a dyn_cast_or_null(), extract the \a Value subclass \c X
581/// from \c MD, return null if \c MD doesn't contain a \a Value or if the \a
582/// Value it does contain is of the wrong subclass.
583template <class X, class Y>
584inline std::enable_if_t<detail::IsValidPointer<X, Y>::value, X *>
586 if (auto *V = dyn_cast<ConstantAsMetadata>(MD))
587 return dyn_cast<X>(V->getValue());
588 return nullptr;
589}
590
591/// Extract a Value from Metadata, if any, allowing null.
592///
593/// As an analogue to \a dyn_cast_or_null(), extract the \a Value subclass \c X
594/// from \c MD, return null if \c MD doesn't contain a \a Value or if the \a
595/// Value it does contain is of the wrong subclass, allowing \c MD to be null.
596template <class X, class Y>
597inline std::enable_if_t<detail::IsValidPointer<X, Y>::value, X *>
599 if (auto *V = dyn_cast_or_null<ConstantAsMetadata>(MD))
600 return dyn_cast<X>(V->getValue());
601 return nullptr;
602}
603
604} // end namespace mdconst
605
606//===----------------------------------------------------------------------===//
607/// A single uniqued string.
608///
609/// These are used to efficiently contain a byte sequence for metadata.
610/// MDString is always unnamed.
611class MDString : public Metadata {
612 friend class StringMapEntryStorage<MDString>;
613
614 StringMapEntry<MDString> *Entry = nullptr;
615
616 MDString() : Metadata(MDStringKind, Uniqued) {}
617
618public:
619 MDString(const MDString &) = delete;
621 MDString &operator=(const MDString &) = delete;
622
623 static MDString *get(LLVMContext &Context, StringRef Str);
624 static MDString *get(LLVMContext &Context, const char *Str) {
625 return get(Context, Str ? StringRef(Str) : StringRef());
626 }
627
628 StringRef getString() const;
629
630 unsigned getLength() const { return (unsigned)getString().size(); }
631
633
634 /// Pointer to the first byte of the string.
635 iterator begin() const { return getString().begin(); }
636
637 /// Pointer to one byte past the end of the string.
638 iterator end() const { return getString().end(); }
639
640 const unsigned char *bytes_begin() const { return getString().bytes_begin(); }
641 const unsigned char *bytes_end() const { return getString().bytes_end(); }
642
643 /// Methods for support type inquiry through isa, cast, and dyn_cast.
644 static bool classof(const Metadata *MD) {
645 return MD->getMetadataID() == MDStringKind;
646 }
647};
648
649/// A collection of metadata nodes that might be associated with a
650/// memory access used by the alias-analysis infrastructure.
651struct AAMDNodes {
652 explicit AAMDNodes() = default;
653 explicit AAMDNodes(MDNode *T, MDNode *TS, MDNode *S, MDNode *N)
654 : TBAA(T), TBAAStruct(TS), Scope(S), NoAlias(N) {}
655
656 bool operator==(const AAMDNodes &A) const {
657 return TBAA == A.TBAA && TBAAStruct == A.TBAAStruct && Scope == A.Scope &&
658 NoAlias == A.NoAlias;
659 }
660
661 bool operator!=(const AAMDNodes &A) const { return !(*this == A); }
662
663 explicit operator bool() const {
664 return TBAA || TBAAStruct || Scope || NoAlias;
665 }
666
667 /// The tag for type-based alias analysis.
668 MDNode *TBAA = nullptr;
669
670 /// The tag for type-based alias analysis (tbaa struct).
671 MDNode *TBAAStruct = nullptr;
672
673 /// The tag for alias scope specification (used with noalias).
674 MDNode *Scope = nullptr;
675
676 /// The tag specifying the noalias scope.
677 MDNode *NoAlias = nullptr;
678
679 // Shift tbaa Metadata node to start off bytes later
680 static MDNode *shiftTBAA(MDNode *M, size_t off);
681
682 // Shift tbaa.struct Metadata node to start off bytes later
683 static MDNode *shiftTBAAStruct(MDNode *M, size_t off);
684
685 // Extend tbaa Metadata node to apply to a series of bytes of length len.
686 // A size of -1 denotes an unknown size.
687 static MDNode *extendToTBAA(MDNode *TBAA, ssize_t len);
688
689 /// Given two sets of AAMDNodes that apply to the same pointer,
690 /// give the best AAMDNodes that are compatible with both (i.e. a set of
691 /// nodes whose allowable aliasing conclusions are a subset of those
692 /// allowable by both of the inputs). However, for efficiency
693 /// reasons, do not create any new MDNodes.
695 AAMDNodes Result;
696 Result.TBAA = Other.TBAA == TBAA ? TBAA : nullptr;
697 Result.TBAAStruct = Other.TBAAStruct == TBAAStruct ? TBAAStruct : nullptr;
698 Result.Scope = Other.Scope == Scope ? Scope : nullptr;
699 Result.NoAlias = Other.NoAlias == NoAlias ? NoAlias : nullptr;
700 return Result;
701 }
702
703 /// Create a new AAMDNode that describes this AAMDNode after applying a
704 /// constant offset to the start of the pointer.
705 AAMDNodes shift(size_t Offset) const {
706 AAMDNodes Result;
707 Result.TBAA = TBAA ? shiftTBAA(TBAA, Offset) : nullptr;
708 Result.TBAAStruct =
710 Result.Scope = Scope;
711 Result.NoAlias = NoAlias;
712 return Result;
713 }
714
715 /// Create a new AAMDNode that describes this AAMDNode after extending it to
716 /// apply to a series of bytes of length Len. A size of -1 denotes an unknown
717 /// size.
718 AAMDNodes extendTo(ssize_t Len) const {
719 AAMDNodes Result;
720 Result.TBAA = TBAA ? extendToTBAA(TBAA, Len) : nullptr;
721 // tbaa.struct contains (offset, size, type) triples. Extending the length
722 // of the tbaa.struct doesn't require changing this (though more information
723 // could be provided by adding more triples at subsequent lengths).
724 Result.TBAAStruct = TBAAStruct;
725 Result.Scope = Scope;
726 Result.NoAlias = NoAlias;
727 return Result;
728 }
729
730 /// Given two sets of AAMDNodes applying to potentially different locations,
731 /// determine the best AAMDNodes that apply to both.
732 AAMDNodes merge(const AAMDNodes &Other) const;
733
734 /// Determine the best AAMDNodes after concatenating two different locations
735 /// together. Different from `merge`, where different locations should
736 /// overlap each other, `concat` puts non-overlapping locations together.
737 AAMDNodes concat(const AAMDNodes &Other) const;
738};
739
740// Specialize DenseMapInfo for AAMDNodes.
741template<>
743 static inline AAMDNodes getEmptyKey() {
745 nullptr, nullptr, nullptr);
746 }
747
748 static inline AAMDNodes getTombstoneKey() {
750 nullptr, nullptr, nullptr);
751 }
752
753 static unsigned getHashValue(const AAMDNodes &Val) {
758 }
759
760 static bool isEqual(const AAMDNodes &LHS, const AAMDNodes &RHS) {
761 return LHS == RHS;
762 }
763};
764
765/// Tracking metadata reference owned by Metadata.
766///
767/// Similar to \a TrackingMDRef, but it's expected to be owned by an instance
768/// of \a Metadata, which has the option of registering itself for callbacks to
769/// re-unique itself.
770///
771/// In particular, this is used by \a MDNode.
773 Metadata *MD = nullptr;
774
775public:
776 MDOperand() = default;
777 MDOperand(const MDOperand &) = delete;
779 MD = Op.MD;
780 if (MD)
781 (void)MetadataTracking::retrack(Op.MD, MD);
782 Op.MD = nullptr;
783 }
784 MDOperand &operator=(const MDOperand &) = delete;
786 MD = Op.MD;
787 if (MD)
788 (void)MetadataTracking::retrack(Op.MD, MD);
789 Op.MD = nullptr;
790 return *this;
791 }
792 ~MDOperand() { untrack(); }
793
794 Metadata *get() const { return MD; }
795 operator Metadata *() const { return get(); }
796 Metadata *operator->() const { return get(); }
797 Metadata &operator*() const { return *get(); }
798
799 void reset() {
800 untrack();
801 MD = nullptr;
802 }
803 void reset(Metadata *MD, Metadata *Owner) {
804 untrack();
805 this->MD = MD;
806 track(Owner);
807 }
808
809private:
810 void track(Metadata *Owner) {
811 if (MD) {
812 if (Owner)
813 MetadataTracking::track(this, *MD, *Owner);
814 else
816 }
817 }
818
819 void untrack() {
820 assert(static_cast<void *>(this) == &MD && "Expected same address");
821 if (MD)
823 }
824};
825
826template <> struct simplify_type<MDOperand> {
828
829 static SimpleType getSimplifiedValue(MDOperand &MD) { return MD.get(); }
830};
831
832template <> struct simplify_type<const MDOperand> {
834
835 static SimpleType getSimplifiedValue(const MDOperand &MD) { return MD.get(); }
836};
837
838/// Pointer to the context, with optional RAUW support.
839///
840/// Either a raw (non-null) pointer to the \a LLVMContext, or an owned pointer
841/// to \a ReplaceableMetadataImpl (which has a reference to \a LLVMContext).
844
845public:
848 std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses)
849 : Ptr(ReplaceableUses.release()) {
850 assert(getReplaceableUses() && "Expected non-null replaceable uses");
851 }
859
860 operator LLVMContext &() { return getContext(); }
861
862 /// Whether this contains RAUW support.
863 bool hasReplaceableUses() const {
864 return Ptr.is<ReplaceableMetadataImpl *>();
865 }
866
868 if (hasReplaceableUses())
869 return getReplaceableUses()->getContext();
870 return *Ptr.get<LLVMContext *>();
871 }
872
874 if (hasReplaceableUses())
875 return Ptr.get<ReplaceableMetadataImpl *>();
876 return nullptr;
877 }
878
879 /// Ensure that this has RAUW support, and then return it.
881 if (!hasReplaceableUses())
882 makeReplaceable(std::make_unique<ReplaceableMetadataImpl>(getContext()));
883 return getReplaceableUses();
884 }
885
886 /// Assign RAUW support to this.
887 ///
888 /// Make this replaceable, taking ownership of \c ReplaceableUses (which must
889 /// not be null).
890 void
891 makeReplaceable(std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses) {
892 assert(ReplaceableUses && "Expected non-null replaceable uses");
893 assert(&ReplaceableUses->getContext() == &getContext() &&
894 "Expected same context");
895 delete getReplaceableUses();
896 Ptr = ReplaceableUses.release();
897 }
898
899 /// Drop RAUW support.
900 ///
901 /// Cede ownership of RAUW support, returning it.
902 std::unique_ptr<ReplaceableMetadataImpl> takeReplaceableUses() {
903 assert(hasReplaceableUses() && "Expected to own replaceable uses");
904 std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses(
906 Ptr = &ReplaceableUses->getContext();
907 return ReplaceableUses;
908 }
909};
910
912 inline void operator()(MDNode *Node) const;
913};
914
915#define HANDLE_MDNODE_LEAF(CLASS) \
916 using Temp##CLASS = std::unique_ptr<CLASS, TempMDNodeDeleter>;
917#define HANDLE_MDNODE_BRANCH(CLASS) HANDLE_MDNODE_LEAF(CLASS)
918#include "llvm/IR/Metadata.def"
919
920/// Metadata node.
921///
922/// Metadata nodes can be uniqued, like constants, or distinct. Temporary
923/// metadata nodes (with full support for RAUW) can be used to delay uniquing
924/// until forward references are known. The basic metadata node is an \a
925/// MDTuple.
926///
927/// There is limited support for RAUW at construction time. At construction
928/// time, if any operand is a temporary node (or an unresolved uniqued node,
929/// which indicates a transitive temporary operand), the node itself will be
930/// unresolved. As soon as all operands become resolved, it will drop RAUW
931/// support permanently.
932///
933/// If an unresolved node is part of a cycle, \a resolveCycles() needs
934/// to be called on some member of the cycle once all temporary nodes have been
935/// replaced.
936///
937/// MDNodes can be large or small, as well as resizable or non-resizable.
938/// Large MDNodes' operands are allocated in a separate storage vector,
939/// whereas small MDNodes' operands are co-allocated. Distinct and temporary
940/// MDnodes are resizable, but only MDTuples support this capability.
941///
942/// Clients can add operands to resizable MDNodes using push_back().
943class MDNode : public Metadata {
945 friend class LLVMContextImpl;
946 friend class DIArgList;
947
948 /// The header that is coallocated with an MDNode along with its "small"
949 /// operands. It is located immediately before the main body of the node.
950 /// The operands are in turn located immediately before the header.
951 /// For resizable MDNodes, the space for the storage vector is also allocated
952 /// immediately before the header, overlapping with the operands.
953 /// Explicity set alignment because bitfields by default have an
954 /// alignment of 1 on z/OS.
955 struct alignas(alignof(size_t)) Header {
956 bool IsResizable : 1;
957 bool IsLarge : 1;
958 size_t SmallSize : 4;
959 size_t SmallNumOps : 4;
960 size_t : sizeof(size_t) * CHAR_BIT - 10;
961
962 unsigned NumUnresolved = 0;
963 using LargeStorageVector = SmallVector<MDOperand, 0>;
964
965 static constexpr size_t NumOpsFitInVector =
966 sizeof(LargeStorageVector) / sizeof(MDOperand);
967 static_assert(
968 NumOpsFitInVector * sizeof(MDOperand) == sizeof(LargeStorageVector),
969 "sizeof(LargeStorageVector) must be a multiple of sizeof(MDOperand)");
970
971 static constexpr size_t MaxSmallSize = 15;
972
973 static constexpr size_t getOpSize(unsigned NumOps) {
974 return sizeof(MDOperand) * NumOps;
975 }
976 /// Returns the number of operands the node has space for based on its
977 /// allocation characteristics.
978 static size_t getSmallSize(size_t NumOps, bool IsResizable, bool IsLarge) {
979 return IsLarge ? NumOpsFitInVector
980 : std::max(NumOps, NumOpsFitInVector * IsResizable);
981 }
982 /// Returns the number of bytes allocated for operands and header.
983 static size_t getAllocSize(StorageType Storage, size_t NumOps) {
984 return getOpSize(
985 getSmallSize(NumOps, isResizable(Storage), isLarge(NumOps))) +
986 sizeof(Header);
987 }
988
989 /// Only temporary and distinct nodes are resizable.
990 static bool isResizable(StorageType Storage) { return Storage != Uniqued; }
991 static bool isLarge(size_t NumOps) { return NumOps > MaxSmallSize; }
992
993 size_t getAllocSize() const {
994 return getOpSize(SmallSize) + sizeof(Header);
995 }
996 void *getAllocation() {
997 return reinterpret_cast<char *>(this + 1) -
998 alignTo(getAllocSize(), alignof(uint64_t));
999 }
1000
1001 void *getLargePtr() const {
1002 static_assert(alignof(LargeStorageVector) <= alignof(Header),
1003 "LargeStorageVector too strongly aligned");
1004 return reinterpret_cast<char *>(const_cast<Header *>(this)) -
1005 sizeof(LargeStorageVector);
1006 }
1007
1008 void *getSmallPtr();
1009
1010 LargeStorageVector &getLarge() {
1011 assert(IsLarge);
1012 return *reinterpret_cast<LargeStorageVector *>(getLargePtr());
1013 }
1014
1015 const LargeStorageVector &getLarge() const {
1016 assert(IsLarge);
1017 return *reinterpret_cast<const LargeStorageVector *>(getLargePtr());
1018 }
1019
1020 void resizeSmall(size_t NumOps);
1021 void resizeSmallToLarge(size_t NumOps);
1022 void resize(size_t NumOps);
1023
1024 explicit Header(size_t NumOps, StorageType Storage);
1025 ~Header();
1026
1027 MutableArrayRef<MDOperand> operands() {
1028 if (IsLarge)
1029 return getLarge();
1030 return MutableArrayRef(
1031 reinterpret_cast<MDOperand *>(this) - SmallSize, SmallNumOps);
1032 }
1033
1034 ArrayRef<MDOperand> operands() const {
1035 if (IsLarge)
1036 return getLarge();
1037 return ArrayRef(reinterpret_cast<const MDOperand *>(this) - SmallSize,
1038 SmallNumOps);
1039 }
1040
1041 unsigned getNumOperands() const {
1042 if (!IsLarge)
1043 return SmallNumOps;
1044 return getLarge().size();
1045 }
1046 };
1047
1048 Header &getHeader() { return *(reinterpret_cast<Header *>(this) - 1); }
1049
1050 const Header &getHeader() const {
1051 return *(reinterpret_cast<const Header *>(this) - 1);
1052 }
1053
1054 ContextAndReplaceableUses Context;
1055
1056protected:
1057 MDNode(LLVMContext &Context, unsigned ID, StorageType Storage,
1058 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = std::nullopt);
1059 ~MDNode() = default;
1060
1061 void *operator new(size_t Size, size_t NumOps, StorageType Storage);
1062 void operator delete(void *Mem);
1063
1064 /// Required by std, but never called.
1065 void operator delete(void *, unsigned) {
1066 llvm_unreachable("Constructor throws?");
1067 }
1068
1069 /// Required by std, but never called.
1070 void operator delete(void *, unsigned, bool) {
1071 llvm_unreachable("Constructor throws?");
1072 }
1073
1074 void dropAllReferences();
1075
1076 MDOperand *mutable_begin() { return getHeader().operands().begin(); }
1077 MDOperand *mutable_end() { return getHeader().operands().end(); }
1078
1080
1083 }
1084
1085public:
1086 MDNode(const MDNode &) = delete;
1087 void operator=(const MDNode &) = delete;
1088 void *operator new(size_t) = delete;
1089
1090 static inline MDTuple *get(LLVMContext &Context, ArrayRef<Metadata *> MDs);
1091 static inline MDTuple *getIfExists(LLVMContext &Context,
1093 static inline MDTuple *getDistinct(LLVMContext &Context,
1095 static inline TempMDTuple getTemporary(LLVMContext &Context,
1097
1098 /// Create a (temporary) clone of this.
1099 TempMDNode clone() const;
1100
1101 /// Deallocate a node created by getTemporary.
1102 ///
1103 /// Calls \c replaceAllUsesWith(nullptr) before deleting, so any remaining
1104 /// references will be reset.
1105 static void deleteTemporary(MDNode *N);
1106
1107 LLVMContext &getContext() const { return Context.getContext(); }
1108
1109 /// Replace a specific operand.
1110 void replaceOperandWith(unsigned I, Metadata *New);
1111
1112 /// Check if node is fully resolved.
1113 ///
1114 /// If \a isTemporary(), this always returns \c false; if \a isDistinct(),
1115 /// this always returns \c true.
1116 ///
1117 /// If \a isUniqued(), returns \c true if this has already dropped RAUW
1118 /// support (because all operands are resolved).
1119 ///
1120 /// As forward declarations are resolved, their containers should get
1121 /// resolved automatically. However, if this (or one of its operands) is
1122 /// involved in a cycle, \a resolveCycles() needs to be called explicitly.
1123 bool isResolved() const { return !isTemporary() && !getNumUnresolved(); }
1124
1125 bool isUniqued() const { return Storage == Uniqued; }
1126 bool isDistinct() const { return Storage == Distinct; }
1127 bool isTemporary() const { return Storage == Temporary; }
1128
1129 /// RAUW a temporary.
1130 ///
1131 /// \pre \a isTemporary() must be \c true.
1133 assert(isTemporary() && "Expected temporary node");
1134 if (Context.hasReplaceableUses())
1135 Context.getReplaceableUses()->replaceAllUsesWith(MD);
1136 }
1137
1138 /// Resolve cycles.
1139 ///
1140 /// Once all forward declarations have been resolved, force cycles to be
1141 /// resolved.
1142 ///
1143 /// \pre No operands (or operands' operands, etc.) have \a isTemporary().
1144 void resolveCycles();
1145
1146 /// Resolve a unique, unresolved node.
1147 void resolve();
1148
1149 /// Replace a temporary node with a permanent one.
1150 ///
1151 /// Try to create a uniqued version of \c N -- in place, if possible -- and
1152 /// return it. If \c N cannot be uniqued, return a distinct node instead.
1153 template <class T>
1154 static std::enable_if_t<std::is_base_of<MDNode, T>::value, T *>
1155 replaceWithPermanent(std::unique_ptr<T, TempMDNodeDeleter> N) {
1156 return cast<T>(N.release()->replaceWithPermanentImpl());
1157 }
1158
1159 /// Replace a temporary node with a uniqued one.
1160 ///
1161 /// Create a uniqued version of \c N -- in place, if possible -- and return
1162 /// it. Takes ownership of the temporary node.
1163 ///
1164 /// \pre N does not self-reference.
1165 template <class T>
1166 static std::enable_if_t<std::is_base_of<MDNode, T>::value, T *>
1167 replaceWithUniqued(std::unique_ptr<T, TempMDNodeDeleter> N) {
1168 return cast<T>(N.release()->replaceWithUniquedImpl());
1169 }
1170
1171 /// Replace a temporary node with a distinct one.
1172 ///
1173 /// Create a distinct version of \c N -- in place, if possible -- and return
1174 /// it. Takes ownership of the temporary node.
1175 template <class T>
1176 static std::enable_if_t<std::is_base_of<MDNode, T>::value, T *>
1177 replaceWithDistinct(std::unique_ptr<T, TempMDNodeDeleter> N) {
1178 return cast<T>(N.release()->replaceWithDistinctImpl());
1179 }
1180
1181 /// Print in tree shape.
1182 ///
1183 /// Prints definition of \c this in tree shape.
1184 ///
1185 /// If \c M is provided, metadata nodes will be numbered canonically;
1186 /// otherwise, pointer addresses are substituted.
1187 /// @{
1188 void printTree(raw_ostream &OS, const Module *M = nullptr) const;
1190 const Module *M = nullptr) const;
1191 /// @}
1192
1193 /// User-friendly dump in tree shape.
1194 ///
1195 /// If \c M is provided, metadata nodes will be numbered canonically;
1196 /// otherwise, pointer addresses are substituted.
1197 ///
1198 /// Note: this uses an explicit overload instead of default arguments so that
1199 /// the nullptr version is easy to call from a debugger.
1200 ///
1201 /// @{
1202 void dumpTree() const;
1203 void dumpTree(const Module *M) const;
1204 /// @}
1205
1206private:
1207 MDNode *replaceWithPermanentImpl();
1208 MDNode *replaceWithUniquedImpl();
1209 MDNode *replaceWithDistinctImpl();
1210
1211protected:
1212 /// Set an operand.
1213 ///
1214 /// Sets the operand directly, without worrying about uniquing.
1215 void setOperand(unsigned I, Metadata *New);
1216
1217 unsigned getNumUnresolved() const { return getHeader().NumUnresolved; }
1218
1219 void setNumUnresolved(unsigned N) { getHeader().NumUnresolved = N; }
1221 template <class T, class StoreT>
1222 static T *storeImpl(T *N, StorageType Storage, StoreT &Store);
1223 template <class T> static T *storeImpl(T *N, StorageType Storage);
1224
1225 /// Resize the node to hold \a NumOps operands.
1226 ///
1227 /// \pre \a isTemporary() or \a isDistinct()
1228 /// \pre MetadataID == MDTupleKind
1229 void resize(size_t NumOps) {
1230 assert(!isUniqued() && "Resizing is not supported for uniqued nodes");
1231 assert(getMetadataID() == MDTupleKind &&
1232 "Resizing is not supported for this node kind");
1233 getHeader().resize(NumOps);
1234 }
1235
1236private:
1237 void handleChangedOperand(void *Ref, Metadata *New);
1238
1239 /// Drop RAUW support, if any.
1240 void dropReplaceableUses();
1241
1242 void resolveAfterOperandChange(Metadata *Old, Metadata *New);
1243 void decrementUnresolvedOperandCount();
1244 void countUnresolvedOperands();
1245
1246 /// Mutate this to be "uniqued".
1247 ///
1248 /// Mutate this so that \a isUniqued().
1249 /// \pre \a isTemporary().
1250 /// \pre already added to uniquing set.
1251 void makeUniqued();
1252
1253 /// Mutate this to be "distinct".
1254 ///
1255 /// Mutate this so that \a isDistinct().
1256 /// \pre \a isTemporary().
1257 void makeDistinct();
1258
1259 void deleteAsSubclass();
1260 MDNode *uniquify();
1261 void eraseFromStore();
1262
1263 template <class NodeTy> struct HasCachedHash;
1264 template <class NodeTy>
1265 static void dispatchRecalculateHash(NodeTy *N, std::true_type) {
1266 N->recalculateHash();
1267 }
1268 template <class NodeTy>
1269 static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
1270 template <class NodeTy>
1271 static void dispatchResetHash(NodeTy *N, std::true_type) {
1272 N->setHash(0);
1273 }
1274 template <class NodeTy>
1275 static void dispatchResetHash(NodeTy *, std::false_type) {}
1276
1277public:
1278 using op_iterator = const MDOperand *;
1280
1282 return const_cast<MDNode *>(this)->mutable_begin();
1283 }
1284
1286 return const_cast<MDNode *>(this)->mutable_end();
1287 }
1288
1289 ArrayRef<MDOperand> operands() const { return getHeader().operands(); }
1290
1291 const MDOperand &getOperand(unsigned I) const {
1292 assert(I < getNumOperands() && "Out of range");
1293 return getHeader().operands()[I];
1294 }
1295
1296 /// Return number of MDNode operands.
1297 unsigned getNumOperands() const { return getHeader().getNumOperands(); }
1298
1299 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1300 static bool classof(const Metadata *MD) {
1301 switch (MD->getMetadataID()) {
1302 default:
1303 return false;
1304#define HANDLE_MDNODE_LEAF(CLASS) \
1305 case CLASS##Kind: \
1306 return true;
1307#include "llvm/IR/Metadata.def"
1308 }
1309 }
1310
1311 /// Check whether MDNode is a vtable access.
1312 bool isTBAAVtableAccess() const;
1313
1314 /// Methods for metadata merging.
1315 static MDNode *concatenate(MDNode *A, MDNode *B);
1316 static MDNode *intersect(MDNode *A, MDNode *B);
1322};
1323
1324/// Tuple of metadata.
1325///
1326/// This is the simple \a MDNode arbitrary tuple. Nodes are uniqued by
1327/// default based on their operands.
1328class MDTuple : public MDNode {
1329 friend class LLVMContextImpl;
1330 friend class MDNode;
1331
1332 MDTuple(LLVMContext &C, StorageType Storage, unsigned Hash,
1334 : MDNode(C, MDTupleKind, Storage, Vals) {
1335 setHash(Hash);
1336 }
1337
1339
1340 void setHash(unsigned Hash) { SubclassData32 = Hash; }
1341 void recalculateHash();
1342
1343 static MDTuple *getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
1344 StorageType Storage, bool ShouldCreate = true);
1345
1346 TempMDTuple cloneImpl() const {
1347 ArrayRef<MDOperand> Operands = operands();
1348 return getTemporary(getContext(), SmallVector<Metadata *, 4>(
1349 Operands.begin(), Operands.end()));
1350 }
1351
1352public:
1353 /// Get the hash, if any.
1354 unsigned getHash() const { return SubclassData32; }
1355
1357 return getImpl(Context, MDs, Uniqued);
1358 }
1359
1361 return getImpl(Context, MDs, Uniqued, /* ShouldCreate */ false);
1362 }
1363
1364 /// Return a distinct node.
1365 ///
1366 /// Return a distinct node -- i.e., a node that is not uniqued.
1368 return getImpl(Context, MDs, Distinct);
1369 }
1370
1371 /// Return a temporary node.
1372 ///
1373 /// For use in constructing cyclic MDNode structures. A temporary MDNode is
1374 /// not uniqued, may be RAUW'd, and must be manually deleted with
1375 /// deleteTemporary.
1376 static TempMDTuple getTemporary(LLVMContext &Context,
1378 return TempMDTuple(getImpl(Context, MDs, Temporary));
1379 }
1380
1381 /// Return a (temporary) clone of this.
1382 TempMDTuple clone() const { return cloneImpl(); }
1383
1384 /// Append an element to the tuple. This will resize the node.
1386 size_t NumOps = getNumOperands();
1387 resize(NumOps + 1);
1388 setOperand(NumOps, MD);
1389 }
1390
1391 /// Shrink the operands by 1.
1392 void pop_back() { resize(getNumOperands() - 1); }
1393
1394 static bool classof(const Metadata *MD) {
1395 return MD->getMetadataID() == MDTupleKind;
1396 }
1397};
1398
1400 return MDTuple::get(Context, MDs);
1401}
1402
1404 return MDTuple::getIfExists(Context, MDs);
1405}
1406
1408 return MDTuple::getDistinct(Context, MDs);
1409}
1410
1413 return MDTuple::getTemporary(Context, MDs);
1414}
1415
1418}
1419
1420/// This is a simple wrapper around an MDNode which provides a higher-level
1421/// interface by hiding the details of how alias analysis information is encoded
1422/// in its operands.
1424 const MDNode *Node = nullptr;
1425
1426public:
1427 AliasScopeNode() = default;
1428 explicit AliasScopeNode(const MDNode *N) : Node(N) {}
1429
1430 /// Get the MDNode for this AliasScopeNode.
1431 const MDNode *getNode() const { return Node; }
1432
1433 /// Get the MDNode for this AliasScopeNode's domain.
1434 const MDNode *getDomain() const {
1435 if (Node->getNumOperands() < 2)
1436 return nullptr;
1437 return dyn_cast_or_null<MDNode>(Node->getOperand(1));
1438 }
1440 if (Node->getNumOperands() > 2)
1441 if (MDString *N = dyn_cast_or_null<MDString>(Node->getOperand(2)))
1442 return N->getString();
1443 return StringRef();
1444 }
1445};
1446
1447/// Typed iterator through MDNode operands.
1448///
1449/// An iterator that transforms an \a MDNode::iterator into an iterator over a
1450/// particular Metadata subclass.
1451template <class T> class TypedMDOperandIterator {
1452 MDNode::op_iterator I = nullptr;
1453
1454public:
1455 using iterator_category = std::input_iterator_tag;
1456 using value_type = T *;
1457 using difference_type = std::ptrdiff_t;
1458 using pointer = void;
1459 using reference = T *;
1460
1463
1464 T *operator*() const { return cast_or_null<T>(*I); }
1465
1467 ++I;
1468 return *this;
1469 }
1470
1472 TypedMDOperandIterator Temp(*this);
1473 ++I;
1474 return Temp;
1475 }
1476
1477 bool operator==(const TypedMDOperandIterator &X) const { return I == X.I; }
1478 bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
1479};
1480
1481/// Typed, array-like tuple of metadata.
1482///
1483/// This is a wrapper for \a MDTuple that makes it act like an array holding a
1484/// particular type of metadata.
1485template <class T> class MDTupleTypedArrayWrapper {
1486 const MDTuple *N = nullptr;
1487
1488public:
1491
1492 template <class U>
1495 std::enable_if_t<std::is_convertible<U *, T *>::value> * = nullptr)
1496 : N(Other.get()) {}
1497
1498 template <class U>
1501 std::enable_if_t<!std::is_convertible<U *, T *>::value> * = nullptr)
1502 : N(Other.get()) {}
1503
1504 explicit operator bool() const { return get(); }
1505 explicit operator MDTuple *() const { return get(); }
1506
1507 MDTuple *get() const { return const_cast<MDTuple *>(N); }
1508 MDTuple *operator->() const { return get(); }
1509 MDTuple &operator*() const { return *get(); }
1510
1511 // FIXME: Fix callers and remove condition on N.
1512 unsigned size() const { return N ? N->getNumOperands() : 0u; }
1513 bool empty() const { return N ? N->getNumOperands() == 0 : true; }
1514 T *operator[](unsigned I) const { return cast_or_null<T>(N->getOperand(I)); }
1515
1516 // FIXME: Fix callers and remove condition on N.
1518
1519 iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
1520 iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
1521};
1522
1523#define HANDLE_METADATA(CLASS) \
1524 using CLASS##Array = MDTupleTypedArrayWrapper<CLASS>;
1525#include "llvm/IR/Metadata.def"
1526
1527/// Placeholder metadata for operands of distinct MDNodes.
1528///
1529/// This is a lightweight placeholder for an operand of a distinct node. It's
1530/// purpose is to help track forward references when creating a distinct node.
1531/// This allows distinct nodes involved in a cycle to be constructed before
1532/// their operands without requiring a heavyweight temporary node with
1533/// full-blown RAUW support.
1534///
1535/// Each placeholder supports only a single MDNode user. Clients should pass
1536/// an ID, retrieved via \a getID(), to indicate the "real" operand that this
1537/// should be replaced with.
1538///
1539/// While it would be possible to implement move operators, they would be
1540/// fairly expensive. Leave them unimplemented to discourage their use
1541/// (clients can use std::deque, std::list, BumpPtrAllocator, etc.).
1543 friend class MetadataTracking;
1544
1545 Metadata **Use = nullptr;
1546
1547public:
1549 : Metadata(DistinctMDOperandPlaceholderKind, Distinct) {
1551 }
1552
1556
1558 if (Use)
1559 *Use = nullptr;
1560 }
1561
1562 unsigned getID() const { return SubclassData32; }
1563
1564 /// Replace the use of this with MD.
1566 if (!Use)
1567 return;
1568 *Use = MD;
1569
1570 if (*Use)
1572
1573 Metadata *T = cast<Metadata>(this);
1575 assert(!Use && "Use is still being tracked despite being untracked!");
1576 }
1577};
1578
1579//===----------------------------------------------------------------------===//
1580/// A tuple of MDNodes.
1581///
1582/// Despite its name, a NamedMDNode isn't itself an MDNode.
1583///
1584/// NamedMDNodes are named module-level entities that contain lists of MDNodes.
1585///
1586/// It is illegal for a NamedMDNode to appear as an operand of an MDNode.
1587class NamedMDNode : public ilist_node<NamedMDNode> {
1588 friend class LLVMContextImpl;
1589 friend class Module;
1590
1591 std::string Name;
1592 Module *Parent = nullptr;
1593 void *Operands; // SmallVector<TrackingMDRef, 4>
1594
1595 void setParent(Module *M) { Parent = M; }
1596
1597 explicit NamedMDNode(const Twine &N);
1598
1599 template <class T1, class T2> class op_iterator_impl {
1600 friend class NamedMDNode;
1601
1602 const NamedMDNode *Node = nullptr;
1603 unsigned Idx = 0;
1604
1605 op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) {}
1606
1607 public:
1608 using iterator_category = std::bidirectional_iterator_tag;
1609 using value_type = T2;
1610 using difference_type = std::ptrdiff_t;
1611 using pointer = value_type *;
1612 using reference = value_type &;
1613
1614 op_iterator_impl() = default;
1615
1616 bool operator==(const op_iterator_impl &o) const { return Idx == o.Idx; }
1617 bool operator!=(const op_iterator_impl &o) const { return Idx != o.Idx; }
1618
1619 op_iterator_impl &operator++() {
1620 ++Idx;
1621 return *this;
1622 }
1623
1624 op_iterator_impl operator++(int) {
1625 op_iterator_impl tmp(*this);
1626 operator++();
1627 return tmp;
1628 }
1629
1630 op_iterator_impl &operator--() {
1631 --Idx;
1632 return *this;
1633 }
1634
1635 op_iterator_impl operator--(int) {
1636 op_iterator_impl tmp(*this);
1637 operator--();
1638 return tmp;
1639 }
1640
1641 T1 operator*() const { return Node->getOperand(Idx); }
1642 };
1643
1644public:
1645 NamedMDNode(const NamedMDNode &) = delete;
1646 ~NamedMDNode();
1647
1648 /// Drop all references and remove the node from parent module.
1649 void eraseFromParent();
1650
1651 /// Remove all uses and clear node vector.
1653 /// Drop all references to this node's operands.
1654 void clearOperands();
1655
1656 /// Get the module that holds this named metadata collection.
1657 inline Module *getParent() { return Parent; }
1658 inline const Module *getParent() const { return Parent; }
1659
1660 MDNode *getOperand(unsigned i) const;
1661 unsigned getNumOperands() const;
1662 void addOperand(MDNode *M);
1663 void setOperand(unsigned I, MDNode *New);
1664 StringRef getName() const;
1665 void print(raw_ostream &ROS, bool IsForDebug = false) const;
1666 void print(raw_ostream &ROS, ModuleSlotTracker &MST,
1667 bool IsForDebug = false) const;
1668 void dump() const;
1669
1670 // ---------------------------------------------------------------------------
1671 // Operand Iterator interface...
1672 //
1673 using op_iterator = op_iterator_impl<MDNode *, MDNode>;
1674
1675 op_iterator op_begin() { return op_iterator(this, 0); }
1677
1678 using const_op_iterator = op_iterator_impl<const MDNode *, MDNode>;
1679
1680 const_op_iterator op_begin() const { return const_op_iterator(this, 0); }
1682
1684 return make_range(op_begin(), op_end());
1685 }
1687 return make_range(op_begin(), op_end());
1688 }
1689};
1690
1691// Create wrappers for C Binding types (see CBindingWrapping.h).
1693
1694} // end namespace llvm
1695
1696#endif // LLVM_IR_METADATA_H
aarch64 promote const
Replace within non kernel function use of LDS with pointer
always inline
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)
RelocType Type
Definition: COFFYAML.cpp:390
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 defines DenseMapInfo traits for DenseMap.
This file defines the DenseMap class.
std::string Name
uint64_t Size
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const Module *M)
This lazily constructs the LazyValueInfoImpl.
loop extract
#define I(x, y, z)
Definition: MD5.cpp:58
mir Rename Register Operands
Machine Check Debug Module
#define T1
LLVMContext & Context
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
This file defines the PointerUnion class, which is a discriminated union of pointer types.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
bool operator==(const StringView &LHS, const StringView &RHS)
Definition: StringView.h:115
Value * RHS
Value * LHS
This is a simple wrapper around an MDNode which provides a higher-level interface by hiding the detai...
Definition: Metadata.h:1423
AliasScopeNode()=default
AliasScopeNode(const MDNode *N)
Definition: Metadata.h:1428
const MDNode * getNode() const
Get the MDNode for this AliasScopeNode.
Definition: Metadata.h:1431
const MDNode * getDomain() const
Get the MDNode for this AliasScopeNode's domain.
Definition: Metadata.h:1434
StringRef getName() const
Definition: Metadata.h:1439
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:419
Constant * getValue() const
Definition: Metadata.h:427
static ConstantAsMetadata * getIfExists(Constant *C)
Definition: Metadata.h:423
static bool classof(const Metadata *MD)
Definition: Metadata.h:431
This is an important base class in LLVM.
Definition: Constant.h:41
Pointer to the context, with optional RAUW support.
Definition: Metadata.h:842
ContextAndReplaceableUses & operator=(const ContextAndReplaceableUses &)=delete
ReplaceableMetadataImpl * getReplaceableUses() const
Definition: Metadata.h:873
std::unique_ptr< ReplaceableMetadataImpl > takeReplaceableUses()
Drop RAUW support.
Definition: Metadata.h:902
ContextAndReplaceableUses & operator=(ContextAndReplaceableUses &&)=delete
ReplaceableMetadataImpl * getOrCreateReplaceableUses()
Ensure that this has RAUW support, and then return it.
Definition: Metadata.h:880
void makeReplaceable(std::unique_ptr< ReplaceableMetadataImpl > ReplaceableUses)
Assign RAUW support to this.
Definition: Metadata.h:891
ContextAndReplaceableUses(ContextAndReplaceableUses &&)=delete
ContextAndReplaceableUses(const ContextAndReplaceableUses &)=delete
LLVMContext & getContext() const
Definition: Metadata.h:867
bool hasReplaceableUses() const
Whether this contains RAUW support.
Definition: Metadata.h:863
ContextAndReplaceableUses(LLVMContext &Context)
Definition: Metadata.h:846
ContextAndReplaceableUses(std::unique_ptr< ReplaceableMetadataImpl > ReplaceableUses)
Definition: Metadata.h:847
List of ValueAsMetadata, to be used as an argument to a dbg.value intrinsic.
bool empty() const
Definition: DenseMap.h:98
Placeholder metadata for operands of distinct MDNodes.
Definition: Metadata.h:1542
void replaceUseWith(Metadata *MD)
Replace the use of this with MD.
Definition: Metadata.h:1565
DistinctMDOperandPlaceholder(const DistinctMDOperandPlaceholder &)=delete
DistinctMDOperandPlaceholder(unsigned ID)
Definition: Metadata.h:1548
DistinctMDOperandPlaceholder(DistinctMDOperandPlaceholder &&)=delete
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
static LocalAsMetadata * getIfExists(Value *Local)
Definition: Metadata.h:449
static LocalAsMetadata * get(Value *Local)
Definition: Metadata.h:445
static bool classof(const Metadata *MD)
Definition: Metadata.h:453
Metadata node.
Definition: Metadata.h:943
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
Definition: Metadata.cpp:1032
void printTree(raw_ostream &OS, const Module *M=nullptr) const
Print in tree shape.
Definition: AsmWriter.cpp:4905
void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
Definition: Metadata.cpp:968
iterator_range< MDOperand * > mutable_op_range
Definition: Metadata.h:1079
void resolveCycles()
Resolve cycles.
Definition: Metadata.cpp:732
bool isTBAAVtableAccess() const
Check whether MDNode is a vtable access.
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1407
mutable_op_range mutable_operands()
Definition: Metadata.h:1081
void replaceAllUsesWith(Metadata *MD)
RAUW a temporary.
Definition: Metadata.h:1132
static MDNode * concatenate(MDNode *A, MDNode *B)
Methods for metadata merging.
Definition: Metadata.cpp:1005
static void deleteTemporary(MDNode *N)
Deallocate a node created by getTemporary.
Definition: Metadata.cpp:940
void resolve()
Resolve a unique, unresolved node.
Definition: Metadata.cpp:686
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1291
void storeDistinctInContext()
Definition: Metadata.cpp:946
bool isTemporary() const
Definition: Metadata.h:1127
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1411
ArrayRef< MDOperand > operands() const
Definition: Metadata.h:1289
op_iterator op_end() const
Definition: Metadata.h:1285
MDNode(const MDNode &)=delete
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1399
static std::enable_if_t< std::is_base_of< MDNode, T >::value, T * > replaceWithDistinct(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a distinct one.
Definition: Metadata.h:1177
static bool classof(const Metadata *MD)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Metadata.h:1300
bool isUniqued() const
Definition: Metadata.h:1125
static MDNode * getMostGenericFPMath(MDNode *A, MDNode *B)
Definition: Metadata.cpp:1064
void setNumUnresolved(unsigned N)
Definition: Metadata.h:1219
void resize(size_t NumOps)
Resize the node to hold NumOps operands.
Definition: Metadata.h:1229
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1297
MDOperand * mutable_begin()
Definition: Metadata.h:1076
TempMDNode clone() const
Create a (temporary) clone of this.
Definition: Metadata.cpp:558
static MDNode * getMostGenericRange(MDNode *A, MDNode *B)
Definition: Metadata.cpp:1112
bool isDistinct() const
Definition: Metadata.h:1126
void setOperand(unsigned I, Metadata *New)
Set an operand.
Definition: Metadata.cpp:980
MDNode(LLVMContext &Context, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2=std::nullopt)
Definition: Metadata.cpp:541
bool isResolved() const
Check if node is fully resolved.
Definition: Metadata.h:1123
op_iterator op_begin() const
Definition: Metadata.h:1281
static MDNode * intersect(MDNode *A, MDNode *B)
Definition: Metadata.cpp:1019
static T * storeImpl(T *N, StorageType Storage, StoreT &Store)
Definition: MetadataImpl.h:42
LLVMContext & getContext() const
Definition: Metadata.h:1107
MDOperand * mutable_end()
Definition: Metadata.h:1077
~MDNode()=default
static MDTuple * getIfExists(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1403
static std::enable_if_t< std::is_base_of< MDNode, T >::value, T * > replaceWithPermanent(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a permanent one.
Definition: Metadata.h:1155
void dropAllReferences()
Definition: Metadata.cpp:798
void operator=(const MDNode &)=delete
static std::enable_if_t< std::is_base_of< MDNode, T >::value, T * > replaceWithUniqued(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a uniqued one.
Definition: Metadata.h:1167
void dumpTree() const
User-friendly dump in tree shape.
Definition: AsmWriter.cpp:4969
static MDNode * getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B)
Definition: Metadata.cpp:1184
unsigned getNumUnresolved() const
Definition: Metadata.h:1217
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:772
MDOperand()=default
void reset(Metadata *MD, Metadata *Owner)
Definition: Metadata.h:803
Metadata * operator->() const
Definition: Metadata.h:796
MDOperand & operator=(const MDOperand &)=delete
Metadata & operator*() const
Definition: Metadata.h:797
Metadata * get() const
Definition: Metadata.h:794
MDOperand(const MDOperand &)=delete
void reset()
Definition: Metadata.h:799
MDOperand & operator=(MDOperand &&Op)
Definition: Metadata.h:785
MDOperand(MDOperand &&Op)
Definition: Metadata.h:778
A single uniqued string.
Definition: Metadata.h:611
unsigned getLength() const
Definition: Metadata.h:630
const unsigned char * bytes_begin() const
Definition: Metadata.h:640
MDString(const MDString &)=delete
static MDString * get(LLVMContext &Context, const char *Str)
Definition: Metadata.h:624
MDString & operator=(MDString &&)=delete
static bool classof(const Metadata *MD)
Methods for support type inquiry through isa, cast, and dyn_cast.
Definition: Metadata.h:644
const unsigned char * bytes_end() const
Definition: Metadata.h:641
iterator begin() const
Pointer to the first byte of the string.
Definition: Metadata.h:635
MDString & operator=(const MDString &)=delete
StringRef getString() const
Definition: Metadata.cpp:507
iterator end() const
Pointer to one byte past the end of the string.
Definition: Metadata.h:638
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:497
Typed, array-like tuple of metadata.
Definition: Metadata.h:1485
MDTupleTypedArrayWrapper(const MDTupleTypedArrayWrapper< U > &Other, std::enable_if_t<!std::is_convertible< U *, T * >::value > *=nullptr)
Definition: Metadata.h:1499
MDTupleTypedArrayWrapper(const MDTuple *N)
Definition: Metadata.h:1490
T * operator[](unsigned I) const
Definition: Metadata.h:1514
MDTuple * operator->() const
Definition: Metadata.h:1508
MDTuple & operator*() const
Definition: Metadata.h:1509
MDTupleTypedArrayWrapper(const MDTupleTypedArrayWrapper< U > &Other, std::enable_if_t< std::is_convertible< U *, T * >::value > *=nullptr)
Definition: Metadata.h:1493
TypedMDOperandIterator< T > iterator
Definition: Metadata.h:1517
Tuple of metadata.
Definition: Metadata.h:1328
TempMDTuple clone() const
Return a (temporary) clone of this.
Definition: Metadata.h:1382
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a distinct node.
Definition: Metadata.h:1367
static bool classof(const Metadata *MD)
Definition: Metadata.h:1394
void push_back(Metadata *MD)
Append an element to the tuple. This will resize the node.
Definition: Metadata.h:1385
unsigned getHash() const
Get the hash, if any.
Definition: Metadata.h:1354
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1356
static MDTuple * getIfExists(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1360
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
Definition: Metadata.h:1376
void pop_back()
Shrink the operands by 1.
Definition: Metadata.h:1392
Metadata wrapper in the Value hierarchy.
Definition: Metadata.h:175
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:102
static MetadataAsValue * getIfExists(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:110
static bool classof(const Value *V)
Definition: Metadata.h:194
Metadata * getMetadata() const
Definition: Metadata.h:192
API for tracking metadata references through RAUW and deletion.
Definition: Metadata.h:211
PointerUnion< MetadataAsValue *, Metadata * > OwnerTy
Definition: Metadata.h:266
static bool isReplaceable(const Metadata &MD)
Check whether metadata is replaceable.
Definition: Metadata.cpp:190
static bool track(void *Ref, Metadata &MD, MetadataAsValue &Owner)
Track the reference to metadata for MetadataAsValue.
Definition: Metadata.h:240
static void untrack(Metadata *&MD)
Stop tracking a reference to metadata.
Definition: Metadata.h:247
static bool retrack(Metadata *&MD, Metadata *&New)
Move tracking from one reference to another.
Definition: Metadata.h:258
static bool track(Metadata *&MD)
Track the reference to metadata.
Definition: Metadata.h:222
static bool track(void *Ref, Metadata &MD, Metadata &Owner)
Track the reference to metadata for Metadata.
Definition: Metadata.h:231
Root of the metadata hierarchy.
Definition: Metadata.h:61
void handleChangedOperand(void *, Metadata *)
Default handling of a changed operand, which asserts.
Definition: Metadata.h:96
StorageType
Active type of storage.
Definition: Metadata.h:69
void print(raw_ostream &OS, const Module *M=nullptr, bool IsForDebug=false) const
Print.
Definition: AsmWriter.cpp:4894
unsigned short SubclassData16
Definition: Metadata.h:75
unsigned SubclassData32
Definition: Metadata.h:76
~Metadata()=default
unsigned char Storage
Storage flag for non-uniqued, otherwise unowned, metadata.
Definition: Metadata.h:72
unsigned getMetadataID() const
Definition: Metadata.h:101
unsigned char SubclassData1
Definition: Metadata.h:74
void printAsOperand(raw_ostream &OS, const Module *M=nullptr) const
Print as operand.
Definition: AsmWriter.cpp:4884
Metadata(unsigned ID, StorageType Storage)
Definition: Metadata.h:85
void dump() const
User-friendly dump.
Definition: AsmWriter.cpp:4960
Manage lifetime of a slot tracker for printing IR.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A tuple of MDNodes.
Definition: Metadata.h:1587
const_op_iterator op_begin() const
Definition: Metadata.h:1680
NamedMDNode(const NamedMDNode &)=delete
void dump() const
Definition: AsmWriter.cpp:4957
op_iterator_impl< MDNode *, MDNode > op_iterator
Definition: Metadata.h:1673
void setOperand(unsigned I, MDNode *New)
Definition: Metadata.cpp:1223
StringRef getName() const
Definition: Metadata.cpp:1232
void dropAllReferences()
Remove all uses and clear node vector.
Definition: Metadata.h:1652
void print(raw_ostream &ROS, bool IsForDebug=false) const
Definition: AsmWriter.cpp:4621
void eraseFromParent()
Drop all references and remove the node from parent module.
Definition: Metadata.cpp:1228
const_op_iterator op_end() const
Definition: Metadata.h:1681
iterator_range< const_op_iterator > operands() const
Definition: Metadata.h:1686
op_iterator op_end()
Definition: Metadata.h:1676
MDNode * getOperand(unsigned i) const
Definition: Metadata.cpp:1215
op_iterator op_begin()
Definition: Metadata.h:1675
unsigned getNumOperands() const
Definition: Metadata.cpp:1211
const Module * getParent() const
Definition: Metadata.h:1658
void clearOperands()
Drop all references to this node's operands.
Definition: Metadata.cpp:1230
iterator_range< op_iterator > operands()
Definition: Metadata.h:1683
op_iterator_impl< const MDNode *, MDNode > const_op_iterator
Definition: Metadata.h:1678
Module * getParent()
Get the module that holds this named metadata collection.
Definition: Metadata.h:1657
void addOperand(MDNode *M)
Definition: Metadata.cpp:1221
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
Shared implementation of use-lists for replaceable metadata.
Definition: Metadata.h:280
static void SalvageDebugInfo(const Constant &C)
Replace all uses of the constant with Undef in debug info metadata.
Definition: Metadata.cpp:248
void replaceAllUsesWith(Metadata *MD)
Replace all uses of this with MD.
Definition: Metadata.cpp:278
ReplaceableMetadataImpl(LLVMContext &Context)
Definition: Metadata.h:292
LLVMContext & getContext() const
Definition: Metadata.h:298
void resolveAllUses(bool ResolveUsers=true)
Resolve all uses of this.
Definition: Metadata.cpp:324
SmallVector< Metadata * > getAllArgListUsers()
Returns the list of all DIArgList users of this.
Definition: Metadata.cpp:194
MetadataTracking::OwnerTy OwnerTy
Definition: Metadata.h:284
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringMapEntryStorage - Holds the value in a StringMapEntry.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
const char * iterator
Definition: StringRef.h:54
const unsigned char * bytes_end() const
Definition: StringRef.h:118
iterator begin() const
Definition: StringRef.h:111
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
iterator end() const
Definition: StringRef.h:113
const unsigned char * bytes_begin() const
Definition: StringRef.h:115
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Typed iterator through MDNode operands.
Definition: Metadata.h:1451
TypedMDOperandIterator operator++(int)
Definition: Metadata.h:1471
std::ptrdiff_t difference_type
Definition: Metadata.h:1457
std::input_iterator_tag iterator_category
Definition: Metadata.h:1455
bool operator==(const TypedMDOperandIterator &X) const
Definition: Metadata.h:1477
TypedMDOperandIterator & operator++()
Definition: Metadata.h:1466
TypedMDOperandIterator(MDNode::op_iterator I)
Definition: Metadata.h:1462
bool operator!=(const TypedMDOperandIterator &X) const
Definition: Metadata.h:1478
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
Value wrapper in the Metadata hierarchy.
Definition: Metadata.h:344
Type * getType() const
Definition: Metadata.h:385
static LocalAsMetadata * getLocalIfExists(Value *Local)
Definition: Metadata.h:380
void replaceAllUsesWith(Metadata *MD)
Handle collisions after Value::replaceAllUsesWith().
Definition: Metadata.h:401
LLVMContext & getContext() const
Definition: Metadata.h:386
static void handleDeletion(Value *V)
Definition: Metadata.cpp:416
static LocalAsMetadata * getLocal(Value *Local)
Definition: Metadata.h:370
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:392
static ConstantAsMetadata * getConstantIfExists(Value *C)
Definition: Metadata.h:376
static ConstantAsMetadata * getConstant(Value *C)
Definition: Metadata.h:366
static ValueAsMetadata * getIfExists(Value *V)
Definition: Metadata.cpp:411
static void handleRAUW(Value *From, Value *To)
Definition: Metadata.cpp:435
static bool classof(const Metadata *MD)
Definition: Metadata.h:406
SmallVector< Metadata * > getAllArgListUsers()
Definition: Metadata.h:388
ValueAsMetadata(unsigned ID, Value *V)
Definition: Metadata.h:356
Value * getValue() const
Definition: Metadata.h:384
~ValueAsMetadata()=default
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:532
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:994
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:52
struct LLVMOpaqueNamedMDNode * LLVMNamedMDNodeRef
Represents an LLVM Named Metadata Node.
Definition: Types.h:96
struct LLVMOpaqueMetadata * LLVMMetadataRef
Represents an LLVM Metadata.
Definition: Types.h:89
This file defines the ilist_node class template, which is a convenient base class for creating classe...
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ArchKind & operator--(ArchKind &Kind)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
LLVMConstants
Definition: Dwarf.h:44
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract_or_null(Y &&MD)
Extract a Value from Metadata, if any, allowing null.
Definition: Metadata.h:598
std::enable_if_t< detail::IsValidPointer< X, Y >::value, bool > hasa(Y &&MD)
Check whether Metadata has a Value.
Definition: Metadata.h:540
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
Definition: Metadata.h:572
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
Definition: Metadata.h:585
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:406
APInt operator*(APInt a, uint64_t RHS)
Definition: APInt.h:2162
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:2040
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
@ Ref
The access may reference the value stored in memory.
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:285
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:292
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::optional< APInt > getAllocSize(const CallBase *CB, const TargetLibraryInfo *TLI, function_ref< const Value *(const Value *)> Mapper=[](const Value *V) { return V;})
Return the size of the requested allocation.
const uint64_t NOMORE_ICP_MAGICNUM
Magic number in the value profile metadata showing a target has been promoted for the instruction and...
Definition: Metadata.h:56
@ DEBUG_METADATA_VERSION
Definition: Metadata.h:51
#define N
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition: Metadata.h:651
AAMDNodes concat(const AAMDNodes &Other) const
Determine the best AAMDNodes after concatenating two different locations together.
static MDNode * shiftTBAAStruct(MDNode *M, size_t off)
bool operator!=(const AAMDNodes &A) const
Definition: Metadata.h:661
MDNode * TBAAStruct
The tag for type-based alias analysis (tbaa struct).
Definition: Metadata.h:671
MDNode * Scope
The tag for alias scope specification (used with noalias).
Definition: Metadata.h:674
static MDNode * extendToTBAA(MDNode *TBAA, ssize_t len)
MDNode * TBAA
The tag for type-based alias analysis.
Definition: Metadata.h:668
AAMDNodes shift(size_t Offset) const
Create a new AAMDNode that describes this AAMDNode after applying a constant offset to the start of t...
Definition: Metadata.h:705
AAMDNodes merge(const AAMDNodes &Other) const
Given two sets of AAMDNodes applying to potentially different locations, determine the best AAMDNodes...
MDNode * NoAlias
The tag specifying the noalias scope.
Definition: Metadata.h:677
AAMDNodes intersect(const AAMDNodes &Other) const
Given two sets of AAMDNodes that apply to the same pointer, give the best AAMDNodes that are compatib...
Definition: Metadata.h:694
AAMDNodes(MDNode *T, MDNode *TS, MDNode *S, MDNode *N)
Definition: Metadata.h:653
AAMDNodes extendTo(ssize_t Len) const
Create a new AAMDNode that describes this AAMDNode after extending it to apply to a series of bytes o...
Definition: Metadata.h:718
bool operator==(const AAMDNodes &A) const
Definition: Metadata.h:656
AAMDNodes()=default
static MDNode * shiftTBAA(MDNode *M, size_t off)
static AAMDNodes getEmptyKey()
Definition: Metadata.h:743
static unsigned getHashValue(const AAMDNodes &Val)
Definition: Metadata.h:753
static AAMDNodes getTombstoneKey()
Definition: Metadata.h:748
static bool isEqual(const AAMDNodes &LHS, const AAMDNodes &RHS)
Definition: Metadata.h:760
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:51
void operator()(MDNode *Node) const
Definition: Metadata.h:1416
static Yes & hasDereference(SFINAE< sizeof(static_cast< V >(*make< U >()))> *=0)
static SimpleType getSimplifiedValue(MDOperand &MD)
Definition: Metadata.h:829
static SimpleType getSimplifiedValue(const MDOperand &MD)
Definition: Metadata.h:835
Define a template that can be specialized by smart pointers to reflect the fact that they are automat...
Definition: Casting.h:34