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