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/IR/Function.h"
16 #include "llvm/IR/PassManager.h"
17 #include "llvm/Pass.h"
18 #include "llvm/Support/raw_ostream.h"
22 #define DEBUG_TYPE "postdomtree"
24 //===----------------------------------------------------------------------===//
25 // PostDominatorTree Implementation
26 //===----------------------------------------------------------------------===//
28 char PostDominatorTreeWrapperPass::ID = 0;
30 INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
31 "Post-Dominator Tree Construction", true, true)
33 bool 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>());
42 bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
47 void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
51 FunctionPass* llvm::createPostDomTree() {
52 return new PostDominatorTreeWrapperPass();
55 AnalysisKey PostDominatorTreeAnalysis::Key;
57 PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
58 FunctionAnalysisManager &) {
59 PostDominatorTree PDT;
64 PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS)
68 PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
69 OS << "PostDominatorTree for function: " << F.getName() << "\n";
70 AM.getResult<PostDominatorTreeAnalysis>(F).print(OS);
72 return PreservedAnalyses::all();