blob: fc34e6388a5d77b272b4c199d6911f6dd509a1ab [file] [log] [blame]
Chris Lattnerd43023a2002-08-02 16:43:03 +00001//===- PostDominators.cpp - Post-Dominator Calculation --------------------===//
Misha Brukman01808ca2005-04-21 21:13:18 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman01808ca2005-04-21 21:13:18 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner081aabc2001-07-02 05:46:38 +00009//
Chris Lattnerd43023a2002-08-02 16:43:03 +000010// This file implements the post-dominator construction algorithms.
Chris Lattner081aabc2001-07-02 05:46:38 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattnerc86203a2002-08-21 23:43:50 +000014#include "llvm/Analysis/PostDominators.h"
Eugene Zelenkobb1b2d02017-08-16 22:07:40 +000015#include "llvm/IR/Function.h"
Hongbin Zheng3f978402016-02-25 17:54:07 +000016#include "llvm/IR/PassManager.h"
Eugene Zelenkobb1b2d02017-08-16 22:07:40 +000017#include "llvm/Pass.h"
18#include "llvm/Support/raw_ostream.h"
19
Chris Lattnerf9f7c2d2003-12-07 00:35:42 +000020using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000021
Chandler Carruthf1221bd2014-04-22 02:48:03 +000022#define DEBUG_TYPE "postdomtree"
23
Jakub Kuderskib292c222017-07-14 18:26:09 +000024template class llvm::DominatorTreeBase<BasicBlock, true>; // PostDomTreeBase
25
Chris Lattnerc385beb2001-07-06 16:58:22 +000026//===----------------------------------------------------------------------===//
Owen Andersonf35a1db2007-04-15 08:47:27 +000027// PostDominatorTree Implementation
Nate Begemand5811b92006-03-11 02:20:46 +000028//===----------------------------------------------------------------------===//
29
Hongbin Zheng3f978402016-02-25 17:54:07 +000030char PostDominatorTreeWrapperPass::ID = 0;
Eugene Zelenkobb1b2d02017-08-16 22:07:40 +000031
Hongbin Zheng3f978402016-02-25 17:54:07 +000032INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
Owen Andersondf7a4f22010-10-07 22:25:06 +000033 "Post-Dominator Tree Construction", true, true)
Nate Begemand5811b92006-03-11 02:20:46 +000034
Chandler Carruthca68a3e2017-01-15 06:32:49 +000035bool PostDominatorTree::invalidate(Function &F, const PreservedAnalyses &PA,
36 FunctionAnalysisManager::Invalidator &) {
37 // Check whether the analysis, all analyses on functions, or the function's
38 // CFG have been preserved.
39 auto PAC = PA.getChecker<PostDominatorTreeAnalysis>();
40 return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() ||
41 PAC.preservedSet<CFGAnalyses>());
42}
43
Hongbin Zheng3f978402016-02-25 17:54:07 +000044bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
45 DT.recalculate(F);
Owen Andersonb60f2542007-10-03 03:20:17 +000046 return false;
47}
48
Hongbin Zheng3f978402016-02-25 17:54:07 +000049void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
50 DT.print(OS);
Torok Edwin2a455752008-05-03 20:25:26 +000051}
52
Owen Andersonb1ba3522008-05-29 17:00:13 +000053FunctionPass* llvm::createPostDomTree() {
Hongbin Zheng3f978402016-02-25 17:54:07 +000054 return new PostDominatorTreeWrapperPass();
Owen Andersonb1ba3522008-05-29 17:00:13 +000055}
56
Chandler Carruthdab4eae2016-11-23 17:53:26 +000057AnalysisKey PostDominatorTreeAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +000058
Chandler Carruth164a2aa62016-06-17 00:11:01 +000059PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
60 FunctionAnalysisManager &) {
Hongbin Zheng3f978402016-02-25 17:54:07 +000061 PostDominatorTree PDT;
62 PDT.recalculate(F);
63 return PDT;
64}
65
66PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS)
67 : OS(OS) {}
68
69PreservedAnalyses
Chandler Carruthb47f8012016-03-11 11:05:24 +000070PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
Hongbin Zheng3f978402016-02-25 17:54:07 +000071 OS << "PostDominatorTree for function: " << F.getName() << "\n";
Chandler Carruthb47f8012016-03-11 11:05:24 +000072 AM.getResult<PostDominatorTreeAnalysis>(F).print(OS);
Hongbin Zheng3f978402016-02-25 17:54:07 +000073
74 return PreservedAnalyses::all();
75}