AMDGPU: Rework how private buffer passed for HSA
[oota-llvm.git] / lib / Target / AMDGPU / SIRegisterInfo.h
1 //===-- SIRegisterInfo.h - SI Register Info Interface ----------*- 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 Interface definition for SIRegisterInfo
12 //
13 //===----------------------------------------------------------------------===//
14
15
16 #ifndef LLVM_LIB_TARGET_R600_SIREGISTERINFO_H
17 #define LLVM_LIB_TARGET_R600_SIREGISTERINFO_H
18
19 #include "AMDGPURegisterInfo.h"
20 #include "AMDGPUSubtarget.h"
21 #include "llvm/Support/Debug.h"
22
23 namespace llvm {
24
25 struct SIRegisterInfo : public AMDGPURegisterInfo {
26 private:
27   void reserveRegisterTuples(BitVector &, unsigned Reg) const;
28
29 public:
30   SIRegisterInfo();
31
32   /// Return the end register initially reserved for the scratch buffer in case
33   /// spilling is needed.
34   unsigned reservedPrivateSegmentBufferReg(const MachineFunction &MF) const;
35
36   /// Return the end register initially reserved for the scratch wave offset in
37   /// case spilling is needed.
38   unsigned reservedPrivateSegmentWaveByteOffsetReg(
39     const MachineFunction &MF) const;
40
41   BitVector getReservedRegs(const MachineFunction &MF) const override;
42
43   unsigned getRegPressureSetLimit(const MachineFunction &MF,
44                                   unsigned Idx) const override;
45
46   bool requiresRegisterScavenging(const MachineFunction &Fn) const override;
47
48   void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj,
49                            unsigned FIOperandNum,
50                            RegScavenger *RS) const override;
51
52   unsigned getHWRegIndex(unsigned Reg) const override;
53
54   /// \brief Return the 'base' register class for this register.
55   /// e.g. SGPR0 => SReg_32, VGPR => VGPR_32 SGPR0_SGPR1 -> SReg_32, etc.
56   const TargetRegisterClass *getPhysRegClass(unsigned Reg) const;
57
58   /// \returns true if this class contains only SGPR registers
59   bool isSGPRClass(const TargetRegisterClass *RC) const {
60     return !hasVGPRs(RC);
61   }
62
63   /// \returns true if this class ID contains only SGPR registers
64   bool isSGPRClassID(unsigned RCID) const {
65     return isSGPRClass(getRegClass(RCID));
66   }
67
68   /// \returns true if this class contains VGPR registers.
69   bool hasVGPRs(const TargetRegisterClass *RC) const;
70
71   /// returns true if this is a pseudoregister class combination of VGPRs and
72   /// SGPRs for operand modeling. FIXME: We should set isAllocatable = 0 on
73   /// them.
74   static bool isPseudoRegClass(const TargetRegisterClass *RC) {
75     return RC == &AMDGPU::VS_32RegClass || RC == &AMDGPU::VS_64RegClass;
76   }
77
78   /// \returns A VGPR reg class with the same width as \p SRC
79   const TargetRegisterClass *getEquivalentVGPRClass(
80                                           const TargetRegisterClass *SRC) const;
81
82   /// \returns The register class that is used for a sub-register of \p RC for
83   /// the given \p SubIdx.  If \p SubIdx equals NoSubRegister, \p RC will
84   /// be returned.
85   const TargetRegisterClass *getSubRegClass(const TargetRegisterClass *RC,
86                                             unsigned SubIdx) const;
87
88   bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
89                             unsigned DefSubReg,
90                             const TargetRegisterClass *SrcRC,
91                             unsigned SrcSubReg) const override;
92
93   /// \p Channel This is the register channel (e.g. a value from 0-16), not the
94   ///            SubReg index.
95   /// \returns The sub-register of Reg that is in Channel.
96   unsigned getPhysRegSubReg(unsigned Reg, const TargetRegisterClass *SubRC,
97                             unsigned Channel) const;
98
99   /// \returns True if operands defined with this operand type can accept
100   /// a literal constant (i.e. any 32-bit immediate).
101   bool opCanUseLiteralConstant(unsigned OpType) const;
102
103   /// \returns True if operands defined with this operand type can accept
104   /// an inline constant. i.e. An integer value in the range (-16, 64) or
105   /// -4.0f, -2.0f, -1.0f, -0.5f, 0.0f, 0.5f, 1.0f, 2.0f, 4.0f.
106   bool opCanUseInlineConstant(unsigned OpType) const;
107
108   enum PreloadedValue {
109     // SGPRS:
110     PRIVATE_SEGMENT_BUFFER =  0,
111     DISPATCH_PTR        =  1,
112     QUEUE_PTR           =  2,
113     KERNARG_SEGMENT_PTR =  3,
114     WORKGROUP_ID_X      = 10,
115     WORKGROUP_ID_Y      = 11,
116     WORKGROUP_ID_Z      = 12,
117     PRIVATE_SEGMENT_WAVE_BYTE_OFFSET = 14,
118
119     // VGPRS:
120     FIRST_VGPR_VALUE    = 15,
121     WORKITEM_ID_X       = FIRST_VGPR_VALUE,
122     WORKITEM_ID_Y       = 16,
123     WORKITEM_ID_Z       = 17
124   };
125
126   /// \brief Returns the physical register that \p Value is stored in.
127   unsigned getPreloadedValue(const MachineFunction &MF,
128                              enum PreloadedValue Value) const;
129
130   /// \brief Give the maximum number of VGPRs that can be used by \p WaveCount
131   ///        concurrent waves.
132   unsigned getNumVGPRsAllowed(unsigned WaveCount) const;
133
134   /// \brief Give the maximum number of SGPRs that can be used by \p WaveCount
135   ///        concurrent waves.
136   unsigned getNumSGPRsAllowed(AMDGPUSubtarget::Generation gen,
137                               unsigned WaveCount) const;
138
139   unsigned findUnusedRegister(const MachineRegisterInfo &MRI,
140                               const TargetRegisterClass *RC) const;
141
142 private:
143   void buildScratchLoadStore(MachineBasicBlock::iterator MI,
144                              unsigned LoadStoreOp, unsigned Value,
145                              unsigned ScratchRsrcReg, unsigned ScratchOffset,
146                              int64_t Offset, RegScavenger *RS) const;
147 };
148
149 } // End namespace llvm
150
151 #endif