1 //===- DominanceFrontier.cpp - Dominance Frontier 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 #include "llvm/Analysis/DominanceFrontier.h"
11 #include "llvm/Analysis/DominanceFrontierImpl.h"
12 #include "llvm/Config/llvm-config.h"
13 #include "llvm/IR/Dominators.h"
14 #include "llvm/IR/Function.h"
15 #include "llvm/IR/PassManager.h"
16 #include "llvm/Pass.h"
17 #include "llvm/Support/Compiler.h"
18 #include "llvm/Support/Debug.h"
19 #include "llvm/Support/raw_ostream.h"
25 template class DominanceFrontierBase
<BasicBlock
, false>;
26 template class DominanceFrontierBase
<BasicBlock
, true>;
27 template class ForwardDominanceFrontierBase
<BasicBlock
>;
29 } // end namespace llvm
31 char DominanceFrontierWrapperPass::ID
= 0;
33 INITIALIZE_PASS_BEGIN(DominanceFrontierWrapperPass
, "domfrontier",
34 "Dominance Frontier Construction", true, true)
35 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass
)
36 INITIALIZE_PASS_END(DominanceFrontierWrapperPass
, "domfrontier",
37 "Dominance Frontier Construction", true, true)
39 DominanceFrontierWrapperPass::DominanceFrontierWrapperPass()
40 : FunctionPass(ID
), DF() {
41 initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry());
44 void DominanceFrontierWrapperPass::releaseMemory() {
48 bool DominanceFrontierWrapperPass::runOnFunction(Function
&) {
50 DF
.analyze(getAnalysis
<DominatorTreeWrapperPass
>().getDomTree());
54 void DominanceFrontierWrapperPass::getAnalysisUsage(AnalysisUsage
&AU
) const {
56 AU
.addRequired
<DominatorTreeWrapperPass
>();
59 void DominanceFrontierWrapperPass::print(raw_ostream
&OS
, const Module
*) const {
63 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
64 LLVM_DUMP_METHOD
void DominanceFrontierWrapperPass::dump() const {
69 /// Handle invalidation explicitly.
70 bool DominanceFrontier::invalidate(Function
&F
, const PreservedAnalyses
&PA
,
71 FunctionAnalysisManager::Invalidator
&) {
72 // Check whether the analysis, all analyses on functions, or the function's
73 // CFG have been preserved.
74 auto PAC
= PA
.getChecker
<DominanceFrontierAnalysis
>();
75 return !(PAC
.preserved() || PAC
.preservedSet
<AllAnalysesOn
<Function
>>() ||
76 PAC
.preservedSet
<CFGAnalyses
>());
79 AnalysisKey
DominanceFrontierAnalysis::Key
;
81 DominanceFrontier
DominanceFrontierAnalysis::run(Function
&F
,
82 FunctionAnalysisManager
&AM
) {
84 DF
.analyze(AM
.getResult
<DominatorTreeAnalysis
>(F
));
88 DominanceFrontierPrinterPass::DominanceFrontierPrinterPass(raw_ostream
&OS
)
92 DominanceFrontierPrinterPass::run(Function
&F
, FunctionAnalysisManager
&AM
) {
93 OS
<< "DominanceFrontier for function: " << F
.getName() << "\n";
94 AM
.getResult
<DominanceFrontierAnalysis
>(F
).print(OS
);
96 return PreservedAnalyses::all();