CodeGen: Use mop_iterator instead of MIOperands/ConstMIOperands

MIOperands/ConstMIOperands are classes iterating over the MachineOperand
of a MachineInstr, however MachineInstr::mop_iterator does the same
thing.

I assume these two iterators exist to have a uniform interface to
iterate over the operands of a machine instruction bundle and a single
machine instruction. However in practice I find it more confusing to have 2
different iterator classes, so this patch transforms (nearly all) the
code to use mop_iterators.

The only exception being MIOperands::anlayzePhysReg() and
MIOperands::analyzeVirtReg() still needing an equivalent, I leave that
as an exercise for the next patch.

Differential Revision: http://reviews.llvm.org/D9932

This version is slightly modified from the proposed revision in that it
introduces MachineInstr::getOperandNo to avoid the extra counting
variable in the few loops that previously used MIOperands::getOperandNo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238539 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Matthias Braun
2015-05-29 02:56:46 +00:00
parent 7e31fe7e20
commit e67bd6c248
13 changed files with 104 additions and 91 deletions

View File

@@ -331,6 +331,11 @@ public:
operands_begin() + getDesc().getNumDefs(), operands_end()); operands_begin() + getDesc().getNumDefs(), operands_end());
} }
/// Returns the number of the operand iterator \p I points to.
unsigned getOperandNo(const_mop_iterator I) const {
return I - operands_begin();
}
/// Access to memory operands of the instruction /// Access to memory operands of the instruction
mmo_iterator memoperands_begin() const { return MemRefs; } mmo_iterator memoperands_begin() const { return MemRefs; }
mmo_iterator memoperands_end() const { return MemRefs + NumMemRefs; } mmo_iterator memoperands_end() const { return MemRefs + NumMemRefs; }

View File

@@ -226,21 +226,21 @@ bool SSAIfConv::canSpeculateInstrs(MachineBasicBlock *MBB) {
} }
// Check for any dependencies on Head instructions. // Check for any dependencies on Head instructions.
for (MIOperands MO(I); MO.isValid(); ++MO) { for (const MachineOperand MO : I->operands()) {
if (MO->isRegMask()) { if (MO.isRegMask()) {
DEBUG(dbgs() << "Won't speculate regmask: " << *I); DEBUG(dbgs() << "Won't speculate regmask: " << *I);
return false; return false;
} }
if (!MO->isReg()) if (!MO.isReg())
continue; continue;
unsigned Reg = MO->getReg(); unsigned Reg = MO.getReg();
// Remember clobbered regunits. // Remember clobbered regunits.
if (MO->isDef() && TargetRegisterInfo::isPhysicalRegister(Reg)) if (MO.isDef() && TargetRegisterInfo::isPhysicalRegister(Reg))
for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units) for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units)
ClobberedRegUnits.set(*Units); ClobberedRegUnits.set(*Units);
if (!MO->readsReg() || !TargetRegisterInfo::isVirtualRegister(Reg)) if (!MO.readsReg() || !TargetRegisterInfo::isVirtualRegister(Reg))
continue; continue;
MachineInstr *DefMI = MRI->getVRegDef(Reg); MachineInstr *DefMI = MRI->getVRegDef(Reg);
if (!DefMI || DefMI->getParent() != Head) if (!DefMI || DefMI->getParent() != Head)
@@ -284,19 +284,19 @@ bool SSAIfConv::findInsertionPoint() {
} }
// Update live regunits. // Update live regunits.
for (MIOperands MO(I); MO.isValid(); ++MO) { for (const MachineOperand &MO : I->operands()) {
// We're ignoring regmask operands. That is conservatively correct. // We're ignoring regmask operands. That is conservatively correct.
if (!MO->isReg()) if (!MO.isReg())
continue; continue;
unsigned Reg = MO->getReg(); unsigned Reg = MO.getReg();
if (!TargetRegisterInfo::isPhysicalRegister(Reg)) if (!TargetRegisterInfo::isPhysicalRegister(Reg))
continue; continue;
// I clobbers Reg, so it isn't live before I. // I clobbers Reg, so it isn't live before I.
if (MO->isDef()) if (MO.isDef())
for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units) for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units)
LiveRegUnits.erase(*Units); LiveRegUnits.erase(*Units);
// Unless I reads Reg. // Unless I reads Reg.
if (MO->readsReg()) if (MO.readsReg())
Reads.push_back(Reg); Reads.push_back(Reg);
} }
// Anything read by I is live before I. // Anything read by I is live before I.

View File

@@ -223,11 +223,11 @@ void LiveIntervals::computeRegMasks() {
RMB.first = RegMaskSlots.size(); RMB.first = RegMaskSlots.size();
for (MachineBasicBlock::iterator MI = MBB->begin(), ME = MBB->end(); for (MachineBasicBlock::iterator MI = MBB->begin(), ME = MBB->end();
MI != ME; ++MI) MI != ME; ++MI)
for (MIOperands MO(MI); MO.isValid(); ++MO) { for (const MachineOperand &MO : MI->operands()) {
if (!MO->isRegMask()) if (!MO.isRegMask())
continue; continue;
RegMaskSlots.push_back(Indexes->getInstructionIndex(MI).getRegSlot()); RegMaskSlots.push_back(Indexes->getInstructionIndex(MI).getRegSlot());
RegMaskBits.push_back(MO->getRegMask()); RegMaskBits.push_back(MO.getRegMask());
} }
// Compute the number of register mask instructions in this block. // Compute the number of register mask instructions in this block.
RMB.second = RegMaskSlots.size() - RMB.first; RMB.second = RegMaskSlots.size() - RMB.first;
@@ -927,23 +927,23 @@ public:
void updateAllRanges(MachineInstr *MI) { void updateAllRanges(MachineInstr *MI) {
DEBUG(dbgs() << "handleMove " << OldIdx << " -> " << NewIdx << ": " << *MI); DEBUG(dbgs() << "handleMove " << OldIdx << " -> " << NewIdx << ": " << *MI);
bool hasRegMask = false; bool hasRegMask = false;
for (MIOperands MO(MI); MO.isValid(); ++MO) { for (MachineOperand &MO : MI->operands()) {
if (MO->isRegMask()) if (MO.isRegMask())
hasRegMask = true; hasRegMask = true;
if (!MO->isReg()) if (!MO.isReg())
continue; continue;
// Aggressively clear all kill flags. // Aggressively clear all kill flags.
// They are reinserted by VirtRegRewriter. // They are reinserted by VirtRegRewriter.
if (MO->isUse()) if (MO.isUse())
MO->setIsKill(false); MO.setIsKill(false);
unsigned Reg = MO->getReg(); unsigned Reg = MO.getReg();
if (!Reg) if (!Reg)
continue; continue;
if (TargetRegisterInfo::isVirtualRegister(Reg)) { if (TargetRegisterInfo::isVirtualRegister(Reg)) {
LiveInterval &LI = LIS.getInterval(Reg); LiveInterval &LI = LIS.getInterval(Reg);
if (LI.hasSubRanges()) { if (LI.hasSubRanges()) {
unsigned SubReg = MO->getSubReg(); unsigned SubReg = MO.getSubReg();
unsigned LaneMask = TRI.getSubRegIndexLaneMask(SubReg); unsigned LaneMask = TRI.getSubRegIndexLaneMask(SubReg);
for (LiveInterval::SubRange &S : LI.subranges()) { for (LiveInterval::SubRange &S : LI.subranges()) {
if ((S.LaneMask & LaneMask) == 0) if ((S.LaneMask & LaneMask) == 0)

View File

@@ -1092,9 +1092,8 @@ const TargetRegisterClass *MachineInstr::getRegClassConstraintEffectForVReg(
OpndIt.getOperandNo(), Reg, CurRC, TII, TRI); OpndIt.getOperandNo(), Reg, CurRC, TII, TRI);
else else
// Otherwise, just check the current operands. // Otherwise, just check the current operands.
for (ConstMIOperands OpndIt(this); OpndIt.isValid() && CurRC; ++OpndIt) for (unsigned i = 0, e = NumOperands; i < e && CurRC; ++i)
CurRC = getRegClassConstraintEffectForVRegImpl(OpndIt.getOperandNo(), Reg, CurRC = getRegClassConstraintEffectForVRegImpl(i, Reg, CurRC, TII, TRI);
CurRC, TII, TRI);
return CurRC; return CurRC;
} }

View File

@@ -1012,10 +1012,10 @@ bool MachineLICM::HasLoopPHIUse(const MachineInstr *MI) const {
SmallVector<const MachineInstr*, 8> Work(1, MI); SmallVector<const MachineInstr*, 8> Work(1, MI);
do { do {
MI = Work.pop_back_val(); MI = Work.pop_back_val();
for (ConstMIOperands MO(MI); MO.isValid(); ++MO) { for (const MachineOperand &MO : MI->operands()) {
if (!MO->isReg() || !MO->isDef()) if (!MO.isReg() || !MO.isDef())
continue; continue;
unsigned Reg = MO->getReg(); unsigned Reg = MO.getReg();
if (!TargetRegisterInfo::isVirtualRegister(Reg)) if (!TargetRegisterInfo::isVirtualRegister(Reg))
continue; continue;
for (MachineInstr &UseMI : MRI->use_instructions(Reg)) { for (MachineInstr &UseMI : MRI->use_instructions(Reg)) {

View File

@@ -627,10 +627,12 @@ static bool getDataDeps(const MachineInstr *UseMI,
SmallVectorImpl<DataDep> &Deps, SmallVectorImpl<DataDep> &Deps,
const MachineRegisterInfo *MRI) { const MachineRegisterInfo *MRI) {
bool HasPhysRegs = false; bool HasPhysRegs = false;
for (ConstMIOperands MO(UseMI); MO.isValid(); ++MO) { for (MachineInstr::const_mop_iterator I = UseMI->operands_begin(),
if (!MO->isReg()) E = UseMI->operands_end(); I != E; ++I) {
const MachineOperand &MO = *I;
if (!MO.isReg())
continue; continue;
unsigned Reg = MO->getReg(); unsigned Reg = MO.getReg();
if (!Reg) if (!Reg)
continue; continue;
if (TargetRegisterInfo::isPhysicalRegister(Reg)) { if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
@@ -638,8 +640,8 @@ static bool getDataDeps(const MachineInstr *UseMI,
continue; continue;
} }
// Collect virtual register reads. // Collect virtual register reads.
if (MO->readsReg()) if (MO.readsReg())
Deps.push_back(DataDep(MRI, Reg, MO.getOperandNo())); Deps.push_back(DataDep(MRI, Reg, UseMI->getOperandNo(I)));
} }
return HasPhysRegs; return HasPhysRegs;
} }
@@ -690,28 +692,30 @@ static void updatePhysDepsDownwards(const MachineInstr *UseMI,
SmallVector<unsigned, 8> Kills; SmallVector<unsigned, 8> Kills;
SmallVector<unsigned, 8> LiveDefOps; SmallVector<unsigned, 8> LiveDefOps;
for (ConstMIOperands MO(UseMI); MO.isValid(); ++MO) { for (MachineInstr::const_mop_iterator MI = UseMI->operands_begin(),
if (!MO->isReg()) ME = UseMI->operands_end(); MI != ME; ++MI) {
const MachineOperand &MO = *MI;
if (!MO.isReg())
continue; continue;
unsigned Reg = MO->getReg(); unsigned Reg = MO.getReg();
if (!TargetRegisterInfo::isPhysicalRegister(Reg)) if (!TargetRegisterInfo::isPhysicalRegister(Reg))
continue; continue;
// Track live defs and kills for updating RegUnits. // Track live defs and kills for updating RegUnits.
if (MO->isDef()) { if (MO.isDef()) {
if (MO->isDead()) if (MO.isDead())
Kills.push_back(Reg); Kills.push_back(Reg);
else else
LiveDefOps.push_back(MO.getOperandNo()); LiveDefOps.push_back(UseMI->getOperandNo(MI));
} else if (MO->isKill()) } else if (MO.isKill())
Kills.push_back(Reg); Kills.push_back(Reg);
// Identify dependencies. // Identify dependencies.
if (!MO->readsReg()) if (!MO.readsReg())
continue; continue;
for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units) { for (MCRegUnitIterator Units(Reg, TRI); Units.isValid(); ++Units) {
SparseSet<LiveRegUnit>::iterator I = RegUnits.find(*Units); SparseSet<LiveRegUnit>::iterator I = RegUnits.find(*Units);
if (I == RegUnits.end()) if (I == RegUnits.end())
continue; continue;
Deps.push_back(DataDep(I->MI, I->Op, MO.getOperandNo())); Deps.push_back(DataDep(I->MI, I->Op, UseMI->getOperandNo(MI)));
break; break;
} }
} }
@@ -864,15 +868,18 @@ static unsigned updatePhysDepsUpwards(const MachineInstr *MI, unsigned Height,
const TargetInstrInfo *TII, const TargetInstrInfo *TII,
const TargetRegisterInfo *TRI) { const TargetRegisterInfo *TRI) {
SmallVector<unsigned, 8> ReadOps; SmallVector<unsigned, 8> ReadOps;
for (ConstMIOperands MO(MI); MO.isValid(); ++MO) {
if (!MO->isReg()) for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(),
MOE = MI->operands_end(); MOI != MOE; ++MOI) {
const MachineOperand &MO = *MOI;
if (!MO.isReg())
continue; continue;
unsigned Reg = MO->getReg(); unsigned Reg = MO.getReg();
if (!TargetRegisterInfo::isPhysicalRegister(Reg)) if (!TargetRegisterInfo::isPhysicalRegister(Reg))
continue; continue;
if (MO->readsReg()) if (MO.readsReg())
ReadOps.push_back(MO.getOperandNo()); ReadOps.push_back(MI->getOperandNo(MOI));
if (!MO->isDef()) if (!MO.isDef())
continue; continue;
// This is a def of Reg. Remove corresponding entries from RegUnits, and // This is a def of Reg. Remove corresponding entries from RegUnits, and
// update MI Height to consider the physreg dependencies. // update MI Height to consider the physreg dependencies.
@@ -885,7 +892,7 @@ static unsigned updatePhysDepsUpwards(const MachineInstr *MI, unsigned Height,
// We may not know the UseMI of this dependency, if it came from the // We may not know the UseMI of this dependency, if it came from the
// live-in list. SchedModel can handle a NULL UseMI. // live-in list. SchedModel can handle a NULL UseMI.
DepHeight += SchedModel DepHeight += SchedModel
.computeOperandLatency(MI, MO.getOperandNo(), I->MI, I->Op); .computeOperandLatency(MI, MI->getOperandNo(MOI), I->MI, I->Op);
} }
Height = std::max(Height, DepHeight); Height = std::max(Height, DepHeight);
// This regunit is dead above MI. // This regunit is dead above MI.

View File

@@ -68,8 +68,8 @@ bool ProcessImplicitDefs::canTurnIntoImplicitDef(MachineInstr *MI) {
!MI->isRegSequence() && !MI->isRegSequence() &&
!MI->isPHI()) !MI->isPHI())
return false; return false;
for (MIOperands MO(MI); MO.isValid(); ++MO) for (const MachineOperand &MO : MI->operands())
if (MO->isReg() && MO->isUse() && MO->readsReg()) if (MO.isReg() && MO.isUse() && MO.readsReg())
return false; return false;
return true; return true;
} }
@@ -100,17 +100,17 @@ void ProcessImplicitDefs::processImplicitDef(MachineInstr *MI) {
MachineBasicBlock::instr_iterator UserE = MI->getParent()->instr_end(); MachineBasicBlock::instr_iterator UserE = MI->getParent()->instr_end();
bool Found = false; bool Found = false;
for (++UserMI; UserMI != UserE; ++UserMI) { for (++UserMI; UserMI != UserE; ++UserMI) {
for (MIOperands MO(UserMI); MO.isValid(); ++MO) { for (MachineOperand &MO : UserMI->operands()) {
if (!MO->isReg()) if (!MO.isReg())
continue; continue;
unsigned UserReg = MO->getReg(); unsigned UserReg = MO.getReg();
if (!TargetRegisterInfo::isPhysicalRegister(UserReg) || if (!TargetRegisterInfo::isPhysicalRegister(UserReg) ||
!TRI->regsOverlap(Reg, UserReg)) !TRI->regsOverlap(Reg, UserReg))
continue; continue;
// UserMI uses or redefines Reg. Set <undef> flags on all uses. // UserMI uses or redefines Reg. Set <undef> flags on all uses.
Found = true; Found = true;
if (MO->isUse()) if (MO.isUse())
MO->setIsUndef(); MO.setIsUndef();
} }
if (Found) if (Found)
break; break;

View File

@@ -1834,12 +1834,12 @@ public:
unsigned JoinVals::computeWriteLanes(const MachineInstr *DefMI, bool &Redef) unsigned JoinVals::computeWriteLanes(const MachineInstr *DefMI, bool &Redef)
const { const {
unsigned L = 0; unsigned L = 0;
for (ConstMIOperands MO(DefMI); MO.isValid(); ++MO) { for (const MachineOperand &MO : DefMI->operands()) {
if (!MO->isReg() || MO->getReg() != Reg || !MO->isDef()) if (!MO.isReg() || MO.getReg() != Reg || !MO.isDef())
continue; continue;
L |= TRI->getSubRegIndexLaneMask( L |= TRI->getSubRegIndexLaneMask(
TRI->composeSubRegIndices(SubIdx, MO->getSubReg())); TRI->composeSubRegIndices(SubIdx, MO.getSubReg()));
if (MO->readsReg()) if (MO.readsReg())
Redef = true; Redef = true;
} }
return L; return L;
@@ -2224,13 +2224,13 @@ bool JoinVals::usesLanes(const MachineInstr *MI, unsigned Reg, unsigned SubIdx,
unsigned Lanes) const { unsigned Lanes) const {
if (MI->isDebugValue()) if (MI->isDebugValue())
return false; return false;
for (ConstMIOperands MO(MI); MO.isValid(); ++MO) { for (const MachineOperand &MO : MI->operands()) {
if (!MO->isReg() || MO->isDef() || MO->getReg() != Reg) if (!MO.isReg() || MO.isDef() || MO.getReg() != Reg)
continue; continue;
if (!MO->readsReg()) if (!MO.readsReg())
continue; continue;
if (Lanes & TRI->getSubRegIndexLaneMask( if (Lanes & TRI->getSubRegIndexLaneMask(
TRI->composeSubRegIndices(SubIdx, MO->getSubReg()))) TRI->composeSubRegIndices(SubIdx, MO.getSubReg())))
return true; return true;
} }
return false; return false;
@@ -2339,11 +2339,11 @@ void JoinVals::pruneValues(JoinVals &Other,
// Remove <def,read-undef> flags. This def is now a partial redef. // Remove <def,read-undef> flags. This def is now a partial redef.
// Also remove <def,dead> flags since the joined live range will // Also remove <def,dead> flags since the joined live range will
// continue past this instruction. // continue past this instruction.
for (MIOperands MO(Indexes->getInstructionFromIndex(Def)); for (MachineOperand &MO :
MO.isValid(); ++MO) { Indexes->getInstructionFromIndex(Def)->operands()) {
if (MO->isReg() && MO->isDef() && MO->getReg() == Reg) { if (MO.isReg() && MO.isDef() && MO.getReg() == Reg) {
MO->setIsUndef(EraseImpDef); MO.setIsUndef(EraseImpDef);
MO->setIsDead(false); MO.setIsDead(false);
} }
} }
} }

View File

@@ -1106,25 +1106,25 @@ static void toggleBundleKillFlag(MachineInstr *MI, unsigned Reg,
MachineBasicBlock::instr_iterator Begin = MI; MachineBasicBlock::instr_iterator Begin = MI;
MachineBasicBlock::instr_iterator End = getBundleEnd(MI); MachineBasicBlock::instr_iterator End = getBundleEnd(MI);
while (Begin != End) { while (Begin != End) {
for (MIOperands MO(--End); MO.isValid(); ++MO) { for (MachineOperand &MO : (--End)->operands()) {
if (!MO->isReg() || MO->isDef() || Reg != MO->getReg()) if (!MO.isReg() || MO.isDef() || Reg != MO.getReg())
continue; continue;
// DEBUG_VALUE nodes do not contribute to code generation and should // DEBUG_VALUE nodes do not contribute to code generation and should
// always be ignored. Failure to do so may result in trying to modify // always be ignored. Failure to do so may result in trying to modify
// KILL flags on DEBUG_VALUE nodes, which is distressing. // KILL flags on DEBUG_VALUE nodes, which is distressing.
if (MO->isDebug()) if (MO.isDebug())
continue; continue;
// If the register has the internal flag then it could be killing an // If the register has the internal flag then it could be killing an
// internal def of the register. In this case, just skip. We only want // internal def of the register. In this case, just skip. We only want
// to toggle the flag on operands visible outside the bundle. // to toggle the flag on operands visible outside the bundle.
if (MO->isInternalRead()) if (MO.isInternalRead())
continue; continue;
if (MO->isKill() == NewKillState) if (MO.isKill() == NewKillState)
continue; continue;
MO->setIsKill(NewKillState); MO.setIsKill(NewKillState);
if (NewKillState) if (NewKillState)
return; return;
} }

View File

@@ -762,10 +762,10 @@ void ARMLoadStoreOpt::MergeOpsUpdate(MachineBasicBlock &MBB,
Regs.push_back(std::make_pair(Reg, isKill)); Regs.push_back(std::make_pair(Reg, isKill));
// Collect any implicit defs of super-registers. They must be preserved. // Collect any implicit defs of super-registers. They must be preserved.
for (MIOperands MO(memOps[i].MBBI); MO.isValid(); ++MO) { for (const MachineOperand &MO : memOps[i].MBBI->operands()) {
if (!MO->isReg() || !MO->isDef() || !MO->isImplicit() || MO->isDead()) if (!MO.isReg() || !MO.isDef() || !MO.isImplicit() || MO.isDead())
continue; continue;
unsigned DefReg = MO->getReg(); unsigned DefReg = MO.getReg();
if (std::find(ImpDefs.begin(), ImpDefs.end(), DefReg) == ImpDefs.end()) if (std::find(ImpDefs.begin(), ImpDefs.end(), DefReg) == ImpDefs.end())
ImpDefs.push_back(DefReg); ImpDefs.push_back(DefReg);

View File

@@ -94,12 +94,12 @@ static void TrackDefUses(MachineInstr *MI,
/// conservatively remove more kill flags than are necessary, but removing them /// conservatively remove more kill flags than are necessary, but removing them
/// is safer than incorrect kill flags remaining on instructions. /// is safer than incorrect kill flags remaining on instructions.
static void ClearKillFlags(MachineInstr *MI, SmallSet<unsigned, 4> &Uses) { static void ClearKillFlags(MachineInstr *MI, SmallSet<unsigned, 4> &Uses) {
for (MIOperands MO(MI); MO.isValid(); ++MO) { for (MachineOperand &MO : MI->operands()) {
if (!MO->isReg() || MO->isDef() || !MO->isKill()) if (!MO.isReg() || MO.isDef() || !MO.isKill())
continue; continue;
if (!Uses.count(MO->getReg())) if (!Uses.count(MO.getReg()))
continue; continue;
MO->setIsKill(false); MO.setIsKill(false);
} }
} }

View File

@@ -201,17 +201,17 @@ namespace {
break; break;
} }
// Check individual operands. // Check individual operands.
for (ConstMIOperands Mo(MI); Mo.isValid(); ++Mo) { for (const MachineOperand &MO : MI->operands()) {
// While the presence of a frame index does not prove that a stack // While the presence of a frame index does not prove that a stack
// frame will be required, all frame indexes should be within alloc- // frame will be required, all frame indexes should be within alloc-
// frame/deallocframe. Otherwise, the code that translates a frame // frame/deallocframe. Otherwise, the code that translates a frame
// index into an offset would have to be aware of the placement of // index into an offset would have to be aware of the placement of
// the frame creation/destruction instructions. // the frame creation/destruction instructions.
if (Mo->isFI()) if (MO.isFI())
return true; return true;
if (!Mo->isReg()) if (!MO.isReg())
continue; continue;
unsigned R = Mo->getReg(); unsigned R = MO.getReg();
// Virtual registers will need scavenging, which then may require // Virtual registers will need scavenging, which then may require
// a stack slot. // a stack slot.
if (TargetRegisterInfo::isVirtualRegister(R)) if (TargetRegisterInfo::isVirtualRegister(R))

View File

@@ -3541,16 +3541,18 @@ bool X86FastISel::tryToFoldLoadIntoMI(MachineInstr *MI, unsigned OpNo,
// to just look at OpNo + the offset to the index reg. We actually need to // to just look at OpNo + the offset to the index reg. We actually need to
// scan the instruction to find the index reg and see if its the correct reg // scan the instruction to find the index reg and see if its the correct reg
// class. // class.
for (MIOperands MO(Result); MO.isValid(); ++MO) { unsigned OperandNo = 0;
if (!MO->isReg() || MO->isDef() || MO->getReg() != AM.IndexReg) for (MachineInstr::mop_iterator I = Result->operands_begin(),
E = Result->operands_end(); I != E; ++I, ++OperandNo) {
MachineOperand &MO = *I;
if (!MO.isReg() || MO.isDef() || MO.getReg() != AM.IndexReg)
continue; continue;
// Found the index reg, now try to rewrite it. // Found the index reg, now try to rewrite it.
unsigned OpNo = MO.getOperandNo();
unsigned IndexReg = constrainOperandRegClass(Result->getDesc(), unsigned IndexReg = constrainOperandRegClass(Result->getDesc(),
MO->getReg(), OpNo); MO.getReg(), OperandNo);
if (IndexReg == MO->getReg()) if (IndexReg == MO.getReg())
continue; continue;
MO->setReg(IndexReg); MO.setReg(IndexReg);
} }
Result->addMemOperand(*FuncInfo.MF, createMachineMemOperandFor(LI)); Result->addMemOperand(*FuncInfo.MF, createMachineMemOperandFor(LI));