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, 40480093f4SDimitry Andric PM_AGPR512 = 34, 41480093f4SDimitry 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}, 66480093f4SDimitry Andric {0, 96, VGPRRegBank}, 67480093f4SDimitry Andric {0, 96, AGPRRegBank}, 68480093f4SDimitry Andric 69480093f4SDimitry Andric {0, 32, AGPRRegBank}, // AGPR begin 70480093f4SDimitry Andric {0, 64, AGPRRegBank}, 71480093f4SDimitry Andric {0, 128, AGPRRegBank}, 72480093f4SDimitry Andric {0, 512, AGPRRegBank}, 73480093f4SDimitry Andric {0, 1024, AGPRRegBank} 740b57cec5SDimitry Andric}; 750b57cec5SDimitry Andric 760b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping ValMappings[] { 77480093f4SDimitry Andric // VCC 780b57cec5SDimitry Andric {&PartMappings[0], 1}, 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric // SGPRs 81480093f4SDimitry Andric {&PartMappings[1], 1}, // 1 820b57cec5SDimitry Andric {nullptr, 0}, // Illegal power of 2 sizes 830b57cec5SDimitry Andric {nullptr, 0}, 840b57cec5SDimitry Andric {nullptr, 0}, 85480093f4SDimitry Andric {&PartMappings[2], 1}, // 16 86480093f4SDimitry Andric {&PartMappings[3], 1}, // 32 87480093f4SDimitry Andric {&PartMappings[4], 1}, // 64 88480093f4SDimitry Andric {&PartMappings[5], 1}, // 128 89480093f4SDimitry Andric {&PartMappings[6], 1}, // 256 90480093f4SDimitry Andric {&PartMappings[7], 1}, // 512 91480093f4SDimitry Andric {&PartMappings[8], 1}, // 1024 920b57cec5SDimitry Andric 930b57cec5SDimitry Andric // VGPRs 94480093f4SDimitry Andric {&PartMappings[9], 1}, // 1 950b57cec5SDimitry Andric {nullptr, 0}, 960b57cec5SDimitry Andric {nullptr, 0}, 970b57cec5SDimitry Andric {nullptr, 0}, 98480093f4SDimitry Andric {&PartMappings[10], 1}, // 16 99480093f4SDimitry Andric {&PartMappings[11], 1}, // 32 100480093f4SDimitry Andric {&PartMappings[12], 1}, // 64 101480093f4SDimitry Andric {&PartMappings[13], 1}, // 128 102480093f4SDimitry Andric {&PartMappings[14], 1}, // 256 103480093f4SDimitry Andric {&PartMappings[15], 1}, // 512 104480093f4SDimitry Andric {&PartMappings[16], 1}, // 1024 105480093f4SDimitry Andric {&PartMappings[17], 1}, 1068bcb0991SDimitry Andric {&PartMappings[18], 1}, 107480093f4SDimitry Andric {&PartMappings[19], 1}, 108480093f4SDimitry Andric 109480093f4SDimitry Andric // AGPRs 110480093f4SDimitry Andric {nullptr, 0}, 111480093f4SDimitry Andric {nullptr, 0}, 112480093f4SDimitry Andric {nullptr, 0}, 113480093f4SDimitry Andric {nullptr, 0}, 114480093f4SDimitry Andric {nullptr, 0}, 115480093f4SDimitry Andric {&PartMappings[20], 1}, // 32 116480093f4SDimitry Andric {&PartMappings[21], 1}, // 64 117480093f4SDimitry Andric {&PartMappings[22], 1}, // 128 118480093f4SDimitry Andric {nullptr, 0}, 119480093f4SDimitry Andric {&PartMappings[23], 1}, // 512 120480093f4SDimitry 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 135*5ffd83dbSDimitry Andric// For some instructions which can operate 64-bit only for the scalar 136*5ffd83dbSDimitry Andric// version. Otherwise, these need to be split into 2 32-bit operations. 1370b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping ValMappingsSGPR64OnlyVGPR32[] { 1380b57cec5SDimitry Andric /*32-bit sgpr*/ {&SGPROnly64BreakDown[0], 1}, 1390b57cec5SDimitry Andric /*2 x 32-bit sgpr*/ {&SGPROnly64BreakDown[1], 2}, 1400b57cec5SDimitry Andric /*64-bit sgpr */ {&SGPROnly64BreakDown[3], 1}, 1410b57cec5SDimitry Andric 1420b57cec5SDimitry Andric /*32-bit vgpr*/ {&SGPROnly64BreakDown[4], 1}, 1430b57cec5SDimitry Andric /*2 x 32-bit vgpr*/ {&SGPROnly64BreakDown[5], 2} 1440b57cec5SDimitry Andric}; 1450b57cec5SDimitry Andric 1460b57cec5SDimitry Andricenum ValueMappingIdx { 147480093f4SDimitry Andric SGPRStartIdx = 1, 148480093f4SDimitry Andric VGPRStartIdx = 12, 149480093f4SDimitry Andric AGPRStartIdx = 26 1500b57cec5SDimitry Andric}; 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping *getValueMapping(unsigned BankID, 1530b57cec5SDimitry Andric unsigned Size) { 1540b57cec5SDimitry Andric unsigned Idx; 1550b57cec5SDimitry Andric switch (Size) { 1560b57cec5SDimitry Andric case 1: 1570b57cec5SDimitry Andric if (BankID == AMDGPU::VCCRegBankID) 158480093f4SDimitry Andric return &ValMappings[0]; 1590b57cec5SDimitry Andric 1600b57cec5SDimitry Andric Idx = BankID == AMDGPU::SGPRRegBankID ? PM_SGPR1 : PM_VGPR1; 1610b57cec5SDimitry Andric break; 1620b57cec5SDimitry Andric case 96: 163480093f4SDimitry Andric switch (BankID) { 164480093f4SDimitry Andric case AMDGPU::VGPRRegBankID: 165480093f4SDimitry Andric Idx = PM_VGPR96; 166480093f4SDimitry Andric break; 167480093f4SDimitry Andric case AMDGPU::SGPRRegBankID: 168480093f4SDimitry Andric Idx = PM_SGPR96; 169480093f4SDimitry Andric break; 170480093f4SDimitry Andric case AMDGPU::AGPRRegBankID: 171480093f4SDimitry Andric Idx = PM_AGPR96; 172480093f4SDimitry Andric break; 173480093f4SDimitry Andric default: llvm_unreachable("Invalid register bank"); 174480093f4SDimitry Andric } 1750b57cec5SDimitry Andric break; 1760b57cec5SDimitry Andric default: 177480093f4SDimitry Andric switch (BankID) { 178480093f4SDimitry Andric case AMDGPU::VGPRRegBankID: 179480093f4SDimitry Andric Idx = VGPRStartIdx; 180480093f4SDimitry Andric break; 181480093f4SDimitry Andric case AMDGPU::SGPRRegBankID: 182480093f4SDimitry Andric Idx = SGPRStartIdx; 183480093f4SDimitry Andric break; 184480093f4SDimitry Andric case AMDGPU::AGPRRegBankID: 185480093f4SDimitry Andric Idx = AGPRStartIdx; 186480093f4SDimitry Andric break; 187480093f4SDimitry Andric default: llvm_unreachable("Invalid register bank"); 188480093f4SDimitry Andric } 1890b57cec5SDimitry Andric Idx += Log2_32_Ceil(Size); 1900b57cec5SDimitry Andric break; 1910b57cec5SDimitry Andric } 1920b57cec5SDimitry Andric 1930b57cec5SDimitry Andric assert(Log2_32_Ceil(Size) == Log2_32_Ceil(ValMappings[Idx].BreakDown->Length)); 1940b57cec5SDimitry Andric assert(BankID == ValMappings[Idx].BreakDown->RegBank->getID()); 1950b57cec5SDimitry Andric 1960b57cec5SDimitry Andric return &ValMappings[Idx]; 1970b57cec5SDimitry Andric} 1980b57cec5SDimitry Andric 1990b57cec5SDimitry Andricconst RegisterBankInfo::ValueMapping *getValueMappingSGPR64Only(unsigned BankID, 2000b57cec5SDimitry Andric unsigned Size) { 2010b57cec5SDimitry Andric if (Size != 64) 2020b57cec5SDimitry Andric return getValueMapping(BankID, Size); 2030b57cec5SDimitry Andric 2040b57cec5SDimitry Andric if (BankID == AMDGPU::VGPRRegBankID) 2050b57cec5SDimitry Andric return &ValMappingsSGPR64OnlyVGPR32[4]; 2060b57cec5SDimitry Andric 2070b57cec5SDimitry Andric assert(BankID == AMDGPU::SGPRRegBankID); 2080b57cec5SDimitry Andric return &ValMappingsSGPR64OnlyVGPR32[2]; 2090b57cec5SDimitry Andric} 2100b57cec5SDimitry Andric 211*5ffd83dbSDimitry Andric/// Split any 64-bit value into 2 32-bit pieces. Unlike 212*5ffd83dbSDimitry Andric/// getValueMappingSGPR64Only, this splits both VGPRs and SGPRs. 213*5ffd83dbSDimitry Andricconst RegisterBankInfo::ValueMapping *getValueMappingSplit64(unsigned BankID, 214*5ffd83dbSDimitry Andric unsigned Size) { 215*5ffd83dbSDimitry Andric assert(Size == 64); 216*5ffd83dbSDimitry Andric if (BankID == AMDGPU::VGPRRegBankID) 217*5ffd83dbSDimitry Andric return &ValMappingsSGPR64OnlyVGPR32[4]; 2180b57cec5SDimitry Andric 219*5ffd83dbSDimitry Andric assert(BankID == AMDGPU::SGPRRegBankID); 220*5ffd83dbSDimitry Andric return &ValMappingsSGPR64OnlyVGPR32[1]; 2210b57cec5SDimitry Andric} 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andric 2240b57cec5SDimitry Andric} // End AMDGPU namespace. 2250b57cec5SDimitry Andric} // End llvm namespace. 226