LLVM 24.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
26struct AMDGPUOptions;
29class Argument;
30class DataLayout;
31class Function;
32class MachineFunction;
33class MDNode;
34class Module;
35struct SIProgramInfo;
36class Type;
37
38namespace AMDGPU {
39
40class TargetID;
41
42namespace HSAMD {
43
45public:
46 virtual ~MetadataStreamer() = default;
47
48 virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
49
50 virtual void begin(const Module &Mod, const TargetID &TargetID) = 0;
51
52 virtual void end() = 0;
53
54 virtual void emitKernel(const MachineFunction &MF,
55 const SIProgramInfo &ProgramInfo) = 0;
56
57protected:
58 virtual void emitVersion() = 0;
59 virtual void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
60 msgpack::ArrayDocNode Args) = 0;
61 virtual void emitKernelAttrs(const AMDGPUTargetMachine &TM,
62 const MachineFunction &MF,
63 msgpack::MapDocNode Kern) = 0;
64};
65
67 : public MetadataStreamer {
68protected:
69 const AMDGPUOptions &CLOpts;
70
71 std::unique_ptr<DelayedMCExprs> DelayedExprs =
72 std::make_unique<DelayedMCExprs>();
73
74 std::unique_ptr<msgpack::Document> HSAMetadataDoc =
75 std::make_unique<msgpack::Document>();
76
77 void dump(StringRef HSAMetadataString) const;
78
79 void verify(StringRef HSAMetadataString) const;
80
81 std::optional<StringRef> getAccessQualifier(StringRef AccQual) const;
82
83 std::optional<StringRef>
85
87 StringRef BaseTypeName) const;
88
89 std::string getTypeName(Type *Ty, bool Signed) const;
90
92
94 const SIProgramInfo &ProgramInfo,
95 unsigned CodeObjectVersion) const;
96
97 void emitVersion() override;
98
99 void emitTargetID(const TargetID &TargetID);
100
101 void emitPrintf(const Module &Mod);
102
103 void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
104
105 void emitKernelAttrs(const AMDGPUTargetMachine &TM, const MachineFunction &MF,
106 msgpack::MapDocNode Kern) override;
107
109
110 void emitKernelArg(const Argument &Arg, unsigned &Offset,
112
113 void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
114 StringRef ValueKind, unsigned &Offset,
116 MaybeAlign PointeeAlign = std::nullopt,
117 StringRef Name = "", StringRef TypeName = "",
118 StringRef BaseTypeName = "", StringRef ActAccQual = "",
119 StringRef AccQual = "", StringRef TypeQual = "");
120
121 void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
122 msgpack::ArrayDocNode Args) override;
123
125 return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
126 }
127
128public:
129 explicit MetadataStreamerMsgPackV4(const AMDGPUOptions &CLOpts)
130 : CLOpts(CLOpts) {}
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:
161 using MetadataStreamerMsgPackV5::MetadataStreamerMsgPackV5;
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:1081
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
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:577
@ 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:111
Track resource usage for kernels / entry functions.