LLVM 22.0.0git
PostDominators.cpp
Go to the documentation of this file.
1//===- PostDominators.cpp - Post-Dominator Calculation --------------------===//
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 implements the post-dominator construction algorithms.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/IR/Function.h"
16#include "llvm/IR/PassManager.h"
18#include "llvm/Pass.h"
20
21using namespace llvm;
22
23#define DEBUG_TYPE "postdomtree"
24
25#ifdef EXPENSIVE_CHECKS
26static constexpr bool ExpensiveChecksEnabled = true;
27#else
28static constexpr bool ExpensiveChecksEnabled = false;
29#endif
30
31//===----------------------------------------------------------------------===//
32// PostDominatorTree Implementation
33//===----------------------------------------------------------------------===//
34
36
38 : FunctionPass(ID) {}
39
41 "Post-Dominator Tree Construction", true, true)
42
44 FunctionAnalysisManager::Invalidator &) {
45 // Check whether the analysis, all analyses on functions, or the function's
46 // CFG have been preserved.
47 auto PAC = PA.getChecker<PostDominatorTreeAnalysis>();
48 return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() ||
49 PAC.preservedSet<CFGAnalyses>());
50}
51
53 const Instruction *I2) const {
54 assert(I1 && I2 && "Expecting valid I1 and I2");
55
56 const BasicBlock *BB1 = I1->getParent();
57 const BasicBlock *BB2 = I2->getParent();
58
59 if (BB1 != BB2)
60 return Base::dominates(BB1, BB2);
61
62 // PHINodes in a block are unordered.
63 if (isa<PHINode>(I1) && isa<PHINode>(I2))
64 return false;
65
66 // Loop through the basic block until we find I1 or I2.
68 for (; &*I != I1 && &*I != I2; ++I)
69 /*empty*/;
70
71 return &*I == I2;
72}
73
76 return false;
77}
78
80 if (VerifyDomInfo)
84}
85
87 DT.print(OS);
88}
89
92}
93
94AnalysisKey PostDominatorTreeAnalysis::Key;
95
99 return PDT;
100}
101
103 : OS(OS) {}
104
107 OS << "PostDominatorTree for function: " << F.getName() << "\n";
109
110 return PreservedAnalyses::all();
111}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:56
static constexpr bool ExpensiveChecksEnabled
raw_pwrite_stream & OS
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
Definition: Analysis.h:50
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:255
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:412
LLVM Basic Block Representation.
Definition: BasicBlock.h:62
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:459
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:171
Represents analyses that only rely on functions' control flow.
Definition: Analysis.h:73
void print(raw_ostream &O) const
print - Convert to human readable form
bool verify(VerificationLevel VL=VerificationLevel::Full) const
verify - checks if the tree is correct.
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:314
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
Analysis pass which computes a PostDominatorTree.
LLVM_ABI PostDominatorTree run(Function &F, FunctionAnalysisManager &)
Run the analysis pass over a function and produce a post dominator tree.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM_ABI PostDominatorTreePrinterPass(raw_ostream &OS)
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
LLVM_ABI 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:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:118
const ParentTy * getParent() const
Definition: ilist_node.h:34
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: AddressRanges.h:18
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
LLVM_ABI FunctionPass * createPostDomTree()
LLVM_ABI bool VerifyDomInfo
Enables verification of dominator trees.
Definition: Dominators.cpp:41
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:29
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void print(raw_ostream &OS, const Module *) const override
print - Print out the internal state of the pass.
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...