xref: /aosp_15_r20/external/llvm/lib/Analysis/PostDominators.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- PostDominators.cpp - Post-Dominator Calculation --------------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file implements the post-dominator construction algorithms.
11*9880d681SAndroid Build Coastguard Worker //
12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
13*9880d681SAndroid Build Coastguard Worker 
14*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/PostDominators.h"
15*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/DepthFirstIterator.h"
16*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SetOperations.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/CFG.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Instructions.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/PassManager.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Debug.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/GenericDomTreeConstruction.h"
22*9880d681SAndroid Build Coastguard Worker using namespace llvm;
23*9880d681SAndroid Build Coastguard Worker 
24*9880d681SAndroid Build Coastguard Worker #define DEBUG_TYPE "postdomtree"
25*9880d681SAndroid Build Coastguard Worker 
26*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
27*9880d681SAndroid Build Coastguard Worker //  PostDominatorTree Implementation
28*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
29*9880d681SAndroid Build Coastguard Worker 
30*9880d681SAndroid Build Coastguard Worker char PostDominatorTreeWrapperPass::ID = 0;
31*9880d681SAndroid Build Coastguard Worker INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
32*9880d681SAndroid Build Coastguard Worker                 "Post-Dominator Tree Construction", true, true)
33*9880d681SAndroid Build Coastguard Worker 
runOnFunction(Function & F)34*9880d681SAndroid Build Coastguard Worker bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
35*9880d681SAndroid Build Coastguard Worker   DT.recalculate(F);
36*9880d681SAndroid Build Coastguard Worker   return false;
37*9880d681SAndroid Build Coastguard Worker }
38*9880d681SAndroid Build Coastguard Worker 
print(raw_ostream & OS,const Module *) const39*9880d681SAndroid Build Coastguard Worker void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
40*9880d681SAndroid Build Coastguard Worker   DT.print(OS);
41*9880d681SAndroid Build Coastguard Worker }
42*9880d681SAndroid Build Coastguard Worker 
createPostDomTree()43*9880d681SAndroid Build Coastguard Worker FunctionPass* llvm::createPostDomTree() {
44*9880d681SAndroid Build Coastguard Worker   return new PostDominatorTreeWrapperPass();
45*9880d681SAndroid Build Coastguard Worker }
46*9880d681SAndroid Build Coastguard Worker 
47*9880d681SAndroid Build Coastguard Worker char PostDominatorTreeAnalysis::PassID;
48*9880d681SAndroid Build Coastguard Worker 
run(Function & F,FunctionAnalysisManager &)49*9880d681SAndroid Build Coastguard Worker PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
50*9880d681SAndroid Build Coastguard Worker                                                  FunctionAnalysisManager &) {
51*9880d681SAndroid Build Coastguard Worker   PostDominatorTree PDT;
52*9880d681SAndroid Build Coastguard Worker   PDT.recalculate(F);
53*9880d681SAndroid Build Coastguard Worker   return PDT;
54*9880d681SAndroid Build Coastguard Worker }
55*9880d681SAndroid Build Coastguard Worker 
PostDominatorTreePrinterPass(raw_ostream & OS)56*9880d681SAndroid Build Coastguard Worker PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS)
57*9880d681SAndroid Build Coastguard Worker   : OS(OS) {}
58*9880d681SAndroid Build Coastguard Worker 
59*9880d681SAndroid Build Coastguard Worker PreservedAnalyses
run(Function & F,FunctionAnalysisManager & AM)60*9880d681SAndroid Build Coastguard Worker PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
61*9880d681SAndroid Build Coastguard Worker   OS << "PostDominatorTree for function: " << F.getName() << "\n";
62*9880d681SAndroid Build Coastguard Worker   AM.getResult<PostDominatorTreeAnalysis>(F).print(OS);
63*9880d681SAndroid Build Coastguard Worker 
64*9880d681SAndroid Build Coastguard Worker   return PreservedAnalyses::all();
65*9880d681SAndroid Build Coastguard Worker }
66