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 "llvm/CodeGen/AsmPrinter.h"
23 class AMDGPUAsmPrinter final : public AsmPrinter {
25 struct SIProgramInfo {
45 DebuggerWavefrontPrivateSegmentOffsetSGPR((uint16_t)-1),
46 DebuggerPrivateSegmentBufferSGPR((uint16_t)-1),
50 // Fields set in PGM_RSRC1 pm4 packet.
61 uint64_t ComputePGMRSrc1;
63 // Fields set in PGM_RSRC2 pm4 packet.
65 uint32_t ScratchBlocks;
67 uint64_t ComputePGMRSrc2;
74 // If ReservedVGPRCount is 0 then must be 0. Otherwise, this is the first
75 // fixed VGPR number reserved.
76 uint16_t ReservedVGPRFirst;
77 // The number of consecutive VGPRs reserved.
78 uint16_t ReservedVGPRCount;
80 // Fixed SGPR number used to hold wave scratch offset for entire kernel
81 // execution, or uint16_t(-1) if the register is not used or not known.
82 uint16_t DebuggerWavefrontPrivateSegmentOffsetSGPR;
83 // Fixed SGPR number of the first 4 SGPRs used to hold scratch V# for entire
84 // kernel execution, or uint16_t(-1) if the register is not used or not
86 uint16_t DebuggerPrivateSegmentBufferSGPR;
88 // Bonus information for debugging.
93 void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF) const;
94 void findNumUsedRegistersSI(const MachineFunction &MF,
96 unsigned &NumVGPR) const;
98 /// \brief Emit register usage information so that the GPU driver
99 /// can correctly setup the GPU state.
100 void EmitProgramInfoR600(const MachineFunction &MF);
101 void EmitProgramInfoSI(const MachineFunction &MF, const SIProgramInfo &KernelInfo);
102 void EmitAmdKernelCodeT(const MachineFunction &MF,
103 const SIProgramInfo &KernelInfo) const;
106 explicit AMDGPUAsmPrinter(TargetMachine &TM,
107 std::unique_ptr<MCStreamer> Streamer);
109 bool runOnMachineFunction(MachineFunction &MF) override;
111 const char *getPassName() const override {
112 return "AMDGPU Assembly Printer";
115 /// Implemented in AMDGPUMCInstLower.cpp
116 void EmitInstruction(const MachineInstr *MI) override;
118 void EmitFunctionBodyStart() override;
120 void EmitFunctionEntryLabel() override;
122 void EmitGlobalVariable(const GlobalVariable *GV) override;
124 void EmitStartOfAsmFile(Module &M) override;
126 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
127 unsigned AsmVariant, const char *ExtraCode,
128 raw_ostream &O) override;
130 void emitStartOfRuntimeMetadata(const Module &M);
132 void emitRuntimeMetadata(const Function &F);
135 std::vector<std::string> DisasmLines, HexLines;
136 size_t DisasmLineMaxLen;
139 } // End anonymous llvm