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