1 //===- MachineDomTreeUpdater.cpp -----------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the MachineDomTreeUpdater class, which provides a
10 // uniform way to update dominator tree related data structures.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/MachineDomTreeUpdater.h"
15 #include "llvm/Analysis/GenericDomTreeUpdaterImpl.h"
16 #include "llvm/CodeGen/MachinePostDominators.h"
20 template class GenericDomTreeUpdater
<
21 MachineDomTreeUpdater
, MachineDominatorTree
, MachinePostDominatorTree
>;
24 GenericDomTreeUpdater
<MachineDomTreeUpdater
, MachineDominatorTree
,
25 MachinePostDominatorTree
>::recalculate(MachineFunction
28 template void GenericDomTreeUpdater
<
29 MachineDomTreeUpdater
, MachineDominatorTree
,
30 MachinePostDominatorTree
>::applyUpdatesImpl
</*IsForward=*/true>();
31 template void GenericDomTreeUpdater
<
32 MachineDomTreeUpdater
, MachineDominatorTree
,
33 MachinePostDominatorTree
>::applyUpdatesImpl
</*IsForward=*/false>();
35 bool MachineDomTreeUpdater::forceFlushDeletedBB() {
36 if (DeletedBBs
.empty())
39 for (auto *BB
: DeletedBBs
) {
41 BB
->eraseFromParent();
47 // The DT and PDT require the nodes related to updates
48 // are not deleted when update functions are called.
49 // So MachineBasicBlock deletions must be pended when the
50 // UpdateStrategy is Lazy. When the UpdateStrategy is
51 // Eager, the MachineBasicBlock will be deleted immediately.
52 void MachineDomTreeUpdater::deleteBB(MachineBasicBlock
*DelBB
) {
53 validateDeleteBB(DelBB
);
54 if (Strategy
== UpdateStrategy::Lazy
) {
55 DeletedBBs
.insert(DelBB
);
59 eraseDelBBNode(DelBB
);
60 DelBB
->eraseFromParent();
63 void MachineDomTreeUpdater::validateDeleteBB(MachineBasicBlock
*DelBB
) {
64 assert(DelBB
&& "Invalid push_back of nullptr DelBB.");
65 assert(DelBB
->pred_empty() && "DelBB has one or more predecessors.");