2011-01-18 06:06:27 +00:00
|
|
|
//===- DominanceFrontier.cpp - Dominance Frontier Calculation -------------===//
|
|
|
|
//
|
2019-01-19 08:50:56 +00: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 06:06:27 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Analysis/DominanceFrontier.h"
|
2014-07-12 21:59:52 +00:00
|
|
|
#include "llvm/Analysis/DominanceFrontierImpl.h"
|
2018-04-30 14:59:11 +00:00
|
|
|
#include "llvm/Config/llvm-config.h"
|
2017-07-24 23:16:33 +00:00
|
|
|
#include "llvm/IR/Dominators.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
2016-02-25 17:54:15 +00:00
|
|
|
#include "llvm/IR/PassManager.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-13 21:15:01 +00:00
|
|
|
#include "llvm/InitializePasses.h"
|
2017-07-24 23:16:33 +00:00
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.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 {
|
2017-07-24 23:16:33 +00:00
|
|
|
|
2017-07-14 18:26:09 +00:00
|
|
|
template class DominanceFrontierBase<BasicBlock, false>;
|
|
|
|
template class DominanceFrontierBase<BasicBlock, true>;
|
2014-07-12 21:59:52 +00:00
|
|
|
template class ForwardDominanceFrontierBase<BasicBlock>;
|
2017-07-24 23:16:33 +00:00
|
|
|
|
|
|
|
} // end namespace llvm
|
2014-07-12 21:59:52 +00:00
|
|
|
|
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)
|
|
|
|
|
2017-07-24 23:16:33 +00:00
|
|
|
DominanceFrontierWrapperPass::DominanceFrontierWrapperPass()
|
2016-02-25 17:54:15 +00:00
|
|
|
: 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
|
|
|
}
|
|
|
|
|
2017-10-15 14:32:27 +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();
|
|
|
|
}
|