Skip to content

Commit 761517f

Browse files
committed
Unify apply{DT,PDT}Updates
1 parent 95661ce commit 761517f

File tree

6 files changed

+50
-40
lines changed

6 files changed

+50
-40
lines changed

llvm/include/llvm/Analysis/DomTreeUpdater.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ extern template class GenericDomTreeUpdater<DomTreeUpdater, DominatorTree,
120120
extern template void
121121
GenericDomTreeUpdater<DomTreeUpdater, DominatorTree,
122122
PostDominatorTree>::recalculate(Function &F);
123+
124+
extern template void
125+
GenericDomTreeUpdater<DomTreeUpdater, DominatorTree, PostDominatorTree>::
126+
applyUpdatesImpl</*IsForward=*/true>();
127+
extern template void
128+
GenericDomTreeUpdater<DomTreeUpdater, DominatorTree, PostDominatorTree>::
129+
applyUpdatesImpl</*IsForward=*/false>();
123130
} // namespace llvm
124131

125132
#endif // LLVM_ANALYSIS_DOMTREEUPDATER_H

llvm/include/llvm/Analysis/GenericDomTreeUpdater.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ class GenericDomTreeUpdater {
246246
}
247247

248248
/// Helper function to apply all pending DomTree updates.
249-
void applyDomTreeUpdates();
249+
void applyDomTreeUpdates() { applyUpdatesImpl<true>(); }
250250

251251
/// Helper function to apply all pending PostDomTree updates.
252-
void applyPostDomTreeUpdates();
252+
void applyPostDomTreeUpdates() { applyUpdatesImpl<false>(); }
253253

254254
/// Returns true if the update appears in the LLVM IR.
255255
/// It is used to check whether an update is valid in
@@ -271,6 +271,7 @@ class GenericDomTreeUpdater {
271271
private:
272272
void splitDTCriticalEdges(ArrayRef<CriticalEdge> Updates);
273273
void splitPDTCriticalEdges(ArrayRef<CriticalEdge> Updates);
274+
template <bool IsForward> void applyUpdatesImpl();
274275
};
275276

276277
} // namespace llvm

llvm/include/llvm/Analysis/GenericDomTreeUpdaterImpl.h

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -263,58 +263,39 @@ GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::dump() const {
263263
}
264264

265265
template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
266+
template <bool IsForward>
266267
void GenericDomTreeUpdater<DerivedT, DomTreeT,
267-
PostDomTreeT>::applyDomTreeUpdates() {
268+
PostDomTreeT>::applyUpdatesImpl() {
269+
auto *DomTree = [&]() {
270+
if constexpr (IsForward)
271+
return DT;
272+
else
273+
return PDT;
274+
}();
268275
// No pending DomTreeUpdates.
269-
if (Strategy != UpdateStrategy::Lazy || !DT)
276+
if (Strategy != UpdateStrategy::Lazy || !DomTree)
270277
return;
278+
size_t &PendUpdateIndex = IsForward ? PendDTUpdateIndex : PendPDTUpdateIndex;
271279

272-
// Only apply updates not are applied by DomTree.
273-
while (hasPendingDomTreeUpdates()) {
274-
auto I = PendUpdates.begin() + PendDTUpdateIndex;
280+
// Only apply updates not are applied by (Post)DomTree.
281+
while (IsForward ? hasPendingDomTreeUpdates()
282+
: hasPendingPostDomTreeUpdates()) {
283+
auto I = PendUpdates.begin() + PendUpdateIndex;
275284
const auto E = PendUpdates.end();
276285
assert(I < E && "Iterator range invalid; there should be DomTree updates.");
277286
if (!I->IsCriticalEdgeSplit) {
278287
SmallVector<UpdateT, 32> NormalUpdates;
279288
for (; I != E && !I->IsCriticalEdgeSplit; ++I)
280289
NormalUpdates.push_back(I->Update);
281-
DT->applyUpdates(NormalUpdates);
282-
PendDTUpdateIndex += NormalUpdates.size();
283-
} else {
284-
SmallVector<CriticalEdge> CriticalEdges;
285-
for (; I != E && I->IsCriticalEdgeSplit; ++I)
286-
CriticalEdges.push_back(I->EdgeSplit);
287-
splitDTCriticalEdges(CriticalEdges);
288-
PendDTUpdateIndex += CriticalEdges.size();
289-
}
290-
}
291-
}
292-
293-
template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
294-
void GenericDomTreeUpdater<DerivedT, DomTreeT,
295-
PostDomTreeT>::applyPostDomTreeUpdates() {
296-
// No pending PostDomTreeUpdates.
297-
if (Strategy != UpdateStrategy::Lazy || !PDT)
298-
return;
299-
300-
// Only apply updates not are applied by PostDomTree.
301-
while (hasPendingPostDomTreeUpdates()) {
302-
auto I = PendUpdates.begin() + PendPDTUpdateIndex;
303-
const auto E = PendUpdates.end();
304-
assert(I < E &&
305-
"Iterator range invalid; there should be PostDomTree updates.");
306-
if (!I->IsCriticalEdgeSplit) {
307-
SmallVector<UpdateT, 32> NormalUpdates;
308-
for (; I != E && !I->IsCriticalEdgeSplit; ++I)
309-
NormalUpdates.push_back(I->Update);
310-
PDT->applyUpdates(NormalUpdates);
311-
PendPDTUpdateIndex += NormalUpdates.size();
290+
DomTree->applyUpdates(NormalUpdates);
291+
PendUpdateIndex += NormalUpdates.size();
312292
} else {
313293
SmallVector<CriticalEdge> CriticalEdges;
314294
for (; I != E && I->IsCriticalEdgeSplit; ++I)
315295
CriticalEdges.push_back(I->EdgeSplit);
316-
splitPDTCriticalEdges(CriticalEdges);
317-
PendPDTUpdateIndex += CriticalEdges.size();
296+
IsForward ? splitDTCriticalEdges(CriticalEdges)
297+
: splitPDTCriticalEdges(CriticalEdges);
298+
PendUpdateIndex += CriticalEdges.size();
318299
}
319300
}
320301
}

llvm/include/llvm/CodeGen/MachineDomTreeUpdater.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,12 @@ extern template void
6969
GenericDomTreeUpdater<MachineDomTreeUpdater, MachineDominatorTree,
7070
MachinePostDominatorTree>::recalculate(MachineFunction
7171
&MF);
72+
73+
extern template void GenericDomTreeUpdater<
74+
MachineDomTreeUpdater, MachineDominatorTree,
75+
MachinePostDominatorTree>::applyUpdatesImpl</*IsForward=*/true>();
76+
extern template void GenericDomTreeUpdater<
77+
MachineDomTreeUpdater, MachineDominatorTree,
78+
MachinePostDominatorTree>::applyUpdatesImpl</*IsForward=*/false>();
7279
} // namespace llvm
7380
#endif // LLVM_CODEGEN_MACHINEDOMTREEUPDATER_H

llvm/lib/Analysis/DomTreeUpdater.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ template void
2828
GenericDomTreeUpdater<DomTreeUpdater, DominatorTree,
2929
PostDominatorTree>::recalculate(Function &F);
3030

31+
template void
32+
GenericDomTreeUpdater<DomTreeUpdater, DominatorTree, PostDominatorTree>::
33+
applyUpdatesImpl</*IsForward=*/true>();
34+
template void
35+
GenericDomTreeUpdater<DomTreeUpdater, DominatorTree, PostDominatorTree>::
36+
applyUpdatesImpl</*IsForward=*/false>();
37+
3138
bool DomTreeUpdater::forceFlushDeletedBB() {
3239
if (DeletedBBs.empty())
3340
return false;

llvm/lib/CodeGen/MachineDomTreeUpdater.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ GenericDomTreeUpdater<MachineDomTreeUpdater, MachineDominatorTree,
2525
MachinePostDominatorTree>::recalculate(MachineFunction
2626
&MF);
2727

28+
template void GenericDomTreeUpdater<
29+
MachineDomTreeUpdater, MachineDominatorTree,
30+
MachinePostDominatorTree>::applyUpdatesImpl</*IsForward=*/true>();
31+
template void GenericDomTreeUpdater<
32+
MachineDomTreeUpdater, MachineDominatorTree,
33+
MachinePostDominatorTree>::applyUpdatesImpl</*IsForward=*/false>();
34+
2835
bool MachineDomTreeUpdater::forceFlushDeletedBB() {
2936
if (DeletedBBs.empty())
3037
return false;

0 commit comments

Comments
 (0)