llvm-project
96 строк · 3.2 Кб
1//===- DominanceFrontier.cpp - Dominance Frontier Calculation -------------===//
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/Analysis/DominanceFrontier.h"
10#include "llvm/Analysis/DominanceFrontierImpl.h"
11#include "llvm/Config/llvm-config.h"
12#include "llvm/IR/Dominators.h"
13#include "llvm/IR/Function.h"
14#include "llvm/IR/PassManager.h"
15#include "llvm/InitializePasses.h"
16#include "llvm/Pass.h"
17#include "llvm/Support/Compiler.h"
18#include "llvm/Support/raw_ostream.h"
19
20using namespace llvm;
21
22namespace llvm {
23
24template class DominanceFrontierBase<BasicBlock, false>;
25template class DominanceFrontierBase<BasicBlock, true>;
26template class ForwardDominanceFrontierBase<BasicBlock>;
27
28} // end namespace llvm
29
30char DominanceFrontierWrapperPass::ID = 0;
31
32INITIALIZE_PASS_BEGIN(DominanceFrontierWrapperPass, "domfrontier",
33"Dominance Frontier Construction", true, true)
34INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
35INITIALIZE_PASS_END(DominanceFrontierWrapperPass, "domfrontier",
36"Dominance Frontier Construction", true, true)
37
38DominanceFrontierWrapperPass::DominanceFrontierWrapperPass()
39: FunctionPass(ID) {
40initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry());
41}
42
43void DominanceFrontierWrapperPass::releaseMemory() {
44DF.releaseMemory();
45}
46
47bool DominanceFrontierWrapperPass::runOnFunction(Function &) {
48releaseMemory();
49DF.analyze(getAnalysis<DominatorTreeWrapperPass>().getDomTree());
50return false;
51}
52
53void DominanceFrontierWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
54AU.setPreservesAll();
55AU.addRequired<DominatorTreeWrapperPass>();
56}
57
58void DominanceFrontierWrapperPass::print(raw_ostream &OS, const Module *) const {
59DF.print(OS);
60}
61
62#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
63LLVM_DUMP_METHOD void DominanceFrontierWrapperPass::dump() const {
64print(dbgs());
65}
66#endif
67
68/// Handle invalidation explicitly.
69bool DominanceFrontier::invalidate(Function &F, const PreservedAnalyses &PA,
70FunctionAnalysisManager::Invalidator &) {
71// Check whether the analysis, all analyses on functions, or the function's
72// CFG have been preserved.
73auto PAC = PA.getChecker<DominanceFrontierAnalysis>();
74return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() ||
75PAC.preservedSet<CFGAnalyses>());
76}
77
78AnalysisKey DominanceFrontierAnalysis::Key;
79
80DominanceFrontier DominanceFrontierAnalysis::run(Function &F,
81FunctionAnalysisManager &AM) {
82DominanceFrontier DF;
83DF.analyze(AM.getResult<DominatorTreeAnalysis>(F));
84return DF;
85}
86
87DominanceFrontierPrinterPass::DominanceFrontierPrinterPass(raw_ostream &OS)
88: OS(OS) {}
89
90PreservedAnalyses
91DominanceFrontierPrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
92OS << "DominanceFrontier for function: " << F.getName() << "\n";
93AM.getResult<DominanceFrontierAnalysis>(F).print(OS);
94
95return PreservedAnalyses::all();
96}
97