Skip to content

Commit bede937

Browse files
author
Jessica Paquette
committed
[GlobalISel][AArch64] NFC: Factor out HasFPConstraints into a proper function
Factor it out into a function, and replace places where we had the same check with the new function. Differential Revision: https://reviews.llvm.org/D62421 llvm-svn: 361677
1 parent 78a6ae7 commit bede937

File tree

2 files changed

+32
-41
lines changed

2 files changed

+32
-41
lines changed

llvm/lib/Target/AArch64/AArch64RegisterBankInfo.cpp

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,25 @@ AArch64RegisterBankInfo::getSameKindOfOperandsMapping(
457457
getValueMapping(RBIdx, Size), NumOperands);
458458
}
459459

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+
460479
const RegisterBankInfo::InstructionMapping &
461480
AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
462481
const unsigned Opc = MI.getOpcode();
@@ -476,24 +495,6 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
476495
const TargetSubtargetInfo &STI = MF.getSubtarget();
477496
const TargetRegisterInfo &TRI = *STI.getRegisterInfo();
478497

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-
497498
switch (Opc) {
498499
// G_{F|S|U}REM are not listed because they are not legal.
499500
// Arithmetic ops.
@@ -641,15 +642,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
641642
// assume this was a floating point load in the IR.
642643
// If it was not, we would have had a bitcast before
643644
// 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)) {
653646
OpRegBankIdx[0] = PMI_FirstFPR;
654647
break;
655648
}
@@ -662,15 +655,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
662655
if (!VReg)
663656
break;
664657
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))
674659
OpRegBankIdx[0] = PMI_FirstFPR;
675660
break;
676661
}
@@ -700,8 +685,9 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
700685
//
701686
// %z = G_SELECT %cond %x %y
702687
// 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); }))
705691
++NumFP;
706692

707693
// Check if the defs of the source values always produce floating point
@@ -721,7 +707,7 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
721707
unsigned VReg = MI.getOperand(Idx).getReg();
722708
MachineInstr *DefMI = MRI.getVRegDef(VReg);
723709
if (getRegBank(VReg, MRI, TRI) == &AArch64::FPRRegBank ||
724-
HasFPConstraints(*DefMI))
710+
hasFPConstraints(*DefMI, MRI, TRI))
725711
++NumFP;
726712
}
727713

@@ -743,8 +729,9 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
743729
// UNMERGE into scalars from a vector should always use FPR.
744730
// Likewise if any of the uses are FP instructions.
745731
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); })) {
748735
// Set the register bank of every operand to FPR.
749736
for (unsigned Idx = 0, NumOperands = MI.getNumOperands();
750737
Idx < NumOperands; ++Idx)

llvm/lib/Target/AArch64/AArch64RegisterBankInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ class AArch64RegisterBankInfo final : public AArch64GenRegisterBankInfo {
113113
const InstructionMapping &
114114
getSameKindOfOperandsMapping(const MachineInstr &MI) const;
115115

116+
/// Returns true if the output of \p MI must be stored on a FPR register.
117+
bool hasFPConstraints(const MachineInstr &MI, const MachineRegisterInfo &MRI,
118+
const TargetRegisterInfo &TRI) const;
119+
116120
public:
117121
AArch64RegisterBankInfo(const TargetRegisterInfo &TRI);
118122

0 commit comments

Comments
 (0)