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 <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.
124
125/// \brief Analysis pass which computes a \c MachineDominatorTree.
127 // MachineFunctionPass may verify the analysis result without running pass,
128 // e.g. when `F.hasAvailableExternallyLinkage` is true.
129 std::optional<MachineDominatorTree> DT;
130
131public:
132 static char ID;
133
135
137 const MachineDominatorTree &getDomTree() const { return *DT; }
138
139 bool runOnMachineFunction(MachineFunction &MF) override;
140
141 void verifyAnalysis() const override;
142
143 void getAnalysisUsage(AnalysisUsage &AU) const override {
144 AU.setPreservesAll();
146 }
147
148 void releaseMemory() override;
149
150 void print(raw_ostream &OS, const Module *M = nullptr) const override;
151};
152
153//===-------------------------------------
154/// DominatorTree GraphTraits specialization so the DominatorTree can be
155/// iterable by generic graph iterators.
156///
157
158template <class Node, class ChildIterator>
160 using NodeRef = Node *;
161 using ChildIteratorType = ChildIterator;
162
163 static NodeRef getEntryNode(NodeRef N) { return N; }
164 static ChildIteratorType child_begin(NodeRef N) { return N->begin(); }
165 static ChildIteratorType child_end(NodeRef N) { return N->end(); }
166};
167
168template <class T> struct GraphTraits;
169
170template <>
175
176template <>
181
185 return DT->getRootNode();
186 }
187};
188
189} // end namespace llvm
190
191#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.
ArrayRef - 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.
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.
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.
Definition PassManager.h:92
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 to automatically provide informational APIs needed for passes.
Definition PassManager.h:69