Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / lib / Target / AArch64 / AArch64GenRegisterBankInfo.def
blobfb5b8a01156e4c21cc5eadd025f61a9e02d237c9
1 //===- AArch64GenRegisterBankInfo.def ----------------------------*- C++ -*-==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 /// This file defines all the static objects used by AArch64RegisterBankInfo.
10 /// \todo This should be generated by TableGen.
11 //===----------------------------------------------------------------------===//
13 namespace llvm {
14 RegisterBankInfo::PartialMapping AArch64GenRegisterBankInfo::PartMappings[]{
15 /* StartIdx, Length, RegBank */
16 // 0: FPR 16-bit value.
17 {0, 16, AArch64::FPRRegBank},
18 // 1: FPR 32-bit value.
19 {0, 32, AArch64::FPRRegBank},
20 // 2: FPR 64-bit value.
21 {0, 64, AArch64::FPRRegBank},
22 // 3: FPR 128-bit value.
23 {0, 128, AArch64::FPRRegBank},
24 // 4: FPR 256-bit value.
25 {0, 256, AArch64::FPRRegBank},
26 // 5: FPR 512-bit value.
27 {0, 512, AArch64::FPRRegBank},
28 // 6: GPR 32-bit value.
29 {0, 32, AArch64::GPRRegBank},
30 // 7: GPR 64-bit value.
31 {0, 64, AArch64::GPRRegBank},
34 // ValueMappings.
35 RegisterBankInfo::ValueMapping AArch64GenRegisterBankInfo::ValMappings[]{
36 /* BreakDown, NumBreakDowns */
37 // 0: invalid
38 {nullptr, 0},
39 // 3-operands instructions (all binary operations should end up with one of
40 // those mapping).
41 // 1: FPR 16-bit value. <-- This must match First3OpsIdx.
42 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR16 - PMI_Min], 1},
43 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR16 - PMI_Min], 1},
44 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR16 - PMI_Min], 1},
45 // 4: FPR 32-bit value. <-- This must match First3OpsIdx.
46 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1},
47 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1},
48 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1},
49 // 7: FPR 64-bit value.
50 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
51 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
52 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
53 // 10: FPR 128-bit value.
54 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR128 - PMI_Min], 1},
55 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR128 - PMI_Min], 1},
56 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR128 - PMI_Min], 1},
57 // 13: FPR 256-bit value.
58 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR256 - PMI_Min], 1},
59 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR256 - PMI_Min], 1},
60 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR256 - PMI_Min], 1},
61 // 16: FPR 512-bit value.
62 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR512 - PMI_Min], 1},
63 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR512 - PMI_Min], 1},
64 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR512 - PMI_Min], 1},
65 // 19: GPR 32-bit value.
66 {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1},
67 {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1},
68 {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1},
69 // 22: GPR 64-bit value. <-- This must match Last3OpsIdx.
70 {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1},
71 {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1},
72 {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1},
73 // Cross register bank copies.
74 // 25: FPR 16-bit value to GPR 16-bit. <-- This must match
75 // FirstCrossRegCpyIdx.
76 // Note: This is the kind of copy we see with physical registers.
77 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR16 - PMI_Min], 1},
78 {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1},
79 // 27: FPR 32-bit value to GPR 32-bit value.
80 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1},
81 {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1},
82 // 29: FPR 64-bit value to GPR 64-bit value.
83 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
84 {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1},
85 // 31: FPR 128-bit value to GPR 128-bit value (invalid)
86 {nullptr, 1},
87 {nullptr, 1},
88 // 33: FPR 256-bit value to GPR 256-bit value (invalid)
89 {nullptr, 1},
90 {nullptr, 1},
91 // 35: FPR 512-bit value to GPR 512-bit value (invalid)
92 {nullptr, 1},
93 {nullptr, 1},
94 // 37: GPR 32-bit value to FPR 32-bit value.
95 {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1},
96 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1},
97 // 39: GPR 64-bit value to FPR 64-bit value. <-- This must match
98 // LastCrossRegCpyIdx.
99 {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1},
100 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
101 // 41: FPExt: 16 to 32. <-- This must match FPExt16To32Idx.
102 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1},
103 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR16 - PMI_Min], 1},
104 // 43: FPExt: 16 to 32. <-- This must match FPExt16To64Idx.
105 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
106 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR16 - PMI_Min], 1},
107 // 45: FPExt: 32 to 64. <-- This must match FPExt32To64Idx.
108 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
109 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1},
110 // 47: FPExt vector: 64 to 128. <-- This must match FPExt64To128Idx.
111 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR128 - PMI_Min], 1},
112 {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
115 bool AArch64GenRegisterBankInfo::checkPartialMap(unsigned Idx,
116 unsigned ValStartIdx,
117 unsigned ValLength,
118 const RegisterBank &RB) {
119 const PartialMapping &Map = PartMappings[Idx - PartialMappingIdx::PMI_Min];
120 return Map.StartIdx == ValStartIdx && Map.Length == ValLength &&
121 Map.RegBank == &RB;
124 bool AArch64GenRegisterBankInfo::checkValueMapImpl(unsigned Idx,
125 unsigned FirstInBank,
126 unsigned Size,
127 unsigned Offset) {
128 unsigned PartialMapBaseIdx = Idx - PartialMappingIdx::PMI_Min;
129 const ValueMapping &Map =
130 AArch64GenRegisterBankInfo::getValueMapping((PartialMappingIdx)FirstInBank, Size)[Offset];
131 return Map.BreakDown == &PartMappings[PartialMapBaseIdx] &&
132 Map.NumBreakDowns == 1;
135 bool AArch64GenRegisterBankInfo::checkPartialMappingIdx(
136 PartialMappingIdx FirstAlias, PartialMappingIdx LastAlias,
137 ArrayRef<PartialMappingIdx> Order) {
138 if (Order.front() != FirstAlias)
139 return false;
140 if (Order.back() != LastAlias)
141 return false;
142 if (Order.front() > Order.back())
143 return false;
145 PartialMappingIdx Previous = Order.front();
146 bool First = true;
147 for (const auto &Current : Order) {
148 if (First) {
149 First = false;
150 continue;
152 if (Previous + 1 != Current)
153 return false;
154 Previous = Current;
156 return true;
159 unsigned AArch64GenRegisterBankInfo::getRegBankBaseIdxOffset(unsigned RBIdx,
160 unsigned Size) {
161 if (RBIdx == PMI_FirstGPR) {
162 if (Size <= 32)
163 return 0;
164 if (Size <= 64)
165 return 1;
166 return -1;
168 if (RBIdx == PMI_FirstFPR) {
169 if (Size <= 16)
170 return 0;
171 if (Size <= 32)
172 return 1;
173 if (Size <= 64)
174 return 2;
175 if (Size <= 128)
176 return 3;
177 if (Size <= 256)
178 return 4;
179 if (Size <= 512)
180 return 5;
181 return -1;
183 return -1;
186 const RegisterBankInfo::ValueMapping *
187 AArch64GenRegisterBankInfo::getValueMapping(PartialMappingIdx RBIdx,
188 unsigned Size) {
189 assert(RBIdx != PartialMappingIdx::PMI_None && "No mapping needed for that");
190 unsigned BaseIdxOffset = getRegBankBaseIdxOffset(RBIdx, Size);
191 if (BaseIdxOffset == -1u)
192 return &ValMappings[InvalidIdx];
194 unsigned ValMappingIdx =
195 First3OpsIdx + (RBIdx - PartialMappingIdx::PMI_Min + BaseIdxOffset) *
196 ValueMappingIdx::DistanceBetweenRegBanks;
197 assert(ValMappingIdx >= First3OpsIdx && ValMappingIdx <= Last3OpsIdx &&
198 "Mapping out of bound");
200 return &ValMappings[ValMappingIdx];
203 AArch64GenRegisterBankInfo::PartialMappingIdx
204 AArch64GenRegisterBankInfo::BankIDToCopyMapIdx[]{
205 PMI_None, // CCR
206 PMI_FirstFPR, // FPR
207 PMI_FirstGPR, // GPR
210 const RegisterBankInfo::ValueMapping *
211 AArch64GenRegisterBankInfo::getCopyMapping(unsigned DstBankID,
212 unsigned SrcBankID, unsigned Size) {
213 assert(DstBankID < AArch64::NumRegisterBanks && "Invalid bank ID");
214 assert(SrcBankID < AArch64::NumRegisterBanks && "Invalid bank ID");
215 PartialMappingIdx DstRBIdx = BankIDToCopyMapIdx[DstBankID];
216 PartialMappingIdx SrcRBIdx = BankIDToCopyMapIdx[SrcBankID];
217 assert(DstRBIdx != PMI_None && "No such mapping");
218 assert(SrcRBIdx != PMI_None && "No such mapping");
220 if (DstRBIdx == SrcRBIdx)
221 return getValueMapping(DstRBIdx, Size);
223 assert(Size <= 64 && "GPR cannot handle that size");
224 unsigned ValMappingIdx =
225 FirstCrossRegCpyIdx +
226 (DstRBIdx - PMI_Min + getRegBankBaseIdxOffset(DstRBIdx, Size)) *
227 ValueMappingIdx::DistanceBetweenCrossRegCpy;
228 assert(ValMappingIdx >= FirstCrossRegCpyIdx &&
229 ValMappingIdx <= LastCrossRegCpyIdx && "Mapping out of bound");
230 return &ValMappings[ValMappingIdx];
233 const RegisterBankInfo::ValueMapping *
234 AArch64GenRegisterBankInfo::getFPExtMapping(unsigned DstSize,
235 unsigned SrcSize) {
236 // We support:
237 // - For Scalar:
238 // - 16 to 32.
239 // - 16 to 64.
240 // - 32 to 64.
241 // => FPR 16 to FPR 32|64
242 // => FPR 32 to FPR 64
243 // - For vectors:
244 // - v4f16 to v4f32
245 // - v2f32 to v2f64
246 // => FPR 64 to FPR 128
248 // Check that we have been asked sensible sizes.
249 if (SrcSize == 16) {
250 assert((DstSize == 32 || DstSize == 64) && "Unexpected half extension");
251 if (DstSize == 32)
252 return &ValMappings[FPExt16To32Idx];
253 return &ValMappings[FPExt16To64Idx];
256 if (SrcSize == 32) {
257 assert(DstSize == 64 && "Unexpected float extension");
258 return &ValMappings[FPExt32To64Idx];
260 assert((SrcSize == 64 || DstSize == 128) && "Unexpected vector extension");
261 return &ValMappings[FPExt64To128Idx];
263 } // End llvm namespace.