1 //===-- AMDGPUAsmPrinter.h - Print AMDGPU assembly code ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief AMDGPU Assembly printer class.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
16 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
18 #include "AMDKernelCodeT.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/CodeGen/AsmPrinter.h"
31 class AMDGPUTargetStreamer;
34 class AMDGPUAsmPrinter final : public AsmPrinter {
36 struct SIProgramInfo {
37 // Fields set in PGM_RSRC1 pm4 packet.
38 uint32_t VGPRBlocks = 0;
39 uint32_t SGPRBlocks = 0;
40 uint32_t Priority = 0;
41 uint32_t FloatMode = 0;
43 uint32_t DX10Clamp = 0;
44 uint32_t DebugMode = 0;
45 uint32_t IEEEMode = 0;
46 uint32_t ScratchSize = 0;
48 uint64_t ComputePGMRSrc1 = 0;
50 // Fields set in PGM_RSRC2 pm4 packet.
51 uint32_t LDSBlocks = 0;
52 uint32_t ScratchBlocks = 0;
54 uint64_t ComputePGMRSrc2 = 0;
59 bool FlatUsed = false;
61 // Number of SGPRs that meets number of waves per execution unit request.
62 uint32_t NumSGPRsForWavesPerEU = 0;
64 // Number of VGPRs that meets number of waves per execution unit request.
65 uint32_t NumVGPRsForWavesPerEU = 0;
67 // If ReservedVGPRCount is 0 then must be 0. Otherwise, this is the first
68 // fixed VGPR number reserved.
69 uint16_t ReservedVGPRFirst = 0;
71 // The number of consecutive VGPRs reserved.
72 uint16_t ReservedVGPRCount = 0;
74 // Fixed SGPR number used to hold wave scratch offset for entire kernel
75 // execution, or std::numeric_limits<uint16_t>::max() if the register is not
77 uint16_t DebuggerWavefrontPrivateSegmentOffsetSGPR =
78 std::numeric_limits<uint16_t>::max();
80 // Fixed SGPR number of the first 4 SGPRs used to hold scratch V# for entire
81 // kernel execution, or std::numeric_limits<uint16_t>::max() if the register
82 // is not used or not known.
83 uint16_t DebuggerPrivateSegmentBufferSGPR =
84 std::numeric_limits<uint16_t>::max();
86 // Bonus information for debugging.
89 SIProgramInfo() = default;
92 uint64_t getFunctionCodeSize(const MachineFunction &MF) const;
93 void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF) const;
94 void getAmdKernelCode(amd_kernel_code_t &Out, const SIProgramInfo &KernelInfo,
95 const MachineFunction &MF) const;
96 void findNumUsedRegistersSI(const MachineFunction &MF,
98 unsigned &NumVGPR) const;
100 /// \brief Emit register usage information so that the GPU driver
101 /// can correctly setup the GPU state.
102 void EmitProgramInfoR600(const MachineFunction &MF);
103 void EmitProgramInfoSI(const MachineFunction &MF, const SIProgramInfo &KernelInfo);
106 explicit AMDGPUAsmPrinter(TargetMachine &TM,
107 std::unique_ptr<MCStreamer> Streamer);
109 StringRef getPassName() const override;
111 const MCSubtargetInfo* getSTI() const;
113 AMDGPUTargetStreamer& getTargetStreamer() const;
115 bool runOnMachineFunction(MachineFunction &MF) override;
117 /// \brief Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated
119 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
121 /// \brief Lower the specified LLVM Constant to an MCExpr.
122 /// The AsmPrinter::lowerConstantof does not know how to lower
123 /// addrspacecast, therefore they should be lowered by this function.
124 const MCExpr *lowerConstant(const Constant *CV) override;
126 /// \brief tblgen'erated driver function for lowering simple MI->MC pseudo
128 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
129 const MachineInstr *MI);
131 /// Implemented in AMDGPUMCInstLower.cpp
132 void EmitInstruction(const MachineInstr *MI) override;
134 void EmitFunctionBodyStart() override;
136 void EmitFunctionEntryLabel() override;
138 void EmitGlobalVariable(const GlobalVariable *GV) override;
140 void EmitStartOfAsmFile(Module &M) override;
142 void EmitEndOfAsmFile(Module &M) override;
144 bool isBlockOnlyReachableByFallthrough(
145 const MachineBasicBlock *MBB) const override;
147 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
148 unsigned AsmVariant, const char *ExtraCode,
149 raw_ostream &O) override;
152 std::vector<std::string> DisasmLines, HexLines;
153 size_t DisasmLineMaxLen;
157 } // end namespace llvm
159 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H