2011-01-18 06:06:27 +00:00
|
|
|
//===- DominanceFrontier.cpp - Dominance Frontier Calculation -------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Analysis/DominanceFrontier.h"
|
2014-07-12 21:59:52 +00:00
|
|
|
#include "llvm/Analysis/DominanceFrontierImpl.h"
|
2016-02-25 17:54:15 +00:00
|
|
|
#include "llvm/IR/PassManager.h"
|
2014-07-12 21:59:52 +00:00
|
|
|
|
2011-01-18 06:06:27 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-07-12 21:59:52 +00:00
|
|
|
namespace llvm {
|
|
|
|
template class DominanceFrontierBase<BasicBlock>;
|
|
|
|
template class ForwardDominanceFrontierBase<BasicBlock>;
|
|
|
|
}
|
|
|
|
|
2016-02-25 17:54:15 +00:00
|
|
|
char DominanceFrontierWrapperPass::ID = 0;
|
2014-07-12 21:59:52 +00:00
|
|
|
|
2016-02-25 17:54:15 +00:00
|
|
|
INITIALIZE_PASS_BEGIN(DominanceFrontierWrapperPass, "domfrontier",
|
2011-01-18 06:06:27 +00:00
|
|
|
"Dominance Frontier Construction", true, true)
|
2014-01-13 13:07:17 +00:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
2016-02-25 17:54:15 +00:00
|
|
|
INITIALIZE_PASS_END(DominanceFrontierWrapperPass, "domfrontier",
|
2011-01-18 06:06:27 +00:00
|
|
|
"Dominance Frontier Construction", true, true)
|
|
|
|
|
2016-02-25 17:54:15 +00:00
|
|
|
DominanceFrontierWrapperPass::DominanceFrontierWrapperPass()
|
|
|
|
: FunctionPass(ID), DF() {
|
|
|
|
initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry());
|
2011-01-18 06:06:27 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 17:54:15 +00:00
|
|
|
void DominanceFrontierWrapperPass::releaseMemory() {
|
|
|
|
DF.releaseMemory();
|
2014-07-12 21:59:52 +00:00
|
|
|
}
|
2011-01-18 06:06:27 +00:00
|
|
|
|
2016-02-25 17:54:15 +00:00
|
|
|
bool DominanceFrontierWrapperPass::runOnFunction(Function &) {
|
2014-07-12 21:59:52 +00:00
|
|
|
releaseMemory();
|
2016-02-25 17:54:15 +00:00
|
|
|
DF.analyze(getAnalysis<DominatorTreeWrapperPass>().getDomTree());
|
2014-07-12 21:59:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-18 06:06:27 +00:00
|
|
|
|
2016-02-25 17:54:15 +00:00
|
|
|
void DominanceFrontierWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
2014-07-12 21:59:52 +00:00
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addRequired<DominatorTreeWrapperPass>();
|
2011-01-18 06:06:27 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 17:54:15 +00:00
|
|
|
void DominanceFrontierWrapperPass::print(raw_ostream &OS, const Module *) const {
|
|
|
|
DF.print(OS);
|
2011-01-18 06:06:27 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 05:06:18 +00:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2016-02-25 17:54:15 +00:00
|
|
|
LLVM_DUMP_METHOD void DominanceFrontierWrapperPass::dump() const {
|
2011-01-18 06:06:27 +00:00
|
|
|
print(dbgs());
|
|
|
|
}
|
2012-09-06 19:55:56 +00:00
|
|
|
#endif
|
2016-02-25 17:54:15 +00:00
|
|
|
|
2017-01-15 06:32:49 +00:00
|
|
|
/// Handle invalidation explicitly.
|
|
|
|
bool DominanceFrontier::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<DominanceFrontierAnalysis>();
|
|
|
|
return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() ||
|
|
|
|
PAC.preservedSet<CFGAnalyses>());
|
|
|
|
}
|
|
|
|
|
2016-11-23 17:53:26 +00:00
|
|
|
AnalysisKey DominanceFrontierAnalysis::Key;
|
2016-02-28 17:17:00 +00:00
|
|
|
|
2016-02-25 17:54:15 +00:00
|
|
|
DominanceFrontier DominanceFrontierAnalysis::run(Function &F,
|
2016-03-11 11:05:24 +00:00
|
|
|
FunctionAnalysisManager &AM) {
|
2016-02-25 17:54:15 +00:00
|
|
|
DominanceFrontier DF;
|
2016-03-11 11:05:24 +00:00
|
|
|
DF.analyze(AM.getResult<DominatorTreeAnalysis>(F));
|
2016-02-25 17:54:15 +00:00
|
|
|
return DF;
|
|
|
|
}
|
|
|
|
|
|
|
|
DominanceFrontierPrinterPass::DominanceFrontierPrinterPass(raw_ostream &OS)
|
|
|
|
: OS(OS) {}
|
|
|
|
|
|
|
|
PreservedAnalyses
|
2016-03-11 11:05:24 +00:00
|
|
|
DominanceFrontierPrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
|
2016-02-25 17:54:15 +00:00
|
|
|
OS << "DominanceFrontier for function: " << F.getName() << "\n";
|
2016-03-11 11:05:24 +00:00
|
|
|
AM.getResult<DominanceFrontierAnalysis>(F).print(OS);
|
2016-02-25 17:54:15 +00:00
|
|
|
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|