R600/SI: Add preliminary support for flat address space
[oota-llvm.git] / lib / Target / R600 / 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_R600_AMDGPUASMPRINTER_H
16 #define LLVM_LIB_TARGET_R600_AMDGPUASMPRINTER_H
17
18 #include "llvm/CodeGen/AsmPrinter.h"
19 #include <vector>
20
21 namespace llvm {
22
23 class AMDGPUAsmPrinter : public AsmPrinter {
24 private:
25   struct SIProgramInfo {
26     SIProgramInfo() :
27       NumVGPR(0),
28       NumSGPR(0),
29       Priority(0),
30       FloatMode(0),
31       Priv(0),
32       DX10Clamp(0),
33       DebugMode(0),
34       IEEEMode(0),
35       ScratchSize(0),
36       FlatUsed(false),
37       VCCUsed(false),
38       CodeLen(0) {}
39
40     // Fields set in PGM_RSRC1 pm4 packet.
41     uint32_t NumVGPR;
42     uint32_t NumSGPR;
43     uint32_t Priority;
44     uint32_t FloatMode;
45     uint32_t Priv;
46     uint32_t DX10Clamp;
47     uint32_t DebugMode;
48     uint32_t IEEEMode;
49     uint32_t ScratchSize;
50
51     bool FlatUsed;
52
53     // Bonus information for debugging.
54     bool VCCUsed;
55     uint64_t CodeLen;
56   };
57
58   void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF) const;
59   void findNumUsedRegistersSI(const MachineFunction &MF,
60                               unsigned &NumSGPR,
61                               unsigned &NumVGPR) const;
62
63   /// \brief Emit register usage information so that the GPU driver
64   /// can correctly setup the GPU state.
65   void EmitProgramInfoR600(const MachineFunction &MF);
66   void EmitProgramInfoSI(const MachineFunction &MF, const SIProgramInfo &KernelInfo);
67
68 public:
69   explicit AMDGPUAsmPrinter(TargetMachine &TM, MCStreamer &Streamer);
70
71   bool runOnMachineFunction(MachineFunction &MF) override;
72
73   const char *getPassName() const override {
74     return "AMDGPU Assembly Printer";
75   }
76
77   /// Implemented in AMDGPUMCInstLower.cpp
78   void EmitInstruction(const MachineInstr *MI) override;
79
80   void EmitEndOfAsmFile(Module &M) override;
81
82 protected:
83   bool DisasmEnabled;
84   std::vector<std::string> DisasmLines, HexLines;
85   size_t DisasmLineMaxLen;
86 };
87
88 } // End anonymous llvm
89
90 #endif