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 class GCNSubtarget;
34 
35 namespace AMDGPU {
36 
37 namespace IsaInfo {
38 class AMDGPUTargetID;
39 }
40 
41 namespace HSAMD {
42 
44 public:
45  virtual ~MetadataStreamer(){};
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 
58 // TODO: Rename MetadataStreamerV3 -> MetadataStreamerMsgPackV3.
60 protected:
61  std::unique_ptr<msgpack::Document> HSAMetadataDoc =
62  std::make_unique<msgpack::Document>();
63 
64  void dump(StringRef HSAMetadataString) const;
65 
66  void verify(StringRef HSAMetadataString) const;
67 
69 
71 
72  StringRef getValueKind(Type *Ty, StringRef TypeQual,
73  StringRef BaseTypeName) const;
74 
75  std::string getTypeName(Type *Ty, bool Signed) const;
76 
78 
80  const SIProgramInfo &ProgramInfo) const;
81 
82  void emitVersion();
83 
84  void emitPrintf(const Module &Mod);
85 
86  void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
87 
88  void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern);
89 
90  void emitKernelArgs(const Function &Func, const GCNSubtarget &ST,
91  msgpack::MapDocNode Kern);
92 
93  void emitKernelArg(const Argument &Arg, unsigned &Offset,
95 
96  void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
97  StringRef ValueKind, unsigned &Offset,
99  StringRef Name = "", StringRef TypeName = "",
100  StringRef BaseTypeName = "", StringRef AccQual = "",
101  StringRef TypeQual = "");
102 
103  void emitHiddenKernelArgs(const Function &Func, const GCNSubtarget &ST,
104  unsigned &Offset, msgpack::ArrayDocNode Args);
105 
107  return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
108  }
109 
111  return HSAMetadataDoc->getRoot();
112  }
113 
114 public:
115  MetadataStreamerV3() = default;
116  ~MetadataStreamerV3() = default;
117 
118  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
119 
120  void begin(const Module &Mod,
121  const IsaInfo::AMDGPUTargetID &TargetID) override;
122 
123  void end() override;
124 
125  void emitKernel(const MachineFunction &MF,
126  const SIProgramInfo &ProgramInfo) override;
127 };
128 
129 // TODO: Rename MetadataStreamerV4 -> MetadataStreamerMsgPackV4.
131  void emitVersion();
132 
133  void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID);
134 
135 public:
136  MetadataStreamerV4() = default;
137  ~MetadataStreamerV4() = default;
138 
139  void begin(const Module &Mod,
140  const IsaInfo::AMDGPUTargetID &TargetID) override;
141 };
142 
143 // TODO: Rename MetadataStreamerV2 -> MetadataStreamerYamlV2.
144 class MetadataStreamerV2 final : public MetadataStreamer {
145 private:
146  Metadata HSAMetadata;
147 
148  void dump(StringRef HSAMetadataString) const;
149 
150  void verify(StringRef HSAMetadataString) const;
151 
152  AccessQualifier getAccessQualifier(StringRef AccQual) const;
153 
154  AddressSpaceQualifier getAddressSpaceQualifier(unsigned AddressSpace) const;
155 
156  ValueKind getValueKind(Type *Ty, StringRef TypeQual,
157  StringRef BaseTypeName) const;
158 
159  std::string getTypeName(Type *Ty, bool Signed) const;
160 
161  std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
162 
163  Kernel::CodeProps::Metadata getHSACodeProps(
164  const MachineFunction &MF,
165  const SIProgramInfo &ProgramInfo) const;
166  Kernel::DebugProps::Metadata getHSADebugProps(
167  const MachineFunction &MF,
168  const SIProgramInfo &ProgramInfo) const;
169 
170  void emitVersion();
171 
172  void emitPrintf(const Module &Mod);
173 
174  void emitKernelLanguage(const Function &Func);
175 
176  void emitKernelAttrs(const Function &Func);
177 
178  void emitKernelArgs(const Function &Func, const GCNSubtarget &ST);
179 
180  void emitKernelArg(const Argument &Arg);
181 
182  void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
184  StringRef Name = "", StringRef TypeName = "",
185  StringRef BaseTypeName = "", StringRef AccQual = "",
186  StringRef TypeQual = "");
187 
188  void emitHiddenKernelArgs(const Function &Func, const GCNSubtarget &ST);
189 
190  const Metadata &getHSAMetadata() const {
191  return HSAMetadata;
192  }
193 
194 public:
195  MetadataStreamerV2() = default;
196  ~MetadataStreamerV2() = default;
197 
198  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
199 
200  void begin(const Module &Mod,
201  const IsaInfo::AMDGPUTargetID &TargetID) override;
202 
203  void end() override;
204 
205  void emitKernel(const MachineFunction &MF,
206  const SIProgramInfo &ProgramInfo) override;
207 };
208 
209 } // end namespace HSAMD
210 } // end namespace AMDGPU
211 } // end namespace llvm
212 
213 #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:4631
llvm::AMDGPU::HSAMD::Kernel::DebugProps::Metadata
In-memory representation of kernel debug properties metadata.
Definition: AMDGPUMetadata.h:341
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernel
void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) override
Definition: AMDGPUHSAMetadataStreamer.cpp:912
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernelArgs
void emitKernelArgs(const Function &Func, const GCNSubtarget &ST, msgpack::MapDocNode Kern)
Definition: AMDGPUHSAMetadataStreamer.cpp:676
llvm::Function
Definition: Function.h:62
llvm::AMDGPU::HSAMD::MetadataStreamerV2::end
void end() override
Definition: AMDGPUHSAMetadataStreamer.cpp:445
llvm::AMDGPU::HSAMD::MetadataStreamerV3::~MetadataStreamerV3
~MetadataStreamerV3()=default
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitHiddenKernelArgs
void emitHiddenKernelArgs(const Function &Func, const GCNSubtarget &ST, unsigned &Offset, msgpack::ArrayDocNode Args)
Definition: AMDGPUHSAMetadataStreamer.cpp:795
llvm::AMDGPU::HSAMD::MetadataStreamerV3::HSAMetadataDoc
std::unique_ptr< msgpack::Document > HSAMetadataDoc
Definition: AMDGPUHSAMetadataStreamer.h:61
llvm::AMDGPU::HSAMD::MetadataStreamerV3::dump
void dump(StringRef HSAMetadataString) const
Definition: AMDGPUHSAMetadataStreamer.cpp:482
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:59
llvm::Optional
Definition: APInt.h:33
llvm::AMDGPU::HSAMD::MetadataStreamer::~MetadataStreamer
virtual ~MetadataStreamer()
Definition: AMDGPUHSAMetadataStreamer.h:45
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
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:601
llvm::AMDGPU::HSAMD::MetadataStreamerV4::begin
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
Definition: AMDGPUHSAMetadataStreamer.cpp:952
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:632
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:894
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:517
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:486
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:106
llvm::msgpack::MapDocNode
A DocNode that is a map.
Definition: MsgPackDocument.h:219
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
MsgPackDocument.h
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitKernelAttrs
void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern)
Definition: AMDGPUHSAMetadataStreamer.cpp:651
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:689
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitTo
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override
Definition: AMDGPUHSAMetadataStreamer.cpp:890
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:619
llvm::AMDGPU::HSAMD::MetadataStreamerV3::end
void end() override
Definition: AMDGPUHSAMetadataStreamer.cpp:901
llvm::AMDGPU::HSAMD::MetadataStreamerV2::emitTo
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override
Definition: AMDGPUHSAMetadataStreamer.cpp:435
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:857
llvm::AMDGPU::HSAMD::MetadataStreamerV2
Definition: AMDGPUHSAMetadataStreamer.h:144
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getValueKind
StringRef getValueKind(Type *Ty, StringRef TypeQual, StringRef BaseTypeName) const
Definition: AMDGPUHSAMetadataStreamer.cpp:536
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:563
llvm::AMDGPU::HSAMD::MetadataStreamerV2::begin
void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
Definition: AMDGPUHSAMetadataStreamer.cpp:439
llvm::AMDGPU::HSAMD::MetadataStreamerV3::getAccessQualifier
Optional< StringRef > getAccessQualifier(StringRef AccQual) const
Definition: AMDGPUHSAMetadataStreamer.cpp:508
llvm::AMDGPU::HSAMD::MetadataStreamerV3::emitVersion
void emitVersion()
Definition: AMDGPUHSAMetadataStreamer.cpp:612
llvm::AMDGPU::HSAMD::MetadataStreamerV2::emitKernel
void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) override
Definition: AMDGPUHSAMetadataStreamer.cpp:456
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:110
llvm::AMDGPU::HSAMD::MetadataStreamerV4
Definition: AMDGPUHSAMetadataStreamer.h:130
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::AMDGPU::HSAMD::MetadataStreamer::emitTo
virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer)=0