Change MRegisterInfo::foldMemoryOperand to return the folded
instruction to make the API more flexible.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12386 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp
index d6cc357..7f6afc5 100644
--- a/lib/CodeGen/LiveIntervalAnalysis.cpp
+++ b/lib/CodeGen/LiveIntervalAnalysis.cpp
@@ -209,13 +209,15 @@
for (unsigned i = 0; i < mi->getNumOperands(); ++i) {
MachineOperand& mop = mi->getOperand(i);
if (mop.isRegister() && mop.getReg() == li.reg) {
- MachineInstr* old = mi;
- if (mri_->foldMemoryOperand(mi, i, slot)) {
- lv_->instructionChanged(old, mi);
- vrm.virtFolded(li.reg, old, mi);
- mi2iMap_.erase(old);
- i2miMap_[index/InstrSlots::NUM] = mi;
- mi2iMap_[mi] = index;
+ if (MachineInstr* fmi =
+ mri_->foldMemoryOperand(mi, i, slot)) {
+ lv_->instructionChanged(mi, fmi);
+ vrm.virtFolded(li.reg, mi, fmi);
+ mi2iMap_.erase(mi);
+ i2miMap_[index/InstrSlots::NUM] = fmi;
+ mi2iMap_[fmi] = index;
+ MachineBasicBlock& mbb = *mi->getParent();
+ mi = mbb.insert(mbb.erase(mi), fmi);
++numFolded;
goto for_operand;
}
diff --git a/lib/CodeGen/RegAllocLocal.cpp b/lib/CodeGen/RegAllocLocal.cpp
index bd1e090..0b5fdc5 100644
--- a/lib/CodeGen/RegAllocLocal.cpp
+++ b/lib/CodeGen/RegAllocLocal.cpp
@@ -487,13 +487,12 @@
assignVirtToPhysReg(VirtReg, PhysReg);
} else { // No registers available.
// If we can fold this spill into this instruction, do so now.
- MachineBasicBlock::iterator MII = MI;
- if (RegInfo->foldMemoryOperand(MII, OpNum, FrameIndex)) {
+ if (MachineInstr* FMI = RegInfo->foldMemoryOperand(MI, OpNum, FrameIndex)){
++NumFolded;
// Since we changed the address of MI, make sure to update live variables
// to know that the new instruction has the properties of the old one.
- LV->instructionChanged(MI, MII);
- return MII;
+ LV->instructionChanged(MI, FMI);
+ return MBB.insert(MBB.erase(MI), FMI);
}
// It looks like we can't fold this virtual register load into this