Skip to content

Commit 084f463

Browse files
preamesgithub-actions[bot]
authored andcommitted
Automerge: [CodeGen] Untangle RegisterCoalescer from LRE's ScannedRemattable flag [nfc[ (#159839)
LiveRangeEdit's rematerialization checking logic is used in two quite different ways. For SplitKit and InlineSpiller, we're analyzing all defs associated with a live interval, doing that analysis up front, and then using the result a bit later. The RegisterCoalescer, we're analysing exactly one ValNo at a time, and using the legality result immediately. LRE had a checkRematerializable which existed basically to adapt the later into the former usage model. Instead, this change bypasses the ScannedRemat and Remattable structures, and directly queries the underlying routines. This is easy to read, and makes it more clear as to which uses actually need the deferred analysis. (A following change may try to unwind that too, but it's not strictly NFC.)
2 parents b99b6b4 + 57b673b commit 084f463

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

llvm/include/llvm/CodeGen/LiveRangeEdit.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,10 @@ class LiveRangeEdit : private MachineRegisterInfo::Delegate {
176176
Register create() { return createFrom(getReg()); }
177177

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

183-
/// checkRematerializable - Manually add VNI to the list of rematerializable
184-
/// values if DefMI may be rematerializable.
185-
bool checkRematerializable(VNInfo *VNI, const MachineInstr *DefMI);
186-
187183
/// Remat - Information needed to rematerialize at a specific location.
188184
struct Remat {
189185
const VNInfo *const ParentVNI; // parent_'s value at the remat location.

llvm/lib/CodeGen/LiveRangeEdit.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ Register LiveRangeEdit::createFrom(Register OldReg) {
6868
return VReg;
6969
}
7070

71-
bool LiveRangeEdit::checkRematerializable(VNInfo *VNI,
72-
const MachineInstr *DefMI) {
73-
assert(DefMI && "Missing instruction");
74-
ScannedRemattable = true;
75-
if (!TII.isTriviallyReMaterializable(*DefMI))
76-
return false;
77-
Remattable.insert(VNI);
78-
return true;
79-
}
80-
8171
void LiveRangeEdit::scanRemattable() {
8272
for (VNInfo *VNI : getParent().valnos) {
8373
if (VNI->isUnused())
@@ -90,7 +80,8 @@ void LiveRangeEdit::scanRemattable() {
9080
MachineInstr *DefMI = LIS.getInstructionFromIndex(OrigVNI->def);
9181
if (!DefMI)
9282
continue;
93-
checkRematerializable(OrigVNI, DefMI);
83+
if (TII.isTriviallyReMaterializable(*DefMI))
84+
Remattable.insert(OrigVNI);
9485
}
9586
ScannedRemattable = true;
9687
}

llvm/lib/CodeGen/RegisterCoalescer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,9 +1325,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
13251325
if (!TII->isAsCheapAsAMove(*DefMI))
13261326
return false;
13271327

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

13331331
if (!definesFullReg(*DefMI, SrcReg))
@@ -1395,15 +1393,18 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
13951393
}
13961394
}
13971395

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

14031402
DebugLoc DL = CopyMI->getDebugLoc();
14041403
MachineBasicBlock *MBB = CopyMI->getParent();
14051404
MachineBasicBlock::iterator MII =
14061405
std::next(MachineBasicBlock::iterator(CopyMI));
1406+
LiveRangeEdit::Remat RM(ValNo);
1407+
RM.OrigMI = DefMI;
14071408
Edit.rematerializeAt(*MBB, MII, DstReg, RM, *TRI, false, SrcIdx, CopyMI);
14081409
MachineInstr &NewMI = *std::prev(MII);
14091410
NewMI.setDebugLoc(DL);

0 commit comments

Comments
 (0)