LLVM  16.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 
20 #include "llvm/Support/Alignment.h"
21 
22 namespace llvm {
23 
24 class AMDGPUTargetStreamer;
25 class Argument;
26 class DataLayout;
27 class Function;
28 class MachineFunction;
29 class MDNode;
30 class Module;
31 struct SIProgramInfo;
32 class Type;
33 class GCNSubtarget;
34 
35 namespace AMDGPU {
36 
37 namespace IsaInfo {
38 class AMDGPUTargetID;
39 }
40 
41 namespace HSAMD {
42 
44 public:
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 
57 protected:
58  virtual void emitVersion() = 0;
59  virtual void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
61 };
62 
64 protected:
65  std::unique_ptr<msgpack::Document> HSAMetadataDoc =
66  std::make_unique<msgpack::Document>();
67 
68  void dump(StringRef HSAMetadataString) const;
69 
70  void verify(StringRef HSAMetadataString) const;
71 
73 
75 
76  StringRef getValueKind(Type *Ty, StringRef TypeQual,
77  StringRef BaseTypeName) const;
78 
79  std::string getTypeName(Type *Ty, bool Signed) const;
80 
82 
84  const SIProgramInfo &ProgramInfo) const;
85 
86  void emitVersion() override;
87 
88  void emitPrintf(const Module &Mod);
89 
90  void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
91 
92  void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern);
93 
95 
96  void emitKernelArg(const Argument &Arg, unsigned &Offset,
98 
99  void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
100  StringRef ValueKind, unsigned &Offset,
102  MaybeAlign PointeeAlign = std::nullopt,
103  StringRef Name = "", StringRef TypeName = "",
104  StringRef BaseTypeName = "", StringRef AccQual = "",
105  StringRef TypeQual = "");
106 
107  void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
108  msgpack::ArrayDocNode Args) override;
109 
111  return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
112  }
113 
115  return HSAMetadataDoc->getRoot();
116  }
117 
118 public:
119  MetadataStreamerMsgPackV3() = default;
120  ~MetadataStreamerMsgPackV3() = default;
121 
122  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
123 
124  void begin(const Module &Mod,
125  const IsaInfo::AMDGPUTargetID &TargetID) override;
126 
127  void end() override;
128 
129  void emitKernel(const MachineFunction &MF,
130  const SIProgramInfo &ProgramInfo) override;
131 };
132 
134 protected:
135  void emitVersion() override;
136  void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID);
137 
138 public:
139  MetadataStreamerMsgPackV4() = default;
140  ~MetadataStreamerMsgPackV4() = default;
141 
142  void begin(const Module &Mod,
143  const IsaInfo::AMDGPUTargetID &TargetID) override;
144 };
145 
147 protected:
148  void emitVersion() override;
149  void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
150  msgpack::ArrayDocNode Args) override;
151 
152 public:
153  MetadataStreamerMsgPackV5() = default;
154  ~MetadataStreamerMsgPackV5() = default;
155 };
156 
157 // TODO: Rename MetadataStreamerV2 -> MetadataStreamerYamlV2.
159 private:
160  Metadata HSAMetadata;
161 
162  void dump(StringRef HSAMetadataString) const;
163 
164  void verify(StringRef HSAMetadataString) const;
165 
166  AccessQualifier getAccessQualifier(StringRef AccQual) const;
167 
168  AddressSpaceQualifier getAddressSpaceQualifier(unsigned AddressSpace) const;
169 
170  ValueKind getValueKind(Type *Ty, StringRef TypeQual,
171  StringRef BaseTypeName) const;
172 
173  std::string getTypeName(Type *Ty, bool Signed) const;
174 
175  std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
176 
177  Kernel::CodeProps::Metadata getHSACodeProps(
178  const MachineFunction &MF,
179  const SIProgramInfo &ProgramInfo) const;
180  Kernel::DebugProps::Metadata getHSADebugProps(
181  const MachineFunction &MF,
182  const SIProgramInfo &ProgramInfo) const;
183 
184  void emitPrintf(const Module &Mod);
185 
186  void emitKernelLanguage(const Function &Func);
187 
188  void emitKernelAttrs(const Function &Func);
189 
190  void emitKernelArgs(const Function &Func, const GCNSubtarget &ST);
191 
192  void emitKernelArg(const Argument &Arg);
193 
194  void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
196  MaybeAlign PointeeAlign = std::nullopt,
197  StringRef Name = "", StringRef TypeName = "",
198  StringRef BaseTypeName = "", StringRef AccQual = "",
199  StringRef TypeQual = "");
200 
201  void emitHiddenKernelArgs(const Function &Func, const GCNSubtarget &ST);
202 
203  const Metadata &getHSAMetadata() const {
204  return HSAMetadata;
205  }
206 
207 protected:
208  void emitVersion() override;
209  void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
210  msgpack::ArrayDocNode Args) override {
211  llvm_unreachable("Dummy override should not be invoked!");
212  }
213 
214 public:
215  MetadataStreamerYamlV2() = default;
216  ~MetadataStreamerYamlV2() = default;
217 
218  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
219 
220  void begin(const Module &Mod,
221  const IsaInfo::AMDGPUTargetID &TargetID) override;
222 
223  void end() override;
224 
225  void emitKernel(const MachineFunction &MF,
226  const SIProgramInfo &ProgramInfo) override;
227 };
228 
229 } // end namespace HSAMD
230 } // end namespace AMDGPU
231 } // end namespace llvm
232 
233 #endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::verify
void verify(StringRef HSAMetadataString) const
Definition: AMDGPUHSAMetadataStreamer.cpp:482
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
Signed
@ Signed
Definition: NVPTXISelLowering.cpp:4715
llvm::AMDGPU::HSAMD::Kernel::DebugProps::Metadata
In-memory representation of kernel debug properties metadata.
Definition: AMDGPUMetadata.h:346
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::getHSAKernelProps
msgpack::MapDocNode getHSAKernelProps(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) const
Definition: AMDGPUHSAMetadataStreamer.cpp:862
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::AMDGPU::HSAMD::MetadataStreamer::emitVersion
virtual void emitVersion()=0
llvm::Function
Definition: Function.h:60
llvm::AMDGPU::HSAMD::MetadataStreamerYamlV2::emitKernel
void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) override
Definition: AMDGPUHSAMetadataStreamer.cpp:452
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::emitKernelArgs
void emitKernelArgs(const MachineFunction &MF, msgpack::MapDocNode Kern)
Definition: AMDGPUHSAMetadataStreamer.cpp:674
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::begin
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
Definition: AMDGPUHSAMetadataStreamer.cpp:908
llvm::AMDGPU::HSAMD::MetadataStreamer::~MetadataStreamer
virtual ~MetadataStreamer()=default
llvm::AMDGPU::HSAMD::MetadataStreamerYamlV2::end
void end() override
Definition: AMDGPUHSAMetadataStreamer.cpp:441
llvm::AMDGPU::HSAMD::MetadataStreamer::end
virtual void end()=0
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::AMDGPU::HSAMD::MetadataStreamerYamlV2::MetadataStreamerYamlV2
MetadataStreamerYamlV2()=default
llvm::Optional
Definition: APInt.h:33
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV5
Definition: AMDGPUHSAMetadataStreamer.h:146
llvm::GCNSubtarget
Definition: GCNSubtarget.h:31
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::MetadataStreamerMsgPackV3
MetadataStreamerMsgPackV3()=default
llvm::AMDGPU::HSAMD::MetadataStreamer::emitKernel
virtual void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo)=0
llvm::logicalview::LVAttributeKind::Argument
@ Argument
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::getTypeName
std::string getTypeName(Type *Ty, bool Signed) const
Definition: AMDGPUHSAMetadataStreamer.cpp:560
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::emitVersion
void emitVersion() override
Definition: AMDGPUHSAMetadataStreamer.cpp:953
llvm::AMDGPU::HSAMD::MetadataStreamerYamlV2::emitHiddenKernelArgs
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args) override
Definition: AMDGPUHSAMetadataStreamer.h:209
llvm::AMDGPU::HSAMD::AccessQualifier
AccessQualifier
Access qualifiers.
Definition: AMDGPUMetadata.h:58
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::emitKernel
void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) override
Definition: AMDGPUHSAMetadataStreamer.cpp:926
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:187
llvm::AMDGPU::HSAMD::ValueKind
ValueKind
Value kinds.
Definition: AMDGPUMetadata.h:78
llvm::AMDGPU::IsaInfo::AMDGPUTargetID
Definition: AMDGPUBaseInfo.h:110
llvm::AMDGPU::HSAMD::MetadataStreamerYamlV2::emitVersion
void emitVersion() override
Definition: AMDGPUHSAMetadataStreamer.cpp:224
llvm::msgpack::DocNode
A node in a MsgPack Document.
Definition: MsgPackDocument.h:38
llvm::AMDGPU::HSAMD::MetadataStreamer::begin
virtual void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID)=0
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::~MetadataStreamerMsgPackV3
~MetadataStreamerMsgPackV3()=default
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::AccQual
constexpr char AccQual[]
Key for Kernel::Arg::Metadata::mAccQual.
Definition: AMDGPUMetadata.h:191
llvm::AMDGPU::HSAMD::MetadataStreamer::emitHiddenKernelArgs
virtual void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args)=0
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:486
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::getWorkGroupDimensions
msgpack::ArrayDocNode getWorkGroupDimensions(MDNode *Node) const
Definition: AMDGPUHSAMetadataStreamer.cpp:599
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::getAddressSpaceQualifier
Optional< StringRef > getAddressSpaceQualifier(unsigned AddressSpace) const
Definition: AMDGPUHSAMetadataStreamer.cpp:512
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::dump
void dump(StringRef HSAMetadataString) const
Definition: AMDGPUHSAMetadataStreamer.cpp:478
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
AMDGPU
Definition: AMDGPUReplaceLDSUseWithPointer.cpp:114
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::begin
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
Definition: AMDGPUHSAMetadataStreamer.cpp:966
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::emitTargetID
void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID)
Definition: AMDGPUHSAMetadataStreamer.cpp:960
llvm::AMDGPU::HSAMD::Metadata
In-memory representation of HSA metadata.
Definition: AMDGPUMetadata.h:436
llvm::AMDGPU::HSAMD::MetadataStreamerYamlV2
Definition: AMDGPUHSAMetadataStreamer.h:158
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::AddressSpace
AddressSpace
Definition: NVPTXBaseInfo.h:21
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::emitKernelLanguage
void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern)
Definition: AMDGPUHSAMetadataStreamer.cpp:630
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::getValueKind
StringRef getValueKind(Type *Ty, StringRef TypeQual, StringRef BaseTypeName) const
Definition: AMDGPUHSAMetadataStreamer.cpp:533
llvm::AMDGPU::HSAMD::MetadataStreamerYamlV2::emitTo
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override
Definition: AMDGPUHSAMetadataStreamer.cpp:431
llvm::msgpack::MapDocNode
A DocNode that is a map.
Definition: MsgPackDocument.h:219
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::emitKernelArg
void emitKernelArg(const Argument &Arg, unsigned &Offset, msgpack::ArrayDocNode Args)
Definition: AMDGPUHSAMetadataStreamer.cpp:687
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::emitHiddenKernelArgs
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args) override
Definition: AMDGPUHSAMetadataStreamer.cpp:795
MsgPackDocument.h
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::emitKernelAttrs
void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern)
Definition: AMDGPUHSAMetadataStreamer.cpp:649
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::emitVersion
void emitVersion() override
Definition: AMDGPUHSAMetadataStreamer.cpp:610
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::PointeeAlign
constexpr char PointeeAlign[]
Key for Kernel::Arg::Metadata::mPointeeAlign.
Definition: AMDGPUMetadata.h:187
TemplateParamKind::Type
@ Type
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::getAccessQualifier
Optional< StringRef > getAccessQualifier(StringRef AccQual) const
Definition: AMDGPUHSAMetadataStreamer.cpp:504
llvm::AMDGPU::HSAMD::Kernel::CodeProps::Metadata
In-memory representation of kernel code properties metadata.
Definition: AMDGPUMetadata.h:274
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::getHSAMetadataRoot
msgpack::DocNode & getHSAMetadataRoot()
Definition: AMDGPUHSAMetadataStreamer.h:114
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:66
llvm::MDNode
Metadata node.
Definition: Metadata.h:944
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV5::MetadataStreamerMsgPackV5
MetadataStreamerMsgPackV5()=default
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::end
void end() override
Definition: AMDGPUHSAMetadataStreamer.cpp:915
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::emitPrintf
void emitPrintf(const Module &Mod)
Definition: AMDGPUHSAMetadataStreamer.cpp:617
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::getRootMetadata
msgpack::DocNode & getRootMetadata(StringRef Key)
Definition: AMDGPUHSAMetadataStreamer.h:110
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::~MetadataStreamerMsgPackV4
~MetadataStreamerMsgPackV4()=default
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV5::emitHiddenKernelArgs
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args) override
Definition: AMDGPUHSAMetadataStreamer.cpp:985
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::AMDGPU::HSAMD::MetadataStreamerYamlV2::begin
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
Definition: AMDGPUHSAMetadataStreamer.cpp:435
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV5::~MetadataStreamerMsgPackV5
~MetadataStreamerMsgPackV5()=default
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::AMDGPUTargetStreamer
Definition: AMDGPUTargetStreamer.h:34
Node
Definition: ItaniumDemangle.h:156
llvm::AMDGPU::HSAMD::AddressSpaceQualifier
AddressSpaceQualifier
Address space qualifiers.
Definition: AMDGPUMetadata.h:67
Alignment.h
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::emitTo
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override
Definition: AMDGPUHSAMetadataStreamer.cpp:904
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::TypeName
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
Definition: AMDGPUMetadata.h:175
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3
Definition: AMDGPUHSAMetadataStreamer.h:63
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV3::HSAMetadataDoc
std::unique_ptr< msgpack::Document > HSAMetadataDoc
Definition: AMDGPUHSAMetadataStreamer.h:65
llvm::AMDGPU::HSAMD::MetadataStreamerYamlV2::~MetadataStreamerYamlV2
~MetadataStreamerYamlV2()=default
llvm::AMDGPU::HSAMD::MetadataStreamer
Definition: AMDGPUHSAMetadataStreamer.h:43
llvm::msgpack::ArrayDocNode
A DocNode that is an array.
Definition: MsgPackDocument.h:249
llvm::SIProgramInfo
Track resource usage for kernels / entry functions.
Definition: SIProgramInfo.h:25
AMDGPUMetadata.h
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4::MetadataStreamerMsgPackV4
MetadataStreamerMsgPackV4()=default
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV5::emitVersion
void emitVersion() override
Definition: AMDGPUHSAMetadataStreamer.cpp:978
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::AMDGPU::HSAMD::MetadataStreamerMsgPackV4
Definition: AMDGPUHSAMetadataStreamer.h:133
llvm::AMDGPU::HSAMD::MetadataStreamer::emitTo
virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer)=0