LLVM 23.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// CAUTION: For SSA-construction-like problems there are more efficient ways to
13// do that, take a look at GenericIteratedDominanceFrontier.h/SSAUpdater.h. Also
14// note that that this analysis computes dominance frontiers for *every* block
15// which inherently increases complexity. Unless you do need *all* of them and
16// *without* any modifications to the DomTree/CFG in between queries there
17// should be better alternatives.
18//
19//===----------------------------------------------------------------------===//
20
21#ifndef LLVM_ANALYSIS_DOMINANCEFRONTIER_H
22#define LLVM_ANALYSIS_DOMINANCEFRONTIER_H
23
24#include "llvm/ADT/DenseMap.h"
26#include "llvm/ADT/SetVector.h"
27#include "llvm/IR/PassManager.h"
28#include "llvm/Pass.h"
30#include <cassert>
31
32namespace llvm {
33
34class BasicBlock;
35class Function;
36class raw_ostream;
37
38//===----------------------------------------------------------------------===//
39/// DominanceFrontierBase - Common base class for computing forward and inverse
40/// dominance frontiers for a function.
41///
42template <class BlockT, bool IsPostDom>
44public:
45 // Dom set for a bb. Use SetVector to make iterating dom frontiers of a bb
46 // deterministic.
51
52protected:
53 using GraphTy = std::conditional_t<IsPostDom, Inverse<BlockT *>, BlockT *>;
55
57 static constexpr bool IsPostDominators = IsPostDom;
58
59public:
61
62 /// isPostDominator - Returns true if analysis based of postdoms
63 bool isPostDominator() const {
64 return IsPostDominators;
65 }
66
68 Frontiers.clear();
69 }
70
71 // Accessor interface:
74
75 iterator begin() { return Frontiers.begin(); }
76 const_iterator begin() const { return Frontiers.begin(); }
77 iterator end() { return Frontiers.end(); }
78 const_iterator end() const { return Frontiers.end(); }
79 iterator find(BlockT *B) { return Frontiers.find(B); }
80 const_iterator find(BlockT *B) const { return Frontiers.find(B); }
81
82 /// print - Convert to human readable form
83 ///
84 void print(raw_ostream &OS) const;
85
86 /// dump - Dump the dominance frontier to dbgs().
87#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
88 void dump() const;
89#endif
90
91 void analyze(const DomTreeT &DT);
92};
93
94class DominanceFrontier : public DominanceFrontierBase<BasicBlock, false> {
95public:
101
102 /// Handle invalidation explicitly.
103 bool invalidate(Function &F, const PreservedAnalyses &PA,
104 FunctionAnalysisManager::Invalidator &);
105};
106
109
110public:
111 static char ID; // Pass ID, replacement for typeid
112
114
116 const DominanceFrontier &getDominanceFrontier() const { return DF; }
117
118 void releaseMemory() override;
119
120 bool runOnFunction(Function &) override;
121
122 void getAnalysisUsage(AnalysisUsage &AU) const override;
123
124 void print(raw_ostream &OS, const Module * = nullptr) const override;
125
126 void dump() const;
127};
128
129extern template class DominanceFrontierBase<BasicBlock, false>;
130extern template class DominanceFrontierBase<BasicBlock, true>;
131
132/// Analysis pass which computes a \c DominanceFrontier.
136
137 static AnalysisKey Key;
138
139public:
140 /// Provide the result type for this analysis pass.
142
143 /// Run the analysis pass over a function and produce a dominator tree.
145};
146
147/// Printer pass for the \c DominanceFrontier.
150 raw_ostream &OS;
151
152public:
154
156
157 static bool isRequired() { return true; }
158};
159
160} // end namespace llvm
161
162#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: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.
std::conditional_t< IsPostDom, Inverse< BlockT * >, BlockT * > GraphTy
void analyze(const DomTreeT &DT)
DominatorTreeBase< BlockT, IsPostDom > DomTreeT
void print(raw_ostream &OS) const
print - Convert to human readable form
const_iterator find(BlockT *B) const
typename DomSetMapType::iterator iterator
const_iterator end() const
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
DomTreeNodeBase< BlockT > DomTreeNodeT
GraphTraits< GraphTy > BlockTraits
SetVector< BlockT * > DomSetType
typename DomSetMapType::const_iterator const_iterator
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.
DominanceFrontier::const_iterator const_iterator
DomTreeNodeBase< BasicBlock > DomTreeNodeT
DomTreeBase< BasicBlock > DomTreeT
DominanceFrontier::iterator iterator
DominanceFrontier::DomSetType DomSetType
Core dominator tree base class.
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:57
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.
Definition Types.h:26
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:93
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:70