aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/BasicBlockSections.cpp
diff options
context:
space:
mode:
authorAlexis Engelke <engelke@in.tum.de>2024-08-06 13:46:19 +0200
committerGitHub <noreply@github.com>2024-08-06 13:46:19 +0200
commitd871b2e0d09b872c57139ee0e24f966d58b92d33 (patch)
treee55859aa357cab9400243d9f4b828cf5d9ff0e81 /llvm/lib/CodeGen/BasicBlockSections.cpp
parent80721e0d6c7793eec699b5846dcf5d3ffff331a8 (diff)
downloadllvm-d871b2e0d09b872c57139ee0e24f966d58b92d33.zip
llvm-d871b2e0d09b872c57139ee0e24f966d58b92d33.tar.gz
llvm-d871b2e0d09b872c57139ee0e24f966d58b92d33.tar.bz2
[CodeGen] Use optimized domtree for MachineFunction (#102107)
The dominator tree gained an optimization to use block numbers instead of a DenseMap to store blocks. Given that machine basic blocks already have numbers, expose these via appropriate GraphTraits. For debugging, block number epochs are added to MachineFunction -- this greatly helps in finding uses of block numbers after RenumberBlocks(). In a few cases where dominator trees are preserved across renumberings, the dominator tree is updated to use the new numbers.
Diffstat (limited to 'llvm/lib/CodeGen/BasicBlockSections.cpp')
-rw-r--r--llvm/lib/CodeGen/BasicBlockSections.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/BasicBlockSections.cpp b/llvm/lib/CodeGen/BasicBlockSections.cpp
index 09e45ea..0071284 100644
--- a/llvm/lib/CodeGen/BasicBlockSections.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSections.cpp
@@ -72,8 +72,10 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/BasicBlockSectionUtils.h"
#include "llvm/CodeGen/BasicBlockSectionsProfileReader.h"
+#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachinePostDominators.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/InitializePasses.h"
@@ -393,12 +395,21 @@ bool BasicBlockSections::runOnMachineFunction(MachineFunction &MF) {
auto R1 = handleBBSections(MF);
// Handle basic block address map after basic block sections are finalized.
auto R2 = handleBBAddrMap(MF);
+
+ // We renumber blocks, so update the dominator tree we want to preserve.
+ if (auto *WP = getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>())
+ WP->getDomTree().updateBlockNumbers();
+ if (auto *WP = getAnalysisIfAvailable<MachinePostDominatorTreeWrapperPass>())
+ WP->getPostDomTree().updateBlockNumbers();
+
return R1 || R2;
}
void BasicBlockSections::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<BasicBlockSectionsProfileReaderWrapperPass>();
+ AU.addUsedIfAvailable<MachineDominatorTreeWrapperPass>();
+ AU.addUsedIfAvailable<MachinePostDominatorTreeWrapperPass>();
MachineFunctionPass::getAnalysisUsage(AU);
}