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"
|
|
|
|
|
|
|
|
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
|
|
|
}
|