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
66
67//===-------------------------------------
68/// DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to
69/// compute a normal dominator tree.
70///
72
73public:
75
78
79 /// Handle invalidation explicitly.
80 LLVM_ABI bool invalidate(MachineFunction &, const PreservedAnalyses &PA,
81 MachineFunctionAnalysisManager::Invalidator &);
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.
113
114/// \brief Machine function pass which print \c MachineDominatorTree.
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 <>
176
177template <>
182
186 return DT->getRootNode();
187 }
188};
189
190} // end namespace llvm
191
192#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:58
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: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.
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: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)
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:70