LLVM 22.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 LLVM_EXPORT_TEMPLATE
23
24namespace DomTreeBuilder {
25
26template LLVM_EXPORT_TEMPLATE void
27Calculate<MBBPostDomTree>(MBBPostDomTree &DT);
28template LLVM_EXPORT_TEMPLATE void
29InsertEdge<MBBPostDomTree>(MBBPostDomTree &DT, MachineBasicBlock *From,
31template LLVM_EXPORT_TEMPLATE void
32DeleteEdge<MBBPostDomTree>(MBBPostDomTree &DT, MachineBasicBlock *From,
34template LLVM_EXPORT_TEMPLATE void
35ApplyUpdates<MBBPostDomTree>(MBBPostDomTree &DT, MBBPostDomTreeGraphDiff &,
36 MBBPostDomTreeGraphDiff *);
37template LLVM_EXPORT_TEMPLATE bool
38Verify<MBBPostDomTree>(const MBBPostDomTree &DT,
39 MBBPostDomTree::VerificationLevel VL);
40
41} // namespace DomTreeBuilder
42extern bool VerifyMachineDomInfo;
43} // namespace llvm
44
45AnalysisKey MachinePostDominatorTreeAnalysis::Key;
46
50 return MachinePostDominatorTree(MF);
51}
52
56 OS << "MachinePostDominatorTree for machine function: " << MF.getName()
57 << '\n';
60}
61
63
64//declare initializeMachinePostDominatorTreePass
66 "MachinePostDominator Tree Construction", true, true)
67
69 : MachineFunctionPass(ID), PDT() {
72}
73
77 PDT->recalculate(F);
78 return false;
79}
80
82 AnalysisUsage &AU) const {
83 AU.setPreservesAll();
85}
86
90 // Check whether the analysis, all analyses on machine functions, or the
91 // machine function's CFG have been preserved.
93 return !PAC.preserved() &&
94 !PAC.preservedSet<AllAnalysesOn<MachineFunction>>() &&
95 !PAC.preservedSet<CFGAnalyses>();
96}
97
100 assert(!Blocks.empty());
101
102 MachineBasicBlock *NCD = Blocks.consume_front();
103 for (MachineBasicBlock *BB : Blocks) {
105
106 // Stop when the root is reached.
107 if (isVirtualRoot(getNode(NCD)))
108 return nullptr;
109 }
110
111 return NCD;
112}
113
115 if (VerifyMachineDomInfo && PDT &&
117 report_fatal_error("MachinePostDominatorTree verification failed!");
118}
119
121 const Module *M) const {
122 PDT->print(OS);
123}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
BlockVerifier::State From
#define LLVM_EXPORT_TEMPLATE
Definition: Compiler.h:215
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:56
raw_pwrite_stream & OS
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
Definition: Analysis.h:50
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:294
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
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:73
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.
LLVM_ABI Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
LLVM_ABI 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...
LLVM_ABI bool invalidate(MachineFunction &, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly.
LLVM_ABI 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:67
static LLVM_ABI 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:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:118
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition: Analysis.h:275
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 void initializeMachinePostDominatorTreeWrapperPassPass(PassRegistry &)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
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:29