LLVM 22.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
28namespace llvm {
29
30class BasicBlock;
31class Function;
32class raw_ostream;
33
34//===----------------------------------------------------------------------===//
35/// DominanceFrontierBase - Common base class for computing forward and inverse
36/// dominance frontiers for a function.
37///
38template <class BlockT, bool IsPostDom>
40public:
41 // Dom set for a bb. Use SetVector to make iterating dom frontiers of a bb
42 // deterministic.
45
46protected:
48
50 // Postdominators can have multiple roots.
52 static constexpr bool IsPostDominators = IsPostDom;
53
54public:
56
57 /// getRoots - Return the root blocks of the current CFG. This may include
58 /// multiple blocks if we are computing post dominators. For forward
59 /// dominators, this will always be a single block (the entry node).
60 const SmallVectorImpl<BlockT *> &getRoots() const { return Roots; }
61
62 BlockT *getRoot() const {
63 assert(Roots.size() == 1 && "Should always have entry node!");
64 return Roots[0];
65 }
66
67 /// isPostDominator - Returns true if analysis based of postdoms
68 bool isPostDominator() const {
69 return IsPostDominators;
70 }
71
73 Frontiers.clear();
74 }
75
76 // Accessor interface:
79
80 iterator begin() { return Frontiers.begin(); }
81 const_iterator begin() const { return Frontiers.begin(); }
82 iterator end() { return Frontiers.end(); }
83 const_iterator end() const { return Frontiers.end(); }
84 iterator find(BlockT *B) { return Frontiers.find(B); }
85 const_iterator find(BlockT *B) const { return Frontiers.find(B); }
86
87 /// print - Convert to human readable form
88 ///
89 void print(raw_ostream &OS) const;
90
91 /// dump - Dump the dominance frontier to dbgs().
92#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
93 void dump() const;
94#endif
95};
96
97//===-------------------------------------
98/// DominanceFrontier Class - Concrete subclass of DominanceFrontierBase that is
99/// used to compute a forward dominator frontiers.
100///
101template <class BlockT>
103 : public DominanceFrontierBase<BlockT, false> {
104private:
105 using BlockTraits = GraphTraits<BlockT *>;
106
107public:
111
112 void analyze(DomTreeT &DT) {
113 assert(DT.root_size() == 1 &&
114 "Only one entry block for forward domfronts!");
115 this->Roots = {DT.getRoot()};
116 calculate(DT, DT[this->Roots[0]]);
117 }
118
119 const DomSetType &calculate(const DomTreeT &DT, const DomTreeNodeT *Node);
120};
121
135
138
139public:
140 static char ID; // Pass ID, replacement for typeid
141
143
145 const DominanceFrontier &getDominanceFrontier() const { return DF; }
146
147 void releaseMemory() override;
148
149 bool runOnFunction(Function &) override;
150
151 void getAnalysisUsage(AnalysisUsage &AU) const override;
152
153 void print(raw_ostream &OS, const Module * = nullptr) const override;
154
155 void dump() const;
156};
157
158extern template class DominanceFrontierBase<BasicBlock, false>;
159extern template class DominanceFrontierBase<BasicBlock, true>;
160extern template class ForwardDominanceFrontierBase<BasicBlock>;
161
162/// Analysis pass which computes a \c DominanceFrontier.
166
167 static AnalysisKey Key;
168
169public:
170 /// Provide the result type for this analysis pass.
172
173 /// Run the analysis pass over a function and produce a dominator tree.
175};
176
177/// Printer pass for the \c DominanceFrontier.
180 raw_ostream &OS;
181
182public:
184
186
187 static bool isRequired() { return true; }
188};
189
190} // end namespace llvm
191
192#endif // LLVM_ANALYSIS_DOMINANCEFRONTIER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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:54
This file implements a set that has insertion order iteration characteristics.
Represent the analysis usage information of a pass.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
Definition DenseMap.h:74
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Definition DenseMap.h:75
Base class for the actual dominator tree node.
Analysis pass which computes a DominanceFrontier.
DominanceFrontier Result
Provide the result type for this analysis pass.
DominanceFrontier run(Function &F, FunctionAnalysisManager &AM)
Run the analysis pass over a function and produce a dominator tree.
void print(raw_ostream &OS) const
print - Convert to human readable form
const_iterator find(BlockT *B) const
GraphTraits< BlockT * > BlockTraits
typename DomSetMapType::iterator iterator
SmallVector< BasicBlock *, 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
DenseMap< BlockT *, DomSetType > DomSetMapType
SetVector< BlockT * > DomSetType
typename DomSetMapType::const_iterator const_iterator
DomSetMapType Frontiers
const_iterator begin() const
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
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.
DomTreeNodeBase< BasicBlock > DomTreeNodeT
DomTreeBase< BasicBlock > DomTreeT
DominanceFrontierBase< BasicBlock, false >::iterator iterator
DominanceFrontierBase< BasicBlock, false >::const_iterator const_iterator
DominanceFrontierBase< BasicBlock, false >::DomSetType DomSetType
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(char &pid)
Definition Pass.h:316
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
A vector that has set insertion semantics.
Definition SetVector.h:58
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
DominatorTreeBase< T, false > DomTreeBase
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
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
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition PassManager.h:69