https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/241159
>From 3d0a4bee2fc58595f5ce77a57538248baff4c1b1 Mon Sep 17 00:00:00 2001 From: PaperChalice <[email protected]> Date: Wed, 11 Nov 2026 14:51:21 +0800 Subject: [PATCH] [AArch64] Use generated instruction mappings --- .../AArch64/AArch64GenRegisterBankInfo.def | 278 ---------- .../Target/AArch64/AArch64RegisterBanks.td | 137 ++++- .../AArch64/GISel/AArch64RegisterBankInfo.cpp | 495 ++++-------------- .../AArch64/GISel/AArch64RegisterBankInfo.h | 81 +-- 4 files changed, 226 insertions(+), 765 deletions(-) delete mode 100644 llvm/lib/Target/AArch64/AArch64GenRegisterBankInfo.def diff --git a/llvm/lib/Target/AArch64/AArch64GenRegisterBankInfo.def b/llvm/lib/Target/AArch64/AArch64GenRegisterBankInfo.def deleted file mode 100644 index bc15805d08626b..00000000000000 --- a/llvm/lib/Target/AArch64/AArch64GenRegisterBankInfo.def +++ /dev/null @@ -1,278 +0,0 @@ -//===- AArch64GenRegisterBankInfo.def ----------------------------*- C++ -*-==// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -/// \file -/// This file defines all the static objects used by AArch64RegisterBankInfo. -/// \todo This should be generated by TableGen. -//===----------------------------------------------------------------------===// - -namespace llvm { -const RegisterBankInfo::PartialMapping AArch64GenRegisterBankInfo::PartMappings[]{ - /* StartIdx, Length, RegBank */ - // 0: FPR 16-bit value. - {0, 16, AArch64::FPRRegBank}, - // 1: FPR 32-bit value. - {0, 32, AArch64::FPRRegBank}, - // 2: FPR 64-bit value. - {0, 64, AArch64::FPRRegBank}, - // 3: FPR 128-bit value. - {0, 128, AArch64::FPRRegBank}, - // 4: FPR 256-bit value. - {0, 256, AArch64::FPRRegBank}, - // 5: FPR 512-bit value. - {0, 512, AArch64::FPRRegBank}, - // 6: GPR 32-bit value. - {0, 32, AArch64::GPRRegBank}, - // 7: GPR 64-bit value. - {0, 64, AArch64::GPRRegBank}, - // 8: GPR 128-bit value. - {0, 128, AArch64::GPRRegBank}, -}; - -// ValueMappings. -const RegisterBankInfo::ValueMapping AArch64GenRegisterBankInfo::ValMappings[]{ - /* BreakDown, NumBreakDowns */ - // 0: invalid - {nullptr, 0}, - // 3-operands instructions (all binary operations should end up with one of - // those mapping). - // 1: FPR 16-bit value. <-- This must match First3OpsIdx. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR16 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR16 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR16 - PMI_Min], 1}, - // 4: FPR 32-bit value. <-- This must match First3OpsIdx. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1}, - // 7: FPR 64-bit value. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1}, - // 10: FPR 128-bit value. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR128 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR128 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR128 - PMI_Min], 1}, - // 13: FPR 256-bit value. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR256 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR256 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR256 - PMI_Min], 1}, - // 16: FPR 512-bit value. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR512 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR512 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR512 - PMI_Min], 1}, - // 19: GPR 32-bit value. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1}, - // 22: GPR 64-bit value. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1}, - // 25: GPR 128-bit value. <-- This must match Last3OpsIdx. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR128 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR128 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR128 - PMI_Min], 1}, - // Cross register bank copies. - // 28: FPR 16-bit value to GPR 16-bit. <-- This must match - // FirstCrossRegCpyIdx. - // Note: This is the kind of copy we see with physical registers. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR16 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1}, - // 30: FPR 32-bit value to GPR 32-bit value. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1}, - // 32: FPR 64-bit value to GPR 64-bit value. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1}, - // 34: FPR 128-bit value to GPR 128-bit value (invalid) - {nullptr, 1}, - {nullptr, 1}, - // 36: FPR 256-bit value to GPR 256-bit value (invalid) - {nullptr, 1}, - {nullptr, 1}, - // 38: FPR 512-bit value to GPR 512-bit value (invalid) - {nullptr, 1}, - {nullptr, 1}, - // 40: GPR 32-bit value to FPR 32-bit value. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1}, - // 42: GPR 64-bit value to FPR 64-bit value. <-- This must match - // LastCrossRegCpyIdx. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1}, - // 44: FPExt: 16 to 32. <-- This must match FPExt16To32Idx. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR16 - PMI_Min], 1}, - // 46: FPExt: 16 to 32. <-- This must match FPExt16To64Idx. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR16 - PMI_Min], 1}, - // 48: FPExt: 32 to 64. <-- This must match FPExt32To64Idx. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1}, - // 50: FPExt vector: 64 to 128. <-- This must match FPExt64To128Idx. - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR128 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1}, - // 52: Shift scalar with 64 bit shift imm - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1}, - {&AArch64GenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1}, -}; - -bool AArch64GenRegisterBankInfo::checkPartialMap(unsigned Idx, - unsigned ValStartIdx, - unsigned ValLength, - const RegisterBank &RB) { - const PartialMapping &Map = PartMappings[Idx - PartialMappingIdx::PMI_Min]; - return Map.StartIdx == ValStartIdx && Map.Length == ValLength && - Map.RegBank == &RB; -} - -bool AArch64GenRegisterBankInfo::checkValueMapImpl(unsigned Idx, - unsigned FirstInBank, - unsigned Size, - unsigned Offset) { - unsigned PartialMapBaseIdx = Idx - PartialMappingIdx::PMI_Min; - const ValueMapping &Map = - AArch64GenRegisterBankInfo::getValueMapping( - (PartialMappingIdx)FirstInBank, - TypeSize::getFixed(Size))[Offset]; - return Map.BreakDown == &PartMappings[PartialMapBaseIdx] && - Map.NumBreakDowns == 1; -} - -bool AArch64GenRegisterBankInfo::checkPartialMappingIdx( - PartialMappingIdx FirstAlias, PartialMappingIdx LastAlias, - ArrayRef<PartialMappingIdx> Order) { - if (Order.front() != FirstAlias) - return false; - if (Order.back() != LastAlias) - return false; - if (Order.front() > Order.back()) - return false; - - PartialMappingIdx Previous = Order.front(); - for (const auto &Current : Order.drop_front()) { - if (Previous + 1 != Current) - return false; - Previous = Current; - } - return true; -} - -unsigned AArch64GenRegisterBankInfo::getRegBankBaseIdxOffset(unsigned RBIdx, - TypeSize Size) { - if (RBIdx == PMI_FirstGPR) { - if (Size <= 32) - return 0; - if (Size <= 64) - return 1; - if (Size <= 128) - return 2; - return -1; - } - if (RBIdx == PMI_FirstFPR) { - const unsigned MinSize = Size.getKnownMinValue(); - assert((!Size.isScalable() || MinSize >= 128) && - "Scalable vector types should have size of at least 128 bits"); - if (Size.isScalable()) - return 3; - if (MinSize <= 16) - return 0; - if (MinSize <= 32) - return 1; - if (MinSize <= 64) - return 2; - if (MinSize <= 128) - return 3; - if (MinSize <= 256) - return 4; - if (MinSize <= 512) - return 5; - return -1; - } - return -1; -} - -const RegisterBankInfo::ValueMapping * -AArch64GenRegisterBankInfo::getValueMapping(PartialMappingIdx RBIdx, - const TypeSize Size) { - assert(RBIdx != PartialMappingIdx::PMI_None && "No mapping needed for that"); - unsigned BaseIdxOffset = getRegBankBaseIdxOffset(RBIdx, Size); - if (BaseIdxOffset == -1u) - return &ValMappings[InvalidIdx]; - - unsigned ValMappingIdx = - First3OpsIdx + (RBIdx - PartialMappingIdx::PMI_Min + BaseIdxOffset) * - ValueMappingIdx::DistanceBetweenRegBanks; - assert(ValMappingIdx >= First3OpsIdx && ValMappingIdx <= Last3OpsIdx && - "Mapping out of bound"); - - return &ValMappings[ValMappingIdx]; -} - -const AArch64GenRegisterBankInfo::PartialMappingIdx - AArch64GenRegisterBankInfo::BankIDToCopyMapIdx[]{ - PMI_None, // CCR - PMI_FirstFPR, // FPR - PMI_FirstGPR, // GPR - }; - -const RegisterBankInfo::ValueMapping * -AArch64GenRegisterBankInfo::getCopyMapping(unsigned DstBankID, - unsigned SrcBankID, - const TypeSize Size) { - assert(DstBankID < AArch64::NumRegisterBanks && "Invalid bank ID"); - assert(SrcBankID < AArch64::NumRegisterBanks && "Invalid bank ID"); - PartialMappingIdx DstRBIdx = BankIDToCopyMapIdx[DstBankID]; - PartialMappingIdx SrcRBIdx = BankIDToCopyMapIdx[SrcBankID]; - assert(DstRBIdx != PMI_None && "No such mapping"); - assert(SrcRBIdx != PMI_None && "No such mapping"); - - if (DstRBIdx == SrcRBIdx) - return getValueMapping(DstRBIdx, Size); - - assert(Size <= 64 && "GPR cannot handle that size"); - unsigned ValMappingIdx = - FirstCrossRegCpyIdx + - (DstRBIdx - PMI_Min + getRegBankBaseIdxOffset(DstRBIdx, Size)) * - ValueMappingIdx::DistanceBetweenCrossRegCpy; - assert(ValMappingIdx >= FirstCrossRegCpyIdx && - ValMappingIdx <= LastCrossRegCpyIdx && "Mapping out of bound"); - return &ValMappings[ValMappingIdx]; -} - -const RegisterBankInfo::ValueMapping * -AArch64GenRegisterBankInfo::getFPExtMapping(unsigned DstSize, - unsigned SrcSize) { - // We support: - // - For Scalar: - // - 16 to 32. - // - 16 to 64. - // - 32 to 64. - // => FPR 16 to FPR 32|64 - // => FPR 32 to FPR 64 - // - For vectors: - // - v4f16 to v4f32 - // - v2f32 to v2f64 - // => FPR 64 to FPR 128 - - // Check that we have been asked sensible sizes. - if (SrcSize == 16) { - assert((DstSize == 32 || DstSize == 64) && "Unexpected half extension"); - if (DstSize == 32) - return &ValMappings[FPExt16To32Idx]; - return &ValMappings[FPExt16To64Idx]; - } - - if (SrcSize == 32) { - assert(DstSize == 64 && "Unexpected float extension"); - return &ValMappings[FPExt32To64Idx]; - } - assert((SrcSize == 64 || DstSize == 128) && "Unexpected vector extension"); - return &ValMappings[FPExt64To128Idx]; -} -} // End llvm namespace. diff --git a/llvm/lib/Target/AArch64/AArch64RegisterBanks.td b/llvm/lib/Target/AArch64/AArch64RegisterBanks.td index 2b597b8606921e..e342df5fa46278 100644 --- a/llvm/lib/Target/AArch64/AArch64RegisterBanks.td +++ b/llvm/lib/Target/AArch64/AArch64RegisterBanks.td @@ -13,7 +13,142 @@ def GPRRegBank : RegisterBank<"GPR", [XSeqPairsClass]>; /// Floating Point, Vector, Scalable Vector Registers: B, H, S, D, Q, Z. -def FPRRegBank : RegisterBank<"FPR", [QQQQ, ZPR]>; +def FPRRegBank : RegisterBank<"FPR", [QQQQ, ZPR]> { + let ScalableMappingSize = 128; + let IgnoredPartialMappings=[PartialMapping<8>, PartialMapping<192>, PartialMapping<384>]; +} /// Conditional register: NZCV. def CCRegBank : RegisterBank<"CC", [CCR]>; + +def RegBankCustomMappingID : RegBankMappingID<"CustomMappingID", 1>; + +def : RegBankInstrMapping<[ + // G_{F|S|U}REM are not listed because they are not legal. + // Arithmetic ops. + G_ADD, G_SUB, G_MUL, G_SDIV, G_UDIV, + // Bitwise ops. + G_AND, G_OR, G_XOR, + // Floating point ops. + G_FADD, G_FSUB, G_FMUL, G_FDIV, + G_FMAXIMUM, G_FMINIMUM + ], [ + RegBankMappingRule<[RegBankTypeMapping<FPRRegBank, type0>], + predicate=[{Type0.isVector() || isPreISelGenericFloatingPointOpcode(Opc)}]>, + RegBankMappingRule<[RegBankTypeMapping<GPRRegBank, type0>]> +]>; + +def : RegBankInstrMapping<[G_PTR_ADD], [ + RegBankMappingRule<[RegBankTypeMapping<FPRRegBank, ptype0>, RegBankTypeMapping<GPRRegBank, type1>], + predicate=[{PType0.isVector()}]>, + RegBankMappingRule<[RegBankTypeMapping<GPRRegBank, ptype0>, RegBankTypeMapping<GPRRegBank, type1>]> +]>; + +def : RegBankInstrMapping<[G_FPEXT], [ + RegBankMappingRule<[ + RegBankTypeMapping<FPRRegBank, type0>, + RegBankTypeMapping<FPRRegBank, type1> + ]> +]>; + +def : RegBankInstrMapping<[ + // Shifts. + G_SHL, G_LSHR, G_ASHR + ], [ + RegBankMappingRule<[ + RegBankTypeMapping<GPRRegBank, type0>, + RegBankTypeMapping<GPRRegBank, type1> + ], predicate=[{Type0Size == 64 && Type1Size == 32}]>, + RegBankMappingRule<[ + RegBankTypeMapping<FPRRegBank, type0>, + RegBankTypeMapping<FPRRegBank, type1> + ], + predicate=[{Type0.isVector()}]>, + RegBankMappingRule<[ + RegBankTypeMapping<GPRRegBank, type0>, + RegBankTypeMapping<GPRRegBank, type1> + ]> +]>; + +def : RegBankInstrMapping<[G_CONSTANT], [ + RegBankMappingRule<[ + RegBankTypeMapping<GPRRegBank, type0> + ], predicate=[{Type0.isPointer() || (Type0.isScalar() && Type0Size >= 32 && Type0Size <= 64)}]>, + RegBankMappingRule<[ + RegBankTypeMapping<GPRRegBank, type0> + ], id=RegBankCustomMappingID, predicate=[{Type0.isScalar() && Type0Size < 32}]>, + RegBankMappingRule<[ + RegBankTypeMapping<GPRRegBank, type0> + ]> +]>; + +def : RegBankInstrMapping<[G_BRCOND], [ + RegBankMappingRule<[ + RegBankTypeMapping<GPRRegBank, type0> + ]> +]>; + +def : RegBankInstrMapping<[G_FRAME_INDEX], [ + RegBankMappingRule<[ + RegBankTypeMapping<GPRRegBank, ptype0> + ]> +]>; + +def : RegBankInstrMapping<[G_FCONSTANT], [ + RegBankMappingRule<[ + RegBankTypeMapping<GPRRegBank, type0>, + ], id=RegBankCustomMappingID, + predicate=[{preferGPRForFPImm(MI, MRI, static_cast<const AArch64Subtarget&>(STI))}]>, + RegBankMappingRule<[ + RegBankTypeMapping<FPRRegBank, type0> + ]> +]>; + +def : RegBankInstrMapping<[G_FCMP], [ + RegBankMappingRule<[ + RegBankTypeMapping<FPRRegBank, type0>, + RegBankTypeMapping<FPRRegBank, type1>, + ], predicate=[{Type0.isVector()}]>, + RegBankMappingRule<[ + RegBankTypeMapping<GPRRegBank, type0>, + RegBankTypeMapping<FPRRegBank, type1>, + ]> +]>; + +def : RegBankInstrMapping<[ + G_VECREDUCE_FADD, G_VECREDUCE_FMUL, G_VECREDUCE_FMAX, + G_VECREDUCE_FMIN, G_VECREDUCE_FMAXIMUM, G_VECREDUCE_FMINIMUM, G_VECREDUCE_ADD, + G_VECREDUCE_MUL, G_VECREDUCE_AND, G_VECREDUCE_OR, G_VECREDUCE_XOR, G_VECREDUCE_SMAX, + G_VECREDUCE_SMIN, G_VECREDUCE_UMAX, G_VECREDUCE_UMIN + ], [ + // Reductions produce a scalar value from a vector, the scalar should be on + // FPR bank. + RegBankMappingRule<[ + RegBankTypeMapping<FPRRegBank, type0>, + RegBankTypeMapping<FPRRegBank, type1> + ]> +]>; + +def : RegBankInstrMapping<[G_INSERT_VECTOR_ELT], [ + RegBankMappingRule<[ + RegBankTypeMapping<FPRRegBank, type0>, + RegBankTypeMapping<FPRRegBank, type1>, + RegBankTypeMapping<GPRRegBank, type2> + ], + // The element may be either a GPR or FPR. Preserve that behaviour. + predicate=[{getRegBank(EltReg, MRI, TRI) == &AArch64::FPRRegBank}]>, + RegBankMappingRule<[ + RegBankTypeMapping<FPRRegBank, type0>, + RegBankTypeMapping<GPRRegBank, type1>, + RegBankTypeMapping<GPRRegBank, type2> + ]> +]>; + +def : RegBankInstrMapping<[G_VECREDUCE_SEQ_FADD, G_VECREDUCE_SEQ_FMUL], [ + RegBankMappingRule<[ + RegBankTypeMapping<FPRRegBank, type0>, + RegBankTypeMapping<FPRRegBank, type1>, + RegBankTypeMapping<FPRRegBank, type2> + ]> +]>; + diff --git a/llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp index cf62075dfc6a00..365b4d63ce5368 100644 --- a/llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.cpp @@ -40,190 +40,35 @@ #include "llvm/Support/Threading.h" #include <cassert> +static bool preferGPRForFPImm(const llvm::MachineInstr &MI, + const llvm::MachineRegisterInfo &MRI, + const llvm::AArch64Subtarget &STI); +static bool preferGPRForFPImm(const llvm::MachineInstr &MI, + const llvm::MachineRegisterInfo &MRI, + const llvm::AArch64Subtarget &STI); + #define GET_TARGET_REGBANK_IMPL #include "AArch64GenRegisterBank.inc" -// This file will be TableGen'ed at some point. -#include "AArch64GenRegisterBankInfo.def" - using namespace llvm; using namespace MIPatternMatch; static const unsigned CustomMappingID = 1; -AArch64RegisterBankInfo::AArch64RegisterBankInfo( - const TargetRegisterInfo &TRI) { - static llvm::once_flag InitializeRegisterBankFlag; - - static auto InitializeRegisterBankOnce = [&]() { - // We have only one set of register banks, whatever the subtarget - // is. Therefore, the initialization of the RegBanks table should be - // done only once. Indeed the table of all register banks - // (AArch64::RegBanks) is unique in the compiler. At some point, it - // will get tablegen'ed and the whole constructor becomes empty. - - const RegisterBank &RBGPR = getRegBank(AArch64::GPRRegBankID); - (void)RBGPR; - assert(&AArch64::GPRRegBank == &RBGPR && - "The order in RegBanks is messed up"); - - const RegisterBank &RBFPR = getRegBank(AArch64::FPRRegBankID); - (void)RBFPR; - assert(&AArch64::FPRRegBank == &RBFPR && - "The order in RegBanks is messed up"); - - const RegisterBank &RBCCR = getRegBank(AArch64::CCRegBankID); - (void)RBCCR; - assert(&AArch64::CCRegBank == &RBCCR && - "The order in RegBanks is messed up"); - - // The GPR register bank is fully defined by all the registers in - // GR64all + its subclasses. - assert(RBGPR.covers(*TRI.getRegClass(AArch64::GPR32RegClassID)) && - "Subclass not added?"); - assert(getMaximumSize(RBGPR.getID()) == 128 && - "GPRs should hold up to 128-bit"); - - // The FPR register bank is fully defined by all the registers in - // GR64all + its subclasses. - assert(RBFPR.covers(*TRI.getRegClass(AArch64::QQRegClassID)) && - "Subclass not added?"); - assert(RBFPR.covers(*TRI.getRegClass(AArch64::FPR64RegClassID)) && - "Subclass not added?"); - assert(getMaximumSize(RBFPR.getID()) == 512 && - "FPRs should hold up to 512-bit via QQQQ sequence"); - - assert(RBCCR.covers(*TRI.getRegClass(AArch64::CCRRegClassID)) && - "Class not added?"); - assert(getMaximumSize(RBCCR.getID()) == 32 && - "CCR should hold up to 32-bit"); - - // Check that the TableGen'ed like file is in sync we our expectations. - // First, the Idx. - assert(checkPartialMappingIdx(PMI_FirstGPR, PMI_LastGPR, - {PMI_GPR32, PMI_GPR64, PMI_GPR128}) && - "PartialMappingIdx's are incorrectly ordered"); - assert(checkPartialMappingIdx(PMI_FirstFPR, PMI_LastFPR, - {PMI_FPR16, PMI_FPR32, PMI_FPR64, PMI_FPR128, - PMI_FPR256, PMI_FPR512}) && - "PartialMappingIdx's are incorrectly ordered"); -// Now, the content. -// Check partial mapping. -#define CHECK_PARTIALMAP(Idx, ValStartIdx, ValLength, RB) \ - do { \ - assert( \ - checkPartialMap(PartialMappingIdx::Idx, ValStartIdx, ValLength, RB) && \ - #Idx " is incorrectly initialized"); \ - } while (false) - - CHECK_PARTIALMAP(PMI_GPR32, 0, 32, RBGPR); - CHECK_PARTIALMAP(PMI_GPR64, 0, 64, RBGPR); - CHECK_PARTIALMAP(PMI_GPR128, 0, 128, RBGPR); - CHECK_PARTIALMAP(PMI_FPR16, 0, 16, RBFPR); - CHECK_PARTIALMAP(PMI_FPR32, 0, 32, RBFPR); - CHECK_PARTIALMAP(PMI_FPR64, 0, 64, RBFPR); - CHECK_PARTIALMAP(PMI_FPR128, 0, 128, RBFPR); - CHECK_PARTIALMAP(PMI_FPR256, 0, 256, RBFPR); - CHECK_PARTIALMAP(PMI_FPR512, 0, 512, RBFPR); - -// Check value mapping. -#define CHECK_VALUEMAP_IMPL(RBName, Size, Offset) \ - do { \ - assert(checkValueMapImpl(PartialMappingIdx::PMI_##RBName##Size, \ - PartialMappingIdx::PMI_First##RBName, Size, \ - Offset) && \ - #RBName #Size " " #Offset " is incorrectly initialized"); \ - } while (false) - -#define CHECK_VALUEMAP(RBName, Size) CHECK_VALUEMAP_IMPL(RBName, Size, 0) - - CHECK_VALUEMAP(GPR, 32); - CHECK_VALUEMAP(GPR, 64); - CHECK_VALUEMAP(GPR, 128); - CHECK_VALUEMAP(FPR, 16); - CHECK_VALUEMAP(FPR, 32); - CHECK_VALUEMAP(FPR, 64); - CHECK_VALUEMAP(FPR, 128); - CHECK_VALUEMAP(FPR, 256); - CHECK_VALUEMAP(FPR, 512); - -// Check the value mapping for 3-operands instructions where all the operands -// map to the same value mapping. -#define CHECK_VALUEMAP_3OPS(RBName, Size) \ - do { \ - CHECK_VALUEMAP_IMPL(RBName, Size, 0); \ - CHECK_VALUEMAP_IMPL(RBName, Size, 1); \ - CHECK_VALUEMAP_IMPL(RBName, Size, 2); \ - } while (false) - - CHECK_VALUEMAP_3OPS(GPR, 32); - CHECK_VALUEMAP_3OPS(GPR, 64); - CHECK_VALUEMAP_3OPS(GPR, 128); - CHECK_VALUEMAP_3OPS(FPR, 32); - CHECK_VALUEMAP_3OPS(FPR, 64); - CHECK_VALUEMAP_3OPS(FPR, 128); - CHECK_VALUEMAP_3OPS(FPR, 256); - CHECK_VALUEMAP_3OPS(FPR, 512); - -#define CHECK_VALUEMAP_CROSSREGCPY(RBNameDst, RBNameSrc, Size) \ - do { \ - unsigned PartialMapDstIdx = PMI_##RBNameDst##Size - PMI_Min; \ - unsigned PartialMapSrcIdx = PMI_##RBNameSrc##Size - PMI_Min; \ - (void)PartialMapDstIdx; \ - (void)PartialMapSrcIdx; \ - const ValueMapping *Map = getCopyMapping(AArch64::RBNameDst##RegBankID, \ - AArch64::RBNameSrc##RegBankID, \ - TypeSize::getFixed(Size)); \ - (void)Map; \ - assert(Map[0].BreakDown == \ - &AArch64GenRegisterBankInfo::PartMappings[PartialMapDstIdx] && \ - Map[0].NumBreakDowns == 1 && \ - #RBNameDst #Size " Dst is incorrectly initialized"); \ - assert(Map[1].BreakDown == \ - &AArch64GenRegisterBankInfo::PartMappings[PartialMapSrcIdx] && \ - Map[1].NumBreakDowns == 1 && \ - #RBNameSrc #Size " Src is incorrectly initialized"); \ - \ - } while (false) - - CHECK_VALUEMAP_CROSSREGCPY(GPR, GPR, 32); - CHECK_VALUEMAP_CROSSREGCPY(GPR, FPR, 32); - CHECK_VALUEMAP_CROSSREGCPY(GPR, GPR, 64); - CHECK_VALUEMAP_CROSSREGCPY(GPR, FPR, 64); - CHECK_VALUEMAP_CROSSREGCPY(FPR, FPR, 32); - CHECK_VALUEMAP_CROSSREGCPY(FPR, GPR, 32); - CHECK_VALUEMAP_CROSSREGCPY(FPR, FPR, 64); - CHECK_VALUEMAP_CROSSREGCPY(FPR, GPR, 64); - -#define CHECK_VALUEMAP_FPEXT(DstSize, SrcSize) \ - do { \ - unsigned PartialMapDstIdx = PMI_FPR##DstSize - PMI_Min; \ - unsigned PartialMapSrcIdx = PMI_FPR##SrcSize - PMI_Min; \ - (void)PartialMapDstIdx; \ - (void)PartialMapSrcIdx; \ - const ValueMapping *Map = getFPExtMapping(DstSize, SrcSize); \ - (void)Map; \ - assert(Map[0].BreakDown == \ - &AArch64GenRegisterBankInfo::PartMappings[PartialMapDstIdx] && \ - Map[0].NumBreakDowns == 1 && "FPR" #DstSize \ - " Dst is incorrectly initialized"); \ - assert(Map[1].BreakDown == \ - &AArch64GenRegisterBankInfo::PartMappings[PartialMapSrcIdx] && \ - Map[1].NumBreakDowns == 1 && "FPR" #SrcSize \ - " Src is incorrectly initialized"); \ - \ - } while (false) - - CHECK_VALUEMAP_FPEXT(32, 16); - CHECK_VALUEMAP_FPEXT(64, 16); - CHECK_VALUEMAP_FPEXT(64, 32); - CHECK_VALUEMAP_FPEXT(128, 64); - - assert(verify(TRI) && "Invalid register bank information"); - }; - - llvm::call_once(InitializeRegisterBankFlag, InitializeRegisterBankOnce); +const RegisterBankInfo::ValueMapping * +AArch64GenRegisterBankInfo::getCopyMapping(unsigned DstBankID, + unsigned SrcBankID, + const TypeSize Size) const { + + const ValueMapping *DstMapping = + AArch64::getGeneratedValueMapping(DstBankID, Size); + const ValueMapping *SrcMapping = + AArch64::getGeneratedValueMapping(SrcBankID, Size); + return getOperandsMapping({DstMapping, SrcMapping}); } +AArch64RegisterBankInfo::AArch64RegisterBankInfo( + const TargetRegisterInfo &TRI) {} + unsigned AArch64RegisterBankInfo::copyCost(const RegisterBank &A, const RegisterBank &B, const TypeSize Size) const { @@ -277,11 +122,15 @@ AArch64RegisterBankInfo::getInstrAlternativeMappings( if (MI.getNumOperands() != 3) break; InstructionMappings AltMappings; + const ValueMapping *GPRVM = + AArch64::getGeneratedValueMapping(AArch64::GPRRegBankID, Size); + const ValueMapping *FPRVM = + AArch64::getGeneratedValueMapping(AArch64::FPRRegBankID, Size); const InstructionMapping &GPRMapping = getInstructionMapping( - /*ID*/ 1, /*Cost*/ 1, getValueMapping(PMI_FirstGPR, Size), + /*ID*/ 1, /*Cost*/ 1, getOperandsMapping({GPRVM, GPRVM, GPRVM}), /*NumOperands*/ 3); const InstructionMapping &FPRMapping = getInstructionMapping( - /*ID*/ 2, /*Cost*/ 1, getValueMapping(PMI_FirstFPR, Size), + /*ID*/ 2, /*Cost*/ 1, getOperandsMapping({FPRVM, FPRVM, FPRVM}), /*NumOperands*/ 3); AltMappings.push_back(&GPRMapping); @@ -342,16 +191,18 @@ AArch64RegisterBankInfo::getInstrAlternativeMappings( const InstructionMapping &GPRMapping = getInstructionMapping( /*ID*/ 1, /*Cost*/ 1, getOperandsMapping( - {getValueMapping(PMI_FirstGPR, Size), + {AArch64::getGeneratedValueMapping(AArch64::GPRRegBankID, Size), // Addresses are GPR 64-bit. - getValueMapping(PMI_FirstGPR, TypeSize::getFixed(64))}), + AArch64::getGeneratedValueMapping(AArch64::GPRRegBankID, + TypeSize::getFixed(64))}), /*NumOperands*/ 2); const InstructionMapping &FPRMapping = getInstructionMapping( /*ID*/ 2, /*Cost*/ 1, getOperandsMapping( - {getValueMapping(PMI_FirstFPR, Size), + {AArch64::getGeneratedValueMapping(AArch64::FPRRegBankID, Size), // Addresses are GPR 64-bit. - getValueMapping(PMI_FirstGPR, TypeSize::getFixed(64))}), + AArch64::getGeneratedValueMapping(AArch64::GPRRegBankID, + TypeSize::getFixed(64))}), /*NumOperands*/ 2); AltMappings.push_back(&GPRMapping); @@ -542,49 +393,6 @@ void AArch64RegisterBankInfo::applyMappingImpl( } } -const RegisterBankInfo::InstructionMapping & -AArch64RegisterBankInfo::getSameKindOfOperandsMapping( - const MachineInstr &MI) const { - const unsigned Opc = MI.getOpcode(); - const MachineFunction &MF = *MI.getParent()->getParent(); - const MachineRegisterInfo &MRI = MF.getRegInfo(); - - unsigned NumOperands = MI.getNumOperands(); - assert(NumOperands <= 3 && - "This code is for instructions with 3 or less operands"); - - LLT Ty = MRI.getType(MI.getOperand(0).getReg()); - TypeSize Size = Ty.getSizeInBits(); - bool IsFPR = Ty.isVector() || isPreISelGenericFloatingPointOpcode(Opc); - - PartialMappingIdx RBIdx = IsFPR ? PMI_FirstFPR : PMI_FirstGPR; - -#ifndef NDEBUG - // Make sure all the operands are using similar size and type. - // Should probably be checked by the machine verifier. - // This code won't catch cases where the number of lanes is - // different between the operands. - // If we want to go to that level of details, it is probably - // best to check that the types are the same, period. - // Currently, we just check that the register banks are the same - // for each types. - for (unsigned Idx = 1; Idx != NumOperands; ++Idx) { - LLT OpTy = MRI.getType(MI.getOperand(Idx).getReg()); - assert( - AArch64GenRegisterBankInfo::getRegBankBaseIdxOffset( - RBIdx, OpTy.getSizeInBits()) == - AArch64GenRegisterBankInfo::getRegBankBaseIdxOffset(RBIdx, Size) && - "Operand has incompatible size"); - bool OpIsFPR = OpTy.isVector() || isPreISelGenericFloatingPointOpcode(Opc); - (void)OpIsFPR; - assert(IsFPR == OpIsFPR && "Operand has incompatible type"); - } -#endif // End NDEBUG. - - return getInstructionMapping(DefaultMappingID, 1, - getValueMapping(RBIdx, Size), NumOperands); -} - /// \returns true if a given intrinsic only uses and defines FPRs. static bool isFPIntrinsic(const MachineRegisterInfo &MRI, const MachineInstr &MI) { @@ -903,51 +711,16 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { return Mapping; } + if (const InstructionMapping &Mapping = getGeneratedInstrMapping(MI); + Mapping.isValid()) + return Mapping; + const MachineFunction &MF = *MI.getParent()->getParent(); const MachineRegisterInfo &MRI = MF.getRegInfo(); const AArch64Subtarget &STI = MF.getSubtarget<AArch64Subtarget>(); const AArch64RegisterInfo &TRI = *STI.getRegisterInfo(); switch (Opc) { - // G_{F|S|U}REM are not listed because they are not legal. - // Arithmetic ops. - case TargetOpcode::G_ADD: - case TargetOpcode::G_SUB: - case TargetOpcode::G_PTR_ADD: - case TargetOpcode::G_MUL: - case TargetOpcode::G_SDIV: - case TargetOpcode::G_UDIV: - // Bitwise ops. - case TargetOpcode::G_AND: - case TargetOpcode::G_OR: - case TargetOpcode::G_XOR: - // Floating point ops. - case TargetOpcode::G_FADD: - case TargetOpcode::G_FSUB: - case TargetOpcode::G_FMUL: - case TargetOpcode::G_FDIV: - case TargetOpcode::G_FMAXIMUM: - case TargetOpcode::G_FMINIMUM: - return getSameKindOfOperandsMapping(MI); - case TargetOpcode::G_FPEXT: { - LLT DstTy = MRI.getType(MI.getOperand(0).getReg()); - LLT SrcTy = MRI.getType(MI.getOperand(1).getReg()); - return getInstructionMapping( - DefaultMappingID, /*Cost*/ 1, - getFPExtMapping(DstTy.getSizeInBits(), SrcTy.getSizeInBits()), - /*NumOperands*/ 2); - } - // Shifts. - case TargetOpcode::G_SHL: - case TargetOpcode::G_LSHR: - case TargetOpcode::G_ASHR: { - LLT ShiftAmtTy = MRI.getType(MI.getOperand(2).getReg()); - LLT SrcTy = MRI.getType(MI.getOperand(1).getReg()); - if (ShiftAmtTy.getSizeInBits() == 64 && SrcTy.getSizeInBits() == 32) - return getInstructionMapping(DefaultMappingID, 1, - &ValMappings[Shift64Imm], 3); - return getSameKindOfOperandsMapping(MI); - } case TargetOpcode::G_BITCAST: { Register SrcReg = MI.getOperand(1).getReg(); const RegisterBank *SrcRB = getRegBank(SrcReg, MRI, TRI); @@ -999,26 +772,6 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { // We only care about the mapping of the destination for COPY. /*NumOperands*/ Opc == TargetOpcode::G_BITCAST ? 2 : 1); } - case TargetOpcode::G_CONSTANT: { - LLT DstTy = MRI.getType(MI.getOperand(0).getReg()); - TypeSize Size = DstTy.getSizeInBits(); - if (!DstTy.isPointer() && (!DstTy.isScalar() || Size < 32 || Size > 64)) - break; - // Scalar constants materialize in GPRs. - [[fallthrough]]; - } - case TargetOpcode::G_BRCOND: - case TargetOpcode::G_FRAME_INDEX: { - // Operand 0 is the only banked operand and is mapped to GPR. - return getInstructionMapping( - DefaultMappingID, /*Cost=*/1, - getOperandsMapping( - {getValueMapping( - PMI_FirstGPR, - MRI.getType(MI.getOperand(0).getReg()).getSizeInBits()), - nullptr}), - /*NumOperands=*/2); - } default: break; } @@ -1028,7 +781,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { // Track the size and bank of each register. We don't do partial mappings. SmallVector<unsigned, 4> OpSize(NumOperands); - SmallVector<PartialMappingIdx, 4> OpRegBankIdx(NumOperands); + SmallVector<unsigned, 4> OpRegBankIdx(NumOperands); for (unsigned Idx = 0; Idx < NumOperands; ++Idx) { auto &MO = MI.getOperand(Idx); if (!MO.isReg() || !MO.getReg()) @@ -1043,59 +796,44 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { // ones go in FPRs, scalars and pointers in GPRs. // For floating-point instructions, scalars go in FPRs. if (Ty.isVector()) - OpRegBankIdx[Idx] = PMI_FirstFPR; + OpRegBankIdx[Idx] = AArch64::FPRRegBankID; else if (isPreISelGenericFloatingPointOpcode(Opc) || (MO.isDef() && onlyDefinesFP(MI, MRI, TRI)) || (MO.isUse() && onlyUsesFP(MI, MRI, TRI)) || Ty.getSizeInBits() > 64) - OpRegBankIdx[Idx] = PMI_FirstFPR; + OpRegBankIdx[Idx] = AArch64::FPRRegBankID; else - OpRegBankIdx[Idx] = PMI_FirstGPR; + OpRegBankIdx[Idx] = AArch64::GPRRegBankID; } unsigned Cost = 1; // Some of the floating-point instructions have mixed GPR and FPR operands: // fine-tune the computed mapping. switch (Opc) { - case TargetOpcode::G_CONSTANT: { - Register Dst = MI.getOperand(0).getReg(); - LLT DstTy = MRI.getType(Dst); - if (DstTy.isScalar() && DstTy.getSizeInBits() < 32) - MappingID = CustomMappingID; - break; - } - case TargetOpcode::G_FCONSTANT: { - if (preferGPRForFPImm(MI, MRI, STI)) { - // Materialize in GPR and rely on later bank copies for FP uses. - MappingID = CustomMappingID; - OpRegBankIdx = {PMI_FirstGPR}; - } - break; - } case TargetOpcode::G_SPLAT_VECTOR: { Register ScalarReg = MI.getOperand(1).getReg(); LLT ScalarTy = MRI.getType(ScalarReg); auto ScalarDef = MRI.getVRegDef(ScalarReg); // We want to select dup(load) into LD1R. if (ScalarDef->getOpcode() == TargetOpcode::G_LOAD) - OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR}; + OpRegBankIdx = {AArch64::FPRRegBankID, AArch64::FPRRegBankID}; else if (getRegBank(ScalarReg, MRI, TRI) == &AArch64::FPRRegBank || onlyDefinesFP(*ScalarDef, MRI, TRI)) - OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR}; + OpRegBankIdx = {AArch64::FPRRegBankID, AArch64::FPRRegBankID}; else { if (ScalarTy.getSizeInBits() < 32 && getRegBank(ScalarReg, MRI, TRI) == &AArch64::GPRRegBank) { // Calls applyMappingImpl() MappingID = CustomMappingID; } - OpRegBankIdx = {PMI_FirstFPR, PMI_FirstGPR}; + OpRegBankIdx = {AArch64::FPRRegBankID, AArch64::GPRRegBankID}; } break; } case TargetOpcode::G_TRUNC: { LLT SrcTy = MRI.getType(MI.getOperand(1).getReg()); if (!SrcTy.isVector() && SrcTy.getSizeInBits() == 128) - OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR}; + OpRegBankIdx = {AArch64::FPRRegBankID, AArch64::FPRRegBankID}; break; } case TargetOpcode::G_SITOFP: @@ -1108,9 +846,9 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { if (getRegBank(SrcReg, MRI, TRI) == &AArch64::FPRRegBank && MRI.getType(SrcReg).getSizeInBits() == MRI.getType(MI.getOperand(0).getReg()).getSizeInBits()) - OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR}; + OpRegBankIdx = {AArch64::FPRRegBankID, AArch64::FPRRegBankID}; else - OpRegBankIdx = {PMI_FirstFPR, PMI_FirstGPR}; + OpRegBankIdx = {AArch64::FPRRegBankID, AArch64::GPRRegBankID}; break; } case TargetOpcode::G_FPTOSI_SAT: @@ -1125,7 +863,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { if (DstType.isVector()) break; if (DstType == LLT::scalar(16)) { - OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR}; + OpRegBankIdx = {AArch64::FPRRegBankID, AArch64::FPRRegBankID}; break; } TypeSize DstSize = TRI.getRegSizeInBits(MI.getOperand(0).getReg(), MRI); @@ -1136,27 +874,16 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { return onlyUsesFP(UseMI, MRI, TRI) || prefersFPUse(UseMI, MRI, TRI); })) - OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR}; + OpRegBankIdx = {AArch64::FPRRegBankID, AArch64::FPRRegBankID}; else - OpRegBankIdx = {PMI_FirstGPR, PMI_FirstFPR}; - break; - } - case TargetOpcode::G_FCMP: { - // If the result is a vector, it must use a FPR. - AArch64GenRegisterBankInfo::PartialMappingIdx Idx0 = - MRI.getType(MI.getOperand(0).getReg()).isVector() ? PMI_FirstFPR - : PMI_FirstGPR; - OpRegBankIdx = {Idx0, - /* Predicate */ PMI_None, PMI_FirstFPR, PMI_FirstFPR}; + OpRegBankIdx = {AArch64::GPRRegBankID, AArch64::FPRRegBankID}; break; } case TargetOpcode::G_BITCAST: // This is going to be a cross register bank copy and this is expensive. if (OpRegBankIdx[0] != OpRegBankIdx[1]) - Cost = copyCost( - *AArch64GenRegisterBankInfo::PartMappings[OpRegBankIdx[0]].RegBank, - *AArch64GenRegisterBankInfo::PartMappings[OpRegBankIdx[1]].RegBank, - TypeSize::getFixed(OpSize[0])); + Cost = copyCost(getRegBank(OpRegBankIdx[0]), getRegBank(OpRegBankIdx[1]), + TypeSize::getFixed(OpSize[0])); break; case TargetOpcode::G_LOAD: { // Loading in vector unit is slightly more expensive. @@ -1165,14 +892,14 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { // for the greedy mode the cost of the cross bank copy will // offset this number. // FIXME: Should be derived from the scheduling model. - if (OpRegBankIdx[0] != PMI_FirstGPR) { + if (OpRegBankIdx[0] != AArch64::GPRRegBankID) { Cost = 2; break; } if (cast<GLoad>(MI).isAtomic()) { // Atomics always use GPR destinations. Don't refine any further. - OpRegBankIdx[0] = PMI_FirstGPR; + OpRegBankIdx[0] = AArch64::GPRRegBankID; if (MRI.getType(MI.getOperand(0).getReg()).getSizeInBits() < 32) MappingID = CustomMappingID; break; @@ -1180,7 +907,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { // Try to guess the type of the load from the MMO. if (isLoadFromFPType(MI)) { - OpRegBankIdx[0] = PMI_FirstFPR; + OpRegBankIdx[0] = AArch64::FPRRegBankID; break; } @@ -1204,7 +931,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { return onlyUsesFP(UseMI, MRI, TRI) || prefersFPUse(UseMI, MRI, TRI); })) - OpRegBankIdx[0] = PMI_FirstFPR; + OpRegBankIdx[0] = AArch64::FPRRegBankID; // On GPR, extend any load < 32bits to 32bit. LLT Ty = MRI.getType(MI.getOperand(0).getReg()); @@ -1214,12 +941,12 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { } case TargetOpcode::G_STORE: // Check if that store is fed by fp instructions. - if (OpRegBankIdx[0] == PMI_FirstGPR) { + if (OpRegBankIdx[0] == AArch64::GPRRegBankID) { Register VReg = MI.getOperand(0).getReg(); if (VReg) { MachineInstr *DefMI = MRI.getVRegDef(VReg); if (onlyDefinesFP(*DefMI, MRI, TRI)) { - OpRegBankIdx[0] = PMI_FirstFPR; + OpRegBankIdx[0] = AArch64::FPRRegBankID; break; } } @@ -1231,36 +958,37 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { } break; case TargetOpcode::G_INDEXED_STORE: - if (OpRegBankIdx[1] == PMI_FirstGPR) { + if (OpRegBankIdx[1] == AArch64::GPRRegBankID) { Register VReg = MI.getOperand(1).getReg(); if (!VReg) break; MachineInstr *DefMI = MRI.getVRegDef(VReg); if (onlyDefinesFP(*DefMI, MRI, TRI)) - OpRegBankIdx[1] = PMI_FirstFPR; + OpRegBankIdx[1] = AArch64::FPRRegBankID; break; } break; case TargetOpcode::G_INDEXED_SEXTLOAD: case TargetOpcode::G_INDEXED_ZEXTLOAD: // These should always be GPR. - OpRegBankIdx[0] = PMI_FirstGPR; + OpRegBankIdx[0] = AArch64::GPRRegBankID; break; case TargetOpcode::G_INDEXED_LOAD: { if (isLoadFromFPType(MI)) - OpRegBankIdx[0] = PMI_FirstFPR; + OpRegBankIdx[0] = AArch64::FPRRegBankID; break; } case TargetOpcode::G_SELECT: { // If the destination is FPR, preserve that. - if (OpRegBankIdx[0] != PMI_FirstGPR) + if (OpRegBankIdx[0] != AArch64::GPRRegBankID) break; // If we're taking in vectors, we have no choice but to put everything on // FPRs, except for the condition. The condition must always be on a GPR. LLT SrcTy = MRI.getType(MI.getOperand(2).getReg()); if (SrcTy.isVector()) { - OpRegBankIdx = {PMI_FirstFPR, PMI_FirstGPR, PMI_FirstFPR, PMI_FirstFPR}; + OpRegBankIdx = {AArch64::FPRRegBankID, AArch64::GPRRegBankID, + AArch64::FPRRegBankID, AArch64::FPRRegBankID}; break; } @@ -1303,14 +1031,15 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { // If we have more FP constraints than not, then move everything over to // FPR. if (NumFP >= 2) - OpRegBankIdx = {PMI_FirstFPR, PMI_FirstGPR, PMI_FirstFPR, PMI_FirstFPR}; + OpRegBankIdx = {AArch64::FPRRegBankID, AArch64::GPRRegBankID, + AArch64::FPRRegBankID, AArch64::FPRRegBankID}; break; } case TargetOpcode::G_UNMERGE_VALUES: { // If the first operand belongs to a FPR register bank, then make sure that // we preserve that. - if (OpRegBankIdx[0] != PMI_FirstGPR) + if (OpRegBankIdx[0] != AArch64::GPRRegBankID) break; LLT SrcTy = MRI.getType(MI.getOperand(MI.getNumOperands()-1).getReg()); @@ -1322,40 +1051,17 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { // Set the register bank of every operand to FPR. for (unsigned Idx = 0, NumOperands = MI.getNumOperands(); Idx < NumOperands; ++Idx) - OpRegBankIdx[Idx] = PMI_FirstFPR; + OpRegBankIdx[Idx] = AArch64::FPRRegBankID; } break; } - case TargetOpcode::G_EXTRACT_VECTOR_ELT: - // Destination and source need to be FPRs. - OpRegBankIdx[0] = PMI_FirstFPR; - OpRegBankIdx[1] = PMI_FirstFPR; - - // Index needs to be a GPR. - OpRegBankIdx[2] = PMI_FirstGPR; - break; case AArch64::G_SQSHLU_I: // Destination and source need to be FPRs. - OpRegBankIdx[0] = PMI_FirstFPR; - OpRegBankIdx[1] = PMI_FirstFPR; + OpRegBankIdx[0] = AArch64::FPRRegBankID; + OpRegBankIdx[1] = AArch64::FPRRegBankID; // Shift Index needs to be a GPR. - OpRegBankIdx[2] = PMI_FirstGPR; - break; - - case TargetOpcode::G_INSERT_VECTOR_ELT: - OpRegBankIdx[0] = PMI_FirstFPR; - OpRegBankIdx[1] = PMI_FirstFPR; - - // The element may be either a GPR or FPR. Preserve that behaviour. - if (getRegBank(MI.getOperand(2).getReg(), MRI, TRI) == &AArch64::FPRRegBank) - OpRegBankIdx[2] = PMI_FirstFPR; - else { - OpRegBankIdx[2] = PMI_FirstGPR; - } - - // Index needs to be a GPR. - OpRegBankIdx[3] = PMI_FirstGPR; + OpRegBankIdx[2] = AArch64::GPRRegBankID; break; case TargetOpcode::G_EXTRACT: { // For s128 sources we have to use fpr unless we know otherwise. @@ -1364,8 +1070,8 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { if (SrcTy.getSizeInBits() != 128) break; auto Idx = MRI.getRegClassOrNull(Src) == &AArch64::XSeqPairsClassRegClass - ? PMI_FirstGPR - : PMI_FirstFPR; + ? AArch64::GPRRegBankID + : AArch64::FPRRegBankID; OpRegBankIdx[0] = Idx; OpRegBankIdx[1] = Idx; break; @@ -1373,7 +1079,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { case TargetOpcode::G_BUILD_VECTOR: { // If the first source operand belongs to a FPR register bank, then make // sure that we preserve that. - if (OpRegBankIdx[1] != PMI_FirstGPR) + if (OpRegBankIdx[1] != AArch64::GPRRegBankID) break; Register VReg = MI.getOperand(1).getReg(); if (!VReg) @@ -1399,35 +1105,10 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { // Make sure every operand gets mapped to a FPR register class. unsigned NumOperands = MI.getNumOperands(); for (unsigned Idx = 0; Idx < NumOperands; ++Idx) - OpRegBankIdx[Idx] = PMI_FirstFPR; + OpRegBankIdx[Idx] = AArch64::FPRRegBankID; } break; } - case TargetOpcode::G_VECREDUCE_FADD: - case TargetOpcode::G_VECREDUCE_FMUL: - case TargetOpcode::G_VECREDUCE_FMAX: - case TargetOpcode::G_VECREDUCE_FMIN: - case TargetOpcode::G_VECREDUCE_FMAXIMUM: - case TargetOpcode::G_VECREDUCE_FMINIMUM: - case TargetOpcode::G_VECREDUCE_ADD: - case TargetOpcode::G_VECREDUCE_MUL: - case TargetOpcode::G_VECREDUCE_AND: - case TargetOpcode::G_VECREDUCE_OR: - case TargetOpcode::G_VECREDUCE_XOR: - case TargetOpcode::G_VECREDUCE_SMAX: - case TargetOpcode::G_VECREDUCE_SMIN: - case TargetOpcode::G_VECREDUCE_UMAX: - case TargetOpcode::G_VECREDUCE_UMIN: - // Reductions produce a scalar value from a vector, the scalar should be on - // FPR bank. - OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR}; - break; - case TargetOpcode::G_VECREDUCE_SEQ_FADD: - case TargetOpcode::G_VECREDUCE_SEQ_FMUL: - // These reductions also take a scalar accumulator input. - // Assign them FPR for now. - OpRegBankIdx = {PMI_FirstFPR, PMI_FirstFPR, PMI_FirstFPR}; - break; case TargetOpcode::G_INTRINSIC: case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS: { switch (cast<GIntrinsic>(MI).getIntrinsicID()) { @@ -1441,41 +1122,41 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { case Intrinsic::aarch64_neon_fcvtnu: case Intrinsic::aarch64_neon_fcvtps: case Intrinsic::aarch64_neon_fcvtpu: { - OpRegBankIdx[2] = PMI_FirstFPR; + OpRegBankIdx[2] = AArch64::FPRRegBankID; if (shouldUseFPRForCvtOperand(MI, /*BankedOpIsDef=*/true, /*ForceFPRForBankedOp16=*/true, /*ForceFPRForOtherOp16=*/false, /*AllowFPRCVT=*/STI.hasFPRCVT(), /*CheckBankedOpUses=*/true)) - OpRegBankIdx[0] = PMI_FirstFPR; + OpRegBankIdx[0] = AArch64::FPRRegBankID; else - OpRegBankIdx[0] = PMI_FirstGPR; + OpRegBankIdx[0] = AArch64::GPRRegBankID; break; } case Intrinsic::aarch64_neon_vcvtfxs2fp: case Intrinsic::aarch64_neon_vcvtfxu2fp: { - OpRegBankIdx[0] = PMI_FirstFPR; + OpRegBankIdx[0] = AArch64::FPRRegBankID; if (shouldUseFPRForCvtOperand(MI, /*BankedOpIsDef=*/false, /*ForceFPRForBankedOp16=*/false, /*ForceFPRForOtherOp16=*/true, /*AllowFPRCVT=*/false, /*CheckBankedOpUses=*/false)) - OpRegBankIdx[2] = PMI_FirstFPR; + OpRegBankIdx[2] = AArch64::FPRRegBankID; else - OpRegBankIdx[2] = PMI_FirstGPR; + OpRegBankIdx[2] = AArch64::GPRRegBankID; break; } case Intrinsic::aarch64_neon_vcvtfp2fxs: case Intrinsic::aarch64_neon_vcvtfp2fxu: { - OpRegBankIdx[2] = PMI_FirstFPR; + OpRegBankIdx[2] = AArch64::FPRRegBankID; if (shouldUseFPRForCvtOperand(MI, /*BankedOpIsDef=*/true, /*ForceFPRForBankedOp16=*/false, /*ForceFPRForOtherOp16=*/true, /*AllowFPRCVT=*/false, /*CheckBankedOpUses=*/true)) - OpRegBankIdx[0] = PMI_FirstFPR; + OpRegBankIdx[0] = AArch64::FPRRegBankID; else - OpRegBankIdx[0] = PMI_FirstGPR; + OpRegBankIdx[0] = AArch64::GPRRegBankID; break; } default: { @@ -1485,7 +1166,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { if (onlyDefinesFP(MI, MRI, TRI)) for (const auto &Op : MI.defs()) { if (Op.isReg()) - OpRegBankIdx[Idx] = PMI_FirstFPR; + OpRegBankIdx[Idx] = AArch64::FPRRegBankID; ++Idx; } else @@ -1494,7 +1175,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { if (onlyUsesFP(MI, MRI, TRI)) for (const auto &Op : MI.explicit_uses()) { if (Op.isReg()) - OpRegBankIdx[Idx] = PMI_FirstFPR; + OpRegBankIdx[Idx] = AArch64::FPRRegBankID; ++Idx; } break; @@ -1511,8 +1192,8 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { LLT Ty = MRI.getType(MI.getOperand(Idx).getReg()); if (!Ty.isValid()) continue; - auto Mapping = - getValueMapping(OpRegBankIdx[Idx], TypeSize::getFixed(OpSize[Idx])); + auto Mapping = AArch64::getGeneratedValueMapping( + OpRegBankIdx[Idx], TypeSize::getFixed(OpSize[Idx])); if (!Mapping->isValid()) return getInvalidInstructionMapping(); diff --git a/llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.h b/llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.h index 53bf6146ad437b..5fcc135a6d7a8a 100644 --- a/llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.h +++ b/llvm/lib/Target/AArch64/GISel/AArch64RegisterBankInfo.h @@ -26,78 +26,11 @@ class AArch64RegisterInfo; class AArch64GenRegisterBankInfo : public RegisterBankInfo { protected: - enum PartialMappingIdx { - PMI_None = -1, - PMI_FPR16 = 1, - PMI_FPR32, - PMI_FPR64, - PMI_FPR128, - PMI_FPR256, - PMI_FPR512, - PMI_GPR32, - PMI_GPR64, - PMI_GPR128, - PMI_FirstGPR = PMI_GPR32, - PMI_LastGPR = PMI_GPR128, - PMI_FirstFPR = PMI_FPR16, - PMI_LastFPR = PMI_FPR512, - PMI_Min = PMI_FirstFPR, - }; - - static const RegisterBankInfo::PartialMapping PartMappings[]; - static const RegisterBankInfo::ValueMapping ValMappings[]; - static const PartialMappingIdx BankIDToCopyMapIdx[]; - - enum ValueMappingIdx { - InvalidIdx = 0, - First3OpsIdx = 1, - Last3OpsIdx = 25, - DistanceBetweenRegBanks = 3, - FirstCrossRegCpyIdx = 28, - LastCrossRegCpyIdx = 42, - DistanceBetweenCrossRegCpy = 2, - FPExt16To32Idx = 44, - FPExt16To64Idx = 46, - FPExt32To64Idx = 48, - FPExt64To128Idx = 50, - Shift64Imm = 52, - }; - - static bool checkPartialMap(unsigned Idx, unsigned ValStartIdx, - unsigned ValLength, const RegisterBank &RB); - static bool checkValueMapImpl(unsigned Idx, unsigned FirstInBank, - unsigned Size, unsigned Offset); - static bool checkPartialMappingIdx(PartialMappingIdx FirstAlias, - PartialMappingIdx LastAlias, - ArrayRef<PartialMappingIdx> Order); - - static unsigned getRegBankBaseIdxOffset(unsigned RBIdx, TypeSize Size); - - /// Get the pointer to the ValueMapping representing the RegisterBank - /// at \p RBIdx with a size of \p Size. - /// - /// The returned mapping works for instructions with the same kind of - /// operands for up to 3 operands. - /// - /// \pre \p RBIdx != PartialMappingIdx::None - static const RegisterBankInfo::ValueMapping * - getValueMapping(PartialMappingIdx RBIdx, TypeSize Size); - /// Get the pointer to the ValueMapping of the operands of a copy /// instruction from the \p SrcBankID register bank to the \p DstBankID /// register bank with a size of \p Size. - static const RegisterBankInfo::ValueMapping * - getCopyMapping(unsigned DstBankID, unsigned SrcBankID, TypeSize Size); - - /// Get the instruction mapping for G_FPEXT. - /// - /// \pre (DstSize, SrcSize) pair is one of the following: - /// (32, 16), (64, 16), (64, 32), (128, 64) - /// - /// \return An InstructionMapping with statically allocated OperandsMapping. - static const RegisterBankInfo::ValueMapping * - getFPExtMapping(unsigned DstSize, unsigned SrcSize); - + const RegisterBankInfo::ValueMapping * + getCopyMapping(unsigned DstBankID, unsigned SrcBankID, TypeSize Size) const; #define GET_TARGET_REGBANK_CLASS #include "AArch64GenRegisterBank.inc" }; @@ -108,16 +41,6 @@ class AArch64RegisterBankInfo final : public AArch64GenRegisterBankInfo { void applyMappingImpl(MachineIRBuilder &Builder, const OperandsMapper &OpdMapper) const override; - /// Get an instruction mapping where all the operands map to - /// the same register bank and have similar size. - /// - /// \pre MI.getNumOperands() <= 3 - /// - /// \return An InstructionMappings with a statically allocated - /// OperandsMapping. - const InstructionMapping & - getSameKindOfOperandsMapping(const MachineInstr &MI) const; - /// Maximum recursion depth for hasFPConstraints. const unsigned MaxFPRSearchDepth = 2; _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
