LLVM 20.0.0git
DominanceFrontier.h
Go to the documentation of this file.
1//===- llvm/Analysis/DominanceFrontier.h - Dominator Frontiers --*- 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 the DominanceFrontier class, which calculate and holds the
10// dominance frontier for a function.
11//
12// This should be considered deprecated, don't add any more uses of this data
13// structure.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_ANALYSIS_DOMINANCEFRONTIER_H
18#define LLVM_ANALYSIS_DOMINANCEFRONTIER_H
19
20#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/SetVector.h"
23#include "llvm/IR/PassManager.h"
24#include "llvm/Pass.h"
26#include <cassert>
27#include <utility>
28
29namespace llvm {
30
31class BasicBlock;
32class Function;
33class raw_ostream;
34
35//===----------------------------------------------------------------------===//
36/// DominanceFrontierBase - Common base class for computing forward and inverse
37/// dominance frontiers for a function.
38///
39template <class BlockT, bool IsPostDom>
41public:
42 // Dom set for a bb. Use SetVector to make iterating dom frontiers of a bb
43 // deterministic.
46
47protected:
49
51 // Postdominators can have multiple roots.
53 static constexpr bool IsPostDominators = IsPostDom;
54
55public:
57
58 /// getRoots - Return the root blocks of the current CFG. This may include
59 /// multiple blocks if we are computing post dominators. For forward
60 /// dominators, this will always be a single block (the entry node).
61 const SmallVectorImpl<BlockT *> &getRoots() const { return Roots; }
62
63 BlockT *getRoot() const {
64 assert(Roots.size() == 1 && "Should always have entry node!");
65 return Roots[0];
66 }
67
68 /// isPostDominator - Returns true if analysis based of postdoms
69 bool isPostDominator() const {
70 return IsPostDominators;
71 }
72
75 }
76
77 // Accessor interface:
80
81 iterator begin() { return Frontiers.begin(); }
82 const_iterator begin() const { return Frontiers.begin(); }
83 iterator end() { return Frontiers.end(); }
84 const_iterator end() const { return Frontiers.end(); }
85 iterator find(BlockT *B) { return Frontiers.find(B); }
86 const_iterator find(BlockT *B) const { return Frontiers.find(B); }
87
88 /// print - Convert to human readable form
89 ///
90 void print(raw_ostream &OS) const;
91
92 /// dump - Dump the dominance frontier to dbgs().
93#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
94 void dump() const;
95#endif
96};
97
98//===-------------------------------------
99/// DominanceFrontier Class - Concrete subclass of DominanceFrontierBase that is
100/// used to compute a forward dominator frontiers.
101///
102template <class BlockT>
104 : public DominanceFrontierBase<BlockT, false> {
105private:
107
108public:
112
113 void analyze(DomTreeT &DT) {
114 assert(DT.root_size() == 1 &&
115 "Only one entry block for forward domfronts!");
116 this->Roots = {DT.getRoot()};
117 calculate(DT, DT[this->Roots[0]]);
118 }
119
120 const DomSetType &calculate(const DomTreeT &DT, const DomTreeNodeT *Node);
121};
122
124public:
131
132 /// Handle invalidation explicitly.
133 bool invalidate(Function &F, const PreservedAnalyses &PA,
135};
136
139
140public:
141 static char ID; // Pass ID, replacement for typeid
142
144
146 const DominanceFrontier &getDominanceFrontier() const { return DF; }
147
148 void releaseMemory() override;
149
150 bool runOnFunction(Function &) override;
151
152 void getAnalysisUsage(AnalysisUsage &AU) const override;
153
154 void print(raw_ostream &OS, const Module * = nullptr) const override;
155
156 void dump() const;
157};
158
159extern template class DominanceFrontierBase<BasicBlock, false>;
160extern template class DominanceFrontierBase<BasicBlock, true>;
161extern template class ForwardDominanceFrontierBase<BasicBlock>;
162
163/// Analysis pass which computes a \c DominanceFrontier.
167
168 static AnalysisKey Key;
169
170public:
171 /// Provide the result type for this analysis pass.
173
174 /// Run the analysis pass over a function and produce a dominator tree.
176};
177
178/// Printer pass for the \c DominanceFrontier.
182
183public:
185
187
188 static bool isRequired() { return true; }
189};
190
191} // end namespace llvm
192
193#endif // LLVM_ANALYSIS_DOMINANCEFRONTIER_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseMap class.
This file defines a set of templates that efficiently compute a dominator tree over a generic graph.
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This file implements a set that has insertion order iteration characteristics.
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.
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:156
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
Definition: DenseMap.h:71
iterator begin()
Definition: DenseMap.h:75
iterator end()
Definition: DenseMap.h:84
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Definition: DenseMap.h:73
Base class for the actual dominator tree node.
Analysis pass which computes a DominanceFrontier.
DominanceFrontierBase - Common base class for computing forward and inverse dominance frontiers for a...
void print(raw_ostream &OS) const
print - Convert to human readable form
const_iterator find(BlockT *B) const
typename DomSetMapType::iterator iterator
SmallVector< BlockT *, IsPostDom ? 4 :1 > Roots
const_iterator end() const
const SmallVectorImpl< BlockT * > & getRoots() const
getRoots - Return the root blocks of the current CFG.
static constexpr bool IsPostDominators
void dump() const
dump - Dump the dominance frontier to dbgs().
bool isPostDominator() const
isPostDominator - Returns true if analysis based of postdoms
typename DomSetMapType::const_iterator const_iterator
const_iterator begin() const
Printer pass for the DominanceFrontier.
const DominanceFrontier & getDominanceFrontier() const
bool runOnFunction(Function &) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void print(raw_ostream &OS, const Module *=nullptr) const override
print - Print out the internal state of the pass.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
DominanceFrontier & getDominanceFrontier()
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly.
DominanceFrontierBase< BasicBlock, false >::iterator iterator
DominanceFrontierBase< BasicBlock, false >::DomSetType DomSetType
DominanceFrontierBase< BasicBlock, false >::const_iterator const_iterator
Core dominator tree base class.
NodeT * getRoot() const
DominanceFrontier Class - Concrete subclass of DominanceFrontierBase that is used to compute a forwar...
const DomSetType & calculate(const DomTreeT &DT, const DomTreeNodeT *Node)
typename DominanceFrontierBase< BlockT, false >::DomSetType DomSetType
DomTreeNodeBase< BlockT > DomTreeNodeT
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:310
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
A vector that has set insertion semantics.
Definition: SetVector.h:57
size_t size() const
Definition: SmallVector.h:78
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69