Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
MDBuilder.h
Go to the documentation of this file.
1//===---- llvm/MDBuilder.h - Builder for LLVM metadata ----------*- 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// This file defines the MDBuilder class, which is used as a convenient way to
10// create LLVM metadata with a consistent and simplified interface.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_MDBUILDER_H
15#define LLVM_IR_MDBUILDER_H
16
17#include "llvm/ADT/DenseSet.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/IR/GlobalValue.h"
21#include "llvm/Support/DataTypes.h"
22#include <utility>
23
24namespacellvm {
25
26classAPInt;
27template <typename T>classArrayRef;
28classLLVMContext;
29classConstant;
30classConstantAsMetadata;
31classFunction;
32classMDNode;
33classMDString;
34classMetadata;
35
36classMDBuilder {
37LLVMContext &Context;
38
39public:
40MDBuilder(LLVMContext &context) : Context(context) {}
41
42 /// Return the given string as metadata.
43MDString *createString(StringRef Str);
44
45 /// Return the given constant as metadata.
46ConstantAsMetadata *createConstant(Constant *C);
47
48//===------------------------------------------------------------------===//
49// FPMath metadata.
50//===------------------------------------------------------------------===//
51
52 /// Return metadata with the given settings. The special value 0.0
53 /// for the Accuracy parameter indicates the default (maximal precision)
54 /// setting.
55MDNode *createFPMath(float Accuracy);
56
57//===------------------------------------------------------------------===//
58// Prof metadata.
59//===------------------------------------------------------------------===//
60
61 /// Return metadata containing two branch weights.
62 /// @param TrueWeight the weight of the true branch
63 /// @param FalseWeight the weight of the false branch
64 /// @param Do these weights come from __builtin_expect*
65MDNode *createBranchWeights(uint32_t TrueWeight,uint32_t FalseWeight,
66bool IsExpected =false);
67
68 /// Return metadata containing two branch weights, with significant bias
69 /// towards `true` destination.
70MDNode *createLikelyBranchWeights();
71
72 /// Return metadata containing two branch weights, with significant bias
73 /// towards `false` destination.
74MDNode *createUnlikelyBranchWeights();
75
76 /// Return metadata containing a number of branch weights.
77 /// @param Weights the weights of all the branches
78 /// @param Do these weights come from __builtin_expect*
79MDNode *createBranchWeights(ArrayRef<uint32_t> Weights,
80bool IsExpected =false);
81
82 /// Return metadata specifying that a branch or switch is unpredictable.
83MDNode *createUnpredictable();
84
85 /// Return metadata containing the entry \p Count for a function, a boolean
86 /// \Synthetic indicating whether the counts were synthetized, and the
87 /// GUIDs stored in \p Imports that need to be imported for sample PGO, to
88 /// enable the same inlines as the profiled optimized binary
89MDNode *createFunctionEntryCount(uint64_t Count,bool Synthetic,
90constDenseSet<GlobalValue::GUID> *Imports);
91
92 /// Return metadata containing the section prefix for a function.
93MDNode *createFunctionSectionPrefix(StringRef Prefix);
94
95 /// Return metadata containing the pseudo probe descriptor for a function.
96MDNode *createPseudoProbeDesc(uint64_t GUID,uint64_t Hash,StringRef FName);
97
98 /// Return metadata containing llvm statistics.
99MDNode *
100createLLVMStats(ArrayRef<std::pair<StringRef, uint64_t>> LLVMStatsVec);
101
102//===------------------------------------------------------------------===//
103// Range metadata.
104//===------------------------------------------------------------------===//
105
106 /// Return metadata describing the range [Lo, Hi).
107MDNode *createRange(constAPInt &Lo,constAPInt &Hi);
108
109 /// Return metadata describing the range [Lo, Hi).
110MDNode *createRange(Constant *Lo,Constant *Hi);
111
112//===------------------------------------------------------------------===//
113// Callees metadata.
114//===------------------------------------------------------------------===//
115
116 /// Return metadata indicating the possible callees of indirect
117 /// calls.
118MDNode *createCallees(ArrayRef<Function *> Callees);
119
120//===------------------------------------------------------------------===//
121// Callback metadata.
122//===------------------------------------------------------------------===//
123
124 /// Return metadata describing a callback (see llvm::AbstractCallSite).
125MDNode *createCallbackEncoding(unsigned CalleeArgNo,ArrayRef<int>Arguments,
126bool VarArgsArePassed);
127
128 /// Merge the new callback encoding \p NewCB into \p ExistingCallbacks.
129MDNode *mergeCallbackEncodings(MDNode *ExistingCallbacks,MDNode *NewCB);
130
131 /// Return metadata feeding to the CodeGen about how to generate a function
132 /// prologue for the "function" santizier.
133MDNode *createRTTIPointerPrologue(Constant *PrologueSig,Constant *RTTI);
134
135//===------------------------------------------------------------------===//
136// PC sections metadata.
137//===------------------------------------------------------------------===//
138
139 /// A pair of PC section name with auxilliary constant data.
140usingPCSection = std::pair<StringRef, SmallVector<Constant *>>;
141
142 /// Return metadata for PC sections.
143MDNode *createPCSections(ArrayRef<PCSection> Sections);
144
145//===------------------------------------------------------------------===//
146// AA metadata.
147//===------------------------------------------------------------------===//
148
149protected:
150 /// Return metadata appropriate for a AA root node (scope or TBAA).
151 /// Each returned node is distinct from all other metadata and will never
152 /// be identified (uniqued) with anything else.
153MDNode *createAnonymousAARoot(StringRefName =StringRef(),
154MDNode *Extra =nullptr);
155
156public:
157 /// Return metadata appropriate for a TBAA root node. Each returned
158 /// node is distinct from all other metadata and will never be identified
159 /// (uniqued) with anything else.
160MDNode *createAnonymousTBAARoot() {
161returncreateAnonymousAARoot();
162 }
163
164 /// Return metadata appropriate for an alias scope domain node.
165 /// Each returned node is distinct from all other metadata and will never
166 /// be identified (uniqued) with anything else.
167MDNode *createAnonymousAliasScopeDomain(StringRefName =StringRef()) {
168returncreateAnonymousAARoot(Name);
169 }
170
171 /// Return metadata appropriate for an alias scope root node.
172 /// Each returned node is distinct from all other metadata and will never
173 /// be identified (uniqued) with anything else.
174MDNode *createAnonymousAliasScope(MDNode *Domain,
175StringRefName =StringRef()) {
176returncreateAnonymousAARoot(Name,Domain);
177 }
178
179 /// Return metadata appropriate for a TBAA root node with the given
180 /// name. This may be identified (uniqued) with other roots with the same
181 /// name.
182MDNode *createTBAARoot(StringRefName);
183
184 /// Return metadata appropriate for an alias scope domain node with
185 /// the given name. This may be identified (uniqued) with other roots with
186 /// the same name.
187MDNode *createAliasScopeDomain(StringRefName);
188
189 /// Return metadata appropriate for an alias scope node with
190 /// the given name. This may be identified (uniqued) with other scopes with
191 /// the same name and domain.
192MDNode *createAliasScope(StringRefName,MDNode *Domain);
193
194 /// Return metadata for a non-root TBAA node with the given name,
195 /// parent in the TBAA tree, and value for 'pointsToConstantMemory'.
196MDNode *createTBAANode(StringRefName,MDNode *Parent,
197boolisConstant =false);
198
199structTBAAStructField {
200uint64_tOffset;
201uint64_tSize;
202MDNode *Type;
203TBAAStructField(uint64_tOffset,uint64_tSize,MDNode *Type) :
204Offset(Offset),Size(Size),Type(Type) {}
205 };
206
207 /// Return metadata for a tbaa.struct node with the given
208 /// struct field descriptions.
209MDNode *createTBAAStructNode(ArrayRef<TBAAStructField> Fields);
210
211 /// Return metadata for a TBAA struct node in the type DAG
212 /// with the given name, a list of pairs (offset, field type in the type DAG).
213MDNode *
214createTBAAStructTypeNode(StringRefName,
215ArrayRef<std::pair<MDNode *, uint64_t>> Fields);
216
217 /// Return metadata for a TBAA scalar type node with the
218 /// given name, an offset and a parent in the TBAA type DAG.
219MDNode *createTBAAScalarTypeNode(StringRefName,MDNode *Parent,
220uint64_tOffset = 0);
221
222 /// Return metadata for a TBAA tag node with the given
223 /// base type, access type and offset relative to the base type.
224MDNode *createTBAAStructTagNode(MDNode *BaseType,MDNode *AccessType,
225uint64_tOffset,bool IsConstant =false);
226
227 /// Return metadata for a TBAA type node in the TBAA type DAG with the
228 /// given parent type, size in bytes, type identifier and a list of fields.
229MDNode *createTBAATypeNode(MDNode *Parent,uint64_tSize,Metadata *Id,
230ArrayRef<TBAAStructField> Fields =
231ArrayRef<TBAAStructField>());
232
233 /// Return metadata for a TBAA access tag with the given base type,
234 /// final access type, offset of the access relative to the base type, size of
235 /// the access and flag indicating whether the accessed object can be
236 /// considered immutable for the purposes of the TBAA analysis.
237MDNode *createTBAAAccessTag(MDNode *BaseType,MDNode *AccessType,
238uint64_tOffset,uint64_tSize,
239bool IsImmutable =false);
240
241 /// Return mutable version of the given mutable or immutable TBAA
242 /// access tag.
243MDNode *createMutableTBAAAccessTag(MDNode *Tag);
244
245 /// Return metadata containing an irreducible loop header weight.
246MDNode *createIrrLoopHeaderWeight(uint64_t Weight);
247};
248
249}// end namespace llvm
250
251#endif
isConstant
static bool isConstant(const MachineInstr &MI)
Definition:AMDGPUInstructionSelector.cpp:2862
Arguments
AMDGPU Lower Kernel Arguments
Definition:AMDGPULowerKernelArguments.cpp:504
Domain
Domain
Definition:CorrelatedValuePropagation.cpp:744
Metadata
dxil translate DXIL Translate Metadata
Definition:DXILTranslateMetadata.cpp:467
DenseSet.h
This file defines the DenseSet and SmallDenseSet classes.
Name
std::string Name
Definition:ELFObjHandler.cpp:77
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
GlobalValue.h
SmallVector.h
This file defines the SmallVector class.
StringRef.h
BaseType
llvm::APInt
Class for arbitrary precision integers.
Definition:APInt.h:78
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::ConstantAsMetadata
Definition:Metadata.h:525
llvm::Constant
This is an important base class in LLVM.
Definition:Constant.h:42
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition:DenseSet.h:278
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition:LLVMContext.h:67
llvm::MDBuilder
Definition:MDBuilder.h:36
llvm::MDBuilder::createTBAAAccessTag
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,...
Definition:MDBuilder.cpp:301
llvm::MDBuilder::createCallbackEncoding
MDNode * createCallbackEncoding(unsigned CalleeArgNo, ArrayRef< int > Arguments, bool VarArgsArePassed)
Return metadata describing a callback (see llvm::AbstractCallSite).
Definition:MDBuilder.cpp:118
llvm::MDBuilder::createAnonymousAARoot
MDNode * createAnonymousAARoot(StringRef Name=StringRef(), MDNode *Extra=nullptr)
Return metadata appropriate for a AA root node (scope or TBAA).
Definition:MDBuilder.cpp:194
llvm::MDBuilder::createFunctionEntryCount
MDNode * createFunctionEntryCount(uint64_t Count, bool Synthetic, const DenseSet< GlobalValue::GUID > *Imports)
Return metadata containing the entry Count for a function, a boolean \Synthetic indicating whether th...
Definition:MDBuilder.cpp:71
llvm::MDBuilder::createAnonymousAliasScope
MDNode * createAnonymousAliasScope(MDNode *Domain, StringRef Name=StringRef())
Return metadata appropriate for an alias scope root node.
Definition:MDBuilder.h:174
llvm::MDBuilder::createPseudoProbeDesc
MDNode * createPseudoProbeDesc(uint64_t GUID, uint64_t Hash, StringRef FName)
Return metadata containing the pseudo probe descriptor for a function.
Definition:MDBuilder.cpp:350
llvm::MDBuilder::createConstant
ConstantAsMetadata * createConstant(Constant *C)
Return the given constant as metadata.
Definition:MDBuilder.cpp:24
llvm::MDBuilder::createFPMath
MDNode * createFPMath(float Accuracy)
Return metadata with the given settings.
Definition:MDBuilder.cpp:28
llvm::MDBuilder::createPCSections
MDNode * createPCSections(ArrayRef< PCSection > Sections)
Return metadata for PC sections.
Definition:MDBuilder.cpp:173
llvm::MDBuilder::createTBAANode
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,...
Definition:MDBuilder.cpp:218
llvm::MDBuilder::createTBAARoot
MDNode * createTBAARoot(StringRef Name)
Return metadata appropriate for a TBAA root node with the given name.
Definition:MDBuilder.cpp:212
llvm::MDBuilder::createBranchWeights
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight, bool IsExpected=false)
Return metadata containing two branch weights.
Definition:MDBuilder.cpp:37
llvm::MDBuilder::createString
MDString * createString(StringRef Str)
Return the given string as metadata.
Definition:MDBuilder.cpp:20
llvm::MDBuilder::createAnonymousTBAARoot
MDNode * createAnonymousTBAARoot()
Return metadata appropriate for a TBAA root node.
Definition:MDBuilder.h:160
llvm::MDBuilder::createTBAAScalarTypeNode
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:265
llvm::MDBuilder::createIrrLoopHeaderWeight
MDNode * createIrrLoopHeaderWeight(uint64_t Weight)
Return metadata containing an irreducible loop header weight.
Definition:MDBuilder.cpp:342
llvm::MDBuilder::createFunctionSectionPrefix
MDNode * createFunctionSectionPrefix(StringRef Prefix)
Return metadata containing the section prefix for a function.
Definition:MDBuilder.cpp:90
llvm::MDBuilder::createUnpredictable
MDNode * createUnpredictable()
Return metadata specifying that a branch or switch is unpredictable.
Definition:MDBuilder.cpp:69
llvm::MDBuilder::createTBAAStructTypeNode
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:251
llvm::MDBuilder::createCallees
MDNode * createCallees(ArrayRef< Function * > Callees)
Return metadata indicating the possible callees of indirect calls.
Definition:MDBuilder.cpp:111
llvm::MDBuilder::createAliasScopeDomain
MDNode * createAliasScopeDomain(StringRef Name)
Return metadata appropriate for an alias scope domain node with the given name.
Definition:MDBuilder.cpp:228
llvm::MDBuilder::PCSection
std::pair< StringRef, SmallVector< Constant * > > PCSection
A pair of PC section name with auxilliary constant data.
Definition:MDBuilder.h:140
llvm::MDBuilder::createRange
MDNode * createRange(const APInt &Lo, const APInt &Hi)
Return metadata describing the range [Lo, Hi).
Definition:MDBuilder.cpp:95
llvm::MDBuilder::createLikelyBranchWeights
MDNode * createLikelyBranchWeights()
Return metadata containing two branch weights, with significant bias towards true destination.
Definition:MDBuilder.cpp:42
llvm::MDBuilder::createTBAAStructNode
MDNode * createTBAAStructNode(ArrayRef< TBAAStructField > Fields)
Return metadata for a tbaa.struct node with the given struct field descriptions.
Definition:MDBuilder.cpp:238
llvm::MDBuilder::MDBuilder
MDBuilder(LLVMContext &context)
Definition:MDBuilder.h:40
llvm::MDBuilder::mergeCallbackEncodings
MDNode * mergeCallbackEncodings(MDNode *ExistingCallbacks, MDNode *NewCB)
Merge the new callback encoding NewCB into ExistingCallbacks.
Definition:MDBuilder.cpp:135
llvm::MDBuilder::createMutableTBAAAccessTag
MDNode * createMutableTBAAAccessTag(MDNode *Tag)
Return mutable version of the given mutable or immutable TBAA access tag.
Definition:MDBuilder.cpp:315
llvm::MDBuilder::createLLVMStats
MDNode * createLLVMStats(ArrayRef< std::pair< StringRef, uint64_t > > LLVMStatsVec)
Return metadata containing llvm statistics.
Definition:MDBuilder.cpp:361
llvm::MDBuilder::createRTTIPointerPrologue
MDNode * createRTTIPointerPrologue(Constant *PrologueSig, Constant *RTTI)
Return metadata feeding to the CodeGen about how to generate a function prologue for the "function" s...
Definition:MDBuilder.cpp:165
llvm::MDBuilder::createAnonymousAliasScopeDomain
MDNode * createAnonymousAliasScopeDomain(StringRef Name=StringRef())
Return metadata appropriate for an alias scope domain node.
Definition:MDBuilder.h:167
llvm::MDBuilder::createUnlikelyBranchWeights
MDNode * createUnlikelyBranchWeights()
Return metadata containing two branch weights, with significant bias towards false destination.
Definition:MDBuilder.cpp:47
llvm::MDBuilder::createAliasScope
MDNode * createAliasScope(StringRef Name, MDNode *Domain)
Return metadata appropriate for an alias scope node with the given name.
Definition:MDBuilder.cpp:232
llvm::MDBuilder::createTBAAStructTagNode
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:274
llvm::MDBuilder::createTBAATypeNode
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,...
Definition:MDBuilder.cpp:285
llvm::MDNode
Metadata node.
Definition:Metadata.h:1073
llvm::MDString
A single uniqued string.
Definition:Metadata.h:724
llvm::Metadata
Root of the metadata hierarchy.
Definition:Metadata.h:62
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
uint32_t
uint64_t
DataTypes.h
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::ISD::Constant
@ Constant
Definition:ISDOpcodes.h:76
llvm::codeview::PublicSymFlags::Function
@ Function
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::PackElem::Hi
@ Hi
llvm::PackElem::Lo
@ Lo
llvm::ArrayRef
ArrayRef(const T &OneElt) -> ArrayRef< T >
llvm::HighlightColor::Tag
@ Tag
llvm::MDBuilder::TBAAStructField
Definition:MDBuilder.h:199
llvm::MDBuilder::TBAAStructField::Type
MDNode * Type
Definition:MDBuilder.h:202
llvm::MDBuilder::TBAAStructField::Offset
uint64_t Offset
Definition:MDBuilder.h:200
llvm::MDBuilder::TBAAStructField::Size
uint64_t Size
Definition:MDBuilder.h:201
llvm::MDBuilder::TBAAStructField::TBAAStructField
TBAAStructField(uint64_t Offset, uint64_t Size, MDNode *Type)
Definition:MDBuilder.h:203

Generated on Thu Jul 17 2025 10:05:31 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp