LLVM  8.0.1
MDBuilder.h
Go to the documentation of this file.
1 //===---- llvm/MDBuilder.h - Builder for LLVM metadata ----------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_IR_MDBUILDER_H
16 #define LLVM_IR_MDBUILDER_H
17 
18 #include "llvm/ADT/DenseSet.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/IR/GlobalValue.h"
21 #include "llvm/Support/DataTypes.h"
22 #include <utility>
23 
24 namespace llvm {
25 
26 class APInt;
27 template <typename T> class ArrayRef;
28 class LLVMContext;
29 class Constant;
30 class ConstantAsMetadata;
31 class MDNode;
32 class MDString;
33 class Metadata;
34 
35 class MDBuilder {
36  LLVMContext &Context;
37 
38 public:
39  MDBuilder(LLVMContext &context) : Context(context) {}
40 
41  /// Return the given string as metadata.
43 
44  /// Return the given constant as metadata.
46 
47  //===------------------------------------------------------------------===//
48  // FPMath metadata.
49  //===------------------------------------------------------------------===//
50 
51  /// Return metadata with the given settings. The special value 0.0
52  /// for the Accuracy parameter indicates the default (maximal precision)
53  /// setting.
54  MDNode *createFPMath(float Accuracy);
55 
56  //===------------------------------------------------------------------===//
57  // Prof metadata.
58  //===------------------------------------------------------------------===//
59 
60  /// Return metadata containing two branch weights.
61  MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight);
62 
63  /// Return metadata containing a number of branch weights.
65 
66  /// Return metadata specifying that a branch or switch is unpredictable.
68 
69  /// Return metadata containing the entry \p Count for a function, a boolean
70  /// \Synthetic indicating whether the counts were synthetized, and the
71  /// GUIDs stored in \p Imports that need to be imported for sample PGO, to
72  /// enable the same inlines as the profiled optimized binary
73  MDNode *createFunctionEntryCount(uint64_t Count, bool Synthetic,
74  const DenseSet<GlobalValue::GUID> *Imports);
75 
76  /// Return metadata containing the section prefix for a function.
78 
79  //===------------------------------------------------------------------===//
80  // Range metadata.
81  //===------------------------------------------------------------------===//
82 
83  /// Return metadata describing the range [Lo, Hi).
84  MDNode *createRange(const APInt &Lo, const APInt &Hi);
85 
86  /// Return metadata describing the range [Lo, Hi).
88 
89  //===------------------------------------------------------------------===//
90  // Callees metadata.
91  //===------------------------------------------------------------------===//
92 
93  /// Return metadata indicating the possible callees of indirect
94  /// calls.
96 
97  //===------------------------------------------------------------------===//
98  // AA metadata.
99  //===------------------------------------------------------------------===//
100 
101 protected:
102  /// Return metadata appropriate for a AA root node (scope or TBAA).
103  /// Each returned node is distinct from all other metadata and will never
104  /// be identified (uniqued) with anything else.
106  MDNode *Extra = nullptr);
107 
108 public:
109  /// Return metadata appropriate for a TBAA root node. Each returned
110  /// node is distinct from all other metadata and will never be identified
111  /// (uniqued) with anything else.
113  return createAnonymousAARoot();
114  }
115 
116  /// Return metadata appropriate for an alias scope domain node.
117  /// Each returned node is distinct from all other metadata and will never
118  /// be identified (uniqued) with anything else.
120  return createAnonymousAARoot(Name);
121  }
122 
123  /// Return metadata appropriate for an alias scope root node.
124  /// Each returned node is distinct from all other metadata and will never
125  /// be identified (uniqued) with anything else.
127  StringRef Name = StringRef()) {
128  return createAnonymousAARoot(Name, Domain);
129  }
130 
131  /// Return metadata appropriate for a TBAA root node with the given
132  /// name. This may be identified (uniqued) with other roots with the same
133  /// name.
135 
136  /// Return metadata appropriate for an alias scope domain node with
137  /// the given name. This may be identified (uniqued) with other roots with
138  /// the same name.
140 
141  /// Return metadata appropriate for an alias scope node with
142  /// the given name. This may be identified (uniqued) with other scopes with
143  /// the same name and domain.
144  MDNode *createAliasScope(StringRef Name, MDNode *Domain);
145 
146  /// Return metadata for a non-root TBAA node with the given name,
147  /// parent in the TBAA tree, and value for 'pointsToConstantMemory'.
148  MDNode *createTBAANode(StringRef Name, MDNode *Parent,
149  bool isConstant = false);
150 
152  uint64_t Offset;
153  uint64_t Size;
155  TBAAStructField(uint64_t Offset, uint64_t Size, MDNode *Type) :
156  Offset(Offset), Size(Size), Type(Type) {}
157  };
158 
159  /// Return metadata for a tbaa.struct node with the given
160  /// struct field descriptions.
162 
163  /// Return metadata for a TBAA struct node in the type DAG
164  /// with the given name, a list of pairs (offset, field type in the type DAG).
165  MDNode *
167  ArrayRef<std::pair<MDNode *, uint64_t>> Fields);
168 
169  /// Return metadata for a TBAA scalar type node with the
170  /// given name, an offset and a parent in the TBAA type DAG.
172  uint64_t Offset = 0);
173 
174  /// Return metadata for a TBAA tag node with the given
175  /// base type, access type and offset relative to the base type.
177  uint64_t Offset, bool IsConstant = false);
178 
179  /// Return metadata for a TBAA type node in the TBAA type DAG with the
180  /// given parent type, size in bytes, type identifier and a list of fields.
181  MDNode *createTBAATypeNode(MDNode *Parent, uint64_t Size, Metadata *Id,
184 
185  /// Return metadata for a TBAA access tag with the given base type,
186  /// final access type, offset of the access relative to the base type, size of
187  /// the access and flag indicating whether the accessed object can be
188  /// considered immutable for the purposes of the TBAA analysis.
189  MDNode *createTBAAAccessTag(MDNode *BaseType, MDNode *AccessType,
190  uint64_t Offset, uint64_t Size,
191  bool IsImmutable = false);
192 
193  /// Return mutable version of the given mutable or immutable TBAA
194  /// access tag.
196 
197  /// Return metadata containing an irreducible loop header weight.
198  MDNode *createIrrLoopHeaderWeight(uint64_t Weight);
199 };
200 
201 } // end namespace llvm
202 
203 #endif
uint64_t CallInst * C
MDNode * createRange(const APInt &Lo, const APInt &Hi)
Return metadata describing the range [Lo, Hi).
Definition: MDBuilder.cpp:87
static bool isConstant(const MachineInstr &MI)
MDNode * createAnonymousAARoot(StringRef Name=StringRef(), MDNode *Extra=nullptr)
Return metadata appropriate for a AA root node (scope or TBAA).
Definition: MDBuilder.cpp:110
MDNode * createUnpredictable()
Return metadata specifying that a branch or switch is unpredictable.
Definition: MDBuilder.cpp:56
This class represents lattice values for constants.
Definition: AllocatorList.h:24
ConstantAsMetadata * createConstant(Constant *C)
Return the given constant as metadata.
Definition: MDBuilder.cpp:25
MDNode * createAnonymousTBAARoot()
Return metadata appropriate for a TBAA root node.
Definition: MDBuilder.h:112
Implements a dense probed hash-table based set.
Definition: DenseSet.h:250
MDNode * createAnonymousAliasScope(MDNode *Domain, StringRef Name=StringRef())
Return metadata appropriate for an alias scope root node.
Definition: MDBuilder.h:126
MDBuilder(LLVMContext &context)
Definition: MDBuilder.h:39
Metadata node.
Definition: Metadata.h:864
MDNode * createFPMath(float Accuracy)
Return metadata with the given settings.
Definition: MDBuilder.cpp:29
MDNode * createIrrLoopHeaderWeight(uint64_t Weight)
Return metadata containing an irreducible loop header weight.
Definition: MDBuilder.cpp:262
MDNode * createFunctionEntryCount(uint64_t Count, bool Synthetic, const DenseSet< GlobalValue::GUID > *Imports)
Return metadata containing the entry Count for a function, a boolean indicating whether the counts w...
Definition: MDBuilder.cpp:60
amdgpu Simplify well known AMD library false Value Value const Twine & Name
MDNode * createTBAAAccessTag(MDNode *BaseType, MDNode *AccessType, uint64_t Offset, uint64_t Size, bool IsImmutable=false)
Return metadata for a TBAA access tag with the given base type, final access type, offset of the access relative to the base type, size of the access and flag indicating whether the accessed object can be considered immutable for the purposes of the TBAA analysis.
Definition: MDBuilder.cpp:221
MDNode * createTBAATypeNode(MDNode *Parent, uint64_t Size, Metadata *Id, ArrayRef< TBAAStructField > Fields=ArrayRef< TBAAStructField >())
Return metadata for a TBAA type node in the TBAA type DAG with the given parent type, size in bytes, type identifier and a list of fields.
Definition: MDBuilder.cpp:205
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
This is an important base class in LLVM.
Definition: Constant.h:42
MDNode * createAliasScopeDomain(StringRef Name)
Return metadata appropriate for an alias scope domain node with the given name.
Definition: MDBuilder.cpp:148
MDNode * createTBAAStructNode(ArrayRef< TBAAStructField > Fields)
Return metadata for a tbaa.struct node with the given struct field descriptions.
Definition: MDBuilder.cpp:158
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight)
Return metadata containing two branch weights.
Definition: MDBuilder.cpp:38
MDNode * createAnonymousAliasScopeDomain(StringRef Name=StringRef())
Return metadata appropriate for an alias scope domain node.
Definition: MDBuilder.h:119
MDNode * createTBAAScalarTypeNode(StringRef Name, MDNode *Parent, uint64_t Offset=0)
Return metadata for a TBAA scalar type node with the given name, an offset and a parent in the TBAA t...
Definition: MDBuilder.cpp:185
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
Class for arbitrary precision integers.
Definition: APInt.h:70
TBAAStructField(uint64_t Offset, uint64_t Size, MDNode *Type)
Definition: MDBuilder.h:155
MDNode * createCallees(ArrayRef< Function *> Callees)
Return metadata indicating the possible callees of indirect calls.
Definition: MDBuilder.cpp:103
MDNode * createTBAAStructTypeNode(StringRef Name, ArrayRef< std::pair< MDNode *, uint64_t >> Fields)
Return metadata for a TBAA struct node in the type DAG with the given name, a list of pairs (offset...
Definition: MDBuilder.cpp:171
MDString * createString(StringRef Str)
Return the given string as metadata.
Definition: MDBuilder.cpp:21
MDNode * createAliasScope(StringRef Name, MDNode *Domain)
Return metadata appropriate for an alias scope node with the given name.
Definition: MDBuilder.cpp:152
MDNode * createTBAAStructTagNode(MDNode *BaseType, MDNode *AccessType, uint64_t Offset, bool IsConstant=false)
Return metadata for a TBAA tag node with the given base type, access type and offset relative to the ...
Definition: MDBuilder.cpp:194
MDNode * createTBAANode(StringRef Name, MDNode *Parent, bool isConstant=false)
Return metadata for a non-root TBAA node with the given name, parent in the TBAA tree, and value for &#39;pointsToConstantMemory&#39;.
Definition: MDBuilder.cpp:138
MDNode * createFunctionSectionPrefix(StringRef Prefix)
Return metadata containing the section prefix for a function.
Definition: MDBuilder.cpp:81
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
MDNode * createTBAARoot(StringRef Name)
Return metadata appropriate for a TBAA root node with the given name.
Definition: MDBuilder.cpp:132
A single uniqued string.
Definition: Metadata.h:604
Root of the metadata hierarchy.
Definition: Metadata.h:58
MDNode * createMutableTBAAAccessTag(MDNode *Tag)
Return mutable version of the given mutable or immutable TBAA access tag.
Definition: MDBuilder.cpp:235
std::vector< uint32_t > Metadata
PAL metadata represented as a vector.