Remove the explicit MachineInstrBuilder(MI) constructor.

Use the version that also takes an MF reference instead.

It would technically be possible to extract an MF reference from the MI
as MI->getParent()->getParent(), but that would not work for MIs that
are not inserted into any basic block.

Given the reasonably small number of places this constructor was used at
all, I preferred the compile time check to a run time assertion.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170588 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jakob Stoklund Olesen 2012-12-19 21:31:56 +00:00
parent 521396ab37
commit 37a942cd52
7 changed files with 34 additions and 35 deletions

View File

@ -46,7 +46,6 @@ class MachineInstrBuilder {
MachineInstr *MI; MachineInstr *MI;
public: public:
MachineInstrBuilder() : MF(0), MI(0) {} MachineInstrBuilder() : MF(0), MI(0) {}
explicit MachineInstrBuilder(MachineInstr *mi) : MF(0), MI(mi) {}
/// Create a MachineInstrBuilder for manipulating an existing instruction. /// Create a MachineInstrBuilder for manipulating an existing instruction.
/// F must be the machine function that was used to allocate I. /// F must be the machine function that was used to allocate I.

View File

@ -109,7 +109,7 @@ unsigned LookForIdenticalPHI(MachineBasicBlock *BB,
/// a value of the given register class at the start of the specified basic /// a value of the given register class at the start of the specified basic
/// block. It returns the virtual register defined by the instruction. /// block. It returns the virtual register defined by the instruction.
static static
MachineInstr *InsertNewDef(unsigned Opcode, MachineInstrBuilder InsertNewDef(unsigned Opcode,
MachineBasicBlock *BB, MachineBasicBlock::iterator I, MachineBasicBlock *BB, MachineBasicBlock::iterator I,
const TargetRegisterClass *RC, const TargetRegisterClass *RC,
MachineRegisterInfo *MRI, MachineRegisterInfo *MRI,
@ -183,13 +183,12 @@ unsigned MachineSSAUpdater::GetValueInMiddleOfBlock(MachineBasicBlock *BB) {
// Otherwise, we do need a PHI: insert one now. // Otherwise, we do need a PHI: insert one now.
MachineBasicBlock::iterator Loc = BB->empty() ? BB->end() : BB->begin(); MachineBasicBlock::iterator Loc = BB->empty() ? BB->end() : BB->begin();
MachineInstr *InsertedPHI = InsertNewDef(TargetOpcode::PHI, BB, MachineInstrBuilder InsertedPHI = InsertNewDef(TargetOpcode::PHI, BB,
Loc, VRC, MRI, TII); Loc, VRC, MRI, TII);
// Fill in all the predecessors of the PHI. // Fill in all the predecessors of the PHI.
MachineInstrBuilder MIB(InsertedPHI);
for (unsigned i = 0, e = PredValues.size(); i != e; ++i) for (unsigned i = 0, e = PredValues.size(); i != e; ++i)
MIB.addReg(PredValues[i].second).addMBB(PredValues[i].first); InsertedPHI.addReg(PredValues[i].second).addMBB(PredValues[i].first);
// See if the PHI node can be merged to a single value. This can happen in // See if the PHI node can be merged to a single value. This can happen in
// loop cases when we get a PHI of itself and one other value. // loop cases when we get a PHI of itself and one other value.

View File

@ -1154,6 +1154,7 @@ bool ARMBaseInstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const{
// All clear, widen the COPY. // All clear, widen the COPY.
DEBUG(dbgs() << "widening: " << *MI); DEBUG(dbgs() << "widening: " << *MI);
MachineInstrBuilder MIB(*MI->getParent()->getParent(), MI);
// Get rid of the old <imp-def> of DstRegD. Leave it if it defines a Q-reg // Get rid of the old <imp-def> of DstRegD. Leave it if it defines a Q-reg
// or some other super-register. // or some other super-register.
@ -1165,14 +1166,14 @@ bool ARMBaseInstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const{
MI->setDesc(get(ARM::VMOVD)); MI->setDesc(get(ARM::VMOVD));
MI->getOperand(0).setReg(DstRegD); MI->getOperand(0).setReg(DstRegD);
MI->getOperand(1).setReg(SrcRegD); MI->getOperand(1).setReg(SrcRegD);
AddDefaultPred(MachineInstrBuilder(MI)); AddDefaultPred(MIB);
// We are now reading SrcRegD instead of SrcRegS. This may upset the // We are now reading SrcRegD instead of SrcRegS. This may upset the
// register scavenger and machine verifier, so we need to indicate that we // register scavenger and machine verifier, so we need to indicate that we
// are reading an undefined value from SrcRegD, but a proper value from // are reading an undefined value from SrcRegD, but a proper value from
// SrcRegS. // SrcRegS.
MI->getOperand(1).setIsUndef(); MI->getOperand(1).setIsUndef();
MachineInstrBuilder(MI).addReg(SrcRegS, RegState::Implicit); MIB.addReg(SrcRegS, RegState::Implicit);
// SrcRegD may actually contain an unrelated value in the ssub_1 // SrcRegD may actually contain an unrelated value in the ssub_1
// sub-register. Don't kill it. Only kill the ssub_0 sub-register. // sub-register. Don't kill it. Only kill the ssub_0 sub-register.
@ -3819,7 +3820,7 @@ void
ARMBaseInstrInfo::setExecutionDomain(MachineInstr *MI, unsigned Domain) const { ARMBaseInstrInfo::setExecutionDomain(MachineInstr *MI, unsigned Domain) const {
unsigned DstReg, SrcReg, DReg; unsigned DstReg, SrcReg, DReg;
unsigned Lane; unsigned Lane;
MachineInstrBuilder MIB(MI); MachineInstrBuilder MIB(*MI->getParent()->getParent(), MI);
const TargetRegisterInfo *TRI = &getRegisterInfo(); const TargetRegisterInfo *TRI = &getRegisterInfo();
switch (MI->getOpcode()) { switch (MI->getOpcode()) {
default: default:

View File

@ -6612,7 +6612,7 @@ EmitSjLjDispatchBlock(MachineInstr *MI, MachineBasicBlock *MBB) const {
DefRegs[OI->getReg()] = true; DefRegs[OI->getReg()] = true;
} }
MachineInstrBuilder MIB(&*II); MachineInstrBuilder MIB(*MF, &*II);
for (unsigned i = 0; SavedRegs[i] != 0; ++i) { for (unsigned i = 0; SavedRegs[i] != 0; ++i) {
unsigned Reg = SavedRegs[i]; unsigned Reg = SavedRegs[i];

View File

@ -390,6 +390,7 @@ rewriteFrameIndex(MachineBasicBlock::iterator II, unsigned FrameRegIdx,
MachineInstr &MI = *II; MachineInstr &MI = *II;
MachineBasicBlock &MBB = *MI.getParent(); MachineBasicBlock &MBB = *MI.getParent();
DebugLoc dl = MI.getDebugLoc(); DebugLoc dl = MI.getDebugLoc();
MachineInstrBuilder MIB(*MBB.getParent(), &MI);
unsigned Opcode = MI.getOpcode(); unsigned Opcode = MI.getOpcode();
const MCInstrDesc &Desc = MI.getDesc(); const MCInstrDesc &Desc = MI.getDesc();
unsigned AddrMode = (Desc.TSFlags & ARMII::AddrModeMask); unsigned AddrMode = (Desc.TSFlags & ARMII::AddrModeMask);
@ -417,7 +418,6 @@ rewriteFrameIndex(MachineBasicBlock::iterator II, unsigned FrameRegIdx,
MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false); MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false);
// Remove offset // Remove offset
MI.RemoveOperand(FrameRegIdx+1); MI.RemoveOperand(FrameRegIdx+1);
MachineInstrBuilder MIB(&MI);
return true; return true;
} }
@ -428,7 +428,6 @@ rewriteFrameIndex(MachineBasicBlock::iterator II, unsigned FrameRegIdx,
if (Opcode == ARM::tADDi3) { if (Opcode == ARM::tADDi3) {
MI.setDesc(TII.get(Opcode)); MI.setDesc(TII.get(Opcode));
removeOperands(MI, FrameRegIdx); removeOperands(MI, FrameRegIdx);
MachineInstrBuilder MIB(&MI);
AddDefaultPred(AddDefaultT1CC(MIB).addReg(FrameReg) AddDefaultPred(AddDefaultT1CC(MIB).addReg(FrameReg)
.addImm(Offset / Scale)); .addImm(Offset / Scale));
} else { } else {
@ -457,7 +456,6 @@ rewriteFrameIndex(MachineBasicBlock::iterator II, unsigned FrameRegIdx,
if (Opcode == ARM::tADDi3) { if (Opcode == ARM::tADDi3) {
MI.setDesc(TII.get(Opcode)); MI.setDesc(TII.get(Opcode));
removeOperands(MI, FrameRegIdx); removeOperands(MI, FrameRegIdx);
MachineInstrBuilder MIB(&MI);
AddDefaultPred(AddDefaultT1CC(MIB).addReg(FrameReg).addImm(Mask)); AddDefaultPred(AddDefaultT1CC(MIB).addReg(FrameReg).addImm(Mask));
} else { } else {
MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false); MI.getOperand(FrameRegIdx).ChangeToRegister(FrameReg, false);
@ -603,6 +601,7 @@ Thumb1RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
MachineFunction &MF = *MBB.getParent(); MachineFunction &MF = *MBB.getParent();
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
DebugLoc dl = MI.getDebugLoc(); DebugLoc dl = MI.getDebugLoc();
MachineInstrBuilder MIB(*MBB.getParent(), &MI);
while (!MI.getOperand(i).isFI()) { while (!MI.getOperand(i).isFI()) {
++i; ++i;
@ -719,8 +718,6 @@ Thumb1RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
} }
// Add predicate back if it's needed. // Add predicate back if it's needed.
if (MI.isPredicable()) { if (MI.isPredicable())
MachineInstrBuilder MIB(&MI);
AddDefaultPred(MIB); AddDefaultPred(MIB);
}
} }

View File

@ -408,7 +408,7 @@ bool llvm::rewriteT2FrameIndex(MachineInstr &MI, unsigned FrameRegIdx,
// Remove offset and remaining explicit predicate operands. // Remove offset and remaining explicit predicate operands.
do MI.RemoveOperand(FrameRegIdx+1); do MI.RemoveOperand(FrameRegIdx+1);
while (MI.getNumOperands() > FrameRegIdx+1); while (MI.getNumOperands() > FrameRegIdx+1);
MachineInstrBuilder MIB(&MI); MachineInstrBuilder MIB(*MI.getParent()->getParent(), &MI);
AddDefaultPred(MIB); AddDefaultPred(MIB);
return true; return true;
} }

View File

@ -3525,43 +3525,44 @@ optimizeLoadInstr(MachineInstr *MI, const MachineRegisterInfo *MRI,
/// to: /// to:
/// %xmm4 = PXORrr %xmm4<undef>, %xmm4<undef> /// %xmm4 = PXORrr %xmm4<undef>, %xmm4<undef>
/// ///
static bool Expand2AddrUndef(MachineInstr *MI, const MCInstrDesc &Desc) { static bool Expand2AddrUndef(MachineInstrBuilder &MIB,
const MCInstrDesc &Desc) {
assert(Desc.getNumOperands() == 3 && "Expected two-addr instruction."); assert(Desc.getNumOperands() == 3 && "Expected two-addr instruction.");
unsigned Reg = MI->getOperand(0).getReg(); unsigned Reg = MIB->getOperand(0).getReg();
MI->setDesc(Desc); MIB->setDesc(Desc);
// MachineInstr::addOperand() will insert explicit operands before any // MachineInstr::addOperand() will insert explicit operands before any
// implicit operands. // implicit operands.
MachineInstrBuilder(MI).addReg(Reg, RegState::Undef) MIB.addReg(Reg, RegState::Undef).addReg(Reg, RegState::Undef);
.addReg(Reg, RegState::Undef);
// But we don't trust that. // But we don't trust that.
assert(MI->getOperand(1).getReg() == Reg && assert(MIB->getOperand(1).getReg() == Reg &&
MI->getOperand(2).getReg() == Reg && "Misplaced operand"); MIB->getOperand(2).getReg() == Reg && "Misplaced operand");
return true; return true;
} }
bool X86InstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const { bool X86InstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const {
bool HasAVX = TM.getSubtarget<X86Subtarget>().hasAVX(); bool HasAVX = TM.getSubtarget<X86Subtarget>().hasAVX();
MachineInstrBuilder MIB(*MI->getParent()->getParent(), MI);
switch (MI->getOpcode()) { switch (MI->getOpcode()) {
case X86::SETB_C8r: case X86::SETB_C8r:
return Expand2AddrUndef(MI, get(X86::SBB8rr)); return Expand2AddrUndef(MIB, get(X86::SBB8rr));
case X86::SETB_C16r: case X86::SETB_C16r:
return Expand2AddrUndef(MI, get(X86::SBB16rr)); return Expand2AddrUndef(MIB, get(X86::SBB16rr));
case X86::SETB_C32r: case X86::SETB_C32r:
return Expand2AddrUndef(MI, get(X86::SBB32rr)); return Expand2AddrUndef(MIB, get(X86::SBB32rr));
case X86::SETB_C64r: case X86::SETB_C64r:
return Expand2AddrUndef(MI, get(X86::SBB64rr)); return Expand2AddrUndef(MIB, get(X86::SBB64rr));
case X86::V_SET0: case X86::V_SET0:
case X86::FsFLD0SS: case X86::FsFLD0SS:
case X86::FsFLD0SD: case X86::FsFLD0SD:
return Expand2AddrUndef(MI, get(HasAVX ? X86::VXORPSrr : X86::XORPSrr)); return Expand2AddrUndef(MIB, get(HasAVX ? X86::VXORPSrr : X86::XORPSrr));
case X86::AVX_SET0: case X86::AVX_SET0:
assert(HasAVX && "AVX not supported"); assert(HasAVX && "AVX not supported");
return Expand2AddrUndef(MI, get(X86::VXORPSYrr)); return Expand2AddrUndef(MIB, get(X86::VXORPSYrr));
case X86::V_SETALLONES: case X86::V_SETALLONES:
return Expand2AddrUndef(MI, get(HasAVX ? X86::VPCMPEQDrr : X86::PCMPEQDrr)); return Expand2AddrUndef(MIB, get(HasAVX ? X86::VPCMPEQDrr : X86::PCMPEQDrr));
case X86::AVX2_SETALLONES: case X86::AVX2_SETALLONES:
return Expand2AddrUndef(MI, get(X86::VPCMPEQDYrr)); return Expand2AddrUndef(MIB, get(X86::VPCMPEQDYrr));
case X86::TEST8ri_NOREX: case X86::TEST8ri_NOREX:
MI->setDesc(get(X86::TEST8ri)); MI->setDesc(get(X86::TEST8ri));
return true; return true;
@ -3587,9 +3588,10 @@ static MachineInstr *FuseTwoAddrInst(MachineFunction &MF, unsigned Opcode,
MachineInstr *MI, MachineInstr *MI,
const TargetInstrInfo &TII) { const TargetInstrInfo &TII) {
// Create the base instruction with the memory operand as the first part. // Create the base instruction with the memory operand as the first part.
// Omit the implicit operands, something BuildMI can't do.
MachineInstr *NewMI = MF.CreateMachineInstr(TII.get(Opcode), MachineInstr *NewMI = MF.CreateMachineInstr(TII.get(Opcode),
MI->getDebugLoc(), true); MI->getDebugLoc(), true);
MachineInstrBuilder MIB(NewMI); MachineInstrBuilder MIB(MF, NewMI);
unsigned NumAddrOps = MOs.size(); unsigned NumAddrOps = MOs.size();
for (unsigned i = 0; i != NumAddrOps; ++i) for (unsigned i = 0; i != NumAddrOps; ++i)
MIB.addOperand(MOs[i]); MIB.addOperand(MOs[i]);
@ -3613,9 +3615,10 @@ static MachineInstr *FuseInst(MachineFunction &MF,
unsigned Opcode, unsigned OpNo, unsigned Opcode, unsigned OpNo,
const SmallVectorImpl<MachineOperand> &MOs, const SmallVectorImpl<MachineOperand> &MOs,
MachineInstr *MI, const TargetInstrInfo &TII) { MachineInstr *MI, const TargetInstrInfo &TII) {
// Omit the implicit operands, something BuildMI can't do.
MachineInstr *NewMI = MF.CreateMachineInstr(TII.get(Opcode), MachineInstr *NewMI = MF.CreateMachineInstr(TII.get(Opcode),
MI->getDebugLoc(), true); MI->getDebugLoc(), true);
MachineInstrBuilder MIB(NewMI); MachineInstrBuilder MIB(MF, NewMI);
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI->getOperand(i); MachineOperand &MO = MI->getOperand(i);
@ -4155,7 +4158,7 @@ bool X86InstrInfo::unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
// Emit the data processing instruction. // Emit the data processing instruction.
MachineInstr *DataMI = MF.CreateMachineInstr(MCID, MI->getDebugLoc(), true); MachineInstr *DataMI = MF.CreateMachineInstr(MCID, MI->getDebugLoc(), true);
MachineInstrBuilder MIB(DataMI); MachineInstrBuilder MIB(MF, DataMI);
if (FoldedStore) if (FoldedStore)
MIB.addReg(Reg, RegState::Define); MIB.addReg(Reg, RegState::Define);