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
793 // Check if MDOperand is of type MDString and equals `Str`.
794 bool equalsStr(StringRef Str) const {
795 return isa<MDString>(this->get()) &&
796 cast<MDString>(this->get())->getString() == Str;
797 }
798
799 ~MDOperand() { untrack(); }
800
801 Metadata *get() const { return MD; }
802 operator Metadata *() const { return get(); }
803 Metadata *operator->() const { return get(); }
804 Metadata &operator*() const { return *get(); }
805
806 void reset() {
807 untrack();
808 MD = nullptr;
809 }
810 void reset(Metadata *MD, Metadata *Owner) {
811 untrack();
812 this->MD = MD;
813 track(Owner);
814 }
815
816private:
817 void track(Metadata *Owner) {
818 if (MD) {
819 if (Owner)
820 MetadataTracking::track(this, *MD, *Owner);
821 else
823 }
824 }
825
826 void untrack() {
827 assert(static_cast<void *>(this) == &MD && "Expected same address");
828 if (MD)
830 }
831};
832
833template <> struct simplify_type<MDOperand> {
835
836 static SimpleType getSimplifiedValue(MDOperand &MD) { return MD.get(); }
837};
838
839template <> struct simplify_type<const MDOperand> {
841
842 static SimpleType getSimplifiedValue(const MDOperand &MD) { return MD.get(); }
843};
844
845/// Pointer to the context, with optional RAUW support.
846///
847/// Either a raw (non-null) pointer to the \a LLVMContext, or an owned pointer
848/// to \a ReplaceableMetadataImpl (which has a reference to \a LLVMContext).
851
852public:
855 std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses)
856 : Ptr(ReplaceableUses.release()) {
857 assert(getReplaceableUses() && "Expected non-null replaceable uses");
858 }
866
867 operator LLVMContext &() { return getContext(); }
868
869 /// Whether this contains RAUW support.
870 bool hasReplaceableUses() const {
871 return isa<ReplaceableMetadataImpl *>(Ptr);
872 }
873
875 if (hasReplaceableUses())
876 return getReplaceableUses()->getContext();
877 return *cast<LLVMContext *>(Ptr);
878 }
879
881 if (hasReplaceableUses())
882 return cast<ReplaceableMetadataImpl *>(Ptr);
883 return nullptr;
884 }
885
886 /// Ensure that this has RAUW support, and then return it.
888 if (!hasReplaceableUses())
889 makeReplaceable(std::make_unique<ReplaceableMetadataImpl>(getContext()));
890 return getReplaceableUses();
891 }
892
893 /// Assign RAUW support to this.
894 ///
895 /// Make this replaceable, taking ownership of \c ReplaceableUses (which must
896 /// not be null).
897 void
898 makeReplaceable(std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses) {
899 assert(ReplaceableUses && "Expected non-null replaceable uses");
900 assert(&ReplaceableUses->getContext() == &getContext() &&
901 "Expected same context");
902 delete getReplaceableUses();
903 Ptr = ReplaceableUses.release();
904 }
905
906 /// Drop RAUW support.
907 ///
908 /// Cede ownership of RAUW support, returning it.
909 std::unique_ptr<ReplaceableMetadataImpl> takeReplaceableUses() {
910 assert(hasReplaceableUses() && "Expected to own replaceable uses");
911 std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses(
913 Ptr = &ReplaceableUses->getContext();
914 return ReplaceableUses;
915 }
916};
917
919 inline void operator()(MDNode *Node) const;
920};
921
922#define HANDLE_MDNODE_LEAF(CLASS) \
923 using Temp##CLASS = std::unique_ptr<CLASS, TempMDNodeDeleter>;
924#define HANDLE_MDNODE_BRANCH(CLASS) HANDLE_MDNODE_LEAF(CLASS)
925#include "llvm/IR/Metadata.def"
926
927/// Metadata node.
928///
929/// Metadata nodes can be uniqued, like constants, or distinct. Temporary
930/// metadata nodes (with full support for RAUW) can be used to delay uniquing
931/// until forward references are known. The basic metadata node is an \a
932/// MDTuple.
933///
934/// There is limited support for RAUW at construction time. At construction
935/// time, if any operand is a temporary node (or an unresolved uniqued node,
936/// which indicates a transitive temporary operand), the node itself will be
937/// unresolved. As soon as all operands become resolved, it will drop RAUW
938/// support permanently.
939///
940/// If an unresolved node is part of a cycle, \a resolveCycles() needs
941/// to be called on some member of the cycle once all temporary nodes have been
942/// replaced.
943///
944/// MDNodes can be large or small, as well as resizable or non-resizable.
945/// Large MDNodes' operands are allocated in a separate storage vector,
946/// whereas small MDNodes' operands are co-allocated. Distinct and temporary
947/// MDnodes are resizable, but only MDTuples support this capability.
948///
949/// Clients can add operands to resizable MDNodes using push_back().
950class MDNode : public Metadata {
952 friend class LLVMContextImpl;
953 friend class DIArgList;
954
955 /// The header that is coallocated with an MDNode along with its "small"
956 /// operands. It is located immediately before the main body of the node.
957 /// The operands are in turn located immediately before the header.
958 /// For resizable MDNodes, the space for the storage vector is also allocated
959 /// immediately before the header, overlapping with the operands.
960 /// Explicity set alignment because bitfields by default have an
961 /// alignment of 1 on z/OS.
962 struct alignas(alignof(size_t)) Header {
963 bool IsResizable : 1;
964 bool IsLarge : 1;
965 size_t SmallSize : 4;
966 size_t SmallNumOps : 4;
967 size_t : sizeof(size_t) * CHAR_BIT - 10;
968
969 unsigned NumUnresolved = 0;
970 using LargeStorageVector = SmallVector<MDOperand, 0>;
971
972 static constexpr size_t NumOpsFitInVector =
973 sizeof(LargeStorageVector) / sizeof(MDOperand);
974 static_assert(
975 NumOpsFitInVector * sizeof(MDOperand) == sizeof(LargeStorageVector),
976 "sizeof(LargeStorageVector) must be a multiple of sizeof(MDOperand)");
977
978 static constexpr size_t MaxSmallSize = 15;
979
980 static constexpr size_t getOpSize(unsigned NumOps) {
981 return sizeof(MDOperand) * NumOps;
982 }
983 /// Returns the number of operands the node has space for based on its
984 /// allocation characteristics.
985 static size_t getSmallSize(size_t NumOps, bool IsResizable, bool IsLarge) {
986 return IsLarge ? NumOpsFitInVector
987 : std::max(NumOps, NumOpsFitInVector * IsResizable);
988 }
989 /// Returns the number of bytes allocated for operands and header.
990 static size_t getAllocSize(StorageType Storage, size_t NumOps) {
991 return getOpSize(
992 getSmallSize(NumOps, isResizable(Storage), isLarge(NumOps))) +
993 sizeof(Header);
994 }
995
996 /// Only temporary and distinct nodes are resizable.
997 static bool isResizable(StorageType Storage) { return Storage != Uniqued; }
998 static bool isLarge(size_t NumOps) { return NumOps > MaxSmallSize; }
999
1000 size_t getAllocSize() const {
1001 return getOpSize(SmallSize) + sizeof(Header);
1002 }
1003 void *getAllocation() {
1004 return reinterpret_cast<char *>(this + 1) -
1005 alignTo(getAllocSize(), alignof(uint64_t));
1006 }
1007
1008 void *getLargePtr() const {
1009 static_assert(alignof(LargeStorageVector) <= alignof(Header),
1010 "LargeStorageVector too strongly aligned");
1011 return reinterpret_cast<char *>(const_cast<Header *>(this)) -
1012 sizeof(LargeStorageVector);
1013 }
1014
1015 void *getSmallPtr();
1016
1017 LargeStorageVector &getLarge() {
1018 assert(IsLarge);
1019 return *reinterpret_cast<LargeStorageVector *>(getLargePtr());
1020 }
1021
1022 const LargeStorageVector &getLarge() const {
1023 assert(IsLarge);
1024 return *reinterpret_cast<const LargeStorageVector *>(getLargePtr());
1025 }
1026
1027 void resizeSmall(size_t NumOps);
1028 void resizeSmallToLarge(size_t NumOps);
1029 void resize(size_t NumOps);
1030
1031 explicit Header(size_t NumOps, StorageType Storage);
1032 ~Header();
1033
1034 MutableArrayRef<MDOperand> operands() {
1035 if (IsLarge)
1036 return getLarge();
1037 return MutableArrayRef(
1038 reinterpret_cast<MDOperand *>(this) - SmallSize, SmallNumOps);
1039 }
1040
1041 ArrayRef<MDOperand> operands() const {
1042 if (IsLarge)
1043 return getLarge();
1044 return ArrayRef(reinterpret_cast<const MDOperand *>(this) - SmallSize,
1045 SmallNumOps);
1046 }
1047
1048 unsigned getNumOperands() const {
1049 if (!IsLarge)
1050 return SmallNumOps;
1051 return getLarge().size();
1052 }
1053 };
1054
1055 Header &getHeader() { return *(reinterpret_cast<Header *>(this) - 1); }
1056
1057 const Header &getHeader() const {
1058 return *(reinterpret_cast<const Header *>(this) - 1);
1059 }
1060
1061 ContextAndReplaceableUses Context;
1062
1063protected:
1064 MDNode(LLVMContext &Context, unsigned ID, StorageType Storage,
1065 ArrayRef<Metadata *> Ops1, ArrayRef<Metadata *> Ops2 = std::nullopt);
1066 ~MDNode() = default;
1067
1068 void *operator new(size_t Size, size_t NumOps, StorageType Storage);
1069 void operator delete(void *Mem);
1070
1071 /// Required by std, but never called.
1072 void operator delete(void *, unsigned) {
1073 llvm_unreachable("Constructor throws?");
1074 }
1075
1076 /// Required by std, but never called.
1077 void operator delete(void *, unsigned, bool) {
1078 llvm_unreachable("Constructor throws?");
1079 }
1080
1081 void dropAllReferences();
1082
1083 MDOperand *mutable_begin() { return getHeader().operands().begin(); }
1084 MDOperand *mutable_end() { return getHeader().operands().end(); }
1085
1087
1090 }
1091
1092public:
1093 MDNode(const MDNode &) = delete;
1094 void operator=(const MDNode &) = delete;
1095 void *operator new(size_t) = delete;
1096
1097 static inline MDTuple *get(LLVMContext &Context, ArrayRef<Metadata *> MDs);
1098 static inline MDTuple *getIfExists(LLVMContext &Context,
1100 static inline MDTuple *getDistinct(LLVMContext &Context,
1102 static inline TempMDTuple getTemporary(LLVMContext &Context,
1104
1105 /// Create a (temporary) clone of this.
1106 TempMDNode clone() const;
1107
1108 /// Deallocate a node created by getTemporary.
1109 ///
1110 /// Calls \c replaceAllUsesWith(nullptr) before deleting, so any remaining
1111 /// references will be reset.
1112 static void deleteTemporary(MDNode *N);
1113
1114 LLVMContext &getContext() const { return Context.getContext(); }
1115
1116 /// Replace a specific operand.
1117 void replaceOperandWith(unsigned I, Metadata *New);
1118
1119 /// Check if node is fully resolved.
1120 ///
1121 /// If \a isTemporary(), this always returns \c false; if \a isDistinct(),
1122 /// this always returns \c true.
1123 ///
1124 /// If \a isUniqued(), returns \c true if this has already dropped RAUW
1125 /// support (because all operands are resolved).
1126 ///
1127 /// As forward declarations are resolved, their containers should get
1128 /// resolved automatically. However, if this (or one of its operands) is
1129 /// involved in a cycle, \a resolveCycles() needs to be called explicitly.
1130 bool isResolved() const { return !isTemporary() && !getNumUnresolved(); }
1131
1132 bool isUniqued() const { return Storage == Uniqued; }
1133 bool isDistinct() const { return Storage == Distinct; }
1134 bool isTemporary() const { return Storage == Temporary; }
1135
1136 /// RAUW a temporary.
1137 ///
1138 /// \pre \a isTemporary() must be \c true.
1140 assert(isTemporary() && "Expected temporary node");
1141 if (Context.hasReplaceableUses())
1142 Context.getReplaceableUses()->replaceAllUsesWith(MD);
1143 }
1144
1145 /// Resolve cycles.
1146 ///
1147 /// Once all forward declarations have been resolved, force cycles to be
1148 /// resolved.
1149 ///
1150 /// \pre No operands (or operands' operands, etc.) have \a isTemporary().
1151 void resolveCycles();
1152
1153 /// Resolve a unique, unresolved node.
1154 void resolve();
1155
1156 /// Replace a temporary node with a permanent one.
1157 ///
1158 /// Try to create a uniqued version of \c N -- in place, if possible -- and
1159 /// return it. If \c N cannot be uniqued, return a distinct node instead.
1160 template <class T>
1161 static std::enable_if_t<std::is_base_of<MDNode, T>::value, T *>
1162 replaceWithPermanent(std::unique_ptr<T, TempMDNodeDeleter> N) {
1163 return cast<T>(N.release()->replaceWithPermanentImpl());
1164 }
1165
1166 /// Replace a temporary node with a uniqued one.
1167 ///
1168 /// Create a uniqued version of \c N -- in place, if possible -- and return
1169 /// it. Takes ownership of the temporary node.
1170 ///
1171 /// \pre N does not self-reference.
1172 template <class T>
1173 static std::enable_if_t<std::is_base_of<MDNode, T>::value, T *>
1174 replaceWithUniqued(std::unique_ptr<T, TempMDNodeDeleter> N) {
1175 return cast<T>(N.release()->replaceWithUniquedImpl());
1176 }
1177
1178 /// Replace a temporary node with a distinct one.
1179 ///
1180 /// Create a distinct version of \c N -- in place, if possible -- and return
1181 /// it. Takes ownership of the temporary node.
1182 template <class T>
1183 static std::enable_if_t<std::is_base_of<MDNode, T>::value, T *>
1184 replaceWithDistinct(std::unique_ptr<T, TempMDNodeDeleter> N) {
1185 return cast<T>(N.release()->replaceWithDistinctImpl());
1186 }
1187
1188 /// Print in tree shape.
1189 ///
1190 /// Prints definition of \c this in tree shape.
1191 ///
1192 /// If \c M is provided, metadata nodes will be numbered canonically;
1193 /// otherwise, pointer addresses are substituted.
1194 /// @{
1195 void printTree(raw_ostream &OS, const Module *M = nullptr) const;
1197 const Module *M = nullptr) const;
1198 /// @}
1199
1200 /// User-friendly dump in tree shape.
1201 ///
1202 /// If \c M is provided, metadata nodes will be numbered canonically;
1203 /// otherwise, pointer addresses are substituted.
1204 ///
1205 /// Note: this uses an explicit overload instead of default arguments so that
1206 /// the nullptr version is easy to call from a debugger.
1207 ///
1208 /// @{
1209 void dumpTree() const;
1210 void dumpTree(const Module *M) const;
1211 /// @}
1212
1213private:
1214 MDNode *replaceWithPermanentImpl();
1215 MDNode *replaceWithUniquedImpl();
1216 MDNode *replaceWithDistinctImpl();
1217
1218protected:
1219 /// Set an operand.
1220 ///
1221 /// Sets the operand directly, without worrying about uniquing.
1222 void setOperand(unsigned I, Metadata *New);
1223
1224 unsigned getNumUnresolved() const { return getHeader().NumUnresolved; }
1225
1226 void setNumUnresolved(unsigned N) { getHeader().NumUnresolved = N; }
1228 template <class T, class StoreT>
1229 static T *storeImpl(T *N, StorageType Storage, StoreT &Store);
1230 template <class T> static T *storeImpl(T *N, StorageType Storage);
1231
1232 /// Resize the node to hold \a NumOps operands.
1233 ///
1234 /// \pre \a isTemporary() or \a isDistinct()
1235 /// \pre MetadataID == MDTupleKind
1236 void resize(size_t NumOps) {
1237 assert(!isUniqued() && "Resizing is not supported for uniqued nodes");
1238 assert(getMetadataID() == MDTupleKind &&
1239 "Resizing is not supported for this node kind");
1240 getHeader().resize(NumOps);
1241 }
1242
1243private:
1244 void handleChangedOperand(void *Ref, Metadata *New);
1245
1246 /// Drop RAUW support, if any.
1247 void dropReplaceableUses();
1248
1249 void resolveAfterOperandChange(Metadata *Old, Metadata *New);
1250 void decrementUnresolvedOperandCount();
1251 void countUnresolvedOperands();
1252
1253 /// Mutate this to be "uniqued".
1254 ///
1255 /// Mutate this so that \a isUniqued().
1256 /// \pre \a isTemporary().
1257 /// \pre already added to uniquing set.
1258 void makeUniqued();
1259
1260 /// Mutate this to be "distinct".
1261 ///
1262 /// Mutate this so that \a isDistinct().
1263 /// \pre \a isTemporary().
1264 void makeDistinct();
1265
1266 void deleteAsSubclass();
1267 MDNode *uniquify();
1268 void eraseFromStore();
1269
1270 template <class NodeTy> struct HasCachedHash;
1271 template <class NodeTy>
1272 static void dispatchRecalculateHash(NodeTy *N, std::true_type) {
1273 N->recalculateHash();
1274 }
1275 template <class NodeTy>
1276 static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
1277 template <class NodeTy>
1278 static void dispatchResetHash(NodeTy *N, std::true_type) {
1279 N->setHash(0);
1280 }
1281 template <class NodeTy>
1282 static void dispatchResetHash(NodeTy *, std::false_type) {}
1283
1284 /// Merge branch weights from two direct callsites.
1285 static MDNode *mergeDirectCallProfMetadata(MDNode *A, MDNode *B,
1286 const Instruction *AInstr,
1287 const Instruction *BInstr);
1288
1289public:
1290 using op_iterator = const MDOperand *;
1292
1294 return const_cast<MDNode *>(this)->mutable_begin();
1295 }
1296
1298 return const_cast<MDNode *>(this)->mutable_end();
1299 }
1300
1301 ArrayRef<MDOperand> operands() const { return getHeader().operands(); }
1302
1303 const MDOperand &getOperand(unsigned I) const {
1304 assert(I < getNumOperands() && "Out of range");
1305 return getHeader().operands()[I];
1306 }
1307
1308 /// Return number of MDNode operands.
1309 unsigned getNumOperands() const { return getHeader().getNumOperands(); }
1310
1311 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1312 static bool classof(const Metadata *MD) {
1313 switch (MD->getMetadataID()) {
1314 default:
1315 return false;
1316#define HANDLE_MDNODE_LEAF(CLASS) \
1317 case CLASS##Kind: \
1318 return true;
1319#include "llvm/IR/Metadata.def"
1320 }
1321 }
1322
1323 /// Check whether MDNode is a vtable access.
1324 bool isTBAAVtableAccess() const;
1325
1326 /// Methods for metadata merging.
1327 static MDNode *concatenate(MDNode *A, MDNode *B);
1328 static MDNode *intersect(MDNode *A, MDNode *B);
1334 /// Merge !prof metadata from two instructions.
1335 /// Currently only implemented with direct callsites with branch weights.
1337 const Instruction *AInstr,
1338 const Instruction *BInstr);
1339};
1340
1341/// Tuple of metadata.
1342///
1343/// This is the simple \a MDNode arbitrary tuple. Nodes are uniqued by
1344/// default based on their operands.
1345class MDTuple : public MDNode {
1346 friend class LLVMContextImpl;
1347 friend class MDNode;
1348
1349 MDTuple(LLVMContext &C, StorageType Storage, unsigned Hash,
1351 : MDNode(C, MDTupleKind, Storage, Vals) {
1352 setHash(Hash);
1353 }
1354
1356
1357 void setHash(unsigned Hash) { SubclassData32 = Hash; }
1358 void recalculateHash();
1359
1360 static MDTuple *getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
1361 StorageType Storage, bool ShouldCreate = true);
1362
1363 TempMDTuple cloneImpl() const {
1364 ArrayRef<MDOperand> Operands = operands();
1365 return getTemporary(getContext(), SmallVector<Metadata *, 4>(
1366 Operands.begin(), Operands.end()));
1367 }
1368
1369public:
1370 /// Get the hash, if any.
1371 unsigned getHash() const { return SubclassData32; }
1372
1374 return getImpl(Context, MDs, Uniqued);
1375 }
1376
1378 return getImpl(Context, MDs, Uniqued, /* ShouldCreate */ false);
1379 }
1380
1381 /// Return a distinct node.
1382 ///
1383 /// Return a distinct node -- i.e., a node that is not uniqued.
1385 return getImpl(Context, MDs, Distinct);
1386 }
1387
1388 /// Return a temporary node.
1389 ///
1390 /// For use in constructing cyclic MDNode structures. A temporary MDNode is
1391 /// not uniqued, may be RAUW'd, and must be manually deleted with
1392 /// deleteTemporary.
1393 static TempMDTuple getTemporary(LLVMContext &Context,
1395 return TempMDTuple(getImpl(Context, MDs, Temporary));
1396 }
1397
1398 /// Return a (temporary) clone of this.
1399 TempMDTuple clone() const { return cloneImpl(); }
1400
1401 /// Append an element to the tuple. This will resize the node.
1403 size_t NumOps = getNumOperands();
1404 resize(NumOps + 1);
1405 setOperand(NumOps, MD);
1406 }
1407
1408 /// Shrink the operands by 1.
1409 void pop_back() { resize(getNumOperands() - 1); }
1410
1411 static bool classof(const Metadata *MD) {
1412 return MD->getMetadataID() == MDTupleKind;
1413 }
1414};
1415
1417 return MDTuple::get(Context, MDs);
1418}
1419
1421 return MDTuple::getIfExists(Context, MDs);
1422}
1423
1425 return MDTuple::getDistinct(Context, MDs);
1426}
1427
1430 return MDTuple::getTemporary(Context, MDs);
1431}
1432
1435}
1436
1437/// This is a simple wrapper around an MDNode which provides a higher-level
1438/// interface by hiding the details of how alias analysis information is encoded
1439/// in its operands.
1441 const MDNode *Node = nullptr;
1442
1443public:
1444 AliasScopeNode() = default;
1445 explicit AliasScopeNode(const MDNode *N) : Node(N) {}
1446
1447 /// Get the MDNode for this AliasScopeNode.
1448 const MDNode *getNode() const { return Node; }
1449
1450 /// Get the MDNode for this AliasScopeNode's domain.
1451 const MDNode *getDomain() const {
1452 if (Node->getNumOperands() < 2)
1453 return nullptr;
1454 return dyn_cast_or_null<MDNode>(Node->getOperand(1));
1455 }
1457 if (Node->getNumOperands() > 2)
1458 if (MDString *N = dyn_cast_or_null<MDString>(Node->getOperand(2)))
1459 return N->getString();
1460 return StringRef();
1461 }
1462};
1463
1464/// Typed iterator through MDNode operands.
1465///
1466/// An iterator that transforms an \a MDNode::iterator into an iterator over a
1467/// particular Metadata subclass.
1468template <class T> class TypedMDOperandIterator {
1469 MDNode::op_iterator I = nullptr;
1470
1471public:
1472 using iterator_category = std::input_iterator_tag;
1473 using value_type = T *;
1474 using difference_type = std::ptrdiff_t;
1475 using pointer = void;
1476 using reference = T *;
1477
1480
1481 T *operator*() const { return cast_or_null<T>(*I); }
1482
1484 ++I;
1485 return *this;
1486 }
1487
1489 TypedMDOperandIterator Temp(*this);
1490 ++I;
1491 return Temp;
1492 }
1493
1494 bool operator==(const TypedMDOperandIterator &X) const { return I == X.I; }
1495 bool operator!=(const TypedMDOperandIterator &X) const { return I != X.I; }
1496};
1497
1498/// Typed, array-like tuple of metadata.
1499///
1500/// This is a wrapper for \a MDTuple that makes it act like an array holding a
1501/// particular type of metadata.
1502template <class T> class MDTupleTypedArrayWrapper {
1503 const MDTuple *N = nullptr;
1504
1505public:
1508
1509 template <class U>
1512 std::enable_if_t<std::is_convertible<U *, T *>::value> * = nullptr)
1513 : N(Other.get()) {}
1514
1515 template <class U>
1518 std::enable_if_t<!std::is_convertible<U *, T *>::value> * = nullptr)
1519 : N(Other.get()) {}
1520
1521 explicit operator bool() const { return get(); }
1522 explicit operator MDTuple *() const { return get(); }
1523
1524 MDTuple *get() const { return const_cast<MDTuple *>(N); }
1525 MDTuple *operator->() const { return get(); }
1526 MDTuple &operator*() const { return *get(); }
1527
1528 // FIXME: Fix callers and remove condition on N.
1529 unsigned size() const { return N ? N->getNumOperands() : 0u; }
1530 bool empty() const { return N ? N->getNumOperands() == 0 : true; }
1531 T *operator[](unsigned I) const { return cast_or_null<T>(N->getOperand(I)); }
1532
1533 // FIXME: Fix callers and remove condition on N.
1535
1536 iterator begin() const { return N ? iterator(N->op_begin()) : iterator(); }
1537 iterator end() const { return N ? iterator(N->op_end()) : iterator(); }
1538};
1539
1540#define HANDLE_METADATA(CLASS) \
1541 using CLASS##Array = MDTupleTypedArrayWrapper<CLASS>;
1542#include "llvm/IR/Metadata.def"
1543
1544/// Placeholder metadata for operands of distinct MDNodes.
1545///
1546/// This is a lightweight placeholder for an operand of a distinct node. It's
1547/// purpose is to help track forward references when creating a distinct node.
1548/// This allows distinct nodes involved in a cycle to be constructed before
1549/// their operands without requiring a heavyweight temporary node with
1550/// full-blown RAUW support.
1551///
1552/// Each placeholder supports only a single MDNode user. Clients should pass
1553/// an ID, retrieved via \a getID(), to indicate the "real" operand that this
1554/// should be replaced with.
1555///
1556/// While it would be possible to implement move operators, they would be
1557/// fairly expensive. Leave them unimplemented to discourage their use
1558/// (clients can use std::deque, std::list, BumpPtrAllocator, etc.).
1560 friend class MetadataTracking;
1561
1562 Metadata **Use = nullptr;
1563
1564public:
1566 : Metadata(DistinctMDOperandPlaceholderKind, Distinct) {
1568 }
1569
1573
1575 if (Use)
1576 *Use = nullptr;
1577 }
1578
1579 unsigned getID() const { return SubclassData32; }
1580
1581 /// Replace the use of this with MD.
1583 if (!Use)
1584 return;
1585 *Use = MD;
1586
1587 if (*Use)
1589
1590 Metadata *T = cast<Metadata>(this);
1592 assert(!Use && "Use is still being tracked despite being untracked!");
1593 }
1594};
1595
1596//===----------------------------------------------------------------------===//
1597/// A tuple of MDNodes.
1598///
1599/// Despite its name, a NamedMDNode isn't itself an MDNode.
1600///
1601/// NamedMDNodes are named module-level entities that contain lists of MDNodes.
1602///
1603/// It is illegal for a NamedMDNode to appear as an operand of an MDNode.
1604class NamedMDNode : public ilist_node<NamedMDNode> {
1605 friend class LLVMContextImpl;
1606 friend class Module;
1607
1608 std::string Name;
1609 Module *Parent = nullptr;
1610 void *Operands; // SmallVector<TrackingMDRef, 4>
1611
1612 void setParent(Module *M) { Parent = M; }
1613
1614 explicit NamedMDNode(const Twine &N);
1615
1616 template <class T1, class T2> class op_iterator_impl {
1617 friend class NamedMDNode;
1618
1619 const NamedMDNode *Node = nullptr;
1620 unsigned Idx = 0;
1621
1622 op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) {}
1623
1624 public:
1625 using iterator_category = std::bidirectional_iterator_tag;
1626 using value_type = T2;
1627 using difference_type = std::ptrdiff_t;
1628 using pointer = value_type *;
1629 using reference = value_type &;
1630
1631 op_iterator_impl() = default;
1632
1633 bool operator==(const op_iterator_impl &o) const { return Idx == o.Idx; }
1634 bool operator!=(const op_iterator_impl &o) const { return Idx != o.Idx; }
1635
1636 op_iterator_impl &operator++() {
1637 ++Idx;
1638 return *this;
1639 }
1640
1641 op_iterator_impl operator++(int) {
1642 op_iterator_impl tmp(*this);
1643 operator++();
1644 return tmp;
1645 }
1646
1647 op_iterator_impl &operator--() {
1648 --Idx;
1649 return *this;
1650 }
1651
1652 op_iterator_impl operator--(int) {
1653 op_iterator_impl tmp(*this);
1654 operator--();
1655 return tmp;
1656 }
1657
1658 T1 operator*() const { return Node->getOperand(Idx); }
1659 };
1660
1661public:
1662 NamedMDNode(const NamedMDNode &) = delete;
1663 ~NamedMDNode();
1664
1665 /// Drop all references and remove the node from parent module.
1666 void eraseFromParent();
1667
1668 /// Remove all uses and clear node vector.
1670 /// Drop all references to this node's operands.
1671 void clearOperands();
1672
1673 /// Get the module that holds this named metadata collection.
1674 inline Module *getParent() { return Parent; }
1675 inline const Module *getParent() const { return Parent; }
1676
1677 MDNode *getOperand(unsigned i) const;
1678 unsigned getNumOperands() const;
1679 void addOperand(MDNode *M);
1680 void setOperand(unsigned I, MDNode *New);
1681 StringRef getName() const;
1682 void print(raw_ostream &ROS, bool IsForDebug = false) const;
1683 void print(raw_ostream &ROS, ModuleSlotTracker &MST,
1684 bool IsForDebug = false) const;
1685 void dump() const;
1686
1687 // ---------------------------------------------------------------------------
1688 // Operand Iterator interface...
1689 //
1690 using op_iterator = op_iterator_impl<MDNode *, MDNode>;
1691
1692 op_iterator op_begin() { return op_iterator(this, 0); }
1694
1695 using const_op_iterator = op_iterator_impl<const MDNode *, MDNode>;
1696
1697 const_op_iterator op_begin() const { return const_op_iterator(this, 0); }
1699
1701 return make_range(op_begin(), op_end());
1702 }
1704 return make_range(op_begin(), op_end());
1705 }
1706};
1707
1708// Create wrappers for C Binding types (see CBindingWrapping.h).
1710
1711} // end namespace llvm
1712
1713#endif // LLVM_IR_METADATA_H
aarch64 promote const
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:391
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")
bool operator==(const HTTPRequest &A, const HTTPRequest &B)
Definition: HTTPClient.cpp:29
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())
raw_pwrite_stream & OS
This file defines the SmallVector class.
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:1440
AliasScopeNode()=default
AliasScopeNode(const MDNode *N)
Definition: Metadata.h:1445
const MDNode * getNode() const
Get the MDNode for this AliasScopeNode.
Definition: Metadata.h:1448
const MDNode * getDomain() const
Get the MDNode for this AliasScopeNode's domain.
Definition: Metadata.h:1451
StringRef getName() const
Definition: Metadata.h:1456
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:849
ContextAndReplaceableUses & operator=(const ContextAndReplaceableUses &)=delete
ReplaceableMetadataImpl * getReplaceableUses() const
Definition: Metadata.h:880
std::unique_ptr< ReplaceableMetadataImpl > takeReplaceableUses()
Drop RAUW support.
Definition: Metadata.h:909
ContextAndReplaceableUses & operator=(ContextAndReplaceableUses &&)=delete
ReplaceableMetadataImpl * getOrCreateReplaceableUses()
Ensure that this has RAUW support, and then return it.
Definition: Metadata.h:887
void makeReplaceable(std::unique_ptr< ReplaceableMetadataImpl > ReplaceableUses)
Assign RAUW support to this.
Definition: Metadata.h:898
ContextAndReplaceableUses(ContextAndReplaceableUses &&)=delete
ContextAndReplaceableUses(const ContextAndReplaceableUses &)=delete
LLVMContext & getContext() const
Definition: Metadata.h:874
bool hasReplaceableUses() const
Whether this contains RAUW support.
Definition: Metadata.h:870
ContextAndReplaceableUses(LLVMContext &Context)
Definition: Metadata.h:853
ContextAndReplaceableUses(std::unique_ptr< ReplaceableMetadataImpl > ReplaceableUses)
Definition: Metadata.h:854
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:1559
void replaceUseWith(Metadata *MD)
Replace the use of this with MD.
Definition: Metadata.h:1582
DistinctMDOperandPlaceholder(const DistinctMDOperandPlaceholder &)=delete
DistinctMDOperandPlaceholder(unsigned ID)
Definition: Metadata.h:1565
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:950
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
Definition: Metadata.cpp:1034
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:970
iterator_range< MDOperand * > mutable_op_range
Definition: Metadata.h:1086
void resolveCycles()
Resolve cycles.
Definition: Metadata.cpp:734
bool isTBAAVtableAccess() const
Check whether MDNode is a vtable access.
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1424
mutable_op_range mutable_operands()
Definition: Metadata.h:1088
void replaceAllUsesWith(Metadata *MD)
RAUW a temporary.
Definition: Metadata.h:1139
static MDNode * concatenate(MDNode *A, MDNode *B)
Methods for metadata merging.
Definition: Metadata.cpp:1007
static void deleteTemporary(MDNode *N)
Deallocate a node created by getTemporary.
Definition: Metadata.cpp:942
void resolve()
Resolve a unique, unresolved node.
Definition: Metadata.cpp:688
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1303
void storeDistinctInContext()
Definition: Metadata.cpp:948
bool isTemporary() const
Definition: Metadata.h:1134
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1428
ArrayRef< MDOperand > operands() const
Definition: Metadata.h:1301
op_iterator op_end() const
Definition: Metadata.h:1297
MDNode(const MDNode &)=delete
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1416
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:1184
static MDNode * getMergedProfMetadata(MDNode *A, MDNode *B, const Instruction *AInstr, const Instruction *BInstr)
Merge !prof metadata from two instructions.
Definition: Metadata.cpp:1116
static bool classof(const Metadata *MD)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition: Metadata.h:1312
bool isUniqued() const
Definition: Metadata.h:1132
static MDNode * getMostGenericFPMath(MDNode *A, MDNode *B)
Definition: Metadata.cpp:1066
void setNumUnresolved(unsigned N)
Definition: Metadata.h:1226
void resize(size_t NumOps)
Resize the node to hold NumOps operands.
Definition: Metadata.h:1236
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1309
MDOperand * mutable_begin()
Definition: Metadata.h:1083
TempMDNode clone() const
Create a (temporary) clone of this.
Definition: Metadata.cpp:560
static MDNode * getMostGenericRange(MDNode *A, MDNode *B)
Definition: Metadata.cpp:1178
bool isDistinct() const
Definition: Metadata.h:1133
void setOperand(unsigned I, Metadata *New)
Set an operand.
Definition: Metadata.cpp:982
MDNode(LLVMContext &Context, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2=std::nullopt)
Definition: Metadata.cpp:543
bool isResolved() const
Check if node is fully resolved.
Definition: Metadata.h:1130
op_iterator op_begin() const
Definition: Metadata.h:1293
static MDNode * intersect(MDNode *A, MDNode *B)
Definition: Metadata.cpp:1021
static T * storeImpl(T *N, StorageType Storage, StoreT &Store)
Definition: MetadataImpl.h:42
LLVMContext & getContext() const
Definition: Metadata.h:1114
MDOperand * mutable_end()
Definition: Metadata.h:1084
~MDNode()=default
static MDTuple * getIfExists(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1420
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:1162
void dropAllReferences()
Definition: Metadata.cpp:800
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:1174
void dumpTree() const
User-friendly dump in tree shape.
Definition: AsmWriter.cpp:4969
static MDNode * getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B)
Definition: Metadata.cpp:1250
unsigned getNumUnresolved() const
Definition: Metadata.h:1224
Tracking metadata reference owned by Metadata.
Definition: Metadata.h:772
MDOperand()=default
bool equalsStr(StringRef Str) const
Definition: Metadata.h:794
void reset(Metadata *MD, Metadata *Owner)
Definition: Metadata.h:810
Metadata * operator->() const
Definition: Metadata.h:803
MDOperand & operator=(const MDOperand &)=delete
Metadata & operator*() const
Definition: Metadata.h:804
Metadata * get() const
Definition: Metadata.h:801
MDOperand(const MDOperand &)=delete
void reset()
Definition: Metadata.h:806
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:509
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:499
Typed, array-like tuple of metadata.
Definition: Metadata.h:1502
MDTupleTypedArrayWrapper(const MDTupleTypedArrayWrapper< U > &Other, std::enable_if_t<!std::is_convertible< U *, T * >::value > *=nullptr)
Definition: Metadata.h:1516
MDTupleTypedArrayWrapper(const MDTuple *N)
Definition: Metadata.h:1507
T * operator[](unsigned I) const
Definition: Metadata.h:1531
MDTuple * operator->() const
Definition: Metadata.h:1525
MDTuple & operator*() const
Definition: Metadata.h:1526
MDTupleTypedArrayWrapper(const MDTupleTypedArrayWrapper< U > &Other, std::enable_if_t< std::is_convertible< U *, T * >::value > *=nullptr)
Definition: Metadata.h:1510
TypedMDOperandIterator< T > iterator
Definition: Metadata.h:1534
Tuple of metadata.
Definition: Metadata.h:1345
TempMDTuple clone() const
Return a (temporary) clone of this.
Definition: Metadata.h:1399
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a distinct node.
Definition: Metadata.h:1384
static bool classof(const Metadata *MD)
Definition: Metadata.h:1411
void push_back(Metadata *MD)
Append an element to the tuple. This will resize the node.
Definition: Metadata.h:1402
unsigned getHash() const
Get the hash, if any.
Definition: Metadata.h:1371
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1373
static MDTuple * getIfExists(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1377
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
Definition: Metadata.h:1393
void pop_back()
Shrink the operands by 1.
Definition: Metadata.h:1409
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:1604
const_op_iterator op_begin() const
Definition: Metadata.h:1697
NamedMDNode(const NamedMDNode &)=delete
void dump() const
Definition: AsmWriter.cpp:4957
op_iterator_impl< MDNode *, MDNode > op_iterator
Definition: Metadata.h:1690
void setOperand(unsigned I, MDNode *New)
Definition: Metadata.cpp:1289
StringRef getName() const
Definition: Metadata.cpp:1298
void dropAllReferences()
Remove all uses and clear node vector.
Definition: Metadata.h:1669
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:1294
const_op_iterator op_end() const
Definition: Metadata.h:1698
iterator_range< const_op_iterator > operands() const
Definition: Metadata.h:1703
op_iterator op_end()
Definition: Metadata.h:1693
MDNode * getOperand(unsigned i) const
Definition: Metadata.cpp:1281
op_iterator op_begin()
Definition: Metadata.h:1692
unsigned getNumOperands() const
Definition: Metadata.cpp:1277
const Module * getParent() const
Definition: Metadata.h:1675
void clearOperands()
Drop all references to this node's operands.
Definition: Metadata.cpp:1296
iterator_range< op_iterator > operands()
Definition: Metadata.h:1700
op_iterator_impl< const MDNode *, MDNode > const_op_iterator
Definition: Metadata.h:1695
Module * getParent()
Get the module that holds this named metadata collection.
Definition: Metadata.h:1674
void addOperand(MDNode *M)
Definition: Metadata.cpp:1287
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:326
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:1468
TypedMDOperandIterator operator++(int)
Definition: Metadata.h:1488
std::ptrdiff_t difference_type
Definition: Metadata.h:1474
std::input_iterator_tag iterator_category
Definition: Metadata.h:1472
bool operator==(const TypedMDOperandIterator &X) const
Definition: Metadata.h:1494
TypedMDOperandIterator & operator++()
Definition: Metadata.h:1483
TypedMDOperandIterator(MDNode::op_iterator I)
Definition: Metadata.h:1479
bool operator!=(const TypedMDOperandIterator &X) const
Definition: Metadata.h:1495
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:418
static LocalAsMetadata * getLocal(Value *Local)
Definition: Metadata.h:370
static ValueAsMetadata * get(Value *V)
Definition: Metadata.cpp:394
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:413
static void handleRAUW(Value *From, Value *To)
Definition: Metadata.cpp:437
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
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:440
APInt operator*(APInt a, uint64_t RHS)
Definition: APInt.h:2174
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:2052
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:290
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:1433
static Yes & hasDereference(SFINAE< sizeof(static_cast< V >(*make< U >()))> *=0)
static SimpleType getSimplifiedValue(MDOperand &MD)
Definition: Metadata.h:836
static SimpleType getSimplifiedValue(const MDOperand &MD)
Definition: Metadata.h:842
Define a template that can be specialized by smart pointers to reflect the fact that they are automat...
Definition: Casting.h:34