Revert r107655.

llvm-svn: 107668
This commit is contained in:
Dan Gohman 2010-07-06 15:49:48 +00:00
parent 33134fa75f
commit f4f04107ef
14 changed files with 215 additions and 280 deletions

View File

@ -259,11 +259,6 @@ public:
/// machine basic block (i.e., copies all the successors fromMBB and /// machine basic block (i.e., copies all the successors fromMBB and
/// remove all the successors from fromMBB). /// remove all the successors from fromMBB).
void transferSuccessors(MachineBasicBlock *fromMBB); void transferSuccessors(MachineBasicBlock *fromMBB);
/// transferSuccessorsAndUpdatePHIs - Transfers all the successors, as
/// in transferSuccessors, and update PHI operands in the successor blocks
/// which refer to fromMBB to refer to this.
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *fromMBB);
/// isSuccessor - Return true if the specified MBB is a successor of this /// isSuccessor - Return true if the specified MBB is a successor of this
/// block. /// block.

View File

@ -335,32 +335,12 @@ void MachineBasicBlock::transferSuccessors(MachineBasicBlock *fromMBB) {
if (this == fromMBB) if (this == fromMBB)
return; return;
while (!fromMBB->succ_empty()) { for (MachineBasicBlock::succ_iterator I = fromMBB->succ_begin(),
MachineBasicBlock *Succ = *fromMBB->succ_begin(); E = fromMBB->succ_end(); I != E; ++I)
addSuccessor(Succ); addSuccessor(*I);
fromMBB->removeSuccessor(Succ);
}
}
void
MachineBasicBlock::transferSuccessorsAndUpdatePHIs(MachineBasicBlock *fromMBB) {
if (this == fromMBB)
return;
while (!fromMBB->succ_empty()) { while (!fromMBB->succ_empty())
MachineBasicBlock *Succ = *fromMBB->succ_begin(); fromMBB->removeSuccessor(fromMBB->succ_begin());
addSuccessor(Succ);
fromMBB->removeSuccessor(Succ);
// Fix up any PHI nodes in the successor.
for (MachineBasicBlock::iterator MI = Succ->begin(), ME = Succ->end();
MI != ME && MI->isPHI(); ++MI)
for (unsigned i = 2, e = MI->getNumOperands()+1; i != e; i += 2) {
MachineOperand &MO = MI->getOperand(i);
if (MO.getMBB() == fromMBB)
MO.setMBB(this);
}
}
} }
bool MachineBasicBlock::isSuccessor(const MachineBasicBlock *MBB) const { bool MachineBasicBlock::isSuccessor(const MachineBasicBlock *MBB) const {

View File

@ -3637,12 +3637,7 @@ ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI,
MF->insert(It, loop1MBB); MF->insert(It, loop1MBB);
MF->insert(It, loop2MBB); MF->insert(It, loop2MBB);
MF->insert(It, exitMBB); MF->insert(It, exitMBB);
exitMBB->transferSuccessors(BB);
// Transfer the remainder of BB and its successor edges to exitMBB.
exitMBB->splice(exitMBB->begin(), BB,
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
exitMBB->transferSuccessorsAndUpdatePHIs(BB);
// thisMBB: // thisMBB:
// ... // ...
@ -3680,7 +3675,7 @@ ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI,
// ... // ...
BB = exitMBB; BB = exitMBB;
MI->eraseFromParent(); // The instruction is gone now. MF->DeleteMachineInstr(MI); // The instruction is gone now.
return BB; return BB;
} }
@ -3723,12 +3718,7 @@ ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB,
MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB);
MF->insert(It, loopMBB); MF->insert(It, loopMBB);
MF->insert(It, exitMBB); MF->insert(It, exitMBB);
exitMBB->transferSuccessors(BB);
// Transfer the remainder of BB and its successor edges to exitMBB.
exitMBB->splice(exitMBB->begin(), BB,
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
exitMBB->transferSuccessorsAndUpdatePHIs(BB);
MachineRegisterInfo &RegInfo = MF->getRegInfo(); MachineRegisterInfo &RegInfo = MF->getRegInfo();
unsigned scratch = RegInfo.createVirtualRegister(ARM::GPRRegisterClass); unsigned scratch = RegInfo.createVirtualRegister(ARM::GPRRegisterClass);
@ -3773,7 +3763,7 @@ ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB,
// ... // ...
BB = exitMBB; BB = exitMBB;
MI->eraseFromParent(); // The instruction is gone now. MF->DeleteMachineInstr(MI); // The instruction is gone now.
return BB; return BB;
} }
@ -3858,20 +3848,21 @@ ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
MachineFunction *F = BB->getParent(); MachineFunction *F = BB->getParent();
MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
F->insert(It, copy0MBB);
F->insert(It, sinkMBB);
// Transfer the remainder of BB and its successor edges to sinkMBB.
sinkMBB->splice(sinkMBB->begin(), BB,
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
sinkMBB->transferSuccessorsAndUpdatePHIs(BB);
BB->addSuccessor(copy0MBB);
BB->addSuccessor(sinkMBB);
BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB)
.addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg());
F->insert(It, copy0MBB);
F->insert(It, sinkMBB);
// Update machine-CFG edges by first adding all successors of the current
// block to the new block which will contain the Phi node for the select.
for (MachineBasicBlock::succ_iterator I = BB->succ_begin(),
E = BB->succ_end(); I != E; ++I)
sinkMBB->addSuccessor(*I);
// Next, remove all successors of the current block, and add the true
// and fallthrough blocks as its successors.
while (!BB->succ_empty())
BB->removeSuccessor(BB->succ_begin());
BB->addSuccessor(copy0MBB);
BB->addSuccessor(sinkMBB);
// copy0MBB: // copy0MBB:
// %FalseValue = ... // %FalseValue = ...
@ -3885,12 +3876,11 @@ ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
// ... // ...
BB = sinkMBB; BB = sinkMBB;
BuildMI(*BB, BB->begin(), dl, BuildMI(BB, dl, TII->get(ARM::PHI), MI->getOperand(0).getReg())
TII->get(ARM::PHI), MI->getOperand(0).getReg())
.addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB)
.addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return BB; return BB;
} }
@ -3911,7 +3901,7 @@ ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
const TargetRegisterClass *RC = MF->getRegInfo().getRegClass(SrcReg); const TargetRegisterClass *RC = MF->getRegInfo().getRegClass(SrcReg);
unsigned CopyOpc = (RC == ARM::tGPRRegisterClass) unsigned CopyOpc = (RC == ARM::tGPRRegisterClass)
? ARM::tMOVtgpr2gpr : ARM::tMOVgpr2gpr; ? ARM::tMOVtgpr2gpr : ARM::tMOVgpr2gpr;
BuildMI(*BB, MI, dl, TII->get(CopyOpc), ARM::SP) BuildMI(BB, dl, TII->get(CopyOpc), ARM::SP)
.addReg(SrcReg, getKillRegState(SrcIsKill)); .addReg(SrcReg, getKillRegState(SrcIsKill));
} }
@ -3943,7 +3933,7 @@ ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
NeedPred = true; NeedCC = true; NeedOp3 = true; NeedPred = true; NeedCC = true; NeedOp3 = true;
break; break;
} }
MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(OpOpc), ARM::SP); MachineInstrBuilder MIB = BuildMI(BB, dl, TII->get(OpOpc), ARM::SP);
if (OpOpc == ARM::tAND) if (OpOpc == ARM::tAND)
AddDefaultT1CC(MIB); AddDefaultT1CC(MIB);
MIB.addReg(ARM::SP); MIB.addReg(ARM::SP);
@ -3959,10 +3949,10 @@ ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
const TargetRegisterClass *RC = MF->getRegInfo().getRegClass(DstReg); const TargetRegisterClass *RC = MF->getRegInfo().getRegClass(DstReg);
unsigned CopyOpc = (RC == ARM::tGPRRegisterClass) unsigned CopyOpc = (RC == ARM::tGPRRegisterClass)
? ARM::tMOVgpr2tgpr : ARM::tMOVgpr2gpr; ? ARM::tMOVgpr2tgpr : ARM::tMOVgpr2gpr;
BuildMI(*BB, MI, dl, TII->get(CopyOpc)) BuildMI(BB, dl, TII->get(CopyOpc))
.addReg(DstReg, getDefRegState(true) | getDeadRegState(DstIsDead)) .addReg(DstReg, getDefRegState(true) | getDeadRegState(DstIsDead))
.addReg(ARM::SP); .addReg(ARM::SP);
MI->eraseFromParent(); // The pseudo instruction is gone now. MF->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return BB; return BB;
} }
} }

View File

@ -863,10 +863,7 @@ AlphaTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
MachineBasicBlock *llscMBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *llscMBB = F->CreateMachineBasicBlock(LLVM_BB);
MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
sinkMBB->splice(sinkMBB->begin(), thisMBB, sinkMBB->transferSuccessors(thisMBB);
llvm::next(MachineBasicBlock::iterator(MI)),
thisMBB->end());
sinkMBB->transferSuccessorsAndUpdatePHIs(thisMBB);
F->insert(It, llscMBB); F->insert(It, llscMBB);
F->insert(It, sinkMBB); F->insert(It, sinkMBB);
@ -915,7 +912,7 @@ AlphaTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
thisMBB->addSuccessor(llscMBB); thisMBB->addSuccessor(llscMBB);
llscMBB->addSuccessor(llscMBB); llscMBB->addSuccessor(llscMBB);
llscMBB->addSuccessor(sinkMBB); llscMBB->addSuccessor(sinkMBB);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return sinkMBB; return sinkMBB;
} }

View File

@ -234,24 +234,6 @@ MBlazeTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
MachineRegisterInfo &R = F->getRegInfo(); MachineRegisterInfo &R = F->getRegInfo();
MachineBasicBlock *loop = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *loop = F->CreateMachineBasicBlock(LLVM_BB);
MachineBasicBlock *finish = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *finish = F->CreateMachineBasicBlock(LLVM_BB);
F->insert(It, loop);
F->insert(It, finish);
// Update machine-CFG edges by transfering adding all successors and
// remaining instructions from the current block to the new block which
// will contain the Phi node for the select.
finish->splice(finish->begin(), BB,
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
finish->transferSuccessorsAndUpdatePHIs(BB);
// Add the true and fallthrough blocks as its successors.
BB->addSuccessor(loop);
BB->addSuccessor(finish);
// Next, add the finish block as a successor of the loop block
loop->addSuccessor(finish);
loop->addSuccessor(loop);
unsigned IAMT = R.createVirtualRegister(MBlaze::CPURegsRegisterClass); unsigned IAMT = R.createVirtualRegister(MBlaze::CPURegsRegisterClass);
BuildMI(BB, dl, TII->get(MBlaze::ANDI), IAMT) BuildMI(BB, dl, TII->get(MBlaze::ANDI), IAMT)
@ -267,6 +249,26 @@ MBlazeTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
.addReg(IAMT) .addReg(IAMT)
.addMBB(finish); .addMBB(finish);
F->insert(It, loop);
F->insert(It, finish);
// Update machine-CFG edges by first adding all successors of the current
// block to the new block which will contain the Phi node for the select.
for(MachineBasicBlock::succ_iterator i = BB->succ_begin(),
e = BB->succ_end(); i != e; ++i)
finish->addSuccessor(*i);
// Next, remove all successors of the current block, and add the true
// and fallthrough blocks as its successors.
while(!BB->succ_empty())
BB->removeSuccessor(BB->succ_begin());
BB->addSuccessor(loop);
BB->addSuccessor(finish);
// Next, add the finish block as a successor of the loop block
loop->addSuccessor(finish);
loop->addSuccessor(loop);
unsigned DST = R.createVirtualRegister(MBlaze::CPURegsRegisterClass); unsigned DST = R.createVirtualRegister(MBlaze::CPURegsRegisterClass);
unsigned NDST = R.createVirtualRegister(MBlaze::CPURegsRegisterClass); unsigned NDST = R.createVirtualRegister(MBlaze::CPURegsRegisterClass);
BuildMI(loop, dl, TII->get(MBlaze::PHI), DST) BuildMI(loop, dl, TII->get(MBlaze::PHI), DST)
@ -296,13 +298,12 @@ MBlazeTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
.addReg(NAMT) .addReg(NAMT)
.addMBB(loop); .addMBB(loop);
BuildMI(*finish, finish->begin(), dl, BuildMI(finish, dl, TII->get(MBlaze::PHI), MI->getOperand(0).getReg())
TII->get(MBlaze::PHI), MI->getOperand(0).getReg())
.addReg(IVAL).addMBB(BB) .addReg(IVAL).addMBB(BB)
.addReg(NDST).addMBB(loop); .addReg(NDST).addMBB(loop);
// The pseudo instruction is no longer needed so remove it // The pseudo instruction is no longer needed so remove it
MI->eraseFromParent(); F->DeleteMachineInstr(MI);
return finish; return finish;
} }
@ -337,23 +338,27 @@ MBlazeTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
case MBlazeCC::LE: Opc = MBlaze::BGTID; break; case MBlazeCC::LE: Opc = MBlaze::BGTID; break;
} }
F->insert(It, flsBB);
F->insert(It, dneBB);
// Transfer the remainder of BB and its successor edges to dneBB.
dneBB->splice(dneBB->begin(), BB,
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
dneBB->transferSuccessorsAndUpdatePHIs(BB);
BB->addSuccessor(flsBB);
BB->addSuccessor(dneBB);
flsBB->addSuccessor(dneBB);
BuildMI(BB, dl, TII->get(Opc)) BuildMI(BB, dl, TII->get(Opc))
.addReg(MI->getOperand(3).getReg()) .addReg(MI->getOperand(3).getReg())
.addMBB(dneBB); .addMBB(dneBB);
F->insert(It, flsBB);
F->insert(It, dneBB);
// Update machine-CFG edges by first adding all successors of the current
// block to the new block which will contain the Phi node for the select.
for(MachineBasicBlock::succ_iterator i = BB->succ_begin(),
e = BB->succ_end(); i != e; ++i)
dneBB->addSuccessor(*i);
// Next, remove all successors of the current block, and add the true
// and fallthrough blocks as its successors.
while(!BB->succ_empty())
BB->removeSuccessor(BB->succ_begin());
BB->addSuccessor(flsBB);
BB->addSuccessor(dneBB);
flsBB->addSuccessor(dneBB);
// sinkMBB: // sinkMBB:
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
// ... // ...
@ -361,12 +366,11 @@ MBlazeTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
// .addReg(MI->getOperand(1).getReg()).addMBB(flsBB) // .addReg(MI->getOperand(1).getReg()).addMBB(flsBB)
// .addReg(MI->getOperand(2).getReg()).addMBB(BB); // .addReg(MI->getOperand(2).getReg()).addMBB(BB);
BuildMI(*dneBB, dneBB->begin(), dl, BuildMI(dneBB, dl, TII->get(MBlaze::PHI), MI->getOperand(0).getReg())
TII->get(MBlaze::PHI), MI->getOperand(0).getReg())
.addReg(MI->getOperand(2).getReg()).addMBB(flsBB) .addReg(MI->getOperand(2).getReg()).addMBB(flsBB)
.addReg(MI->getOperand(1).getReg()).addMBB(BB); .addReg(MI->getOperand(1).getReg()).addMBB(BB);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return dneBB; return dneBB;
} }
} }

View File

@ -1070,10 +1070,7 @@ MSP430TargetLowering::EmitShiftInstr(MachineInstr *MI,
// Update machine-CFG edges by transferring all successors of the current // Update machine-CFG edges by transferring all successors of the current
// block to the block containing instructions after shift. // block to the block containing instructions after shift.
RemBB->splice(RemBB->begin(), BB, RemBB->transferSuccessors(BB);
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
RemBB->transferSuccessorsAndUpdatePHIs(BB);
// Add adges BB => LoopBB => RemBB, BB => RemBB, LoopBB => LoopBB // Add adges BB => LoopBB => RemBB, BB => RemBB, LoopBB => LoopBB
BB->addSuccessor(LoopBB); BB->addSuccessor(LoopBB);
@ -1119,11 +1116,11 @@ MSP430TargetLowering::EmitShiftInstr(MachineInstr *MI,
// RemBB: // RemBB:
// DestReg = phi [%SrcReg, BB], [%ShiftReg, LoopBB] // DestReg = phi [%SrcReg, BB], [%ShiftReg, LoopBB]
BuildMI(*RemBB, RemBB->begin(), dl, TII.get(MSP430::PHI), DstReg) BuildMI(RemBB, dl, TII.get(MSP430::PHI), DstReg)
.addReg(SrcReg).addMBB(BB) .addReg(SrcReg).addMBB(BB)
.addReg(ShiftReg2).addMBB(LoopBB); .addReg(ShiftReg2).addMBB(LoopBB);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return RemBB; return RemBB;
} }
@ -1161,22 +1158,18 @@ MSP430TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
MachineFunction *F = BB->getParent(); MachineFunction *F = BB->getParent();
MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
MachineBasicBlock *copy1MBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *copy1MBB = F->CreateMachineBasicBlock(LLVM_BB);
BuildMI(BB, dl, TII.get(MSP430::JCC))
.addMBB(copy1MBB)
.addImm(MI->getOperand(3).getImm());
F->insert(I, copy0MBB); F->insert(I, copy0MBB);
F->insert(I, copy1MBB); F->insert(I, copy1MBB);
// Update machine-CFG edges by transferring all successors of the current // 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. // block to the new block which will contain the Phi node for the select.
copy1MBB->splice(copy1MBB->begin(), BB, copy1MBB->transferSuccessors(BB);
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
copy1MBB->transferSuccessorsAndUpdatePHIs(BB);
// Next, add the true and fallthrough blocks as its successors. // Next, add the true and fallthrough blocks as its successors.
BB->addSuccessor(copy0MBB); BB->addSuccessor(copy0MBB);
BB->addSuccessor(copy1MBB); BB->addSuccessor(copy1MBB);
BuildMI(BB, dl, TII.get(MSP430::JCC))
.addMBB(copy1MBB)
.addImm(MI->getOperand(3).getImm());
// copy0MBB: // copy0MBB:
// %FalseValue = ... // %FalseValue = ...
// # fallthrough to copy1MBB // # fallthrough to copy1MBB
@ -1189,11 +1182,11 @@ MSP430TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
// ... // ...
BB = copy1MBB; BB = copy1MBB;
BuildMI(*BB, BB->begin(), dl, TII.get(MSP430::PHI), BuildMI(BB, dl, TII.get(MSP430::PHI),
MI->getOperand(0).getReg()) MI->getOperand(0).getReg())
.addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB) .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB)
.addReg(MI->getOperand(1).getReg()).addMBB(thisMBB); .addReg(MI->getOperand(1).getReg()).addMBB(thisMBB);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return BB; return BB;
} }

View File

@ -284,18 +284,6 @@ MipsTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
MachineFunction *F = BB->getParent(); MachineFunction *F = BB->getParent();
MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
F->insert(It, copy0MBB);
F->insert(It, sinkMBB);
// Transfer the remainder of BB and its successor edges to sinkMBB.
sinkMBB->splice(sinkMBB->begin(), BB,
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
sinkMBB->transferSuccessorsAndUpdatePHIs(BB);
// Next, add the true and fallthrough blocks as its successors.
BB->addSuccessor(copy0MBB);
BB->addSuccessor(sinkMBB);
// Emit the right instruction according to the type of the operands compared // Emit the right instruction according to the type of the operands compared
if (isFPCmp) { if (isFPCmp) {
@ -308,6 +296,20 @@ MipsTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
BuildMI(BB, dl, TII->get(Mips::BNE)).addReg(MI->getOperand(1).getReg()) BuildMI(BB, dl, TII->get(Mips::BNE)).addReg(MI->getOperand(1).getReg())
.addReg(Mips::ZERO).addMBB(sinkMBB); .addReg(Mips::ZERO).addMBB(sinkMBB);
F->insert(It, copy0MBB);
F->insert(It, sinkMBB);
// Update machine-CFG edges by first adding all successors of the current
// block to the new block which will contain the Phi node for the select.
for(MachineBasicBlock::succ_iterator i = BB->succ_begin(),
e = BB->succ_end(); i != e; ++i)
sinkMBB->addSuccessor(*i);
// Next, remove all successors of the current block, and add the true
// and fallthrough blocks as its successors.
while(!BB->succ_empty())
BB->removeSuccessor(BB->succ_begin());
BB->addSuccessor(copy0MBB);
BB->addSuccessor(sinkMBB);
// copy0MBB: // copy0MBB:
// %FalseValue = ... // %FalseValue = ...
// # fallthrough to sinkMBB // # fallthrough to sinkMBB
@ -320,12 +322,11 @@ MipsTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
// ... // ...
BB = sinkMBB; BB = sinkMBB;
BuildMI(*BB, BB->begin(), dl, BuildMI(BB, dl, TII->get(Mips::PHI), MI->getOperand(0).getReg())
TII->get(Mips::PHI), MI->getOperand(0).getReg())
.addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB) .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB)
.addReg(MI->getOperand(3).getReg()).addMBB(thisMBB); .addReg(MI->getOperand(3).getReg()).addMBB(thisMBB);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return BB; return BB;
} }
} }

View File

@ -1928,12 +1928,15 @@ PIC16TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
F->insert(It, copy0MBB); F->insert(It, copy0MBB);
F->insert(It, sinkMBB); F->insert(It, sinkMBB);
// Transfer the remainder of BB and its successor edges to sinkMBB. // Update machine-CFG edges by first adding all successors of the current
sinkMBB->splice(sinkMBB->begin(), BB, // block to the new block which will contain the Phi node for the select.
llvm::next(MachineBasicBlock::iterator(MI)), for (MachineBasicBlock::succ_iterator I = BB->succ_begin(),
BB->end()); E = BB->succ_end(); I != E; ++I)
sinkMBB->transferSuccessorsAndUpdatePHIs(BB); sinkMBB->addSuccessor(*I);
// Next, remove all successors of the current block, and add the true
// and fallthrough blocks as its successors.
while (!BB->succ_empty())
BB->removeSuccessor(BB->succ_begin());
// Next, add the true and fallthrough blocks as its successors. // Next, add the true and fallthrough blocks as its successors.
BB->addSuccessor(copy0MBB); BB->addSuccessor(copy0MBB);
BB->addSuccessor(sinkMBB); BB->addSuccessor(sinkMBB);
@ -1950,12 +1953,11 @@ PIC16TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
// ... // ...
BB = sinkMBB; BB = sinkMBB;
BuildMI(*BB, BB->begin(), dl, BuildMI(BB, dl, TII.get(PIC16::PHI), MI->getOperand(0).getReg())
TII.get(PIC16::PHI), MI->getOperand(0).getReg())
.addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB) .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB)
.addReg(MI->getOperand(1).getReg()).addMBB(thisMBB); .addReg(MI->getOperand(1).getReg()).addMBB(thisMBB);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return BB; return BB;
} }

View File

@ -4513,10 +4513,7 @@ PPCTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB,
MachineBasicBlock *exitMBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *exitMBB = F->CreateMachineBasicBlock(LLVM_BB);
F->insert(It, loopMBB); F->insert(It, loopMBB);
F->insert(It, exitMBB); F->insert(It, exitMBB);
exitMBB->splice(exitMBB->begin(), BB, exitMBB->transferSuccessors(BB);
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
exitMBB->transferSuccessorsAndUpdatePHIs(BB);
MachineRegisterInfo &RegInfo = F->getRegInfo(); MachineRegisterInfo &RegInfo = F->getRegInfo();
unsigned TmpReg = (!BinOpcode) ? incr : unsigned TmpReg = (!BinOpcode) ? incr :
@ -4581,10 +4578,7 @@ PPCTargetLowering::EmitPartwordAtomicBinary(MachineInstr *MI,
MachineBasicBlock *exitMBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *exitMBB = F->CreateMachineBasicBlock(LLVM_BB);
F->insert(It, loopMBB); F->insert(It, loopMBB);
F->insert(It, exitMBB); F->insert(It, exitMBB);
exitMBB->splice(exitMBB->begin(), BB, exitMBB->transferSuccessors(BB);
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
exitMBB->transferSuccessorsAndUpdatePHIs(BB);
MachineRegisterInfo &RegInfo = F->getRegInfo(); MachineRegisterInfo &RegInfo = F->getRegInfo();
const TargetRegisterClass *RC = const TargetRegisterClass *RC =
@ -4717,22 +4711,23 @@ PPCTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
unsigned SelectPred = MI->getOperand(4).getImm(); unsigned SelectPred = MI->getOperand(4).getImm();
DebugLoc dl = MI->getDebugLoc(); DebugLoc dl = MI->getDebugLoc();
BuildMI(BB, dl, TII->get(PPC::BCC))
.addImm(SelectPred).addReg(MI->getOperand(1).getReg()).addMBB(sinkMBB);
F->insert(It, copy0MBB); F->insert(It, copy0MBB);
F->insert(It, sinkMBB); F->insert(It, sinkMBB);
// Update machine-CFG edges by first adding all successors of the current
// Transfer the remainder of BB and its successor edges to sinkMBB. // block to the new block which will contain the Phi node for the select.
sinkMBB->splice(sinkMBB->begin(), BB, for (MachineBasicBlock::succ_iterator I = BB->succ_begin(),
llvm::next(MachineBasicBlock::iterator(MI)), E = BB->succ_end(); I != E; ++I)
BB->end()); sinkMBB->addSuccessor(*I);
sinkMBB->transferSuccessorsAndUpdatePHIs(BB); // Next, remove all successors of the current block, and add the true
// and fallthrough blocks as its successors.
while (!BB->succ_empty())
BB->removeSuccessor(BB->succ_begin());
// Next, add the true and fallthrough blocks as its successors. // Next, add the true and fallthrough blocks as its successors.
BB->addSuccessor(copy0MBB); BB->addSuccessor(copy0MBB);
BB->addSuccessor(sinkMBB); BB->addSuccessor(sinkMBB);
BuildMI(BB, dl, TII->get(PPC::BCC))
.addImm(SelectPred).addReg(MI->getOperand(1).getReg()).addMBB(sinkMBB);
// copy0MBB: // copy0MBB:
// %FalseValue = ... // %FalseValue = ...
// # fallthrough to sinkMBB // # fallthrough to sinkMBB
@ -4745,8 +4740,7 @@ PPCTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
// ... // ...
BB = sinkMBB; BB = sinkMBB;
BuildMI(*BB, BB->begin(), dl, BuildMI(BB, dl, TII->get(PPC::PHI), MI->getOperand(0).getReg())
TII->get(PPC::PHI), MI->getOperand(0).getReg())
.addReg(MI->getOperand(3).getReg()).addMBB(copy0MBB) .addReg(MI->getOperand(3).getReg()).addMBB(copy0MBB)
.addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
} }
@ -4832,10 +4826,7 @@ PPCTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
F->insert(It, loop2MBB); F->insert(It, loop2MBB);
F->insert(It, midMBB); F->insert(It, midMBB);
F->insert(It, exitMBB); F->insert(It, exitMBB);
exitMBB->splice(exitMBB->begin(), BB, exitMBB->transferSuccessors(BB);
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
exitMBB->transferSuccessorsAndUpdatePHIs(BB);
// thisMBB: // thisMBB:
// ... // ...
@ -4903,10 +4894,7 @@ PPCTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
F->insert(It, loop2MBB); F->insert(It, loop2MBB);
F->insert(It, midMBB); F->insert(It, midMBB);
F->insert(It, exitMBB); F->insert(It, exitMBB);
exitMBB->splice(exitMBB->begin(), BB, exitMBB->transferSuccessors(BB);
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
exitMBB->transferSuccessorsAndUpdatePHIs(BB);
MachineRegisterInfo &RegInfo = F->getRegInfo(); MachineRegisterInfo &RegInfo = F->getRegInfo();
const TargetRegisterClass *RC = const TargetRegisterClass *RC =
@ -5032,7 +5020,7 @@ PPCTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
llvm_unreachable("Unexpected instr type to insert"); llvm_unreachable("Unexpected instr type to insert");
} }
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return BB; return BB;
} }

View File

@ -1007,20 +1007,21 @@ SparcTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
MachineFunction *F = BB->getParent(); MachineFunction *F = BB->getParent();
MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
// Transfer the remainder of BB and its successor edges to sinkMBB.
sinkMBB->splice(sinkMBB->begin(), BB,
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
sinkMBB->transferSuccessorsAndUpdatePHIs(BB);
// Add the true and fallthrough blocks as its successors.
BB->addSuccessor(copy0MBB);
BB->addSuccessor(sinkMBB);
BuildMI(BB, dl, TII.get(BROpcode)).addMBB(sinkMBB).addImm(CC); BuildMI(BB, dl, TII.get(BROpcode)).addMBB(sinkMBB).addImm(CC);
F->insert(It, copy0MBB); F->insert(It, copy0MBB);
F->insert(It, sinkMBB); F->insert(It, sinkMBB);
// Update machine-CFG edges by first adding all successors of the current
// block to the new block which will contain the Phi node for the select.
for (MachineBasicBlock::succ_iterator I = BB->succ_begin(),
E = BB->succ_end(); I != E; ++I)
sinkMBB->addSuccessor(*I);
// Next, remove all successors of the current block, and add the true
// and fallthrough blocks as its successors.
while (!BB->succ_empty())
BB->removeSuccessor(BB->succ_begin());
// Next, add the true and fallthrough blocks as its successors.
BB->addSuccessor(copy0MBB);
BB->addSuccessor(sinkMBB);
// copy0MBB: // copy0MBB:
// %FalseValue = ... // %FalseValue = ...
@ -1034,11 +1035,11 @@ SparcTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
// ... // ...
BB = sinkMBB; BB = sinkMBB;
BuildMI(*BB, BB->begin(), dl, TII.get(SP::PHI), MI->getOperand(0).getReg()) BuildMI(BB, dl, TII.get(SP::PHI), MI->getOperand(0).getReg())
.addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB) .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB)
.addReg(MI->getOperand(1).getReg()).addMBB(thisMBB); .addReg(MI->getOperand(1).getReg()).addMBB(thisMBB);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return BB; return BB;
} }

View File

@ -827,20 +827,16 @@ SystemZTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
MachineBasicBlock *copy1MBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *copy1MBB = F->CreateMachineBasicBlock(LLVM_BB);
SystemZCC::CondCodes CC = (SystemZCC::CondCodes)MI->getOperand(3).getImm(); SystemZCC::CondCodes CC = (SystemZCC::CondCodes)MI->getOperand(3).getImm();
BuildMI(BB, dl, TII.getBrCond(CC)).addMBB(copy1MBB);
F->insert(I, copy0MBB); F->insert(I, copy0MBB);
F->insert(I, copy1MBB); F->insert(I, copy1MBB);
// Update machine-CFG edges by transferring all successors of the current // 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. // block to the new block which will contain the Phi node for the select.
copy1MBB->splice(copy1MBB->begin(), BB, copy1MBB->transferSuccessors(BB);
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
copy1MBB->transferSuccessorsAndUpdatePHIs(BB);
// Next, add the true and fallthrough blocks as its successors. // Next, add the true and fallthrough blocks as its successors.
BB->addSuccessor(copy0MBB); BB->addSuccessor(copy0MBB);
BB->addSuccessor(copy1MBB); BB->addSuccessor(copy1MBB);
BuildMI(BB, dl, TII.getBrCond(CC)).addMBB(copy1MBB);
// copy0MBB: // copy0MBB:
// %FalseValue = ... // %FalseValue = ...
// # fallthrough to copy1MBB // # fallthrough to copy1MBB
@ -853,11 +849,11 @@ SystemZTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
// ... // ...
BB = copy1MBB; BB = copy1MBB;
BuildMI(*BB, BB->begin(), dl, TII.get(SystemZ::PHI), BuildMI(BB, dl, TII.get(SystemZ::PHI),
MI->getOperand(0).getReg()) MI->getOperand(0).getReg())
.addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB) .addReg(MI->getOperand(2).getReg()).addMBB(copy0MBB)
.addReg(MI->getOperand(1).getReg()).addMBB(thisMBB); .addReg(MI->getOperand(1).getReg()).addMBB(thisMBB);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return BB; return BB;
} }

View File

@ -8023,11 +8023,8 @@ X86TargetLowering::EmitAtomicBitwiseWithCustomInserter(MachineInstr *bInstr,
F->insert(MBBIter, newMBB); F->insert(MBBIter, newMBB);
F->insert(MBBIter, nextMBB); F->insert(MBBIter, nextMBB);
// Transfer the remainder of thisMBB and its successor edges to nextMBB. // Move all successors to thisMBB to nextMBB
nextMBB->splice(nextMBB->begin(), thisMBB, nextMBB->transferSuccessors(thisMBB);
llvm::next(MachineBasicBlock::iterator(bInstr)),
thisMBB->end());
nextMBB->transferSuccessorsAndUpdatePHIs(thisMBB);
// Update thisMBB to fall through to newMBB // Update thisMBB to fall through to newMBB
thisMBB->addSuccessor(newMBB); thisMBB->addSuccessor(newMBB);
@ -8090,7 +8087,7 @@ X86TargetLowering::EmitAtomicBitwiseWithCustomInserter(MachineInstr *bInstr,
// insert branch // insert branch
BuildMI(newMBB, dl, TII->get(X86::JNE_4)).addMBB(newMBB); BuildMI(newMBB, dl, TII->get(X86::JNE_4)).addMBB(newMBB);
bInstr->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(bInstr); // The pseudo instruction is gone now.
return nextMBB; return nextMBB;
} }
@ -8135,11 +8132,8 @@ X86TargetLowering::EmitAtomicBit6432WithCustomInserter(MachineInstr *bInstr,
F->insert(MBBIter, newMBB); F->insert(MBBIter, newMBB);
F->insert(MBBIter, nextMBB); F->insert(MBBIter, nextMBB);
// Transfer the remainder of thisMBB and its successor edges to nextMBB. // Move all successors to thisMBB to nextMBB
nextMBB->splice(nextMBB->begin(), thisMBB, nextMBB->transferSuccessors(thisMBB);
llvm::next(MachineBasicBlock::iterator(bInstr)),
thisMBB->end());
nextMBB->transferSuccessorsAndUpdatePHIs(thisMBB);
// Update thisMBB to fall through to newMBB // Update thisMBB to fall through to newMBB
thisMBB->addSuccessor(newMBB); thisMBB->addSuccessor(newMBB);
@ -8256,7 +8250,7 @@ X86TargetLowering::EmitAtomicBit6432WithCustomInserter(MachineInstr *bInstr,
// insert branch // insert branch
BuildMI(newMBB, dl, TII->get(X86::JNE_4)).addMBB(newMBB); BuildMI(newMBB, dl, TII->get(X86::JNE_4)).addMBB(newMBB);
bInstr->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(bInstr); // The pseudo instruction is gone now.
return nextMBB; return nextMBB;
} }
@ -8290,11 +8284,8 @@ X86TargetLowering::EmitAtomicMinMaxWithCustomInserter(MachineInstr *mInstr,
F->insert(MBBIter, newMBB); F->insert(MBBIter, newMBB);
F->insert(MBBIter, nextMBB); F->insert(MBBIter, nextMBB);
// Transfer the remainder of thisMBB and its successor edges to nextMBB. // Move all successors of thisMBB to nextMBB
nextMBB->splice(nextMBB->begin(), thisMBB, nextMBB->transferSuccessors(thisMBB);
llvm::next(MachineBasicBlock::iterator(mInstr)),
thisMBB->end());
nextMBB->transferSuccessorsAndUpdatePHIs(thisMBB);
// Update thisMBB to fall through to newMBB // Update thisMBB to fall through to newMBB
thisMBB->addSuccessor(newMBB); thisMBB->addSuccessor(newMBB);
@ -8362,7 +8353,7 @@ X86TargetLowering::EmitAtomicMinMaxWithCustomInserter(MachineInstr *mInstr,
// insert branch // insert branch
BuildMI(newMBB, dl, TII->get(X86::JNE_4)).addMBB(newMBB); BuildMI(newMBB, dl, TII->get(X86::JNE_4)).addMBB(newMBB);
mInstr->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(mInstr); // The pseudo instruction is gone now.
return nextMBB; return nextMBB;
} }
@ -8372,6 +8363,7 @@ MachineBasicBlock *
X86TargetLowering::EmitPCMP(MachineInstr *MI, MachineBasicBlock *BB, X86TargetLowering::EmitPCMP(MachineInstr *MI, MachineBasicBlock *BB,
unsigned numArgs, bool memArg) const { unsigned numArgs, bool memArg) const {
MachineFunction *F = BB->getParent();
DebugLoc dl = MI->getDebugLoc(); DebugLoc dl = MI->getDebugLoc();
const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
@ -8393,7 +8385,7 @@ X86TargetLowering::EmitPCMP(MachineInstr *MI, MachineBasicBlock *BB,
BuildMI(BB, dl, TII->get(X86::MOVAPSrr), MI->getOperand(0).getReg()) BuildMI(BB, dl, TII->get(X86::MOVAPSrr), MI->getOperand(0).getReg())
.addReg(X86::XMM0); .addReg(X86::XMM0);
MI->eraseFromParent(); F->DeleteMachineInstr(MI);
return BB; return BB;
} }
@ -8422,12 +8414,9 @@ X86TargetLowering::EmitVAStartSaveXMMRegsWithCustomInserter(
F->insert(MBBIter, XMMSaveMBB); F->insert(MBBIter, XMMSaveMBB);
F->insert(MBBIter, EndMBB); F->insert(MBBIter, EndMBB);
// Transfer the remainder of MBB and its successor edges to EndMBB. // Set up the CFG.
EndMBB->splice(EndMBB->begin(), MBB, // Move any original successors of MBB to the end block.
llvm::next(MachineBasicBlock::iterator(MI)), EndMBB->transferSuccessors(MBB);
MBB->end());
EndMBB->transferSuccessorsAndUpdatePHIs(MBB);
// The original block will now fall through to the XMM save block. // The original block will now fall through to the XMM save block.
MBB->addSuccessor(XMMSaveMBB); MBB->addSuccessor(XMMSaveMBB);
// The XMMSaveMBB will fall through to the end block. // The XMMSaveMBB will fall through to the end block.
@ -8466,7 +8455,7 @@ X86TargetLowering::EmitVAStartSaveXMMRegsWithCustomInserter(
.addMemOperand(MMO); .addMemOperand(MMO);
} }
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return EndMBB; return EndMBB;
} }
@ -8495,17 +8484,37 @@ X86TargetLowering::EmitLoweredSelect(MachineInstr *MI,
MachineFunction *F = BB->getParent(); MachineFunction *F = BB->getParent();
MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
MachineBasicBlock *sinkMBB = 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, copy0MBB);
F->insert(It, sinkMBB); F->insert(It, sinkMBB);
// Update machine-CFG edges by first adding all successors of the current
// block to the new block which will contain the Phi node for the select.
for (MachineBasicBlock::succ_iterator I = BB->succ_begin(),
E = BB->succ_end(); I != E; ++I)
sinkMBB->addSuccessor(*I);
// Next, remove all successors of the current block, and add the true
// and fallthrough blocks as its successors.
while (!BB->succ_empty())
BB->removeSuccessor(BB->succ_begin());
// Add the true and fallthrough blocks as its successors.
BB->addSuccessor(copy0MBB);
BB->addSuccessor(sinkMBB);
// If the EFLAGS register isn't dead in the terminator, then claim that it's // If the EFLAGS register isn't dead in the terminator, then claim that it's
// live into the sink and copy blocks. // live into the sink and copy blocks.
const MachineFunction *MF = BB->getParent(); const MachineFunction *MF = BB->getParent();
const TargetRegisterInfo *TRI = MF->getTarget().getRegisterInfo(); const TargetRegisterInfo *TRI = MF->getTarget().getRegisterInfo();
BitVector ReservedRegs = TRI->getReservedRegs(*MF); BitVector ReservedRegs = TRI->getReservedRegs(*MF);
const MachineInstr *Term = BB->getFirstTerminator();
for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) { for (unsigned I = 0, E = Term->getNumOperands(); I != E; ++I) {
const MachineOperand &MO = MI->getOperand(I); const MachineOperand &MO = Term->getOperand(I);
if (!MO.isReg() || MO.isKill() || MO.isDead()) continue; if (!MO.isReg() || MO.isKill() || MO.isDead()) continue;
unsigned Reg = MO.getReg(); unsigned Reg = MO.getReg();
if (Reg != X86::EFLAGS) continue; if (Reg != X86::EFLAGS) continue;
@ -8513,21 +8522,6 @@ X86TargetLowering::EmitLoweredSelect(MachineInstr *MI,
sinkMBB->addLiveIn(Reg); sinkMBB->addLiveIn(Reg);
} }
// Transfer the remainder of BB and its successor edges to sinkMBB.
sinkMBB->splice(sinkMBB->begin(), BB,
llvm::next(MachineBasicBlock::iterator(MI)),
BB->end());
sinkMBB->transferSuccessorsAndUpdatePHIs(BB);
// Add the true and fallthrough blocks as its successors.
BB->addSuccessor(copy0MBB);
BB->addSuccessor(sinkMBB);
// Create the conditional branch instruction.
unsigned Opc =
X86::GetCondBranchFromCond((X86::CondCode)MI->getOperand(3).getImm());
BuildMI(BB, DL, TII->get(Opc)).addMBB(sinkMBB);
// copy0MBB: // copy0MBB:
// %FalseValue = ... // %FalseValue = ...
// # fallthrough to sinkMBB // # fallthrough to sinkMBB
@ -8536,12 +8530,11 @@ X86TargetLowering::EmitLoweredSelect(MachineInstr *MI,
// sinkMBB: // sinkMBB:
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
// ... // ...
BuildMI(*sinkMBB, sinkMBB->begin(), DL, BuildMI(sinkMBB, DL, TII->get(X86::PHI), MI->getOperand(0).getReg())
TII->get(X86::PHI), MI->getOperand(0).getReg())
.addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB)
.addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return sinkMBB; return sinkMBB;
} }
@ -8550,20 +8543,21 @@ X86TargetLowering::EmitLoweredMingwAlloca(MachineInstr *MI,
MachineBasicBlock *BB) const { MachineBasicBlock *BB) const {
const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); const TargetInstrInfo *TII = getTargetMachine().getInstrInfo();
DebugLoc DL = MI->getDebugLoc(); DebugLoc DL = MI->getDebugLoc();
MachineFunction *F = BB->getParent();
// The lowering is pretty easy: we're just emitting the call to _alloca. The // The lowering is pretty easy: we're just emitting the call to _alloca. The
// non-trivial part is impdef of ESP. // non-trivial part is impdef of ESP.
// FIXME: The code should be tweaked as soon as we'll try to do codegen for // FIXME: The code should be tweaked as soon as we'll try to do codegen for
// mingw-w64. // mingw-w64.
BuildMI(*BB, MI, DL, TII->get(X86::CALLpcrel32)) BuildMI(BB, DL, TII->get(X86::CALLpcrel32))
.addExternalSymbol("_alloca") .addExternalSymbol("_alloca")
.addReg(X86::EAX, RegState::Implicit) .addReg(X86::EAX, RegState::Implicit)
.addReg(X86::ESP, RegState::Implicit) .addReg(X86::ESP, RegState::Implicit)
.addReg(X86::EAX, RegState::Define | RegState::Implicit) .addReg(X86::EAX, RegState::Define | RegState::Implicit)
.addReg(X86::ESP, RegState::Define | RegState::Implicit); .addReg(X86::ESP, RegState::Define | RegState::Implicit);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return BB; return BB;
} }
@ -8582,38 +8576,35 @@ X86TargetLowering::EmitLoweredTLSCall(MachineInstr *MI,
assert(MI->getOperand(3).isGlobal() && "This should be a global"); assert(MI->getOperand(3).isGlobal() && "This should be a global");
if (Subtarget->is64Bit()) { if (Subtarget->is64Bit()) {
MachineInstrBuilder MIB = BuildMI(*BB, MI, DL, MachineInstrBuilder MIB = BuildMI(BB, DL, TII->get(X86::MOV64rm), X86::RDI)
TII->get(X86::MOV64rm), X86::RDI)
.addReg(X86::RIP) .addReg(X86::RIP)
.addImm(0).addReg(0) .addImm(0).addReg(0)
.addGlobalAddress(MI->getOperand(3).getGlobal(), 0, .addGlobalAddress(MI->getOperand(3).getGlobal(), 0,
MI->getOperand(3).getTargetFlags()) MI->getOperand(3).getTargetFlags())
.addReg(0); .addReg(0);
MIB = BuildMI(*BB, MI, DL, TII->get(X86::CALL64m)); MIB = BuildMI(BB, DL, TII->get(X86::CALL64m));
addDirectMem(MIB, X86::RDI).addReg(0); addDirectMem(MIB, X86::RDI).addReg(0);
} else if (getTargetMachine().getRelocationModel() != Reloc::PIC_) { } else if (getTargetMachine().getRelocationModel() != Reloc::PIC_) {
MachineInstrBuilder MIB = BuildMI(*BB, MI, DL, MachineInstrBuilder MIB = BuildMI(BB, DL, TII->get(X86::MOV32rm), X86::EAX)
TII->get(X86::MOV32rm), X86::EAX)
.addReg(0) .addReg(0)
.addImm(0).addReg(0) .addImm(0).addReg(0)
.addGlobalAddress(MI->getOperand(3).getGlobal(), 0, .addGlobalAddress(MI->getOperand(3).getGlobal(), 0,
MI->getOperand(3).getTargetFlags()) MI->getOperand(3).getTargetFlags())
.addReg(0); .addReg(0);
MIB = BuildMI(*BB, MI, DL, TII->get(X86::CALL32m)); MIB = BuildMI(BB, DL, TII->get(X86::CALL32m));
addDirectMem(MIB, X86::EAX).addReg(0); addDirectMem(MIB, X86::EAX).addReg(0);
} else { } else {
MachineInstrBuilder MIB = BuildMI(*BB, MI, DL, MachineInstrBuilder MIB = BuildMI(BB, DL, TII->get(X86::MOV32rm), X86::EAX)
TII->get(X86::MOV32rm), X86::EAX)
.addReg(TII->getGlobalBaseReg(F)) .addReg(TII->getGlobalBaseReg(F))
.addImm(0).addReg(0) .addImm(0).addReg(0)
.addGlobalAddress(MI->getOperand(3).getGlobal(), 0, .addGlobalAddress(MI->getOperand(3).getGlobal(), 0,
MI->getOperand(3).getTargetFlags()) MI->getOperand(3).getTargetFlags())
.addReg(0); .addReg(0);
MIB = BuildMI(*BB, MI, DL, TII->get(X86::CALL32m)); MIB = BuildMI(BB, DL, TII->get(X86::CALL32m));
addDirectMem(MIB, X86::EAX).addReg(0); addDirectMem(MIB, X86::EAX).addReg(0);
} }
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return BB; return BB;
} }
@ -8657,25 +8648,23 @@ X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
// 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, false); int CWFrameIdx = F->getFrameInfo()->CreateStackObject(2, 2, false);
addFrameReference(BuildMI(*BB, MI, DL, addFrameReference(BuildMI(BB, DL, TII->get(X86::FNSTCW16m)), CWFrameIdx);
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, MI, 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, MI, 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, MI, DL, addFrameReference(BuildMI(BB, DL, TII->get(X86::FLDCW16m)), CWFrameIdx);
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, MI, 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.
@ -8714,14 +8703,13 @@ X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
} else { } else {
AM.Disp = Op.getImm(); AM.Disp = Op.getImm();
} }
addFullAddress(BuildMI(*BB, MI, 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, MI, DL, addFrameReference(BuildMI(BB, DL, TII->get(X86::FLDCW16m)), CWFrameIdx);
TII->get(X86::FLDCW16m)), CWFrameIdx);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return BB; return BB;
} }
// String/text processing lowering. // String/text processing lowering.

View File

@ -173,14 +173,14 @@ bool X86TargetMachine::addInstSelector(PassManagerBase &PM,
// Install an instruction selector. // Install an instruction selector.
PM.add(createX86ISelDag(*this, OptLevel)); PM.add(createX86ISelDag(*this, OptLevel));
// Install a pass to insert x87 FP_REG_KILL instructions, as needed.
PM.add(createX87FPRegKillInserterPass());
return false; return false;
} }
bool X86TargetMachine::addPreRegAlloc(PassManagerBase &PM, bool X86TargetMachine::addPreRegAlloc(PassManagerBase &PM,
CodeGenOpt::Level OptLevel) { CodeGenOpt::Level OptLevel) {
// Install a pass to insert x87 FP_REG_KILL instructions, as needed.
PM.add(createX87FPRegKillInserterPass());
PM.add(createX86MaxStackAlignmentHeuristicPass()); PM.add(createX86MaxStackAlignmentHeuristicPass());
return false; // -print-machineinstr shouldn't print after this. return false; // -print-machineinstr shouldn't print after this.
} }

View File

@ -1221,22 +1221,23 @@ XCoreTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
MachineFunction *F = BB->getParent(); MachineFunction *F = BB->getParent();
MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
BuildMI(BB, dl, TII.get(XCore::BRFT_lru6))
.addReg(MI->getOperand(1).getReg()).addMBB(sinkMBB);
F->insert(It, copy0MBB); F->insert(It, copy0MBB);
F->insert(It, sinkMBB); F->insert(It, sinkMBB);
// Update machine-CFG edges by first adding all successors of the current
// Transfer the remainder of BB and its successor edges to sinkMBB. // block to the new block which will contain the Phi node for the select.
sinkMBB->splice(sinkMBB->begin(), BB, for (MachineBasicBlock::succ_iterator I = BB->succ_begin(),
llvm::next(MachineBasicBlock::iterator(MI)), E = BB->succ_end(); I != E; ++I)
BB->end()); sinkMBB->addSuccessor(*I);
sinkMBB->transferSuccessorsAndUpdatePHIs(BB); // Next, remove all successors of the current block, and add the true
// and fallthrough blocks as its successors.
while (!BB->succ_empty())
BB->removeSuccessor(BB->succ_begin());
// Next, add the true and fallthrough blocks as its successors. // Next, add the true and fallthrough blocks as its successors.
BB->addSuccessor(copy0MBB); BB->addSuccessor(copy0MBB);
BB->addSuccessor(sinkMBB); BB->addSuccessor(sinkMBB);
BuildMI(BB, dl, TII.get(XCore::BRFT_lru6))
.addReg(MI->getOperand(1).getReg()).addMBB(sinkMBB);
// copy0MBB: // copy0MBB:
// %FalseValue = ... // %FalseValue = ...
// # fallthrough to sinkMBB // # fallthrough to sinkMBB
@ -1249,12 +1250,11 @@ XCoreTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
// ... // ...
BB = sinkMBB; BB = sinkMBB;
BuildMI(*BB, BB->begin(), dl, BuildMI(BB, dl, TII.get(XCore::PHI), MI->getOperand(0).getReg())
TII.get(XCore::PHI), MI->getOperand(0).getReg())
.addReg(MI->getOperand(3).getReg()).addMBB(copy0MBB) .addReg(MI->getOperand(3).getReg()).addMBB(copy0MBB)
.addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
MI->eraseFromParent(); // The pseudo instruction is gone now. F->DeleteMachineInstr(MI); // The pseudo instruction is gone now.
return BB; return BB;
} }