|
15 | 15 | #define LLVM_CODEGEN_MACHINEPOSTDOMINATORS_H
|
16 | 16 |
|
17 | 17 | #include "llvm/CodeGen/MachineDominators.h"
|
18 |
| -#include "llvm/CodeGen/MachineFunctionPass.h" |
19 |
| -#include <memory> |
20 | 18 |
|
21 | 19 | namespace llvm {
|
22 | 20 |
|
| 21 | +extern template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTree |
| 22 | + |
| 23 | +namespace DomTreeBuilder { |
| 24 | +using MBBPostDomTree = PostDomTreeBase<MachineBasicBlock>; |
| 25 | +using MBBPostDomTreeGraphDiff = GraphDiff<MachineBasicBlock *, true>; |
| 26 | + |
| 27 | +extern template void Calculate<MBBPostDomTree>(MBBPostDomTree &DT); |
| 28 | +extern template void InsertEdge<MBBPostDomTree>(MBBPostDomTree &DT, |
| 29 | + MachineBasicBlock *From, |
| 30 | + MachineBasicBlock *To); |
| 31 | +extern template void DeleteEdge<MBBPostDomTree>(MBBPostDomTree &DT, |
| 32 | + MachineBasicBlock *From, |
| 33 | + MachineBasicBlock *To); |
| 34 | +extern template void ApplyUpdates<MBBPostDomTree>(MBBPostDomTree &DT, |
| 35 | + MBBPostDomTreeGraphDiff &, |
| 36 | + MBBPostDomTreeGraphDiff *); |
| 37 | +extern template bool |
| 38 | +Verify<MBBPostDomTree>(const MBBPostDomTree &DT, |
| 39 | + MBBPostDomTree::VerificationLevel VL); |
| 40 | +} // namespace DomTreeBuilder |
| 41 | + |
23 | 42 | ///
|
24 | 43 | /// MachinePostDominatorTree - an analysis pass wrapper for DominatorTree
|
25 | 44 | /// used to compute the post-dominator tree for MachineFunctions.
|
26 | 45 | ///
|
27 |
| -class MachinePostDominatorTree : public MachineFunctionPass { |
28 |
| - using PostDomTreeT = PostDomTreeBase<MachineBasicBlock>; |
29 |
| - std::unique_ptr<PostDomTreeT> PDT; |
| 46 | +class MachinePostDominatorTree : public PostDomTreeBase<MachineBasicBlock> { |
| 47 | + using Base = PostDomTreeBase<MachineBasicBlock>; |
30 | 48 |
|
31 | 49 | public:
|
32 |
| - static char ID; |
33 |
| - |
34 |
| - MachinePostDominatorTree(); |
35 |
| - |
36 |
| - PostDomTreeT &getBase() { |
37 |
| - if (!PDT) |
38 |
| - PDT.reset(new PostDomTreeT()); |
39 |
| - return *PDT; |
40 |
| - } |
41 |
| - |
42 |
| - FunctionPass *createMachinePostDominatorTreePass(); |
43 |
| - |
44 |
| - MachineDomTreeNode *getRootNode() const { return PDT->getRootNode(); } |
45 |
| - |
46 |
| - MachineDomTreeNode *operator[](MachineBasicBlock *BB) const { |
47 |
| - return PDT->getNode(BB); |
48 |
| - } |
49 |
| - |
50 |
| - MachineDomTreeNode *getNode(MachineBasicBlock *BB) const { |
51 |
| - return PDT->getNode(BB); |
52 |
| - } |
53 |
| - |
54 |
| - bool dominates(const MachineDomTreeNode *A, |
55 |
| - const MachineDomTreeNode *B) const { |
56 |
| - return PDT->dominates(A, B); |
57 |
| - } |
58 |
| - |
59 |
| - bool dominates(const MachineBasicBlock *A, const MachineBasicBlock *B) const { |
60 |
| - return PDT->dominates(A, B); |
61 |
| - } |
| 50 | + MachinePostDominatorTree() = default; |
62 | 51 |
|
63 |
| - bool properlyDominates(const MachineDomTreeNode *A, |
64 |
| - const MachineDomTreeNode *B) const { |
65 |
| - return PDT->properlyDominates(A, B); |
66 |
| - } |
67 |
| - |
68 |
| - bool properlyDominates(const MachineBasicBlock *A, |
69 |
| - const MachineBasicBlock *B) const { |
70 |
| - return PDT->properlyDominates(A, B); |
71 |
| - } |
72 |
| - |
73 |
| - bool isVirtualRoot(const MachineDomTreeNode *Node) const { |
74 |
| - return PDT->isVirtualRoot(Node); |
75 |
| - } |
76 |
| - |
77 |
| - MachineBasicBlock *findNearestCommonDominator(MachineBasicBlock *A, |
78 |
| - MachineBasicBlock *B) const { |
79 |
| - return PDT->findNearestCommonDominator(A, B); |
80 |
| - } |
| 52 | + /// Make findNearestCommonDominator(const NodeT *A, const NodeT *B) available. |
| 53 | + using Base::findNearestCommonDominator; |
81 | 54 |
|
82 | 55 | /// Returns the nearest common dominator of the given blocks.
|
83 | 56 | /// If that tree node is a virtual root, a nullptr will be returned.
|
84 | 57 | MachineBasicBlock *
|
85 | 58 | findNearestCommonDominator(ArrayRef<MachineBasicBlock *> Blocks) const;
|
| 59 | +}; |
| 60 | + |
| 61 | +class MachinePostDominatorTreeWrapperPass : public MachineFunctionPass { |
| 62 | + std::optional<MachinePostDominatorTree> PDT; |
| 63 | + |
| 64 | +public: |
| 65 | + static char ID; |
| 66 | + |
| 67 | + MachinePostDominatorTreeWrapperPass(); |
| 68 | + |
| 69 | + MachinePostDominatorTree &getPostDomTree() { return *PDT; } |
| 70 | + const MachinePostDominatorTree &getPostDomTree() const { return *PDT; } |
86 | 71 |
|
87 | 72 | bool runOnMachineFunction(MachineFunction &MF) override;
|
88 | 73 | void getAnalysisUsage(AnalysisUsage &AU) const override;
|
89 |
| - void releaseMemory() override { PDT.reset(nullptr); } |
| 74 | + void releaseMemory() override { PDT.reset(); } |
90 | 75 | void verifyAnalysis() const override;
|
91 | 76 | void print(llvm::raw_ostream &OS, const Module *M = nullptr) const override;
|
92 | 77 | };
|
|
0 commit comments