@@ -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?
160195bool 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
192209const RegisterBankInfo::InstructionMapping &
0 commit comments