xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/AMDGPUGenRegisterBankInfo.def (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric//===- AMDGPUGenRegisterBankInfo.def -----------------------------*- C++ -*-==//
20b57cec5SDimitry Andric//
30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric//
70b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric/// \file
90b57cec5SDimitry Andric/// This file defines all the static objects used by AMDGPURegisterBankInfo.
100b57cec5SDimitry Andric/// \todo This should be generated by TableGen.
110b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric
130b57cec5SDimitry Andricnamespace llvm {
140b57cec5SDimitry Andricnamespace AMDGPU {
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricenum PartialMappingIdx {
170b57cec5SDimitry Andric  None = - 1,
18480093f4SDimitry Andric  PM_SGPR1  = 1,
19480093f4SDimitry Andric  PM_SGPR16 = 5,
20480093f4SDimitry Andric  PM_SGPR32 = 6,
21480093f4SDimitry Andric  PM_SGPR64 = 7,
22480093f4SDimitry Andric  PM_SGPR128 = 8,
23480093f4SDimitry Andric  PM_SGPR256 = 9,
24480093f4SDimitry Andric  PM_SGPR512 = 10,
25480093f4SDimitry Andric  PM_SGPR1024 = 11,
26480093f4SDimitry Andric  PM_VGPR1  = 12,
27480093f4SDimitry Andric  PM_VGPR16 = 16,
28480093f4SDimitry Andric  PM_VGPR32 = 17,
29480093f4SDimitry Andric  PM_VGPR64 = 18,
30480093f4SDimitry Andric  PM_VGPR128 = 19,
31480093f4SDimitry Andric  PM_VGPR256 = 20,
32480093f4SDimitry Andric  PM_VGPR512 = 21,
33480093f4SDimitry Andric  PM_VGPR1024 = 22,
34480093f4SDimitry Andric  PM_SGPR96 = 23,
35480093f4SDimitry Andric  PM_VGPR96 = 24,
36480093f4SDimitry Andric  PM_AGPR96 = 25,
37480093f4SDimitry Andric  PM_AGPR32 = 31,
38480093f4SDimitry Andric  PM_AGPR64 = 32,
39480093f4SDimitry Andric  PM_AGPR128 = 33,
40*e8d8bef9SDimitry Andric  PM_AGPR256 = 34,
41*e8d8bef9SDimitry Andric  PM_AGPR512 = 35,
42*e8d8bef9SDimitry Andric  PM_AGPR1024 = 36
430b57cec5SDimitry Andric};
440b57cec5SDimitry Andric
450b57cec5SDimitry Andricconst RegisterBankInfo::PartialMapping PartMappings[] {
460b57cec5SDimitry Andric  // StartIdx, Length, RegBank
470b57cec5SDimitry Andric  {0, 1,  VCCRegBank},
480b57cec5SDimitry Andric
490b57cec5SDimitry Andric  {0, 1,  SGPRRegBank}, // SGPR begin
500b57cec5SDimitry Andric  {0, 16, SGPRRegBank},
510b57cec5SDimitry Andric  {0, 32, SGPRRegBank},
520b57cec5SDimitry Andric  {0, 64, SGPRRegBank},
530b57cec5SDimitry Andric  {0, 128, SGPRRegBank},
540b57cec5SDimitry Andric  {0, 256, SGPRRegBank},
550b57cec5SDimitry Andric  {0, 512, SGPRRegBank},
568bcb0991SDimitry Andric  {0, 1024, SGPRRegBank},
570b57cec5SDimitry Andric
580b57cec5SDimitry Andric  {0, 1,  VGPRRegBank}, // VGPR begin
590b57cec5SDimitry Andric  {0, 16, VGPRRegBank},
600b57cec5SDimitry Andric  {0, 32, VGPRRegBank},
610b57cec5SDimitry Andric  {0, 64, VGPRRegBank},
620b57cec5SDimitry Andric  {0, 128, VGPRRegBank},
630b57cec5SDimitry Andric  {0, 256, VGPRRegBank},
640b57cec5SDimitry Andric  {0, 512, VGPRRegBank},
658bcb0991SDimitry Andric  {0, 1024, VGPRRegBank},
660b57cec5SDimitry Andric  {0, 96, SGPRRegBank},
67480093f4SDimitry Andric  {0, 96, VGPRRegBank},
68480093f4SDimitry Andric  {0, 96, AGPRRegBank},
69480093f4SDimitry Andric
70480093f4SDimitry Andric  {0, 32, AGPRRegBank}, // AGPR begin
71480093f4SDimitry Andric  {0, 64, AGPRRegBank},
72480093f4SDimitry Andric  {0, 128, AGPRRegBank},
73*e8d8bef9SDimitry Andric  {0, 256, AGPRRegBank},
74480093f4SDimitry Andric  {0, 512, AGPRRegBank},
75480093f4SDimitry Andric  {0, 1024, AGPRRegBank}
760b57cec5SDimitry Andric};
770b57cec5SDimitry Andric
780b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping ValMappings[] {
79480093f4SDimitry Andric  // VCC
800b57cec5SDimitry Andric  {&PartMappings[0], 1},
810b57cec5SDimitry Andric
820b57cec5SDimitry Andric  // SGPRs
83480093f4SDimitry Andric  {&PartMappings[1], 1}, // 1
840b57cec5SDimitry Andric  {nullptr, 0}, // Illegal power of 2 sizes
850b57cec5SDimitry Andric  {nullptr, 0},
860b57cec5SDimitry Andric  {nullptr, 0},
87480093f4SDimitry Andric  {&PartMappings[2], 1}, // 16
88480093f4SDimitry Andric  {&PartMappings[3], 1}, // 32
89480093f4SDimitry Andric  {&PartMappings[4], 1}, // 64
90480093f4SDimitry Andric  {&PartMappings[5], 1}, // 128
91480093f4SDimitry Andric  {&PartMappings[6], 1}, // 256
92480093f4SDimitry Andric  {&PartMappings[7], 1}, // 512
93480093f4SDimitry Andric  {&PartMappings[8], 1}, // 1024
940b57cec5SDimitry Andric
950b57cec5SDimitry Andric  // VGPRs
96480093f4SDimitry Andric  {&PartMappings[9], 1}, // 1
970b57cec5SDimitry Andric  {nullptr, 0},
980b57cec5SDimitry Andric  {nullptr, 0},
990b57cec5SDimitry Andric  {nullptr, 0},
100480093f4SDimitry Andric  {&PartMappings[10], 1}, // 16
101480093f4SDimitry Andric  {&PartMappings[11], 1}, // 32
102480093f4SDimitry Andric  {&PartMappings[12], 1}, // 64
103480093f4SDimitry Andric  {&PartMappings[13], 1}, // 128
104480093f4SDimitry Andric  {&PartMappings[14], 1}, // 256
105480093f4SDimitry Andric  {&PartMappings[15], 1}, // 512
106480093f4SDimitry Andric  {&PartMappings[16], 1}, // 1024
107480093f4SDimitry Andric  {&PartMappings[17], 1},
1088bcb0991SDimitry Andric  {&PartMappings[18], 1},
109480093f4SDimitry Andric  {&PartMappings[19], 1},
110480093f4SDimitry Andric
111480093f4SDimitry Andric  // AGPRs
112480093f4SDimitry Andric  {nullptr, 0},
113480093f4SDimitry Andric  {nullptr, 0},
114480093f4SDimitry Andric  {nullptr, 0},
115480093f4SDimitry Andric  {nullptr, 0},
116480093f4SDimitry Andric  {nullptr, 0},
117480093f4SDimitry Andric  {&PartMappings[20], 1}, // 32
118480093f4SDimitry Andric  {&PartMappings[21], 1}, // 64
119480093f4SDimitry Andric  {&PartMappings[22], 1}, // 128
120*e8d8bef9SDimitry Andric  {&PartMappings[23], 1}, // 256
121*e8d8bef9SDimitry Andric  {&PartMappings[24], 1}, // 512
122*e8d8bef9SDimitry Andric  {&PartMappings[25], 1}  // 1024
1230b57cec5SDimitry Andric};
1240b57cec5SDimitry Andric
1250b57cec5SDimitry Andricconst RegisterBankInfo::PartialMapping SGPROnly64BreakDown[] {
1268bcb0991SDimitry Andric  {0, 32, SGPRRegBank}, // 32-bit op
1278bcb0991SDimitry Andric  {0, 32, SGPRRegBank}, // 2x32-bit op
1280b57cec5SDimitry Andric  {32, 32, SGPRRegBank},
1298bcb0991SDimitry Andric  {0, 64, SGPRRegBank}, // <2x32-bit> op
1300b57cec5SDimitry Andric
1318bcb0991SDimitry Andric  {0, 32, VGPRRegBank}, // 32-bit op
1328bcb0991SDimitry Andric  {0, 32, VGPRRegBank}, // 2x32-bit op
1330b57cec5SDimitry Andric  {32, 32, VGPRRegBank},
1340b57cec5SDimitry Andric};
1350b57cec5SDimitry Andric
1360b57cec5SDimitry Andric
1375ffd83dbSDimitry Andric// For some instructions which can operate 64-bit only for the scalar
1385ffd83dbSDimitry Andric// version. Otherwise, these need to be split into 2 32-bit operations.
1390b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping ValMappingsSGPR64OnlyVGPR32[] {
1400b57cec5SDimitry Andric  /*32-bit sgpr*/     {&SGPROnly64BreakDown[0], 1},
1410b57cec5SDimitry Andric  /*2 x 32-bit sgpr*/ {&SGPROnly64BreakDown[1], 2},
1420b57cec5SDimitry Andric  /*64-bit sgpr */    {&SGPROnly64BreakDown[3], 1},
1430b57cec5SDimitry Andric
1440b57cec5SDimitry Andric  /*32-bit vgpr*/     {&SGPROnly64BreakDown[4], 1},
1450b57cec5SDimitry Andric  /*2 x 32-bit vgpr*/ {&SGPROnly64BreakDown[5], 2}
1460b57cec5SDimitry Andric};
1470b57cec5SDimitry Andric
1480b57cec5SDimitry Andricenum ValueMappingIdx {
149480093f4SDimitry Andric  SGPRStartIdx = 1,
150480093f4SDimitry Andric  VGPRStartIdx = 12,
151480093f4SDimitry Andric  AGPRStartIdx = 26
1520b57cec5SDimitry Andric};
1530b57cec5SDimitry Andric
1540b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping *getValueMapping(unsigned BankID,
1550b57cec5SDimitry Andric                                                      unsigned Size) {
1560b57cec5SDimitry Andric  unsigned Idx;
1570b57cec5SDimitry Andric  switch (Size) {
1580b57cec5SDimitry Andric  case 1:
1590b57cec5SDimitry Andric    if (BankID == AMDGPU::VCCRegBankID)
160480093f4SDimitry Andric      return &ValMappings[0];
1610b57cec5SDimitry Andric
1620b57cec5SDimitry Andric    Idx = BankID == AMDGPU::SGPRRegBankID ? PM_SGPR1 : PM_VGPR1;
1630b57cec5SDimitry Andric    break;
1640b57cec5SDimitry Andric  case 96:
165480093f4SDimitry Andric    switch (BankID) {
166480093f4SDimitry Andric      case AMDGPU::VGPRRegBankID:
167480093f4SDimitry Andric        Idx = PM_VGPR96;
168480093f4SDimitry Andric        break;
169480093f4SDimitry Andric      case AMDGPU::SGPRRegBankID:
170480093f4SDimitry Andric        Idx = PM_SGPR96;
171480093f4SDimitry Andric        break;
172480093f4SDimitry Andric      case AMDGPU::AGPRRegBankID:
173480093f4SDimitry Andric        Idx = PM_AGPR96;
174480093f4SDimitry Andric        break;
175480093f4SDimitry Andric      default: llvm_unreachable("Invalid register bank");
176480093f4SDimitry Andric    }
1770b57cec5SDimitry Andric    break;
1780b57cec5SDimitry Andric  default:
179480093f4SDimitry Andric    switch (BankID) {
180480093f4SDimitry Andric      case AMDGPU::VGPRRegBankID:
181480093f4SDimitry Andric        Idx = VGPRStartIdx;
182480093f4SDimitry Andric        break;
183480093f4SDimitry Andric      case AMDGPU::SGPRRegBankID:
184480093f4SDimitry Andric        Idx = SGPRStartIdx;
185480093f4SDimitry Andric        break;
186480093f4SDimitry Andric      case AMDGPU::AGPRRegBankID:
187480093f4SDimitry Andric        Idx = AGPRStartIdx;
188480093f4SDimitry Andric        break;
189480093f4SDimitry Andric      default: llvm_unreachable("Invalid register bank");
190480093f4SDimitry Andric    }
1910b57cec5SDimitry Andric    Idx += Log2_32_Ceil(Size);
1920b57cec5SDimitry Andric    break;
1930b57cec5SDimitry Andric  }
1940b57cec5SDimitry Andric
1950b57cec5SDimitry Andric  assert(Log2_32_Ceil(Size) == Log2_32_Ceil(ValMappings[Idx].BreakDown->Length));
1960b57cec5SDimitry Andric  assert(BankID == ValMappings[Idx].BreakDown->RegBank->getID());
1970b57cec5SDimitry Andric
1980b57cec5SDimitry Andric  return &ValMappings[Idx];
1990b57cec5SDimitry Andric}
2000b57cec5SDimitry Andric
2010b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping *getValueMappingSGPR64Only(unsigned BankID,
2020b57cec5SDimitry Andric                                                                unsigned Size) {
2030b57cec5SDimitry Andric  if (Size != 64)
2040b57cec5SDimitry Andric    return getValueMapping(BankID, Size);
2050b57cec5SDimitry Andric
2060b57cec5SDimitry Andric  if (BankID == AMDGPU::VGPRRegBankID)
2070b57cec5SDimitry Andric    return &ValMappingsSGPR64OnlyVGPR32[4];
2080b57cec5SDimitry Andric
2090b57cec5SDimitry Andric  assert(BankID == AMDGPU::SGPRRegBankID);
2100b57cec5SDimitry Andric  return &ValMappingsSGPR64OnlyVGPR32[2];
2110b57cec5SDimitry Andric}
2120b57cec5SDimitry Andric
2135ffd83dbSDimitry Andric/// Split any 64-bit value into 2 32-bit pieces. Unlike
2145ffd83dbSDimitry Andric/// getValueMappingSGPR64Only, this splits both VGPRs and SGPRs.
2155ffd83dbSDimitry Andricconst RegisterBankInfo::ValueMapping *getValueMappingSplit64(unsigned BankID,
2165ffd83dbSDimitry Andric                                                             unsigned Size) {
2175ffd83dbSDimitry Andric  assert(Size == 64);
2185ffd83dbSDimitry Andric  if (BankID == AMDGPU::VGPRRegBankID)
2195ffd83dbSDimitry Andric    return &ValMappingsSGPR64OnlyVGPR32[4];
2200b57cec5SDimitry Andric
2215ffd83dbSDimitry Andric  assert(BankID == AMDGPU::SGPRRegBankID);
2225ffd83dbSDimitry Andric  return &ValMappingsSGPR64OnlyVGPR32[1];
2230b57cec5SDimitry Andric}
2240b57cec5SDimitry Andric
2250b57cec5SDimitry Andric
2260b57cec5SDimitry Andric} // End AMDGPU namespace.
2270b57cec5SDimitry Andric} // End llvm namespace.
228