blob: 7b04c539520d507dfd8b0daa17c1d2c28a01479f [file] [log] [blame]
Matt Arsenaultd82c1832013-11-10 01:03:59 +00001//===-- AMDGPUAsmPrinter.h - Print AMDGPU assembly code ---------*- C++ -*-===//
Tom Stellard75aadc22012-12-11 21:25:42 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10/// \file
11/// \brief AMDGPU Assembly printer class.
12//
13//===----------------------------------------------------------------------===//
14
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000015#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
16#define LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
Tom Stellard75aadc22012-12-11 21:25:42 +000017
18#include "llvm/CodeGen/AsmPrinter.h"
Tom Stellarded699252013-10-12 05:02:51 +000019#include <vector>
Tom Stellard75aadc22012-12-11 21:25:42 +000020
21namespace llvm {
22
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000023class AMDGPUAsmPrinter final : public AsmPrinter {
Matt Arsenault89cc49f2013-12-05 05:15:35 +000024private:
25 struct SIProgramInfo {
Matt Arsenaulte500e322014-04-15 22:40:47 +000026 SIProgramInfo() :
Tom Stellard4df465b2014-12-02 21:28:53 +000027 VGPRBlocks(0),
28 SGPRBlocks(0),
Matt Arsenault0989d512014-06-26 17:22:30 +000029 Priority(0),
30 FloatMode(0),
31 Priv(0),
32 DX10Clamp(0),
33 DebugMode(0),
34 IEEEMode(0),
Tom Stellardb02094e2014-07-21 15:45:01 +000035 ScratchSize(0),
Tom Stellard4df465b2014-12-02 21:28:53 +000036 ComputePGMRSrc1(0),
37 LDSBlocks(0),
38 ScratchBlocks(0),
39 ComputePGMRSrc2(0),
40 NumVGPR(0),
41 NumSGPR(0),
Matt Arsenault3f981402014-09-15 15:41:53 +000042 FlatUsed(false),
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +000043 ReservedVGPRFirst(0),
44 ReservedVGPRCount(0),
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +000045 DebuggerWavefrontPrivateSegmentOffsetSGPR((uint16_t)-1),
46 DebuggerPrivateSegmentBufferSGPR((uint16_t)-1),
Matt Arsenault3f981402014-09-15 15:41:53 +000047 VCCUsed(false),
Matt Arsenault0989d512014-06-26 17:22:30 +000048 CodeLen(0) {}
Matt Arsenaulte500e322014-04-15 22:40:47 +000049
Matt Arsenault0989d512014-06-26 17:22:30 +000050 // Fields set in PGM_RSRC1 pm4 packet.
Tom Stellard4df465b2014-12-02 21:28:53 +000051 uint32_t VGPRBlocks;
52 uint32_t SGPRBlocks;
Matt Arsenault0989d512014-06-26 17:22:30 +000053 uint32_t Priority;
54 uint32_t FloatMode;
55 uint32_t Priv;
56 uint32_t DX10Clamp;
57 uint32_t DebugMode;
58 uint32_t IEEEMode;
Tom Stellardb02094e2014-07-21 15:45:01 +000059 uint32_t ScratchSize;
Matt Arsenault0989d512014-06-26 17:22:30 +000060
Tom Stellard4df465b2014-12-02 21:28:53 +000061 uint64_t ComputePGMRSrc1;
62
63 // Fields set in PGM_RSRC2 pm4 packet.
64 uint32_t LDSBlocks;
65 uint32_t ScratchBlocks;
66
67 uint64_t ComputePGMRSrc2;
68
69 uint32_t NumVGPR;
70 uint32_t NumSGPR;
71 uint32_t LDSSize;
Matt Arsenault3f981402014-09-15 15:41:53 +000072 bool FlatUsed;
73
Konstantin Zhuravlyov71515e52016-04-26 17:24:40 +000074 // If ReservedVGPRCount is 0 then must be 0. Otherwise, this is the first
75 // fixed VGPR number reserved.
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +000076 uint16_t ReservedVGPRFirst;
Konstantin Zhuravlyov71515e52016-04-26 17:24:40 +000077 // The number of consecutive VGPRs reserved.
Konstantin Zhuravlyov1d99c4d2016-04-26 15:43:14 +000078 uint16_t ReservedVGPRCount;
79
Konstantin Zhuravlyovf2f3d142016-06-25 03:11:28 +000080 // 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
85 // known.
86 uint16_t DebuggerPrivateSegmentBufferSGPR;
87
Matt Arsenault0989d512014-06-26 17:22:30 +000088 // Bonus information for debugging.
Matt Arsenault3f981402014-09-15 15:41:53 +000089 bool VCCUsed;
Matt Arsenaulte500e322014-04-15 22:40:47 +000090 uint64_t CodeLen;
Matt Arsenault89cc49f2013-12-05 05:15:35 +000091 };
92
Matt Arsenaultd32dbb62014-07-13 03:06:43 +000093 void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF) const;
94 void findNumUsedRegistersSI(const MachineFunction &MF,
Matt Arsenault89cc49f2013-12-05 05:15:35 +000095 unsigned &NumSGPR,
96 unsigned &NumVGPR) const;
97
98 /// \brief Emit register usage information so that the GPU driver
99 /// can correctly setup the GPU state.
Matt Arsenaultd32dbb62014-07-13 03:06:43 +0000100 void EmitProgramInfoR600(const MachineFunction &MF);
101 void EmitProgramInfoSI(const MachineFunction &MF, const SIProgramInfo &KernelInfo);
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000102 void EmitAmdKernelCodeT(const MachineFunction &MF,
103 const SIProgramInfo &KernelInfo) const;
Tom Stellard75aadc22012-12-11 21:25:42 +0000104
105public:
David Blaikie94598322015-01-18 20:29:04 +0000106 explicit AMDGPUAsmPrinter(TargetMachine &TM,
107 std::unique_ptr<MCStreamer> Streamer);
Tom Stellard75aadc22012-12-11 21:25:42 +0000108
Craig Topper5656db42014-04-29 07:57:24 +0000109 bool runOnMachineFunction(MachineFunction &MF) override;
Tom Stellard75aadc22012-12-11 21:25:42 +0000110
Craig Topper5656db42014-04-29 07:57:24 +0000111 const char *getPassName() const override {
Tom Stellard75aadc22012-12-11 21:25:42 +0000112 return "AMDGPU Assembly Printer";
113 }
114
Tom Stellard75aadc22012-12-11 21:25:42 +0000115 /// Implemented in AMDGPUMCInstLower.cpp
Craig Topper5656db42014-04-29 07:57:24 +0000116 void EmitInstruction(const MachineInstr *MI) override;
Tom Stellarded699252013-10-12 05:02:51 +0000117
Tom Stellardf151a452015-06-26 21:14:58 +0000118 void EmitFunctionBodyStart() override;
119
Tom Stellard1e1b05d2015-11-06 11:45:14 +0000120 void EmitFunctionEntryLabel() override;
121
Tom Stellarde3b5aea2015-12-02 17:00:42 +0000122 void EmitGlobalVariable(const GlobalVariable *GV) override;
123
Tom Stellardf4218372016-01-12 17:18:17 +0000124 void EmitStartOfAsmFile(Module &M) override;
125
Tom Stellardd7e6f132015-04-08 01:09:26 +0000126 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
127 unsigned AsmVariant, const char *ExtraCode,
Tom Stellard80e169a2015-04-08 02:07:05 +0000128 raw_ostream &O) override;
Tom Stellardd7e6f132015-04-08 01:09:26 +0000129
Yaxun Liua711cc72016-07-16 05:09:21 +0000130 void emitStartOfRuntimeMetadata(const Module &M);
131
132 void emitRuntimeMetadata(const Function &F);
133
Tom Stellarded699252013-10-12 05:02:51 +0000134protected:
Tom Stellarded699252013-10-12 05:02:51 +0000135 std::vector<std::string> DisasmLines, HexLines;
136 size_t DisasmLineMaxLen;
Tom Stellard75aadc22012-12-11 21:25:42 +0000137};
138
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000139} // End anonymous llvm
Tom Stellard75aadc22012-12-11 21:25:42 +0000140
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000141#endif