2009-06-02 17:52:33 +00:00
|
|
|
//===- PostDominators.cpp - Post-Dominator Calculation --------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the post-dominator construction algorithms.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Analysis/PostDominators.h"
|
|
|
|
#include "llvm/ADT/DepthFirstIterator.h"
|
|
|
|
#include "llvm/ADT/SetOperations.h"
|
2014-11-24 09:08:18 +00:00
|
|
|
#include "llvm/IR/CFG.h"
|
2013-04-08 18:41:23 +00:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2016-07-23 20:41:05 +00:00
|
|
|
#include "llvm/IR/PassManager.h"
|
2013-04-08 18:41:23 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2014-11-24 09:08:18 +00:00
|
|
|
#include "llvm/Support/GenericDomTreeConstruction.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-11-24 09:08:18 +00:00
|
|
|
#define DEBUG_TYPE "postdomtree"
|
|
|
|
|
2009-06-02 17:52:33 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PostDominatorTree Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
char PostDominatorTreeWrapperPass::ID = 0;
|
|
|
|
INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
|
2011-02-20 12:57:14 +00:00
|
|
|
"Post-Dominator Tree Construction", true, true)
|
2009-06-02 17:52:33 +00:00
|
|
|
|
2017-04-16 16:01:22 +00: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-07-23 20:41:05 +00:00
|
|
|
bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
|
|
|
|
DT.recalculate(F);
|
2009-06-02 17:52:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
|
|
|
|
DT.print(OS);
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
FunctionPass* llvm::createPostDomTree() {
|
|
|
|
return new PostDominatorTreeWrapperPass();
|
2009-10-14 17:57:32 +00:00
|
|
|
}
|
|
|
|
|
2017-01-02 19:17:04 +00:00
|
|
|
AnalysisKey PostDominatorTreeAnalysis::Key;
|
2009-10-14 17:57:32 +00:00
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
|
|
|
|
FunctionAnalysisManager &) {
|
|
|
|
PostDominatorTree PDT;
|
|
|
|
PDT.recalculate(F);
|
|
|
|
return PDT;
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS)
|
|
|
|
: OS(OS) {}
|
|
|
|
|
|
|
|
PreservedAnalyses
|
|
|
|
PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
|
|
|
|
OS << "PostDominatorTree for function: " << F.getName() << "\n";
|
|
|
|
AM.getResult<PostDominatorTreeAnalysis>(F).print(OS);
|
|
|
|
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|