Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/llvm/lib/CodeGen/MachinePostDominators.cpp
Line
Count
Source (jump to first uncovered line)
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
14
#include "llvm/CodeGen/MachinePostDominators.h"
15
#include "llvm/InitializePasses.h"
16
17
using namespace llvm;
18
19
namespace llvm {
20
template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTreeBase
21
22
extern bool VerifyMachineDomInfo;
23
} // namespace llvm
24
25
char MachinePostDominatorTree::ID = 0;
26
27
//declare initializeMachinePostDominatorTreePass
28
INITIALIZE_PASS(MachinePostDominatorTree, "machinepostdomtree",
29
                "MachinePostDominator Tree Construction", true, true)
30
31
MachinePostDominatorTree::MachinePostDominatorTree()
32
117k
    : MachineFunctionPass(ID), PDT(nullptr) {
33
117k
  initializeMachinePostDominatorTreePass(*PassRegistry::getPassRegistry());
34
117k
}
35
36
0
FunctionPass *MachinePostDominatorTree::createMachinePostDominatorTreePass() {
37
0
  return new MachinePostDominatorTree();
38
0
}
39
40
367k
bool MachinePostDominatorTree::runOnMachineFunction(MachineFunction &F) {
41
367k
  PDT = std::make_unique<PostDomTreeT>();
42
367k
  PDT->recalculate(F);
43
367k
  return false;
44
367k
}
45
46
109k
void MachinePostDominatorTree::getAnalysisUsage(AnalysisUsage &AU) const {
47
109k
  AU.setPreservesAll();
48
109k
  MachineFunctionPass::getAnalysisUsage(AU);
49
109k
}
50
51
MachineBasicBlock *MachinePostDominatorTree::findNearestCommonDominator(
52
0
    ArrayRef<MachineBasicBlock *> Blocks) const {
53
0
  assert(!Blocks.empty());
54
55
0
  MachineBasicBlock *NCD = Blocks.front();
56
0
  for (MachineBasicBlock *BB : Blocks.drop_front()) {
57
0
    NCD = PDT->findNearestCommonDominator(NCD, BB);
58
59
    // Stop when the root is reached.
60
0
    if (PDT->isVirtualRoot(PDT->getNode(NCD)))
61
0
      return nullptr;
62
0
  }
63
64
0
  return NCD;
65
0
}
66
67
30.4k
void MachinePostDominatorTree::verifyAnalysis() const {
68
30.4k
  if (PDT && VerifyMachineDomInfo)
69
0
    if (!PDT->verify(PostDomTreeT::VerificationLevel::Basic)) {
70
0
      errs() << "MachinePostDominatorTree verification failed\n";
71
72
0
      abort();
73
0
    }
74
30.4k
}
75
76
void MachinePostDominatorTree::print(llvm::raw_ostream &OS,
77
0
                                     const Module *M) const {
78
0
  PDT->print(OS);
79
0
}