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"
|
2004-09-02 06:55:40 +08:00
|
|
|
#include "llvm/ADT/DepthFirstIterator.h"
|
|
|
|
#include "llvm/ADT/SetOperations.h"
|
2014-03-04 19:45:46 +08:00
|
|
|
#include "llvm/IR/CFG.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2016-02-26 01:54:07 +08:00
|
|
|
#include "llvm/IR/PassManager.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2014-03-04 18:07:28 +08:00
|
|
|
#include "llvm/Support/GenericDomTreeConstruction.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"
|
|
|
|
|
2017-07-15 02:26:09 +08:00
|
|
|
template class llvm::DominatorTreeBase<BasicBlock, true>; // PostDomTreeBase
|
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|