LLVM 20.0.0git
PostDominators.h
Go to the documentation of this file.
1//=- llvm/Analysis/PostDominators.h - Post Dominator 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 exposes interfaces to post dominance information.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_ANALYSIS_POSTDOMINATORS_H
14#define LLVM_ANALYSIS_POSTDOMINATORS_H
15
17#include "llvm/IR/Dominators.h"
18#include "llvm/IR/PassManager.h"
19#include "llvm/Pass.h"
20
21namespace llvm {
22
23class Function;
24class raw_ostream;
25
26/// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
27/// compute the post-dominator tree.
28class PostDominatorTree : public PostDomTreeBase<BasicBlock> {
29public:
31
32 PostDominatorTree() = default;
34 /// Handle invalidation explicitly.
37
38 // Ensure base-class overloads are visible.
39 using Base::dominates;
40
41 /// Return true if \p I1 dominates \p I2. This checks if \p I2 comes before
42 /// \p I1 if they belongs to the same basic block.
43 bool dominates(const Instruction *I1, const Instruction *I2) const;
44};
45
46/// Analysis pass which computes a \c PostDominatorTree.
48 : public AnalysisInfoMixin<PostDominatorTreeAnalysis> {
50
51 static AnalysisKey Key;
52
53public:
54 /// Provide the result type for this analysis pass.
56
57 /// Run the analysis pass over a function and produce a post dominator
58 /// tree.
60};
61
62/// Printer pass for the \c PostDominatorTree.
64 : public PassInfoMixin<PostDominatorTreePrinterPass> {
65 raw_ostream &OS;
66
67public:
69
71
72 static bool isRequired() { return true; }
73};
74
76 static char ID; // Pass identification, replacement for typeid
77
79
81
83 const PostDominatorTree &getPostDomTree() const { return DT; }
84
85 bool runOnFunction(Function &F) override;
86
87 void verifyAnalysis() const override;
88
89 void getAnalysisUsage(AnalysisUsage &AU) const override {
90 AU.setPreservesAll();
91 }
92
93 void releaseMemory() override { DT.reset(); }
94
95 void print(raw_ostream &OS, const Module*) const override;
96};
97
98FunctionPass* createPostDomTree();
99
100template <> struct GraphTraits<PostDominatorTree*>
103 return DT->getRootNode();
104 }
105
107 return df_begin(getEntryNode(N));
108 }
109
111 return df_end(getEntryNode(N));
112 }
113};
114
115} // end namespace llvm
116
117#endif // LLVM_ANALYSIS_POSTDOMINATORS_H
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition: MD5.cpp:55
raw_pwrite_stream & OS
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.
void setPreservesAll()
Set by analyses that do not transform their input at all.
Core dominator tree base class.
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
bool dominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
dominates - Returns true iff A dominates B.
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
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
Analysis pass which computes a PostDominatorTree.
PostDominatorTree run(Function &F, FunctionAnalysisManager &)
Run the analysis pass over a function and produce a post dominator tree.
Printer pass for the PostDominatorTree.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
PostDominatorTree(Function &F)
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly.
bool dominates(const Instruction *I1, const Instruction *I2) const
Return true if I1 dominates I2.
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
df_iterator< T > df_begin(const T &G)
FunctionPass * createPostDomTree()
df_iterator< T > df_end(const T &G)
#define N
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
static NodeRef getEntryNode(PostDominatorTree *DT)
static nodes_iterator nodes_end(PostDominatorTree *N)
static nodes_iterator nodes_begin(PostDominatorTree *N)
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing 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...
const PostDominatorTree & getPostDomTree() const
void print(raw_ostream &OS, const Module *) const override
print - Print out the internal state of the pass.
PostDominatorTree & getPostDomTree()
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...