xref: /freebsd/contrib/llvm-project/llvm/include/llvm/CodeGen/MachineDomTreeUpdater.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //===- llvm/CodeGen/MachineDomTreeUpdater.h -----------------------*- C++-*-==//
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 exposes interfaces to post dominance information for
10 // target-specific code.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_MACHINEDOMTREEUPDATER_H
15 #define LLVM_CODEGEN_MACHINEDOMTREEUPDATER_H
16 
17 #include "llvm/Analysis/GenericDomTreeUpdater.h"
18 #include "llvm/CodeGen/MachineDominators.h"
19 
20 namespace llvm {
21 
22 class MachinePostDominatorTree;
23 
24 class MachineDomTreeUpdater
25     : public GenericDomTreeUpdater<MachineDomTreeUpdater, MachineDominatorTree,
26                                    MachinePostDominatorTree> {
27   friend GenericDomTreeUpdater<MachineDomTreeUpdater, MachineDominatorTree,
28                                MachinePostDominatorTree>;
29 
30 public:
31   using Base =
32       GenericDomTreeUpdater<MachineDomTreeUpdater, MachineDominatorTree,
33                             MachinePostDominatorTree>;
34   using Base::Base;
35 
~MachineDomTreeUpdater()36   ~MachineDomTreeUpdater() { flush(); }
37 
38   ///@{
39   /// \name Mutation APIs
40   ///
41 
42   /// Delete DelBB. DelBB will be removed from its Parent and
43   /// erased from available trees if it exists and finally get deleted.
44   /// Under Eager UpdateStrategy, DelBB will be processed immediately.
45   /// Under Lazy UpdateStrategy, DelBB will be queued until a flush event and
46   /// all available trees are up-to-date. Assert if any instruction of DelBB is
47   /// modified while awaiting deletion. When both DT and PDT are nullptrs, DelBB
48   /// will be queued until flush() is called.
49   void deleteBB(MachineBasicBlock *DelBB);
50 
51   ///@}
52 
53 private:
54   /// First remove all the instructions of DelBB and then make sure DelBB has a
55   /// valid terminator instruction which is necessary to have when DelBB still
56   /// has to be inside of its parent Function while awaiting deletion under Lazy
57   /// UpdateStrategy to prevent other routines from asserting the state of the
58   /// IR is inconsistent. Assert if DelBB is nullptr or has predecessors.
59   void validateDeleteBB(MachineBasicBlock *DelBB);
60 
61   /// Returns true if at least one MachineBasicBlock is deleted.
62   bool forceFlushDeletedBB();
63 };
64 
65 extern template class GenericDomTreeUpdater<
66     MachineDomTreeUpdater, MachineDominatorTree, MachinePostDominatorTree>;
67 
68 extern template void
69 GenericDomTreeUpdater<MachineDomTreeUpdater, MachineDominatorTree,
70                       MachinePostDominatorTree>::recalculate(MachineFunction
71                                                                  &MF);
72 } // namespace llvm
73 #endif // LLVM_CODEGEN_MACHINEDOMTREEUPDATER_H
74