2012-09-17 22:08:37 +08:00
|
|
|
//===- MachinePostDominators.cpp -Machine Post Dominator 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
|
2012-09-17 22:08:37 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements simple dominator construction algorithms for finding
|
|
|
|
// post dominators on machine functions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachinePostDominators.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"
|
2012-09-17 22:08:37 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2017-07-15 02:26:09 +08:00
|
|
|
namespace llvm {
|
|
|
|
template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTreeBase
|
2019-10-01 23:23:27 +08:00
|
|
|
|
|
|
|
extern bool VerifyMachineDomInfo;
|
|
|
|
} // namespace llvm
|
2017-07-15 02:26:09 +08:00
|
|
|
|
2012-09-17 22:08:37 +08:00
|
|
|
char MachinePostDominatorTree::ID = 0;
|
|
|
|
|
|
|
|
//declare initializeMachinePostDominatorTreePass
|
|
|
|
INITIALIZE_PASS(MachinePostDominatorTree, "machinepostdomtree",
|
|
|
|
"MachinePostDominator Tree Construction", true, true)
|
|
|
|
|
[Dominators][AMDGPU] Don't use virtual exit node in findNearestCommonDominator. Cleanup MachinePostDominators.
Summary:
This patch fixes a bug that originated from passing a virtual exit block (nullptr) to `MachinePostDominatorTee::findNearestCommonDominator` and resulted in assertion failures inside its callee. It also applies a small cleanup to the class.
The patch introduces a new function in PDT that given a list of `MachineBasicBlock`s finds their NCD. The new overload of `findNearestCommonDominator` handles virtual root correctly.
Note that similar handling of virtual root nodes is not necessary in (forward) `DominatorTree`s, as right now they don't use virtual roots.
Reviewers: tstellar, tpr, nhaehnle, arsenm, NutshellySima, grosser, hliao
Reviewed By: hliao
Subscribers: hliao, kzhuravl, jvesely, wdng, yaxunl, dstuttard, t-tye, hiraditya, llvm-commits
Tags: #amdgpu, #llvm
Differential Revision: https://reviews.llvm.org/D67974
llvm-svn: 372874
2019-09-25 22:04:36 +08:00
|
|
|
MachinePostDominatorTree::MachinePostDominatorTree()
|
|
|
|
: MachineFunctionPass(ID), PDT(nullptr) {
|
2012-09-17 22:08:37 +08:00
|
|
|
initializeMachinePostDominatorTreePass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
[Dominators][AMDGPU] Don't use virtual exit node in findNearestCommonDominator. Cleanup MachinePostDominators.
Summary:
This patch fixes a bug that originated from passing a virtual exit block (nullptr) to `MachinePostDominatorTee::findNearestCommonDominator` and resulted in assertion failures inside its callee. It also applies a small cleanup to the class.
The patch introduces a new function in PDT that given a list of `MachineBasicBlock`s finds their NCD. The new overload of `findNearestCommonDominator` handles virtual root correctly.
Note that similar handling of virtual root nodes is not necessary in (forward) `DominatorTree`s, as right now they don't use virtual roots.
Reviewers: tstellar, tpr, nhaehnle, arsenm, NutshellySima, grosser, hliao
Reviewed By: hliao
Subscribers: hliao, kzhuravl, jvesely, wdng, yaxunl, dstuttard, t-tye, hiraditya, llvm-commits
Tags: #amdgpu, #llvm
Differential Revision: https://reviews.llvm.org/D67974
llvm-svn: 372874
2019-09-25 22:04:36 +08:00
|
|
|
FunctionPass *MachinePostDominatorTree::createMachinePostDominatorTreePass() {
|
2012-09-17 22:08:37 +08:00
|
|
|
return new MachinePostDominatorTree();
|
|
|
|
}
|
|
|
|
|
[Dominators][AMDGPU] Don't use virtual exit node in findNearestCommonDominator. Cleanup MachinePostDominators.
Summary:
This patch fixes a bug that originated from passing a virtual exit block (nullptr) to `MachinePostDominatorTee::findNearestCommonDominator` and resulted in assertion failures inside its callee. It also applies a small cleanup to the class.
The patch introduces a new function in PDT that given a list of `MachineBasicBlock`s finds their NCD. The new overload of `findNearestCommonDominator` handles virtual root correctly.
Note that similar handling of virtual root nodes is not necessary in (forward) `DominatorTree`s, as right now they don't use virtual roots.
Reviewers: tstellar, tpr, nhaehnle, arsenm, NutshellySima, grosser, hliao
Reviewed By: hliao
Subscribers: hliao, kzhuravl, jvesely, wdng, yaxunl, dstuttard, t-tye, hiraditya, llvm-commits
Tags: #amdgpu, #llvm
Differential Revision: https://reviews.llvm.org/D67974
llvm-svn: 372874
2019-09-25 22:04:36 +08:00
|
|
|
bool MachinePostDominatorTree::runOnMachineFunction(MachineFunction &F) {
|
|
|
|
PDT = std::make_unique<PostDomTreeT>();
|
|
|
|
PDT->recalculate(F);
|
2012-09-17 22:08:37 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
[Dominators][AMDGPU] Don't use virtual exit node in findNearestCommonDominator. Cleanup MachinePostDominators.
Summary:
This patch fixes a bug that originated from passing a virtual exit block (nullptr) to `MachinePostDominatorTee::findNearestCommonDominator` and resulted in assertion failures inside its callee. It also applies a small cleanup to the class.
The patch introduces a new function in PDT that given a list of `MachineBasicBlock`s finds their NCD. The new overload of `findNearestCommonDominator` handles virtual root correctly.
Note that similar handling of virtual root nodes is not necessary in (forward) `DominatorTree`s, as right now they don't use virtual roots.
Reviewers: tstellar, tpr, nhaehnle, arsenm, NutshellySima, grosser, hliao
Reviewed By: hliao
Subscribers: hliao, kzhuravl, jvesely, wdng, yaxunl, dstuttard, t-tye, hiraditya, llvm-commits
Tags: #amdgpu, #llvm
Differential Revision: https://reviews.llvm.org/D67974
llvm-svn: 372874
2019-09-25 22:04:36 +08:00
|
|
|
void MachinePostDominatorTree::getAnalysisUsage(AnalysisUsage &AU) const {
|
2012-09-17 22:08:37 +08:00
|
|
|
AU.setPreservesAll();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
[Dominators][AMDGPU] Don't use virtual exit node in findNearestCommonDominator. Cleanup MachinePostDominators.
Summary:
This patch fixes a bug that originated from passing a virtual exit block (nullptr) to `MachinePostDominatorTee::findNearestCommonDominator` and resulted in assertion failures inside its callee. It also applies a small cleanup to the class.
The patch introduces a new function in PDT that given a list of `MachineBasicBlock`s finds their NCD. The new overload of `findNearestCommonDominator` handles virtual root correctly.
Note that similar handling of virtual root nodes is not necessary in (forward) `DominatorTree`s, as right now they don't use virtual roots.
Reviewers: tstellar, tpr, nhaehnle, arsenm, NutshellySima, grosser, hliao
Reviewed By: hliao
Subscribers: hliao, kzhuravl, jvesely, wdng, yaxunl, dstuttard, t-tye, hiraditya, llvm-commits
Tags: #amdgpu, #llvm
Differential Revision: https://reviews.llvm.org/D67974
llvm-svn: 372874
2019-09-25 22:04:36 +08:00
|
|
|
MachineBasicBlock *MachinePostDominatorTree::findNearestCommonDominator(
|
|
|
|
ArrayRef<MachineBasicBlock *> Blocks) const {
|
|
|
|
assert(!Blocks.empty());
|
|
|
|
|
|
|
|
MachineBasicBlock *NCD = Blocks.front();
|
|
|
|
for (MachineBasicBlock *BB : Blocks.drop_front()) {
|
|
|
|
NCD = PDT->findNearestCommonDominator(NCD, BB);
|
|
|
|
|
|
|
|
// Stop when the root is reached.
|
|
|
|
if (PDT->isVirtualRoot(PDT->getNode(NCD)))
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NCD;
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:23:27 +08:00
|
|
|
void MachinePostDominatorTree::verifyAnalysis() const {
|
|
|
|
if (PDT && VerifyMachineDomInfo)
|
|
|
|
if (!PDT->verify(PostDomTreeT::VerificationLevel::Basic)) {
|
|
|
|
errs() << "MachinePostDominatorTree verification failed\n";
|
|
|
|
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[Dominators][AMDGPU] Don't use virtual exit node in findNearestCommonDominator. Cleanup MachinePostDominators.
Summary:
This patch fixes a bug that originated from passing a virtual exit block (nullptr) to `MachinePostDominatorTee::findNearestCommonDominator` and resulted in assertion failures inside its callee. It also applies a small cleanup to the class.
The patch introduces a new function in PDT that given a list of `MachineBasicBlock`s finds their NCD. The new overload of `findNearestCommonDominator` handles virtual root correctly.
Note that similar handling of virtual root nodes is not necessary in (forward) `DominatorTree`s, as right now they don't use virtual roots.
Reviewers: tstellar, tpr, nhaehnle, arsenm, NutshellySima, grosser, hliao
Reviewed By: hliao
Subscribers: hliao, kzhuravl, jvesely, wdng, yaxunl, dstuttard, t-tye, hiraditya, llvm-commits
Tags: #amdgpu, #llvm
Differential Revision: https://reviews.llvm.org/D67974
llvm-svn: 372874
2019-09-25 22:04:36 +08:00
|
|
|
void MachinePostDominatorTree::print(llvm::raw_ostream &OS,
|
|
|
|
const Module *M) const {
|
|
|
|
PDT->print(OS);
|
2012-09-17 22:08:37 +08:00
|
|
|
}
|