2011-01-18 14:06:27 +08: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-13 05:59:52 +08:00
|
|
|
#include "llvm/Analysis/DominanceFrontierImpl.h"
|
2016-02-26 01:54:15 +08:00
|
|
|
#include "llvm/IR/PassManager.h"
|
2014-07-13 05:59:52 +08:00
|
|
|
|
2011-01-18 14:06:27 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-07-13 05:59:52 +08:00
|
|
|
namespace llvm {
|
|
|
|
template class DominanceFrontierBase<BasicBlock>;
|
|
|
|
template class ForwardDominanceFrontierBase<BasicBlock>;
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:54:15 +08:00
|
|
|
char DominanceFrontierWrapperPass::ID = 0;
|
2014-07-13 05:59:52 +08:00
|
|
|
|
2016-02-26 01:54:15 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(DominanceFrontierWrapperPass, "domfrontier",
|
2011-01-18 14:06:27 +08:00
|
|
|
"Dominance Frontier Construction", true, true)
|
2014-01-13 21:07:17 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
2016-02-26 01:54:15 +08:00
|
|
|
INITIALIZE_PASS_END(DominanceFrontierWrapperPass, "domfrontier",
|
2011-01-18 14:06:27 +08:00
|
|
|
"Dominance Frontier Construction", true, true)
|
|
|
|
|
2016-02-26 01:54:15 +08:00
|
|
|
DominanceFrontierWrapperPass::DominanceFrontierWrapperPass()
|
|
|
|
: FunctionPass(ID), DF() {
|
|
|
|
initializeDominanceFrontierWrapperPassPass(*PassRegistry::getPassRegistry());
|
2011-01-18 14:06:27 +08:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:54:15 +08:00
|
|
|
void DominanceFrontierWrapperPass::releaseMemory() {
|
|
|
|
DF.releaseMemory();
|
2014-07-13 05:59:52 +08:00
|
|
|
}
|
2011-01-18 14:06:27 +08:00
|
|
|
|
2016-02-26 01:54:15 +08:00
|
|
|
bool DominanceFrontierWrapperPass::runOnFunction(Function &) {
|
2014-07-13 05:59:52 +08:00
|
|
|
releaseMemory();
|
2016-02-26 01:54:15 +08:00
|
|
|
DF.analyze(getAnalysis<DominatorTreeWrapperPass>().getDomTree());
|
2014-07-13 05:59:52 +08:00
|
|
|
return false;
|
|
|
|
}
|
2011-01-18 14:06:27 +08:00
|
|
|
|
2016-02-26 01:54:15 +08:00
|
|
|
void DominanceFrontierWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
2014-07-13 05:59:52 +08:00
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addRequired<DominatorTreeWrapperPass>();
|
2011-01-18 14:06:27 +08:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:54:15 +08:00
|
|
|
void DominanceFrontierWrapperPass::print(raw_ostream &OS, const Module *) const {
|
|
|
|
DF.print(OS);
|
2011-01-18 14:06:27 +08:00
|
|
|
}
|
|
|
|
|
2012-09-12 13:06:18 +08:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2016-02-26 01:54:15 +08:00
|
|
|
LLVM_DUMP_METHOD void DominanceFrontierWrapperPass::dump() const {
|
2011-01-18 14:06:27 +08:00
|
|
|
print(dbgs());
|
|
|
|
}
|
2012-09-07 03:55:56 +08:00
|
|
|
#endif
|
2016-02-26 01:54:15 +08:00
|
|
|
|
2016-03-11 18:22:49 +08:00
|
|
|
char DominanceFrontierAnalysis::PassID;
|
2016-02-29 01:17:00 +08:00
|
|
|
|
2016-02-26 01:54:15 +08:00
|
|
|
DominanceFrontier DominanceFrontierAnalysis::run(Function &F,
|
2016-03-11 19:05:24 +08:00
|
|
|
FunctionAnalysisManager &AM) {
|
2016-02-26 01:54:15 +08:00
|
|
|
DominanceFrontier DF;
|
2016-03-11 19:05:24 +08:00
|
|
|
DF.analyze(AM.getResult<DominatorTreeAnalysis>(F));
|
2016-02-26 01:54:15 +08:00
|
|
|
return DF;
|
|
|
|
}
|
|
|
|
|
|
|
|
DominanceFrontierPrinterPass::DominanceFrontierPrinterPass(raw_ostream &OS)
|
|
|
|
: OS(OS) {}
|
|
|
|
|
|
|
|
PreservedAnalyses
|
2016-03-11 19:05:24 +08:00
|
|
|
DominanceFrontierPrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
|
2016-02-26 01:54:15 +08:00
|
|
|
OS << "DominanceFrontier for function: " << F.getName() << "\n";
|
2016-03-11 19:05:24 +08:00
|
|
|
AM.getResult<DominanceFrontierAnalysis>(F).print(OS);
|
2016-02-26 01:54:15 +08:00
|
|
|
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|