1 | //===- llvm/CodeGen/MachinePostDominators.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_MACHINEPOSTDOMINATORS_H |
15 | #define LLVM_CODEGEN_MACHINEPOSTDOMINATORS_H |
16 | |
17 | #include "llvm/CodeGen/MachineDominators.h" |
18 | #include "llvm/Support/Compiler.h" |
19 | |
20 | namespace llvm { |
21 | |
22 | extern template class LLVM_TEMPLATE_ABI |
23 | DominatorTreeBase<MachineBasicBlock, true>; // PostDomTree |
24 | |
25 | namespace DomTreeBuilder { |
26 | using MBBPostDomTree = PostDomTreeBase<MachineBasicBlock>; |
27 | using MBBPostDomTreeGraphDiff = GraphDiff<MachineBasicBlock *, true>; |
28 | |
29 | extern template LLVM_TEMPLATE_ABI void |
30 | Calculate<MBBPostDomTree>(MBBPostDomTree &DT); |
31 | extern template LLVM_TEMPLATE_ABI void |
32 | InsertEdge<MBBPostDomTree>(MBBPostDomTree &DT, MachineBasicBlock *From, |
33 | MachineBasicBlock *To); |
34 | extern template LLVM_TEMPLATE_ABI void |
35 | DeleteEdge<MBBPostDomTree>(MBBPostDomTree &DT, MachineBasicBlock *From, |
36 | MachineBasicBlock *To); |
37 | extern template LLVM_TEMPLATE_ABI void |
38 | ApplyUpdates<MBBPostDomTree>(MBBPostDomTree &DT, MBBPostDomTreeGraphDiff &, |
39 | MBBPostDomTreeGraphDiff *); |
40 | extern template LLVM_TEMPLATE_ABI bool |
41 | Verify<MBBPostDomTree>(const MBBPostDomTree &DT, |
42 | MBBPostDomTree::VerificationLevel VL); |
43 | } // namespace DomTreeBuilder |
44 | |
45 | /// |
46 | /// MachinePostDominatorTree - an analysis pass wrapper for DominatorTree |
47 | /// used to compute the post-dominator tree for MachineFunctions. |
48 | /// |
49 | class MachinePostDominatorTree : public PostDomTreeBase<MachineBasicBlock> { |
50 | using Base = PostDomTreeBase<MachineBasicBlock>; |
51 | |
52 | public: |
53 | MachinePostDominatorTree() = default; |
54 | |
55 | explicit MachinePostDominatorTree(MachineFunction &MF) { recalculate(Func&: MF); } |
56 | |
57 | /// Handle invalidation explicitly. |
58 | LLVM_ABI bool invalidate(MachineFunction &, const PreservedAnalyses &PA, |
59 | MachineFunctionAnalysisManager::Invalidator &); |
60 | |
61 | /// Make findNearestCommonDominator(const NodeT *A, const NodeT *B) available. |
62 | using Base::findNearestCommonDominator; |
63 | |
64 | /// Returns the nearest common dominator of the given blocks. |
65 | /// If that tree node is a virtual root, a nullptr will be returned. |
66 | LLVM_ABI MachineBasicBlock * |
67 | findNearestCommonDominator(ArrayRef<MachineBasicBlock *> Blocks) const; |
68 | }; |
69 | |
70 | class MachinePostDominatorTreeAnalysis |
71 | : public AnalysisInfoMixin<MachinePostDominatorTreeAnalysis> { |
72 | friend AnalysisInfoMixin<MachinePostDominatorTreeAnalysis>; |
73 | |
74 | LLVM_ABI static AnalysisKey Key; |
75 | |
76 | public: |
77 | using Result = MachinePostDominatorTree; |
78 | |
79 | LLVM_ABI Result run(MachineFunction &MF, |
80 | MachineFunctionAnalysisManager &MFAM); |
81 | }; |
82 | |
83 | class MachinePostDominatorTreePrinterPass |
84 | : public PassInfoMixin<MachinePostDominatorTreePrinterPass> { |
85 | raw_ostream &OS; |
86 | |
87 | public: |
88 | explicit MachinePostDominatorTreePrinterPass(raw_ostream &OS) : OS(OS) {} |
89 | LLVM_ABI PreservedAnalyses run(MachineFunction &MF, |
90 | MachineFunctionAnalysisManager &MFAM); |
91 | static bool isRequired() { return true; } |
92 | }; |
93 | |
94 | class LLVM_ABI MachinePostDominatorTreeWrapperPass |
95 | : public MachineFunctionPass { |
96 | std::optional<MachinePostDominatorTree> PDT; |
97 | |
98 | public: |
99 | static char ID; |
100 | |
101 | MachinePostDominatorTreeWrapperPass(); |
102 | |
103 | MachinePostDominatorTree &getPostDomTree() { return *PDT; } |
104 | const MachinePostDominatorTree &getPostDomTree() const { return *PDT; } |
105 | |
106 | bool runOnMachineFunction(MachineFunction &MF) override; |
107 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
108 | void releaseMemory() override { PDT.reset(); } |
109 | void verifyAnalysis() const override; |
110 | void print(llvm::raw_ostream &OS, const Module *M = nullptr) const override; |
111 | }; |
112 | } //end of namespace llvm |
113 | |
114 | #endif |
115 | |