LLVM 22.0.0git
AMDGPUAsmPrinter.h
Go to the documentation of this file.
1//===-- AMDGPUAsmPrinter.h - Print AMDGPU assembly code ---------*- 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 Assembly printer class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
15#define LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
16
18#include "SIProgramInfo.h"
20
21namespace llvm {
22
23class AMDGPUMachineFunction;
24class AMDGPUResourceUsageAnalysis;
25class AMDGPUTargetStreamer;
26class MCCodeEmitter;
27class MCOperand;
28class MCResourceInfo;
29
30namespace AMDGPU {
31struct MCKernelDescriptor;
32struct AMDGPUMCKernelCodeT;
33namespace HSAMD {
34class MetadataStreamer;
35}
36} // namespace AMDGPU
37
38class AMDGPUAsmPrinter final : public AsmPrinter {
39public:
40 static char ID;
41
42private:
43 unsigned CodeObjectVersion;
44 void initializeTargetID(const Module &M);
45
47 *ResourceUsage;
48
50
51 SIProgramInfo CurrentProgramInfo;
52
53 std::unique_ptr<AMDGPU::HSAMD::MetadataStreamer> HSAMetadataStream;
54
55 MCCodeEmitter *DumpCodeInstEmitter = nullptr;
56
57 // When appropriate, add a _dvgpr$ symbol.
58 void emitDVgprSymbol(MachineFunction &MF);
59
60 void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF);
61 void getAmdKernelCode(AMDGPU::AMDGPUMCKernelCodeT &Out,
63 const MachineFunction &MF) const;
64
65 /// Emit register usage information so that the GPU driver
66 /// can correctly setup the GPU state.
67 void EmitProgramInfoSI(const MachineFunction &MF,
69 void EmitPALMetadata(const MachineFunction &MF,
71 void emitPALFunctionMetadata(const MachineFunction &MF);
72 void emitCommonFunctionComments(const MCExpr *NumVGPR, const MCExpr *NumAGPR,
73 const MCExpr *TotalNumVGPR,
74 const MCExpr *NumSGPR,
75 const MCExpr *ScratchSize, uint64_t CodeSize,
76 const AMDGPUMachineFunction *MFI);
77 void emitResourceUsageRemarks(const MachineFunction &MF,
78 const SIProgramInfo &CurrentProgramInfo,
79 bool isModuleEntryFunction, bool hasMAIInsts);
80
81 const MCExpr *getAmdhsaKernelCodeProperties(const MachineFunction &MF) const;
82
84 getAmdhsaKernelDescriptor(const MachineFunction &MF,
85 const SIProgramInfo &PI) const;
86
87 void initTargetStreamer(Module &M);
88
89 SmallString<128> getMCExprStr(const MCExpr *Value);
90
91 /// Attempts to replace the validation that is missed in getSIProgramInfo due
92 /// to MCExpr being unknown. Invoked during doFinalization such that the
93 /// MCResourceInfo symbols are known.
94 void validateMCResourceInfo(Function &F);
95
96public:
98 std::unique_ptr<MCStreamer> Streamer);
99
100 StringRef getPassName() const override;
101
102 const MCSubtargetInfo* getGlobalSTI() const;
103
105
106 bool doInitialization(Module &M) override;
107 bool doFinalization(Module &M) override;
109
110 /// Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated
111 /// pseudo lowering.
112 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
113
114 /// Lower the specified LLVM Constant to an MCExpr.
115 /// The AsmPrinter::lowerConstantof does not know how to lower
116 /// addrspacecast, therefore they should be lowered by this function.
117 const MCExpr *lowerConstant(const Constant *CV, const Constant *BaseCV,
118 uint64_t Offset) override;
119
120 /// tblgen'erated driver function for lowering simple MI->MC pseudo
121 /// instructions.
123
124 /// Implemented in AMDGPUMCInstLower.cpp
125 void emitInstruction(const MachineInstr *MI) override;
126
127 void emitFunctionBodyStart() override;
128
129 void emitFunctionBodyEnd() override;
130
131 void emitImplicitDef(const MachineInstr *MI) const override;
132
133 void emitFunctionEntryLabel() override;
134
135 void emitBasicBlockStart(const MachineBasicBlock &MBB) override;
136
137 void emitGlobalVariable(const GlobalVariable *GV) override;
138
139 void emitStartOfAsmFile(Module &M) override;
140
141 void emitEndOfAsmFile(Module &M) override;
142
143 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
144 const char *ExtraCode, raw_ostream &O) override;
145
146protected:
147 void getAnalysisUsage(AnalysisUsage &AU) const override;
148
149 std::vector<std::string> DisasmLines, HexLines;
152};
153
154} // end namespace llvm
155
156#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
MC infrastructure to propagate the function level resource usage info.
MachineBasicBlock & MBB
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
Defines struct to track resource usage and hardware flags for kernels and entry functions.
void emitFunctionEntryLabel() override
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
const MCSubtargetInfo * getGlobalSTI() const
void emitImplicitDef(const MachineInstr *MI) const override
Targets can override this to customize the output of IMPLICIT_DEF instructions in verbose mode.
std::vector< std::string > DisasmLines
void emitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
std::vector< std::string > HexLines
void emitGlobalVariable(const GlobalVariable *GV) override
Emit the specified global variable to the .s file.
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const
Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated pseudo lowering.
bool lowerPseudoInstExpansion(const MachineInstr *MI, MCInst &Inst)
tblgen'erated driver function for lowering simple MI->MC pseudo instructions.
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
void emitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
bool doFinalization(Module &M) override
Shut down the asmprinter.
void emitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
void emitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
const MCExpr * lowerConstant(const Constant *CV, const Constant *BaseCV, uint64_t Offset) override
Lower the specified LLVM Constant to an MCExpr.
void emitBasicBlockStart(const MachineBasicBlock &MBB) override
Targets can override this to emit stuff at the start of a basic block.
void emitInstruction(const MachineInstr *MI) override
Implemented in AMDGPUMCInstLower.cpp.
AMDGPUTargetStreamer * getTargetStreamer() const
Represent the analysis usage information of a pass.
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:90
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:93
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:108
This is an important base class in LLVM.
Definition: Constant.h:43
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:23
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:188
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:40
Generic base class for all target subtargets.
Representation of each machine instruction.
Definition: MachineInstr.h:72
MachineOperand class - Representation of each machine instruction operand.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:83
LLVM Value Representation.
Definition: Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
Track resource usage for kernels / entry functions.
Definition: SIProgramInfo.h:32