@@ -457,6 +457,25 @@ AArch64RegisterBankInfo::getSameKindOfOperandsMapping(
457
457
getValueMapping (RBIdx, Size ), NumOperands);
458
458
}
459
459
460
+ bool AArch64RegisterBankInfo::hasFPConstraints (
461
+ const MachineInstr &MI, const MachineRegisterInfo &MRI,
462
+ const TargetRegisterInfo &TRI) const {
463
+ unsigned Op = MI.getOpcode ();
464
+
465
+ // Do we have an explicit floating point instruction?
466
+ if (isPreISelGenericFloatingPointOpcode (Op))
467
+ return true ;
468
+
469
+ // No. Check if we have a copy-like instruction. If we do, then we could
470
+ // still be fed by floating point instructions.
471
+ if (Op != TargetOpcode::COPY && !MI.isPHI ())
472
+ return false ;
473
+
474
+ // MI is copy-like. Return true if it outputs an FPR.
475
+ return getRegBank (MI.getOperand (0 ).getReg (), MRI, TRI) ==
476
+ &AArch64::FPRRegBank;
477
+ }
478
+
460
479
const RegisterBankInfo::InstructionMapping &
461
480
AArch64RegisterBankInfo::getInstrMapping (const MachineInstr &MI) const {
462
481
const unsigned Opc = MI.getOpcode ();
@@ -476,24 +495,6 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
476
495
const TargetSubtargetInfo &STI = MF.getSubtarget ();
477
496
const TargetRegisterInfo &TRI = *STI.getRegisterInfo ();
478
497
479
- // Helper lambda that returns true if MI has floating point constraints.
480
- auto HasFPConstraints = [&TRI, &MRI, this ](MachineInstr &MI) {
481
- unsigned Op = MI.getOpcode ();
482
-
483
- // Do we have an explicit floating point instruction?
484
- if (isPreISelGenericFloatingPointOpcode (Op))
485
- return true ;
486
-
487
- // No. Check if we have a copy-like instruction. If we do, then we could
488
- // still be fed by floating point instructions.
489
- if (Op != TargetOpcode::COPY && !MI.isPHI ())
490
- return false ;
491
-
492
- // MI is copy-like. Return true if it's using an FPR.
493
- return getRegBank (MI.getOperand (0 ).getReg (), MRI, TRI) ==
494
- &AArch64::FPRRegBank;
495
- };
496
-
497
498
switch (Opc) {
498
499
// G_{F|S|U}REM are not listed because they are not legal.
499
500
// Arithmetic ops.
@@ -641,15 +642,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
641
642
// assume this was a floating point load in the IR.
642
643
// If it was not, we would have had a bitcast before
643
644
// reaching that instruction.
644
- unsigned UseOpc = UseMI.getOpcode ();
645
- if (isPreISelGenericFloatingPointOpcode (UseOpc) ||
646
- // Check if we feed a copy-like instruction with
647
- // floating point constraints. In that case, we are still
648
- // feeding fp instructions, but indirectly
649
- // (e.g., through ABI copies).
650
- ((UseOpc == TargetOpcode::COPY || UseMI.isPHI ()) &&
651
- getRegBank (UseMI.getOperand (0 ).getReg (), MRI, TRI) ==
652
- &AArch64::FPRRegBank)) {
645
+ if (hasFPConstraints (UseMI, MRI, TRI)) {
653
646
OpRegBankIdx[0 ] = PMI_FirstFPR;
654
647
break ;
655
648
}
@@ -662,15 +655,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
662
655
if (!VReg)
663
656
break ;
664
657
MachineInstr *DefMI = MRI.getVRegDef (VReg);
665
- unsigned DefOpc = DefMI->getOpcode ();
666
- if (isPreISelGenericFloatingPointOpcode (DefOpc) ||
667
- // Check if we come from a copy-like instruction with
668
- // floating point constraints. In that case, we are still
669
- // fed by fp instructions, but indirectly
670
- // (e.g., through ABI copies).
671
- ((DefOpc == TargetOpcode::COPY || DefMI->isPHI ()) &&
672
- getRegBank (DefMI->getOperand (0 ).getReg (), MRI, TRI) ==
673
- &AArch64::FPRRegBank))
658
+ if (hasFPConstraints (*DefMI, MRI, TRI))
674
659
OpRegBankIdx[0 ] = PMI_FirstFPR;
675
660
break ;
676
661
}
@@ -700,8 +685,9 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
700
685
//
701
686
// %z = G_SELECT %cond %x %y
702
687
// fpr = G_FOO %z ...
703
- if (any_of (MRI.use_instructions (MI.getOperand (0 ).getReg ()),
704
- [&](MachineInstr &MI) { return HasFPConstraints (MI); }))
688
+ if (any_of (
689
+ MRI.use_instructions (MI.getOperand (0 ).getReg ()),
690
+ [&](MachineInstr &MI) { return hasFPConstraints (MI, MRI, TRI); }))
705
691
++NumFP;
706
692
707
693
// Check if the defs of the source values always produce floating point
@@ -721,7 +707,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
721
707
unsigned VReg = MI.getOperand (Idx).getReg ();
722
708
MachineInstr *DefMI = MRI.getVRegDef (VReg);
723
709
if (getRegBank (VReg, MRI, TRI) == &AArch64::FPRRegBank ||
724
- HasFPConstraints (*DefMI))
710
+ hasFPConstraints (*DefMI, MRI, TRI ))
725
711
++NumFP;
726
712
}
727
713
@@ -743,8 +729,9 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
743
729
// UNMERGE into scalars from a vector should always use FPR.
744
730
// Likewise if any of the uses are FP instructions.
745
731
if (SrcTy.isVector () ||
746
- any_of (MRI.use_instructions (MI.getOperand (0 ).getReg ()),
747
- [&](MachineInstr &MI) { return HasFPConstraints (MI); })) {
732
+ any_of (
733
+ MRI.use_instructions (MI.getOperand (0 ).getReg ()),
734
+ [&](MachineInstr &MI) { return hasFPConstraints (MI, MRI, TRI); })) {
748
735
// Set the register bank of every operand to FPR.
749
736
for (unsigned Idx = 0 , NumOperands = MI.getNumOperands ();
750
737
Idx < NumOperands; ++Idx)
0 commit comments