2012-02-18 01:35:10 +08:00
|
|
|
//===-- LiveRangeEdit.cpp - Basic tools for editing a register live range -===//
|
2010-10-15 07:49:52 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LiveRangeEdit class represents changes done to a virtual register when it
|
|
|
|
// is spilled or split.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/LiveRangeEdit.h"
|
2011-05-06 01:22:53 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2011-03-30 05:20:19 +08:00
|
|
|
#include "llvm/CodeGen/CalcSpillWeights.h"
|
2010-10-15 07:49:52 +08:00
|
|
|
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-11-29 03:13:06 +08:00
|
|
|
#include "llvm/CodeGen/VirtRegMap.h"
|
2011-03-09 06:46:11 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2010-10-15 07:49:52 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:02:50 +08:00
|
|
|
#define DEBUG_TYPE "regalloc"
|
|
|
|
|
2011-05-06 01:22:53 +08:00
|
|
|
STATISTIC(NumDCEDeleted, "Number of instructions deleted by DCE");
|
|
|
|
STATISTIC(NumDCEFoldedLoads, "Number of single use loads folded after DCE");
|
|
|
|
STATISTIC(NumFracRanges, "Number of live ranges fractured by DCE");
|
|
|
|
|
2011-12-20 10:50:00 +08:00
|
|
|
void LiveRangeEdit::Delegate::anchor() { }
|
|
|
|
|
2013-08-15 07:50:16 +08:00
|
|
|
LiveInterval &LiveRangeEdit::createEmptyIntervalFrom(unsigned OldReg) {
|
2011-03-18 04:37:07 +08:00
|
|
|
unsigned VReg = MRI.createVirtualRegister(MRI.getRegClass(OldReg));
|
2012-04-03 08:28:46 +08:00
|
|
|
if (VRM) {
|
|
|
|
VRM->setIsSplitFromReg(VReg, VRM->getOriginal(OldReg));
|
|
|
|
}
|
2013-08-15 07:50:16 +08:00
|
|
|
LiveInterval &LI = LIS.createEmptyInterval(VReg);
|
2011-03-18 04:37:07 +08:00
|
|
|
return LI;
|
2010-10-15 07:49:52 +08:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:50:16 +08:00
|
|
|
unsigned LiveRangeEdit::createFrom(unsigned OldReg) {
|
|
|
|
unsigned VReg = MRI.createVirtualRegister(MRI.getRegClass(OldReg));
|
|
|
|
if (VRM) {
|
|
|
|
VRM->setIsSplitFromReg(VReg, VRM->getOriginal(OldReg));
|
|
|
|
}
|
|
|
|
return VReg;
|
|
|
|
}
|
|
|
|
|
2011-04-21 06:14:20 +08:00
|
|
|
bool LiveRangeEdit::checkRematerializable(VNInfo *VNI,
|
2011-03-29 11:12:02 +08:00
|
|
|
const MachineInstr *DefMI,
|
|
|
|
AliasAnalysis *aa) {
|
|
|
|
assert(DefMI && "Missing instruction");
|
2012-05-19 06:10:15 +08:00
|
|
|
ScannedRemattable = true;
|
2012-04-03 06:22:53 +08:00
|
|
|
if (!TII.isTriviallyReMaterializable(DefMI, aa))
|
2011-04-21 06:14:20 +08:00
|
|
|
return false;
|
2012-05-19 06:10:15 +08:00
|
|
|
Remattable.insert(VNI);
|
2011-04-21 06:14:20 +08:00
|
|
|
return true;
|
2011-03-29 11:12:02 +08:00
|
|
|
}
|
|
|
|
|
2012-04-03 06:22:53 +08:00
|
|
|
void LiveRangeEdit::scanRemattable(AliasAnalysis *aa) {
|
2014-12-11 07:07:54 +08:00
|
|
|
for (VNInfo *VNI : getParent().valnos) {
|
2010-10-21 06:00:51 +08:00
|
|
|
if (VNI->isUnused())
|
|
|
|
continue;
|
2012-04-03 06:22:53 +08:00
|
|
|
MachineInstr *DefMI = LIS.getInstructionFromIndex(VNI->def);
|
2010-10-21 06:00:51 +08:00
|
|
|
if (!DefMI)
|
|
|
|
continue;
|
2012-04-03 06:22:53 +08:00
|
|
|
checkRematerializable(VNI, DefMI, aa);
|
2010-10-21 06:00:51 +08:00
|
|
|
}
|
2012-05-19 06:10:15 +08:00
|
|
|
ScannedRemattable = true;
|
2010-10-21 06:00:51 +08:00
|
|
|
}
|
|
|
|
|
2012-04-03 06:22:53 +08:00
|
|
|
bool LiveRangeEdit::anyRematerializable(AliasAnalysis *aa) {
|
2012-05-19 06:10:15 +08:00
|
|
|
if (!ScannedRemattable)
|
2012-04-03 06:22:53 +08:00
|
|
|
scanRemattable(aa);
|
2012-05-19 06:10:15 +08:00
|
|
|
return !Remattable.empty();
|
2010-10-21 06:00:51 +08:00
|
|
|
}
|
|
|
|
|
2010-10-15 07:49:52 +08:00
|
|
|
/// allUsesAvailableAt - Return true if all registers used by OrigMI at
|
|
|
|
/// OrigIdx are also available with the same value at UseIdx.
|
|
|
|
bool LiveRangeEdit::allUsesAvailableAt(const MachineInstr *OrigMI,
|
|
|
|
SlotIndex OrigIdx,
|
2013-03-19 07:40:46 +08:00
|
|
|
SlotIndex UseIdx) const {
|
2011-11-14 04:45:27 +08:00
|
|
|
OrigIdx = OrigIdx.getRegSlot(true);
|
|
|
|
UseIdx = UseIdx.getRegSlot(true);
|
2010-10-15 07:49:52 +08:00
|
|
|
for (unsigned i = 0, e = OrigMI->getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = OrigMI->getOperand(i);
|
2012-06-23 01:31:01 +08:00
|
|
|
if (!MO.isReg() || !MO.getReg() || !MO.readsReg())
|
2010-10-15 07:49:52 +08:00
|
|
|
continue;
|
|
|
|
|
2012-06-23 01:31:01 +08:00
|
|
|
// We can't remat physreg uses, unless it is a constant.
|
|
|
|
if (TargetRegisterInfo::isPhysicalRegister(MO.getReg())) {
|
2012-09-28 00:34:19 +08:00
|
|
|
if (MRI.isConstantPhysReg(MO.getReg(), *OrigMI->getParent()->getParent()))
|
2012-06-23 01:31:01 +08:00
|
|
|
continue;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-03 06:22:53 +08:00
|
|
|
LiveInterval &li = LIS.getInterval(MO.getReg());
|
2010-10-15 07:49:52 +08:00
|
|
|
const VNInfo *OVNI = li.getVNInfoAt(OrigIdx);
|
|
|
|
if (!OVNI)
|
|
|
|
continue;
|
2012-10-17 06:51:58 +08:00
|
|
|
|
|
|
|
// Don't allow rematerialization immediately after the original def.
|
|
|
|
// It would be incorrect if OrigMI redefines the register.
|
|
|
|
// See PR14098.
|
|
|
|
if (SlotIndex::isSameInstr(OrigIdx, UseIdx))
|
|
|
|
return false;
|
|
|
|
|
2010-10-15 07:49:52 +08:00
|
|
|
if (OVNI != li.getVNInfoAt(UseIdx))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-10 09:05:12 +08:00
|
|
|
bool LiveRangeEdit::canRematerializeAt(Remat &RM,
|
|
|
|
SlotIndex UseIdx,
|
2012-04-03 06:22:53 +08:00
|
|
|
bool cheapAsAMove) {
|
2012-05-19 06:10:15 +08:00
|
|
|
assert(ScannedRemattable && "Call anyRematerializable first");
|
2010-10-21 06:00:51 +08:00
|
|
|
|
|
|
|
// Use scanRemattable info.
|
2012-05-19 06:10:15 +08:00
|
|
|
if (!Remattable.count(RM.ParentVNI))
|
2010-11-10 09:05:12 +08:00
|
|
|
return false;
|
2010-10-21 06:00:51 +08:00
|
|
|
|
2011-03-29 11:12:02 +08:00
|
|
|
// No defining instruction provided.
|
|
|
|
SlotIndex DefIdx;
|
|
|
|
if (RM.OrigMI)
|
2012-04-03 06:22:53 +08:00
|
|
|
DefIdx = LIS.getInstructionIndex(RM.OrigMI);
|
2011-03-29 11:12:02 +08:00
|
|
|
else {
|
|
|
|
DefIdx = RM.ParentVNI->def;
|
2012-04-03 06:22:53 +08:00
|
|
|
RM.OrigMI = LIS.getInstructionFromIndex(DefIdx);
|
2011-03-29 11:12:02 +08:00
|
|
|
assert(RM.OrigMI && "No defining instruction for remattable value");
|
|
|
|
}
|
2010-10-21 06:00:51 +08:00
|
|
|
|
|
|
|
// If only cheap remats were requested, bail out early.
|
2014-07-29 09:55:19 +08:00
|
|
|
if (cheapAsAMove && !TII.isAsCheapAsAMove(RM.OrigMI))
|
2010-11-10 09:05:12 +08:00
|
|
|
return false;
|
2010-10-21 06:00:51 +08:00
|
|
|
|
|
|
|
// Verify that all used registers are available with the same values.
|
2012-04-03 06:22:53 +08:00
|
|
|
if (!allUsesAvailableAt(RM.OrigMI, DefIdx, UseIdx))
|
2010-11-10 09:05:12 +08:00
|
|
|
return false;
|
2010-10-21 06:00:51 +08:00
|
|
|
|
2010-11-10 09:05:12 +08:00
|
|
|
return true;
|
2010-10-21 06:00:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SlotIndex LiveRangeEdit::rematerializeAt(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned DestReg,
|
|
|
|
const Remat &RM,
|
2011-05-02 13:29:58 +08:00
|
|
|
const TargetRegisterInfo &tri,
|
|
|
|
bool Late) {
|
2010-10-21 06:00:51 +08:00
|
|
|
assert(RM.OrigMI && "Invalid remat");
|
2012-04-03 06:22:53 +08:00
|
|
|
TII.reMaterialize(MBB, MI, DestReg, 0, RM.OrigMI, tri);
|
2012-05-19 06:10:15 +08:00
|
|
|
Rematted.insert(RM.ParentVNI);
|
2012-04-03 06:22:53 +08:00
|
|
|
return LIS.getSlotIndexes()->insertMachineInstrInMaps(--MI, Late)
|
2011-11-14 04:45:27 +08:00
|
|
|
.getRegSlot();
|
2010-10-21 06:00:51 +08:00
|
|
|
}
|
|
|
|
|
2012-04-03 06:22:53 +08:00
|
|
|
void LiveRangeEdit::eraseVirtReg(unsigned Reg) {
|
2012-05-19 06:10:15 +08:00
|
|
|
if (TheDelegate && TheDelegate->LRE_CanEraseVirtReg(Reg))
|
2011-03-13 09:23:11 +08:00
|
|
|
LIS.removeInterval(Reg);
|
|
|
|
}
|
|
|
|
|
2011-04-06 04:20:26 +08:00
|
|
|
bool LiveRangeEdit::foldAsLoad(LiveInterval *LI,
|
2012-04-03 06:22:53 +08:00
|
|
|
SmallVectorImpl<MachineInstr*> &Dead) {
|
2014-04-14 08:51:57 +08:00
|
|
|
MachineInstr *DefMI = nullptr, *UseMI = nullptr;
|
2011-04-06 04:20:26 +08:00
|
|
|
|
|
|
|
// Check that there is a single def and a single use.
|
2014-03-18 03:36:09 +08:00
|
|
|
for (MachineOperand &MO : MRI.reg_nodbg_operands(LI->reg)) {
|
|
|
|
MachineInstr *MI = MO.getParent();
|
2011-04-06 04:20:26 +08:00
|
|
|
if (MO.isDef()) {
|
|
|
|
if (DefMI && DefMI != MI)
|
|
|
|
return false;
|
2011-12-07 15:15:52 +08:00
|
|
|
if (!MI->canFoldAsLoad())
|
2011-04-06 04:20:26 +08:00
|
|
|
return false;
|
|
|
|
DefMI = MI;
|
|
|
|
} else if (!MO.isUndef()) {
|
|
|
|
if (UseMI && UseMI != MI)
|
|
|
|
return false;
|
|
|
|
// FIXME: Targets don't know how to fold subreg uses.
|
|
|
|
if (MO.getSubReg())
|
|
|
|
return false;
|
|
|
|
UseMI = MI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!DefMI || !UseMI)
|
|
|
|
return false;
|
|
|
|
|
2012-07-21 05:29:31 +08:00
|
|
|
// Since we're moving the DefMI load, make sure we're not extending any live
|
|
|
|
// ranges.
|
|
|
|
if (!allUsesAvailableAt(DefMI,
|
|
|
|
LIS.getInstructionIndex(DefMI),
|
|
|
|
LIS.getInstructionIndex(UseMI)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// We also need to make sure it is safe to move the load.
|
|
|
|
// Assume there are stores between DefMI and UseMI.
|
|
|
|
bool SawStore = true;
|
2015-05-20 05:22:20 +08:00
|
|
|
if (!DefMI->isSafeToMove(nullptr, SawStore))
|
2012-07-21 05:29:31 +08:00
|
|
|
return false;
|
|
|
|
|
2011-04-06 04:20:26 +08:00
|
|
|
DEBUG(dbgs() << "Try to fold single def: " << *DefMI
|
|
|
|
<< " into single use: " << *UseMI);
|
|
|
|
|
|
|
|
SmallVector<unsigned, 8> Ops;
|
|
|
|
if (UseMI->readsWritesVirtualRegister(LI->reg, &Ops).second)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MachineInstr *FoldMI = TII.foldMemoryOperand(UseMI, Ops, DefMI);
|
|
|
|
if (!FoldMI)
|
|
|
|
return false;
|
|
|
|
DEBUG(dbgs() << " folded: " << *FoldMI);
|
|
|
|
LIS.ReplaceMachineInstrInMaps(UseMI, FoldMI);
|
|
|
|
UseMI->eraseFromParent();
|
2014-04-14 08:51:57 +08:00
|
|
|
DefMI->addRegisterDead(LI->reg, nullptr);
|
2011-04-06 04:20:26 +08:00
|
|
|
Dead.push_back(DefMI);
|
2011-05-06 01:22:53 +08:00
|
|
|
++NumDCEFoldedLoads;
|
2011-04-06 04:20:26 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-02 05:26:26 +08:00
|
|
|
bool LiveRangeEdit::useIsKill(const LiveInterval &LI,
|
|
|
|
const MachineOperand &MO) const {
|
|
|
|
const MachineInstr *MI = MO.getParent();
|
|
|
|
SlotIndex Idx = LIS.getInstructionIndex(MI).getRegSlot();
|
|
|
|
if (LI.Query(Idx).isKill())
|
|
|
|
return true;
|
|
|
|
const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
|
|
|
|
unsigned SubReg = MO.getSubReg();
|
|
|
|
unsigned LaneMask = TRI.getSubRegIndexLaneMask(SubReg);
|
|
|
|
for (const LiveInterval::SubRange &S : LI.subranges()) {
|
|
|
|
if ((S.LaneMask & LaneMask) != 0 && S.Query(Idx).isKill())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-22 02:33:17 +08:00
|
|
|
/// Find all live intervals that need to shrink, then remove the instruction.
|
|
|
|
void LiveRangeEdit::eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink) {
|
|
|
|
assert(MI->allDefsAreDead() && "Def isn't really dead");
|
|
|
|
SlotIndex Idx = LIS.getInstructionIndex(MI).getRegSlot();
|
2011-03-09 06:46:11 +08:00
|
|
|
|
2013-06-22 08:33:48 +08:00
|
|
|
// Never delete a bundled instruction.
|
|
|
|
if (MI->isBundled()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-06-22 02:33:17 +08:00
|
|
|
// Never delete inline asm.
|
|
|
|
if (MI->isInlineAsm()) {
|
|
|
|
DEBUG(dbgs() << "Won't delete: " << Idx << '\t' << *MI);
|
|
|
|
return;
|
|
|
|
}
|
2011-03-09 06:46:11 +08:00
|
|
|
|
2013-06-22 02:33:17 +08:00
|
|
|
// Use the same criteria as DeadMachineInstructionElim.
|
|
|
|
bool SawStore = false;
|
2015-05-20 05:22:20 +08:00
|
|
|
if (!MI->isSafeToMove(nullptr, SawStore)) {
|
2013-06-22 02:33:17 +08:00
|
|
|
DEBUG(dbgs() << "Can't delete: " << Idx << '\t' << *MI);
|
|
|
|
return;
|
|
|
|
}
|
2011-03-09 06:46:11 +08:00
|
|
|
|
2013-06-22 02:33:17 +08:00
|
|
|
DEBUG(dbgs() << "Deleting dead def " << Idx << '\t' << *MI);
|
|
|
|
|
|
|
|
// Collect virtual registers to be erased after MI is gone.
|
|
|
|
SmallVector<unsigned, 8> RegsToErase;
|
|
|
|
bool ReadsPhysRegs = false;
|
2011-03-09 06:46:11 +08:00
|
|
|
|
2013-06-22 02:33:17 +08:00
|
|
|
// Check for live intervals that may shrink
|
|
|
|
for (MachineInstr::mop_iterator MOI = MI->operands_begin(),
|
|
|
|
MOE = MI->operands_end(); MOI != MOE; ++MOI) {
|
|
|
|
if (!MOI->isReg())
|
|
|
|
continue;
|
|
|
|
unsigned Reg = MOI->getReg();
|
|
|
|
if (!TargetRegisterInfo::isVirtualRegister(Reg)) {
|
|
|
|
// Check if MI reads any unreserved physregs.
|
|
|
|
if (Reg && MOI->readsReg() && !MRI.isReserved(Reg))
|
|
|
|
ReadsPhysRegs = true;
|
2015-01-22 02:50:21 +08:00
|
|
|
else if (MOI->isDef())
|
|
|
|
LIS.removePhysRegDefAt(Reg, Idx);
|
2013-06-22 02:33:17 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
LiveInterval &LI = LIS.getInterval(Reg);
|
|
|
|
|
|
|
|
// Shrink read registers, unless it is likely to be expensive and
|
|
|
|
// unlikely to change anything. We typically don't want to shrink the
|
|
|
|
// PIC base register that has lots of uses everywhere.
|
|
|
|
// Always shrink COPY uses that probably come from live range splitting.
|
2015-06-02 05:26:26 +08:00
|
|
|
if ((MI->readsVirtualRegister(Reg) && (MI->isCopy() || MOI->isDef())) ||
|
|
|
|
(MOI->readsReg() && (MRI.hasOneNonDBGUse(Reg) || useIsKill(LI, *MOI))))
|
2013-06-22 02:33:17 +08:00
|
|
|
ToShrink.insert(&LI);
|
|
|
|
|
|
|
|
// Remove defined value.
|
|
|
|
if (MOI->isDef()) {
|
2015-01-22 03:02:30 +08:00
|
|
|
if (TheDelegate && LI.getVNInfoAt(Idx) != nullptr)
|
|
|
|
TheDelegate->LRE_WillShrinkVirtReg(LI.reg);
|
|
|
|
LIS.removeVRegDefAt(LI, Idx);
|
|
|
|
if (LI.empty())
|
|
|
|
RegsToErase.push_back(Reg);
|
2013-06-22 02:33:17 +08:00
|
|
|
}
|
|
|
|
}
|
2012-05-22 22:52:12 +08:00
|
|
|
|
2013-06-22 02:33:17 +08:00
|
|
|
// Currently, we don't support DCE of physreg live ranges. If MI reads
|
|
|
|
// any unreserved physregs, don't erase the instruction, but turn it into
|
|
|
|
// a KILL instead. This way, the physreg live ranges don't end up
|
|
|
|
// dangling.
|
|
|
|
// FIXME: It would be better to have something like shrinkToUses() for
|
|
|
|
// physregs. That could potentially enable more DCE and it would free up
|
|
|
|
// the physreg. It would not happen often, though.
|
|
|
|
if (ReadsPhysRegs) {
|
|
|
|
MI->setDesc(TII.get(TargetOpcode::KILL));
|
|
|
|
// Remove all operands that aren't physregs.
|
|
|
|
for (unsigned i = MI->getNumOperands(); i; --i) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(i-1);
|
|
|
|
if (MO.isReg() && TargetRegisterInfo::isPhysicalRegister(MO.getReg()))
|
|
|
|
continue;
|
|
|
|
MI->RemoveOperand(i-1);
|
|
|
|
}
|
|
|
|
DEBUG(dbgs() << "Converted physregs to:\t" << *MI);
|
|
|
|
} else {
|
|
|
|
if (TheDelegate)
|
|
|
|
TheDelegate->LRE_WillEraseInstruction(MI);
|
|
|
|
LIS.RemoveMachineInstrFromMaps(MI);
|
|
|
|
MI->eraseFromParent();
|
|
|
|
++NumDCEDeleted;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Erase any virtregs that are now empty and unused. There may be <undef>
|
|
|
|
// uses around. Keep the empty live range in that case.
|
|
|
|
for (unsigned i = 0, e = RegsToErase.size(); i != e; ++i) {
|
|
|
|
unsigned Reg = RegsToErase[i];
|
|
|
|
if (LIS.hasInterval(Reg) && MRI.reg_nodbg_empty(Reg)) {
|
|
|
|
ToShrink.remove(&LIS.getInterval(Reg));
|
|
|
|
eraseVirtReg(Reg);
|
2011-03-09 06:46:11 +08:00
|
|
|
}
|
2013-06-22 02:33:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LiveRangeEdit::eliminateDeadDefs(SmallVectorImpl<MachineInstr*> &Dead,
|
|
|
|
ArrayRef<unsigned> RegsBeingSpilled) {
|
|
|
|
ToShrinkSet ToShrink;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
// Erase all dead defs.
|
|
|
|
while (!Dead.empty())
|
|
|
|
eliminateDeadDef(Dead.pop_back_val(), ToShrink);
|
2011-03-09 06:46:11 +08:00
|
|
|
|
|
|
|
if (ToShrink.empty())
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Shrink just one live interval. Then delete new dead defs.
|
2011-03-17 06:56:16 +08:00
|
|
|
LiveInterval *LI = ToShrink.back();
|
2011-03-09 06:46:11 +08:00
|
|
|
ToShrink.pop_back();
|
2012-04-03 06:22:53 +08:00
|
|
|
if (foldAsLoad(LI, Dead))
|
2011-04-06 04:20:26 +08:00
|
|
|
continue;
|
2015-09-22 11:44:41 +08:00
|
|
|
unsigned VReg = LI->reg;
|
2012-05-19 06:10:15 +08:00
|
|
|
if (TheDelegate)
|
2015-09-22 11:44:41 +08:00
|
|
|
TheDelegate->LRE_WillShrinkVirtReg(VReg);
|
2011-03-18 04:37:07 +08:00
|
|
|
if (!LIS.shrinkToUses(LI, &Dead))
|
|
|
|
continue;
|
2013-06-22 02:33:14 +08:00
|
|
|
|
2011-12-13 06:16:27 +08:00
|
|
|
// Don't create new intervals for a register being spilled.
|
|
|
|
// The new intervals would have to be spilled anyway so its not worth it.
|
|
|
|
// Also they currently aren't spilled so creating them and not spilling
|
|
|
|
// them results in incorrect code.
|
|
|
|
bool BeingSpilled = false;
|
|
|
|
for (unsigned i = 0, e = RegsBeingSpilled.size(); i != e; ++i) {
|
2015-09-22 11:44:41 +08:00
|
|
|
if (VReg == RegsBeingSpilled[i]) {
|
2011-12-13 06:16:27 +08:00
|
|
|
BeingSpilled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-06-22 02:33:14 +08:00
|
|
|
|
2011-12-13 06:16:27 +08:00
|
|
|
if (BeingSpilled) continue;
|
2011-03-18 04:37:07 +08:00
|
|
|
|
|
|
|
// LI may have been separated, create new intervals.
|
2013-08-15 01:28:52 +08:00
|
|
|
LI->RenumberValues();
|
2015-09-22 11:44:41 +08:00
|
|
|
SmallVector<LiveInterval*, 8> SplitLIs;
|
|
|
|
LIS.splitSeparateComponents(*LI, SplitLIs);
|
|
|
|
if (!SplitLIs.empty())
|
|
|
|
++NumFracRanges;
|
|
|
|
|
|
|
|
unsigned Original = VRM ? VRM->getOriginal(VReg) : 0;
|
|
|
|
for (const LiveInterval *SplitLI : SplitLIs) {
|
2011-07-05 23:38:41 +08:00
|
|
|
// If LI is an original interval that hasn't been split yet, make the new
|
|
|
|
// intervals their own originals instead of referring to LI. The original
|
|
|
|
// interval must contain all the split products, and LI doesn't.
|
2015-09-22 11:44:41 +08:00
|
|
|
if (Original != VReg && Original != 0)
|
|
|
|
VRM->setIsSplitFromReg(SplitLI->reg, Original);
|
2012-05-19 06:10:15 +08:00
|
|
|
if (TheDelegate)
|
2015-09-22 11:44:41 +08:00
|
|
|
TheDelegate->LRE_DidCloneVirtReg(SplitLI->reg, VReg);
|
2011-03-30 10:52:39 +08:00
|
|
|
}
|
2011-03-09 06:46:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 07:50:09 +08:00
|
|
|
// Keep track of new virtual registers created via
|
|
|
|
// MachineRegisterInfo::createVirtualRegister.
|
|
|
|
void
|
|
|
|
LiveRangeEdit::MRI_NoteNewVirtualRegister(unsigned VReg)
|
|
|
|
{
|
|
|
|
if (VRM)
|
|
|
|
VRM->grow();
|
|
|
|
|
|
|
|
NewRegs.push_back(VReg);
|
|
|
|
}
|
|
|
|
|
2013-06-18 03:00:36 +08:00
|
|
|
void
|
|
|
|
LiveRangeEdit::calculateRegClassAndHint(MachineFunction &MF,
|
|
|
|
const MachineLoopInfo &Loops,
|
|
|
|
const MachineBlockFrequencyInfo &MBFI) {
|
2015-08-10 19:59:44 +08:00
|
|
|
VirtRegAuxInfo VRAI(MF, LIS, VRM, Loops, MBFI);
|
2013-08-15 07:50:04 +08:00
|
|
|
for (unsigned I = 0, Size = size(); I < Size; ++I) {
|
|
|
|
LiveInterval &LI = LIS.getInterval(get(I));
|
2015-01-27 09:15:16 +08:00
|
|
|
if (MRI.recomputeRegClass(LI.reg))
|
2014-11-17 13:50:14 +08:00
|
|
|
DEBUG({
|
|
|
|
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
|
|
|
|
dbgs() << "Inflated " << PrintReg(LI.reg) << " to "
|
2014-11-17 13:58:26 +08:00
|
|
|
<< TRI->getRegClassName(MRI.getRegClass(LI.reg)) << '\n';
|
2014-11-17 13:50:14 +08:00
|
|
|
});
|
2013-11-12 03:04:45 +08:00
|
|
|
VRAI.calculateSpillWeightAndHint(LI);
|
2011-03-30 05:20:19 +08:00
|
|
|
}
|
|
|
|
}
|