LLVM 19.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
16
17using namespace llvm;
18
19namespace llvm {
20template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTreeBase
21
22extern bool VerifyMachineDomInfo;
23} // namespace llvm
24
26
27//declare initializeMachinePostDominatorTreePass
29 "MachinePostDominator Tree Construction", true, true)
30
32 : MachineFunctionPass(ID), PDT(nullptr) {
34}
35
37 return new MachinePostDominatorTree();
38}
39
41 PDT = std::make_unique<PostDomTreeT>();
42 PDT->recalculate(F);
43 return false;
44}
45
47 AU.setPreservesAll();
49}
50
53 assert(!Blocks.empty());
54
55 MachineBasicBlock *NCD = Blocks.front();
56 for (MachineBasicBlock *BB : Blocks.drop_front()) {
57 NCD = PDT->findNearestCommonDominator(NCD, BB);
58
59 // Stop when the root is reached.
60 if (PDT->isVirtualRoot(PDT->getNode(NCD)))
61 return nullptr;
62 }
63
64 return NCD;
65}
66
68 if (PDT && VerifyMachineDomInfo)
70 errs() << "MachinePostDominatorTree verification failed\n";
71
72 abort();
73 }
74}
75
77 const Module *M) const {
78 PDT->print(OS);
79}
DenseMap< Block *, BlockRelaxAux > Blocks
Definition: ELF_riscv.cpp:507
#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
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
Core dominator tree base class.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
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.
MachinePostDominatorTree - an analysis pass wrapper for DominatorTree used to compute the post-domina...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
FunctionPass * createMachinePostDominatorTreePass()
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.
MachineBasicBlock * findNearestCommonDominator(MachineBasicBlock *A, MachineBasicBlock *B) const
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...
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
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool VerifyMachineDomInfo
void initializeMachinePostDominatorTreePass(PassRegistry &)