[Alignment][NFC] Convert StoreInst to MaybeAlign
[llvm-complete.git] / lib / CodeGen / MachinePostDominators.cpp
blobf4daff667e86df70202bca25143bda8165e8db5e
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.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/MachinePostDominators.h"
16 using namespace llvm;
18 namespace llvm {
19 template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTreeBase
21 extern bool VerifyMachineDomInfo;
22 } // namespace llvm
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>();
41 PDT->recalculate(F);
42 return false;
45 void MachinePostDominatorTree::getAnalysisUsage(AnalysisUsage &AU) const {
46 AU.setPreservesAll();
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)))
60 return nullptr;
63 return NCD;
66 void MachinePostDominatorTree::verifyAnalysis() const {
67 if (PDT && VerifyMachineDomInfo)
68 if (!PDT->verify(PostDomTreeT::VerificationLevel::Basic)) {
69 errs() << "MachinePostDominatorTree verification failed\n";
71 abort();
75 void MachinePostDominatorTree::print(llvm::raw_ostream &OS,
76 const Module *M) const {
77 PDT->print(OS);