LLVM 20.0.0git
MachinePostDominators.cpp
Go to the documentation of this file.
1//===- MachinePostDominators.cpp -Machine 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 simple dominator construction algorithms for finding
10// post dominators on machine functions.
11//
12//===----------------------------------------------------------------------===//
13
17
18using namespace llvm;
19
20namespace llvm {
21template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTreeBase
22
23namespace DomTreeBuilder {
24
25template void Calculate<MBBPostDomTree>(MBBPostDomTree &DT);
26template void InsertEdge<MBBPostDomTree>(MBBPostDomTree &DT,
29template void DeleteEdge<MBBPostDomTree>(MBBPostDomTree &DT,
32template void ApplyUpdates<MBBPostDomTree>(MBBPostDomTree &DT,
33 MBBPostDomTreeGraphDiff &,
34 MBBPostDomTreeGraphDiff *);
35template bool Verify<MBBPostDomTree>(const MBBPostDomTree &DT,
36 MBBPostDomTree::VerificationLevel VL);
37
38} // namespace DomTreeBuilder
39extern bool VerifyMachineDomInfo;
40} // namespace llvm
41
42AnalysisKey MachinePostDominatorTreeAnalysis::Key;
43
47 return MachinePostDominatorTree(MF);
48}
49
53 OS << "MachinePostDominatorTree for machine function: " << MF.getName()
54 << '\n';
57}
58
60
61//declare initializeMachinePostDominatorTreePass
63 "MachinePostDominator Tree Construction", true, true)
64
66 : MachineFunctionPass(ID), PDT() {
69}
70
74 PDT->recalculate(F);
75 return false;
76}
77
79 AnalysisUsage &AU) const {
80 AU.setPreservesAll();
82}
83
87 // Check whether the analysis, all analyses on machine functions, or the
88 // machine function's CFG have been preserved.
90 return !PAC.preserved() &&
91 !PAC.preservedSet<AllAnalysesOn<MachineFunction>>() &&
92 !PAC.preservedSet<CFGAnalyses>();
93}
94
97 assert(!Blocks.empty());
98
99 MachineBasicBlock *NCD = Blocks.front();
100 for (MachineBasicBlock *BB : Blocks.drop_front()) {
102
103 // Stop when the root is reached.
104 if (isVirtualRoot(getNode(NCD)))
105 return nullptr;
106 }
107
108 return NCD;
109}
110
112 if (VerifyMachineDomInfo && PDT &&
114 report_fatal_error("MachinePostDominatorTree verification failed!");
115}
116
118 const Module *M) const {
119 PDT->print(OS);
120}
BlockVerifier::State From
DenseMap< Block *, BlockRelaxAux > Blocks
Definition: ELF_riscv.cpp:507
Generic dominator tree construction - this file provides routines to construct immediate dominator in...
#define F(x, y, z)
Definition: MD5.cpp:55
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
Definition: Analysis.h:49
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
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:405
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Represents analyses that only rely on functions' control flow.
Definition: Analysis.h:72
Core dominator tree base class.
NodeT * findNearestCommonDominator(NodeT *A, NodeT *B) const
Find nearest common dominator basic block for basic block A and B.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
bool isVirtualRoot(const DomTreeNodeBase< NodeT > *A) const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
void print(llvm::raw_ostream &OS, const Module *M=nullptr) const override
print - Print out the internal state of the pass.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachinePostDominatorTree - an analysis pass wrapper for DominatorTree used to compute the post-domina...
bool invalidate(MachineFunction &, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly.
MachineBasicBlock * findNearestCommonDominator(ArrayRef< MachineBasicBlock * > Blocks) const
Returns the nearest common dominator of the given blocks.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition: Analysis.h:264
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
void initializeMachinePostDominatorTreeWrapperPassPass(PassRegistry &)
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
bool VerifyMachineDomInfo
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28