DominanceFrontier.cpp revision 309124
1//===- DominanceFrontier.cpp - Dominance Frontier Calculation -------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/Analysis/DominanceFrontier.h"
11#include "llvm/Analysis/DominanceFrontierImpl.h"
12#include "llvm/IR/PassManager.h"
13
14using namespace llvm;
15
16namespace llvm {
17template class DominanceFrontierBase<BasicBlock>;
18template class ForwardDominanceFrontierBase<BasicBlock>;
19}
20
21char DominanceFrontierWrapperPass::ID = 0;
22
23INITIALIZE_PASS_BEGIN(DominanceFrontierWrapperPass, "domfrontier",
24                "Dominance Frontier Construction", true, true)
25INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
26INITIALIZE_PASS_END(DominanceFrontierWrapperPass, "domfrontier",
27                "Dominance Frontier Construction", true, true)
28
29 DominanceFrontierWrapperPass::DominanceFrontierWrapperPass()
30    : FunctionPass(ID), DF() {
31  initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry());
32}
33
34void DominanceFrontierWrapperPass::releaseMemory() {
35  DF.releaseMemory();
36}
37
38bool DominanceFrontierWrapperPass::runOnFunction(Function &) {
39  releaseMemory();
40  DF.analyze(getAnalysis<DominatorTreeWrapperPass>().getDomTree());
41  return false;
42}
43
44void DominanceFrontierWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
45  AU.setPreservesAll();
46  AU.addRequired<DominatorTreeWrapperPass>();
47}
48
49void DominanceFrontierWrapperPass::print(raw_ostream &OS, const Module *) const {
50  DF.print(OS);
51}
52
53#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
54LLVM_DUMP_METHOD void DominanceFrontierWrapperPass::dump() const {
55  print(dbgs());
56}
57#endif
58
59char DominanceFrontierAnalysis::PassID;
60
61DominanceFrontier DominanceFrontierAnalysis::run(Function &F,
62                                                 FunctionAnalysisManager &AM) {
63  DominanceFrontier DF;
64  DF.analyze(AM.getResult<DominatorTreeAnalysis>(F));
65  return DF;
66}
67
68DominanceFrontierPrinterPass::DominanceFrontierPrinterPass(raw_ostream &OS)
69  : OS(OS) {}
70
71PreservedAnalyses
72DominanceFrontierPrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
73  OS << "DominanceFrontier for function: " << F.getName() << "\n";
74  AM.getResult<DominanceFrontierAnalysis>(F).print(OS);
75
76  return PreservedAnalyses::all();
77}
78