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