]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AArch64/AArch64GenRegisterBankInfo.def
Merge llvm, clang, lld and lldb release_40 branch r292009. Also update
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / AArch64 / AArch64GenRegisterBankInfo.def
1 //===- AArch64GenRegisterBankInfo.def ----------------------------*- 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 /// \file
10 /// This file defines all the static objects used by AArch64RegisterBankInfo.
11 /// \todo This should be generated by TableGen.
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_BUILD_GLOBAL_ISEL
15 #error "You shouldn't build this"
16 #endif
17
18 namespace llvm {
19 namespace AArch64 {
20
21 const uint32_t GPRCoverageData[] = {
22     // Classes 0-31
23     (1u << AArch64::GPR32allRegClassID) | (1u << AArch64::GPR32RegClassID) |
24         (1u << AArch64::GPR32spRegClassID) |
25         (1u << AArch64::GPR32commonRegClassID) |
26         (1u << AArch64::GPR32sponlyRegClassID) |
27         (1u << AArch64::GPR64allRegClassID) | (1u << AArch64::GPR64RegClassID) |
28         (1u << AArch64::GPR64spRegClassID) |
29         (1u << AArch64::GPR64commonRegClassID) |
30         (1u << AArch64::tcGPR64RegClassID) |
31         (1u << AArch64::GPR64sponlyRegClassID),
32     // Classes 32-63
33     0,
34     // FIXME: The entries below this point can be safely removed once this is
35     // tablegenerated. It's only needed because of the hardcoded register class
36     // limit.
37     // Classes 64-96
38     0,
39     // Classes 97-128
40     0,
41     // Classes 129-160
42     0,
43     // Classes 161-192
44     0,
45     // Classes 193-224
46     0,
47 };
48
49 const uint32_t FPRCoverageData[] = {
50     // Classes 0-31
51     (1u << AArch64::FPR8RegClassID) | (1u << AArch64::FPR16RegClassID) |
52         (1u << AArch64::FPR32RegClassID) | (1u << AArch64::FPR64RegClassID) |
53         (1u << AArch64::DDRegClassID) | (1u << AArch64::FPR128RegClassID) |
54         (1u << AArch64::FPR128_loRegClassID) | (1u << AArch64::DDDRegClassID) |
55         (1u << AArch64::DDDDRegClassID),
56     // Classes 32-63
57     (1u << (AArch64::QQRegClassID - 32)) |
58         (1u << (AArch64::QQ_with_qsub0_in_FPR128_loRegClassID - 32)) |
59         (1u << (AArch64::QQ_with_qsub1_in_FPR128_loRegClassID - 32)) |
60         (1u
61          << (AArch64::
62                  QQQ_with_qsub1_in_FPR128_lo_and_QQQ_with_qsub2_in_FPR128_loRegClassID -
63              32)) |
64         (1u
65          << (AArch64::
66                  QQQ_with_qsub0_in_FPR128_lo_and_QQQ_with_qsub2_in_FPR128_loRegClassID -
67              32)) |
68         (1u << (AArch64::QQQQRegClassID - 32)) |
69         (1u << (AArch64::QQQQ_with_qsub0_in_FPR128_loRegClassID - 32)) |
70         (1u << (AArch64::QQQQ_with_qsub1_in_FPR128_loRegClassID - 32)) |
71         (1u << (AArch64::QQQQ_with_qsub2_in_FPR128_loRegClassID - 32)) |
72         (1u << (AArch64::QQQQ_with_qsub3_in_FPR128_loRegClassID - 32)) |
73         (1u
74          << (AArch64::
75                  QQQQ_with_qsub0_in_FPR128_lo_and_QQQQ_with_qsub1_in_FPR128_loRegClassID -
76              32)) |
77         (1u
78          << (AArch64::
79                  QQQQ_with_qsub1_in_FPR128_lo_and_QQQQ_with_qsub2_in_FPR128_loRegClassID -
80              32)) |
81         (1u
82          << (AArch64::
83                  QQQQ_with_qsub2_in_FPR128_lo_and_QQQQ_with_qsub3_in_FPR128_loRegClassID -
84              32)) |
85         (1u
86          << (AArch64::
87                  QQQQ_with_qsub0_in_FPR128_lo_and_QQQQ_with_qsub2_in_FPR128_loRegClassID -
88              32)) |
89         (1u
90          << (AArch64::
91                  QQQQ_with_qsub1_in_FPR128_lo_and_QQQQ_with_qsub3_in_FPR128_loRegClassID -
92              32)) |
93         (1u
94          << (AArch64::
95                  QQQQ_with_qsub0_in_FPR128_lo_and_QQQQ_with_qsub3_in_FPR128_loRegClassID -
96              32)) |
97         (1u
98          << (AArch64::
99                  QQ_with_qsub0_in_FPR128_lo_and_QQ_with_qsub1_in_FPR128_loRegClassID -
100              32)) |
101         (1u << (AArch64::QQQRegClassID - 32)) |
102         (1u << (AArch64::QQQ_with_qsub0_in_FPR128_loRegClassID - 32)) |
103         (1u << (AArch64::QQQ_with_qsub1_in_FPR128_loRegClassID - 32)) |
104         (1u << (AArch64::QQQ_with_qsub2_in_FPR128_loRegClassID - 32)) |
105         (1u
106          << (AArch64::
107                  QQQ_with_qsub0_in_FPR128_lo_and_QQQ_with_qsub1_in_FPR128_loRegClassID -
108              32)),
109     // FIXME: The entries below this point can be safely removed once this
110     // is tablegenerated. It's only needed because of the hardcoded register
111     // class limit.
112     // Classes 64-96
113     0,
114     // Classes 97-128
115     0,
116     // Classes 129-160
117     0,
118     // Classes 161-192
119     0,
120     // Classes 193-224
121     0,
122 };
123
124 const uint32_t CCRCoverageData[] = {
125     // Classes 0-31
126     1u << AArch64::CCRRegClassID,
127     // Classes 32-63
128     0,
129     // FIXME: The entries below this point can be safely removed once this
130     // is tablegenerated. It's only needed because of the hardcoded register
131     // class limit.
132     // Classes 64-96
133     0,
134     // Classes 97-128
135     0,
136     // Classes 129-160
137     0,
138     // Classes 161-192
139     0,
140     // Classes 193-224
141     0,
142 };
143
144 RegisterBank GPRRegBank(AArch64::GPRRegBankID, "GPR", 64, GPRCoverageData);
145 RegisterBank FPRRegBank(AArch64::FPRRegBankID, "FPR", 512, FPRCoverageData);
146 RegisterBank CCRRegBank(AArch64::CCRRegBankID, "CCR", 32, CCRCoverageData);
147
148 RegisterBank *RegBanks[] = {&GPRRegBank, &FPRRegBank, &CCRRegBank};
149
150 // PartialMappings.
151 enum PartialMappingIdx {
152   PMI_None = -1,
153   PMI_GPR32 = 1,
154   PMI_GPR64,
155   PMI_FPR32,
156   PMI_FPR64,
157   PMI_FPR128,
158   PMI_FPR256,
159   PMI_FPR512,
160   PMI_FirstGPR = PMI_GPR32,
161   PMI_LastGPR = PMI_GPR64,
162   PMI_FirstFPR = PMI_FPR32,
163   PMI_LastFPR = PMI_FPR512,
164   PMI_Min = PMI_FirstGPR,
165 };
166
167 static unsigned getRegBankBaseIdxOffset(unsigned Size) {
168   assert(Size && "0-sized type!!");
169   // Make anything smaller than 32 gets 32
170   Size = ((Size + 31) / 32) * 32;
171   // 32 is 0, 64 is 1, 128 is 2, and so on.
172   return Log2_32(Size) - /*Log2_32(32)=*/ 5;
173 }
174
175 RegisterBankInfo::PartialMapping PartMappings[] {
176   /* StartIdx, Length, RegBank */
177   // 0: GPR 32-bit value.
178   {0, 32, GPRRegBank},
179   // 1: GPR 64-bit value.
180   {0, 64, GPRRegBank},
181   // 2: FPR 32-bit value.
182   {0, 32, FPRRegBank},
183   // 3: FPR 64-bit value.
184   {0, 64, FPRRegBank},
185   // 4: FPR 128-bit value.
186   {0, 128, FPRRegBank},
187   // 5: FPR 256-bit value.
188   {0, 256, FPRRegBank},
189   // 6: FPR 512-bit value.
190   {0, 512, FPRRegBank}
191 };
192
193 enum ValueMappingIdx {
194   First3OpsIdx = 0,
195   Last3OpsIdx = 18,
196   DistanceBetweenRegBanks = 3,
197   FirstCrossRegCpyIdx = 21,
198   LastCrossRegCpyIdx = 27,
199   DistanceBetweenCrossRegCpy = 2
200 };
201
202 // ValueMappings.
203 RegisterBankInfo::ValueMapping ValMappings[]{
204     /* BreakDown, NumBreakDowns */
205     // 3-operands instructions (all binary operations should end up with one of
206     // those mapping).
207     // 0: GPR 32-bit value. <-- This must match First3OpsIdx.
208     {&PartMappings[PMI_GPR32 - PMI_Min], 1},
209     {&PartMappings[PMI_GPR32 - PMI_Min], 1},
210     {&PartMappings[PMI_GPR32 - PMI_Min], 1},
211     // 3: GPR 64-bit value.
212     {&PartMappings[PMI_GPR64 - PMI_Min], 1},
213     {&PartMappings[PMI_GPR64 - PMI_Min], 1},
214     {&PartMappings[PMI_GPR64 - PMI_Min], 1},
215     // 6: FPR 32-bit value.
216     {&PartMappings[PMI_FPR32 - PMI_Min], 1},
217     {&PartMappings[PMI_FPR32 - PMI_Min], 1},
218     {&PartMappings[PMI_FPR32 - PMI_Min], 1},
219     // 9: FPR 64-bit value.
220     {&PartMappings[PMI_FPR64 - PMI_Min], 1},
221     {&PartMappings[PMI_FPR64 - PMI_Min], 1},
222     {&PartMappings[PMI_FPR64 - PMI_Min], 1},
223     // 12: FPR 128-bit value.
224     {&PartMappings[PMI_FPR128 - PMI_Min], 1},
225     {&PartMappings[PMI_FPR128 - PMI_Min], 1},
226     {&PartMappings[PMI_FPR128 - PMI_Min], 1},
227     // 15: FPR 256-bit value.
228     {&PartMappings[PMI_FPR256 - PMI_Min], 1},
229     {&PartMappings[PMI_FPR256 - PMI_Min], 1},
230     {&PartMappings[PMI_FPR256 - PMI_Min], 1},
231     // 18: FPR 512-bit value. <-- This must match Last3OpsIdx.
232     {&PartMappings[PMI_FPR512 - PMI_Min], 1},
233     {&PartMappings[PMI_FPR512 - PMI_Min], 1},
234     {&PartMappings[PMI_FPR512 - PMI_Min], 1},
235     // Cross register bank copies.
236     // 21: GPR 32-bit value to FPR 32-bit value. <-- This must match
237     //                                               FirstCrossRegCpyIdx.
238     {&PartMappings[PMI_GPR32 - PMI_Min], 1},
239     {&PartMappings[PMI_FPR32 - PMI_Min], 1},
240     // 23: GPR 64-bit value to FPR 64-bit value.
241     {&PartMappings[PMI_GPR64 - PMI_Min], 1},
242     {&PartMappings[PMI_FPR64 - PMI_Min], 1},
243     // 25: FPR 32-bit value to GPR 32-bit value.
244     {&PartMappings[PMI_FPR32 - PMI_Min], 1},
245     {&PartMappings[PMI_GPR32 - PMI_Min], 1},
246     // 27: FPR 64-bit value to GPR 64-bit value. <-- This must match
247     //                                               LastCrossRegCpyIdx.
248     {&PartMappings[PMI_FPR64 - PMI_Min], 1},
249     {&PartMappings[PMI_GPR64 - PMI_Min], 1}
250 };
251
252 /// Get the pointer to the ValueMapping representing the RegisterBank
253 /// at \p RBIdx with a size of \p Size.
254 ///
255 /// The returned mapping works for instructions with the same kind of
256 /// operands for up to 3 operands.
257 ///
258 /// \pre \p RBIdx != PartialMappingIdx::None
259 const RegisterBankInfo::ValueMapping *
260 getValueMapping(PartialMappingIdx RBIdx, unsigned Size) {
261   assert(RBIdx != PartialMappingIdx::PMI_None && "No mapping needed for that");
262   unsigned ValMappingIdx = First3OpsIdx +
263                            (RBIdx - AArch64::PartialMappingIdx::PMI_Min +
264                             getRegBankBaseIdxOffset(Size)) *
265                                ValueMappingIdx::DistanceBetweenRegBanks;
266   assert(ValMappingIdx >= AArch64::First3OpsIdx &&
267          ValMappingIdx <= AArch64::Last3OpsIdx && "Mapping out of bound");
268
269   return &ValMappings[ValMappingIdx];
270 }
271
272 /// Get the pointer to the ValueMapping of the operands of a copy
273 /// instruction from a GPR or FPR register to a GPR or FPR register
274 /// with a size of \p Size.
275 ///
276 /// If \p DstIsGPR is true, the destination of the copy is on GPR,
277 /// otherwise it is on FPR. Same thing for \p SrcIsGPR.
278 const RegisterBankInfo::ValueMapping *
279 getCopyMapping(bool DstIsGPR, bool SrcIsGPR, unsigned Size) {
280   PartialMappingIdx DstRBIdx = DstIsGPR ? PMI_FirstGPR : PMI_FirstFPR;
281   PartialMappingIdx SrcRBIdx = SrcIsGPR ? PMI_FirstGPR : PMI_FirstFPR;
282   if (DstRBIdx == SrcRBIdx)
283     return getValueMapping(DstRBIdx, Size);
284   assert(Size <= 64 && "GPR cannot handle that size");
285   unsigned ValMappingIdx =
286       FirstCrossRegCpyIdx +
287       (DstRBIdx - PMI_Min + getRegBankBaseIdxOffset(Size)) *
288           ValueMappingIdx::DistanceBetweenCrossRegCpy;
289   assert(ValMappingIdx >= AArch64::FirstCrossRegCpyIdx &&
290          ValMappingIdx <= AArch64::LastCrossRegCpyIdx &&
291          "Mapping out of bound");
292   return &ValMappings[ValMappingIdx];
293 }
294
295 } // End AArch64 namespace.
296 } // End llvm namespace.