15 #ifndef LLVM_IR_METADATA_H 16 #define LLVM_IR_METADATA_H 41 #include <type_traits> 47 class ModuleSlotTracker;
62 const unsigned char SubclassID;
79 #define HANDLE_METADATA_LEAF(CLASS) CLASS##Kind, 80 #include "llvm/IR/Metadata.def" 86 static_assert(
sizeof(*
this) == 8,
"Metadata fields poorly packed");
123 bool IsForDebug =
false)
const;
125 bool IsForDebug =
false)
const;
137 const Module *M =
nullptr)
const;
146 return reinterpret_cast<Metadata**
>(MDs);
149 #define HANDLE_METADATA(CLASS) class CLASS; 150 #include "llvm/IR/Metadata.def" 154 #define HANDLE_METADATA_LEAF(CLASS) \ 155 template <> struct isa_impl<CLASS, Metadata> { \ 156 static inline bool doit(const Metadata &MD) { \ 157 return MD.getMetadataID() == Metadata::CLASS##Kind; \ 160 #include "llvm/IR/Metadata.def" 183 void dropUse() { MD =
nullptr; }
198 void handleChangedMetadata(
Metadata *MD);
222 return track(&MD, *MD, static_cast<Metadata *>(
nullptr));
231 return track(Ref, MD, &Owner);
240 return track(Ref, MD, &Owner);
258 return retrack(&MD, *MD, &New);
260 static bool retrack(
void *Ref,
Metadata &MD,
void *New);
263 static bool isReplaceable(
const Metadata &MD);
287 uint64_t NextIndex = 0;
294 assert(UseMap.
empty() &&
"Cannot destroy in-use replaceable metadata");
302 void replaceAllUsesWith(
Metadata *MD);
309 void resolveAllUses(
bool ResolveUsers =
true);
313 void dropRef(
void *Ref);
314 void moveRef(
void *Ref,
void *New,
const Metadata &MD);
328 static bool isReplaceable(
const Metadata &MD);
353 assert(V &&
"Expected valid value");
362 return cast<ConstantAsMetadata>(
get(
C));
366 return cast<LocalAsMetadata>(
get(Local));
372 return cast_or_null<ConstantAsMetadata>(getIfExists(C));
376 return cast_or_null<LocalAsMetadata>(getIfExists(Local));
383 static void handleDeletion(
Value *V);
432 assert(!isa<Constant>(Local) &&
"Expected local value");
501 template <
class T>
T &
make();
507 template <
class U,
class V>
508 static Yes &hasDereference(
SFINAE<
sizeof(static_cast<V>(*make<U>()))> * = 0);
509 template <
class U,
class V>
static No &hasDereference(...);
511 static const bool value =
512 sizeof(hasDereference<T, Result>(
nullptr)) ==
sizeof(
Yes);
515 static const bool value = std::is_base_of<Constant, V>::value &&
519 static const bool value = std::is_base_of<Constant, V>::value &&
520 std::is_convertible<M, const Metadata &>::value;
529 template <
class X,
class Y>
530 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value,
bool>
::type 532 assert(MD &&
"Null pointer sent into hasa");
533 if (
auto *V = dyn_cast<ConstantAsMetadata>(MD))
534 return isa<X>(V->getValue());
537 template <
class X,
class Y>
539 typename std::enable_if<detail::IsValidReference<X, Y &>::value,
bool>
::type 547 template <
class X,
class Y>
548 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value,
X *>
::type 550 return cast<X>(cast<ConstantAsMetadata>(MD)->getValue());
552 template <
class X,
class Y>
554 typename std::enable_if<detail::IsValidReference<X, Y &>::value,
X *>
::type 563 template <
class X,
class Y>
564 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value,
X *>
::type 566 if (
auto *V = cast_or_null<ConstantAsMetadata>(MD))
567 return cast<X>(V->getValue());
576 template <
class X,
class Y>
577 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value,
X *>
::type 579 if (
auto *V = dyn_cast<ConstantAsMetadata>(MD))
589 template <
class X,
class Y>
590 inline typename std::enable_if<detail::IsValidPointer<X, Y>::value,
X *>
::type 592 if (
auto *V = dyn_cast_or_null<ConstantAsMetadata>(MD))
656 explicit operator bool()
const {
679 Result.
TBAA = Other.
TBAA == TBAA ? TBAA :
nullptr;
692 nullptr,
nullptr,
nullptr);
697 nullptr,
nullptr,
nullptr);
756 assert(static_cast<void *>(
this) == &MD &&
"Expected same address");
784 std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses)
785 : Ptr(ReplaceableUses.
release()) {
786 assert(getReplaceableUses() &&
"Expected non-null replaceable uses");
804 if (hasReplaceableUses())
805 return getReplaceableUses()->getContext();
810 if (hasReplaceableUses())
817 if (!hasReplaceableUses())
818 makeReplaceable(std::make_unique<ReplaceableMetadataImpl>(getContext()));
819 return getReplaceableUses();
828 assert(ReplaceableUses &&
"Expected non-null replaceable uses");
829 assert(&ReplaceableUses->getContext() == &getContext() &&
830 "Expected same context");
831 delete getReplaceableUses();
832 Ptr = ReplaceableUses.release();
839 assert(hasReplaceableUses() &&
"Expected to own replaceable uses");
840 std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses(
841 getReplaceableUses());
842 Ptr = &ReplaceableUses->getContext();
843 return ReplaceableUses;
851 #define HANDLE_MDNODE_LEAF(CLASS) \ 852 using Temp##CLASS = std::unique_ptr<CLASS, TempMDNodeDeleter>; 853 #define HANDLE_MDNODE_BRANCH(CLASS) HANDLE_MDNODE_LEAF(CLASS) 854 #include "llvm/IR/Metadata.def" 876 unsigned NumOperands;
877 unsigned NumUnresolved;
886 void *
operator new(
size_t Size,
unsigned NumOps);
887 void operator delete(
void *Mem);
899 void dropAllReferences();
912 void operator=(
const MDNode &) =
delete;
913 void *
operator new(
size_t) =
delete;
920 static inline TempMDTuple getTemporary(
LLVMContext &Context,
924 TempMDNode clone()
const;
930 static void deleteTemporary(
MDNode *
N);
935 void replaceOperandWith(
unsigned I,
Metadata *New);
948 bool isResolved()
const {
return !isTemporary() && !NumUnresolved; }
958 assert(isTemporary() &&
"Expected temporary node");
959 if (Context.hasReplaceableUses())
960 Context.getReplaceableUses()->replaceAllUsesWith(MD);
969 void resolveCycles();
979 static typename std::enable_if<std::is_base_of<MDNode, T>::value,
T *>
::type 981 return cast<T>(N.release()->replaceWithPermanentImpl());
991 static typename std::enable_if<std::is_base_of<MDNode, T>::value,
T *>
::type 993 return cast<T>(N.release()->replaceWithUniquedImpl());
1001 static typename std::enable_if<std::is_base_of<MDNode, T>::value,
T *>
::type 1003 return cast<T>(N.release()->replaceWithDistinctImpl());
1007 MDNode *replaceWithPermanentImpl();
1008 MDNode *replaceWithUniquedImpl();
1009 MDNode *replaceWithDistinctImpl();
1015 void setOperand(
unsigned I,
Metadata *New);
1017 void storeDistinctInContext();
1018 template <
class T,
class StoreT>
1020 template <
class T>
static T *storeImpl(
T *N,
StorageType Storage);
1026 void dropReplaceableUses();
1029 void decrementUnresolvedOperandCount();
1030 void countUnresolvedOperands();
1043 void makeDistinct();
1045 void deleteAsSubclass();
1047 void eraseFromStore();
1049 template <
class NodeTy>
struct HasCachedHash;
1050 template <
class NodeTy>
1051 static void dispatchRecalculateHash(NodeTy *N, std::true_type) {
1052 N->recalculateHash();
1054 template <
class NodeTy>
1055 static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
1056 template <
class NodeTy>
1057 static void dispatchResetHash(NodeTy *N, std::true_type) {
1060 template <
class NodeTy>
1061 static void dispatchResetHash(NodeTy *, std::false_type) {}
1068 return const_cast<MDNode *
>(
this)->mutable_begin();
1072 return const_cast<MDNode *
>(
this)->mutable_end();
1078 assert(I < NumOperands &&
"Out of range");
1079 return op_begin()[
I];
1090 #define HANDLE_MDNODE_LEAF(CLASS) \ 1093 #include "llvm/IR/Metadata.def" 1098 bool isTBAAVtableAccess()
const;
1120 :
MDNode(C, MDTupleKind, Storage, Vals) {
1124 ~
MDTuple() { dropAllReferences(); }
1127 void recalculateHash();
1132 TempMDTuple cloneImpl()
const {
1133 return getTemporary(getContext(),
1167 TempMDTuple
clone()
const {
return cloneImpl(); }
1201 :
public std::iterator<std::input_iterator_tag, T *, std::ptrdiff_t, void,
1240 typename std::enable_if<std::is_convertible<U *, T *>::value>::
type * =
1247 typename std::enable_if<!std::is_convertible<U *, T *>::value>::
type * =
1251 explicit operator bool()
const {
return get(); }
1252 explicit operator MDTuple *()
const {
return get(); }
1270 #define HANDLE_METADATA(CLASS) \ 1271 using CLASS##Array = MDTupleTypedArrayWrapper<CLASS>; 1272 #include "llvm/IR/Metadata.def" 1322 assert(!Use &&
"Use is still being tracked despite being untracked!");
1339 Module *Parent =
nullptr;
1342 void setParent(
Module *M) { Parent = M; }
1346 template<
class T1,
class T2>
1347 class op_iterator_impl :
1348 public std::iterator<std::bidirectional_iterator_tag, T2> {
1354 op_iterator_impl(
const NamedMDNode *
N,
unsigned i) : Node(N), Idx(i) {}
1357 op_iterator_impl() =
default;
1359 bool operator==(
const op_iterator_impl &o)
const {
return Idx == o.Idx; }
1360 bool operator!=(
const op_iterator_impl &o)
const {
return Idx != o.Idx; }
1362 op_iterator_impl &operator++() {
1367 op_iterator_impl operator++(
int) {
1368 op_iterator_impl tmp(*
this);
1373 op_iterator_impl &operator--() {
1378 op_iterator_impl operator--(
int) {
1379 op_iterator_impl tmp(*
this);
1392 void eraseFromParent();
1397 void clearOperands();
1403 MDNode *getOperand(
unsigned i)
const;
1404 unsigned getNumOperands()
const;
1406 void setOperand(
unsigned I,
MDNode *New);
1410 bool IsForDebug =
false)
const;
1439 #endif // LLVM_IR_METADATA_H Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface ...
void dropAllReferences()
Remove all uses and clear node vector.
static void deleteTemporary(MDNode *N)
Deallocate a node created by getTemporary.
Tracking metadata reference owned by Metadata.
ContextAndReplaceableUses(std::unique_ptr< ReplaceableMetadataImpl > ReplaceableUses)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool classof(const Metadata *MD)
unsigned getValueID() const
Return an ID for the concrete type of this object.
MDNode * Scope
The tag for alias scope specification (used with noalias).
const unsigned char * bytes_end() const
MDNode * getOperand(unsigned i) const
This class represents lattice values for constants.
MDNode * TBAA
The tag for type-based alias analysis.
const unsigned char * bytes_end() const
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
TypedMDOperandIterator operator++(int)
static std::enable_if< std::is_base_of< MDNode, T >::value, T * >::type replaceWithPermanent(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a permanent one.
A Module instance is used to store all the information related to an LLVM module. ...
iterator begin() const
Pointer to the first byte of the string.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
unsigned getLength() const
std::unique_ptr< ReplaceableMetadataImpl > takeReplaceableUses()
Drop RAUW support.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
Metadata * operator->() const
The two locations do not alias at all.
ContextAndReplaceableUses(LLVMContext &Context)
~ContextAndReplaceableUses()
LLVMContext & getContext() const
All values hold a context through their type.
MDTupleTypedArrayWrapper(const MDTuple *N)
const MDOperand & getOperand(unsigned I) const
LLVMContext & getContext() const
Manage lifetime of a slot tracker for printing IR.
Typed, array-like tuple of metadata.
void replaceUseWith(Metadata *MD)
Replace the use of this with MD.
T get() const
Returns the value of the specified pointer type.
op_iterator op_end() const
bool operator!=(const AAMDNodes &A) const
static std::enable_if< std::is_base_of< MDNode, T >::value, T * >::type replaceWithDistinct(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a distinct one.
Metadata & operator*() const
static AAMDNodes getEmptyKey()
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
struct LLVMOpaqueNamedMDNode * LLVMNamedMDNodeRef
Represents an LLVM Named Metadata Node.
Attribute unwrap(LLVMAttributeRef Attr)
void makeReplaceable(std::unique_ptr< ReplaceableMetadataImpl > ReplaceableUses)
Assign RAUW support to this.
bool isResolved() const
Check if node is fully resolved.
A Use represents the edge between a Value definition and its users.
The access may reference the value stored in memory.
unsigned getHash() const
Get the hash, if any.
Typed iterator through MDNode operands.
static StringRef getName(Value *V)
static MDTuple * getIfExists(LLVMContext &Context, ArrayRef< Metadata *> MDs)
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Placeholder metadata for operands of distinct MDNodes.
TypedMDOperandIterator & operator++()
mir Rename Register Operands
op_iterator_impl< const MDNode *, MDNode > const_op_iterator
#define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)
APInt operator*(APInt a, uint64_t RHS)
op_iterator op_begin() const
static bool classof(const Metadata *MD)
Methods for support type inquiry through isa, cast, and dyn_cast:
Type * getType() const
All values are typed, get the type of this value.
op_range operands() const
MDTuple * operator->() const
LLVMContext & getContext() const
const_op_iterator op_end() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
AAMDNodes(MDNode *T, MDNode *TS, MDNode *S, MDNode *N)
LLVM_NODISCARD size_t size() const
size - Get the string size.
const Module * getParent() const
void replaceAllUsesWith(Metadata *MD)
RAUW a temporary.
static MDTuple * getIfExists(LLVMContext &Context, ArrayRef< Metadata *> MDs)
iterator_range< op_iterator > operands()
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Return a temporary node.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
static std::enable_if< std::is_base_of< MDNode, T >::value, T * >::type replaceWithUniqued(std::unique_ptr< T, TempMDNodeDeleter > N)
Replace a temporary node with a uniqued one.
MDOperand * mutable_end()
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
iterator end() const
Pointer to one byte past the end of the string.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
This is an important base class in LLVM.
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata *> MDs)
MDTupleTypedArrayWrapper(const MDTupleTypedArrayWrapper< U > &Other, typename std::enable_if<!std::is_convertible< U *, T *>::value >::type *=nullptr)
TempMDTuple clone() const
Return a (temporary) clone of this.
const_op_iterator op_begin() const
const unsigned char * bytes_begin() const
op_iterator_impl< MDNode *, MDNode > op_iterator
static SimpleType getSimplifiedValue(MDOperand &MD)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
mutable_op_range mutable_operands()
static bool classof(const Metadata *MD)
Methods for support type inquiry through isa, cast, and dyn_cast.
static bool isEqual(const AAMDNodes &LHS, const AAMDNodes &RHS)
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Return a distinct node.
bool hasReplaceableUses() const
Whether this contains RAUW support.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
BlockVerifier::State From
iterator_range< const_op_iterator > operands() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
MDNode * NoAlias
The tag specifying the noalias scope.
A range adaptor for a pair of iterators.
std::enable_if< detail::IsValidPointer< X, Y >::value, X * >::type extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
T * operator[](unsigned I) const
std::enable_if< detail::IsValidReference< X, Y & >::value, bool >::type hasa(Y &MD)
bool operator==(const AAMDNodes &A) const
Pointer to the context, with optional RAUW support.
MDOperand * mutable_begin()
std::enable_if< detail::IsValidPointer< X, Y >::value, X * >::type dyn_extract_or_null(Y &&MD)
Extract a Value from Metadata, if any, allowing null.
bool operator!=(uint64_t V1, const APInt &V2)
const unsigned char * bytes_begin() const
DistinctMDOperandPlaceholder(unsigned ID)
static ValueLatticeElement intersect(const ValueLatticeElement &A, const ValueLatticeElement &B)
Combine two sets of facts about the same value into a single set of facts.
static AAMDNodes getTombstoneKey()
static SimpleType getSimplifiedValue(const MDOperand &MD)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
MDTupleTypedArrayWrapper(const MDTupleTypedArrayWrapper< U > &Other, typename std::enable_if< std::is_convertible< U *, T *>::value >::type *=nullptr)
int is() const
Test if the Union currently holds the type matching T.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
LLVM_NODISCARD bool empty() const
struct LLVMOpaqueMetadata * LLVMMetadataRef
Represents an LLVM Metadata.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ReplaceableMetadataImpl * getOrCreateReplaceableUses()
Ensure that this has RAUW support, and then return it.
LLVM Value Representation.
void reset(Metadata *MD, Metadata *Owner)
static unsigned getHashValue(const AAMDNodes &Val)
AAMDNodes intersect(const AAMDNodes &Other)
Given two sets of AAMDNodes that apply to the same pointer, give the best AAMDNodes that are compatib...
This class implements an extremely fast bulk output stream that can only output to a stream...
bool operator==(const TypedMDOperandIterator &X) const
StringRef - Represent a constant reference to a string, i.e.
std::enable_if< detail::IsValidPointer< X, Y >::value, X * >::type dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
bool operator==(uint64_t V1, const APInt &V2)
MDTuple & operator*() const
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const DataLayout *DL, DominatorTree *DT=nullptr)
This lazily constructs the LazyValueInfoImpl.
unsigned getNumOperands() const
Return number of MDNode operands.
MDNode * TBAAStruct
The tag for type-based alias analysis (tbaa struct).
TypedMDOperandIterator(MDNode::op_iterator I)
ReplaceableMetadataImpl * getReplaceableUses() const
void operator()(MDNode *Node) const
Module * getParent()
Get the module that holds this named metadata collection.
bool operator!=(const TypedMDOperandIterator &X) const
~DistinctMDOperandPlaceholder()
StringMapEntryStorage - Holds the value in a StringMapEntry.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...