LLVM 22.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"
26#include <cassert>
27#include <memory>
28#include <optional>
29
30namespace llvm {
31class AnalysisUsage;
32class MachineFunction;
33class Module;
34class raw_ostream;
35
37extern template class LLVM_TEMPLATE_ABI
39
41
42namespace DomTreeBuilder {
46
47extern template LLVM_TEMPLATE_ABI void Calculate<MBBDomTree>(MBBDomTree &DT);
48extern template LLVM_TEMPLATE_ABI void
49CalculateWithUpdates<MBBDomTree>(MBBDomTree &DT, MBBUpdates U);
50
51extern template LLVM_TEMPLATE_ABI void
52InsertEdge<MBBDomTree>(MBBDomTree &DT, MachineBasicBlock *From,
54
55extern template LLVM_TEMPLATE_ABI void
56DeleteEdge<MBBDomTree>(MBBDomTree &DT, MachineBasicBlock *From,
58
59extern template LLVM_TEMPLATE_ABI void
60ApplyUpdates<MBBDomTree>(MBBDomTree &DT, MBBDomTreeGraphDiff &,
62
63extern template LLVM_TEMPLATE_ABI bool
64Verify<MBBDomTree>(const MBBDomTree &DT, MBBDomTree::VerificationLevel VL);
65} // namespace DomTreeBuilder
66
67//===-------------------------------------
68/// DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to
69/// compute a normal dominator tree.
70///
72
73public:
75
77 explicit MachineDominatorTree(MachineFunction &MF) { recalculate(MF); }
78
79 /// Handle invalidation explicitly.
80 LLVM_ABI bool invalidate(MachineFunction &, const PreservedAnalyses &PA,
82
83 using Base::dominates;
84
85 // dominates - Return true if A dominates B. This performs the
86 // special checks necessary if A and B are in the same basic block.
87 bool dominates(const MachineInstr *A, const MachineInstr *B) const {
88 const MachineBasicBlock *BBA = A->getParent(), *BBB = B->getParent();
89 if (BBA != BBB)
90 return Base::dominates(BBA, BBB);
91
92 // Loop through the basic block until we find A or B.
94 for (; &*I != A && &*I != B; ++I)
95 /*empty*/ ;
96
97 return &*I == A;
98 }
99};
100
101/// \brief Analysis pass which computes a \c MachineDominatorTree.
105
106 LLVM_ABI static AnalysisKey Key;
107
108public:
110
112};
113
114/// \brief Machine function pass which print \c MachineDominatorTree.
118
119public:
123 static bool isRequired() { return true; }
124};
125
126/// \brief Analysis pass which computes a \c MachineDominatorTree.
128 // MachineFunctionPass may verify the analysis result without running pass,
129 // e.g. when `F.hasAvailableExternallyLinkage` is true.
130 std::optional<MachineDominatorTree> DT;
131
132public:
133 static char ID;
134
136
138 const MachineDominatorTree &getDomTree() const { return *DT; }
139
140 bool runOnMachineFunction(MachineFunction &MF) override;
141
142 void verifyAnalysis() const override;
143
144 void getAnalysisUsage(AnalysisUsage &AU) const override {
145 AU.setPreservesAll();
147 }
148
149 void releaseMemory() override;
150
151 void print(raw_ostream &OS, const Module *M = nullptr) const override;
152};
153
154//===-------------------------------------
155/// DominatorTree GraphTraits specialization so the DominatorTree can be
156/// iterable by generic graph iterators.
157///
158
159template <class Node, class ChildIterator>
161 using NodeRef = Node *;
162 using ChildIteratorType = ChildIterator;
163
164 static NodeRef getEntryNode(NodeRef N) { return N; }
165 static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
166 static ChildIteratorType child_end(NodeRef N) { return N->end(); }
167};
168
169template <class T> struct GraphTraits;
170
171template <>
175};
176
177template <>
181};
182
186 return DT->getRootNode();
187 }
188};
189
190} // end namespace llvm
191
192#endif // LLVM_CODEGEN_MACHINEDOMINATORS_H
aarch64 promote const
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_ABI
Definition: Compiler.h:213
#define LLVM_TEMPLATE_ABI
Definition: Compiler.h:214
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:294
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:255
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.
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:72
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:112
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
template class LLVM_TEMPLATE_ABI DomTreeNodeBase< MachineBasicBlock >
template class LLVM_TEMPLATE_ABI DominatorTreeBase< MachineBasicBlock, false >
DomTreeNodeBase< MachineBasicBlock > MachineDomTreeNode
#define N
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:93
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:29
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:70