Skip to content

Commit 53d8858

Browse files
committed
llvm-reduce: Clone properties of blocks
getSuccProbability was private for some reason, saying to go through MachineBranchProbabilityInfo. There doesn't seem to be much point to that, as that wrapper directly calls this. Like other areas, some of these fields aren't handled by the MIR printer/parser so aren't tested.
1 parent 879ac41 commit 53d8858

File tree

3 files changed

+126
-10
lines changed

3 files changed

+126
-10
lines changed

llvm/include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,11 @@ class MachineBasicBlock
10861086
IrrLoopHeaderWeight = Weight;
10871087
}
10881088

1089+
/// Return probability of the edge from this block to MBB. This method should
1090+
/// NOT be called directly, but by using getEdgeProbability method from
1091+
/// MachineBranchProbabilityInfo class.
1092+
BranchProbability getSuccProbability(const_succ_iterator Succ) const;
1093+
10891094
private:
10901095
/// Return probability iterator corresponding to the I successor iterator.
10911096
probability_iterator getProbabilityIterator(succ_iterator I);
@@ -1095,11 +1100,6 @@ class MachineBasicBlock
10951100
friend class MachineBranchProbabilityInfo;
10961101
friend class MIPrinter;
10971102

1098-
/// Return probability of the edge from this block to MBB. This method should
1099-
/// NOT be called directly, but by using getEdgeProbability method from
1100-
/// MachineBranchProbabilityInfo class.
1101-
BranchProbability getSuccProbability(const_succ_iterator Succ) const;
1102-
11031103
// Methods used to maintain doubly linked list of blocks...
11041104
friend struct ilist_callback_traits<MachineBasicBlock>;
11051105

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# REQUIRES: amdgpu-registered-target
2+
# RUN: llvm-reduce -simplify-mir -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg --check-prefix=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2> %t.log
3+
# RUN: FileCheck --match-full-lines --check-prefix=RESULT %s < %t
4+
5+
# CHECK-INTERESTINGNESS: V_MOV_B32
6+
7+
8+
# RESULT: bb.0.entry:
9+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
10+
11+
# RESULT: bb.1 (address-taken, align 8):
12+
# RESULT: bb.2 (landing-pad, align 16):
13+
# RESULT: bb.3 (inlineasm-br-indirect-target):
14+
# RESULT: bb.4 (ehfunclet-entry):
15+
# RESULT: bb.5 (bbsections 1):
16+
# RESULT: bb.6 (bbsections 2):
17+
# RESULT: bb.7 (bbsections 3):
18+
# RESULT: bb.8:
19+
# RESULT-NEXT: successors: %bb.9(0x66666666), %bb.10(0x1999999a)
20+
# RESULT: bb.9:
21+
# RESULT: bb.10.exitblock:
22+
23+
--- |
24+
define void @func(i32 %size) {
25+
entry:
26+
br label %exitblock
27+
28+
exitblock:
29+
ret void
30+
}
31+
32+
...
33+
34+
---
35+
name: func
36+
alignment: 32
37+
exposesReturnsTwice: true
38+
legalized: true
39+
regBankSelected: true
40+
selected: true
41+
failedISel: true
42+
tracksRegLiveness: true
43+
hasWinCFI: true
44+
failsVerification: true
45+
tracksDebugUserValues: true
46+
body: |
47+
bb.0.entry:
48+
S_NOP 0
49+
%0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
50+
51+
bb.1 (address-taken, align 8):
52+
53+
bb.2 (landing-pad, align 16):
54+
55+
bb.3 (inlineasm-br-indirect-target):
56+
57+
bb.4 (ehfunclet-entry):
58+
59+
bb.5 (bbsections 1):
60+
bb.6 (bbsections 2):
61+
bb.7 (bbsections 3):
62+
63+
bb.8:
64+
successors: %bb.9(4), %bb.10(1)
65+
S_CBRANCH_SCC1 %bb.10, implicit undef $scc
66+
S_BRANCH %bb.9
67+
68+
bb.9:
69+
70+
bb.10.exitblock:
71+
S_ENDPGM 0, implicit %0
72+
...

llvm/tools/llvm-reduce/ReducerWorkItem.cpp

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,41 @@ static std::unique_ptr<MachineFunction> cloneMF(MachineFunction *SrcMF) {
125125
auto *DstMRI = &DstMF->getRegInfo();
126126

127127
// Clone blocks.
128-
for (MachineBasicBlock &SrcMBB : *SrcMF)
129-
Src2DstMBB[&SrcMBB] = DstMF->CreateMachineBasicBlock();
128+
for (MachineBasicBlock &SrcMBB : *SrcMF) {
129+
MachineBasicBlock *DstMBB =
130+
DstMF->CreateMachineBasicBlock(SrcMBB.getBasicBlock());
131+
Src2DstMBB[&SrcMBB] = DstMBB;
132+
133+
if (SrcMBB.hasAddressTaken())
134+
DstMBB->setHasAddressTaken();
135+
136+
// FIXME: This is not serialized
137+
if (SrcMBB.hasLabelMustBeEmitted())
138+
DstMBB->setLabelMustBeEmitted();
139+
140+
DstMBB->setAlignment(SrcMBB.getAlignment());
141+
142+
// FIXME: This is not serialized
143+
DstMBB->setMaxBytesForAlignment(SrcMBB.getMaxBytesForAlignment());
144+
145+
DstMBB->setIsEHPad(SrcMBB.isEHPad());
146+
DstMBB->setIsEHScopeEntry(SrcMBB.isEHScopeEntry());
147+
DstMBB->setIsEHCatchretTarget(SrcMBB.isEHCatchretTarget());
148+
DstMBB->setIsEHFuncletEntry(SrcMBB.isEHFuncletEntry());
149+
150+
// FIXME: These are not serialized
151+
DstMBB->setIsCleanupFuncletEntry(SrcMBB.isCleanupFuncletEntry());
152+
DstMBB->setIsBeginSection(SrcMBB.isBeginSection());
153+
DstMBB->setIsEndSection(SrcMBB.isEndSection());
154+
155+
DstMBB->setSectionID(SrcMBB.getSectionID());
156+
DstMBB->setIsInlineAsmBrIndirectTarget(
157+
SrcMBB.isInlineAsmBrIndirectTarget());
158+
159+
// FIXME: This is not serialized
160+
if (Optional<uint64_t> Weight = SrcMBB.getIrrLoopHeaderWeight())
161+
DstMBB->setIrrLoopHeaderWeight(*Weight);
162+
}
130163

131164
const MachineFrameInfo &SrcMFI = SrcMF->getFrameInfo();
132165
MachineFrameInfo &DstMFI = DstMF->getFrameInfo();
@@ -187,25 +220,36 @@ static std::unique_ptr<MachineFunction> cloneMF(MachineFunction *SrcMF) {
187220
}
188221
}
189222

223+
const TargetSubtargetInfo &STI = DstMF->getSubtarget();
224+
const TargetInstrInfo *TII = STI.getInstrInfo();
225+
const TargetRegisterInfo *TRI = STI.getRegisterInfo();
226+
190227
// Link blocks.
191228
for (auto &SrcMBB : *SrcMF) {
192229
auto *DstMBB = Src2DstMBB[&SrcMBB];
193230
DstMF->push_back(DstMBB);
231+
194232
for (auto It = SrcMBB.succ_begin(), IterEnd = SrcMBB.succ_end();
195233
It != IterEnd; ++It) {
196234
auto *SrcSuccMBB = *It;
197235
auto *DstSuccMBB = Src2DstMBB[SrcSuccMBB];
198-
DstMBB->addSuccessor(DstSuccMBB);
236+
DstMBB->addSuccessor(DstSuccMBB, SrcMBB.getSuccProbability(It));
199237
}
200238
for (auto &LI : SrcMBB.liveins())
201239
DstMBB->addLiveIn(LI);
240+
241+
// Make sure MRI knows about registers clobbered by unwinder.
242+
if (DstMBB->isEHPad()) {
243+
if (auto *RegMask = TRI->getCustomEHPadPreservedMask(*DstMF))
244+
DstMRI->addPhysRegsUsedFromRegMask(RegMask);
245+
}
202246
}
247+
203248
// Clone instructions.
204249
for (auto &SrcMBB : *SrcMF) {
205250
auto *DstMBB = Src2DstMBB[&SrcMBB];
206251
for (auto &SrcMI : SrcMBB) {
207-
const auto &MCID =
208-
DstMF->getSubtarget().getInstrInfo()->get(SrcMI.getOpcode());
252+
const auto &MCID = TII->get(SrcMI.getOpcode());
209253
auto *DstMI = DstMF->CreateMachineInstr(MCID, SrcMI.getDebugLoc(),
210254
/*NoImplicit=*/true);
211255
DstMBB->push_back(DstMI);

0 commit comments

Comments
 (0)