1 //===---- llvm/MDBuilder.h - Builder for LLVM metadata ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the MDBuilder class, which is used as a convenient way to
11 // create LLVM metadata with a consistent and simplified interface.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_IR_MDBUILDER_H
16 #define LLVM_IR_MDBUILDER_H
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Support/DataTypes.h"
25 template <typename T> class ArrayRef;
34 MDBuilder(LLVMContext &context) : Context(context) {}
36 /// \brief Return the given string as metadata.
37 MDString *createString(StringRef Str);
39 //===------------------------------------------------------------------===//
41 //===------------------------------------------------------------------===//
43 /// \brief Return metadata with the given settings. The special value 0.0
44 /// for the Accuracy parameter indicates the default (maximal precision)
46 MDNode *createFPMath(float Accuracy);
48 //===------------------------------------------------------------------===//
50 //===------------------------------------------------------------------===//
52 /// \brief Return metadata containing two branch weights.
53 MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight);
55 /// \brief Return metadata containing a number of branch weights.
56 MDNode *createBranchWeights(ArrayRef<uint32_t> Weights);
58 //===------------------------------------------------------------------===//
60 //===------------------------------------------------------------------===//
62 /// \brief Return metadata describing the range [Lo, Hi).
63 MDNode *createRange(const APInt &Lo, const APInt &Hi);
65 //===------------------------------------------------------------------===//
67 //===------------------------------------------------------------------===//
70 /// \brief Return metadata appropriate for a AA root node (scope or TBAA).
71 /// Each returned node is distinct from all other metadata and will never
72 /// be identified (uniqued) with anything else.
73 MDNode *createAnonymousAARoot(StringRef Name = StringRef(),
74 MDNode *Extra = nullptr);
77 /// \brief Return metadata appropriate for a TBAA root node. Each returned
78 /// node is distinct from all other metadata and will never be identified
79 /// (uniqued) with anything else.
80 MDNode *createAnonymousTBAARoot() {
81 return createAnonymousAARoot();
84 /// \brief Return metadata appropriate for an alias scope domain node.
85 /// Each returned node is distinct from all other metadata and will never
86 /// be identified (uniqued) with anything else.
87 MDNode *createAnonymousAliasScopeDomain(StringRef Name = StringRef()) {
88 return createAnonymousAARoot(Name);
91 /// \brief Return metadata appropriate for an alias scope root node.
92 /// Each returned node is distinct from all other metadata and will never
93 /// be identified (uniqued) with anything else.
94 MDNode *createAnonymousAliasScope(MDNode *Domain,
95 StringRef Name = StringRef()) {
96 return createAnonymousAARoot(Name, Domain);
99 /// \brief Return metadata appropriate for a TBAA root node with the given
100 /// name. This may be identified (uniqued) with other roots with the same
102 MDNode *createTBAARoot(StringRef Name);
104 /// \brief Return metadata appropriate for an alias scope domain node with
105 /// the given name. This may be identified (uniqued) with other roots with
107 MDNode *createAliasScopeDomain(StringRef Name);
109 /// \brief Return metadata appropriate for an alias scope node with
110 /// the given name. This may be identified (uniqued) with other scopes with
111 /// the same name and domain.
112 MDNode *createAliasScope(StringRef Name, MDNode *Domain);
114 /// \brief Return metadata for a non-root TBAA node with the given name,
115 /// parent in the TBAA tree, and value for 'pointsToConstantMemory'.
116 MDNode *createTBAANode(StringRef Name, MDNode *Parent,
117 bool isConstant = false);
119 struct TBAAStructField {
123 TBAAStructField(uint64_t Offset, uint64_t Size, MDNode *TBAA) :
124 Offset(Offset), Size(Size), TBAA(TBAA) {}
127 /// \brief Return metadata for a tbaa.struct node with the given
128 /// struct field descriptions.
129 MDNode *createTBAAStructNode(ArrayRef<TBAAStructField> Fields);
131 /// \brief Return metadata for a TBAA struct node in the type DAG
132 /// with the given name, a list of pairs (offset, field type in the type DAG).
134 createTBAAStructTypeNode(StringRef Name,
135 ArrayRef<std::pair<MDNode *, uint64_t>> Fields);
137 /// \brief Return metadata for a TBAA scalar type node with the
138 /// given name, an offset and a parent in the TBAA type DAG.
139 MDNode *createTBAAScalarTypeNode(StringRef Name, MDNode *Parent,
140 uint64_t Offset = 0);
142 /// \brief Return metadata for a TBAA tag node with the given
143 /// base type, access type and offset relative to the base type.
144 MDNode *createTBAAStructTagNode(MDNode *BaseType, MDNode *AccessType,
148 } // end namespace llvm