LLVM 23.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
20#include "SIProgramInfo.h"
21#include "llvm/ADT/SetVector.h"
23
24namespace llvm {
25
29class MCCodeEmitter;
30class MCOperand;
31class MCResourceInfo;
32
33namespace AMDGPU {
36namespace HSAMD {
38}
39} // namespace AMDGPU
40
41class AMDGPUAsmPrinter final : public AsmPrinter {
42public:
43 static char ID;
44
45private:
46 unsigned CodeObjectVersion;
47 void initializeTargetID(const Module &M);
48
50 *ResourceUsage;
51
53
54 SIProgramInfo CurrentProgramInfo;
55
56 std::unique_ptr<AMDGPU::HSAMD::MetadataStreamer> HSAMetadataStream;
57
58 MCCodeEmitter *DumpCodeInstEmitter = nullptr;
59
60 // When appropriate, add a _dvgpr$ symbol.
61 void emitDVgprSymbol(MachineFunction &MF);
62
63 void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF);
64 void getAmdKernelCode(AMDGPU::AMDGPUMCKernelCodeT &Out,
66 const MachineFunction &MF) const;
67
68 /// Emit register usage information so that the GPU driver
69 /// can correctly setup the GPU state.
70 void EmitProgramInfoSI(const MachineFunction &MF,
72 void EmitPALMetadata(const MachineFunction &MF,
74 void emitPALFunctionMetadata(const MachineFunction &MF);
75 void emitCommonFunctionComments(const MCExpr *NumVGPR, const MCExpr *NumAGPR,
76 const MCExpr *TotalNumVGPR,
77 const MCExpr *NumSGPR,
78 const MCExpr *ScratchSize, uint64_t CodeSize,
79 const AMDGPUMachineFunctionInfo *MFI);
80 void emitResourceUsageRemarks(const MachineFunction &MF,
81 const SIProgramInfo &CurrentProgramInfo,
82 bool isModuleEntryFunction, bool hasMAIInsts);
83
84 const MCExpr *getAmdhsaKernelCodeProperties(const MachineFunction &MF) const;
85
87 getAmdhsaKernelDescriptor(const MachineFunction &MF,
88 const SIProgramInfo &PI) const;
89
90 void initTargetStreamer(Module &M);
91
92 void emitAMDGPUInfo(Module &M);
93 void collectCallEdge(const MachineInstr &MI);
94
96
98
99 SmallString<128> getMCExprStr(const MCExpr *Value);
100
101 /// Attempts to replace the validation that is missed in getSIProgramInfo due
102 /// to MCExpr being unknown. Invoked during doFinalization such that the
103 /// MCResourceInfo symbols are known.
104 void validateMCResourceInfo(Function &F);
105
106public:
108 std::unique_ptr<MCStreamer> Streamer);
109
110 StringRef getPassName() const override;
111
112 const MCSubtargetInfo* getGlobalSTI() const;
113
115
116 bool doInitialization(Module &M) override;
117 bool doFinalization(Module &M) override;
119
120 /// Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated
121 /// pseudo lowering.
122 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
123
124 /// Lower the specified LLVM Constant to an MCExpr.
125 /// The AsmPrinter::lowerConstantof does not know how to lower
126 /// addrspacecast, therefore they should be lowered by this function.
127 const MCExpr *lowerConstant(const Constant *CV, const Constant *BaseCV,
128 uint64_t Offset) override;
129
130 /// tblgen'erated driver function for lowering simple MI->MC pseudo
131 /// instructions.
133
134 /// Implemented in AMDGPUMCInstLower.cpp
135 void emitInstruction(const MachineInstr *MI) override;
136
137 void emitFunctionBodyStart() override;
138
139 void endFunction(const MachineFunction *MF);
140
141 void emitImplicitDef(const MachineInstr *MI) const override;
142
143 void emitFunctionEntryLabel() override;
144
145 void emitBasicBlockStart(const MachineBasicBlock &MBB) override;
146
147 void emitGlobalVariable(const GlobalVariable *GV) override;
148
149 void emitStartOfAsmFile(Module &M) override;
150
151 void emitEndOfAsmFile(Module &M) override;
152
153 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
154 const char *ExtraCode, raw_ostream &O) override;
155
156protected:
157 void getAnalysisUsage(AnalysisUsage &AU) const override;
158
159 std::vector<std::string> DisasmLines, HexLines;
162};
163
164} // end namespace llvm
165
166#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
MC infrastructure to propagate the function level resource usage info.
Analyzes how many registers and other resources are used by functions.
MachineBasicBlock & MBB
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition MD5.cpp:54
Defines struct to track resource usage and hardware flags for kernels and entry functions.
This file implements a set that has insertion order iteration characteristics.
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...
void endFunction(const MachineFunction *MF)
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
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
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
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
void emitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
AMDGPUAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
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.
TargetMachine & TM
Target machine description.
Definition AsmPrinter.h:94
MachineFunction * MF
The current machine function.
Definition AsmPrinter.h:109
AsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer, char &ID=AsmPrinter::ID)
This is an important base class in LLVM.
Definition Constant.h:43
MCCodeEmitter - Generic instruction encoding interface.
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.
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
A vector that has set insertion semantics.
Definition SetVector.h:57
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Primary interface to the complete machine description for the target machine.
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.
@ Offset
Definition DWP.cpp:557
AMDGPUResourceUsageAnalysisImpl::SIFunctionResourceInfo FunctionResourceInfo
Track resource usage for kernels / entry functions.