LLVM 20.0.0git
MachineDominators.h
Go to the documentation of this file.
1//==- llvm/CodeGen/MachineDominators.h - Machine Dom Calculation -*- 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 defines classes mirroring those in llvm/Analysis/Dominators.h,
10// but for target-specific code rather than target-independent IR.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CODEGEN_MACHINEDOMINATORS_H
15#define LLVM_CODEGEN_MACHINEDOMINATORS_H
16
17#include "llvm/ADT/SmallSet.h"
25#include <cassert>
26#include <memory>
27#include <optional>
28
29namespace llvm {
30class AnalysisUsage;
31class MachineFunction;
32class Module;
33class raw_ostream;
34
35template <>
38 this->Roots.push_back(MBB);
39}
40
41extern template class DomTreeNodeBase<MachineBasicBlock>;
42extern template class DominatorTreeBase<MachineBasicBlock, false>; // DomTree
43
45
46namespace DomTreeBuilder {
50
51extern template void Calculate<MBBDomTree>(MBBDomTree &DT);
52extern template void CalculateWithUpdates<MBBDomTree>(MBBDomTree &DT,
53 MBBUpdates U);
54
55extern template void InsertEdge<MBBDomTree>(MBBDomTree &DT,
58
59extern template void DeleteEdge<MBBDomTree>(MBBDomTree &DT,
62
63extern template void ApplyUpdates<MBBDomTree>(MBBDomTree &DT,
66
67extern template bool Verify<MBBDomTree>(const MBBDomTree &DT,
69} // namespace DomTreeBuilder
70
71//===-------------------------------------
72/// DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to
73/// compute a normal dominator tree.
74///
76
77public:
79
81 explicit MachineDominatorTree(MachineFunction &MF) { recalculate(MF); }
82
83 /// Handle invalidation explicitly.
84 bool invalidate(MachineFunction &, const PreservedAnalyses &PA,
86
87 using Base::dominates;
88
89 // dominates - Return true if A dominates B. This performs the
90 // special checks necessary if A and B are in the same basic block.
91 bool dominates(const MachineInstr *A, const MachineInstr *B) const {
92 const MachineBasicBlock *BBA = A->getParent(), *BBB = B->getParent();
93 if (BBA != BBB)
94 return Base::dominates(BBA, BBB);
95
96 // Loop through the basic block until we find A or B.
98 for (; &*I != A && &*I != B; ++I)
99 /*empty*/ ;
100
101 return &*I == A;
102 }
103};
104
105/// \brief Analysis pass which computes a \c MachineDominatorTree.
109
110 static AnalysisKey Key;
111
112public:
114
116};
117
118/// \brief Machine function pass which print \c MachineDominatorTree.
122
123public:
127 static bool isRequired() { return true; }
128};
129
130/// \brief Analysis pass which computes a \c MachineDominatorTree.
132 // MachineFunctionPass may verify the analysis result without running pass,
133 // e.g. when `F.hasAvailableExternallyLinkage` is true.
134 std::optional<MachineDominatorTree> DT;
135
136public:
137 static char ID;
138
140
142 const MachineDominatorTree &getDomTree() const { return *DT; }
143
144 bool runOnMachineFunction(MachineFunction &MF) override;
145
146 void verifyAnalysis() const override;
147
148 void getAnalysisUsage(AnalysisUsage &AU) const override {
149 AU.setPreservesAll();
151 }
152
153 void releaseMemory() override;
154
155 void print(raw_ostream &OS, const Module *M = nullptr) const override;
156};
157
158//===-------------------------------------
159/// DominatorTree GraphTraits specialization so the DominatorTree can be
160/// iterable by generic graph iterators.
161///
162
163template <class Node, class ChildIterator>
165 using NodeRef = Node *;
166 using ChildIteratorType = ChildIterator;
167
168 static NodeRef getEntryNode(NodeRef N) { return N; }
169 static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
170 static ChildIteratorType child_end(NodeRef N) { return N->end(); }
171};
172
173template <class T> struct GraphTraits;
174
175template <>
179};
180
181template <>
185};
186
190 return DT->getRootNode();
191 }
192};
193
194} // end namespace llvm
195
196#endif // LLVM_CODEGEN_MACHINEDOMINATORS_H
aarch64 promote const
MachineBasicBlock & MBB
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file defines a set of templates that efficiently compute a dominator tree over a generic graph.
#define I(x, y, z)
Definition: MD5.cpp:58
Machine Check Debug Module
raw_pwrite_stream & OS
This file defines the SmallSet class.
This file defines the SmallVector class.
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:292
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Base class for the actual dominator tree node.
typename SmallVector< DomTreeNodeBase *, 4 >::const_iterator const_iterator
Core dominator tree base class.
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
void addRoot(NodeT *BB)
Analysis pass which computes a MachineDominatorTree.
Machine function pass which print MachineDominatorTree.
Analysis pass which computes a MachineDominatorTree.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
const MachineDominatorTree & getDomTree() const
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
bool dominates(const MachineInstr *A, const MachineInstr *B) const
MachineDominatorTree(MachineFunction &MF)
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Representation of each machine instruction.
Definition: MachineInstr.h:69
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
DomTreeNodeBase< MachineBasicBlock > MachineDomTreeNode
#define N
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
static NodeRef getEntryNode(MachineDominatorTree *DT)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
static ChildIteratorType child_end(NodeRef N)
static NodeRef getEntryNode(NodeRef N)
static ChildIteratorType child_begin(NodeRef N)
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69