2002-08-03 00:43:03 +08:00
|
|
|
//===- PostDominators.cpp - Post-Dominator Calculation --------------------===//
|
2005-04-22 05:13:18 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 05:13:18 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-02 13:46:38 +08:00
|
|
|
//
|
2002-08-03 00:43:03 +08:00
|
|
|
// This file implements the post-dominator construction algorithms.
|
2001-07-02 13:46:38 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-08-22 07:43:50 +08:00
|
|
|
#include "llvm/Analysis/PostDominators.h"
|
2017-08-17 06:07:40 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
2016-02-26 01:54:07 +08:00
|
|
|
#include "llvm/IR/PassManager.h"
|
2017-08-17 06:07:40 +08:00
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
2003-12-07 08:35:42 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2014-04-22 10:48:03 +08:00
|
|
|
#define DEBUG_TYPE "postdomtree"
|
|
|
|
|
2018-02-28 19:00:08 +08:00
|
|
|
#ifdef EXPENSIVE_CHECKS
|
|
|
|
static constexpr bool ExpensiveChecksEnabled = true;
|
|
|
|
#else
|
|
|
|
static constexpr bool ExpensiveChecksEnabled = false;
|
|
|
|
#endif
|
|
|
|
|
2006-03-11 10:20:46 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-04-15 16:47:27 +08:00
|
|
|
// PostDominatorTree Implementation
|
2006-03-11 10:20:46 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-02-26 01:54:07 +08:00
|
|
|
char PostDominatorTreeWrapperPass::ID = 0;
|
2017-08-17 06:07:40 +08:00
|
|
|
|
2016-02-26 01:54:07 +08:00
|
|
|
INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
|
2010-10-08 06:25:06 +08:00
|
|
|
"Post-Dominator Tree Construction", true, true)
|
2006-03-11 10:20:46 +08:00
|
|
|
|
2017-01-15 14:32:49 +08:00
|
|
|
bool PostDominatorTree::invalidate(Function &F, const PreservedAnalyses &PA,
|
|
|
|
FunctionAnalysisManager::Invalidator &) {
|
|
|
|
// Check whether the analysis, all analyses on functions, or the function's
|
|
|
|
// CFG have been preserved.
|
|
|
|
auto PAC = PA.getChecker<PostDominatorTreeAnalysis>();
|
|
|
|
return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() ||
|
|
|
|
PAC.preservedSet<CFGAnalyses>());
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:54:07 +08:00
|
|
|
bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
|
|
|
|
DT.recalculate(F);
|
2007-10-03 11:20:17 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-28 19:00:08 +08:00
|
|
|
void PostDominatorTreeWrapperPass::verifyAnalysis() const {
|
|
|
|
if (VerifyDomInfo)
|
|
|
|
assert(DT.verify(PostDominatorTree::VerificationLevel::Full));
|
|
|
|
else if (ExpensiveChecksEnabled)
|
|
|
|
assert(DT.verify(PostDominatorTree::VerificationLevel::Basic));
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:54:07 +08:00
|
|
|
void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
|
|
|
|
DT.print(OS);
|
2008-05-04 04:25:26 +08:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:54:07 +08:00
|
|
|
FunctionPass* llvm::createPostDomTree() {
|
|
|
|
return new PostDominatorTreeWrapperPass();
|
2009-08-23 13:17:37 +08:00
|
|
|
}
|
|
|
|
|
2016-11-24 01:53:26 +08:00
|
|
|
AnalysisKey PostDominatorTreeAnalysis::Key;
|
2016-02-29 01:17:00 +08:00
|
|
|
|
2016-06-17 08:11:01 +08:00
|
|
|
PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
|
|
|
|
FunctionAnalysisManager &) {
|
2016-02-26 01:54:07 +08:00
|
|
|
PostDominatorTree PDT;
|
|
|
|
PDT.recalculate(F);
|
|
|
|
return PDT;
|
2008-05-30 01:00:13 +08:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:54:07 +08:00
|
|
|
PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS)
|
|
|
|
: OS(OS) {}
|
|
|
|
|
|
|
|
PreservedAnalyses
|
2016-03-11 19:05:24 +08:00
|
|
|
PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
|
2016-02-26 01:54:07 +08:00
|
|
|
OS << "PostDominatorTree for function: " << F.getName() << "\n";
|
2016-03-11 19:05:24 +08:00
|
|
|
AM.getResult<PostDominatorTreeAnalysis>(F).print(OS);
|
2016-02-26 01:54:07 +08:00
|
|
|
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|