blob: 1caf151546d9bad39b425eefd1c5620770c74b80 [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"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "llvm/ADT/DepthFirstIterator.h"
16#include "llvm/ADT/SetOperations.h"
Chandler Carruth1305dc32014-03-04 11:45:46 +000017#include "llvm/IR/CFG.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000018#include "llvm/IR/Instructions.h"
Hongbin Zheng3f978402016-02-25 17:54:07 +000019#include "llvm/IR/PassManager.h"
Owen Anderson57236b52008-04-16 04:21:16 +000020#include "llvm/Support/Debug.h"
Chandler Carruth442f7842014-03-04 10:07:28 +000021#include "llvm/Support/GenericDomTreeConstruction.h"
Chris Lattnerf9f7c2d2003-12-07 00:35:42 +000022using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000023
Chandler Carruthf1221bd2014-04-22 02:48:03 +000024#define DEBUG_TYPE "postdomtree"
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;
31INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
Owen Andersondf7a4f22010-10-07 22:25:06 +000032 "Post-Dominator Tree Construction", true, true)
Nate Begemand5811b92006-03-11 02:20:46 +000033
Chandler Carruthca68a3e2017-01-15 06:32:49 +000034bool PostDominatorTree::invalidate(Function &F, const PreservedAnalyses &PA,
35 FunctionAnalysisManager::Invalidator &) {
36 // Check whether the analysis, all analyses on functions, or the function's
37 // CFG have been preserved.
38 auto PAC = PA.getChecker<PostDominatorTreeAnalysis>();
39 return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() ||
40 PAC.preservedSet<CFGAnalyses>());
41}
42
Hongbin Zheng3f978402016-02-25 17:54:07 +000043bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
44 DT.recalculate(F);
Owen Andersonb60f2542007-10-03 03:20:17 +000045 return false;
46}
47
Hongbin Zheng3f978402016-02-25 17:54:07 +000048void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
49 DT.print(OS);
Torok Edwin2a455752008-05-03 20:25:26 +000050}
51
Owen Andersonb1ba3522008-05-29 17:00:13 +000052FunctionPass* llvm::createPostDomTree() {
Hongbin Zheng3f978402016-02-25 17:54:07 +000053 return new PostDominatorTreeWrapperPass();
Owen Andersonb1ba3522008-05-29 17:00:13 +000054}
55
Chandler Carruthdab4eae2016-11-23 17:53:26 +000056AnalysisKey PostDominatorTreeAnalysis::Key;
NAKAMURA Takumidf0cd722016-02-28 17:17:00 +000057
Chandler Carruth164a2aa62016-06-17 00:11:01 +000058PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
59 FunctionAnalysisManager &) {
Hongbin Zheng3f978402016-02-25 17:54:07 +000060 PostDominatorTree PDT;
61 PDT.recalculate(F);
62 return PDT;
63}
64
65PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS)
66 : OS(OS) {}
67
68PreservedAnalyses
Chandler Carruthb47f8012016-03-11 11:05:24 +000069PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
Hongbin Zheng3f978402016-02-25 17:54:07 +000070 OS << "PostDominatorTree for function: " << F.getName() << "\n";
Chandler Carruthb47f8012016-03-11 11:05:24 +000071 AM.getResult<PostDominatorTreeAnalysis>(F).print(OS);
Hongbin Zheng3f978402016-02-25 17:54:07 +000072
73 return PreservedAnalyses::all();
74}