blob: 4554374252a4abba3031243bffe477ee81097e35 [file] [log] [blame]
Cameron Zwarich6b0c4c92011-01-18 06:06:27 +00001//===- 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"
Matt Arsenault4181ea32014-07-12 21:59:52 +000011#include "llvm/Analysis/DominanceFrontierImpl.h"
Hongbin Zheng751337f2016-02-25 17:54:15 +000012#include "llvm/IR/PassManager.h"
Matt Arsenault4181ea32014-07-12 21:59:52 +000013
Cameron Zwarich6b0c4c92011-01-18 06:06:27 +000014using namespace llvm;
15
Matt Arsenault4181ea32014-07-12 21:59:52 +000016namespace llvm {
17template class DominanceFrontierBase<BasicBlock>;
18template class ForwardDominanceFrontierBase<BasicBlock>;
19}
20
Hongbin Zheng751337f2016-02-25 17:54:15 +000021char DominanceFrontierWrapperPass::ID = 0;
Matt Arsenault4181ea32014-07-12 21:59:52 +000022
Hongbin Zheng751337f2016-02-25 17:54:15 +000023INITIALIZE_PASS_BEGIN(DominanceFrontierWrapperPass, "domfrontier",
Cameron Zwarich6b0c4c92011-01-18 06:06:27 +000024 "Dominance Frontier Construction", true, true)
Chandler Carruth73523022014-01-13 13:07:17 +000025INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
Hongbin Zheng751337f2016-02-25 17:54:15 +000026INITIALIZE_PASS_END(DominanceFrontierWrapperPass, "domfrontier",
Cameron Zwarich6b0c4c92011-01-18 06:06:27 +000027 "Dominance Frontier Construction", true, true)
28
Hongbin Zheng751337f2016-02-25 17:54:15 +000029 DominanceFrontierWrapperPass::DominanceFrontierWrapperPass()
30 : FunctionPass(ID), DF() {
31 initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry());
Cameron Zwarich6b0c4c92011-01-18 06:06:27 +000032}
33
Hongbin Zheng751337f2016-02-25 17:54:15 +000034void DominanceFrontierWrapperPass::releaseMemory() {
35 DF.releaseMemory();
Cameron Zwarich6b0c4c92011-01-18 06:06:27 +000036}
37
Hongbin Zheng751337f2016-02-25 17:54:15 +000038bool DominanceFrontierWrapperPass::runOnFunction(Function &) {
Matt Arsenault4181ea32014-07-12 21:59:52 +000039 releaseMemory();
Hongbin Zheng751337f2016-02-25 17:54:15 +000040 DF.analyze(getAnalysis<DominatorTreeWrapperPass>().getDomTree());
Matt Arsenault4181ea32014-07-12 21:59:52 +000041 return false;
42}
43
Hongbin Zheng751337f2016-02-25 17:54:15 +000044void DominanceFrontierWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
Matt Arsenault4181ea32014-07-12 21:59:52 +000045 AU.setPreservesAll();
46 AU.addRequired<DominatorTreeWrapperPass>();
47}
48
Hongbin Zheng751337f2016-02-25 17:54:15 +000049void DominanceFrontierWrapperPass::print(raw_ostream &OS, const Module *) const {
50 DF.print(OS);
Cameron Zwarich6b0c4c92011-01-18 06:06:27 +000051}
52
Manman Ren49d684e2012-09-12 05:06:18 +000053#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Hongbin Zheng751337f2016-02-25 17:54:15 +000054LLVM_DUMP_METHOD void DominanceFrontierWrapperPass::dump() const {
Cameron Zwarich6b0c4c92011-01-18 06:06:27 +000055 print(dbgs());
56}
Manman Renc3366cc2012-09-06 19:55:56 +000057#endif
Hongbin Zheng751337f2016-02-25 17:54:15 +000058
Chandler Carruthb4faf132016-03-11 10:22:49 +000059char DominanceFrontierAnalysis::PassID;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +000060
Hongbin Zheng751337f2016-02-25 17:54:15 +000061DominanceFrontier DominanceFrontierAnalysis::run(Function &F,
Chandler Carruthb47f8012016-03-11 11:05:24 +000062 FunctionAnalysisManager &AM) {
Hongbin Zheng751337f2016-02-25 17:54:15 +000063 DominanceFrontier DF;
Chandler Carruthb47f8012016-03-11 11:05:24 +000064 DF.analyze(AM.getResult<DominatorTreeAnalysis>(F));
Hongbin Zheng751337f2016-02-25 17:54:15 +000065 return DF;
66}
67
68DominanceFrontierPrinterPass::DominanceFrontierPrinterPass(raw_ostream &OS)
69 : OS(OS) {}
70
71PreservedAnalyses
Chandler Carruthb47f8012016-03-11 11:05:24 +000072DominanceFrontierPrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
Hongbin Zheng751337f2016-02-25 17:54:15 +000073 OS << "DominanceFrontier for function: " << F.getName() << "\n";
Chandler Carruthb47f8012016-03-11 11:05:24 +000074 AM.getResult<DominanceFrontierAnalysis>(F).print(OS);
Hongbin Zheng751337f2016-02-25 17:54:15 +000075
76 return PreservedAnalyses::all();
77}