2012-09-17 14:08:37 +00:00
|
|
|
//===- MachinePostDominators.cpp -Machine Post Dominator 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
|
2012-09-17 14:08:37 +00: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-13 13:15:01 -08:00
|
|
|
#include "llvm/InitializePasses.h"
|
2024-06-11 16:42:40 +02:00
|
|
|
#include "llvm/Support/GenericDomTreeConstruction.h"
|
2012-09-17 14:08:37 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2017-07-14 18:26:09 +00:00
|
|
|
namespace llvm {
|
|
|
|
template class DominatorTreeBase<MachineBasicBlock, true>; // PostDomTreeBase
|
2019-10-01 15:23:27 +00:00
|
|
|
|
2024-06-12 14:29:22 +08:00
|
|
|
namespace DomTreeBuilder {
|
|
|
|
|
|
|
|
template void Calculate<MBBPostDomTree>(MBBPostDomTree &DT);
|
|
|
|
template void InsertEdge<MBBPostDomTree>(MBBPostDomTree &DT,
|
|
|
|
MachineBasicBlock *From,
|
|
|
|
MachineBasicBlock *To);
|
|
|
|
template void DeleteEdge<MBBPostDomTree>(MBBPostDomTree &DT,
|
|
|
|
MachineBasicBlock *From,
|
|
|
|
MachineBasicBlock *To);
|
|
|
|
template void ApplyUpdates<MBBPostDomTree>(MBBPostDomTree &DT,
|
|
|
|
MBBPostDomTreeGraphDiff &,
|
|
|
|
MBBPostDomTreeGraphDiff *);
|
|
|
|
template bool Verify<MBBPostDomTree>(const MBBPostDomTree &DT,
|
|
|
|
MBBPostDomTree::VerificationLevel VL);
|
|
|
|
|
|
|
|
} // namespace DomTreeBuilder
|
2019-10-01 15:23:27 +00:00
|
|
|
extern bool VerifyMachineDomInfo;
|
|
|
|
} // namespace llvm
|
2017-07-14 18:26:09 +00:00
|
|
|
|
2024-06-25 14:23:01 +08:00
|
|
|
AnalysisKey MachinePostDominatorTreeAnalysis::Key;
|
|
|
|
|
|
|
|
MachinePostDominatorTreeAnalysis::Result
|
|
|
|
MachinePostDominatorTreeAnalysis::run(MachineFunction &MF,
|
|
|
|
MachineFunctionAnalysisManager &) {
|
|
|
|
return MachinePostDominatorTree(MF);
|
|
|
|
}
|
|
|
|
|
|
|
|
PreservedAnalyses
|
|
|
|
MachinePostDominatorTreePrinterPass::run(MachineFunction &MF,
|
|
|
|
MachineFunctionAnalysisManager &MFAM) {
|
|
|
|
OS << "MachinePostDominatorTree for machine function: " << MF.getName()
|
|
|
|
<< '\n';
|
|
|
|
MFAM.getResult<MachinePostDominatorTreeAnalysis>(MF).print(OS);
|
|
|
|
return PreservedAnalyses::all();
|
|
|
|
}
|
|
|
|
|
2024-06-12 14:29:22 +08:00
|
|
|
char MachinePostDominatorTreeWrapperPass::ID = 0;
|
2012-09-17 14:08:37 +00:00
|
|
|
|
|
|
|
//declare initializeMachinePostDominatorTreePass
|
2024-06-12 14:29:22 +08:00
|
|
|
INITIALIZE_PASS(MachinePostDominatorTreeWrapperPass, "machinepostdomtree",
|
2012-09-17 14:08:37 +00:00
|
|
|
"MachinePostDominator Tree Construction", true, true)
|
|
|
|
|
2024-06-12 14:29:22 +08:00
|
|
|
MachinePostDominatorTreeWrapperPass::MachinePostDominatorTreeWrapperPass()
|
|
|
|
: MachineFunctionPass(ID), PDT() {
|
|
|
|
initializeMachinePostDominatorTreeWrapperPassPass(
|
|
|
|
*PassRegistry::getPassRegistry());
|
2012-09-17 14:08:37 +00:00
|
|
|
}
|
|
|
|
|
2024-06-12 14:29:22 +08:00
|
|
|
bool MachinePostDominatorTreeWrapperPass::runOnMachineFunction(
|
|
|
|
MachineFunction &F) {
|
|
|
|
PDT = 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 14:04:36 +00:00
|
|
|
PDT->recalculate(F);
|
2012-09-17 14:08:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-06-12 14:29:22 +08:00
|
|
|
void MachinePostDominatorTreeWrapperPass::getAnalysisUsage(
|
|
|
|
AnalysisUsage &AU) const {
|
2012-09-17 14:08:37 +00:00
|
|
|
AU.setPreservesAll();
|
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
2024-06-25 14:23:01 +08:00
|
|
|
bool MachinePostDominatorTree::invalidate(
|
|
|
|
MachineFunction &, const PreservedAnalyses &PA,
|
|
|
|
MachineFunctionAnalysisManager::Invalidator &) {
|
|
|
|
// Check whether the analysis, all analyses on machine functions, or the
|
|
|
|
// machine function's CFG have been preserved.
|
|
|
|
auto PAC = PA.getChecker<MachinePostDominatorTreeAnalysis>();
|
|
|
|
return !PAC.preserved() &&
|
|
|
|
!PAC.preservedSet<AllAnalysesOn<MachineFunction>>() &&
|
|
|
|
!PAC.preservedSet<CFGAnalyses>();
|
|
|
|
}
|
|
|
|
|
[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 14:04:36 +00:00
|
|
|
MachineBasicBlock *MachinePostDominatorTree::findNearestCommonDominator(
|
|
|
|
ArrayRef<MachineBasicBlock *> Blocks) const {
|
|
|
|
assert(!Blocks.empty());
|
|
|
|
|
|
|
|
MachineBasicBlock *NCD = Blocks.front();
|
|
|
|
for (MachineBasicBlock *BB : Blocks.drop_front()) {
|
2024-06-12 14:29:22 +08:00
|
|
|
NCD = Base::findNearestCommonDominator(NCD, BB);
|
[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 14:04:36 +00:00
|
|
|
|
|
|
|
// Stop when the root is reached.
|
2024-06-12 14:29:22 +08:00
|
|
|
if (isVirtualRoot(getNode(NCD)))
|
[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 14:04:36 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NCD;
|
|
|
|
}
|
|
|
|
|
2024-06-12 14:29:22 +08:00
|
|
|
void MachinePostDominatorTreeWrapperPass::verifyAnalysis() const {
|
|
|
|
if (VerifyMachineDomInfo && PDT &&
|
|
|
|
!PDT->verify(MachinePostDominatorTree::VerificationLevel::Basic))
|
|
|
|
report_fatal_error("MachinePostDominatorTree verification failed!");
|
2019-10-01 15:23:27 +00:00
|
|
|
}
|
|
|
|
|
2024-06-12 14:29:22 +08:00
|
|
|
void MachinePostDominatorTreeWrapperPass::print(llvm::raw_ostream &OS,
|
|
|
|
const Module *M) const {
|
[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 14:04:36 +00:00
|
|
|
PDT->print(OS);
|
2012-09-17 14:08:37 +00:00
|
|
|
}
|