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