LLVM 22.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
39namespace IsaInfo {
40class AMDGPUTargetID;
41}
42
43namespace HSAMD {
44
46public:
47 virtual ~MetadataStreamer() = default;
48
49 virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
50
51 virtual void begin(const Module &Mod,
52 const IsaInfo::AMDGPUTargetID &TargetID) = 0;
53
54 virtual void end() = 0;
55
56 virtual void emitKernel(const MachineFunction &MF,
57 const SIProgramInfo &ProgramInfo) = 0;
58
59protected:
60 virtual void emitVersion() = 0;
61 virtual void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
62 msgpack::ArrayDocNode Args) = 0;
63 virtual void emitKernelAttrs(const AMDGPUTargetMachine &TM,
64 const MachineFunction &MF,
65 msgpack::MapDocNode Kern) = 0;
66};
67
69 : public MetadataStreamer {
70protected:
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 IsaInfo::AMDGPUTargetID &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
129 return HSAMetadataDoc->getRoot();
130 }
131
132public:
135
136 bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
137
138 void begin(const Module &Mod,
139 const IsaInfo::AMDGPUTargetID &TargetID) override;
140
141 void end() override;
142
143 void emitKernel(const MachineFunction &MF,
144 const SIProgramInfo &ProgramInfo) override;
145};
146
148protected:
149 void emitVersion() override;
150 void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
151 msgpack::ArrayDocNode Args) override;
152 void emitKernelAttrs(const AMDGPUTargetMachine &TM, const MachineFunction &MF,
153 msgpack::MapDocNode Kern) override;
154
155public:
158};
159
161protected:
162 void emitVersion() override;
163
164public:
167
168 void emitKernelAttrs(const AMDGPUTargetMachine &TM, const MachineFunction &MF,
169 msgpack::MapDocNode Kern) override;
170};
171
172} // end namespace HSAMD
173} // end namespace AMDGPU
174} // end namespace llvm
175
176#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 begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID) override
void emitKernelArg(const Argument &Arg, unsigned &Offset, msgpack::ArrayDocNode Args)
void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID)
void emitKernelAttrs(const AMDGPUTargetMachine &TM, const MachineFunction &MF, msgpack::MapDocNode Kern) 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 IsaInfo::AMDGPUTargetID &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:63
Metadata node.
Definition Metadata.h:1077
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
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:477
@ 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:117
Track resource usage for kernels / entry functions.