[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / llvm / lib / CodeGen / MachinePostDominators.cpp
blobfb96d0efa4d4c2166df1b7b1e8ecfb89234592d7
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"
15 #include "llvm/InitializePasses.h"
17 using namespace llvm;
19 namespace llvm {
20 template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTreeBase
22 extern bool VerifyMachineDomInfo;
23 } // namespace llvm
25 char MachinePostDominatorTree::ID = 0;
27 //declare initializeMachinePostDominatorTreePass
28 INITIALIZE_PASS(MachinePostDominatorTree, "machinepostdomtree",
29 "MachinePostDominator Tree Construction", true, true)
31 MachinePostDominatorTree::MachinePostDominatorTree()
32 : MachineFunctionPass(ID), PDT(nullptr) {
33 initializeMachinePostDominatorTreePass(*PassRegistry::getPassRegistry());
36 FunctionPass *MachinePostDominatorTree::createMachinePostDominatorTreePass() {
37 return new MachinePostDominatorTree();
40 bool MachinePostDominatorTree::runOnMachineFunction(MachineFunction &F) {
41 PDT = std::make_unique<PostDomTreeT>();
42 PDT->recalculate(F);
43 return false;
46 void MachinePostDominatorTree::getAnalysisUsage(AnalysisUsage &AU) const {
47 AU.setPreservesAll();
48 MachineFunctionPass::getAnalysisUsage(AU);
51 MachineBasicBlock *MachinePostDominatorTree::findNearestCommonDominator(
52 ArrayRef<MachineBasicBlock *> Blocks) const {
53 assert(!Blocks.empty());
55 MachineBasicBlock *NCD = Blocks.front();
56 for (MachineBasicBlock *BB : Blocks.drop_front()) {
57 NCD = PDT->findNearestCommonDominator(NCD, BB);
59 // Stop when the root is reached.
60 if (PDT->isVirtualRoot(PDT->getNode(NCD)))
61 return nullptr;
64 return NCD;
67 void MachinePostDominatorTree::verifyAnalysis() const {
68 if (PDT && VerifyMachineDomInfo)
69 if (!PDT->verify(PostDomTreeT::VerificationLevel::Basic)) {
70 errs() << "MachinePostDominatorTree verification failed\n";
72 abort();
76 void MachinePostDominatorTree::print(llvm::raw_ostream &OS,
77 const Module *M) const {
78 PDT->print(OS);