Skip to content

Commit 51fa032

Browse files
author
Jessica Paquette
committed
[MachineOutliner] NFC: Add debug output to overlap pruning code
This had no debug output. Since it was committed as NFC, it had no testcase. The me of today was nerdsniped by the me of 6 years ago and decided that this ought to have a testcase and some debug output.
1 parent e07452d commit 51fa032

File tree

2 files changed

+124
-16
lines changed

2 files changed

+124
-16
lines changed

llvm/lib/CodeGen/MachineOutliner.cpp

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -572,11 +572,19 @@ void MachineOutliner::findCandidates(
572572
// First, find all of the repeated substrings in the tree of minimum length
573573
// 2.
574574
std::vector<Candidate> CandidatesForRepeatedSeq;
575+
LLVM_DEBUG(dbgs() << "*** Discarding overlapping candidates *** \n");
576+
LLVM_DEBUG(
577+
dbgs() << "Searching for overlaps in all repeated sequences...\n");
575578
for (const SuffixTree::RepeatedSubstring &RS : ST) {
576579
CandidatesForRepeatedSeq.clear();
577580
unsigned StringLen = RS.Length;
581+
LLVM_DEBUG(dbgs() << " Sequence length: " << StringLen << "\n");
582+
// Debug code to keep track of how many candidates we removed.
583+
#ifndef NDEBUG
584+
unsigned NumDiscarded = 0;
585+
unsigned NumKept = 0;
586+
#endif
578587
for (const unsigned &StartIdx : RS.StartIndices) {
579-
unsigned EndIdx = StartIdx + StringLen - 1;
580588
// Trick: Discard some candidates that would be incompatible with the
581589
// ones we've already found for this sequence. This will save us some
582590
// work in candidate selection.
@@ -598,23 +606,39 @@ void MachineOutliner::findCandidates(
598606
// That is, one must either
599607
// * End before the other starts
600608
// * Start after the other ends
601-
if (all_of(CandidatesForRepeatedSeq, [&StartIdx,
602-
&EndIdx](const Candidate &C) {
603-
return (EndIdx < C.getStartIdx() || StartIdx > C.getEndIdx());
604-
})) {
605-
// It doesn't overlap with anything, so we can outline it.
606-
// Each sequence is over [StartIt, EndIt].
607-
// Save the candidate and its location.
608-
609-
MachineBasicBlock::iterator StartIt = Mapper.InstrList[StartIdx];
610-
MachineBasicBlock::iterator EndIt = Mapper.InstrList[EndIdx];
611-
MachineBasicBlock *MBB = StartIt->getParent();
612-
613-
CandidatesForRepeatedSeq.emplace_back(StartIdx, StringLen, StartIt,
614-
EndIt, MBB, FunctionList.size(),
615-
Mapper.MBBFlagsMap[MBB]);
609+
unsigned EndIdx = StartIdx + StringLen - 1;
610+
auto FirstOverlap = find_if(
611+
CandidatesForRepeatedSeq, [StartIdx, EndIdx](const Candidate &C) {
612+
return EndIdx >= C.getStartIdx() && StartIdx <= C.getEndIdx();
613+
});
614+
if (FirstOverlap != CandidatesForRepeatedSeq.end()) {
615+
#ifndef NDEBUG
616+
++NumDiscarded;
617+
LLVM_DEBUG(dbgs() << " .. DISCARD candidate @ [" << StartIdx
618+
<< ", " << EndIdx << "]; overlaps with candidate @ ["
619+
<< FirstOverlap->getStartIdx() << ", "
620+
<< FirstOverlap->getEndIdx() << "]\n");
621+
#endif
622+
continue;
616623
}
624+
// It doesn't overlap with anything, so we can outline it.
625+
// Each sequence is over [StartIt, EndIt].
626+
// Save the candidate and its location.
627+
#ifndef NDEBUG
628+
++NumKept;
629+
#endif
630+
MachineBasicBlock::iterator StartIt = Mapper.InstrList[StartIdx];
631+
MachineBasicBlock::iterator EndIt = Mapper.InstrList[EndIdx];
632+
MachineBasicBlock *MBB = StartIt->getParent();
633+
CandidatesForRepeatedSeq.emplace_back(StartIdx, StringLen, StartIt, EndIt,
634+
MBB, FunctionList.size(),
635+
Mapper.MBBFlagsMap[MBB]);
617636
}
637+
#ifndef NDEBUG
638+
LLVM_DEBUG(dbgs() << " Candidates discarded: " << NumDiscarded
639+
<< "\n");
640+
LLVM_DEBUG(dbgs() << " Candidates kept: " << NumKept << "\n\n");
641+
#endif
618642

619643
// We've found something we might want to outline.
620644
// Create an OutlinedFunction to store it and check if it'd be beneficial
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --include-generated-funcs
2+
# RUN: llc %s -mtriple aarch64 -debug-only=machine-outliner -run-pass=machine-outliner -o - 2>&1 | FileCheck %s
3+
# REQUIRES: asserts
4+
5+
# CHECK: *** Discarding overlapping candidates ***
6+
# CHECK-NEXT:Searching for overlaps in all repeated sequences...
7+
# CHECK-DAG: Sequence length: 7
8+
# CHECK-NEXT: Candidates discarded: 0
9+
# CHECK-NEXT: Candidates kept: 2
10+
# CHECK-DAG: Sequence length: 8
11+
# CHECK-NEXT: .. DISCARD candidate @ [5, 12]; overlaps with candidate @ [12, 19]
12+
# CHECK-NEXT: Candidates discarded: 1
13+
# CHECK-NEXT: Candidates kept: 1
14+
# CHECK-DAG: Sequence length: 9
15+
# CHECK-NEXT: .. DISCARD candidate @ [4, 12]; overlaps with candidate @ [11, 19]
16+
# CHECK-NEXT: Candidates discarded: 1
17+
# CHECK-NEXT: Candidates kept: 1
18+
# CHECK-DAG: Sequence length: 10
19+
# CHECK-NEXT: .. DISCARD candidate @ [3, 12]; overlaps with candidate @ [10, 19]
20+
# CHECK-NEXT: Candidates discarded: 1
21+
# CHECK-NEXT: Candidates kept: 1
22+
# CHECK-DAG: Sequence length: 11
23+
# CHECK-NEXT: .. DISCARD candidate @ [2, 12]; overlaps with candidate @ [9, 19]
24+
# CHECK-NEXT: Candidates discarded: 1
25+
# CHECK-NEXT: Candidates kept: 1
26+
# CHECK-DAG: Sequence length: 12
27+
# CHECK-NEXT: .. DISCARD candidate @ [1, 12]; overlaps with candidate @ [8, 19]
28+
# CHECK-NEXT: Candidates discarded: 1
29+
# CHECK-NEXT: Candidates kept: 1
30+
# CHECK-DAG: Sequence length: 13
31+
# CHECK-NEXT: .. DISCARD candidate @ [0, 12]; overlaps with candidate @ [7, 19]
32+
# CHECK-NEXT: Candidates discarded: 1
33+
# CHECK-NEXT: Candidates kept: 1
34+
35+
...
36+
---
37+
name: overlap
38+
tracksRegLiveness: true
39+
machineFunctionInfo:
40+
hasRedZone: false
41+
body: |
42+
bb.0:
43+
liveins: $x0, $x9
44+
; CHECK-LABEL: name: overlap
45+
; CHECK: liveins: $x0, $x9
46+
; CHECK-NEXT: {{ $}}
47+
; CHECK-NEXT: $x9 = ADDXri $x9, 16, 0
48+
; CHECK-NEXT: $x9 = ADDXri $x9, 16, 0
49+
; CHECK-NEXT: $x9 = ADDXri $x9, 16, 0
50+
; CHECK-NEXT: $x9 = ADDXri $x9, 16, 0
51+
; CHECK-NEXT: $x9 = ADDXri $x9, 16, 0
52+
; CHECK-NEXT: $x9 = ADDXri $x9, 16, 0
53+
; CHECK-NEXT: BL @OUTLINED_FUNCTION_0, implicit-def $lr, implicit $sp, implicit-def $lr, implicit-def $x8, implicit-def $x9, implicit $sp, implicit $x0, implicit $x9
54+
; CHECK-NEXT: BL @OUTLINED_FUNCTION_0, implicit-def $lr, implicit $sp, implicit-def $lr, implicit-def $x8, implicit-def $x9, implicit $sp, implicit $x0, implicit $x9
55+
; CHECK-NEXT: RET undef $x9
56+
57+
; fixme: outline!
58+
$x9 = ADDXri $x9, 16, 0
59+
$x9 = ADDXri $x9, 16, 0
60+
$x9 = ADDXri $x9, 16, 0
61+
$x9 = ADDXri $x9, 16, 0
62+
$x9 = ADDXri $x9, 16, 0
63+
$x9 = ADDXri $x9, 16, 0
64+
65+
$x8 = ADDXri $x0, 3, 0
66+
67+
; outline
68+
$x9 = ADDXri $x9, 16, 0
69+
$x9 = ADDXri $x9, 16, 0
70+
$x9 = ADDXri $x9, 16, 0
71+
$x9 = ADDXri $x9, 16, 0
72+
$x9 = ADDXri $x9, 16, 0
73+
$x9 = ADDXri $x9, 16, 0
74+
75+
$x8 = ADDXri $x0, 3, 0
76+
77+
; outline
78+
$x9 = ADDXri $x9, 16, 0
79+
$x9 = ADDXri $x9, 16, 0
80+
$x9 = ADDXri $x9, 16, 0
81+
$x9 = ADDXri $x9, 16, 0
82+
$x9 = ADDXri $x9, 16, 0
83+
$x9 = ADDXri $x9, 16, 0
84+
RET undef $x9

0 commit comments

Comments
 (0)