16 #ifndef LLVM_IR_METADATA_H 17 #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))
655 explicit operator bool()
const {
return TBAA || Scope ||
NoAlias; }
673 Result.
TBAA = Other.
TBAA == TBAA ? TBAA :
nullptr;
674 Result.
Scope = Other.
Scope == Scope ? Scope :
nullptr;
748 assert(static_cast<void *>(
this) == &MD &&
"Expected same address");
776 std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses)
777 : Ptr(ReplaceableUses.
release()) {
778 assert(getReplaceableUses() &&
"Expected non-null replaceable uses");
796 if (hasReplaceableUses())
797 return getReplaceableUses()->getContext();
802 if (hasReplaceableUses())
809 if (!hasReplaceableUses())
810 makeReplaceable(llvm::make_unique<ReplaceableMetadataImpl>(getContext()));
811 return getReplaceableUses();
820 assert(ReplaceableUses &&
"Expected non-null replaceable uses");
821 assert(&ReplaceableUses->getContext() == &getContext() &&
822 "Expected same context");
823 delete getReplaceableUses();
824 Ptr = ReplaceableUses.release();
831 assert(hasReplaceableUses() &&
"Expected to own replaceable uses");
832 std::unique_ptr<ReplaceableMetadataImpl> ReplaceableUses(
833 getReplaceableUses());
834 Ptr = &ReplaceableUses->getContext();
835 return ReplaceableUses;
840 inline void operator()(
MDNode *Node)
const;
843 #define HANDLE_MDNODE_LEAF(CLASS) \ 844 using Temp##CLASS = std::unique_ptr<CLASS, TempMDNodeDeleter>; 845 #define HANDLE_MDNODE_BRANCH(CLASS) HANDLE_MDNODE_LEAF(CLASS) 846 #include "llvm/IR/Metadata.def" 868 unsigned NumOperands;
869 unsigned NumUnresolved;
878 void *
operator new(
size_t Size,
unsigned NumOps);
879 void operator delete(
void *Mem);
891 void dropAllReferences();
904 void operator=(
const MDNode &) =
delete;
905 void *
operator new(
size_t) =
delete;
912 static inline TempMDTuple getTemporary(
LLVMContext &Context,
916 TempMDNode clone()
const;
922 static void deleteTemporary(
MDNode *
N);
927 void replaceOperandWith(
unsigned I,
Metadata *New);
940 bool isResolved()
const {
return !isTemporary() && !NumUnresolved; }
950 assert(isTemporary() &&
"Expected temporary node");
951 if (Context.hasReplaceableUses())
952 Context.getReplaceableUses()->replaceAllUsesWith(MD);
961 void resolveCycles();
971 static typename std::enable_if<std::is_base_of<MDNode, T>::value,
T *>
::type 973 return cast<T>(N.release()->replaceWithPermanentImpl());
983 static typename std::enable_if<std::is_base_of<MDNode, T>::value,
T *>
::type 985 return cast<T>(N.release()->replaceWithUniquedImpl());
993 static typename std::enable_if<std::is_base_of<MDNode, T>::value,
T *>
::type 995 return cast<T>(N.release()->replaceWithDistinctImpl());
999 MDNode *replaceWithPermanentImpl();
1000 MDNode *replaceWithUniquedImpl();
1001 MDNode *replaceWithDistinctImpl();
1007 void setOperand(
unsigned I,
Metadata *New);
1009 void storeDistinctInContext();
1010 template <
class T,
class StoreT>
1012 template <
class T>
static T *storeImpl(
T *N,
StorageType Storage);
1018 void dropReplaceableUses();
1021 void decrementUnresolvedOperandCount();
1022 void countUnresolvedOperands();
1035 void makeDistinct();
1037 void deleteAsSubclass();
1039 void eraseFromStore();
1041 template <
class NodeTy>
struct HasCachedHash;
1042 template <
class NodeTy>
1043 static void dispatchRecalculateHash(NodeTy *N, std::true_type) {
1044 N->recalculateHash();
1046 template <
class NodeTy>
1047 static void dispatchRecalculateHash(NodeTy *, std::false_type) {}
1048 template <
class NodeTy>
1049 static void dispatchResetHash(NodeTy *N, std::true_type) {
1052 template <
class NodeTy>
1053 static void dispatchResetHash(NodeTy *, std::false_type) {}
1060 return const_cast<MDNode *
>(
this)->mutable_begin();
1064 return const_cast<MDNode *
>(
this)->mutable_end();
1070 assert(I < NumOperands &&
"Out of range");
1071 return op_begin()[
I];
1082 #define HANDLE_MDNODE_LEAF(CLASS) \ 1085 #include "llvm/IR/Metadata.def" 1090 bool isTBAAVtableAccess()
const;
1112 :
MDNode(C, MDTupleKind, Storage, Vals) {
1116 ~
MDTuple() { dropAllReferences(); }
1119 void recalculateHash();
1124 TempMDTuple cloneImpl()
const {
1125 return getTemporary(getContext(),
1159 TempMDTuple
clone()
const {
return cloneImpl(); }
1193 :
public std::iterator<std::input_iterator_tag, T *, std::ptrdiff_t, void,
1232 typename std::enable_if<std::is_convertible<U *, T *>::value>::
type * =
1239 typename std::enable_if<!std::is_convertible<U *, T *>::value>::
type * =
1243 explicit operator bool()
const {
return get(); }
1244 explicit operator MDTuple *()
const {
return get(); }
1262 #define HANDLE_METADATA(CLASS) \ 1263 using CLASS##Array = MDTupleTypedArrayWrapper<CLASS>; 1264 #include "llvm/IR/Metadata.def" 1314 assert(!Use &&
"Use is still being tracked despite being untracked!");
1331 Module *Parent =
nullptr;
1334 void setParent(
Module *M) { Parent = M; }
1338 template<
class T1,
class T2>
1339 class op_iterator_impl :
1340 public std::iterator<std::bidirectional_iterator_tag, T2> {
1346 op_iterator_impl(
const NamedMDNode *
N,
unsigned i) : Node(N), Idx(i) {}
1349 op_iterator_impl() =
default;
1351 bool operator==(
const op_iterator_impl &o)
const {
return Idx == o.Idx; }
1352 bool operator!=(
const op_iterator_impl &o)
const {
return Idx != o.Idx; }
1354 op_iterator_impl &operator++() {
1359 op_iterator_impl operator++(
int) {
1360 op_iterator_impl tmp(*
this);
1365 op_iterator_impl &operator--() {
1370 op_iterator_impl operator--(
int) {
1371 op_iterator_impl tmp(*
this);
1384 void eraseFromParent();
1389 void clearOperands();
1395 MDNode *getOperand(
unsigned i)
const;
1396 unsigned getNumOperands()
const;
1398 void setOperand(
unsigned I,
MDNode *New);
1402 bool IsForDebug =
false)
const;
1431 #endif // LLVM_IR_METADATA_H 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.
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
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.
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...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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.
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")
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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++()
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)...
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)
AAMDNodes(MDNode *T=nullptr, MDNode *S=nullptr, MDNode *N=nullptr)
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)
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
T get() const
Returns the value of the specified pointer type.
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.
int is() const
Test if the Union currently holds the type matching T.
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.
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()
A discriminated union of two pointer types, with the discriminator in the low bit of the pointer...