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, 18*480093f4SDimitry Andric PM_SGPR1 = 1, 19*480093f4SDimitry Andric PM_SGPR16 = 5, 20*480093f4SDimitry Andric PM_SGPR32 = 6, 21*480093f4SDimitry Andric PM_SGPR64 = 7, 22*480093f4SDimitry Andric PM_SGPR128 = 8, 23*480093f4SDimitry Andric PM_SGPR256 = 9, 24*480093f4SDimitry Andric PM_SGPR512 = 10, 25*480093f4SDimitry Andric PM_SGPR1024 = 11, 26*480093f4SDimitry Andric PM_VGPR1 = 12, 27*480093f4SDimitry Andric PM_VGPR16 = 16, 28*480093f4SDimitry Andric PM_VGPR32 = 17, 29*480093f4SDimitry Andric PM_VGPR64 = 18, 30*480093f4SDimitry Andric PM_VGPR128 = 19, 31*480093f4SDimitry Andric PM_VGPR256 = 20, 32*480093f4SDimitry Andric PM_VGPR512 = 21, 33*480093f4SDimitry Andric PM_VGPR1024 = 22, 34*480093f4SDimitry Andric PM_SGPR96 = 23, 35*480093f4SDimitry Andric PM_VGPR96 = 24, 36*480093f4SDimitry Andric PM_AGPR96 = 25, 37*480093f4SDimitry Andric PM_AGPR32 = 31, 38*480093f4SDimitry Andric PM_AGPR64 = 32, 39*480093f4SDimitry Andric PM_AGPR128 = 33, 40*480093f4SDimitry Andric PM_AGPR512 = 34, 41*480093f4SDimitry Andric PM_AGPR1024 = 35 420b57cec5SDimitry Andric}; 430b57cec5SDimitry Andric 440b57cec5SDimitry Andricconst RegisterBankInfo::PartialMapping PartMappings[] { 450b57cec5SDimitry Andric // StartIdx, Length, RegBank 460b57cec5SDimitry Andric {0, 1, VCCRegBank}, 470b57cec5SDimitry Andric 480b57cec5SDimitry Andric {0, 1, SGPRRegBank}, // SGPR begin 490b57cec5SDimitry Andric {0, 16, SGPRRegBank}, 500b57cec5SDimitry Andric {0, 32, SGPRRegBank}, 510b57cec5SDimitry Andric {0, 64, SGPRRegBank}, 520b57cec5SDimitry Andric {0, 128, SGPRRegBank}, 530b57cec5SDimitry Andric {0, 256, SGPRRegBank}, 540b57cec5SDimitry Andric {0, 512, SGPRRegBank}, 558bcb0991SDimitry Andric {0, 1024, SGPRRegBank}, 560b57cec5SDimitry Andric 570b57cec5SDimitry Andric {0, 1, VGPRRegBank}, // VGPR begin 580b57cec5SDimitry Andric {0, 16, VGPRRegBank}, 590b57cec5SDimitry Andric {0, 32, VGPRRegBank}, 600b57cec5SDimitry Andric {0, 64, VGPRRegBank}, 610b57cec5SDimitry Andric {0, 128, VGPRRegBank}, 620b57cec5SDimitry Andric {0, 256, VGPRRegBank}, 630b57cec5SDimitry Andric {0, 512, VGPRRegBank}, 648bcb0991SDimitry Andric {0, 1024, VGPRRegBank}, 650b57cec5SDimitry Andric {0, 96, SGPRRegBank}, 66*480093f4SDimitry Andric {0, 96, VGPRRegBank}, 67*480093f4SDimitry Andric {0, 96, AGPRRegBank}, 68*480093f4SDimitry Andric 69*480093f4SDimitry Andric {0, 32, AGPRRegBank}, // AGPR begin 70*480093f4SDimitry Andric {0, 64, AGPRRegBank}, 71*480093f4SDimitry Andric {0, 128, AGPRRegBank}, 72*480093f4SDimitry Andric {0, 512, AGPRRegBank}, 73*480093f4SDimitry Andric {0, 1024, AGPRRegBank} 740b57cec5SDimitry Andric}; 750b57cec5SDimitry Andric 760b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping ValMappings[] { 77*480093f4SDimitry Andric // VCC 780b57cec5SDimitry Andric {&PartMappings[0], 1}, 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric // SGPRs 81*480093f4SDimitry Andric {&PartMappings[1], 1}, // 1 820b57cec5SDimitry Andric {nullptr, 0}, // Illegal power of 2 sizes 830b57cec5SDimitry Andric {nullptr, 0}, 840b57cec5SDimitry Andric {nullptr, 0}, 85*480093f4SDimitry Andric {&PartMappings[2], 1}, // 16 86*480093f4SDimitry Andric {&PartMappings[3], 1}, // 32 87*480093f4SDimitry Andric {&PartMappings[4], 1}, // 64 88*480093f4SDimitry Andric {&PartMappings[5], 1}, // 128 89*480093f4SDimitry Andric {&PartMappings[6], 1}, // 256 90*480093f4SDimitry Andric {&PartMappings[7], 1}, // 512 91*480093f4SDimitry Andric {&PartMappings[8], 1}, // 1024 920b57cec5SDimitry Andric 930b57cec5SDimitry Andric // VGPRs 94*480093f4SDimitry Andric {&PartMappings[9], 1}, // 1 950b57cec5SDimitry Andric {nullptr, 0}, 960b57cec5SDimitry Andric {nullptr, 0}, 970b57cec5SDimitry Andric {nullptr, 0}, 98*480093f4SDimitry Andric {&PartMappings[10], 1}, // 16 99*480093f4SDimitry Andric {&PartMappings[11], 1}, // 32 100*480093f4SDimitry Andric {&PartMappings[12], 1}, // 64 101*480093f4SDimitry Andric {&PartMappings[13], 1}, // 128 102*480093f4SDimitry Andric {&PartMappings[14], 1}, // 256 103*480093f4SDimitry Andric {&PartMappings[15], 1}, // 512 104*480093f4SDimitry Andric {&PartMappings[16], 1}, // 1024 105*480093f4SDimitry Andric {&PartMappings[17], 1}, 1068bcb0991SDimitry Andric {&PartMappings[18], 1}, 107*480093f4SDimitry Andric {&PartMappings[19], 1}, 108*480093f4SDimitry Andric 109*480093f4SDimitry Andric // AGPRs 110*480093f4SDimitry Andric {nullptr, 0}, 111*480093f4SDimitry Andric {nullptr, 0}, 112*480093f4SDimitry Andric {nullptr, 0}, 113*480093f4SDimitry Andric {nullptr, 0}, 114*480093f4SDimitry Andric {nullptr, 0}, 115*480093f4SDimitry Andric {&PartMappings[20], 1}, // 32 116*480093f4SDimitry Andric {&PartMappings[21], 1}, // 64 117*480093f4SDimitry Andric {&PartMappings[22], 1}, // 128 118*480093f4SDimitry Andric {nullptr, 0}, 119*480093f4SDimitry Andric {&PartMappings[23], 1}, // 512 120*480093f4SDimitry Andric {&PartMappings[24], 1} // 1024 1210b57cec5SDimitry Andric}; 1220b57cec5SDimitry Andric 1230b57cec5SDimitry Andricconst RegisterBankInfo::PartialMapping SGPROnly64BreakDown[] { 1248bcb0991SDimitry Andric {0, 32, SGPRRegBank}, // 32-bit op 1258bcb0991SDimitry Andric {0, 32, SGPRRegBank}, // 2x32-bit op 1260b57cec5SDimitry Andric {32, 32, SGPRRegBank}, 1278bcb0991SDimitry Andric {0, 64, SGPRRegBank}, // <2x32-bit> op 1280b57cec5SDimitry Andric 1298bcb0991SDimitry Andric {0, 32, VGPRRegBank}, // 32-bit op 1308bcb0991SDimitry Andric {0, 32, VGPRRegBank}, // 2x32-bit op 1310b57cec5SDimitry Andric {32, 32, VGPRRegBank}, 1320b57cec5SDimitry Andric}; 1330b57cec5SDimitry Andric 1340b57cec5SDimitry Andric 1350b57cec5SDimitry Andric// For some instructions which can operate 64-bit only for the scalar version. 1360b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping ValMappingsSGPR64OnlyVGPR32[] { 1370b57cec5SDimitry Andric /*32-bit sgpr*/ {&SGPROnly64BreakDown[0], 1}, 1380b57cec5SDimitry Andric /*2 x 32-bit sgpr*/ {&SGPROnly64BreakDown[1], 2}, 1390b57cec5SDimitry Andric /*64-bit sgpr */ {&SGPROnly64BreakDown[3], 1}, 1400b57cec5SDimitry Andric 1410b57cec5SDimitry Andric /*32-bit vgpr*/ {&SGPROnly64BreakDown[4], 1}, 1420b57cec5SDimitry Andric /*2 x 32-bit vgpr*/ {&SGPROnly64BreakDown[5], 2} 1430b57cec5SDimitry Andric}; 1440b57cec5SDimitry Andric 1450b57cec5SDimitry Andricenum ValueMappingIdx { 146*480093f4SDimitry Andric SGPRStartIdx = 1, 147*480093f4SDimitry Andric VGPRStartIdx = 12, 148*480093f4SDimitry Andric AGPRStartIdx = 26 1490b57cec5SDimitry Andric}; 1500b57cec5SDimitry Andric 1510b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping *getValueMapping(unsigned BankID, 1520b57cec5SDimitry Andric unsigned Size) { 1530b57cec5SDimitry Andric unsigned Idx; 1540b57cec5SDimitry Andric switch (Size) { 1550b57cec5SDimitry Andric case 1: 1560b57cec5SDimitry Andric if (BankID == AMDGPU::VCCRegBankID) 157*480093f4SDimitry Andric return &ValMappings[0]; 1580b57cec5SDimitry Andric 1590b57cec5SDimitry Andric Idx = BankID == AMDGPU::SGPRRegBankID ? PM_SGPR1 : PM_VGPR1; 1600b57cec5SDimitry Andric break; 1610b57cec5SDimitry Andric case 96: 162*480093f4SDimitry Andric switch (BankID) { 163*480093f4SDimitry Andric case AMDGPU::VGPRRegBankID: 164*480093f4SDimitry Andric Idx = PM_VGPR96; 165*480093f4SDimitry Andric break; 166*480093f4SDimitry Andric case AMDGPU::SGPRRegBankID: 167*480093f4SDimitry Andric Idx = PM_SGPR96; 168*480093f4SDimitry Andric break; 169*480093f4SDimitry Andric case AMDGPU::AGPRRegBankID: 170*480093f4SDimitry Andric Idx = PM_AGPR96; 171*480093f4SDimitry Andric break; 172*480093f4SDimitry Andric default: llvm_unreachable("Invalid register bank"); 173*480093f4SDimitry Andric } 1740b57cec5SDimitry Andric break; 1750b57cec5SDimitry Andric default: 176*480093f4SDimitry Andric switch (BankID) { 177*480093f4SDimitry Andric case AMDGPU::VGPRRegBankID: 178*480093f4SDimitry Andric Idx = VGPRStartIdx; 179*480093f4SDimitry Andric break; 180*480093f4SDimitry Andric case AMDGPU::SGPRRegBankID: 181*480093f4SDimitry Andric Idx = SGPRStartIdx; 182*480093f4SDimitry Andric break; 183*480093f4SDimitry Andric case AMDGPU::AGPRRegBankID: 184*480093f4SDimitry Andric Idx = AGPRStartIdx; 185*480093f4SDimitry Andric break; 186*480093f4SDimitry Andric default: llvm_unreachable("Invalid register bank"); 187*480093f4SDimitry Andric } 1880b57cec5SDimitry Andric Idx += Log2_32_Ceil(Size); 1890b57cec5SDimitry Andric break; 1900b57cec5SDimitry Andric } 1910b57cec5SDimitry Andric 1920b57cec5SDimitry Andric assert(Log2_32_Ceil(Size) == Log2_32_Ceil(ValMappings[Idx].BreakDown->Length)); 1930b57cec5SDimitry Andric assert(BankID == ValMappings[Idx].BreakDown->RegBank->getID()); 1940b57cec5SDimitry Andric 1950b57cec5SDimitry Andric return &ValMappings[Idx]; 1960b57cec5SDimitry Andric} 1970b57cec5SDimitry Andric 1980b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping *getValueMappingSGPR64Only(unsigned BankID, 1990b57cec5SDimitry Andric unsigned Size) { 2000b57cec5SDimitry Andric if (Size != 64) 2010b57cec5SDimitry Andric return getValueMapping(BankID, Size); 2020b57cec5SDimitry Andric 2030b57cec5SDimitry Andric if (BankID == AMDGPU::VGPRRegBankID) 2040b57cec5SDimitry Andric return &ValMappingsSGPR64OnlyVGPR32[4]; 2050b57cec5SDimitry Andric 2060b57cec5SDimitry Andric assert(BankID == AMDGPU::SGPRRegBankID); 2070b57cec5SDimitry Andric return &ValMappingsSGPR64OnlyVGPR32[2]; 2080b57cec5SDimitry Andric} 2090b57cec5SDimitry Andric 2100b57cec5SDimitry Andricconst RegisterBankInfo::PartialMapping LoadSGPROnlyBreakDown[] { 2110b57cec5SDimitry Andric /* 256-bit load */ {0, 256, SGPRRegBank}, 2120b57cec5SDimitry Andric /* 512-bit load */ {0, 512, SGPRRegBank}, 2130b57cec5SDimitry Andric /* 8 32-bit loads */ {0, 32, VGPRRegBank}, {32, 32, VGPRRegBank}, 2140b57cec5SDimitry Andric {64, 32, VGPRRegBank}, {96, 32, VGPRRegBank}, 2150b57cec5SDimitry Andric {128, 32, VGPRRegBank}, {160, 32, VGPRRegBank}, 2160b57cec5SDimitry Andric {192, 32, VGPRRegBank}, {224, 32, VGPRRegBank}, 2170b57cec5SDimitry Andric /* 16 32-bit loads */ {0, 32, VGPRRegBank}, {32, 32, VGPRRegBank}, 2180b57cec5SDimitry Andric {64, 32, VGPRRegBank}, {96, 32, VGPRRegBank}, 2190b57cec5SDimitry Andric {128, 32, VGPRRegBank}, {160, 32, VGPRRegBank}, 2200b57cec5SDimitry Andric {192, 32, VGPRRegBank}, {224, 32, VGPRRegBank}, 2210b57cec5SDimitry Andric {256, 32, VGPRRegBank}, {288, 32, VGPRRegBank}, 2220b57cec5SDimitry Andric {320, 32, VGPRRegBank}, {352, 32, VGPRRegBank}, 2230b57cec5SDimitry Andric {384, 32, VGPRRegBank}, {416, 32, VGPRRegBank}, 2240b57cec5SDimitry Andric {448, 32, VGPRRegBank}, {480, 32, VGPRRegBank}, 2250b57cec5SDimitry Andric /* 4 64-bit loads */ {0, 64, VGPRRegBank}, {64, 64, VGPRRegBank}, 2260b57cec5SDimitry Andric {128, 64, VGPRRegBank}, {192, 64, VGPRRegBank}, 2270b57cec5SDimitry Andric /* 8 64-bit loads */ {0, 64, VGPRRegBank}, {64, 64, VGPRRegBank}, 2280b57cec5SDimitry Andric {128, 64, VGPRRegBank}, {192, 64, VGPRRegBank}, 2290b57cec5SDimitry Andric {256, 64, VGPRRegBank}, {320, 64, VGPRRegBank}, 2300b57cec5SDimitry Andric {384, 64, VGPRRegBank}, {448, 64, VGPRRegBank}, 2310b57cec5SDimitry Andric 2320b57cec5SDimitry Andric /* FIXME: The generic register bank select does not support complex 2330b57cec5SDimitry Andric * break downs where the number of vector elements does not equal the 2340b57cec5SDimitry Andric * number of breakdowns. 2350b57cec5SDimitry Andric * FIXME: register bank select now tries to handle complex break downs, 2360b57cec5SDimitry Andric * but it emits an illegal instruction: 2370b57cec5SDimitry Andric * %1:vgpr(<8 x s32>) = G_CONCAT_VECTORS %2:vgpr(s128), %3:vgpr(s128) 2380b57cec5SDimitry Andric */ 2390b57cec5SDimitry Andric /* 2 128-bit loads */ {0, 128, VGPRRegBank}, {128, 128, VGPRRegBank}, 2400b57cec5SDimitry Andric /* 4 128-bit loads */ {0, 128, VGPRRegBank}, {128, 128, VGPRRegBank}, 2410b57cec5SDimitry Andric {256, 128, VGPRRegBank}, {384, 128, VGPRRegBank} 2420b57cec5SDimitry Andric}; 2430b57cec5SDimitry Andric 2440b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping ValMappingsLoadSGPROnly[] { 2450b57cec5SDimitry Andric /* 256-bit load */ {&LoadSGPROnlyBreakDown[0], 1}, 2460b57cec5SDimitry Andric /* 512-bit load */ {&LoadSGPROnlyBreakDown[1], 1}, 2470b57cec5SDimitry Andric /* <8 x i32> load */ {&LoadSGPROnlyBreakDown[2], 8}, 2480b57cec5SDimitry Andric /* <16 x i32> load */ {&LoadSGPROnlyBreakDown[10], 16}, 2490b57cec5SDimitry Andric /* <4 x i64> load */ {&LoadSGPROnlyBreakDown[26], 4}, 2500b57cec5SDimitry Andric /* <8 x i64> load */ {&LoadSGPROnlyBreakDown[30], 8} 2510b57cec5SDimitry Andric}; 2520b57cec5SDimitry Andric 2530b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping * 2540b57cec5SDimitry AndricgetValueMappingLoadSGPROnly(unsigned BankID, LLT SizeTy) { 2550b57cec5SDimitry Andric unsigned Size = SizeTy.getSizeInBits(); 2560b57cec5SDimitry Andric if (Size < 256 || BankID == AMDGPU::SGPRRegBankID) 2570b57cec5SDimitry Andric return getValueMapping(BankID, Size); 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andric assert((Size == 256 || Size == 512) && BankID == AMDGPU::VGPRRegBankID); 2600b57cec5SDimitry Andric 2610b57cec5SDimitry Andric // Default to using the non-split ValueMappings, we will use these if 2620b57cec5SDimitry Andric // the register bank is SGPR or if we don't know how to handle the vector 2630b57cec5SDimitry Andric // type. 2640b57cec5SDimitry Andric unsigned Idx = Size == 256 ? 0 : 1; 2650b57cec5SDimitry Andric 2660b57cec5SDimitry Andric // We need to split this load if it has a vgpr pointer. 2670b57cec5SDimitry Andric if (BankID == AMDGPU::VGPRRegBankID) { 2680b57cec5SDimitry Andric if (SizeTy == LLT::vector(8, 32)) 2690b57cec5SDimitry Andric Idx = 2; 2700b57cec5SDimitry Andric else if (SizeTy == LLT::vector(16, 32)) 2710b57cec5SDimitry Andric Idx = 3; 2720b57cec5SDimitry Andric else if (SizeTy == LLT::vector(4, 64)) 2730b57cec5SDimitry Andric Idx = 4; 2740b57cec5SDimitry Andric else if (SizeTy == LLT::vector(8, 64)) 2750b57cec5SDimitry Andric Idx = 5; 2760b57cec5SDimitry Andric } 2770b57cec5SDimitry Andric 2780b57cec5SDimitry Andric return &ValMappingsLoadSGPROnly[Idx]; 2790b57cec5SDimitry Andric} 2800b57cec5SDimitry Andric 2810b57cec5SDimitry Andric 2820b57cec5SDimitry Andric} // End AMDGPU namespace. 2830b57cec5SDimitry Andric} // End llvm namespace. 284