1 //===- PostDominators.cpp - Post-Dominator Calculation --------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the post-dominator construction algorithms.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Analysis/PostDominators.h"
14 #include "llvm/IR/Function.h"
15 #include "llvm/IR/PassManager.h"
16 #include "llvm/Pass.h"
17 #include "llvm/Support/raw_ostream.h"
21 #define DEBUG_TYPE "postdomtree"
23 #ifdef EXPENSIVE_CHECKS
24 static constexpr bool ExpensiveChecksEnabled
= true;
26 static constexpr bool ExpensiveChecksEnabled
= false;
29 //===----------------------------------------------------------------------===//
30 // PostDominatorTree Implementation
31 //===----------------------------------------------------------------------===//
33 char PostDominatorTreeWrapperPass::ID
= 0;
35 INITIALIZE_PASS(PostDominatorTreeWrapperPass
, "postdomtree",
36 "Post-Dominator Tree Construction", true, true)
38 bool PostDominatorTree::invalidate(Function
&F
, const PreservedAnalyses
&PA
,
39 FunctionAnalysisManager::Invalidator
&) {
40 // Check whether the analysis, all analyses on functions, or the function's
41 // CFG have been preserved.
42 auto PAC
= PA
.getChecker
<PostDominatorTreeAnalysis
>();
43 return !(PAC
.preserved() || PAC
.preservedSet
<AllAnalysesOn
<Function
>>() ||
44 PAC
.preservedSet
<CFGAnalyses
>());
47 bool PostDominatorTreeWrapperPass::runOnFunction(Function
&F
) {
52 void PostDominatorTreeWrapperPass::verifyAnalysis() const {
54 assert(DT
.verify(PostDominatorTree::VerificationLevel::Full
));
55 else if (ExpensiveChecksEnabled
)
56 assert(DT
.verify(PostDominatorTree::VerificationLevel::Basic
));
59 void PostDominatorTreeWrapperPass::print(raw_ostream
&OS
, const Module
*) const {
63 FunctionPass
* llvm::createPostDomTree() {
64 return new PostDominatorTreeWrapperPass();
67 AnalysisKey
PostDominatorTreeAnalysis::Key
;
69 PostDominatorTree
PostDominatorTreeAnalysis::run(Function
&F
,
70 FunctionAnalysisManager
&) {
71 PostDominatorTree
PDT(F
);
75 PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream
&OS
)
79 PostDominatorTreePrinterPass::run(Function
&F
, FunctionAnalysisManager
&AM
) {
80 OS
<< "PostDominatorTree for function: " << F
.getName() << "\n";
81 AM
.getResult
<PostDominatorTreeAnalysis
>(F
).print(OS
);
83 return PreservedAnalyses::all();