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_R600_AMDGPUASMPRINTER_H
16#define LLVM_LIB_TARGET_R600_AMDGPUASMPRINTER_H
17
18#include "llvm/CodeGen/AsmPrinter.h"
19#include <vector>
20
21namespace llvm {
22
23class AMDGPUAsmPrinter : public AsmPrinter {
24private:
25  struct SIProgramInfo {
26    SIProgramInfo() :
27      VGPRBlocks(0),
28      SGPRBlocks(0),
29      Priority(0),
30      FloatMode(0),
31      Priv(0),
32      DX10Clamp(0),
33      DebugMode(0),
34      IEEEMode(0),
35      ScratchSize(0),
36      ComputePGMRSrc1(0),
37      LDSBlocks(0),
38      ScratchBlocks(0),
39      ComputePGMRSrc2(0),
40      NumVGPR(0),
41      NumSGPR(0),
42      FlatUsed(false),
43      VCCUsed(false),
44      CodeLen(0) {}
45
46    // Fields set in PGM_RSRC1 pm4 packet.
47    uint32_t VGPRBlocks;
48    uint32_t SGPRBlocks;
49    uint32_t Priority;
50    uint32_t FloatMode;
51    uint32_t Priv;
52    uint32_t DX10Clamp;
53    uint32_t DebugMode;
54    uint32_t IEEEMode;
55    uint32_t ScratchSize;
56
57    uint64_t ComputePGMRSrc1;
58
59    // Fields set in PGM_RSRC2 pm4 packet.
60    uint32_t LDSBlocks;
61    uint32_t ScratchBlocks;
62
63    uint64_t ComputePGMRSrc2;
64
65    uint32_t NumVGPR;
66    uint32_t NumSGPR;
67    uint32_t LDSSize;
68    bool FlatUsed;
69
70    // Bonus information for debugging.
71    bool VCCUsed;
72    uint64_t CodeLen;
73  };
74
75  void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF) const;
76  void findNumUsedRegistersSI(const MachineFunction &MF,
77                              unsigned &NumSGPR,
78                              unsigned &NumVGPR) const;
79
80  /// \brief Emit register usage information so that the GPU driver
81  /// can correctly setup the GPU state.
82  void EmitProgramInfoR600(const MachineFunction &MF);
83  void EmitProgramInfoSI(const MachineFunction &MF, const SIProgramInfo &KernelInfo);
84  void EmitAmdKernelCodeT(const MachineFunction &MF,
85                          const SIProgramInfo &KernelInfo) const;
86
87public:
88  explicit AMDGPUAsmPrinter(TargetMachine &TM,
89                            std::unique_ptr<MCStreamer> Streamer);
90
91  bool runOnMachineFunction(MachineFunction &MF) override;
92
93  const char *getPassName() const override {
94    return "AMDGPU Assembly Printer";
95  }
96
97  /// Implemented in AMDGPUMCInstLower.cpp
98  void EmitInstruction(const MachineInstr *MI) override;
99
100  void EmitEndOfAsmFile(Module &M) override;
101
102  bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
103                       unsigned AsmVariant, const char *ExtraCode,
104                       raw_ostream &O) override;
105
106protected:
107  std::vector<std::string> DisasmLines, HexLines;
108  size_t DisasmLineMaxLen;
109};
110
111} // End anonymous llvm
112
113#endif
114