1 //===- MachinePostDominators.cpp -Machine Post Dominator Calculation ------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements simple dominator construction algorithms for finding
10 // post dominators on machine functions.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/MachinePostDominators.h"
19 template class DominatorTreeBase
<MachineBasicBlock
, true>; // PostDomTreeBase
21 extern bool VerifyMachineDomInfo
;
24 char MachinePostDominatorTree::ID
= 0;
26 //declare initializeMachinePostDominatorTreePass
27 INITIALIZE_PASS(MachinePostDominatorTree
, "machinepostdomtree",
28 "MachinePostDominator Tree Construction", true, true)
30 MachinePostDominatorTree::MachinePostDominatorTree()
31 : MachineFunctionPass(ID
), PDT(nullptr) {
32 initializeMachinePostDominatorTreePass(*PassRegistry::getPassRegistry());
35 FunctionPass
*MachinePostDominatorTree::createMachinePostDominatorTreePass() {
36 return new MachinePostDominatorTree();
39 bool MachinePostDominatorTree::runOnMachineFunction(MachineFunction
&F
) {
40 PDT
= std::make_unique
<PostDomTreeT
>();
45 void MachinePostDominatorTree::getAnalysisUsage(AnalysisUsage
&AU
) const {
47 MachineFunctionPass::getAnalysisUsage(AU
);
50 MachineBasicBlock
*MachinePostDominatorTree::findNearestCommonDominator(
51 ArrayRef
<MachineBasicBlock
*> Blocks
) const {
52 assert(!Blocks
.empty());
54 MachineBasicBlock
*NCD
= Blocks
.front();
55 for (MachineBasicBlock
*BB
: Blocks
.drop_front()) {
56 NCD
= PDT
->findNearestCommonDominator(NCD
, BB
);
58 // Stop when the root is reached.
59 if (PDT
->isVirtualRoot(PDT
->getNode(NCD
)))
66 void MachinePostDominatorTree::verifyAnalysis() const {
67 if (PDT
&& VerifyMachineDomInfo
)
68 if (!PDT
->verify(PostDomTreeT::VerificationLevel::Basic
)) {
69 errs() << "MachinePostDominatorTree verification failed\n";
75 void MachinePostDominatorTree::print(llvm::raw_ostream
&OS
,
76 const Module
*M
) const {