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
16using namespace llvm;
17
18namespace llvm {
19template class DominanceFrontierBase<MachineBasicBlock, false>;
20template class DominanceFrontierBase<MachineBasicBlock, true>;
21template class ForwardDominanceFrontierBase<MachineBasicBlock>;
22}
23
24char MachineDominanceFrontierWrapperPass::ID = 0;
25
26INITIALIZE_PASS_BEGIN(MachineDominanceFrontierWrapperPass,
27 "machine-domfrontier",
28 "Machine Dominance Frontier Construction", true, true)
29INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
30INITIALIZE_PASS_END(MachineDominanceFrontierWrapperPass, "machine-domfrontier",
31 "Machine Dominance Frontier Construction", true, true)
32
33MachineDominanceFrontierWrapperPass::MachineDominanceFrontierWrapperPass()
34 : MachineFunctionPass(ID) {}
35
36char &llvm::MachineDominanceFrontierID =
37 MachineDominanceFrontierWrapperPass::ID;
38
39bool 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
48bool MachineDominanceFrontierWrapperPass::runOnMachineFunction(
49 MachineFunction &) {
50 MDF.releaseMemory();
51 auto &MDT = getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
52 MDF.analyze(DT&: MDT);
53 return false;
54}
55
56void MachineDominanceFrontierWrapperPass::releaseMemory() {
57 MDF.releaseMemory();
58}
59
60void MachineDominanceFrontierWrapperPass::getAnalysisUsage(
61 AnalysisUsage &AU) const {
62 AU.setPreservesAll();
63 AU.addRequired<MachineDominatorTreeWrapperPass>();
64 MachineFunctionPass::getAnalysisUsage(AU);
65}
66
67AnalysisKey MachineDominanceFrontierAnalysis::Key;
68
69MachineDominanceFrontierAnalysis::Result
70MachineDominanceFrontierAnalysis::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