LLVM 17.0.0git
AMDGPUHSAMetadataStreamer.h
Go to the documentation of this file.
1//===--- AMDGPUHSAMetadataStreamer.h ----------------------------*- 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/// \file
10/// AMDGPU HSA Metadata Streamer.
11///
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
16#define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
17
21
22namespace llvm {
23
24class AMDGPUTargetStreamer;
25class Argument;
26class DataLayout;
27class Function;
28class MachineFunction;
29class MDNode;
30class Module;
31struct SIProgramInfo;
32class Type;
33class GCNSubtarget;
34
35namespace AMDGPU {
36
37namespace IsaInfo {
38class AMDGPUTargetID;
39}
40
41namespace HSAMD {
42
44public:
45 virtual ~MetadataStreamer() = default;
46
47 virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
48
49 virtual void begin(const Module &Mod,
50 const IsaInfo::AMDGPUTargetID &TargetID) = 0;
51
52 virtual void end() = 0;
53
54 virtual void emitKernel(const MachineFunction &MF,
55 const SIProgramInfo &ProgramInfo) = 0;
56
57protected:
58 virtual void emitVersion() = 0;
59 virtual void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
60 msgpack::ArrayDocNode Args) = 0;
61 virtual void emitKernelAttrs(const Function &Func,
62 msgpack::MapDocNode Kern) = 0;
63};
64
66protected:
67 std::unique_ptr<msgpack::Document> HSAMetadataDoc =
68 std::make_unique<msgpack::Document>();
69
70 void dump(StringRef HSAMetadataString) const;
71
72 void verify(StringRef HSAMetadataString) const;
73
74 std::optional<StringRef> getAccessQualifier(StringRef AccQual) const;
75
76 std::optional<StringRef>
78
80 StringRef BaseTypeName) const;
81
82 std::string getTypeName(Type *Ty, bool Signed) const;
83
85
87 const SIProgramInfo &ProgramInfo,
88 unsigned CodeObjectVersion) const;
89
90 void emitVersion() override;
91
92 void emitPrintf(const Module &Mod);
93
94 void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
95
96 void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern) override;
97
99
100 void emitKernelArg(const Argument &Arg, unsigned &Offset,
102
103 void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
104 StringRef ValueKind, unsigned &Offset,
106 MaybeAlign PointeeAlign = std::nullopt,
107 StringRef Name = "", StringRef TypeName = "",
108 StringRef BaseTypeName = "", StringRef AccQual = "",
109 StringRef TypeQual = "");
110
111 void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
112 msgpack::ArrayDocNode Args) override;
113
115 return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
116 }
117
119 return HSAMetadataDoc->getRoot();
120 }
121
122public:
125
126 bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
127
128 void begin(const Module &Mod,
129 const IsaInfo::AMDGPUTargetID &TargetID) override;
130
131 void end() override;
132
133 void emitKernel(const MachineFunction &MF,
134 const SIProgramInfo &ProgramInfo) override;
135};
136
138protected:
139 void emitVersion() override;
140 void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID);
141
142public:
145
146 void begin(const Module &Mod,
147 const IsaInfo::AMDGPUTargetID &TargetID) override;
148};
149
151protected:
152 void emitVersion() override;
153 void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
154 msgpack::ArrayDocNode Args) override;
155 void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern) override;
156
157public:
160};
161
162// TODO: Rename MetadataStreamerV2 -> MetadataStreamerYamlV2.
164private:
165 Metadata HSAMetadata;
166
167 void dump(StringRef HSAMetadataString) const;
168
169 void verify(StringRef HSAMetadataString) const;
170
171 AccessQualifier getAccessQualifier(StringRef AccQual) const;
172
173 AddressSpaceQualifier getAddressSpaceQualifier(unsigned AddressSpace) const;
174
175 ValueKind getValueKind(Type *Ty, StringRef TypeQual,
176 StringRef BaseTypeName) const;
177
178 std::string getTypeName(Type *Ty, bool Signed) const;
179
180 std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
181
182 Kernel::CodeProps::Metadata getHSACodeProps(
183 const MachineFunction &MF,
184 const SIProgramInfo &ProgramInfo) const;
185 Kernel::DebugProps::Metadata getHSADebugProps(
186 const MachineFunction &MF,
187 const SIProgramInfo &ProgramInfo) const;
188
189 void emitPrintf(const Module &Mod);
190
191 void emitKernelLanguage(const Function &Func);
192
193 void emitKernelAttrs(const Function &Func);
194
195 void emitKernelArgs(const Function &Func, const GCNSubtarget &ST);
196
197 void emitKernelArg(const Argument &Arg);
198
199 void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
201 MaybeAlign PointeeAlign = std::nullopt,
202 StringRef Name = "", StringRef TypeName = "",
203 StringRef BaseTypeName = "", StringRef AccQual = "",
204 StringRef TypeQual = "");
205
206 void emitHiddenKernelArgs(const Function &Func, const GCNSubtarget &ST);
207
208 const Metadata &getHSAMetadata() const {
209 return HSAMetadata;
210 }
211
212protected:
213 void emitVersion() override;
214 void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
215 msgpack::ArrayDocNode Args) override {
216 llvm_unreachable("Dummy override should not be invoked!");
217 }
218 void emitKernelAttrs(const Function &Func,
219 msgpack::MapDocNode Kern) override {
220 llvm_unreachable("Dummy override should not be invoked!");
221 }
222
223public:
226
227 bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
228
229 void begin(const Module &Mod,
230 const IsaInfo::AMDGPUTargetID &TargetID) override;
231
232 void end() override;
233
234 void emitKernel(const MachineFunction &MF,
235 const SIProgramInfo &ProgramInfo) override;
236};
237
238} // end namespace HSAMD
239} // end namespace AMDGPU
240} // end namespace llvm
241
242#endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
AMDGPU metadata definitions and in-memory representations.
RelocType Type
Definition: COFFYAML.cpp:391
std::string Name
Machine Check Debug Module
This file declares a class that exposes a simple in-memory representation of a document of MsgPack ob...
ppc ctr loops verify
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args) override
void emitKernelArgs(const MachineFunction &MF, msgpack::MapDocNode Kern)
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override
void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) override
std::unique_ptr< msgpack::Document > HSAMetadataDoc
void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern) override
StringRef getValueKind(Type *Ty, StringRef TypeQual, StringRef BaseTypeName) const
std::optional< StringRef > getAccessQualifier(StringRef AccQual) const
void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern)
void emitKernelArg(const Argument &Arg, unsigned &Offset, msgpack::ArrayDocNode Args)
msgpack::ArrayDocNode getWorkGroupDimensions(MDNode *Node) const
std::optional< StringRef > getAddressSpaceQualifier(unsigned AddressSpace) const
msgpack::MapDocNode getHSAKernelProps(const MachineFunction &MF, const SIProgramInfo &ProgramInfo, unsigned CodeObjectVersion) const
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID)
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args) override
void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern) override
void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) override
void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern) override
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args) override
virtual void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo)=0
virtual void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args)=0
virtual void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern)=0
virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer)=0
virtual void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID)=0
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
Metadata node.
Definition: Metadata.h:950
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
A DocNode that is an array.
A node in a MsgPack Document.
A DocNode that is a map.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
AddressSpaceQualifier
Address space qualifiers.
ValueKind
Value kinds.
AccessQualifier
Access qualifiers.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:406
AddressSpace
Definition: NVPTXBaseInfo.h:21
StringRef getTypeName()
We provide a function which tries to compute the (demangled) name of a type statically.
Definition: TypeName.h:27
@ Mod
The access may modify the value stored in memory.
In-memory representation of kernel code properties metadata.
In-memory representation of kernel debug properties metadata.
In-memory representation of HSA metadata.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
Track resource usage for kernels / entry functions.
Definition: SIProgramInfo.h:25