1 //===- PostDominators.cpp - Post-Dominator Calculation --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the post-dominator construction algorithms.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Analysis/PostDominators.h"
15 #include "llvm/ADT/DepthFirstIterator.h"
16 #include "llvm/ADT/SetOperations.h"
17 #include "llvm/IR/CFG.h"
18 #include "llvm/IR/Instructions.h"
19 #include "llvm/IR/PassManager.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Support/GenericDomTreeConstruction.h"
24 #define DEBUG_TYPE "postdomtree"
26 template class llvm::DominatorTreeBase<BasicBlock, true>; // PostDomTreeBase
28 //===----------------------------------------------------------------------===//
29 // PostDominatorTree Implementation
30 //===----------------------------------------------------------------------===//
32 char PostDominatorTreeWrapperPass::ID = 0;
33 INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
34 "Post-Dominator Tree Construction", true, true)
36 bool PostDominatorTree::invalidate(Function &F, const PreservedAnalyses &PA,
37 FunctionAnalysisManager::Invalidator &) {
38 // Check whether the analysis, all analyses on functions, or the function's
39 // CFG have been preserved.
40 auto PAC = PA.getChecker<PostDominatorTreeAnalysis>();
41 return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() ||
42 PAC.preservedSet<CFGAnalyses>());
45 bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
50 void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
54 FunctionPass* llvm::createPostDomTree() {
55 return new PostDominatorTreeWrapperPass();
58 AnalysisKey PostDominatorTreeAnalysis::Key;
60 PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
61 FunctionAnalysisManager &) {
62 PostDominatorTree PDT;
67 PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS)
71 PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
72 OS << "PostDominatorTree for function: " << F.getName() << "\n";
73 AM.getResult<PostDominatorTreeAnalysis>(F).print(OS);
75 return PreservedAnalyses::all();