2011-01-18 14:06:27 +08:00
|
|
|
//===- DominanceFrontier.cpp - Dominance Frontier Calculation -------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-01-18 14:06:27 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Analysis/DominanceFrontier.h"
|
2014-07-13 05:59:52 +08:00
|
|
|
#include "llvm/Analysis/DominanceFrontierImpl.h"
|
2018-04-30 22:59:11 +08:00
|
|
|
#include "llvm/Config/llvm-config.h"
|
2017-07-25 07:16:33 +08:00
|
|
|
#include "llvm/IR/Dominators.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
2016-02-26 01:54:15 +08:00
|
|
|
#include "llvm/IR/PassManager.h"
|
2017-07-25 07:16:33 +08:00
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.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 {
|
2017-07-25 07:16:33 +08:00
|
|
|
|
2017-07-15 02:26:09 +08:00
|
|
|
template class DominanceFrontierBase<BasicBlock, false>;
|
|
|
|
template class DominanceFrontierBase<BasicBlock, true>;
|
2014-07-13 05:59:52 +08:00
|
|
|
template class ForwardDominanceFrontierBase<BasicBlock>;
|
2017-07-25 07:16:33 +08:00
|
|
|
|
|
|
|
} // end namespace llvm
|
2014-07-13 05:59:52 +08:00
|
|
|
|
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)
|
|
|
|
|
2017-07-25 07:16:33 +08:00
|
|
|
DominanceFrontierWrapperPass::DominanceFrontierWrapperPass()
|
2016-02-26 01:54:15 +08:00
|
|
|
: 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
|
|
|
}
|
|
|
|
|
2017-10-15 22:32:27 +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
|
|
|
|
2017-01-15 14:32:49 +08: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-24 01:53:26 +08:00
|
|
|
AnalysisKey DominanceFrontierAnalysis::Key;
|
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();
|
|
|
|
}
|