[llvm] [CodeGen] Use SmallVector for MBB preds/succs (PR #101948)
Alexis Engelke via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 5 02:34:12 PDT 2024
https://github.com/aengelke created https://github.com/llvm/llvm-project/pull/101948
Avoid extra heap allocations for typical predecessor/successor counts.
[c-t-t](http://llvm-compile-time-tracker.com/compare.php?from=e7f9d8e5c3e49e729c69aaa9be3322f7902370b8&to=61a0ed0ea4eab2a9d4b0f1d1ce7b62b57b7cf50e&stat=instructions:u) -0.14% stage2-O0-g
>From 61a0ed0ea4eab2a9d4b0f1d1ce7b62b57b7cf50e Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Sun, 4 Aug 2024 17:02:22 +0000
Subject: [PATCH] [CodeGen] Use SmallVector for MBB preds/succs
Avoid extra heap allocations for typical predecessor/successor counts.
---
llvm/include/llvm/Analysis/RegionInfoImpl.h | 2 +-
llvm/include/llvm/CodeGen/MachineBasicBlock.h | 22 ++++++++++---------
.../Target/Hexagon/HexagonCopyHoisting.cpp | 2 +-
3 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/Analysis/RegionInfoImpl.h b/llvm/include/llvm/Analysis/RegionInfoImpl.h
index c5e8821858fd2..2ea432ea95d37 100644
--- a/llvm/include/llvm/Analysis/RegionInfoImpl.h
+++ b/llvm/include/llvm/Analysis/RegionInfoImpl.h
@@ -814,7 +814,7 @@ RegionInfoBase<Tr>::getMaxRegionExit(BlockT *BB) const {
// Get the single exit of BB.
if (R && R->getEntry() == BB)
Exit = R->getExit();
- else if (++BlockTraits::child_begin(BB) == BlockTraits::child_end(BB))
+ else if (BlockTraits::child_begin(BB) + 1 == BlockTraits::child_end(BB))
Exit = *BlockTraits::child_begin(BB);
else // No single exit exists.
return Exit;
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index b8153fd5d3fb7..5b80827b780b5 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -157,8 +157,8 @@ class MachineBasicBlock
Instructions Insts;
/// Keep track of the predecessor / successor basic blocks.
- std::vector<MachineBasicBlock *> Predecessors;
- std::vector<MachineBasicBlock *> Successors;
+ SmallVector<MachineBasicBlock *, 4> Predecessors;
+ SmallVector<MachineBasicBlock *, 2> Successors;
/// Keep track of the probabilities to the successors. This vector has the
/// same order as Successors, or it is empty if we don't use it (disable
@@ -387,18 +387,20 @@ class MachineBasicBlock
}
// Machine-CFG iterators
- using pred_iterator = std::vector<MachineBasicBlock *>::iterator;
- using const_pred_iterator = std::vector<MachineBasicBlock *>::const_iterator;
- using succ_iterator = std::vector<MachineBasicBlock *>::iterator;
- using const_succ_iterator = std::vector<MachineBasicBlock *>::const_iterator;
+ using pred_iterator = SmallVectorImpl<MachineBasicBlock *>::iterator;
+ using const_pred_iterator =
+ SmallVectorImpl<MachineBasicBlock *>::const_iterator;
+ using succ_iterator = SmallVectorImpl<MachineBasicBlock *>::iterator;
+ using const_succ_iterator =
+ SmallVectorImpl<MachineBasicBlock *>::const_iterator;
using pred_reverse_iterator =
- std::vector<MachineBasicBlock *>::reverse_iterator;
+ SmallVectorImpl<MachineBasicBlock *>::reverse_iterator;
using const_pred_reverse_iterator =
- std::vector<MachineBasicBlock *>::const_reverse_iterator;
+ SmallVectorImpl<MachineBasicBlock *>::const_reverse_iterator;
using succ_reverse_iterator =
- std::vector<MachineBasicBlock *>::reverse_iterator;
+ SmallVectorImpl<MachineBasicBlock *>::reverse_iterator;
using const_succ_reverse_iterator =
- std::vector<MachineBasicBlock *>::const_reverse_iterator;
+ SmallVectorImpl<MachineBasicBlock *>::const_reverse_iterator;
pred_iterator pred_begin() { return Predecessors.begin(); }
const_pred_iterator pred_begin() const { return Predecessors.begin(); }
pred_iterator pred_end() { return Predecessors.end(); }
diff --git a/llvm/lib/Target/Hexagon/HexagonCopyHoisting.cpp b/llvm/lib/Target/Hexagon/HexagonCopyHoisting.cpp
index e9d95c6e89db4..a43042a303093 100644
--- a/llvm/lib/Target/Hexagon/HexagonCopyHoisting.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonCopyHoisting.cpp
@@ -249,7 +249,7 @@ void HexagonCopyHoisting::moveCopyInstr(MachineBasicBlock *DestBB,
DestBB->splice(FirstTI, MI->getParent(), MI);
addMItoCopyList(MI);
- for (auto I = ++(DestBB->succ_begin()), E = DestBB->succ_end(); I != E; ++I) {
+ for (auto I = DestBB->succ_begin() + 1, E = DestBB->succ_end(); I != E; ++I) {
MachineBasicBlock *SuccBB = *I;
auto &BBCopyInst = CopyMIList[SuccBB->getNumber()];
MachineInstr *SuccMI = BBCopyInst[Key];
More information about the llvm-commits
mailing list