Skip to content

Commit 07a1925

Browse files
committed
Revert "Refactor recomputeLiveIns to operate on whole CFG (#79498)"
This reverts commit 59bf605. Introduces a major compile-time regression.
1 parent 6f97e6b commit 07a1925

30 files changed

+1698
-1996
lines changed

llvm/include/llvm/CodeGen/LivePhysRegs.h

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
#include "llvm/ADT/SparseSet.h"
3333
#include "llvm/CodeGen/MachineBasicBlock.h"
34-
#include "llvm/CodeGen/MachineFunction.h"
3534
#include "llvm/CodeGen/TargetRegisterInfo.h"
3635
#include "llvm/MC/MCRegister.h"
3736
#include "llvm/MC/MCRegisterInfo.h"
@@ -194,31 +193,11 @@ void addLiveIns(MachineBasicBlock &MBB, const LivePhysRegs &LiveRegs);
194193
void computeAndAddLiveIns(LivePhysRegs &LiveRegs,
195194
MachineBasicBlock &MBB);
196195

197-
/// Function to update the live-in's for a basic block and return whether any
198-
/// changes were made.
199-
static inline bool updateBlockLiveInfo(MachineBasicBlock &MBB) {
196+
/// Convenience function for recomputing live-in's for \p MBB.
197+
static inline void recomputeLiveIns(MachineBasicBlock &MBB) {
200198
LivePhysRegs LPR;
201-
auto oldLiveIns = MBB.getLiveIns();
202-
203199
MBB.clearLiveIns();
204200
computeAndAddLiveIns(LPR, MBB);
205-
MBB.sortUniqueLiveIns();
206-
207-
auto newLiveIns = MBB.getLiveIns();
208-
return oldLiveIns != newLiveIns;
209-
}
210-
211-
/// Convenience function for recomputing live-in's for the entire CFG until
212-
/// convergence is reached.
213-
static inline void recomputeLiveIns(MachineFunction &MF) {
214-
bool anyChanged;
215-
do {
216-
anyChanged = false;
217-
for (auto MFI = MF.rbegin(), MFE = MF.rend(); MFI != MFE; ++MFI) {
218-
MachineBasicBlock &MBB = *MFI;
219-
anyChanged |= updateBlockLiveInfo(MBB);
220-
}
221-
} while (anyChanged);
222201
}
223202

224203
} // end namespace llvm

llvm/include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ class MachineBasicBlock
111111

112112
RegisterMaskPair(MCPhysReg PhysReg, LaneBitmask LaneMask)
113113
: PhysReg(PhysReg), LaneMask(LaneMask) {}
114-
115-
bool operator==(const RegisterMaskPair &other) const {
116-
return PhysReg == other.PhysReg && LaneMask == other.LaneMask;
117-
}
118114
};
119115

120116
private:
@@ -477,8 +473,6 @@ class MachineBasicBlock
477473
/// Remove entry from the livein set and return iterator to the next.
478474
livein_iterator removeLiveIn(livein_iterator I);
479475

480-
std::vector<RegisterMaskPair> getLiveIns() const { return LiveIns; }
481-
482476
class liveout_iterator {
483477
public:
484478
using iterator_category = std::input_iterator_tag;

llvm/lib/CodeGen/BranchFolding.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,8 @@ bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
20482048
FBB->erase(FBB->begin(), FIB);
20492049

20502050
if (UpdateLiveIns) {
2051-
recomputeLiveIns(*MBB->getParent());
2051+
recomputeLiveIns(*TBB);
2052+
recomputeLiveIns(*FBB);
20522053
}
20532054

20542055
++NumHoist;

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4339,7 +4339,8 @@ AArch64FrameLowering::inlineStackProbeLoopExactMultiple(
43394339
ExitMBB->transferSuccessorsAndUpdatePHIs(&MBB);
43404340
MBB.addSuccessor(LoopMBB);
43414341
// Update liveins.
4342-
recomputeLiveIns(MF);
4342+
recomputeLiveIns(*LoopMBB);
4343+
recomputeLiveIns(*ExitMBB);
43434344

43444345
return ExitMBB->begin();
43454346
}

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9597,7 +9597,9 @@ AArch64InstrInfo::probedStackAlloc(MachineBasicBlock::iterator MBBI,
95979597

95989598
// Update liveins.
95999599
if (MF.getRegInfo().reservedRegsFrozen()) {
9600-
recomputeLiveIns(MF);
9600+
recomputeLiveIns(*LoopTestMBB);
9601+
recomputeLiveIns(*LoopBodyMBB);
9602+
recomputeLiveIns(*ExitMBB);
96019603
}
96029604

96039605
return ExitMBB->begin();

llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,12 @@ void ARMLowOverheadLoops::Expand(LowOverheadLoop &LoLoop) {
18061806
PostOrderLoopTraversal DFS(LoLoop.ML, *MLI);
18071807
DFS.ProcessLoop();
18081808
const SmallVectorImpl<MachineBasicBlock*> &PostOrder = DFS.getOrder();
1809-
recomputeLiveIns(*LoLoop.MF);
1809+
for (auto *MBB : PostOrder) {
1810+
recomputeLiveIns(*MBB);
1811+
// FIXME: For some reason, the live-in print order is non-deterministic for
1812+
// our tests and I can't out why... So just sort them.
1813+
MBB->sortUniqueLiveIns();
1814+
}
18101815

18111816
for (auto *MBB : reverse(PostOrder))
18121817
recomputeLivenessFlags(*MBB);

llvm/lib/Target/PowerPC/PPCExpandAtomicPseudoInsts.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ bool PPCExpandAtomicPseudo::expandAtomicRMW128(
208208
.addMBB(LoopMBB);
209209
CurrentMBB->addSuccessor(LoopMBB);
210210
CurrentMBB->addSuccessor(ExitMBB);
211-
recomputeLiveIns(*MF);
211+
recomputeLiveIns(*LoopMBB);
212+
recomputeLiveIns(*ExitMBB);
212213
NMBBI = MBB.end();
213214
MI.eraseFromParent();
214215
return true;
@@ -285,7 +286,9 @@ bool PPCExpandAtomicPseudo::expandAtomicCmpSwap128(
285286
CurrentMBB->addSuccessor(LoopCmpMBB);
286287
CurrentMBB->addSuccessor(ExitMBB);
287288

288-
recomputeLiveIns(*MF);
289+
recomputeLiveIns(*LoopCmpMBB);
290+
recomputeLiveIns(*CmpSuccMBB);
291+
recomputeLiveIns(*ExitMBB);
289292
NMBBI = MBB.end();
290293
MI.eraseFromParent();
291294
return true;

llvm/lib/Target/PowerPC/PPCFrameLowering.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,8 @@ void PPCFrameLowering::inlineStackProbe(MachineFunction &MF,
14411441
ProbeLoopBodyMBB->addSuccessor(ProbeLoopBodyMBB);
14421442
}
14431443
// Update liveins.
1444-
recomputeLiveIns(MF);
1444+
recomputeLiveIns(*ProbeLoopBodyMBB);
1445+
recomputeLiveIns(*ProbeExitMBB);
14451446
return ProbeExitMBB;
14461447
};
14471448
// For case HasBP && MaxAlign > 1, we have to realign the SP by performing
@@ -1533,7 +1534,8 @@ void PPCFrameLowering::inlineStackProbe(MachineFunction &MF,
15331534
buildDefCFAReg(*ExitMBB, ExitMBB->begin(), SPReg);
15341535
}
15351536
// Update liveins.
1536-
recomputeLiveIns(MF);
1537+
recomputeLiveIns(*LoopMBB);
1538+
recomputeLiveIns(*ExitMBB);
15371539
}
15381540
}
15391541
++NumPrologProbed;

llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,8 @@ void SystemZELFFrameLowering::inlineStackProbe(
840840
StackAllocMI->eraseFromParent();
841841
if (DoneMBB != nullptr) {
842842
// Compute the live-in lists for the new blocks.
843-
recomputeLiveIns(MF);
843+
recomputeLiveIns(*DoneMBB);
844+
recomputeLiveIns(*LoopMBB);
844845
}
845846
}
846847

@@ -1438,7 +1439,8 @@ void SystemZXPLINKFrameLowering::inlineStackProbe(
14381439
StackAllocMI->eraseFromParent();
14391440

14401441
// Compute the live-in lists for the new blocks.
1441-
recomputeLiveIns(MF);
1442+
recomputeLiveIns(*NextMBB);
1443+
recomputeLiveIns(*StackExtMBB);
14421444
}
14431445

14441446
bool SystemZXPLINKFrameLowering::hasFP(const MachineFunction &MF) const {

llvm/lib/Target/X86/X86FrameLowering.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,8 @@ void X86FrameLowering::emitStackProbeInlineGenericLoop(
885885
}
886886

887887
// Update Live In information
888-
recomputeLiveIns(MF);
888+
recomputeLiveIns(*testMBB);
889+
recomputeLiveIns(*tailMBB);
889890
}
890891

891892
void X86FrameLowering::emitStackProbeInlineWindowsCoreCLR64(
@@ -1377,7 +1378,10 @@ void X86FrameLowering::BuildStackAlignAND(MachineBasicBlock &MBB,
13771378
footMBB->addSuccessor(&MBB);
13781379
}
13791380

1380-
recomputeLiveIns(MF);
1381+
recomputeLiveIns(*headMBB);
1382+
recomputeLiveIns(*bodyMBB);
1383+
recomputeLiveIns(*footMBB);
1384+
recomputeLiveIns(MBB);
13811385
}
13821386
} else {
13831387
MachineInstr *MI = BuildMI(MBB, MBBI, DL, TII.get(AndOp), Reg)

llvm/test/CodeGen/AArch64/stack-probing-last-in-block.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ body: |
8282
; CHECK-LABEL: name: f
8383
; CHECK: bb.0.entry:
8484
; CHECK-NEXT: successors: %bb.3(0x80000000)
85-
; CHECK-NEXT: liveins: $fp, $lr
85+
; CHECK-NEXT: liveins: $lr, $fp
8686
; CHECK-NEXT: {{ $}}
8787
; CHECK-NEXT: early-clobber $sp = frame-setup STPXpre killed $fp, killed $lr, $sp, -2 :: (store (s64) into %stack.2), (store (s64) into %stack.1)
8888
; CHECK-NEXT: frame-setup CFI_INSTRUCTION def_cfa_offset 16

llvm/test/CodeGen/SystemZ/branch-folder-hoist-livein.mir

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
21
# RUN: llc -verify-machineinstrs -O1 -mtriple=s390x-ibm-linux -o - %s -run-pass=branch-folder | FileCheck %s
32
--- |
43
target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"
@@ -16,30 +15,6 @@
1615
name: f1
1716
tracksRegLiveness: true
1817
body: |
19-
; CHECK-LABEL: name: f1
20-
; CHECK: bb.0:
21-
; CHECK-NEXT: successors: %bb.2(0x7fffffff), %bb.1(0x00000001)
22-
; CHECK-NEXT: {{ $}}
23-
; CHECK-NEXT: renamable $r1d = LGRL @b :: (load (s32) from got, align 8)
24-
; CHECK-NEXT: renamable $r1l = LH killed renamable $r1d, 0, $noreg, implicit-def $r1d :: (dereferenceable load (s8) from @b)
25-
; CHECK-NEXT: renamable $r2l = LHI 0
26-
; CHECK-NEXT: renamable $r3d = LGRL @d :: (load (s32) from got, align 8)
27-
; CHECK-NEXT: renamable $r4d = LLILL 0, implicit-def $r4q
28-
; CHECK-NEXT: renamable $r4d = COPY killed renamable $r4d, implicit killed $r4q
29-
; CHECK-NEXT: CHI killed renamable $r2l, 0, implicit-def $cc
30-
; CHECK-NEXT: BRC 14, 6, %bb.2, implicit killed $cc
31-
; CHECK-NEXT: {{ $}}
32-
; CHECK-NEXT: bb.1:
33-
; CHECK-NEXT: successors:
34-
; CHECK-NEXT: liveins: $r3d, $r4d, $r1l
35-
; CHECK-NEXT: {{ $}}
36-
; CHECK-NEXT: STH renamable $r1l, killed renamable $r3d, 0, $noreg, implicit killed $r4d :: (store (s8) into @d)
37-
; CHECK-NEXT: {{ $}}
38-
; CHECK-NEXT: bb.2:
39-
; CHECK-NEXT: liveins: $r3d, $r4d, $r1l
40-
; CHECK-NEXT: {{ $}}
41-
; CHECK-NEXT: STH renamable $r1l, killed renamable $r3d, 0, $noreg, implicit killed $r4d :: (store (s8) into @d)
42-
; CHECK-NEXT: Return
4318
bb.0:
4419
successors: %bb.2(0x7fffffff), %bb.1(0x00000001)
4520
liveins:
@@ -69,3 +44,14 @@ body: |
6944
Return
7045

7146
...
47+
48+
# CHECK: renamable $r4d = COPY killed renamable $r4d, implicit killed $r4q
49+
# CHECK-NEXT: CHI killed renamable $r2l, 0, implicit-def $cc
50+
# CHECK-NEXT: BRC 14, 6, %bb.2, implicit killed $cc
51+
# CHECK-NEXT: {{^ $}}
52+
# CHECK-NEXT: bb.1:
53+
# CHECK-NEXT: successors:
54+
# CHECK-NEXT: liveins: $r1l, $r3d, $r4d
55+
56+
# CHECK: bb.2:
57+
# CHECK-NEXT: liveins: $r1l, $r3d, $r4d

0 commit comments

Comments
 (0)