-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[CodeGen] Use SmallVector for MBB preds/succs #101948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Avoid extra heap allocations for typical predecessor/successor counts.
@llvm/pr-subscribers-pgo @llvm/pr-subscribers-backend-hexagon Author: Alexis Engelke (aengelke) ChangesAvoid extra heap allocations for typical predecessor/successor counts. c-t-t -0.14% stage2-O0-g Full diff: https://github.com/llvm/llvm-project/pull/101948.diff 3 Files Affected:
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];
|
|
@@ -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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use std::next() to make this independent of implementation details?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this wasn't already the case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Avoid extra heap allocations for typical predecessor/successor counts.
c-t-t -0.14% stage2-O0-g