blob: 2282401085d423bdd7ddb2b128c0fc4babddba4b [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
Chris Lattnerc385beb2001-07-06 16:58:22 +000024//===----------------------------------------------------------------------===//
Owen Andersonf35a1db2007-04-15 08:47:27 +000025// PostDominatorTree Implementation
Nate Begemand5811b92006-03-11 02:20:46 +000026//===----------------------------------------------------------------------===//
27
Hongbin Zheng3f978402016-02-25 17:54:07 +000028char PostDominatorTreeWrapperPass::ID = 0;
Eugene Zelenkobb1b2d02017-08-16 22:07:40 +000029
Hongbin Zheng3f978402016-02-25 17:54:07 +000030INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
Owen Andersondf7a4f22010-10-07 22:25:06 +000031 "Post-Dominator Tree Construction", true, true)
Nate Begemand5811b92006-03-11 02:20:46 +000032
Chandler Carruthca68a3e2017-01-15 06:32:49 +000033bool PostDominatorTree::invalidate(Function &F, const PreservedAnalyses &PA,
34 FunctionAnalysisManager::Invalidator &) {
35 // Check whether the analysis, all analyses on functions, or the function's
36 // CFG have been preserved.
37 auto PAC = PA.getChecker<PostDominatorTreeAnalysis>();
38 return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() ||
39 PAC.preservedSet<CFGAnalyses>());
40}
41
Hongbin Zheng3f978402016-02-25 17:54:07 +000042bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
43 DT.recalculate(F);
Owen Andersonb60f2542007-10-03 03:20:17 +000044 return false;
45}
46
Hongbin Zheng3f978402016-02-25 17:54:07 +000047void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
48 DT.print(OS);
Torok Edwin2a455752008-05-03 20:25:26 +000049}
50
Owen Andersonb1ba3522008-05-29 17:00:13 +000051FunctionPass* llvm::createPostDomTree() {
Hongbin Zheng3f978402016-02-25 17:54:07 +000052 return new PostDominatorTreeWrapperPass();
Owen Andersonb1ba3522008-05-29 17:00:13 +000053}
54
Chandler Carruthdab4eae2016-11-23 17:53:26 +000055AnalysisKey PostDominatorTreeAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +000056
Chandler Carruth164a2aa62016-06-17 00:11:01 +000057PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
58 FunctionAnalysisManager &) {
Hongbin Zheng3f978402016-02-25 17:54:07 +000059 PostDominatorTree PDT;
60 PDT.recalculate(F);
61 return PDT;
62}
63
64PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS)
65 : OS(OS) {}
66
67PreservedAnalyses
Chandler Carruthb47f8012016-03-11 11:05:24 +000068PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
Hongbin Zheng3f978402016-02-25 17:54:07 +000069 OS << "PostDominatorTree for function: " << F.getName() << "\n";
Chandler Carruthb47f8012016-03-11 11:05:24 +000070 AM.getResult<PostDominatorTreeAnalysis>(F).print(OS);
Hongbin Zheng3f978402016-02-25 17:54:07 +000071
72 return PreservedAnalyses::all();
73}