Skip to content

Commit 9e88a20

Browse files
committed
[RISCV][GISel] Add isPreISelGenericFloatingPointOpcode and FPConstraints. NFC
This brings us closer to how AArch64 is structured. I plan to use isPreISelGenericFloatingPointOpcode in another change.
1 parent e845754 commit 9e88a20

File tree

2 files changed

+57
-36
lines changed

2 files changed

+57
-36
lines changed

llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.cpp

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -123,70 +123,87 @@ static const RegisterBankInfo::ValueMapping *getFPValueMapping(unsigned Size) {
123123
return &RISCV::ValueMappings[Idx];
124124
}
125125

126-
// TODO: Make this more like AArch64?
127-
bool RISCVRegisterBankInfo::onlyUsesFP(const MachineInstr &MI,
128-
const MachineRegisterInfo &MRI,
129-
const TargetRegisterInfo &TRI) const {
130-
switch (MI.getOpcode()) {
126+
/// Returns whether opcode \p Opc is a pre-isel generic floating-point opcode,
127+
/// having only floating-point operands.
128+
/// FIXME: this is copied from target AArch64. Needs some code refactor here to
129+
/// put this function in GlobalISel/Utils.cpp.
130+
static bool isPreISelGenericFloatingPointOpcode(unsigned Opc) {
131+
switch (Opc) {
131132
case TargetOpcode::G_FADD:
132133
case TargetOpcode::G_FSUB:
133134
case TargetOpcode::G_FMUL:
135+
case TargetOpcode::G_FMA:
134136
case TargetOpcode::G_FDIV:
137+
case TargetOpcode::G_FCONSTANT:
138+
case TargetOpcode::G_FPEXT:
139+
case TargetOpcode::G_FPTRUNC:
140+
case TargetOpcode::G_FCEIL:
141+
case TargetOpcode::G_FFLOOR:
142+
case TargetOpcode::G_FNEARBYINT:
135143
case TargetOpcode::G_FNEG:
136-
case TargetOpcode::G_FABS:
144+
case TargetOpcode::G_FCOS:
145+
case TargetOpcode::G_FSIN:
146+
case TargetOpcode::G_FLOG10:
147+
case TargetOpcode::G_FLOG:
148+
case TargetOpcode::G_FLOG2:
137149
case TargetOpcode::G_FSQRT:
150+
case TargetOpcode::G_FABS:
151+
case TargetOpcode::G_FEXP:
152+
case TargetOpcode::G_FRINT:
153+
case TargetOpcode::G_INTRINSIC_TRUNC:
154+
case TargetOpcode::G_INTRINSIC_ROUND:
155+
case TargetOpcode::G_INTRINSIC_ROUNDEVEN:
138156
case TargetOpcode::G_FMAXNUM:
139157
case TargetOpcode::G_FMINNUM:
140-
case TargetOpcode::G_FPEXT:
141-
case TargetOpcode::G_FPTRUNC:
142-
case TargetOpcode::G_FCMP:
158+
case TargetOpcode::G_FMAXIMUM:
159+
case TargetOpcode::G_FMINIMUM:
160+
return true;
161+
}
162+
return false;
163+
}
164+
165+
// TODO: Make this more like AArch64?
166+
bool RISCVRegisterBankInfo::hasFPConstraints(
167+
const MachineInstr &MI, const MachineRegisterInfo &MRI,
168+
const TargetRegisterInfo &TRI) const {
169+
if (isPreISelGenericFloatingPointOpcode(MI.getOpcode()))
170+
return true;
171+
172+
// If we have a copy instruction, we could be feeding floating point
173+
// instructions.
174+
if (MI.getOpcode() != TargetOpcode::COPY)
175+
return false;
176+
177+
return getRegBank(MI.getOperand(0).getReg(), MRI, TRI) == &RISCV::FPRBRegBank;
178+
}
179+
180+
bool RISCVRegisterBankInfo::onlyUsesFP(const MachineInstr &MI,
181+
const MachineRegisterInfo &MRI,
182+
const TargetRegisterInfo &TRI) const {
183+
switch (MI.getOpcode()) {
143184
case TargetOpcode::G_FPTOSI:
144185
case TargetOpcode::G_FPTOUI:
186+
case TargetOpcode::G_FCMP:
145187
return true;
146188
default:
147189
break;
148190
}
149191

150-
// If we have a copy instruction, we could be feeding floating point
151-
// instructions.
152-
if (MI.getOpcode() == TargetOpcode::COPY)
153-
return getRegBank(MI.getOperand(0).getReg(), MRI, TRI) ==
154-
&RISCV::FPRBRegBank;
155-
156-
return false;
192+
return hasFPConstraints(MI, MRI, TRI);
157193
}
158194

159-
// TODO: Make this more like AArch64?
160195
bool RISCVRegisterBankInfo::onlyDefinesFP(const MachineInstr &MI,
161196
const MachineRegisterInfo &MRI,
162197
const TargetRegisterInfo &TRI) const {
163198
switch (MI.getOpcode()) {
164-
case TargetOpcode::G_FADD:
165-
case TargetOpcode::G_FSUB:
166-
case TargetOpcode::G_FMUL:
167-
case TargetOpcode::G_FDIV:
168-
case TargetOpcode::G_FNEG:
169-
case TargetOpcode::G_FABS:
170-
case TargetOpcode::G_FSQRT:
171-
case TargetOpcode::G_FMAXNUM:
172-
case TargetOpcode::G_FMINNUM:
173-
case TargetOpcode::G_FPEXT:
174-
case TargetOpcode::G_FPTRUNC:
175199
case TargetOpcode::G_SITOFP:
176200
case TargetOpcode::G_UITOFP:
177-
case TargetOpcode::G_FCONSTANT:
178201
return true;
179202
default:
180203
break;
181204
}
182205

183-
// If we have a copy instruction, we could be fed by floating point
184-
// instructions.
185-
if (MI.getOpcode() == TargetOpcode::COPY)
186-
return getRegBank(MI.getOperand(0).getReg(), MRI, TRI) ==
187-
&RISCV::FPRBRegBank;
188-
189-
return false;
206+
return hasFPConstraints(MI, MRI, TRI);
190207
}
191208

192209
const RegisterBankInfo::InstructionMapping &

llvm/lib/Target/RISCV/GISel/RISCVRegisterBankInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class RISCVRegisterBankInfo final : public RISCVGenRegisterBankInfo {
4040
getInstrMapping(const MachineInstr &MI) const override;
4141

4242
private:
43+
/// \returns true if \p MI only uses and defines FPRs.
44+
bool hasFPConstraints(const MachineInstr &MI, const MachineRegisterInfo &MRI,
45+
const TargetRegisterInfo &TRI) const;
46+
4347
/// \returns true if \p MI only uses FPRs.
4448
bool onlyUsesFP(const MachineInstr &MI, const MachineRegisterInfo &MRI,
4549
const TargetRegisterInfo &TRI) const;

0 commit comments

Comments
 (0)