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