LLVM  14.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 
34 namespace AMDGPU {
35 
36 namespace IsaInfo {
37 class AMDGPUTargetID;
38 }
39 
40 namespace HSAMD {
41 
43 public:
44  virtual ~MetadataStreamer(){};
45 
46  virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
47 
48  virtual void begin(const Module &Mod,
49  const IsaInfo::AMDGPUTargetID &TargetID) = 0;
50 
51  virtual void end() = 0;
52 
53  virtual void emitKernel(const MachineFunction &MF,
54  const SIProgramInfo &ProgramInfo) = 0;
55 };
56 
57 // TODO: Rename MetadataStreamerV3 -> MetadataStreamerMsgPackV3.
59 protected:
60  std::unique_ptr<msgpack::Document> HSAMetadataDoc =
61  std::make_unique<msgpack::Document>();
62 
63  void dump(StringRef HSAMetadataString) const;
64 
65  void verify(StringRef HSAMetadataString) const;
66 
68 
70 
71  StringRef getValueKind(Type *Ty, StringRef TypeQual,
72  StringRef BaseTypeName) const;
73 
74  std::string getTypeName(Type *Ty, bool Signed) const;
75 
77 
79  const SIProgramInfo &ProgramInfo) const;
80 
81  void emitVersion();
82 
83  void emitPrintf(const Module &Mod);
84 
85  void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
86 
87  void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern);
88 
89  void emitKernelArgs(const Function &Func, msgpack::MapDocNode Kern);
90 
91  void emitKernelArg(const Argument &Arg, unsigned &Offset,
93 
94  void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
95  StringRef ValueKind, unsigned &Offset,
97  StringRef Name = "", StringRef TypeName = "",
98  StringRef BaseTypeName = "", StringRef AccQual = "",
99  StringRef TypeQual = "");
100 
101  void emitHiddenKernelArgs(const Function &Func, unsigned &Offset,
103 
105  return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
106  }
107 
109  return HSAMetadataDoc->getRoot();
110  }
111 
112 public:
113  MetadataStreamerV3() = default;
114  ~MetadataStreamerV3() = default;
115 
116  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
117 
118  void begin(const Module &Mod,
119  const IsaInfo::AMDGPUTargetID &TargetID) override;
120 
121  void end() override;
122 
123  void emitKernel(const MachineFunction &MF,
124  const SIProgramInfo &ProgramInfo) override;
125 };
126 
127 // TODO: Rename MetadataStreamerV4 -> MetadataStreamerMsgPackV4.
129  void emitVersion();
130 
131  void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID);
132 
133 public:
134  MetadataStreamerV4() = default;
135  ~MetadataStreamerV4() = default;
136 
137  void begin(const Module &Mod,
138  const IsaInfo::AMDGPUTargetID &TargetID) override;
139 };
140 
141 // TODO: Rename MetadataStreamerV2 -> MetadataStreamerYamlV2.
142 class MetadataStreamerV2 final : public MetadataStreamer {
143 private:
144  Metadata HSAMetadata;
145 
146  void dump(StringRef HSAMetadataString) const;
147 
148  void verify(StringRef HSAMetadataString) const;
149 
150  AccessQualifier getAccessQualifier(StringRef AccQual) const;
151 
152  AddressSpaceQualifier getAddressSpaceQualifier(unsigned AddressSpace) const;
153 
154  ValueKind getValueKind(Type *Ty, StringRef TypeQual,
155  StringRef BaseTypeName) const;
156 
157  std::string getTypeName(Type *Ty, bool Signed) const;
158 
159  std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
160 
161  Kernel::CodeProps::Metadata getHSACodeProps(
162  const MachineFunction &MF,
163  const SIProgramInfo &ProgramInfo) const;
164  Kernel::DebugProps::Metadata getHSADebugProps(
165  const MachineFunction &MF,
166  const SIProgramInfo &ProgramInfo) const;
167 
168  void emitVersion();
169 
170  void emitPrintf(const Module &Mod);
171 
172  void emitKernelLanguage(const Function &Func);
173 
174  void emitKernelAttrs(const Function &Func);
175 
176  void emitKernelArgs(const Function &Func);
177 
178  void emitKernelArg(const Argument &Arg);
179 
180  void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
182  StringRef Name = "", StringRef TypeName = "",
183  StringRef BaseTypeName = "", StringRef AccQual = "",
184  StringRef TypeQual = "");
185 
186  void emitHiddenKernelArgs(const Function &Func);
187 
188  const Metadata &getHSAMetadata() const {
189  return HSAMetadata;
190  }
191 
192 public:
193  MetadataStreamerV2() = default;
194  ~MetadataStreamerV2() = default;
195 
196  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
197 
198  void begin(const Module &Mod,
199  const IsaInfo::AMDGPUTargetID &TargetID) override;
200 
201  void end() override;
202 
203  void emitKernel(const MachineFunction &MF,
204  const SIProgramInfo &ProgramInfo) override;
205 };
206 
207 } // end namespace HSAMD
208 } // end namespace AMDGPU
209 } // end namespace llvm
210 
211 #endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
llvm::AMDGPU::HSAMD::MetadataStreamerV2::MetadataStreamerV2
MetadataStreamerV2()=default
Signed
@ Signed
Definition: NVPTXISelLowering.cpp:4636
llvm::AMDGPU::HSAMD::Kernel::DebugProps::Metadata
In-memory representation of kernel debug properties metadata.
Definition: AMDGPUMetadata.h:341
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernel
void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) override
Definition: AMDGPUHSAMetadataStreamer.cpp:908
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::Function
Definition: Function.h:62
llvm::AMDGPU::HSAMD::MetadataStreamerV2::end
void end() override
Definition: AMDGPUHSAMetadataStreamer.cpp:444
llvm::AMDGPU::HSAMD::MetadataStreamerV3::~MetadataStreamerV3
~MetadataStreamerV3()=default
llvm::AMDGPU::HSAMD::MetadataStreamerV3::HSAMetadataDoc
std::unique_ptr< msgpack::Document > HSAMetadataDoc
Definition: AMDGPUHSAMetadataStreamer.h:60
llvm::AMDGPU::HSAMD::MetadataStreamerV3::dump
void dump(StringRef HSAMetadataString) const
Definition: AMDGPUHSAMetadataStreamer.cpp:480
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:58
llvm::Optional
Definition: APInt.h:33
llvm::AMDGPU::HSAMD::MetadataStreamer::~MetadataStreamer
virtual ~MetadataStreamer()
Definition: AMDGPUHSAMetadataStreamer.h:44
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::AMDGPU::HSAMD::MetadataStreamer::emitKernel
virtual void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo)=0
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernelArgs
void emitKernelArgs(const Function &Func, msgpack::MapDocNode Kern)
Definition: AMDGPUHSAMetadataStreamer.cpp:674
llvm::AMDGPU::HSAMD::MetadataStreamerV2::~MetadataStreamerV2
~MetadataStreamerV2()=default
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getWorkGroupDimensions
msgpack::ArrayDocNode getWorkGroupDimensions(MDNode *Node) const
Definition: AMDGPUHSAMetadataStreamer.cpp:599
llvm::AMDGPU::HSAMD::MetadataStreamerV4::begin
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
Definition: AMDGPUHSAMetadataStreamer.cpp:947
llvm::AMDGPU::HSAMD::AccessQualifier
AccessQualifier
Access qualifiers.
Definition: AMDGPUMetadata.h:53
llvm::AMDGPU::HSAMD::MetadataStreamerV3::MetadataStreamerV3
MetadataStreamerV3()=default
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernelLanguage
void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern)
Definition: AMDGPUHSAMetadataStreamer.cpp:630
llvm::AMDGPU::HSAMD::ValueKind
ValueKind
Value kinds.
Definition: AMDGPUMetadata.h:73
llvm::AMDGPU::IsaInfo::AMDGPUTargetID
Definition: AMDGPUBaseInfo.h:85
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:186
llvm::AMDGPU::HSAMD::MetadataStreamerV3::begin
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
Definition: AMDGPUHSAMetadataStreamer.cpp:890
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:109
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getAddressSpaceQualifier
Optional< StringRef > getAddressSpaceQualifier(unsigned AddressSpace) const
Definition: AMDGPUHSAMetadataStreamer.cpp:515
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitHiddenKernelArgs
void emitHiddenKernelArgs(const Function &Func, unsigned &Offset, msgpack::ArrayDocNode Args)
Definition: AMDGPUHSAMetadataStreamer.cpp:792
llvm::AMDGPU::HSAMD::Metadata
In-memory representation of HSA metadata.
Definition: AMDGPUMetadata.h:431
llvm::AMDGPU::HSAMD::MetadataStreamerV3::verify
void verify(StringRef HSAMetadataString) const
Definition: AMDGPUHSAMetadataStreamer.cpp:484
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:23
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getRootMetadata
msgpack::DocNode & getRootMetadata(StringRef Key)
Definition: AMDGPUHSAMetadataStreamer.h:104
llvm::msgpack::MapDocNode
A DocNode that is a map.
Definition: MsgPackDocument.h:219
MsgPackDocument.h
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernelAttrs
void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern)
Definition: AMDGPUHSAMetadataStreamer.cpp:649
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::PointeeAlign
constexpr char PointeeAlign[]
Key for Kernel::Arg::Metadata::mPointeeAlign.
Definition: AMDGPUMetadata.h:182
TemplateParamKind::Type
@ Type
llvm::AMDGPU::HSAMD::Kernel::CodeProps::Metadata
In-memory representation of kernel code properties metadata.
Definition: AMDGPUMetadata.h:269
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MDNode
Metadata node.
Definition: Metadata.h:906
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernelArg
void emitKernelArg(const Argument &Arg, unsigned &Offset, msgpack::ArrayDocNode Args)
Definition: AMDGPUHSAMetadataStreamer.cpp:686
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::ReplayInlineScope::Function
@ Function
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitTo
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override
Definition: AMDGPUHSAMetadataStreamer.cpp:886
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:235
llvm::AMDGPU::HSAMD::MetadataStreamerV4::~MetadataStreamerV4
~MetadataStreamerV4()=default
llvm::AMDGPU::HSAMD::AddressSpaceQualifier
AddressSpaceQualifier
Address space qualifiers.
Definition: AMDGPUMetadata.h:62
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitPrintf
void emitPrintf(const Module &Mod)
Definition: AMDGPUHSAMetadataStreamer.cpp:617
llvm::AMDGPU::HSAMD::MetadataStreamerV3::end
void end() override
Definition: AMDGPUHSAMetadataStreamer.cpp:897
llvm::AMDGPU::HSAMD::MetadataStreamerV2::emitTo
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override
Definition: AMDGPUHSAMetadataStreamer.cpp:434
Alignment.h
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::TypeName
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
Definition: AMDGPUMetadata.h:170
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getHSAKernelProps
msgpack::MapDocNode getHSAKernelProps(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) const
Definition: AMDGPUHSAMetadataStreamer.cpp:855
llvm::AMDGPU::HSAMD::MetadataStreamerV2
Definition: AMDGPUHSAMetadataStreamer.h:142
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getValueKind
StringRef getValueKind(Type *Ty, StringRef TypeQual, StringRef BaseTypeName) const
Definition: AMDGPUHSAMetadataStreamer.cpp:534
llvm::AMDGPU::HSAMD::MetadataStreamer
Definition: AMDGPUHSAMetadataStreamer.h:42
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:561
llvm::AMDGPU::HSAMD::MetadataStreamerV2::begin
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
Definition: AMDGPUHSAMetadataStreamer.cpp:438
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getAccessQualifier
Optional< StringRef > getAccessQualifier(StringRef AccQual) const
Definition: AMDGPUHSAMetadataStreamer.cpp:506
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitVersion
void emitVersion()
Definition: AMDGPUHSAMetadataStreamer.cpp:610
llvm::AMDGPU::HSAMD::MetadataStreamerV2::emitKernel
void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) override
Definition: AMDGPUHSAMetadataStreamer.cpp:455
llvm::AMDGPU::HSAMD::MetadataStreamerV4::MetadataStreamerV4
MetadataStreamerV4()=default
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389
Mod
Module * Mod
Definition: PassBuilderBindings.cpp:54
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getHSAMetadataRoot
msgpack::DocNode & getHSAMetadataRoot()
Definition: AMDGPUHSAMetadataStreamer.h:108
llvm::AMDGPU::HSAMD::MetadataStreamerV4
Definition: AMDGPUHSAMetadataStreamer.h:128
llvm::AMDGPU::HSAMD::MetadataStreamer::emitTo
virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer)=0