mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-22 20:18:38 +00:00
[GlobalISel] Legalize G_(S|U)DIV libcalls
Treat them the same as the other binary operations that we have so far, but on integers rather than floating point types. Extract the common code into a helper. This will be used in the ARM backend. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301163 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b9c5aa7d0d
commit
68724fc353
@ -76,6 +76,12 @@ void LegalizerHelper::extractParts(unsigned Reg, LLT Ty, int NumParts,
|
||||
|
||||
static RTLIB::Libcall getRTLibDesc(unsigned Opcode, unsigned Size) {
|
||||
switch (Opcode) {
|
||||
case TargetOpcode::G_SDIV:
|
||||
assert(Size == 32 && "Unsupported size");
|
||||
return RTLIB::SDIV_I32;
|
||||
case TargetOpcode::G_UDIV:
|
||||
assert(Size == 32 && "Unsupported size");
|
||||
return RTLIB::UDIV_I32;
|
||||
case TargetOpcode::G_FADD:
|
||||
assert((Size == 32 || Size == 64) && "Unsupported size");
|
||||
return Size == 64 ? RTLIB::ADD_F64 : RTLIB::ADD_F32;
|
||||
@ -87,31 +93,43 @@ static RTLIB::Libcall getRTLibDesc(unsigned Opcode, unsigned Size) {
|
||||
llvm_unreachable("Unknown libcall function");
|
||||
}
|
||||
|
||||
static LegalizerHelper::LegalizeResult
|
||||
simpleLibcall(MachineInstr &MI, MachineIRBuilder &MIRBuilder, unsigned Size,
|
||||
Type *OpType) {
|
||||
auto &CLI = *MIRBuilder.getMF().getSubtarget().getCallLowering();
|
||||
auto &TLI = *MIRBuilder.getMF().getSubtarget().getTargetLowering();
|
||||
auto Libcall = getRTLibDesc(MI.getOpcode(), Size);
|
||||
const char *Name = TLI.getLibcallName(Libcall);
|
||||
MIRBuilder.getMF().getFrameInfo().setHasCalls(true);
|
||||
CLI.lowerCall(MIRBuilder, TLI.getLibcallCallingConv(Libcall),
|
||||
MachineOperand::CreateES(Name),
|
||||
{MI.getOperand(0).getReg(), OpType},
|
||||
{{MI.getOperand(1).getReg(), OpType},
|
||||
{MI.getOperand(2).getReg(), OpType}});
|
||||
MI.eraseFromParent();
|
||||
return LegalizerHelper::Legalized;
|
||||
}
|
||||
|
||||
LegalizerHelper::LegalizeResult
|
||||
LegalizerHelper::libcall(MachineInstr &MI) {
|
||||
LLT Ty = MRI.getType(MI.getOperand(0).getReg());
|
||||
unsigned Size = Ty.getSizeInBits();
|
||||
auto &Ctx = MIRBuilder.getMF().getFunction()->getContext();
|
||||
MIRBuilder.setInstr(MI);
|
||||
|
||||
switch (MI.getOpcode()) {
|
||||
default:
|
||||
return UnableToLegalize;
|
||||
case TargetOpcode::G_SDIV:
|
||||
case TargetOpcode::G_UDIV: {
|
||||
Type *Ty = Type::getInt32Ty(Ctx);
|
||||
return simpleLibcall(MI, MIRBuilder, Size, Ty);
|
||||
}
|
||||
case TargetOpcode::G_FADD:
|
||||
case TargetOpcode::G_FPOW:
|
||||
case TargetOpcode::G_FREM: {
|
||||
auto &Ctx = MIRBuilder.getMF().getFunction()->getContext();
|
||||
Type *Ty = Size == 64 ? Type::getDoubleTy(Ctx) : Type::getFloatTy(Ctx);
|
||||
auto &CLI = *MIRBuilder.getMF().getSubtarget().getCallLowering();
|
||||
auto &TLI = *MIRBuilder.getMF().getSubtarget().getTargetLowering();
|
||||
auto Libcall = getRTLibDesc(MI.getOpcode(), Size);
|
||||
const char *Name = TLI.getLibcallName(Libcall);
|
||||
MIRBuilder.getMF().getFrameInfo().setHasCalls(true);
|
||||
CLI.lowerCall(
|
||||
MIRBuilder, TLI.getLibcallCallingConv(Libcall),
|
||||
MachineOperand::CreateES(Name), {MI.getOperand(0).getReg(), Ty},
|
||||
{{MI.getOperand(1).getReg(), Ty}, {MI.getOperand(2).getReg(), Ty}});
|
||||
MI.eraseFromParent();
|
||||
return Legalized;
|
||||
return simpleLibcall(MI, MIRBuilder, Size, Ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user