LLVM 23.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
23
24namespace llvm {
25
28class Argument;
29class DataLayout;
30class Function;
31class MachineFunction;
32class MDNode;
33class Module;
34struct SIProgramInfo;
35class Type;
36
37namespace AMDGPU {
38
39class TargetID;
40
41namespace HSAMD {
42
44public:
45 virtual ~MetadataStreamer() = default;
46
47 virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
48
49 virtual void begin(const Module &Mod, const TargetID &TargetID) = 0;
50
51 virtual void end() = 0;
52
53 virtual void emitKernel(const MachineFunction &MF,
54 const SIProgramInfo &ProgramInfo) = 0;
55
56protected:
57 virtual void emitVersion() = 0;
58 virtual void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
59 msgpack::ArrayDocNode Args) = 0;
60 virtual void emitKernelAttrs(const AMDGPUTargetMachine &TM,
61 const MachineFunction &MF,
62 msgpack::MapDocNode Kern) = 0;
63};
64
66 : public MetadataStreamer {
67protected:
68 std::unique_ptr<DelayedMCExprs> DelayedExprs =
69 std::make_unique<DelayedMCExprs>();
70
71 std::unique_ptr<msgpack::Document> HSAMetadataDoc =
72 std::make_unique<msgpack::Document>();
73
74 void dump(StringRef HSAMetadataString) const;
75
76 void verify(StringRef HSAMetadataString) const;
77
78 std::optional<StringRef> getAccessQualifier(StringRef AccQual) const;
79
80 std::optional<StringRef>
82
84 StringRef BaseTypeName) const;
85
86 std::string getTypeName(Type *Ty, bool Signed) const;
87
89
91 const SIProgramInfo &ProgramInfo,
92 unsigned CodeObjectVersion) const;
93
94 void emitVersion() override;
95
96 void emitTargetID(const TargetID &TargetID);
97
98 void emitPrintf(const Module &Mod);
99
100 void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
101
102 void emitKernelAttrs(const AMDGPUTargetMachine &TM, const MachineFunction &MF,
103 msgpack::MapDocNode Kern) override;
104
106
107 void emitKernelArg(const Argument &Arg, unsigned &Offset,
109
110 void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
111 StringRef ValueKind, unsigned &Offset,
113 MaybeAlign PointeeAlign = std::nullopt,
114 StringRef Name = "", StringRef TypeName = "",
115 StringRef BaseTypeName = "", StringRef ActAccQual = "",
116 StringRef AccQual = "", StringRef TypeQual = "");
117
118 void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
119 msgpack::ArrayDocNode Args) override;
120
122 return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
123 }
124
126 return HSAMetadataDoc->getRoot();
127 }
128
129public:
131 ~MetadataStreamerMsgPackV4() override = default;
132
133 bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
134
135 void begin(const Module &Mod, const TargetID &TargetID) override;
136
137 void end() override;
138
139 void emitKernel(const MachineFunction &MF,
140 const SIProgramInfo &ProgramInfo) override;
141};
142
144protected:
145 void emitVersion() override;
146 void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
147 msgpack::ArrayDocNode Args) override;
148 void emitKernelAttrs(const AMDGPUTargetMachine &TM, const MachineFunction &MF,
149 msgpack::MapDocNode Kern) override;
150
151public:
153 ~MetadataStreamerMsgPackV5() override = default;
154};
155
157protected:
158 void emitVersion() override;
159
160public:
162 ~MetadataStreamerMsgPackV6() override = default;
163
164 void emitKernelAttrs(const AMDGPUTargetMachine &TM, const MachineFunction &MF,
165 msgpack::MapDocNode Kern) override;
166};
167
168} // end namespace HSAMD
169} // end namespace AMDGPU
170} // end namespace llvm
171
172#endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
AMDGPU metadata definitions and in-memory representations.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
static std::string getTypeName(OverloadKind Kind, Type *Ty)
This file declares a class that exposes a simple in-memory representation of a document of MsgPack ob...
ppc ctr loops verify
static void emitVersion(raw_ostream &OS)
std::optional< StringRef > getAddressSpaceQualifier(unsigned AddressSpace) const
msgpack::ArrayDocNode getWorkGroupDimensions(MDNode *Node) const
std::optional< StringRef > getAccessQualifier(StringRef AccQual) const
void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern)
msgpack::MapDocNode getHSAKernelProps(const MachineFunction &MF, const SIProgramInfo &ProgramInfo, unsigned CodeObjectVersion) const
std::unique_ptr< msgpack::Document > HSAMetadataDoc
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override
void emitKernelArgs(const MachineFunction &MF, msgpack::MapDocNode Kern)
void emitKernelArg(const Argument &Arg, unsigned &Offset, msgpack::ArrayDocNode Args)
void emitKernelAttrs(const AMDGPUTargetMachine &TM, const MachineFunction &MF, msgpack::MapDocNode Kern) override
void begin(const Module &Mod, const TargetID &TargetID) override
StringRef getValueKind(Type *Ty, StringRef TypeQual, StringRef BaseTypeName) const
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args) override
void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo) override
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args) override
void emitKernelAttrs(const AMDGPUTargetMachine &TM, const MachineFunction &MF, msgpack::MapDocNode Kern) override
void emitKernelAttrs(const AMDGPUTargetMachine &TM, const MachineFunction &MF, msgpack::MapDocNode Kern) override
virtual void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo)=0
virtual void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args)=0
virtual void emitKernelAttrs(const AMDGPUTargetMachine &TM, const MachineFunction &MF, msgpack::MapDocNode Kern)=0
virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer)=0
virtual void begin(const Module &Mod, const TargetID &TargetID)=0
This class represents an incoming formal argument to a Function.
Definition Argument.h:32
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Metadata node.
Definition Metadata.h:1069
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
A DocNode that is an array.
A node in a MsgPack Document.
A DocNode that is a map.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:558
@ Mod
The access may modify the value stored in memory.
Definition ModRef.h:34
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106
Track resource usage for kernels / entry functions.