LLVM  14.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 public:
82  std::unique_ptr<MCStreamer> Streamer);
83 
84  StringRef getPassName() const override;
85 
86  const MCSubtargetInfo* getGlobalSTI() const;
87 
89 
90  bool doFinalization(Module &M) override;
91  bool runOnMachineFunction(MachineFunction &MF) override;
92 
93  /// Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated
94  /// pseudo lowering.
95  bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
96 
97  /// Lower the specified LLVM Constant to an MCExpr.
98  /// The AsmPrinter::lowerConstantof does not know how to lower
99  /// addrspacecast, therefore they should be lowered by this function.
100  const MCExpr *lowerConstant(const Constant *CV) override;
101 
102  /// tblgen'erated driver function for lowering simple MI->MC pseudo
103  /// instructions.
105  const MachineInstr *MI);
106 
107  /// Implemented in AMDGPUMCInstLower.cpp
108  void emitInstruction(const MachineInstr *MI) override;
109 
110  void emitFunctionBodyStart() override;
111 
112  void emitFunctionBodyEnd() override;
113 
114  void emitFunctionEntryLabel() override;
115 
116  void emitBasicBlockStart(const MachineBasicBlock &MBB) override;
117 
118  void emitGlobalVariable(const GlobalVariable *GV) override;
119 
120  void emitStartOfAsmFile(Module &M) override;
121 
122  void emitEndOfAsmFile(Module &M) override;
123 
125  const MachineBasicBlock *MBB) const override;
126 
127  bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
128  const char *ExtraCode, raw_ostream &O) override;
129 
130 protected:
131  void getAnalysisUsage(AnalysisUsage &AU) const override;
132 
133  std::vector<std::string> DisasmLines, HexLines;
135 };
136 
137 } // end namespace llvm
138 
139 #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:285
AsmPrinter.h
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
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:83
llvm::AMDGPUAsmPrinter::emitFunctionBodyStart
void emitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
Definition: AMDGPUAsmPrinter.cpp:176
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::AMDGPUAsmPrinter::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
Definition: AMDGPUAsmPrinter.cpp:1139
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:162
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:161
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
llvm::AMDGPUAsmPrinter::emitInstruction
void emitInstruction(const MachineInstr *MI) override
Implemented in AMDGPUMCInstLower.cpp.
Definition: AMDGPUMCInstLower.cpp:174
llvm::AsmPrinter::OutStreamer
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:96
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:49
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
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:1099
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:111
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:206
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
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:143
llvm::AMDGPUAsmPrinter::getTargetStreamer
AMDGPUTargetStreamer * getTargetStreamer() const
Definition: AMDGPUAsmPrinter.cpp:105
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:80
llvm::AMDGPUAsmPrinter::DisasmLines
std::vector< std::string > DisasmLines
Definition: AMDGPUAsmPrinter.h:133
llvm::AMDGPUAsmPrinter::getGlobalSTI
const MCSubtargetInfo * getGlobalSTI() const
Definition: AMDGPUAsmPrinter.cpp:101
llvm::AsmPrinter::MF
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:99
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::AMDGPUAsmPrinter::lowerConstant
const MCExpr * lowerConstant(const Constant *CV) override
Lower the specified LLVM Constant to an MCExpr.
Definition: AMDGPUMCInstLower.cpp:168
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::AMDGPUAsmPrinter::emitFunctionBodyEnd
void emitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
Definition: AMDGPUAsmPrinter.cpp:221
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:134
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:165
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:81
llvm::AMDGPUAsmPrinter::getPassName
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: AMDGPUAsmPrinter.cpp:97
llvm::AMDGPUAsmPrinter::doFinalization
bool doFinalization(Module &M) override
Shut down the asmprinter.
Definition: AMDGPUAsmPrinter.cpp:332
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:84
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:260
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:437
llvm::AMDGPUAsmPrinter::HexLines
std::vector< std::string > HexLines
Definition: AMDGPUAsmPrinter.h:133
llvm::AMDGPUMachineFunction
Definition: AMDGPUMachineFunction.h:20
llvm::AMDGPUAsmPrinter::emitGlobalVariable
void emitGlobalVariable(const GlobalVariable *GV) override
Emit the specified global variable to the .s file.
Definition: AMDGPUAsmPrinter.cpp:297
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35