LLVM  13.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 
18 #include "Utils/AMDGPUBaseInfo.h"
21 #include "llvm/Support/Alignment.h"
22 
23 namespace llvm {
24 
25 class AMDGPUTargetStreamer;
26 class Argument;
27 class DataLayout;
28 class Function;
29 class MachineFunction;
30 class MDNode;
31 class Module;
32 struct SIProgramInfo;
33 class Type;
34 
35 namespace AMDGPU {
36 namespace HSAMD {
37 
39 public:
40  virtual ~MetadataStreamer(){};
41 
42  virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
43 
44  virtual void begin(const Module &Mod,
45  const IsaInfo::AMDGPUTargetID &TargetID) = 0;
46 
47  virtual void end() = 0;
48 
49  virtual void emitKernel(const MachineFunction &MF,
50  const SIProgramInfo &ProgramInfo) = 0;
51 };
52 
53 // TODO: Rename MetadataStreamerV3 -> MetadataStreamerMsgPackV3.
55 protected:
56  std::unique_ptr<msgpack::Document> HSAMetadataDoc =
57  std::make_unique<msgpack::Document>();
58 
59  void dump(StringRef HSAMetadataString) const;
60 
61  void verify(StringRef HSAMetadataString) const;
62 
64 
66 
67  StringRef getValueKind(Type *Ty, StringRef TypeQual,
68  StringRef BaseTypeName) const;
69 
70  std::string getTypeName(Type *Ty, bool Signed) const;
71 
73 
75  const SIProgramInfo &ProgramInfo) const;
76 
77  void emitVersion();
78 
79  void emitPrintf(const Module &Mod);
80 
81  void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
82 
83  void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern);
84 
85  void emitKernelArgs(const Function &Func, msgpack::MapDocNode Kern);
86 
87  void emitKernelArg(const Argument &Arg, unsigned &Offset,
89 
90  void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
91  StringRef ValueKind, unsigned &Offset,
93  StringRef Name = "", StringRef TypeName = "",
94  StringRef BaseTypeName = "", StringRef AccQual = "",
95  StringRef TypeQual = "");
96 
97  void emitHiddenKernelArgs(const Function &Func, unsigned &Offset,
99 
101  return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
102  }
103 
105  return HSAMetadataDoc->getRoot();
106  }
107 
108 public:
109  MetadataStreamerV3() = default;
110  ~MetadataStreamerV3() = default;
111 
112  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
113 
114  void begin(const Module &Mod,
115  const IsaInfo::AMDGPUTargetID &TargetID) override;
116 
117  void end() override;
118 
119  void emitKernel(const MachineFunction &MF,
120  const SIProgramInfo &ProgramInfo) override;
121 };
122 
123 // TODO: Rename MetadataStreamerV4 -> MetadataStreamerMsgPackV4.
125  void emitVersion();
126 
127  void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID);
128 
129 public:
130  MetadataStreamerV4() = default;
131  ~MetadataStreamerV4() = default;
132 
133  void begin(const Module &Mod,
134  const IsaInfo::AMDGPUTargetID &TargetID) override;
135 };
136 
137 // TODO: Rename MetadataStreamerV2 -> MetadataStreamerYamlV2.
138 class MetadataStreamerV2 final : public MetadataStreamer {
139 private:
140  Metadata HSAMetadata;
141 
142  void dump(StringRef HSAMetadataString) const;
143 
144  void verify(StringRef HSAMetadataString) const;
145 
146  AccessQualifier getAccessQualifier(StringRef AccQual) const;
147 
148  AddressSpaceQualifier getAddressSpaceQualifier(unsigned AddressSpace) const;
149 
150  ValueKind getValueKind(Type *Ty, StringRef TypeQual,
151  StringRef BaseTypeName) const;
152 
153  std::string getTypeName(Type *Ty, bool Signed) const;
154 
155  std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
156 
157  Kernel::CodeProps::Metadata getHSACodeProps(
158  const MachineFunction &MF,
159  const SIProgramInfo &ProgramInfo) const;
160  Kernel::DebugProps::Metadata getHSADebugProps(
161  const MachineFunction &MF,
162  const SIProgramInfo &ProgramInfo) const;
163 
164  void emitVersion();
165 
166  void emitPrintf(const Module &Mod);
167 
168  void emitKernelLanguage(const Function &Func);
169 
170  void emitKernelAttrs(const Function &Func);
171 
172  void emitKernelArgs(const Function &Func);
173 
174  void emitKernelArg(const Argument &Arg);
175 
176  void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
178  StringRef Name = "", StringRef TypeName = "",
179  StringRef BaseTypeName = "", StringRef AccQual = "",
180  StringRef TypeQual = "");
181 
182  void emitHiddenKernelArgs(const Function &Func);
183 
184  const Metadata &getHSAMetadata() const {
185  return HSAMetadata;
186  }
187 
188 public:
189  MetadataStreamerV2() = default;
190  ~MetadataStreamerV2() = default;
191 
192  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
193 
194  void begin(const Module &Mod,
195  const IsaInfo::AMDGPUTargetID &TargetID) override;
196 
197  void end() override;
198 
199  void emitKernel(const MachineFunction &MF,
200  const SIProgramInfo &ProgramInfo) override;
201 };
202 
203 } // end namespace HSAMD
204 } // end namespace AMDGPU
205 } // end namespace llvm
206 
207 #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:4550
llvm::AMDGPU::HSAMD::Kernel::DebugProps::Metadata
In-memory representation of kernel debug properties metadata.
Definition: AMDGPUMetadata.h:341
llvm
Definition: AllocatorList.h:23
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernel
void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) override
Definition: AMDGPUHSAMetadataStreamer.cpp:903
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::Function
Definition: Function.h:61
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:56
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:46
llvm::AMDGPU::HSAMD::MetadataStreamerV3
Definition: AMDGPUHSAMetadataStreamer.h:54
llvm::Optional
Definition: APInt.h:33
llvm::AMDGPU::HSAMD::MetadataStreamer::~MetadataStreamer
virtual ~MetadataStreamer()
Definition: AMDGPUHSAMetadataStreamer.h:40
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:670
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:942
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:205
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:885
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:119
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:788
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:100
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:897
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernelArg
void emitKernelArg(const Argument &Arg, unsigned &Offset, msgpack::ArrayDocNode Args)
Definition: AMDGPUHSAMetadataStreamer.cpp:682
llvm::MachineFunction
Definition: MachineFunction.h:227
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::ModRefInfo::Mod
@ Mod
The access may modify the value stored in memory.
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitTo
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override
Definition: AMDGPUHSAMetadataStreamer.cpp:881
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::AMDGPUTargetStreamer
Definition: AMDGPUTargetStreamer.h:39
Node
Definition: ItaniumDemangle.h:114
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:892
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:850
llvm::AMDGPU::HSAMD::MetadataStreamerV2
Definition: AMDGPUHSAMetadataStreamer.h:138
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:38
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
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getHSAMetadataRoot
msgpack::DocNode & getHSAMetadataRoot()
Definition: AMDGPUHSAMetadataStreamer.h:104
llvm::AMDGPU::HSAMD::MetadataStreamerV4
Definition: AMDGPUHSAMetadataStreamer.h:124
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::AMDGPU::HSAMD::MetadataStreamer::emitTo
virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer)=0
AMDGPUBaseInfo.h