aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineBlockPlacement.cpp
diff options
context:
space:
mode:
authorJohn Brawn <john.brawn@arm.com>2024-07-24 10:49:50 +0100
committerGitHub <noreply@github.com>2024-07-24 10:49:50 +0100
commitf0bd705c9b6bd59496b44934a893a5b74085a376 (patch)
tree9833b3d84f633f7b9897c407693e40c937c14201 /llvm/lib/CodeGen/MachineBlockPlacement.cpp
parent71a848632e2fbef3f2dc97c2dae845ddca0ec47e (diff)
downloadllvm-f0bd705c9b6bd59496b44934a893a5b74085a376.zip
llvm-f0bd705c9b6bd59496b44934a893a5b74085a376.tar.gz
llvm-f0bd705c9b6bd59496b44934a893a5b74085a376.tar.bz2
[CodeGen] Restore MachineBlockPlacement block ordering (#99351)
PR #91843 changed the algorithm used to find the next unplaced block so that it iterates through the blocks in BlockFilter instead of iterating through the blocks in the function and checking if they are in the block filter. Unfortunately this sometimes results in a different block ordering being chosen, as the order of blocks in BlockFilter comes from the order in MachineLoopInfo, and in some cases this differs from the order they are in the function. This can also give an end result that has worse performance. Fix this by making collectLoopBlockSet place blocks in its output in the order that they are in the function.
Diffstat (limited to 'llvm/lib/CodeGen/MachineBlockPlacement.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineBlockPlacement.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index 4c864ca..cb352a5 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -2596,7 +2596,15 @@ void MachineBlockPlacement::rotateLoopWithProfile(
/// otherwise, collect all blocks in the loop.
MachineBlockPlacement::BlockFilterSet
MachineBlockPlacement::collectLoopBlockSet(const MachineLoop &L) {
- BlockFilterSet LoopBlockSet;
+ // Collect the blocks in a set ordered by block number, as this gives the same
+ // order as they appear in the function.
+ struct MBBCompare {
+ bool operator()(const MachineBasicBlock *X,
+ const MachineBasicBlock *Y) const {
+ return X->getNumber() < Y->getNumber();
+ }
+ };
+ std::set<const MachineBasicBlock *, MBBCompare> LoopBlockSet;
// Filter cold blocks off from LoopBlockSet when profile data is available.
// Collect the sum of frequencies of incoming edges to the loop header from
@@ -2627,7 +2635,11 @@ MachineBlockPlacement::collectLoopBlockSet(const MachineLoop &L) {
} else
LoopBlockSet.insert(L.block_begin(), L.block_end());
- return LoopBlockSet;
+ // Copy the blocks into a BlockFilterSet, as iterating it is faster than
+ // std::set. We will only remove blocks and never insert them, which will
+ // preserve the ordering.
+ BlockFilterSet Ret(LoopBlockSet.begin(), LoopBlockSet.end());
+ return Ret;
}
/// Forms basic block chains from the natural loop structures.