1 | //===- MachineDomTreeUpdater.cpp -----------------------------------------===// |
---|---|
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file implements the MachineDomTreeUpdater class, which provides a |
10 | // uniform way to update dominator tree related data structures. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #include "llvm/CodeGen/MachineDomTreeUpdater.h" |
15 | #include "llvm/ADT/SmallSet.h" |
16 | #include "llvm/Analysis/GenericDomTreeUpdaterImpl.h" |
17 | #include "llvm/CodeGen/MachinePostDominators.h" |
18 | #include "llvm/Support/GenericDomTree.h" |
19 | #include <algorithm> |
20 | #include <functional> |
21 | #include <utility> |
22 | |
23 | namespace llvm { |
24 | |
25 | template class GenericDomTreeUpdater< |
26 | MachineDomTreeUpdater, MachineDominatorTree, MachinePostDominatorTree>; |
27 | |
28 | template void |
29 | GenericDomTreeUpdater<MachineDomTreeUpdater, MachineDominatorTree, |
30 | MachinePostDominatorTree>::recalculate(MachineFunction |
31 | &MF); |
32 | |
33 | bool MachineDomTreeUpdater::forceFlushDeletedBB() { |
34 | if (DeletedBBs.empty()) |
35 | return false; |
36 | |
37 | for (auto *BB : DeletedBBs) { |
38 | eraseDelBBNode(DelBB: BB); |
39 | BB->eraseFromParent(); |
40 | } |
41 | DeletedBBs.clear(); |
42 | return true; |
43 | } |
44 | |
45 | // The DT and PDT require the nodes related to updates |
46 | // are not deleted when update functions are called. |
47 | // So MachineBasicBlock deletions must be pended when the |
48 | // UpdateStrategy is Lazy. When the UpdateStrategy is |
49 | // Eager, the MachineBasicBlock will be deleted immediately. |
50 | void MachineDomTreeUpdater::deleteBB(MachineBasicBlock *DelBB) { |
51 | validateDeleteBB(DelBB); |
52 | if (Strategy == UpdateStrategy::Lazy) { |
53 | DeletedBBs.insert(Ptr: DelBB); |
54 | return; |
55 | } |
56 | |
57 | eraseDelBBNode(DelBB); |
58 | DelBB->eraseFromParent(); |
59 | } |
60 | |
61 | void MachineDomTreeUpdater::validateDeleteBB(MachineBasicBlock *DelBB) { |
62 | assert(DelBB && "Invalid push_back of nullptr DelBB."); |
63 | assert(DelBB->pred_empty() && "DelBB has one or more predecessors."); |
64 | } |
65 | |
66 | } // namespace llvm |
67 |