Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions llvm/include/llvm/CodeGen/LiveRangeEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,10 @@ class LiveRangeEdit : private MachineRegisterInfo::Delegate {
Register create() { return createFrom(getReg()); }

/// anyRematerializable - Return true if any parent values may be
/// rematerializable.
/// This function must be called before any rematerialization is attempted.
/// rematerializable. This function must be called before
/// canRematerializeAt is called..
bool anyRematerializable();

/// checkRematerializable - Manually add VNI to the list of rematerializable
/// values if DefMI may be rematerializable.
bool checkRematerializable(VNInfo *VNI, const MachineInstr *DefMI);

/// Remat - Information needed to rematerialize at a specific location.
struct Remat {
const VNInfo *const ParentVNI; // parent_'s value at the remat location.
Expand Down
13 changes: 2 additions & 11 deletions llvm/lib/CodeGen/LiveRangeEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,6 @@ Register LiveRangeEdit::createFrom(Register OldReg) {
return VReg;
}

bool LiveRangeEdit::checkRematerializable(VNInfo *VNI,
const MachineInstr *DefMI) {
assert(DefMI && "Missing instruction");
ScannedRemattable = true;
if (!TII.isTriviallyReMaterializable(*DefMI))
return false;
Remattable.insert(VNI);
return true;
}

void LiveRangeEdit::scanRemattable() {
for (VNInfo *VNI : getParent().valnos) {
if (VNI->isUnused())
Expand All @@ -90,7 +80,8 @@ void LiveRangeEdit::scanRemattable() {
MachineInstr *DefMI = LIS.getInstructionFromIndex(OrigVNI->def);
if (!DefMI)
continue;
checkRematerializable(OrigVNI, DefMI);
if (TII.isTriviallyReMaterializable(*DefMI))
Remattable.insert(OrigVNI);
}
ScannedRemattable = true;
}
Expand Down
13 changes: 7 additions & 6 deletions llvm/lib/CodeGen/RegisterCoalescer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,9 +1325,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
if (!TII->isAsCheapAsAMove(*DefMI))
return false;

SmallVector<Register, 8> NewRegs;
LiveRangeEdit Edit(&SrcInt, NewRegs, *MF, *LIS, nullptr, this);
if (!Edit.checkRematerializable(ValNo, DefMI))
if (!TII->isTriviallyReMaterializable(*DefMI))
return false;

if (!definesFullReg(*DefMI, SrcReg))
Expand Down Expand Up @@ -1395,15 +1393,18 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
}
}

LiveRangeEdit::Remat RM(ValNo);
RM.OrigMI = DefMI;
if (!Edit.canRematerializeAt(RM, ValNo, CopyIdx))
SmallVector<Register, 8> NewRegs;
LiveRangeEdit Edit(&SrcInt, NewRegs, *MF, *LIS, nullptr, this);
SlotIndex DefIdx = LIS->getInstructionIndex(*DefMI);
if (!Edit.allUsesAvailableAt(DefMI, DefIdx, CopyIdx))
return false;

DebugLoc DL = CopyMI->getDebugLoc();
MachineBasicBlock *MBB = CopyMI->getParent();
MachineBasicBlock::iterator MII =
std::next(MachineBasicBlock::iterator(CopyMI));
LiveRangeEdit::Remat RM(ValNo);
RM.OrigMI = DefMI;
Edit.rematerializeAt(*MBB, MII, DstReg, RM, *TRI, false, SrcIdx, CopyMI);
MachineInstr &NewMI = *std::prev(MII);
NewMI.setDebugLoc(DL);
Expand Down
Loading