b1389533ec39f2c4d568412e118ccfd0eb53e35c
[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   BitVector getReservedRegs(const MachineFunction &MF) const override;
33
34   unsigned getRegPressureSetLimit(const MachineFunction &MF,
35                                   unsigned Idx) const override;
36
37   bool requiresRegisterScavenging(const MachineFunction &Fn) const override;
38
39   void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj,
40                            unsigned FIOperandNum,
41                            RegScavenger *RS) const override;
42
43   unsigned getHWRegIndex(unsigned Reg) const override;
44
45   /// \brief Return the 'base' register class for this register.
46   /// e.g. SGPR0 => SReg_32, VGPR => VGPR_32 SGPR0_SGPR1 -> SReg_32, etc.
47   const TargetRegisterClass *getPhysRegClass(unsigned Reg) const;
48
49   /// \returns true if this class contains only SGPR registers
50   bool isSGPRClass(const TargetRegisterClass *RC) const {
51     return !hasVGPRs(RC);
52   }
53
54   /// \returns true if this class ID contains only SGPR registers
55   bool isSGPRClassID(unsigned RCID) const {
56     return isSGPRClass(getRegClass(RCID));
57   }
58
59   /// \returns true if this class contains VGPR registers.
60   bool hasVGPRs(const TargetRegisterClass *RC) const;
61
62   /// returns true if this is a pseudoregister class combination of VGPRs and
63   /// SGPRs for operand modeling. FIXME: We should set isAllocatable = 0 on
64   /// them.
65   static bool isPseudoRegClass(const TargetRegisterClass *RC) {
66     return RC == &AMDGPU::VS_32RegClass || RC == &AMDGPU::VS_64RegClass;
67   }
68
69   /// \returns A VGPR reg class with the same width as \p SRC
70   const TargetRegisterClass *getEquivalentVGPRClass(
71                                           const TargetRegisterClass *SRC) const;
72
73   /// \returns The register class that is used for a sub-register of \p RC for
74   /// the given \p SubIdx.  If \p SubIdx equals NoSubRegister, \p RC will
75   /// be returned.
76   const TargetRegisterClass *getSubRegClass(const TargetRegisterClass *RC,
77                                             unsigned SubIdx) const;
78
79   bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
80                             unsigned DefSubReg,
81                             const TargetRegisterClass *SrcRC,
82                             unsigned SrcSubReg) const override;
83
84   /// \p Channel This is the register channel (e.g. a value from 0-16), not the
85   ///            SubReg index.
86   /// \returns The sub-register of Reg that is in Channel.
87   unsigned getPhysRegSubReg(unsigned Reg, const TargetRegisterClass *SubRC,
88                             unsigned Channel) const;
89
90   /// \returns True if operands defined with this operand type can accept
91   /// a literal constant (i.e. any 32-bit immediate).
92   bool opCanUseLiteralConstant(unsigned OpType) const;
93
94   /// \returns True if operands defined with this operand type can accept
95   /// an inline constant. i.e. An integer value in the range (-16, 64) or
96   /// -4.0f, -2.0f, -1.0f, -0.5f, 0.0f, 0.5f, 1.0f, 2.0f, 4.0f. 
97   bool opCanUseInlineConstant(unsigned OpType) const;
98
99   enum PreloadedValue {
100     // SGPRS:
101     SCRATCH_PTR         =  0,
102     INPUT_PTR           =  3,
103     TGID_X              = 10,
104     TGID_Y              = 11,
105     TGID_Z              = 12,
106     SCRATCH_WAVE_OFFSET = 14,
107     // VGPRS:
108     FIRST_VGPR_VALUE    = 15,
109     TIDIG_X             = FIRST_VGPR_VALUE,
110     TIDIG_Y             = 16,
111     TIDIG_Z             = 17,
112   };
113
114   /// \brief Returns the physical register that \p Value is stored in.
115   unsigned getPreloadedValue(const MachineFunction &MF,
116                              enum PreloadedValue Value) const;
117
118   /// \brief Give the maximum number of VGPRs that can be used by \p WaveCount
119   ///        concurrent waves.
120   unsigned getNumVGPRsAllowed(unsigned WaveCount) const;
121
122   /// \brief Give the maximum number of SGPRs that can be used by \p WaveCount
123   ///        concurrent waves.
124   unsigned getNumSGPRsAllowed(AMDGPUSubtarget::Generation gen,
125                               unsigned WaveCount) const;
126
127   unsigned findUnusedRegister(const MachineRegisterInfo &MRI,
128                               const TargetRegisterClass *RC) const;
129
130 private:
131   void buildScratchLoadStore(MachineBasicBlock::iterator MI,
132                              unsigned LoadStoreOp, unsigned Value,
133                              unsigned ScratchRsrcReg, unsigned ScratchOffset,
134                              int64_t Offset, RegScavenger *RS) const;
135 };
136
137 } // End namespace llvm
138
139 #endif