LLVM 19.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
17#include "SIProgramInfo.h"
19
20namespace llvm {
21
22class AMDGPUMachineFunction;
23struct AMDGPUResourceUsageAnalysis;
24class AMDGPUTargetStreamer;
25class MCCodeEmitter;
26class MCOperand;
27
28namespace AMDGPU {
29struct MCKernelDescriptor;
30struct AMDGPUMCKernelCodeT;
31namespace HSAMD {
32class MetadataStreamer;
33}
34} // namespace AMDGPU
35
36class AMDGPUAsmPrinter final : public AsmPrinter {
37private:
38 unsigned CodeObjectVersion;
39 void initializeTargetID(const Module &M);
40
41 AMDGPUResourceUsageAnalysis *ResourceUsage;
42
43 SIProgramInfo CurrentProgramInfo;
44
45 std::unique_ptr<AMDGPU::HSAMD::MetadataStreamer> HSAMetadataStream;
46
47 MCCodeEmitter *DumpCodeInstEmitter = nullptr;
48
49 uint64_t getFunctionCodeSize(const MachineFunction &MF) const;
50
51 void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF);
52 void getAmdKernelCode(AMDGPU::AMDGPUMCKernelCodeT &Out,
54 const MachineFunction &MF) const;
55
56 /// Emit register usage information so that the GPU driver
57 /// can correctly setup the GPU state.
58 void EmitProgramInfoSI(const MachineFunction &MF,
60 void EmitPALMetadata(const MachineFunction &MF,
62 void emitPALFunctionMetadata(const MachineFunction &MF);
63 void emitCommonFunctionComments(uint32_t NumVGPR,
64 std::optional<uint32_t> NumAGPR,
65 uint32_t TotalNumVGPR, uint32_t NumSGPR,
66 uint64_t ScratchSize, uint64_t CodeSize,
67 const AMDGPUMachineFunction *MFI);
68 void emitCommonFunctionComments(const MCExpr *NumVGPR, const MCExpr *NumAGPR,
69 const MCExpr *TotalNumVGPR,
70 const MCExpr *NumSGPR,
71 const MCExpr *ScratchSize, uint64_t CodeSize,
72 const AMDGPUMachineFunction *MFI);
73 void emitResourceUsageRemarks(const MachineFunction &MF,
74 const SIProgramInfo &CurrentProgramInfo,
75 bool isModuleEntryFunction, bool hasMAIInsts);
76
77 const MCExpr *getAmdhsaKernelCodeProperties(const MachineFunction &MF) const;
78
80 getAmdhsaKernelDescriptor(const MachineFunction &MF,
81 const SIProgramInfo &PI) const;
82
83 void initTargetStreamer(Module &M);
84
85 SmallString<128> getMCExprStr(const MCExpr *Value);
86
87public:
89 std::unique_ptr<MCStreamer> Streamer);
90
91 StringRef getPassName() const override;
92
93 const MCSubtargetInfo* getGlobalSTI() const;
94
96
97 bool doInitialization(Module &M) override;
98 bool doFinalization(Module &M) override;
100
101 /// Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated
102 /// pseudo lowering.
103 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
104
105 /// Lower the specified LLVM Constant to an MCExpr.
106 /// The AsmPrinter::lowerConstantof does not know how to lower
107 /// addrspacecast, therefore they should be lowered by this function.
108 const MCExpr *lowerConstant(const Constant *CV) override;
109
110 /// tblgen'erated driver function for lowering simple MI->MC pseudo
111 /// instructions.
113 const MachineInstr *MI);
114
115 /// Implemented in AMDGPUMCInstLower.cpp
116 void emitInstruction(const MachineInstr *MI) override;
117
118 void emitFunctionBodyStart() override;
119
120 void emitFunctionBodyEnd() override;
121
122 void emitImplicitDef(const MachineInstr *MI) const override;
123
124 void emitFunctionEntryLabel() override;
125
126 void emitBasicBlockStart(const MachineBasicBlock &MBB) override;
127
128 void emitGlobalVariable(const GlobalVariable *GV) override;
129
130 void emitStartOfAsmFile(Module &M) override;
131
132 void emitEndOfAsmFile(Module &M) override;
133
134 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
135 const char *ExtraCode, raw_ostream &O) override;
136
137protected:
138 void getAnalysisUsage(AnalysisUsage &AU) const override;
139
140 std::vector<std::string> DisasmLines, HexLines;
143};
144
145} // end namespace llvm
146
147#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
MachineBasicBlock & MBB
IRTranslator LLVM IR MI
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
bool emitPseudoExpansionLowering(MCStreamer &OutStreamer, const MachineInstr *MI)
tblgen'erated driver function for lowering simple MI->MC pseudo instructions.
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.
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.
const MCExpr * lowerConstant(const Constant *CV) override
Lower the specified LLVM Constant to an MCExpr.
void emitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
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:85
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:88
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:103
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:100
This is an important base class in LLVM.
Definition: Constant.h:41
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:21
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
Streaming machine code generation interface.
Definition: MCStreamer.h:213
Generic base class for all target subtargets.
Representation of each machine instruction.
Definition: MachineInstr.h:69
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:65
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:50
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Track resource usage for kernels / entry functions.
Definition: SIProgramInfo.h:31