LLVM  15.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 
20 struct amd_kernel_code_t;
21 
22 namespace llvm {
23 
24 class AMDGPUMachineFunction;
25 struct AMDGPUResourceUsageAnalysis;
26 class AMDGPUTargetStreamer;
27 class MCCodeEmitter;
28 class MCOperand;
29 
30 namespace AMDGPU {
31 namespace HSAMD {
32 class MetadataStreamer;
33 }
34 } // namespace AMDGPU
35 
36 namespace amdhsa {
37 struct kernel_descriptor_t;
38 }
39 
40 class AMDGPUAsmPrinter final : public AsmPrinter {
41 private:
42  void initializeTargetID(const Module &M);
43 
44  AMDGPUResourceUsageAnalysis *ResourceUsage;
45 
46  SIProgramInfo CurrentProgramInfo;
47 
48  std::unique_ptr<AMDGPU::HSAMD::MetadataStreamer> HSAMetadataStream;
49 
50  MCCodeEmitter *DumpCodeInstEmitter = nullptr;
51 
52  uint64_t getFunctionCodeSize(const MachineFunction &MF) const;
53 
54  void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF);
55  void getAmdKernelCode(amd_kernel_code_t &Out, const SIProgramInfo &KernelInfo,
56  const MachineFunction &MF) const;
57 
58  /// Emit register usage information so that the GPU driver
59  /// can correctly setup the GPU state.
60  void EmitProgramInfoSI(const MachineFunction &MF,
61  const SIProgramInfo &KernelInfo);
62  void EmitPALMetadata(const MachineFunction &MF,
63  const SIProgramInfo &KernelInfo);
64  void emitPALFunctionMetadata(const MachineFunction &MF);
65  void emitCommonFunctionComments(uint32_t NumVGPR,
66  Optional<uint32_t> NumAGPR,
67  uint32_t TotalNumVGPR,
68  uint32_t NumSGPR,
69  uint64_t ScratchSize,
70  uint64_t CodeSize,
71  const AMDGPUMachineFunction* MFI);
72 
73  uint16_t getAmdhsaKernelCodeProperties(
74  const MachineFunction &MF) const;
75 
76  amdhsa::kernel_descriptor_t getAmdhsaKernelDescriptor(
77  const MachineFunction &MF,
78  const SIProgramInfo &PI) const;
79 
80  void initTargetStreamer(Module &M);
81 
82 public:
84  std::unique_ptr<MCStreamer> Streamer);
85 
86  StringRef getPassName() const override;
87 
88  const MCSubtargetInfo* getGlobalSTI() const;
89 
91 
92  bool doFinalization(Module &M) override;
93  bool runOnMachineFunction(MachineFunction &MF) override;
94 
95  /// Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated
96  /// pseudo lowering.
97  bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
98 
99  /// Lower the specified LLVM Constant to an MCExpr.
100  /// The AsmPrinter::lowerConstantof does not know how to lower
101  /// addrspacecast, therefore they should be lowered by this function.
102  const MCExpr *lowerConstant(const Constant *CV) override;
103 
104  /// tblgen'erated driver function for lowering simple MI->MC pseudo
105  /// instructions.
107  const MachineInstr *MI);
108 
109  /// Implemented in AMDGPUMCInstLower.cpp
110  void emitInstruction(const MachineInstr *MI) override;
111 
112  void emitFunctionBodyStart() override;
113 
114  void emitFunctionBodyEnd() override;
115 
116  void emitFunctionEntryLabel() override;
117 
118  void emitBasicBlockStart(const MachineBasicBlock &MBB) override;
119 
120  void emitGlobalVariable(const GlobalVariable *GV) override;
121 
122  void emitStartOfAsmFile(Module &M) override;
123 
124  void emitEndOfAsmFile(Module &M) override;
125 
127  const MachineBasicBlock *MBB) const override;
128 
129  bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
130  const char *ExtraCode, raw_ostream &O) override;
131 
132 protected:
133  void getAnalysisUsage(AnalysisUsage &AU) const override;
134 
135  std::vector<std::string> DisasmLines, HexLines;
138 };
139 
140 } // end namespace llvm
141 
142 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
llvm::AMDGPUAsmPrinter::emitBasicBlockStart
void emitBasicBlockStart(const MachineBasicBlock &MBB) override
Targets can override this to emit stuff at the start of a basic block.
Definition: AMDGPUAsmPrinter.cpp:300
AsmPrinter.h
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:104
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::AMDGPUAsmPrinter::AMDGPUAsmPrinter
AMDGPUAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
Definition: AMDGPUAsmPrinter.cpp:86
llvm::AMDGPUAsmPrinter::emitFunctionBodyStart
void emitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
Definition: AMDGPUAsmPrinter.cpp:191
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::AMDGPUAsmPrinter::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
Definition: AMDGPUAsmPrinter.cpp:1178
llvm::AMDGPUAsmPrinter::isBlockOnlyReachableByFallthrough
bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const override
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
Definition: AMDGPUAsmPrinter.cpp:177
llvm::Optional< uint32_t >
llvm::AMDGPUAsmPrinter
Definition: AMDGPUAsmPrinter.h:40
llvm::AMDGPUAsmPrinter::lowerOperand
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const
Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated pseudo lowering.
Definition: AMDGPUMCInstLower.cpp:160
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:212
llvm::AMDGPUAsmPrinter::emitInstruction
void emitInstruction(const MachineInstr *MI) override
Implemented in AMDGPUMCInstLower.cpp.
Definition: AMDGPUMCInstLower.cpp:173
llvm::AsmPrinter::OutStreamer
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:97
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:48
AMDGPU
Definition: AMDGPUReplaceLDSUseWithPointer.cpp:114
llvm::AMDGPUAsmPrinter::IsTargetStreamerInitialized
bool IsTargetStreamerInitialized
Definition: AMDGPUAsmPrinter.h:137
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
SIProgramInfo.h
llvm::AMDGPUAsmPrinter::PrintAsmOperand
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.
Definition: AMDGPUAsmPrinter.cpp:1138
llvm::AMDGPUAsmPrinter::emitStartOfAsmFile
void emitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
Definition: AMDGPUAsmPrinter.cpp:116
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:240
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:66
uint64_t
llvm::AMDGPUAsmPrinter::emitEndOfAsmFile
void emitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
Definition: AMDGPUAsmPrinter.cpp:154
llvm::AMDGPUAsmPrinter::getTargetStreamer
AMDGPUTargetStreamer * getTargetStreamer() const
Definition: AMDGPUAsmPrinter.cpp:110
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
llvm::AMDGPUAsmPrinter::DisasmLines
std::vector< std::string > DisasmLines
Definition: AMDGPUAsmPrinter.h:135
llvm::AMDGPUAsmPrinter::getGlobalSTI
const MCSubtargetInfo * getGlobalSTI() const
Definition: AMDGPUAsmPrinter.cpp:106
llvm::AsmPrinter::MF
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:100
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::AMDGPUAsmPrinter::lowerConstant
const MCExpr * lowerConstant(const Constant *CV) override
Lower the specified LLVM Constant to an MCExpr.
Definition: AMDGPUMCInstLower.cpp:167
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AMDGPUAsmPrinter::emitFunctionBodyEnd
void emitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
Definition: AMDGPUAsmPrinter.cpp:236
uint32_t
llvm::AMDGPUTargetStreamer
Definition: AMDGPUTargetStreamer.h:34
amd_kernel_code_t
AMD Kernel Code Object (amd_kernel_code_t).
Definition: AMDKernelCodeT.h:526
llvm::AMDGPUAsmPrinter::DisasmLineMaxLen
size_t DisasmLineMaxLen
Definition: AMDGPUAsmPrinter.h:136
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
uint16_t
llvm::MCCodeEmitter
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:21
llvm::amdhsa::kernel_descriptor_t
Definition: AMDHSAKernelDescriptor.h:169
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:82
llvm::AMDGPUAsmPrinter::getPassName
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: AMDGPUAsmPrinter.cpp:102
llvm::AMDGPUAsmPrinter::doFinalization
bool doFinalization(Module &M) override
Shut down the asmprinter.
Definition: AMDGPUAsmPrinter.cpp:347
llvm::SIProgramInfo
Track resource usage for kernels / entry functions.
Definition: SIProgramInfo.h:25
llvm::AMDGPUAsmPrinter::emitPseudoExpansionLowering
bool emitPseudoExpansionLowering(MCStreamer &OutStreamer, const MachineInstr *MI)
tblgen'erated driver function for lowering simple MI->MC pseudo instructions.
llvm::AsmPrinter::TM
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:85
llvm::AMDGPUResourceUsageAnalysis
Definition: AMDGPUResourceUsageAnalysis.h:27
llvm::AMDGPUAsmPrinter::emitFunctionEntryLabel
void emitFunctionEntryLabel() override
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
Definition: AMDGPUAsmPrinter.cpp:275
llvm::MCOperand
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
llvm::AMDGPUAsmPrinter::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: AMDGPUAsmPrinter.cpp:452
llvm::AMDGPUAsmPrinter::HexLines
std::vector< std::string > HexLines
Definition: AMDGPUAsmPrinter.h:135
llvm::AMDGPUMachineFunction
Definition: AMDGPUMachineFunction.h:22
llvm::AMDGPUAsmPrinter::emitGlobalVariable
void emitGlobalVariable(const GlobalVariable *GV) override
Emit the specified global variable to the .s file.
Definition: AMDGPUAsmPrinter.cpp:312
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:76
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35