LLVM  15.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 
63 // TODO: Rename MetadataStreamerV3 -> MetadataStreamerMsgPackV3.
65 protected:
66  std::unique_ptr<msgpack::Document> HSAMetadataDoc =
67  std::make_unique<msgpack::Document>();
68 
69  void dump(StringRef HSAMetadataString) const;
70 
71  void verify(StringRef HSAMetadataString) const;
72 
74 
76 
77  StringRef getValueKind(Type *Ty, StringRef TypeQual,
78  StringRef BaseTypeName) const;
79 
80  std::string getTypeName(Type *Ty, bool Signed) const;
81 
83 
85  const SIProgramInfo &ProgramInfo) const;
86 
87  void emitVersion() override;
88 
89  void emitPrintf(const Module &Mod);
90 
91  void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
92 
93  void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern);
94 
96 
97  void emitKernelArg(const Argument &Arg, unsigned &Offset,
99 
100  void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
101  StringRef ValueKind, unsigned &Offset,
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  MetadataStreamerV3() = default;
120  ~MetadataStreamerV3() = 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 
133 // TODO: Rename MetadataStreamerV4 -> MetadataStreamerMsgPackV4.
135 protected:
136  void emitVersion() override;
137  void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID);
138 
139 public:
140  MetadataStreamerV4() = default;
141  ~MetadataStreamerV4() = default;
142 
143  void begin(const Module &Mod,
144  const IsaInfo::AMDGPUTargetID &TargetID) override;
145 };
146 
147 // TODO: Rename MetadataStreamerV5 -> MetadataStreamerMsgPackV5.
149 protected:
150  void emitVersion() override;
151  void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
152  msgpack::ArrayDocNode Args) override;
153 
154 public:
155  MetadataStreamerV5() = default;
156  ~MetadataStreamerV5() = default;
157 };
158 
159 // TODO: Rename MetadataStreamerV2 -> MetadataStreamerYamlV2.
160 class MetadataStreamerV2 final : public MetadataStreamer {
161 private:
162  Metadata HSAMetadata;
163 
164  void dump(StringRef HSAMetadataString) const;
165 
166  void verify(StringRef HSAMetadataString) const;
167 
168  AccessQualifier getAccessQualifier(StringRef AccQual) const;
169 
170  AddressSpaceQualifier getAddressSpaceQualifier(unsigned AddressSpace) const;
171 
172  ValueKind getValueKind(Type *Ty, StringRef TypeQual,
173  StringRef BaseTypeName) const;
174 
175  std::string getTypeName(Type *Ty, bool Signed) const;
176 
177  std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
178 
179  Kernel::CodeProps::Metadata getHSACodeProps(
180  const MachineFunction &MF,
181  const SIProgramInfo &ProgramInfo) const;
182  Kernel::DebugProps::Metadata getHSADebugProps(
183  const MachineFunction &MF,
184  const SIProgramInfo &ProgramInfo) const;
185 
186  void emitPrintf(const Module &Mod);
187 
188  void emitKernelLanguage(const Function &Func);
189 
190  void emitKernelAttrs(const Function &Func);
191 
192  void emitKernelArgs(const Function &Func, const GCNSubtarget &ST);
193 
194  void emitKernelArg(const Argument &Arg);
195 
196  void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
198  StringRef Name = "", StringRef TypeName = "",
199  StringRef BaseTypeName = "", StringRef AccQual = "",
200  StringRef TypeQual = "");
201 
202  void emitHiddenKernelArgs(const Function &Func, const GCNSubtarget &ST);
203 
204  const Metadata &getHSAMetadata() const {
205  return HSAMetadata;
206  }
207 
208 protected:
209  void emitVersion() override;
210  void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
211  msgpack::ArrayDocNode Args) override {
212  llvm_unreachable("Dummy override should not be invoked!");
213  }
214 
215 public:
216  MetadataStreamerV2() = default;
217  ~MetadataStreamerV2() = default;
218 
219  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
220 
221  void begin(const Module &Mod,
222  const IsaInfo::AMDGPUTargetID &TargetID) override;
223 
224  void end() override;
225 
226  void emitKernel(const MachineFunction &MF,
227  const SIProgramInfo &ProgramInfo) override;
228 };
229 
230 } // end namespace HSAMD
231 } // end namespace AMDGPU
232 } // end namespace llvm
233 
234 #endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
llvm::AMDGPU::HSAMD::MetadataStreamerV5::emitVersion
void emitVersion() override
Definition: AMDGPUHSAMetadataStreamer.cpp:975
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
llvm::AMDGPU::HSAMD::MetadataStreamerV2::MetadataStreamerV2
MetadataStreamerV2()=default
Signed
@ Signed
Definition: NVPTXISelLowering.cpp:4637
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:17
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernel
void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) override
Definition: AMDGPUHSAMetadataStreamer.cpp:924
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::MetadataStreamerV2::end
void end() override
Definition: AMDGPUHSAMetadataStreamer.cpp:446
llvm::AMDGPU::HSAMD::MetadataStreamerV3::~MetadataStreamerV3
~MetadataStreamerV3()=default
llvm::AMDGPU::HSAMD::MetadataStreamerV3::HSAMetadataDoc
std::unique_ptr< msgpack::Document > HSAMetadataDoc
Definition: AMDGPUHSAMetadataStreamer.h:66
llvm::AMDGPU::HSAMD::MetadataStreamerV5::emitHiddenKernelArgs
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args) override
Definition: AMDGPUHSAMetadataStreamer.cpp:982
llvm::AMDGPU::HSAMD::MetadataStreamer::~MetadataStreamer
virtual ~MetadataStreamer()=default
llvm::AMDGPU::HSAMD::MetadataStreamerV3::dump
void dump(StringRef HSAMetadataString) const
Definition: AMDGPUHSAMetadataStreamer.cpp:483
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitVersion
void emitVersion() override
Definition: AMDGPUHSAMetadataStreamer.cpp:613
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::MetadataStreamerV3
Definition: AMDGPUHSAMetadataStreamer.h:64
llvm::Optional
Definition: APInt.h:33
llvm::GCNSubtarget
Definition: GCNSubtarget.h:31
llvm::AMDGPU::HSAMD::MetadataStreamer::emitKernel
virtual void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo)=0
llvm::AMDGPU::HSAMD::MetadataStreamerV2::~MetadataStreamerV2
~MetadataStreamerV2()=default
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getWorkGroupDimensions
msgpack::ArrayDocNode getWorkGroupDimensions(MDNode *Node) const
Definition: AMDGPUHSAMetadataStreamer.cpp:602
llvm::AMDGPU::HSAMD::MetadataStreamerV4::begin
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
Definition: AMDGPUHSAMetadataStreamer.cpp:963
llvm::AMDGPU::HSAMD::AccessQualifier
AccessQualifier
Access qualifiers.
Definition: AMDGPUMetadata.h:58
llvm::AMDGPU::HSAMD::MetadataStreamerV3::MetadataStreamerV3
MetadataStreamerV3()=default
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:186
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernelLanguage
void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern)
Definition: AMDGPUHSAMetadataStreamer.cpp:633
llvm::AMDGPU::HSAMD::ValueKind
ValueKind
Value kinds.
Definition: AMDGPUMetadata.h:78
llvm::AMDGPU::IsaInfo::AMDGPUTargetID
Definition: AMDGPUBaseInfo.h:105
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::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::HSAMD::MetadataStreamerV3::begin
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
Definition: AMDGPUHSAMetadataStreamer.cpp:906
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:486
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::MetadataStreamerV3::getAddressSpaceQualifier
Optional< StringRef > getAddressSpaceQualifier(unsigned AddressSpace) const
Definition: AMDGPUHSAMetadataStreamer.cpp:518
llvm::AMDGPU::HSAMD::MetadataStreamerV4::emitVersion
void emitVersion() override
Definition: AMDGPUHSAMetadataStreamer.cpp:951
llvm::AMDGPU::HSAMD::Metadata
In-memory representation of HSA metadata.
Definition: AMDGPUMetadata.h:436
llvm::AMDGPU::HSAMD::MetadataStreamerV3::verify
void verify(StringRef HSAMetadataString) const
Definition: AMDGPUHSAMetadataStreamer.cpp:487
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::None
const NoneType None
Definition: None.h:24
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernelArgs
void emitKernelArgs(const MachineFunction &MF, msgpack::MapDocNode Kern)
Definition: AMDGPUHSAMetadataStreamer.cpp:677
llvm::AMDGPU::HSAMD::MetadataStreamerV5::MetadataStreamerV5
MetadataStreamerV5()=default
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getRootMetadata
msgpack::DocNode & getRootMetadata(StringRef Key)
Definition: AMDGPUHSAMetadataStreamer.h:110
llvm::msgpack::MapDocNode
A DocNode that is a map.
Definition: MsgPackDocument.h:219
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
llvm::AMDGPU::HSAMD::MetadataStreamerV5::~MetadataStreamerV5
~MetadataStreamerV5()=default
MsgPackDocument.h
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernelAttrs
void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern)
Definition: AMDGPUHSAMetadataStreamer.cpp:652
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::Kernel::CodeProps::Metadata
In-memory representation of kernel code properties metadata.
Definition: AMDGPUMetadata.h:274
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MDNode
Metadata node.
Definition: Metadata.h:944
llvm::AMDGPU::HSAMD::MetadataStreamerV5
Definition: AMDGPUHSAMetadataStreamer.h:148
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernelArg
void emitKernelArg(const Argument &Arg, unsigned &Offset, msgpack::ArrayDocNode Args)
Definition: AMDGPUHSAMetadataStreamer.cpp:690
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AMDGPU::HSAMD::MetadataStreamerV4::emitTargetID
void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID)
Definition: AMDGPUHSAMetadataStreamer.cpp:958
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitTo
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override
Definition: AMDGPUHSAMetadataStreamer.cpp:902
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:155
llvm::AMDGPU::HSAMD::MetadataStreamerV4::~MetadataStreamerV4
~MetadataStreamerV4()=default
llvm::AMDGPU::HSAMD::AddressSpaceQualifier
AddressSpaceQualifier
Address space qualifiers.
Definition: AMDGPUMetadata.h:67
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitPrintf
void emitPrintf(const Module &Mod)
Definition: AMDGPUHSAMetadataStreamer.cpp:620
llvm::AMDGPU::HSAMD::MetadataStreamerV3::end
void end() override
Definition: AMDGPUHSAMetadataStreamer.cpp:913
llvm::AMDGPU::HSAMD::MetadataStreamerV2::emitVersion
void emitVersion() override
Definition: AMDGPUHSAMetadataStreamer.cpp:227
llvm::AMDGPU::HSAMD::MetadataStreamerV2::emitTo
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override
Definition: AMDGPUHSAMetadataStreamer.cpp:436
Alignment.h
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::TypeName
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
Definition: AMDGPUMetadata.h:175
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getHSAKernelProps
msgpack::MapDocNode getHSAKernelProps(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) const
Definition: AMDGPUHSAMetadataStreamer.cpp:863
llvm::AMDGPU::HSAMD::MetadataStreamerV2
Definition: AMDGPUHSAMetadataStreamer.h:160
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getValueKind
StringRef getValueKind(Type *Ty, StringRef TypeQual, StringRef BaseTypeName) const
Definition: AMDGPUHSAMetadataStreamer.cpp:537
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::MetadataStreamerV3::getTypeName
std::string getTypeName(Type *Ty, bool Signed) const
Definition: AMDGPUHSAMetadataStreamer.cpp:564
llvm::AMDGPU::HSAMD::MetadataStreamerV2::emitHiddenKernelArgs
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args) override
Definition: AMDGPUHSAMetadataStreamer.h:210
llvm::AMDGPU::HSAMD::MetadataStreamerV2::begin
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
Definition: AMDGPUHSAMetadataStreamer.cpp:440
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getAccessQualifier
Optional< StringRef > getAccessQualifier(StringRef AccQual) const
Definition: AMDGPUHSAMetadataStreamer.cpp:509
llvm::AMDGPU::HSAMD::MetadataStreamerV2::emitKernel
void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) override
Definition: AMDGPUHSAMetadataStreamer.cpp:457
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitHiddenKernelArgs
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args) override
Definition: AMDGPUHSAMetadataStreamer.cpp:794
llvm::AMDGPU::HSAMD::MetadataStreamerV4::MetadataStreamerV4
MetadataStreamerV4()=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::MetadataStreamerV3::getHSAMetadataRoot
msgpack::DocNode & getHSAMetadataRoot()
Definition: AMDGPUHSAMetadataStreamer.h:114
llvm::AMDGPU::HSAMD::MetadataStreamerV4
Definition: AMDGPUHSAMetadataStreamer.h:134
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::AMDGPU::HSAMD::MetadataStreamer::emitTo
virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer)=0