aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineBlockPlacement.cpp
diff options
context:
space:
mode:
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.