2012-02-17 17:35:10 +00:00
|
|
|
//===-- LiveRangeEdit.cpp - Basic tools for editing a register live range -===//
|
2010-10-14 23:49:52 +00: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.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-03-29 17:47:02 +00:00
|
|
|
#define DEBUG_TYPE "regalloc"
|
2010-10-14 23:49:52 +00:00
|
|
|
#include "VirtRegMap.h"
|
2011-03-08 22:46:11 +00:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
2011-05-05 17:22:53 +00:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2011-03-29 21:20:19 +00:00
|
|
|
#include "llvm/CodeGen/CalcSpillWeights.h"
|
2010-10-14 23:49:52 +00:00
|
|
|
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
|
2012-04-02 22:44:18 +00:00
|
|
|
#include "llvm/CodeGen/LiveRangeEdit.h"
|
2010-10-14 23:49:52 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2010-10-20 22:00:51 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2011-03-08 22:46:11 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2010-10-14 23:49:52 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2011-05-05 17:22:53 +00: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 02:50:00 +00:00
|
|
|
void LiveRangeEdit::Delegate::anchor() { }
|
|
|
|
|
2012-04-02 22:22:53 +00:00
|
|
|
LiveInterval &LiveRangeEdit::createFrom(unsigned OldReg) {
|
2011-03-17 20:37:07 +00:00
|
|
|
unsigned VReg = MRI.createVirtualRegister(MRI.getRegClass(OldReg));
|
2012-04-03 00:28:46 +00:00
|
|
|
if (VRM) {
|
|
|
|
VRM->grow();
|
|
|
|
VRM->setIsSplitFromReg(VReg, VRM->getOriginal(OldReg));
|
|
|
|
}
|
2011-03-17 20:37:07 +00:00
|
|
|
LiveInterval &LI = LIS.getOrCreateInterval(VReg);
|
2012-05-18 22:10:15 +00:00
|
|
|
NewRegs.push_back(&LI);
|
2011-03-17 20:37:07 +00:00
|
|
|
return LI;
|
2010-10-14 23:49:52 +00:00
|
|
|
}
|
|
|
|
|
2011-04-20 22:14:20 +00:00
|
|
|
bool LiveRangeEdit::checkRematerializable(VNInfo *VNI,
|
2011-03-29 03:12:02 +00:00
|
|
|
const MachineInstr *DefMI,
|
|
|
|
AliasAnalysis *aa) {
|
|
|
|
assert(DefMI && "Missing instruction");
|
2012-05-18 22:10:15 +00:00
|
|
|
ScannedRemattable = true;
|
2012-04-02 22:22:53 +00:00
|
|
|
if (!TII.isTriviallyReMaterializable(DefMI, aa))
|
2011-04-20 22:14:20 +00:00
|
|
|
return false;
|
2012-05-18 22:10:15 +00:00
|
|
|
Remattable.insert(VNI);
|
2011-04-20 22:14:20 +00:00
|
|
|
return true;
|
2011-03-29 03:12:02 +00:00
|
|
|
}
|
|
|
|
|
2012-04-02 22:22:53 +00:00
|
|
|
void LiveRangeEdit::scanRemattable(AliasAnalysis *aa) {
|
2012-05-19 05:25:46 +00:00
|
|
|
for (LiveInterval::vni_iterator I = getParent().vni_begin(),
|
|
|
|
E = getParent().vni_end(); I != E; ++I) {
|
2010-10-20 22:00:51 +00:00
|
|
|
VNInfo *VNI = *I;
|
|
|
|
if (VNI->isUnused())
|
|
|
|
continue;
|
2012-04-02 22:22:53 +00:00
|
|
|
MachineInstr *DefMI = LIS.getInstructionFromIndex(VNI->def);
|
2010-10-20 22:00:51 +00:00
|
|
|
if (!DefMI)
|
|
|
|
continue;
|
2012-04-02 22:22:53 +00:00
|
|
|
checkRematerializable(VNI, DefMI, aa);
|
2010-10-20 22:00:51 +00:00
|
|
|
}
|
2012-05-18 22:10:15 +00:00
|
|
|
ScannedRemattable = true;
|
2010-10-20 22:00:51 +00:00
|
|
|
}
|
|
|
|
|
2012-04-02 22:22:53 +00:00
|
|
|
bool LiveRangeEdit::anyRematerializable(AliasAnalysis *aa) {
|
2012-05-18 22:10:15 +00:00
|
|
|
if (!ScannedRemattable)
|
2012-04-02 22:22:53 +00:00
|
|
|
scanRemattable(aa);
|
2012-05-18 22:10:15 +00:00
|
|
|
return !Remattable.empty();
|
2010-10-20 22:00:51 +00:00
|
|
|
}
|
|
|
|
|
2010-10-14 23:49:52 +00: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,
|
2012-04-02 22:22:53 +00:00
|
|
|
SlotIndex UseIdx) {
|
2011-11-13 20:45:27 +00:00
|
|
|
OrigIdx = OrigIdx.getRegSlot(true);
|
|
|
|
UseIdx = UseIdx.getRegSlot(true);
|
2010-10-14 23:49:52 +00:00
|
|
|
for (unsigned i = 0, e = OrigMI->getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = OrigMI->getOperand(i);
|
2012-06-22 17:31:01 +00:00
|
|
|
if (!MO.isReg() || !MO.getReg() || !MO.readsReg())
|
2010-10-14 23:49:52 +00:00
|
|
|
continue;
|
|
|
|
|
2012-06-22 17:31:01 +00:00
|
|
|
// We can't remat physreg uses, unless it is a constant.
|
|
|
|
if (TargetRegisterInfo::isPhysicalRegister(MO.getReg())) {
|
2012-09-27 16:34:19 +00:00
|
|
|
if (MRI.isConstantPhysReg(MO.getReg(), *OrigMI->getParent()->getParent()))
|
2012-06-22 17:31:01 +00:00
|
|
|
continue;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-02 22:22:53 +00:00
|
|
|
LiveInterval &li = LIS.getInterval(MO.getReg());
|
2010-10-14 23:49:52 +00:00
|
|
|
const VNInfo *OVNI = li.getVNInfoAt(OrigIdx);
|
|
|
|
if (!OVNI)
|
|
|
|
continue;
|
2012-10-16 22:51:58 +00: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-14 23:49:52 +00:00
|
|
|
if (OVNI != li.getVNInfoAt(UseIdx))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-10 01:05:12 +00:00
|
|
|
bool LiveRangeEdit::canRematerializeAt(Remat &RM,
|
|
|
|
SlotIndex UseIdx,
|
2012-04-02 22:22:53 +00:00
|
|
|
bool cheapAsAMove) {
|
2012-05-18 22:10:15 +00:00
|
|
|
assert(ScannedRemattable && "Call anyRematerializable first");
|
2010-10-20 22:00:51 +00:00
|
|
|
|
|
|
|
// Use scanRemattable info.
|
2012-05-18 22:10:15 +00:00
|
|
|
if (!Remattable.count(RM.ParentVNI))
|
2010-11-10 01:05:12 +00:00
|
|
|
return false;
|
2010-10-20 22:00:51 +00:00
|
|
|
|
2011-03-29 03:12:02 +00:00
|
|
|
// No defining instruction provided.
|
|
|
|
SlotIndex DefIdx;
|
|
|
|
if (RM.OrigMI)
|
2012-04-02 22:22:53 +00:00
|
|
|
DefIdx = LIS.getInstructionIndex(RM.OrigMI);
|
2011-03-29 03:12:02 +00:00
|
|
|
else {
|
|
|
|
DefIdx = RM.ParentVNI->def;
|
2012-04-02 22:22:53 +00:00
|
|
|
RM.OrigMI = LIS.getInstructionFromIndex(DefIdx);
|
2011-03-29 03:12:02 +00:00
|
|
|
assert(RM.OrigMI && "No defining instruction for remattable value");
|
|
|
|
}
|
2010-10-20 22:00:51 +00:00
|
|
|
|
|
|
|
// If only cheap remats were requested, bail out early.
|
2011-12-07 07:15:52 +00:00
|
|
|
if (cheapAsAMove && !RM.OrigMI->isAsCheapAsAMove())
|
2010-11-10 01:05:12 +00:00
|
|
|
return false;
|
2010-10-20 22:00:51 +00:00
|
|
|
|
|
|
|
// Verify that all used registers are available with the same values.
|
2012-04-02 22:22:53 +00:00
|
|
|
if (!allUsesAvailableAt(RM.OrigMI, DefIdx, UseIdx))
|
2010-11-10 01:05:12 +00:00
|
|
|
return false;
|
2010-10-20 22:00:51 +00:00
|
|
|
|
2010-11-10 01:05:12 +00:00
|
|
|
return true;
|
2010-10-20 22:00:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SlotIndex LiveRangeEdit::rematerializeAt(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned DestReg,
|
|
|
|
const Remat &RM,
|
2011-05-02 05:29:58 +00:00
|
|
|
const TargetRegisterInfo &tri,
|
|
|
|
bool Late) {
|
2010-10-20 22:00:51 +00:00
|
|
|
assert(RM.OrigMI && "Invalid remat");
|
2012-04-02 22:22:53 +00:00
|
|
|
TII.reMaterialize(MBB, MI, DestReg, 0, RM.OrigMI, tri);
|
2012-05-18 22:10:15 +00:00
|
|
|
Rematted.insert(RM.ParentVNI);
|
2012-04-02 22:22:53 +00:00
|
|
|
return LIS.getSlotIndexes()->insertMachineInstrInMaps(--MI, Late)
|
2011-11-13 20:45:27 +00:00
|
|
|
.getRegSlot();
|
2010-10-20 22:00:51 +00:00
|
|
|
}
|
|
|
|
|
2012-04-02 22:22:53 +00:00
|
|
|
void LiveRangeEdit::eraseVirtReg(unsigned Reg) {
|
2012-05-18 22:10:15 +00:00
|
|
|
if (TheDelegate && TheDelegate->LRE_CanEraseVirtReg(Reg))
|
2011-03-13 01:23:11 +00:00
|
|
|
LIS.removeInterval(Reg);
|
|
|
|
}
|
|
|
|
|
2011-04-05 20:20:26 +00:00
|
|
|
bool LiveRangeEdit::foldAsLoad(LiveInterval *LI,
|
2012-04-02 22:22:53 +00:00
|
|
|
SmallVectorImpl<MachineInstr*> &Dead) {
|
2011-04-05 20:20:26 +00:00
|
|
|
MachineInstr *DefMI = 0, *UseMI = 0;
|
|
|
|
|
|
|
|
// Check that there is a single def and a single use.
|
|
|
|
for (MachineRegisterInfo::reg_nodbg_iterator I = MRI.reg_nodbg_begin(LI->reg),
|
|
|
|
E = MRI.reg_nodbg_end(); I != E; ++I) {
|
|
|
|
MachineOperand &MO = I.getOperand();
|
|
|
|
MachineInstr *MI = MO.getParent();
|
|
|
|
if (MO.isDef()) {
|
|
|
|
if (DefMI && DefMI != MI)
|
|
|
|
return false;
|
2011-12-07 07:15:52 +00:00
|
|
|
if (!MI->canFoldAsLoad())
|
2011-04-05 20:20:26 +00: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-20 21:29:31 +00: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;
|
|
|
|
if (!DefMI->isSafeToMove(&TII, 0, SawStore))
|
|
|
|
return false;
|
|
|
|
|
2011-04-05 20:20:26 +00: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();
|
|
|
|
DefMI->addRegisterDead(LI->reg, 0);
|
|
|
|
Dead.push_back(DefMI);
|
2011-05-05 17:22:53 +00:00
|
|
|
++NumDCEFoldedLoads;
|
2011-04-05 20:20:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-08 22:46:11 +00:00
|
|
|
void LiveRangeEdit::eliminateDeadDefs(SmallVectorImpl<MachineInstr*> &Dead,
|
2011-12-12 22:16:27 +00:00
|
|
|
ArrayRef<unsigned> RegsBeingSpilled) {
|
2011-03-08 22:46:11 +00:00
|
|
|
SetVector<LiveInterval*,
|
|
|
|
SmallVector<LiveInterval*, 8>,
|
|
|
|
SmallPtrSet<LiveInterval*, 8> > ToShrink;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
// Erase all dead defs.
|
|
|
|
while (!Dead.empty()) {
|
|
|
|
MachineInstr *MI = Dead.pop_back_val();
|
|
|
|
assert(MI->allDefsAreDead() && "Def isn't really dead");
|
2011-11-13 20:45:27 +00:00
|
|
|
SlotIndex Idx = LIS.getInstructionIndex(MI).getRegSlot();
|
2011-03-08 22:46:11 +00:00
|
|
|
|
|
|
|
// Never delete inline asm.
|
2011-03-16 22:56:08 +00:00
|
|
|
if (MI->isInlineAsm()) {
|
|
|
|
DEBUG(dbgs() << "Won't delete: " << Idx << '\t' << *MI);
|
2011-03-08 22:46:11 +00:00
|
|
|
continue;
|
2011-03-16 22:56:08 +00:00
|
|
|
}
|
2011-03-08 22:46:11 +00:00
|
|
|
|
|
|
|
// Use the same criteria as DeadMachineInstructionElim.
|
|
|
|
bool SawStore = false;
|
2011-03-16 22:56:08 +00:00
|
|
|
if (!MI->isSafeToMove(&TII, 0, SawStore)) {
|
|
|
|
DEBUG(dbgs() << "Can't delete: " << Idx << '\t' << *MI);
|
2011-03-08 22:46:11 +00:00
|
|
|
continue;
|
2011-03-16 22:56:08 +00:00
|
|
|
}
|
2011-03-08 22:46:11 +00:00
|
|
|
|
|
|
|
DEBUG(dbgs() << "Deleting dead def " << Idx << '\t' << *MI);
|
|
|
|
|
2012-05-22 14:52:12 +00:00
|
|
|
// Collect virtual registers to be erased after MI is gone.
|
|
|
|
SmallVector<unsigned, 8> RegsToErase;
|
2012-08-02 16:36:47 +00:00
|
|
|
bool ReadsPhysRegs = false;
|
2012-05-22 14:52:12 +00:00
|
|
|
|
2011-03-08 22:46:11 +00: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();
|
2012-08-02 16:36:47 +00:00
|
|
|
if (!TargetRegisterInfo::isVirtualRegister(Reg)) {
|
|
|
|
// Check if MI reads any unreserved physregs.
|
2012-10-15 22:14:34 +00:00
|
|
|
if (Reg && MOI->readsReg() && !MRI.isReserved(Reg))
|
2012-08-02 16:36:47 +00:00
|
|
|
ReadsPhysRegs = true;
|
2011-03-08 22:46:11 +00:00
|
|
|
continue;
|
2012-08-02 16:36:47 +00:00
|
|
|
}
|
2011-03-08 22:46:11 +00:00
|
|
|
LiveInterval &LI = LIS.getInterval(Reg);
|
2011-03-16 22:56:13 +00:00
|
|
|
|
2011-04-11 15:00:39 +00:00
|
|
|
// 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.
|
|
|
|
if (MI->readsVirtualRegister(Reg) &&
|
|
|
|
(MI->isCopy() || MOI->isDef() || MRI.hasOneNonDBGUse(Reg) ||
|
|
|
|
LI.killedAt(Idx)))
|
2011-03-08 22:46:11 +00:00
|
|
|
ToShrink.insert(&LI);
|
2011-03-16 22:56:13 +00:00
|
|
|
|
|
|
|
// Remove defined value.
|
|
|
|
if (MOI->isDef()) {
|
|
|
|
if (VNInfo *VNI = LI.getVNInfoAt(Idx)) {
|
2012-05-18 22:10:15 +00:00
|
|
|
if (TheDelegate)
|
|
|
|
TheDelegate->LRE_WillShrinkVirtReg(LI.reg);
|
2011-03-16 22:56:13 +00:00
|
|
|
LI.removeValNo(VNI);
|
2012-05-22 14:52:12 +00:00
|
|
|
if (LI.empty())
|
|
|
|
RegsToErase.push_back(Reg);
|
2011-03-16 22:56:13 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-08 22:46:11 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 16:36:47 +00: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;
|
|
|
|
}
|
2012-05-22 14:52:12 +00:00
|
|
|
|
|
|
|
// 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-08 22:46:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ToShrink.empty())
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Shrink just one live interval. Then delete new dead defs.
|
2011-03-16 22:56:16 +00:00
|
|
|
LiveInterval *LI = ToShrink.back();
|
2011-03-08 22:46:11 +00:00
|
|
|
ToShrink.pop_back();
|
2012-04-02 22:22:53 +00:00
|
|
|
if (foldAsLoad(LI, Dead))
|
2011-04-05 20:20:26 +00:00
|
|
|
continue;
|
2012-05-18 22:10:15 +00:00
|
|
|
if (TheDelegate)
|
|
|
|
TheDelegate->LRE_WillShrinkVirtReg(LI->reg);
|
2011-03-17 20:37:07 +00:00
|
|
|
if (!LIS.shrinkToUses(LI, &Dead))
|
|
|
|
continue;
|
2011-12-12 22:16:27 +00: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) {
|
|
|
|
if (LI->reg == RegsBeingSpilled[i]) {
|
|
|
|
BeingSpilled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BeingSpilled) continue;
|
2011-03-17 20:37:07 +00:00
|
|
|
|
|
|
|
// LI may have been separated, create new intervals.
|
|
|
|
LI->RenumberValues(LIS);
|
|
|
|
ConnectedVNInfoEqClasses ConEQ(LIS);
|
|
|
|
unsigned NumComp = ConEQ.Classify(LI);
|
|
|
|
if (NumComp <= 1)
|
|
|
|
continue;
|
2011-05-05 17:22:53 +00:00
|
|
|
++NumFracRanges;
|
2012-04-03 00:28:46 +00:00
|
|
|
bool IsOriginal = VRM && VRM->getOriginal(LI->reg) == LI->reg;
|
2011-03-17 20:37:07 +00:00
|
|
|
DEBUG(dbgs() << NumComp << " components: " << *LI << '\n');
|
|
|
|
SmallVector<LiveInterval*, 8> Dups(1, LI);
|
2011-03-30 02:52:39 +00:00
|
|
|
for (unsigned i = 1; i != NumComp; ++i) {
|
2012-04-02 22:22:53 +00:00
|
|
|
Dups.push_back(&createFrom(LI->reg));
|
2011-07-05 15:38:41 +00: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.
|
|
|
|
if (IsOriginal)
|
2012-04-02 22:22:53 +00:00
|
|
|
VRM->setIsSplitFromReg(Dups.back()->reg, 0);
|
2012-05-18 22:10:15 +00:00
|
|
|
if (TheDelegate)
|
|
|
|
TheDelegate->LRE_DidCloneVirtReg(Dups.back()->reg, LI->reg);
|
2011-03-30 02:52:39 +00:00
|
|
|
}
|
2011-04-11 15:00:39 +00:00
|
|
|
ConEQ.Distribute(&Dups[0], MRI);
|
2012-05-19 23:34:59 +00:00
|
|
|
DEBUG({
|
|
|
|
for (unsigned i = 0; i != NumComp; ++i)
|
|
|
|
dbgs() << '\t' << *Dups[i] << '\n';
|
|
|
|
});
|
2011-03-08 22:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-29 21:20:19 +00:00
|
|
|
void LiveRangeEdit::calculateRegClassAndHint(MachineFunction &MF,
|
|
|
|
const MachineLoopInfo &Loops) {
|
|
|
|
VirtRegAuxInfo VRAI(MF, LIS, Loops);
|
|
|
|
for (iterator I = begin(), E = end(); I != E; ++I) {
|
|
|
|
LiveInterval &LI = **I;
|
2011-08-09 16:46:27 +00:00
|
|
|
if (MRI.recomputeRegClass(LI.reg, MF.getTarget()))
|
|
|
|
DEBUG(dbgs() << "Inflated " << PrintReg(LI.reg) << " to "
|
|
|
|
<< MRI.getRegClass(LI.reg)->getName() << '\n');
|
2011-03-29 21:20:19 +00:00
|
|
|
VRAI.CalculateWeightAndHint(LI);
|
|
|
|
}
|
|
|
|
}
|