2002-08-03 00:43:03 +08:00
|
|
|
//===- PostDominators.cpp - Post-Dominator Calculation --------------------===//
|
2005-04-22 05:13:18 +08:00
|
|
|
//
|
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
|
2005-04-22 05:13:18 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-02 13:46:38 +08:00
|
|
|
//
|
2002-08-03 00:43:03 +08:00
|
|
|
// This file implements the post-dominator construction algorithms.
|
2001-07-02 13:46:38 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-08-22 07:43:50 +08:00
|
|
|
#include "llvm/Analysis/PostDominators.h"
|
2017-08-17 06:07:40 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
[CodeMoverUtils] Added an API to check if an instruction can be safely
moved before another instruction.
Summary:Added an API to check if an instruction can be safely moved
before another instruction. In future PRs, we will like to add support
of moving instructions between blocks that are not control flow
equivalent, and add other APIs to enhance usability, e.g. moving basic
blocks, moving list of instructions...
Loop Fusion will be its first user. When there is intervening code in
between two loops, fusion is currently unable to fuse them. Loop Fusion
can use this utility to check if the intervening code can be safely
moved before or after the two loops, and move them, then it can
successfully fuse them.
Reviewer:kbarton,jdoerfert,Meinersbur,bmahjour,etiotto
Reviewed By:bmahjour
Subscribers:mgorny,hiraditya,llvm-commits
Tag:LLVM
Differential Revision:https://reviews.llvm.org/D70049
2019-11-23 05:27:29 +08:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2016-02-26 01:54:07 +08: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-14 05:15:01 +08:00
|
|
|
#include "llvm/InitializePasses.h"
|
2017-08-17 06:07:40 +08:00
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
2003-12-07 08:35:42 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2014-04-22 10:48:03 +08:00
|
|
|
#define DEBUG_TYPE "postdomtree"
|
|
|
|
|
2018-02-28 19:00:08 +08:00
|
|
|
#ifdef EXPENSIVE_CHECKS
|
|
|
|
static constexpr bool ExpensiveChecksEnabled = true;
|
|
|
|
#else
|
|
|
|
static constexpr bool ExpensiveChecksEnabled = false;
|
|
|
|
#endif
|
|
|
|
|
2006-03-11 10:20:46 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-04-15 16:47:27 +08:00
|
|
|
// PostDominatorTree Implementation
|
2006-03-11 10:20:46 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-02-26 01:54:07 +08:00
|
|
|
char PostDominatorTreeWrapperPass::ID = 0;
|
2017-08-17 06:07:40 +08:00
|
|
|
|
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-14 05:15:01 +08:00
|
|
|
PostDominatorTreeWrapperPass::PostDominatorTreeWrapperPass()
|
|
|
|
: FunctionPass(ID) {
|
|
|
|
initializePostDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:54:07 +08:00
|
|
|
INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
|
2010-10-08 06:25:06 +08:00
|
|
|
"Post-Dominator Tree Construction", true, true)
|
2006-03-11 10:20:46 +08:00
|
|
|
|
2017-01-15 14:32:49 +08: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>());
|
|
|
|
}
|
|
|
|
|
[CodeMoverUtils] Added an API to check if an instruction can be safely
moved before another instruction.
Summary:Added an API to check if an instruction can be safely moved
before another instruction. In future PRs, we will like to add support
of moving instructions between blocks that are not control flow
equivalent, and add other APIs to enhance usability, e.g. moving basic
blocks, moving list of instructions...
Loop Fusion will be its first user. When there is intervening code in
between two loops, fusion is currently unable to fuse them. Loop Fusion
can use this utility to check if the intervening code can be safely
moved before or after the two loops, and move them, then it can
successfully fuse them.
Reviewer:kbarton,jdoerfert,Meinersbur,bmahjour,etiotto
Reviewed By:bmahjour
Subscribers:mgorny,hiraditya,llvm-commits
Tag:LLVM
Differential Revision:https://reviews.llvm.org/D70049
2019-11-23 05:27:29 +08:00
|
|
|
bool PostDominatorTree::dominates(const Instruction *I1,
|
|
|
|
const Instruction *I2) const {
|
|
|
|
assert(I1 && I2 && "Expecting valid I1 and I2");
|
|
|
|
|
|
|
|
const BasicBlock *BB1 = I1->getParent();
|
|
|
|
const BasicBlock *BB2 = I2->getParent();
|
|
|
|
|
|
|
|
if (BB1 != BB2)
|
|
|
|
return Base::dominates(BB1, BB2);
|
|
|
|
|
|
|
|
// PHINodes in a block are unordered.
|
|
|
|
if (isa<PHINode>(I1) && isa<PHINode>(I2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Loop through the basic block until we find I1 or I2.
|
|
|
|
BasicBlock::const_iterator I = BB1->begin();
|
|
|
|
for (; &*I != I1 && &*I != I2; ++I)
|
|
|
|
/*empty*/;
|
|
|
|
|
|
|
|
return &*I == I2;
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:54:07 +08:00
|
|
|
bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
|
|
|
|
DT.recalculate(F);
|
2007-10-03 11:20:17 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-28 19:00:08 +08:00
|
|
|
void PostDominatorTreeWrapperPass::verifyAnalysis() const {
|
|
|
|
if (VerifyDomInfo)
|
|
|
|
assert(DT.verify(PostDominatorTree::VerificationLevel::Full));
|
|
|
|
else if (ExpensiveChecksEnabled)
|
|
|
|
assert(DT.verify(PostDominatorTree::VerificationLevel::Basic));
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:54:07 +08:00
|
|
|
void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
|
|
|
|
DT.print(OS);
|
2008-05-04 04:25:26 +08:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:54:07 +08:00
|
|
|
FunctionPass* llvm::createPostDomTree() {
|
|
|
|
return new PostDominatorTreeWrapperPass();
|
2009-08-23 13:17:37 +08:00
|
|
|
}
|
|
|
|
|
2016-11-24 01:53:26 +08:00
|
|
|
AnalysisKey PostDominatorTreeAnalysis::Key;
|
2016-02-29 01:17:00 +08:00
|
|
|
|
2016-06-17 08:11:01 +08:00
|
|
|
PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
|
|
|
|
FunctionAnalysisManager &) {
|
2018-05-24 01:29:21 +08:00
|
|
|
PostDominatorTree PDT(F);
|
2016-02-26 01:54:07 +08:00
|
|
|
return PDT;
|
2008-05-30 01:00:13 +08:00
|
|
|
}
|
|
|
|
|
2016-02-26 01:54:07 +08:00
|
|
|
PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS)
|
|
|
|
: OS(OS) {}
|
|
|
|
|
|
|
|
PreservedAnalyses
|
2016-03-11 19:05:24 +08:00
|
|
|
PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
|
2016-02-26 01:54:07 +08:00
|
|
|
OS << "PostDominatorTree for function: " << F.getName() << "\n";
|
2016-03-11 19:05:24 +08:00
|
|
|
AM.getResult<PostDominatorTreeAnalysis>(F).print(OS);
|
2016-02-26 01:54:07 +08:00
|
|
|
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|