2002-08-02 18:43:03 +02:00
|
|
|
//===- PostDominators.cpp - Post-Dominator Calculation --------------------===//
|
2005-04-21 23:13:18 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01: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-21 23:13:18 +02:00
|
|
|
//
|
2003-10-20 21:43:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-07-02 07:46:38 +02:00
|
|
|
//
|
2002-08-02 18:43:03 +02:00
|
|
|
// This file implements the post-dominator construction algorithms.
|
2001-07-02 07:46:38 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-08-22 01:43:50 +02:00
|
|
|
#include "llvm/Analysis/PostDominators.h"
|
2017-08-17 00:07:40 +02: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-22 22:27:29 +01:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2016-02-25 18:54:07 +01: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 22:15:01 +01:00
|
|
|
#include "llvm/InitializePasses.h"
|
2017-08-17 00:07:40 +02:00
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
2003-12-07 01:35:42 +01:00
|
|
|
using namespace llvm;
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2014-04-22 04:48:03 +02:00
|
|
|
#define DEBUG_TYPE "postdomtree"
|
|
|
|
|
2018-02-28 12:00:08 +01:00
|
|
|
#ifdef EXPENSIVE_CHECKS
|
|
|
|
static constexpr bool ExpensiveChecksEnabled = true;
|
|
|
|
#else
|
|
|
|
static constexpr bool ExpensiveChecksEnabled = false;
|
|
|
|
#endif
|
|
|
|
|
2006-03-11 03:20:46 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-04-15 10:47:27 +02:00
|
|
|
// PostDominatorTree Implementation
|
2006-03-11 03:20:46 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
char PostDominatorTreeWrapperPass::ID = 0;
|
2017-08-17 00:07:40 +02: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-13 22:15:01 +01:00
|
|
|
PostDominatorTreeWrapperPass::PostDominatorTreeWrapperPass()
|
|
|
|
: FunctionPass(ID) {
|
|
|
|
initializePostDominatorTreeWrapperPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
INITIALIZE_PASS(PostDominatorTreeWrapperPass, "postdomtree",
|
2010-10-08 00:25:06 +02:00
|
|
|
"Post-Dominator Tree Construction", true, true)
|
2006-03-11 03:20:46 +01:00
|
|
|
|
2017-01-15 07:32:49 +01: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-22 22:27:29 +01: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-25 18:54:07 +01:00
|
|
|
bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
|
|
|
|
DT.recalculate(F);
|
2007-10-03 05:20:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-28 12:00:08 +01:00
|
|
|
void PostDominatorTreeWrapperPass::verifyAnalysis() const {
|
|
|
|
if (VerifyDomInfo)
|
|
|
|
assert(DT.verify(PostDominatorTree::VerificationLevel::Full));
|
|
|
|
else if (ExpensiveChecksEnabled)
|
|
|
|
assert(DT.verify(PostDominatorTree::VerificationLevel::Basic));
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
|
|
|
|
DT.print(OS);
|
2008-05-03 22:25:26 +02:00
|
|
|
}
|
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
FunctionPass* llvm::createPostDomTree() {
|
|
|
|
return new PostDominatorTreeWrapperPass();
|
2009-08-23 07:17:37 +02:00
|
|
|
}
|
|
|
|
|
2016-11-23 18:53:26 +01:00
|
|
|
AnalysisKey PostDominatorTreeAnalysis::Key;
|
2016-02-28 18:17:00 +01:00
|
|
|
|
2016-06-17 02:11:01 +02:00
|
|
|
PostDominatorTree PostDominatorTreeAnalysis::run(Function &F,
|
|
|
|
FunctionAnalysisManager &) {
|
2018-05-23 19:29:21 +02:00
|
|
|
PostDominatorTree PDT(F);
|
2016-02-25 18:54:07 +01:00
|
|
|
return PDT;
|
2008-05-29 19:00:13 +02:00
|
|
|
}
|
|
|
|
|
2016-02-25 18:54:07 +01:00
|
|
|
PostDominatorTreePrinterPass::PostDominatorTreePrinterPass(raw_ostream &OS)
|
|
|
|
: OS(OS) {}
|
|
|
|
|
|
|
|
PreservedAnalyses
|
2016-03-11 12:05:24 +01:00
|
|
|
PostDominatorTreePrinterPass::run(Function &F, FunctionAnalysisManager &AM) {
|
2016-02-25 18:54:07 +01:00
|
|
|
OS << "PostDominatorTree for function: " << F.getName() << "\n";
|
2016-03-11 12:05:24 +01:00
|
|
|
AM.getResult<PostDominatorTreeAnalysis>(F).print(OS);
|
2016-02-25 18:54:07 +01:00
|
|
|
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|