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, 180b57cec5SDimitry Andric PM_SGPR1 = 2, 190b57cec5SDimitry Andric PM_SGPR16 = 6, 200b57cec5SDimitry Andric PM_SGPR32 = 7, 210b57cec5SDimitry Andric PM_SGPR64 = 8, 220b57cec5SDimitry Andric PM_SGPR128 = 9, 230b57cec5SDimitry Andric PM_SGPR256 = 10, 240b57cec5SDimitry Andric PM_SGPR512 = 11, 25*8bcb0991SDimitry Andric PM_SGPR1024 = 12, 26*8bcb0991SDimitry Andric PM_VGPR1 = 13, 27*8bcb0991SDimitry Andric PM_VGPR16 = 17, 28*8bcb0991SDimitry Andric PM_VGPR32 = 18, 29*8bcb0991SDimitry Andric PM_VGPR64 = 19, 30*8bcb0991SDimitry Andric PM_VGPR128 = 20, 31*8bcb0991SDimitry Andric PM_VGPR256 = 21, 32*8bcb0991SDimitry Andric PM_VGPR512 = 22, 33*8bcb0991SDimitry Andric PM_VGPR1024 = 23, 34*8bcb0991SDimitry Andric PM_SGPR96 = 24, 35*8bcb0991SDimitry Andric PM_VGPR96 = 25 360b57cec5SDimitry Andric}; 370b57cec5SDimitry Andric 380b57cec5SDimitry Andricconst RegisterBankInfo::PartialMapping PartMappings[] { 390b57cec5SDimitry Andric // StartIdx, Length, RegBank 400b57cec5SDimitry Andric {0, 1, SCCRegBank}, 410b57cec5SDimitry Andric {0, 1, VCCRegBank}, 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric {0, 1, SGPRRegBank}, // SGPR begin 440b57cec5SDimitry Andric {0, 16, SGPRRegBank}, 450b57cec5SDimitry Andric {0, 32, SGPRRegBank}, 460b57cec5SDimitry Andric {0, 64, SGPRRegBank}, 470b57cec5SDimitry Andric {0, 128, SGPRRegBank}, 480b57cec5SDimitry Andric {0, 256, SGPRRegBank}, 490b57cec5SDimitry Andric {0, 512, SGPRRegBank}, 50*8bcb0991SDimitry Andric {0, 1024, SGPRRegBank}, 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric {0, 1, VGPRRegBank}, // VGPR begin 530b57cec5SDimitry Andric {0, 16, VGPRRegBank}, 540b57cec5SDimitry Andric {0, 32, VGPRRegBank}, 550b57cec5SDimitry Andric {0, 64, VGPRRegBank}, 560b57cec5SDimitry Andric {0, 128, VGPRRegBank}, 570b57cec5SDimitry Andric {0, 256, VGPRRegBank}, 580b57cec5SDimitry Andric {0, 512, VGPRRegBank}, 59*8bcb0991SDimitry Andric {0, 1024, VGPRRegBank}, 600b57cec5SDimitry Andric {0, 96, SGPRRegBank}, 61*8bcb0991SDimitry Andric {0, 96, VGPRRegBank} 620b57cec5SDimitry Andric}; 630b57cec5SDimitry Andric 640b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping ValMappings[] { 650b57cec5SDimitry Andric // SCC 660b57cec5SDimitry Andric {&PartMappings[0], 1}, 670b57cec5SDimitry Andric 680b57cec5SDimitry Andric // VCC 690b57cec5SDimitry Andric {&PartMappings[1], 1}, 700b57cec5SDimitry Andric 710b57cec5SDimitry Andric // SGPRs 72*8bcb0991SDimitry Andric {&PartMappings[2], 1}, // 1 730b57cec5SDimitry Andric {nullptr, 0}, // Illegal power of 2 sizes 740b57cec5SDimitry Andric {nullptr, 0}, 750b57cec5SDimitry Andric {nullptr, 0}, 76*8bcb0991SDimitry Andric {&PartMappings[3], 1}, // 16 77*8bcb0991SDimitry Andric {&PartMappings[4], 1}, // 32 78*8bcb0991SDimitry Andric {&PartMappings[5], 1}, // 64 79*8bcb0991SDimitry Andric {&PartMappings[6], 1}, // 128 80*8bcb0991SDimitry Andric {&PartMappings[7], 1}, // 256 81*8bcb0991SDimitry Andric {&PartMappings[8], 1}, // 512 82*8bcb0991SDimitry Andric {&PartMappings[9], 1}, // 1024 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric // VGPRs 85*8bcb0991SDimitry Andric {&PartMappings[10], 1}, // 1 860b57cec5SDimitry Andric {nullptr, 0}, 870b57cec5SDimitry Andric {nullptr, 0}, 880b57cec5SDimitry Andric {nullptr, 0}, 89*8bcb0991SDimitry Andric {&PartMappings[11], 1}, // 16 90*8bcb0991SDimitry Andric {&PartMappings[12], 1}, // 32 91*8bcb0991SDimitry Andric {&PartMappings[13], 1}, // 64 92*8bcb0991SDimitry Andric {&PartMappings[14], 1}, // 128 93*8bcb0991SDimitry Andric {&PartMappings[15], 1}, // 256 94*8bcb0991SDimitry Andric {&PartMappings[16], 1}, // 512 95*8bcb0991SDimitry Andric {&PartMappings[17], 1}, // 1024 96*8bcb0991SDimitry Andric {&PartMappings[18], 1}, 97*8bcb0991SDimitry Andric {&PartMappings[19], 1} 980b57cec5SDimitry Andric}; 990b57cec5SDimitry Andric 1000b57cec5SDimitry Andricconst RegisterBankInfo::PartialMapping SGPROnly64BreakDown[] { 101*8bcb0991SDimitry Andric {0, 32, SGPRRegBank}, // 32-bit op 102*8bcb0991SDimitry Andric {0, 32, SGPRRegBank}, // 2x32-bit op 1030b57cec5SDimitry Andric {32, 32, SGPRRegBank}, 104*8bcb0991SDimitry Andric {0, 64, SGPRRegBank}, // <2x32-bit> op 1050b57cec5SDimitry Andric 106*8bcb0991SDimitry Andric {0, 32, VGPRRegBank}, // 32-bit op 107*8bcb0991SDimitry Andric {0, 32, VGPRRegBank}, // 2x32-bit op 1080b57cec5SDimitry Andric {32, 32, VGPRRegBank}, 1090b57cec5SDimitry Andric}; 1100b57cec5SDimitry Andric 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andric// For some instructions which can operate 64-bit only for the scalar version. 1130b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping ValMappingsSGPR64OnlyVGPR32[] { 1140b57cec5SDimitry Andric /*32-bit sgpr*/ {&SGPROnly64BreakDown[0], 1}, 1150b57cec5SDimitry Andric /*2 x 32-bit sgpr*/ {&SGPROnly64BreakDown[1], 2}, 1160b57cec5SDimitry Andric /*64-bit sgpr */ {&SGPROnly64BreakDown[3], 1}, 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andric /*32-bit vgpr*/ {&SGPROnly64BreakDown[4], 1}, 1190b57cec5SDimitry Andric /*2 x 32-bit vgpr*/ {&SGPROnly64BreakDown[5], 2} 1200b57cec5SDimitry Andric}; 1210b57cec5SDimitry Andric 1220b57cec5SDimitry Andricenum ValueMappingIdx { 1230b57cec5SDimitry Andric SCCStartIdx = 0, 1240b57cec5SDimitry Andric SGPRStartIdx = 2, 125*8bcb0991SDimitry Andric VGPRStartIdx = 13 1260b57cec5SDimitry Andric}; 1270b57cec5SDimitry Andric 1280b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping *getValueMapping(unsigned BankID, 1290b57cec5SDimitry Andric unsigned Size) { 1300b57cec5SDimitry Andric unsigned Idx; 1310b57cec5SDimitry Andric switch (Size) { 1320b57cec5SDimitry Andric case 1: 1330b57cec5SDimitry Andric if (BankID == AMDGPU::SCCRegBankID) 1340b57cec5SDimitry Andric return &ValMappings[0]; 1350b57cec5SDimitry Andric if (BankID == AMDGPU::VCCRegBankID) 1360b57cec5SDimitry Andric return &ValMappings[1]; 1370b57cec5SDimitry Andric 1380b57cec5SDimitry Andric // 1-bit values not from a compare etc. 1390b57cec5SDimitry Andric Idx = BankID == AMDGPU::SGPRRegBankID ? PM_SGPR1 : PM_VGPR1; 1400b57cec5SDimitry Andric break; 1410b57cec5SDimitry Andric case 96: 1420b57cec5SDimitry Andric assert(BankID != AMDGPU::VCCRegBankID); 1430b57cec5SDimitry Andric Idx = BankID == AMDGPU::SGPRRegBankID ? PM_SGPR96 : PM_VGPR96; 1440b57cec5SDimitry Andric break; 1450b57cec5SDimitry Andric default: 1460b57cec5SDimitry Andric assert(BankID != AMDGPU::VCCRegBankID); 1470b57cec5SDimitry Andric Idx = BankID == AMDGPU::VGPRRegBankID ? VGPRStartIdx : SGPRStartIdx; 1480b57cec5SDimitry Andric Idx += Log2_32_Ceil(Size); 1490b57cec5SDimitry Andric break; 1500b57cec5SDimitry Andric } 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andric assert(Log2_32_Ceil(Size) == Log2_32_Ceil(ValMappings[Idx].BreakDown->Length)); 1530b57cec5SDimitry Andric assert(BankID == ValMappings[Idx].BreakDown->RegBank->getID()); 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andric return &ValMappings[Idx]; 1560b57cec5SDimitry Andric} 1570b57cec5SDimitry Andric 1580b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping *getValueMappingSGPR64Only(unsigned BankID, 1590b57cec5SDimitry Andric unsigned Size) { 1600b57cec5SDimitry Andric if (Size != 64) 1610b57cec5SDimitry Andric return getValueMapping(BankID, Size); 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andric if (BankID == AMDGPU::VGPRRegBankID) 1640b57cec5SDimitry Andric return &ValMappingsSGPR64OnlyVGPR32[4]; 1650b57cec5SDimitry Andric 1660b57cec5SDimitry Andric assert(BankID == AMDGPU::SGPRRegBankID); 1670b57cec5SDimitry Andric return &ValMappingsSGPR64OnlyVGPR32[2]; 1680b57cec5SDimitry Andric} 1690b57cec5SDimitry Andric 1700b57cec5SDimitry Andricconst RegisterBankInfo::PartialMapping LoadSGPROnlyBreakDown[] { 1710b57cec5SDimitry Andric /* 256-bit load */ {0, 256, SGPRRegBank}, 1720b57cec5SDimitry Andric /* 512-bit load */ {0, 512, SGPRRegBank}, 1730b57cec5SDimitry Andric /* 8 32-bit loads */ {0, 32, VGPRRegBank}, {32, 32, VGPRRegBank}, 1740b57cec5SDimitry Andric {64, 32, VGPRRegBank}, {96, 32, VGPRRegBank}, 1750b57cec5SDimitry Andric {128, 32, VGPRRegBank}, {160, 32, VGPRRegBank}, 1760b57cec5SDimitry Andric {192, 32, VGPRRegBank}, {224, 32, VGPRRegBank}, 1770b57cec5SDimitry Andric /* 16 32-bit loads */ {0, 32, VGPRRegBank}, {32, 32, VGPRRegBank}, 1780b57cec5SDimitry Andric {64, 32, VGPRRegBank}, {96, 32, VGPRRegBank}, 1790b57cec5SDimitry Andric {128, 32, VGPRRegBank}, {160, 32, VGPRRegBank}, 1800b57cec5SDimitry Andric {192, 32, VGPRRegBank}, {224, 32, VGPRRegBank}, 1810b57cec5SDimitry Andric {256, 32, VGPRRegBank}, {288, 32, VGPRRegBank}, 1820b57cec5SDimitry Andric {320, 32, VGPRRegBank}, {352, 32, VGPRRegBank}, 1830b57cec5SDimitry Andric {384, 32, VGPRRegBank}, {416, 32, VGPRRegBank}, 1840b57cec5SDimitry Andric {448, 32, VGPRRegBank}, {480, 32, VGPRRegBank}, 1850b57cec5SDimitry Andric /* 4 64-bit loads */ {0, 64, VGPRRegBank}, {64, 64, VGPRRegBank}, 1860b57cec5SDimitry Andric {128, 64, VGPRRegBank}, {192, 64, VGPRRegBank}, 1870b57cec5SDimitry Andric /* 8 64-bit loads */ {0, 64, VGPRRegBank}, {64, 64, VGPRRegBank}, 1880b57cec5SDimitry Andric {128, 64, VGPRRegBank}, {192, 64, VGPRRegBank}, 1890b57cec5SDimitry Andric {256, 64, VGPRRegBank}, {320, 64, VGPRRegBank}, 1900b57cec5SDimitry Andric {384, 64, VGPRRegBank}, {448, 64, VGPRRegBank}, 1910b57cec5SDimitry Andric 1920b57cec5SDimitry Andric /* FIXME: The generic register bank select does not support complex 1930b57cec5SDimitry Andric * break downs where the number of vector elements does not equal the 1940b57cec5SDimitry Andric * number of breakdowns. 1950b57cec5SDimitry Andric * FIXME: register bank select now tries to handle complex break downs, 1960b57cec5SDimitry Andric * but it emits an illegal instruction: 1970b57cec5SDimitry Andric * %1:vgpr(<8 x s32>) = G_CONCAT_VECTORS %2:vgpr(s128), %3:vgpr(s128) 1980b57cec5SDimitry Andric */ 1990b57cec5SDimitry Andric /* 2 128-bit loads */ {0, 128, VGPRRegBank}, {128, 128, VGPRRegBank}, 2000b57cec5SDimitry Andric /* 4 128-bit loads */ {0, 128, VGPRRegBank}, {128, 128, VGPRRegBank}, 2010b57cec5SDimitry Andric {256, 128, VGPRRegBank}, {384, 128, VGPRRegBank} 2020b57cec5SDimitry Andric}; 2030b57cec5SDimitry Andric 2040b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping ValMappingsLoadSGPROnly[] { 2050b57cec5SDimitry Andric /* 256-bit load */ {&LoadSGPROnlyBreakDown[0], 1}, 2060b57cec5SDimitry Andric /* 512-bit load */ {&LoadSGPROnlyBreakDown[1], 1}, 2070b57cec5SDimitry Andric /* <8 x i32> load */ {&LoadSGPROnlyBreakDown[2], 8}, 2080b57cec5SDimitry Andric /* <16 x i32> load */ {&LoadSGPROnlyBreakDown[10], 16}, 2090b57cec5SDimitry Andric /* <4 x i64> load */ {&LoadSGPROnlyBreakDown[26], 4}, 2100b57cec5SDimitry Andric /* <8 x i64> load */ {&LoadSGPROnlyBreakDown[30], 8} 2110b57cec5SDimitry Andric}; 2120b57cec5SDimitry Andric 2130b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping * 2140b57cec5SDimitry AndricgetValueMappingLoadSGPROnly(unsigned BankID, LLT SizeTy) { 2150b57cec5SDimitry Andric unsigned Size = SizeTy.getSizeInBits(); 2160b57cec5SDimitry Andric if (Size < 256 || BankID == AMDGPU::SGPRRegBankID) 2170b57cec5SDimitry Andric return getValueMapping(BankID, Size); 2180b57cec5SDimitry Andric 2190b57cec5SDimitry Andric assert((Size == 256 || Size == 512) && BankID == AMDGPU::VGPRRegBankID); 2200b57cec5SDimitry Andric 2210b57cec5SDimitry Andric // Default to using the non-split ValueMappings, we will use these if 2220b57cec5SDimitry Andric // the register bank is SGPR or if we don't know how to handle the vector 2230b57cec5SDimitry Andric // type. 2240b57cec5SDimitry Andric unsigned Idx = Size == 256 ? 0 : 1; 2250b57cec5SDimitry Andric 2260b57cec5SDimitry Andric // We need to split this load if it has a vgpr pointer. 2270b57cec5SDimitry Andric if (BankID == AMDGPU::VGPRRegBankID) { 2280b57cec5SDimitry Andric if (SizeTy == LLT::vector(8, 32)) 2290b57cec5SDimitry Andric Idx = 2; 2300b57cec5SDimitry Andric else if (SizeTy == LLT::vector(16, 32)) 2310b57cec5SDimitry Andric Idx = 3; 2320b57cec5SDimitry Andric else if (SizeTy == LLT::vector(4, 64)) 2330b57cec5SDimitry Andric Idx = 4; 2340b57cec5SDimitry Andric else if (SizeTy == LLT::vector(8, 64)) 2350b57cec5SDimitry Andric Idx = 5; 2360b57cec5SDimitry Andric } 2370b57cec5SDimitry Andric 2380b57cec5SDimitry Andric return &ValMappingsLoadSGPROnly[Idx]; 2390b57cec5SDimitry Andric} 2400b57cec5SDimitry Andric 2410b57cec5SDimitry Andric 2420b57cec5SDimitry Andric} // End AMDGPU namespace. 2430b57cec5SDimitry Andric} // End llvm namespace. 244