| 1 | //===- MachineDominanceFrontier.cpp ---------------------------------------===// |
| 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 | #include "llvm/CodeGen/MachineDominanceFrontier.h" |
| 10 | #include "llvm/CodeGen/MachineDominators.h" |
| 11 | #include "llvm/CodeGen/Passes.h" |
| 12 | #include "llvm/InitializePasses.h" |
| 13 | #include "llvm/Pass.h" |
| 14 | #include "llvm/PassRegistry.h" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | |
| 18 | namespace llvm { |
| 19 | template class DominanceFrontierBase<MachineBasicBlock, false>; |
| 20 | template class DominanceFrontierBase<MachineBasicBlock, true>; |
| 21 | template class ForwardDominanceFrontierBase<MachineBasicBlock>; |
| 22 | } |
| 23 | |
| 24 | char MachineDominanceFrontierWrapperPass::ID = 0; |
| 25 | |
| 26 | INITIALIZE_PASS_BEGIN(MachineDominanceFrontierWrapperPass, |
| 27 | "machine-domfrontier" , |
| 28 | "Machine Dominance Frontier Construction" , true, true) |
| 29 | INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass) |
| 30 | INITIALIZE_PASS_END(MachineDominanceFrontierWrapperPass, "machine-domfrontier" , |
| 31 | "Machine Dominance Frontier Construction" , true, true) |
| 32 | |
| 33 | MachineDominanceFrontierWrapperPass::MachineDominanceFrontierWrapperPass() |
| 34 | : MachineFunctionPass(ID) {} |
| 35 | |
| 36 | char &llvm::MachineDominanceFrontierID = |
| 37 | MachineDominanceFrontierWrapperPass::ID; |
| 38 | |
| 39 | bool MachineDominanceFrontier::invalidate( |
| 40 | MachineFunction &F, const PreservedAnalyses &PA, |
| 41 | MachineFunctionAnalysisManager::Invalidator &) { |
| 42 | auto PAC = PA.getChecker<MachineDominanceFrontierAnalysis>(); |
| 43 | return !PAC.preserved() && |
| 44 | !PAC.preservedSet<AllAnalysesOn<MachineFunction>>() && |
| 45 | !PAC.preservedSet<CFGAnalyses>(); |
| 46 | } |
| 47 | |
| 48 | bool MachineDominanceFrontierWrapperPass::runOnMachineFunction( |
| 49 | MachineFunction &) { |
| 50 | MDF.releaseMemory(); |
| 51 | auto &MDT = getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree(); |
| 52 | MDF.analyze(DT&: MDT); |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | void MachineDominanceFrontierWrapperPass::releaseMemory() { |
| 57 | MDF.releaseMemory(); |
| 58 | } |
| 59 | |
| 60 | void MachineDominanceFrontierWrapperPass::getAnalysisUsage( |
| 61 | AnalysisUsage &AU) const { |
| 62 | AU.setPreservesAll(); |
| 63 | AU.addRequired<MachineDominatorTreeWrapperPass>(); |
| 64 | MachineFunctionPass::getAnalysisUsage(AU); |
| 65 | } |
| 66 | |
| 67 | AnalysisKey MachineDominanceFrontierAnalysis::Key; |
| 68 | |
| 69 | MachineDominanceFrontierAnalysis::Result |
| 70 | MachineDominanceFrontierAnalysis::run(MachineFunction &MF, |
| 71 | MachineFunctionAnalysisManager &MFAM) { |
| 72 | MachineDominanceFrontier MDF; |
| 73 | auto &MDT = MFAM.getResult<MachineDominatorTreeAnalysis>(IR&: MF); |
| 74 | MDF.analyze(DT&: MDT); |
| 75 | return MDF; |
| 76 | } |
| 77 | |