LLVM 19.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/Config/llvm-config.h"
24#include "llvm/IR/PassManager.h"
25#include "llvm/Pass.h"
27#include <cassert>
28#include <utility>
29
30namespace llvm {
31
32class BasicBlock;
33class Function;
34class raw_ostream;
35
36//===----------------------------------------------------------------------===//
37/// DominanceFrontierBase - Common base class for computing forward and inverse
38/// dominance frontiers for a function.
39///
40template <class BlockT, bool IsPostDom>
42public:
43 // Dom set for a bb. Use SetVector to make iterating dom frontiers of a bb
44 // deterministic.
47
48protected:
50
52 // Postdominators can have multiple roots.
54 static constexpr bool IsPostDominators = IsPostDom;
55
56public:
58
59 /// getRoots - Return the root blocks of the current CFG. This may include
60 /// multiple blocks if we are computing post dominators. For forward
61 /// dominators, this will always be a single block (the entry node).
62 const SmallVectorImpl<BlockT *> &getRoots() const { return Roots; }
63
64 BlockT *getRoot() const {
65 assert(Roots.size() == 1 && "Should always have entry node!");
66 return Roots[0];
67 }
68
69 /// isPostDominator - Returns true if analysis based of postdoms
70 bool isPostDominator() const {
71 return IsPostDominators;
72 }
73
76 }
77
78 // Accessor interface:
81
82 iterator begin() { return Frontiers.begin(); }
83 const_iterator begin() const { return Frontiers.begin(); }
84 iterator end() { return Frontiers.end(); }
85 const_iterator end() const { return Frontiers.end(); }
86 iterator find(BlockT *B) { return Frontiers.find(B); }
87 const_iterator find(BlockT *B) const { return Frontiers.find(B); }
88
89 iterator addBasicBlock(BlockT *BB, const DomSetType &frontier) {
90 assert(find(BB) == end() && "Block already in DominanceFrontier!");
91 return Frontiers.insert(std::make_pair(BB, frontier)).first;
92 }
93
94 /// removeBlock - Remove basic block BB's frontier.
95 void removeBlock(BlockT *BB);
96
97 void addToFrontier(iterator I, BlockT *Node);
98
99 void removeFromFrontier(iterator I, BlockT *Node);
100
101 /// compareDomSet - Return false if two domsets match. Otherwise
102 /// return true;
103 bool compareDomSet(DomSetType &DS1, const DomSetType &DS2) const;
104
105 /// compare - Return false if the other dominance frontier base matches
106 /// this dominance frontier base. Otherwise return true.
108
109 /// print - Convert to human readable form
110 ///
111 void print(raw_ostream &OS) const;
112
113 /// dump - Dump the dominance frontier to dbgs().
114#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
115 void dump() const;
116#endif
117};
118
119//===-------------------------------------
120/// DominanceFrontier Class - Concrete subclass of DominanceFrontierBase that is
121/// used to compute a forward dominator frontiers.
122///
123template <class BlockT>
125 : public DominanceFrontierBase<BlockT, false> {
126private:
128
129public:
133
134 void analyze(DomTreeT &DT) {
135 assert(DT.root_size() == 1 &&
136 "Only one entry block for forward domfronts!");
137 this->Roots = {DT.getRoot()};
138 calculate(DT, DT[this->Roots[0]]);
139 }
140
141 const DomSetType &calculate(const DomTreeT &DT, const DomTreeNodeT *Node);
142};
143
145public:
152
153 /// Handle invalidation explicitly.
154 bool invalidate(Function &F, const PreservedAnalyses &PA,
156};
157
160
161public:
162 static char ID; // Pass ID, replacement for typeid
163
165
167 const DominanceFrontier &getDominanceFrontier() const { return DF; }
168
169 void releaseMemory() override;
170
171 bool runOnFunction(Function &) override;
172
173 void getAnalysisUsage(AnalysisUsage &AU) const override;
174
175 void print(raw_ostream &OS, const Module * = nullptr) const override;
176
177 void dump() const;
178};
179
180extern template class DominanceFrontierBase<BasicBlock, false>;
181extern template class DominanceFrontierBase<BasicBlock, true>;
182extern template class ForwardDominanceFrontierBase<BasicBlock>;
183
184/// Analysis pass which computes a \c DominanceFrontier.
188
189 static AnalysisKey Key;
190
191public:
192 /// Provide the result type for this analysis pass.
194
195 /// Run the analysis pass over a function and produce a dominator tree.
197};
198
199/// Printer pass for the \c DominanceFrontier.
203
204public:
206
208
209 static bool isRequired() { return true; }
210};
211
212} // end namespace llvm
213
214#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...
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This header defines various interfaces for pass management in LLVM.
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:155
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
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
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...
bool compare(DominanceFrontierBase &Other) const
compare - Return false if the other dominance frontier base matches this dominance frontier base.
void print(raw_ostream &OS) const
print - Convert to human readable form
iterator addBasicBlock(BlockT *BB, const DomSetType &frontier)
const_iterator find(BlockT *B) const
typename DomSetMapType::iterator iterator
bool compareDomSet(DomSetType &DS1, const DomSetType &DS2) const
compareDomSet - Return false if two domsets match.
SmallVector< BlockT *, IsPostDom ? 4 :1 > Roots
const_iterator end() const
const SmallVectorImpl< BlockT * > & getRoots() const
getRoots - Return the root blocks of the current CFG.
void removeFromFrontier(iterator I, BlockT *Node)
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
SetVector< BlockT * > DomSetType
typename DomSetMapType::const_iterator const_iterator
void addToFrontier(iterator I, BlockT *Node)
const_iterator begin() const
void removeBlock(BlockT *BB)
removeBlock - Remove basic block BB's frontier.
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.
size_t root_size() const
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:311
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:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
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
@ Other
Any other memory.
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