]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.h
Merge llvm, clang, lld and lldb trunk r300890, and update build glue.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / AMDGPU / AMDGPUAsmPrinter.h
1 //===-- AMDGPUAsmPrinter.h - Print AMDGPU assembly code ---------*- C++ -*-===//
2 //
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
15 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
16 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
17
18 #include "AMDKernelCodeT.h"
19 #include "AMDGPU.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/CodeGen/AsmPrinter.h"
22 #include <cstddef>
23 #include <cstdint>
24 #include <limits>
25 #include <memory>
26 #include <string>
27 #include <vector>
28
29 namespace llvm {
30
31 class AMDGPUTargetStreamer;
32 class MCOperand;
33
34 class AMDGPUAsmPrinter final : public AsmPrinter {
35 private:
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;
42     uint32_t Priv = 0;
43     uint32_t DX10Clamp = 0;
44     uint32_t DebugMode = 0;
45     uint32_t IEEEMode = 0;
46     uint32_t ScratchSize = 0;
47
48     uint64_t ComputePGMRSrc1 = 0;
49
50     // Fields set in PGM_RSRC2 pm4 packet.
51     uint32_t LDSBlocks = 0;
52     uint32_t ScratchBlocks = 0;
53
54     uint64_t ComputePGMRSrc2 = 0;
55
56     uint32_t NumVGPR = 0;
57     uint32_t NumSGPR = 0;
58     uint32_t LDSSize = 0;
59     bool FlatUsed = false;
60
61     // Number of SGPRs that meets number of waves per execution unit request.
62     uint32_t NumSGPRsForWavesPerEU = 0;
63
64     // Number of VGPRs that meets number of waves per execution unit request.
65     uint32_t NumVGPRsForWavesPerEU = 0;
66
67     // If ReservedVGPRCount is 0 then must be 0. Otherwise, this is the first
68     // fixed VGPR number reserved.
69     uint16_t ReservedVGPRFirst = 0;
70
71     // The number of consecutive VGPRs reserved.
72     uint16_t ReservedVGPRCount = 0;
73
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
76     // used or not known.
77     uint16_t DebuggerWavefrontPrivateSegmentOffsetSGPR =
78         std::numeric_limits<uint16_t>::max();
79
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();
85
86     // Bonus information for debugging.
87     bool VCCUsed = false;
88
89     SIProgramInfo() = default;
90   };
91
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,
97                               unsigned &NumSGPR,
98                               unsigned &NumVGPR) const;
99
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);
104
105 public:
106   explicit AMDGPUAsmPrinter(TargetMachine &TM,
107                             std::unique_ptr<MCStreamer> Streamer);
108
109   StringRef getPassName() const override;
110
111   const MCSubtargetInfo* getSTI() const;
112
113   AMDGPUTargetStreamer& getTargetStreamer() const;
114
115   bool runOnMachineFunction(MachineFunction &MF) override;
116
117   /// \brief Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated
118   /// pseudo lowering.
119   bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
120
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;
125
126   /// \brief tblgen'erated driver function for lowering simple MI->MC pseudo
127   /// instructions.
128   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
129                                    const MachineInstr *MI);
130
131   /// Implemented in AMDGPUMCInstLower.cpp
132   void EmitInstruction(const MachineInstr *MI) override;
133
134   void EmitFunctionBodyStart() override;
135
136   void EmitFunctionEntryLabel() override;
137
138   void EmitGlobalVariable(const GlobalVariable *GV) override;
139
140   void EmitStartOfAsmFile(Module &M) override;
141
142   void EmitEndOfAsmFile(Module &M) override;
143
144   bool isBlockOnlyReachableByFallthrough(
145     const MachineBasicBlock *MBB) const override;
146
147   bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
148                        unsigned AsmVariant, const char *ExtraCode,
149                        raw_ostream &O) override;
150
151 protected:
152   std::vector<std::string> DisasmLines, HexLines;
153   size_t DisasmLineMaxLen;
154   AMDGPUAS AMDGPUASI;
155 };
156
157 } // end namespace llvm
158
159 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H