mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
refactor select 'sched insertion' out to its own method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80764 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -7702,11 +7702,67 @@ X86TargetLowering::EmitVAStartSaveXMMRegsWithCustomInserter(
|
|||||||
return EndMBB;
|
return EndMBB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MachineBasicBlock *
|
||||||
|
X86TargetLowering::EmitLoweredSelect(MachineInstr *MI,
|
||||||
|
MachineBasicBlock *BB) const {
|
||||||
|
const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
|
||||||
|
DebugLoc DL = MI->getDebugLoc();
|
||||||
|
|
||||||
|
// To "insert" a SELECT_CC instruction, we actually have to insert the
|
||||||
|
// diamond control-flow pattern. The incoming instruction knows the
|
||||||
|
// destination vreg to set, the condition code register to branch on, the
|
||||||
|
// true/false values to select between, and a branch opcode to use.
|
||||||
|
const BasicBlock *LLVM_BB = BB->getBasicBlock();
|
||||||
|
MachineFunction::iterator It = BB;
|
||||||
|
++It;
|
||||||
|
|
||||||
|
// thisMBB:
|
||||||
|
// ...
|
||||||
|
// TrueVal = ...
|
||||||
|
// cmpTY ccX, r1, r2
|
||||||
|
// bCC copy1MBB
|
||||||
|
// fallthrough --> copy0MBB
|
||||||
|
MachineBasicBlock *thisMBB = BB;
|
||||||
|
MachineFunction *F = BB->getParent();
|
||||||
|
MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
|
||||||
|
MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
|
||||||
|
unsigned Opc =
|
||||||
|
X86::GetCondBranchFromCond((X86::CondCode)MI->getOperand(3).getImm());
|
||||||
|
BuildMI(BB, DL, TII->get(Opc)).addMBB(sinkMBB);
|
||||||
|
F->insert(It, copy0MBB);
|
||||||
|
F->insert(It, sinkMBB);
|
||||||
|
// Update machine-CFG edges by transferring all successors of the current
|
||||||
|
// block to the new block which will contain the Phi node for the select.
|
||||||
|
sinkMBB->transferSuccessors(BB);
|
||||||
|
|
||||||
|
// Add the true and fallthrough blocks as its successors.
|
||||||
|
BB->addSuccessor(copy0MBB);
|
||||||
|
BB->addSuccessor(sinkMBB);
|
||||||
|
|
||||||
|
// copy0MBB:
|
||||||
|
// %FalseValue = ...
|
||||||
|
// # fallthrough to sinkMBB
|
||||||
|
BB = copy0MBB;
|
||||||
|
|
||||||
|
// Update machine-CFG edges
|
||||||
|
BB->addSuccessor(sinkMBB);
|
||||||
|
|
||||||
|
// sinkMBB:
|
||||||
|
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
|
||||||
|
// ...
|
||||||
|
BB = sinkMBB;
|
||||||
|
BuildMI(BB, DL, TII->get(X86::PHI), MI->getOperand(0).getReg())
|
||||||
|
.addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB)
|
||||||
|
.addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
|
||||||
|
|
||||||
|
F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
|
||||||
|
return BB;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MachineBasicBlock *
|
MachineBasicBlock *
|
||||||
X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
|
X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
|
||||||
MachineBasicBlock *BB) const {
|
MachineBasicBlock *BB) const {
|
||||||
DebugLoc dl = MI->getDebugLoc();
|
|
||||||
const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
|
|
||||||
switch (MI->getOpcode()) {
|
switch (MI->getOpcode()) {
|
||||||
default: assert(false && "Unexpected instr type to insert");
|
default: assert(false && "Unexpected instr type to insert");
|
||||||
case X86::CMOV_GR8:
|
case X86::CMOV_GR8:
|
||||||
@@ -7715,57 +7771,8 @@ X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
|
|||||||
case X86::CMOV_FR64:
|
case X86::CMOV_FR64:
|
||||||
case X86::CMOV_V4F32:
|
case X86::CMOV_V4F32:
|
||||||
case X86::CMOV_V2F64:
|
case X86::CMOV_V2F64:
|
||||||
case X86::CMOV_V2I64: {
|
case X86::CMOV_V2I64:
|
||||||
// To "insert" a SELECT_CC instruction, we actually have to insert the
|
return EmitLoweredSelect(MI, BB);
|
||||||
// diamond control-flow pattern. The incoming instruction knows the
|
|
||||||
// destination vreg to set, the condition code register to branch on, the
|
|
||||||
// true/false values to select between, and a branch opcode to use.
|
|
||||||
const BasicBlock *LLVM_BB = BB->getBasicBlock();
|
|
||||||
MachineFunction::iterator It = BB;
|
|
||||||
++It;
|
|
||||||
|
|
||||||
// thisMBB:
|
|
||||||
// ...
|
|
||||||
// TrueVal = ...
|
|
||||||
// cmpTY ccX, r1, r2
|
|
||||||
// bCC copy1MBB
|
|
||||||
// fallthrough --> copy0MBB
|
|
||||||
MachineBasicBlock *thisMBB = BB;
|
|
||||||
MachineFunction *F = BB->getParent();
|
|
||||||
MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
|
|
||||||
MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
|
|
||||||
unsigned Opc =
|
|
||||||
X86::GetCondBranchFromCond((X86::CondCode)MI->getOperand(3).getImm());
|
|
||||||
BuildMI(BB, dl, TII->get(Opc)).addMBB(sinkMBB);
|
|
||||||
F->insert(It, copy0MBB);
|
|
||||||
F->insert(It, sinkMBB);
|
|
||||||
// Update machine-CFG edges by transferring all successors of the current
|
|
||||||
// block to the new block which will contain the Phi node for the select.
|
|
||||||
sinkMBB->transferSuccessors(BB);
|
|
||||||
|
|
||||||
// Add the true and fallthrough blocks as its successors.
|
|
||||||
BB->addSuccessor(copy0MBB);
|
|
||||||
BB->addSuccessor(sinkMBB);
|
|
||||||
|
|
||||||
// copy0MBB:
|
|
||||||
// %FalseValue = ...
|
|
||||||
// # fallthrough to sinkMBB
|
|
||||||
BB = copy0MBB;
|
|
||||||
|
|
||||||
// Update machine-CFG edges
|
|
||||||
BB->addSuccessor(sinkMBB);
|
|
||||||
|
|
||||||
// sinkMBB:
|
|
||||||
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
|
|
||||||
// ...
|
|
||||||
BB = sinkMBB;
|
|
||||||
BuildMI(BB, dl, TII->get(X86::PHI), MI->getOperand(0).getReg())
|
|
||||||
.addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB)
|
|
||||||
.addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
|
|
||||||
|
|
||||||
F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
|
|
||||||
return BB;
|
|
||||||
}
|
|
||||||
|
|
||||||
case X86::FP32_TO_INT16_IN_MEM:
|
case X86::FP32_TO_INT16_IN_MEM:
|
||||||
case X86::FP32_TO_INT32_IN_MEM:
|
case X86::FP32_TO_INT32_IN_MEM:
|
||||||
@@ -7776,27 +7783,30 @@ X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
|
|||||||
case X86::FP80_TO_INT16_IN_MEM:
|
case X86::FP80_TO_INT16_IN_MEM:
|
||||||
case X86::FP80_TO_INT32_IN_MEM:
|
case X86::FP80_TO_INT32_IN_MEM:
|
||||||
case X86::FP80_TO_INT64_IN_MEM: {
|
case X86::FP80_TO_INT64_IN_MEM: {
|
||||||
|
const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
|
||||||
|
DebugLoc DL = MI->getDebugLoc();
|
||||||
|
|
||||||
// Change the floating point control register to use "round towards zero"
|
// Change the floating point control register to use "round towards zero"
|
||||||
// mode when truncating to an integer value.
|
// mode when truncating to an integer value.
|
||||||
MachineFunction *F = BB->getParent();
|
MachineFunction *F = BB->getParent();
|
||||||
int CWFrameIdx = F->getFrameInfo()->CreateStackObject(2, 2);
|
int CWFrameIdx = F->getFrameInfo()->CreateStackObject(2, 2);
|
||||||
addFrameReference(BuildMI(BB, dl, TII->get(X86::FNSTCW16m)), CWFrameIdx);
|
addFrameReference(BuildMI(BB, DL, TII->get(X86::FNSTCW16m)), CWFrameIdx);
|
||||||
|
|
||||||
// Load the old value of the high byte of the control word...
|
// Load the old value of the high byte of the control word...
|
||||||
unsigned OldCW =
|
unsigned OldCW =
|
||||||
F->getRegInfo().createVirtualRegister(X86::GR16RegisterClass);
|
F->getRegInfo().createVirtualRegister(X86::GR16RegisterClass);
|
||||||
addFrameReference(BuildMI(BB, dl, TII->get(X86::MOV16rm), OldCW),
|
addFrameReference(BuildMI(BB, DL, TII->get(X86::MOV16rm), OldCW),
|
||||||
CWFrameIdx);
|
CWFrameIdx);
|
||||||
|
|
||||||
// Set the high part to be round to zero...
|
// Set the high part to be round to zero...
|
||||||
addFrameReference(BuildMI(BB, dl, TII->get(X86::MOV16mi)), CWFrameIdx)
|
addFrameReference(BuildMI(BB, DL, TII->get(X86::MOV16mi)), CWFrameIdx)
|
||||||
.addImm(0xC7F);
|
.addImm(0xC7F);
|
||||||
|
|
||||||
// Reload the modified control word now...
|
// Reload the modified control word now...
|
||||||
addFrameReference(BuildMI(BB, dl, TII->get(X86::FLDCW16m)), CWFrameIdx);
|
addFrameReference(BuildMI(BB, DL, TII->get(X86::FLDCW16m)), CWFrameIdx);
|
||||||
|
|
||||||
// Restore the memory image of control word to original value
|
// Restore the memory image of control word to original value
|
||||||
addFrameReference(BuildMI(BB, dl, TII->get(X86::MOV16mr)), CWFrameIdx)
|
addFrameReference(BuildMI(BB, DL, TII->get(X86::MOV16mr)), CWFrameIdx)
|
||||||
.addReg(OldCW);
|
.addReg(OldCW);
|
||||||
|
|
||||||
// Get the X86 opcode to use.
|
// Get the X86 opcode to use.
|
||||||
@@ -7835,11 +7845,11 @@ X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
|
|||||||
} else {
|
} else {
|
||||||
AM.Disp = Op.getImm();
|
AM.Disp = Op.getImm();
|
||||||
}
|
}
|
||||||
addFullAddress(BuildMI(BB, dl, TII->get(Opc)), AM)
|
addFullAddress(BuildMI(BB, DL, TII->get(Opc)), AM)
|
||||||
.addReg(MI->getOperand(X86AddrNumOperands).getReg());
|
.addReg(MI->getOperand(X86AddrNumOperands).getReg());
|
||||||
|
|
||||||
// Reload the original control word now.
|
// Reload the original control word now.
|
||||||
addFrameReference(BuildMI(BB, dl, TII->get(X86::FLDCW16m)), CWFrameIdx);
|
addFrameReference(BuildMI(BB, DL, TII->get(X86::FLDCW16m)), CWFrameIdx);
|
||||||
|
|
||||||
F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
|
F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
|
||||||
return BB;
|
return BB;
|
||||||
|
@@ -738,6 +738,9 @@ namespace llvm {
|
|||||||
MachineInstr *BInstr,
|
MachineInstr *BInstr,
|
||||||
MachineBasicBlock *BB) const;
|
MachineBasicBlock *BB) const;
|
||||||
|
|
||||||
|
MachineBasicBlock *EmitLoweredSelect(MachineInstr *I,
|
||||||
|
MachineBasicBlock *BB) const;
|
||||||
|
|
||||||
/// Emit nodes that will be selected as "test Op0,Op0", or something
|
/// Emit nodes that will be selected as "test Op0,Op0", or something
|
||||||
/// equivalent, for use with the given x86 condition code.
|
/// equivalent, for use with the given x86 condition code.
|
||||||
SDValue EmitTest(SDValue Op0, unsigned X86CC, SelectionDAG &DAG);
|
SDValue EmitTest(SDValue Op0, unsigned X86CC, SelectionDAG &DAG);
|
||||||
|
Reference in New Issue
Block a user