LLVM 23.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 <optional>
28
29namespace llvm {
30class AnalysisUsage;
31class MachineFunction;
32class Module;
33class raw_ostream;
34
36extern template class LLVM_TEMPLATE_ABI
38
40
65
66//===-------------------------------------
67/// DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to
68/// compute a normal dominator tree.
69///
71
72public:
74
77
78 /// Handle invalidation explicitly.
79 LLVM_ABI bool invalidate(MachineFunction &, const PreservedAnalyses &PA,
80 MachineFunctionAnalysisManager::Invalidator &);
81
82 using Base::dominates;
83
84 // dominates - Return true if A dominates B. This performs the
85 // special checks necessary if A and B are in the same basic block.
86 bool dominates(const MachineInstr *A, const MachineInstr *B) const {
87 const MachineBasicBlock *BBA = A->getParent(), *BBB = B->getParent();
88 if (BBA != BBB)
89 return Base::dominates(BBA, BBB);
90
91 // Loop through the basic block until we find A or B.
93 for (; &*I != A && &*I != B; ++I)
94 /*empty*/ ;
95
96 return &*I == A;
97 }
98};
99
100/// \brief Analysis pass which computes a \c MachineDominatorTree.
112
113/// \brief Machine function pass which print \c MachineDominatorTree.
123
124/// \brief Analysis pass which computes a \c MachineDominatorTree.
126 // MachineFunctionPass may verify the analysis result without running pass,
127 // e.g. when `F.hasAvailableExternallyLinkage` is true.
128 std::optional<MachineDominatorTree> DT;
129
130public:
131 static char ID;
132
134
136 const MachineDominatorTree &getDomTree() const { return *DT; }
137
138 bool runOnMachineFunction(MachineFunction &MF) override;
139
140 void verifyAnalysis() const override;
141
142 void getAnalysisUsage(AnalysisUsage &AU) const override {
143 AU.setPreservesAll();
145 }
146
147 void releaseMemory() override;
148
149 void print(raw_ostream &OS, const Module *M = nullptr) const override;
150};
151
152//===-------------------------------------
153/// DominatorTree GraphTraits specialization so the DominatorTree can be
154/// iterable by generic graph iterators.
155///
156
157template <class Node, class ChildIterator>
159 using NodeRef = Node *;
160 using ChildIteratorType = ChildIterator;
161
162 static NodeRef getEntryNode(NodeRef N) { return N; }
163 static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
164 static ChildIteratorType child_end(NodeRef N) { return N->end(); }
165};
166
167template <class T> struct GraphTraits;
168
169template <>
172 MachineDomTreeNode::const_iterator> {
173};
174
175template <>
178 MachineDomTreeNode::const_iterator> {
179};
180
184 return DT->getRootNode();
185 }
186};
187
188} // end namespace llvm
189
190#endif // LLVM_CODEGEN_MACHINEDOMINATORS_H
aarch64 promote const
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#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:57
This file defines the SmallSet class.
This file defines the SmallVector class.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Base class for the actual dominator tree node.
Core dominator tree base class.
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
bool dominates(const DomTreeNodeBase< T > *A, const DomTreeNodeBase< T > *B) const
MachineInstrBundleIterator< const MachineInstr > const_iterator
Analysis pass which computes a MachineDominatorTree.
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &)
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
DomTreeBase< MachineBasicBlock > Base
MachineDominatorTree(MachineFunction &MF)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Representation of each machine instruction.
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
bool Verify(const DomTreeT &DT, typename DomTreeT::VerificationLevel VL)
void CalculateWithUpdates(DomTreeT &DT, ArrayRef< typename DomTreeT::UpdateType > Updates)
GraphDiff< MachineBasicBlock *, false > MBBDomTreeGraphDiff
void DeleteEdge(DomTreeT &DT, typename DomTreeT::NodePtr From, typename DomTreeT::NodePtr To)
ArrayRef< llvm::cfg::Update< MachineBasicBlock * > > MBBUpdates
DomTreeBase< MachineBasicBlock > MBBDomTree
void ApplyUpdates(DomTreeT &DT, GraphDiff< typename DomTreeT::NodePtr, DomTreeT::IsPostDominator > &PreViewCFG, GraphDiff< typename DomTreeT::NodePtr, DomTreeT::IsPostDominator > *PostViewCFG)
void InsertEdge(DomTreeT &DT, typename DomTreeT::NodePtr From, typename DomTreeT::NodePtr To)
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
DominatorTreeBase< T, false > DomTreeBase
DomTreeNodeBase< MachineBasicBlock > MachineDomTreeNode
#define N
A CRTP mix-in that provides informational APIs needed for analysis passes.
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)
typename MachineDominatorTree *::UnknownGraphTypeError NodeRef
Definition GraphTraits.h:95
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 for passes that should not be skipped.