37#include "llvm/IR/IntrinsicsAArch64.h"
42#define GET_TARGET_REGBANK_IMPL
43#include "AArch64GenRegisterBank.inc"
46#include "AArch64GenRegisterBankInfo.def"
55 static auto InitializeRegisterBankOnce = [&]() {
64 assert(&AArch64::GPRRegBank == &RBGPR &&
65 "The order in RegBanks is messed up");
69 assert(&AArch64::FPRRegBank == &RBFPR &&
70 "The order in RegBanks is messed up");
74 assert(&AArch64::CCRegBank == &RBCCR &&
75 "The order in RegBanks is messed up");
80 "Subclass not added?");
82 "GPRs should hold up to 128-bit");
87 "Subclass not added?");
89 "Subclass not added?");
91 "FPRs should hold up to 512-bit via QQQQ sequence");
96 "CCR should hold up to 32-bit");
102 "PartialMappingIdx's are incorrectly ordered");
106 "PartialMappingIdx's are incorrectly ordered");
109#define CHECK_PARTIALMAP(Idx, ValStartIdx, ValLength, RB) \
112 checkPartialMap(PartialMappingIdx::Idx, ValStartIdx, ValLength, RB) && \
113 #Idx " is incorrectly initialized"); \
127#define CHECK_VALUEMAP_IMPL(RBName, Size, Offset) \
129 assert(checkValueMapImpl(PartialMappingIdx::PMI_##RBName##Size, \
130 PartialMappingIdx::PMI_First##RBName, Size, \
132 #RBName #Size " " #Offset " is incorrectly initialized"); \
135#define CHECK_VALUEMAP(RBName, Size) CHECK_VALUEMAP_IMPL(RBName, Size, 0)
149#define CHECK_VALUEMAP_3OPS(RBName, Size) \
151 CHECK_VALUEMAP_IMPL(RBName, Size, 0); \
152 CHECK_VALUEMAP_IMPL(RBName, Size, 1); \
153 CHECK_VALUEMAP_IMPL(RBName, Size, 2); \
165#define CHECK_VALUEMAP_CROSSREGCPY(RBNameDst, RBNameSrc, Size) \
167 unsigned PartialMapDstIdx = PMI_##RBNameDst##Size - PMI_Min; \
168 unsigned PartialMapSrcIdx = PMI_##RBNameSrc##Size - PMI_Min; \
169 (void)PartialMapDstIdx; \
170 (void)PartialMapSrcIdx; \
171 const ValueMapping *Map = getCopyMapping(AArch64::RBNameDst##RegBankID, \
172 AArch64::RBNameSrc##RegBankID, \
173 TypeSize::getFixed(Size)); \
175 assert(Map[0].BreakDown == \
176 &AArch64GenRegisterBankInfo::PartMappings[PartialMapDstIdx] && \
177 Map[0].NumBreakDowns == 1 && \
178 #RBNameDst #Size " Dst is incorrectly initialized"); \
179 assert(Map[1].BreakDown == \
180 &AArch64GenRegisterBankInfo::PartMappings[PartialMapSrcIdx] && \
181 Map[1].NumBreakDowns == 1 && \
182 #RBNameSrc #Size " Src is incorrectly initialized"); \
195#define CHECK_VALUEMAP_FPEXT(DstSize, SrcSize) \
197 unsigned PartialMapDstIdx = PMI_FPR##DstSize - PMI_Min; \
198 unsigned PartialMapSrcIdx = PMI_FPR##SrcSize - PMI_Min; \
199 (void)PartialMapDstIdx; \
200 (void)PartialMapSrcIdx; \
201 const ValueMapping *Map = getFPExtMapping(DstSize, SrcSize); \
203 assert(Map[0].BreakDown == \
204 &AArch64GenRegisterBankInfo::PartMappings[PartialMapDstIdx] && \
205 Map[0].NumBreakDowns == 1 && "FPR" #DstSize \
206 " Dst is incorrectly initialized"); \
207 assert(Map[1].BreakDown == \
208 &AArch64GenRegisterBankInfo::PartMappings[PartialMapSrcIdx] && \
209 Map[1].NumBreakDowns == 1 && "FPR" #SrcSize \
210 " Src is incorrectly initialized"); \
222 llvm::call_once(InitializeRegisterBankFlag, InitializeRegisterBankOnce);
236 if (&
A == &AArch64::GPRRegBank && &
B == &AArch64::FPRRegBank)
239 if (&
A == &AArch64::FPRRegBank && &
B == &AArch64::GPRRegBank)
249 switch (RC.
getID()) {
250 case AArch64::GPR64sponlyRegClassID:
265 switch (
MI.getOpcode()) {
266 case TargetOpcode::G_OR: {
275 if (
MI.getNumOperands() != 3)
289 case TargetOpcode::G_BITCAST: {
296 if (
MI.getNumOperands() != 2)
311 copyCost(AArch64::GPRRegBank, AArch64::FPRRegBank,
318 copyCost(AArch64::GPRRegBank, AArch64::FPRRegBank,
329 case TargetOpcode::G_LOAD: {
336 if (
MI.getNumOperands() != 2)
368 assert(
MI.getOpcode() == TargetOpcode::G_FCONSTANT);
370 LLT Ty =
MRI.getType(Dst);
372 unsigned Size = Ty.getSizeInBits();
379 const APFloat Imm =
MI.getOperand(1).getFPImm()->getValueAPF();
380 const APInt ImmBits = Imm.bitcastToAPInt();
399 return !IsFMov && IsLegal;
414 if (!TruncMI || TruncMI->
getOpcode() != TargetOpcode::G_TRUNC)
419 if (!SrcDef || SrcDef->
getOpcode() != TargetOpcode::G_CONSTANT)
422 LLT TruncSrcTy =
MRI.getType(TruncSrc);
428 MRI.setRegBank(TruncSrc, RBI.
getRegBank(AArch64::GPRRegBankID));
430 if (
MRI.use_empty(ScalarReg))
436void AArch64RegisterBankInfo::applyMappingImpl(
438 MachineInstr &
MI = OpdMapper.getMI();
439 MachineRegisterInfo &
MRI = OpdMapper.getMRI();
441 switch (
MI.getOpcode()) {
442 case TargetOpcode::G_CONSTANT: {
444 [[maybe_unused]] LLT DstTy =
MRI.getType(Dst);
447 "Expected a scalar smaller than 32 bits on a GPR.");
452 APInt Val =
MI.getOperand(1).getCImm()->getValue().zext(32);
454 MI.getOperand(1).setCImm(ConstantInt::get(Ctx, Val));
455 MI.getOperand(0).setReg(ExtReg);
456 MRI.setRegBank(ExtReg, AArch64::GPRRegBank);
460 case TargetOpcode::G_FCONSTANT: {
462 assert(
MRI.getRegBank(Dst) == &AArch64::GPRRegBank &&
463 "Expected Dst to be on a GPR.");
464 const APFloat &
Imm =
MI.getOperand(1).getFPImm()->getValueAPF();
465 APInt
Bits =
Imm.bitcastToAPInt();
467 if (
Bits.getBitWidth() < 32) {
471 MRI.setRegBank(ExtReg, AArch64::GPRRegBank);
475 MI.eraseFromParent();
478 case TargetOpcode::G_STORE: {
480 LLT Ty =
MRI.getType(Dst);
482 if (
MRI.getRegBank(Dst) == &AArch64::GPRRegBank && Ty.
isScalar() &&
490 MI.getOperand(0).setReg(Ext.getReg(0));
491 MRI.setRegBank(Ext.getReg(0), AArch64::GPRRegBank);
495 case TargetOpcode::G_LOAD: {
497 LLT Ty =
MRI.getType(Dst);
498 if (
MRI.getRegBank(Dst) == &AArch64::GPRRegBank && Ty.
isScalar() &&
503 MI.getOperand(0).setReg(ExtReg);
504 MRI.setRegBank(ExtReg, AArch64::GPRRegBank);
508 case TargetOpcode::G_OR:
509 case TargetOpcode::G_BITCAST:
511 assert((OpdMapper.getInstrMapping().getID() >= 1 &&
512 OpdMapper.getInstrMapping().getID() <= 4) &&
513 "Don't know how to handle that ID");
515 case TargetOpcode::G_INSERT_VECTOR_ELT: {
522 MRI.setRegBank(Ext.getReg(0),
getRegBank(AArch64::GPRRegBankID));
523 MI.getOperand(2).setReg(Ext.getReg(0));
526 case AArch64::G_DUP: {
531 assert(
MRI.getType(
MI.getOperand(1).getReg()).getSizeInBits() < 32 &&
532 "Expected sources smaller than 32-bits");
539 MI.getOperand(1).setReg(ConstReg);
549AArch64RegisterBankInfo::getSameKindOfOperandsMapping(
551 const unsigned Opc =
MI.getOpcode();
552 const MachineFunction &MF = *
MI.getParent()->getParent();
555 unsigned NumOperands =
MI.getNumOperands();
556 assert(NumOperands <= 3 &&
557 "This code is for instructions with 3 or less operands");
559 LLT Ty =
MRI.getType(
MI.getOperand(0).getReg());
574 for (
unsigned Idx = 1; Idx != NumOperands; ++Idx) {
575 LLT OpTy =
MRI.getType(
MI.getOperand(Idx).getReg());
580 "Operand has incompatible size");
583 assert(IsFPR == OpIsFPR &&
"Operand has incompatible type");
598 case Intrinsic::aarch64_neon_uaddlv:
599 case Intrinsic::aarch64_neon_uaddv:
600 case Intrinsic::aarch64_neon_saddv:
601 case Intrinsic::aarch64_neon_umaxv:
602 case Intrinsic::aarch64_neon_smaxv:
603 case Intrinsic::aarch64_neon_uminv:
604 case Intrinsic::aarch64_neon_sminv:
605 case Intrinsic::aarch64_neon_faddv:
606 case Intrinsic::aarch64_neon_fmaxv:
607 case Intrinsic::aarch64_neon_fminv:
608 case Intrinsic::aarch64_neon_fmaxnmv:
609 case Intrinsic::aarch64_neon_fminnmv:
610 case Intrinsic::aarch64_neon_fmulx:
611 case Intrinsic::aarch64_neon_frecpe:
612 case Intrinsic::aarch64_neon_frecps:
613 case Intrinsic::aarch64_neon_frecpx:
614 case Intrinsic::aarch64_neon_frsqrte:
615 case Intrinsic::aarch64_neon_frsqrts:
616 case Intrinsic::aarch64_neon_facge:
617 case Intrinsic::aarch64_neon_facgt:
618 case Intrinsic::aarch64_neon_fabd:
619 case Intrinsic::aarch64_neon_sqrdmlah:
620 case Intrinsic::aarch64_neon_sqrdmlsh:
621 case Intrinsic::aarch64_neon_sqrdmulh:
622 case Intrinsic::aarch64_neon_sqadd:
623 case Intrinsic::aarch64_neon_sqsub:
624 case Intrinsic::aarch64_neon_srshl:
625 case Intrinsic::aarch64_neon_urshl:
626 case Intrinsic::aarch64_neon_sqshl:
627 case Intrinsic::aarch64_neon_uqshl:
628 case Intrinsic::aarch64_neon_sqrshl:
629 case Intrinsic::aarch64_neon_uqrshl:
630 case Intrinsic::aarch64_neon_ushl:
631 case Intrinsic::aarch64_neon_sshl:
632 case Intrinsic::aarch64_neon_sqshrn:
633 case Intrinsic::aarch64_neon_sqshrun:
634 case Intrinsic::aarch64_neon_sqrshrn:
635 case Intrinsic::aarch64_neon_sqrshrun:
636 case Intrinsic::aarch64_neon_uqshrn:
637 case Intrinsic::aarch64_neon_uqrshrn:
638 case Intrinsic::aarch64_crypto_sha1h:
639 case Intrinsic::aarch64_crypto_sha1c:
640 case Intrinsic::aarch64_crypto_sha1p:
641 case Intrinsic::aarch64_crypto_sha1m:
642 case Intrinsic::aarch64_sisd_fcvtxn:
643 case Intrinsic::aarch64_sisd_fabd:
645 case Intrinsic::aarch64_neon_saddlv: {
646 const LLT SrcTy =
MRI.getType(
MI.getOperand(2).getReg());
647 return SrcTy.getElementType().getSizeInBits() >= 16 &&
648 SrcTy.getElementCount().getFixedValue() >= 4;
653bool AArch64RegisterBankInfo::isPHIWithFPConstraints(
656 if (!
MI.isPHI() ||
Depth > MaxFPRSearchDepth)
659 return any_of(
MRI.use_nodbg_instructions(
MI.getOperand(0).getReg()),
660 [&](
const MachineInstr &
UseMI) {
661 if (onlyUsesFP(UseMI, MRI, TRI, Depth + 1))
663 return isPHIWithFPConstraints(UseMI, MRI, TRI, Depth + 1);
667bool AArch64RegisterBankInfo::hasFPConstraints(
const MachineInstr &
MI,
670 unsigned Depth)
const {
671 unsigned Op =
MI.getOpcode();
681 if (
Op != TargetOpcode::COPY && !
MI.isPHI() &&
687 if (RB == &AArch64::FPRRegBank)
689 if (RB == &AArch64::GPRRegBank)
696 if (!
MI.isPHI() ||
Depth > MaxFPRSearchDepth)
699 return any_of(
MI.explicit_uses(), [&](
const MachineOperand &
Op) {
701 onlyDefinesFP(*MRI.getVRegDef(Op.getReg()), MRI, TRI, Depth + 1);
708 unsigned Depth)
const {
709 switch (
MI.getOpcode()) {
710 case TargetOpcode::G_FPTOSI:
711 case TargetOpcode::G_FPTOUI:
712 case TargetOpcode::G_FPTOSI_SAT:
713 case TargetOpcode::G_FPTOUI_SAT:
714 case TargetOpcode::G_FCMP:
715 case TargetOpcode::G_LROUND:
716 case TargetOpcode::G_LLROUND:
717 case AArch64::G_PMULL:
721 case TargetOpcode::G_INTRINSIC:
723 case Intrinsic::aarch64_neon_fcvtas:
724 case Intrinsic::aarch64_neon_fcvtau:
725 case Intrinsic::aarch64_neon_fcvtzs:
726 case Intrinsic::aarch64_neon_fcvtzu:
727 case Intrinsic::aarch64_neon_fcvtms:
728 case Intrinsic::aarch64_neon_fcvtmu:
729 case Intrinsic::aarch64_neon_fcvtns:
730 case Intrinsic::aarch64_neon_fcvtnu:
731 case Intrinsic::aarch64_neon_fcvtps:
732 case Intrinsic::aarch64_neon_fcvtpu:
744bool AArch64RegisterBankInfo::onlyDefinesFP(
const MachineInstr &
MI,
747 unsigned Depth)
const {
748 switch (
MI.getOpcode()) {
750 case AArch64::G_SADDLP:
751 case AArch64::G_UADDLP:
752 case TargetOpcode::G_SITOFP:
753 case TargetOpcode::G_UITOFP:
754 case TargetOpcode::G_EXTRACT_VECTOR_ELT:
755 case TargetOpcode::G_INSERT_VECTOR_ELT:
756 case TargetOpcode::G_BUILD_VECTOR:
757 case TargetOpcode::G_BUILD_VECTOR_TRUNC:
761 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
763 case Intrinsic::aarch64_neon_ld1x2:
764 case Intrinsic::aarch64_neon_ld1x3:
765 case Intrinsic::aarch64_neon_ld1x4:
766 case Intrinsic::aarch64_neon_ld2:
767 case Intrinsic::aarch64_neon_ld2lane:
768 case Intrinsic::aarch64_neon_ld2r:
769 case Intrinsic::aarch64_neon_ld3:
770 case Intrinsic::aarch64_neon_ld3lane:
771 case Intrinsic::aarch64_neon_ld3r:
772 case Intrinsic::aarch64_neon_ld4:
773 case Intrinsic::aarch64_neon_ld4lane:
774 case Intrinsic::aarch64_neon_ld4r:
789 unsigned Depth)
const {
790 switch (
MI.getOpcode()) {
791 case TargetOpcode::G_SITOFP:
792 case TargetOpcode::G_UITOFP:
793 return MRI.getType(
MI.getOperand(0).getReg()).getSizeInBits() ==
794 MRI.getType(
MI.getOperand(1).getReg()).getSizeInBits();
799bool AArch64RegisterBankInfo::isLoadFromFPType(
const MachineInstr &
MI)
const {
802 const Value *LdVal = MemOp->getMMO().getValue();
806 Type *EltTy =
nullptr;
808 EltTy = GV->getValueType();
812 if (StructEltTy->getNumElements() == 0)
814 EltTy = StructEltTy->getTypeAtIndex(0U);
822 for (
const auto *LdUser : LdVal->
users()) {
824 EltTy = LdUser->getType();
828 EltTy = LdUser->getOperand(0)->getType();
838 const unsigned Opc =
MI.getOpcode();
843 Opc == TargetOpcode::G_PHI) {
858 case TargetOpcode::G_ADD:
859 case TargetOpcode::G_SUB:
860 case TargetOpcode::G_PTR_ADD:
861 case TargetOpcode::G_MUL:
862 case TargetOpcode::G_SDIV:
863 case TargetOpcode::G_UDIV:
865 case TargetOpcode::G_AND:
866 case TargetOpcode::G_OR:
867 case TargetOpcode::G_XOR:
869 case TargetOpcode::G_FADD:
870 case TargetOpcode::G_FSUB:
871 case TargetOpcode::G_FMUL:
872 case TargetOpcode::G_FDIV:
873 case TargetOpcode::G_FMAXIMUM:
874 case TargetOpcode::G_FMINIMUM:
875 return getSameKindOfOperandsMapping(
MI);
876 case TargetOpcode::G_FPEXT: {
877 LLT DstTy =
MRI.getType(
MI.getOperand(0).getReg());
878 LLT SrcTy =
MRI.getType(
MI.getOperand(1).getReg());
885 case TargetOpcode::G_SHL:
886 case TargetOpcode::G_LSHR:
887 case TargetOpcode::G_ASHR: {
888 LLT ShiftAmtTy =
MRI.getType(
MI.getOperand(2).getReg());
889 LLT SrcTy =
MRI.getType(
MI.getOperand(1).getReg());
890 if (ShiftAmtTy.
getSizeInBits() == 64 && SrcTy.getSizeInBits() == 32)
893 return getSameKindOfOperandsMapping(
MI);
895 case TargetOpcode::COPY: {
899 if ((DstReg.
isPhysical() || !
MRI.getType(DstReg).isValid()) ||
909 assert(DstRB && SrcRB &&
"Both RegBank were nullptr");
920 case TargetOpcode::G_BITCAST: {
921 LLT DstTy =
MRI.getType(
MI.getOperand(0).getReg());
922 LLT SrcTy =
MRI.getType(
MI.getOperand(1).getReg());
925 bool SrcIsGPR = !SrcTy.isVector() && SrcTy.getSizeInBits() <= 64;
927 DstIsGPR ? AArch64::GPRRegBank : AArch64::FPRRegBank;
929 SrcIsGPR ? AArch64::GPRRegBank : AArch64::FPRRegBank;
934 Opc == TargetOpcode::G_BITCAST ? 2 : 1);
940 unsigned NumOperands =
MI.getNumOperands();
946 for (
unsigned Idx = 0; Idx < NumOperands; ++Idx) {
947 auto &MO =
MI.getOperand(Idx);
948 if (!MO.isReg() || !MO.getReg())
951 LLT Ty =
MRI.getType(MO.getReg());
954 OpSize[Idx] = Ty.getSizeInBits().getKnownMinValue();
962 (MO.isDef() && onlyDefinesFP(
MI,
MRI,
TRI)) ||
963 (MO.isUse() && onlyUsesFP(
MI,
MRI,
TRI)) ||
964 Ty.getSizeInBits() > 64)
974 case TargetOpcode::G_CONSTANT: {
976 LLT DstTy =
MRI.getType(Dst);
981 case TargetOpcode::G_FCONSTANT: {
989 case AArch64::G_DUP: {
990 Register ScalarReg =
MI.getOperand(1).getReg();
991 LLT ScalarTy =
MRI.getType(ScalarReg);
992 auto ScalarDef =
MRI.getVRegDef(ScalarReg);
994 if (ScalarDef->getOpcode() == TargetOpcode::G_LOAD)
999 onlyDefinesFP(*ScalarDef,
MRI,
TRI)))
1011 case TargetOpcode::G_TRUNC: {
1012 LLT SrcTy =
MRI.getType(
MI.getOperand(1).getReg());
1013 if (!SrcTy.isVector() && SrcTy.getSizeInBits() == 128)
1017 case TargetOpcode::G_SITOFP:
1018 case TargetOpcode::G_UITOFP: {
1019 if (
MRI.getType(
MI.getOperand(0).getReg()).isVector())
1025 MRI.getType(SrcReg).getSizeInBits() ==
1026 MRI.getType(
MI.getOperand(0).getReg()).getSizeInBits())
1032 case TargetOpcode::G_FPTOSI_SAT:
1033 case TargetOpcode::G_FPTOUI_SAT:
1034 case TargetOpcode::G_FPTOSI:
1035 case TargetOpcode::G_FPTOUI:
1036 case TargetOpcode::G_INTRINSIC_LRINT:
1037 case TargetOpcode::G_INTRINSIC_LLRINT:
1038 case TargetOpcode::G_LROUND:
1039 case TargetOpcode::G_LLROUND: {
1040 LLT DstType =
MRI.getType(
MI.getOperand(0).getReg());
1041 if (DstType.isVector())
1049 if (((DstSize == SrcSize) || STI.hasFeature(AArch64::FeatureFPRCVT)) &&
1050 all_of(
MRI.use_nodbg_instructions(
MI.getOperand(0).getReg()),
1052 return onlyUsesFP(UseMI, MRI, TRI) ||
1053 prefersFPUse(UseMI, MRI, TRI);
1060 case TargetOpcode::G_FCMP: {
1065 OpRegBankIdx = {Idx0,
1069 case TargetOpcode::G_BITCAST:
1071 if (OpRegBankIdx[0] != OpRegBankIdx[1])
1077 case TargetOpcode::G_LOAD: {
1092 if (
MRI.getType(
MI.getOperand(0).getReg()).getSizeInBits() < 32)
1098 if (isLoadFromFPType(
MI)) {
1106 if (
any_of(
MRI.use_nodbg_instructions(
MI.getOperand(0).getReg()),
1117 if (isPHIWithFPConstraints(UseMI, MRI, TRI))
1120 return onlyUsesFP(UseMI, MRI, TRI) ||
1121 prefersFPUse(UseMI, MRI, TRI);
1126 LLT Ty =
MRI.getType(
MI.getOperand(0).getReg());
1127 if (Ty.isScalar() && Ty.getSizeInBits() < 32)
1131 case TargetOpcode::G_STORE:
1144 LLT Ty =
MRI.getType(
MI.getOperand(0).getReg());
1145 if (Ty.isScalar() && Ty.getSizeInBits() < 32)
1149 case TargetOpcode::G_INDEXED_STORE:
1160 case TargetOpcode::G_INDEXED_SEXTLOAD:
1161 case TargetOpcode::G_INDEXED_ZEXTLOAD:
1165 case TargetOpcode::G_INDEXED_LOAD: {
1166 if (isLoadFromFPType(
MI))
1170 case TargetOpcode::G_SELECT: {
1177 LLT SrcTy =
MRI.getType(
MI.getOperand(2).getReg());
1178 if (SrcTy.isVector()) {
1194 if (
any_of(
MRI.use_nodbg_instructions(
MI.getOperand(0).getReg()),
1211 for (
unsigned Idx = 2; Idx < 4; ++Idx) {
1226 case TargetOpcode::G_UNMERGE_VALUES: {
1232 LLT SrcTy =
MRI.getType(
MI.getOperand(
MI.getNumOperands()-1).getReg());
1235 if (SrcTy.isVector() || SrcTy ==
LLT::scalar(128) ||
1236 any_of(
MRI.use_nodbg_instructions(
MI.getOperand(0).getReg()),
1239 for (
unsigned Idx = 0, NumOperands =
MI.getNumOperands();
1240 Idx < NumOperands; ++Idx)
1245 case TargetOpcode::G_EXTRACT_VECTOR_ELT:
1253 case AArch64::G_SQSHLU_I:
1262 case TargetOpcode::G_INSERT_VECTOR_ELT:
1272 LLT Ty =
MRI.getType(
MI.getOperand(2).getReg());
1273 if (Ty.getSizeInBits() == 8 || Ty.getSizeInBits() == 16) {
1283 case TargetOpcode::G_EXTRACT: {
1285 auto Src =
MI.getOperand(1).getReg();
1286 LLT SrcTy =
MRI.getType(
MI.getOperand(1).getReg());
1287 if (SrcTy.getSizeInBits() != 128)
1289 auto Idx =
MRI.getRegClassOrNull(Src) == &AArch64::XSeqPairsClassRegClass
1292 OpRegBankIdx[0] = Idx;
1293 OpRegBankIdx[1] = Idx;
1296 case TargetOpcode::G_BUILD_VECTOR: {
1311 unsigned DefOpc =
DefMI->getOpcode();
1312 const LLT SrcTy =
MRI.getType(VReg);
1314 return Op.isDef() || MRI.getVRegDef(Op.getReg())->getOpcode() ==
1315 TargetOpcode::G_CONSTANT;
1319 SrcTy.getSizeInBits() < 32 ||
1323 unsigned NumOperands =
MI.getNumOperands();
1324 for (
unsigned Idx = 0; Idx < NumOperands; ++Idx)
1329 case TargetOpcode::G_VECREDUCE_FADD:
1330 case TargetOpcode::G_VECREDUCE_FMUL:
1331 case TargetOpcode::G_VECREDUCE_FMAX:
1332 case TargetOpcode::G_VECREDUCE_FMIN:
1333 case TargetOpcode::G_VECREDUCE_FMAXIMUM:
1334 case TargetOpcode::G_VECREDUCE_FMINIMUM:
1335 case TargetOpcode::G_VECREDUCE_ADD:
1336 case TargetOpcode::G_VECREDUCE_MUL:
1337 case TargetOpcode::G_VECREDUCE_AND:
1338 case TargetOpcode::G_VECREDUCE_OR:
1339 case TargetOpcode::G_VECREDUCE_XOR:
1340 case TargetOpcode::G_VECREDUCE_SMAX:
1341 case TargetOpcode::G_VECREDUCE_SMIN:
1342 case TargetOpcode::G_VECREDUCE_UMAX:
1343 case TargetOpcode::G_VECREDUCE_UMIN:
1348 case TargetOpcode::G_VECREDUCE_SEQ_FADD:
1349 case TargetOpcode::G_VECREDUCE_SEQ_FMUL:
1354 case TargetOpcode::G_INTRINSIC:
1355 case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS: {
1357 case Intrinsic::aarch64_neon_fcvtas:
1358 case Intrinsic::aarch64_neon_fcvtau:
1359 case Intrinsic::aarch64_neon_fcvtzs:
1360 case Intrinsic::aarch64_neon_fcvtzu:
1361 case Intrinsic::aarch64_neon_fcvtms:
1362 case Intrinsic::aarch64_neon_fcvtmu:
1363 case Intrinsic::aarch64_neon_fcvtns:
1364 case Intrinsic::aarch64_neon_fcvtnu:
1365 case Intrinsic::aarch64_neon_fcvtps:
1366 case Intrinsic::aarch64_neon_fcvtpu: {
1368 if (
MRI.getType(
MI.getOperand(0).getReg()).isVector()) {
1378 if (DstSize == 16 ||
1379 ((DstSize == SrcSize || STI.hasFeature(AArch64::FeatureFPRCVT)) &&
1380 all_of(
MRI.use_nodbg_instructions(
MI.getOperand(0).getReg()),
1382 return onlyUsesFP(UseMI, MRI, TRI) ||
1383 prefersFPUse(UseMI, MRI, TRI);
1390 case Intrinsic::aarch64_neon_vcvtfxs2fp:
1391 case Intrinsic::aarch64_neon_vcvtfxu2fp:
1392 case Intrinsic::aarch64_neon_vcvtfp2fxs:
1393 case Intrinsic::aarch64_neon_vcvtfp2fxu:
1407 for (
const auto &
Op :
MI.defs()) {
1413 Idx +=
MI.getNumExplicitDefs();
1416 for (
const auto &
Op :
MI.explicit_uses()) {
1430 for (
unsigned Idx = 0; Idx < NumOperands; ++Idx) {
1431 if (
MI.getOperand(Idx).isReg() &&
MI.getOperand(Idx).getReg()) {
1432 LLT Ty =
MRI.getType(
MI.getOperand(Idx).getReg());
1437 if (!Mapping->isValid())
1440 OpdsMapping[Idx] = Mapping;
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
static unsigned getIntrinsicID(const SDNode *N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define CHECK_VALUEMAP(RBName, Size)
static bool isFPIntrinsic(const MachineRegisterInfo &MRI, const MachineInstr &MI)
#define CHECK_VALUEMAP_3OPS(RBName, Size)
static bool foldTruncOfI32Constant(MachineInstr &MI, unsigned OpIdx, MachineRegisterInfo &MRI, const AArch64RegisterBankInfo &RBI)
static const unsigned CustomMappingID
#define CHECK_PARTIALMAP(Idx, ValStartIdx, ValLength, RB)
#define CHECK_VALUEMAP_CROSSREGCPY(RBNameDst, RBNameSrc, Size)
#define CHECK_VALUEMAP_FPEXT(DstSize, SrcSize)
static bool preferGPRForFPImm(const MachineInstr &MI, const MachineRegisterInfo &MRI, const AArch64Subtarget &STI)
This file declares the targeting of the RegisterBankInfo class for AArch64.
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
Implement a low-level type suitable for MachineInstr level instruction selection.
This file declares the MachineIRBuilder class.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
MachineInstr unsigned OpIdx
static const MCPhysReg FPR[]
FPR - The set of FP registers that should be allocated for arguments on Darwin and AIX.
This file defines the SmallVector class.
static unsigned getRegBankBaseIdxOffset(unsigned RBIdx, TypeSize Size)
static const RegisterBankInfo::ValueMapping * getCopyMapping(unsigned DstBankID, unsigned SrcBankID, TypeSize Size)
Get the pointer to the ValueMapping of the operands of a copy instruction from the SrcBankID register...
static bool checkPartialMappingIdx(PartialMappingIdx FirstAlias, PartialMappingIdx LastAlias, ArrayRef< PartialMappingIdx > Order)
static const RegisterBankInfo::PartialMapping PartMappings[]
static const RegisterBankInfo::ValueMapping * getFPExtMapping(unsigned DstSize, unsigned SrcSize)
Get the instruction mapping for G_FPEXT.
static const RegisterBankInfo::ValueMapping * getValueMapping(PartialMappingIdx RBIdx, TypeSize Size)
Get the pointer to the ValueMapping representing the RegisterBank at RBIdx with a size of Size.
static const RegisterBankInfo::ValueMapping ValMappings[]
This class provides the information for the target register banks.
InstructionMappings getInstrAlternativeMappings(const MachineInstr &MI) const override
Get the alternative mappings for MI.
unsigned copyCost(const RegisterBank &A, const RegisterBank &B, TypeSize Size) const override
Get the cost of a copy from B to A, or put differently, get the cost of A = COPY B.
const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC, LLT Ty) const override
Get a register bank that covers RC.
AArch64RegisterBankInfo(const TargetRegisterInfo &TRI)
const InstructionMapping & getInstrMapping(const MachineInstr &MI) const override
Get the mapping of the different operands of MI on the register bank.
const AArch64RegisterInfo * getRegisterInfo() const override
const AArch64TargetLowering * getTargetLowering() const override
bool isFPImmLegal(const APFloat &Imm, EVT VT, bool ForCodeSize) const override
Returns true if the target can instruction select the specified FP immediate natively.
bool isFPImmLegalAsFMov(const APFloat &Imm, EVT VT) const
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
static LLVM_ABI APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
constexpr bool isScalar() const
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isVector() const
constexpr TypeSize getSizeInBits() const
Returns the total size of the type. Must only be called on sized types.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Helper class to build MachineInstr.
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
MachineFunction & getMF()
Getter for the function we currently build.
MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op, std::optional< unsigned > Flags=std::nullopt)
Build and insert Res = G_TRUNC Op.
MachineInstrBuilder buildAnyExt(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ANYEXT Op0.
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
Register getReg(unsigned Idx) const
Get the register for the operand index.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
LLVM_ABI void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Helper class that represents how the value of an instruction may be mapped and what is the related co...
bool isValid() const
Check whether this object is valid.
virtual InstructionMappings getInstrAlternativeMappings(const MachineInstr &MI) const
Get the alternative mappings for MI.
const InstructionMapping & getInstructionMapping(unsigned ID, unsigned Cost, const ValueMapping *OperandsMapping, unsigned NumOperands) const
Method to get a uniquely generated InstructionMapping.
static void applyDefaultMapping(const OperandsMapper &OpdMapper)
Helper method to apply something that is like the default mapping.
const InstructionMapping & getInvalidInstructionMapping() const
Method to get a uniquely generated invalid InstructionMapping.
const RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
unsigned getMaximumSize(unsigned RegBankID) const
Get the maximum size in bits that fits in the given register bank.
TypeSize getSizeInBits(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
virtual const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC, LLT Ty) const
Get a register bank that covers RC.
const ValueMapping * getOperandsMapping(Iterator Begin, Iterator End) const
Get the uniquely generated array of ValueMapping for the elements of between Begin and End.
static const unsigned DefaultMappingID
Identifier used when the related instruction mapping instance is generated by target independent code...
SmallVector< const InstructionMapping *, 4 > InstructionMappings
Convenient type to represent the alternatives for mapping an instruction.
virtual unsigned copyCost(const RegisterBank &A, const RegisterBank &B, TypeSize Size) const
Get the cost of a copy from B to A, or put differently, get the cost of A = COPY B.
const InstructionMapping & getInstrMappingImpl(const MachineInstr &MI) const
Try to get the mapping of MI.
This class implements the register bank concept.
LLVM_ABI bool covers(const TargetRegisterClass &RC) const
Check whether this register bank covers RC.
unsigned getID() const
Get the identifier of this register bank.
Wrapper class representing virtual and physical registers.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
unsigned getID() const
Return the register class ID number.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Type * getArrayElementType() const
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
iterator_range< user_iterator > users()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool isAdvSIMDModImmType4(uint64_t Imm)
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel.
LLVM_ABI bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *BFI, PGSOQueryType QueryType=PGSOQueryType::Other)
Returns true if machine function MF is suggested to be size-optimized based on the profile.
bool isPreISelGenericOptimizationHint(unsigned Opcode)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
DWARFExpression::Operation Op
void call_once(once_flag &flag, Function &&F, Args &&... ArgList)
Execute the function specified as a parameter once.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool isPreISelGenericFloatingPointOpcode(unsigned Opc)
Returns whether opcode Opc is a pre-isel generic floating-point opcode, having only floating-point op...
static EVT getFloatingPointVT(unsigned BitWidth)
Returns the EVT that represents a floating-point type with the given number of bits.
The llvm::once_flag structure.