aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineBlockPlacement.cpp
diff options
context:
space:
mode:
authorspupyrev <spupyrev@fb.com>2022-07-15 11:52:56 -0700
committerspupyrev <spupyrev@fb.com>2022-08-24 09:40:25 -0700
commit8d5b694da172c97f4fc10d5586830fea1b486037 (patch)
treeb2a8702d2394246a72e9f919cbd0bf9d3c9d3263 /llvm/lib/CodeGen/MachineBlockPlacement.cpp
parent3b4d800911b52ae23da1a1e3f9105f53d8053397 (diff)
downloadllvm-8d5b694da172c97f4fc10d5586830fea1b486037.zip
llvm-8d5b694da172c97f4fc10d5586830fea1b486037.tar.gz
llvm-8d5b694da172c97f4fc10d5586830fea1b486037.tar.bz2
extending code layout alg
The diff modifies ext-tsp code layout algorithm in the following ways: (i) fixes merging of cold block chains (this is a port of D129397); (ii) adjusts the cost model utilized for optimization; (iii) adjusts some APIs so that the implementation can be used in BOLT; this is a prerequisite for D129895. The only non-trivial change is (ii). Here we introduce different weights for conditional and unconditional branches in the cost model. Based on the new model it is slightly more important to increase the number of "fall-through unconditional" jumps, which makes sense, as placing two blocks with an unconditional jump next to each other reduces the number of jump instructions in the generated code. Experimentally, this makes a mild impact on the performance; I've seen up to 0.2%-0.3% perf win on some benchmarks. Reviewed By: hoy Differential Revision: https://reviews.llvm.org/D129893
Diffstat (limited to 'llvm/lib/CodeGen/MachineBlockPlacement.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineBlockPlacement.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index 9ff5c37..4884ac9 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -3488,7 +3488,7 @@ void MachineBlockPlacement::applyExtTsp() {
auto BlockSizes = std::vector<uint64_t>(F->size());
auto BlockCounts = std::vector<uint64_t>(F->size());
- DenseMap<std::pair<uint64_t, uint64_t>, uint64_t> JumpCounts;
+ std::vector<EdgeCountT> JumpCounts;
for (MachineBasicBlock &MBB : *F) {
// Getting the block frequency.
BlockFrequency BlockFreq = MBFI->getBlockFreq(&MBB);
@@ -3506,9 +3506,9 @@ void MachineBlockPlacement::applyExtTsp() {
// Getting jump frequencies.
for (MachineBasicBlock *Succ : MBB.successors()) {
auto EP = MBPI->getEdgeProbability(&MBB, Succ);
- BlockFrequency EdgeFreq = BlockFreq * EP;
- auto Edge = std::make_pair(BlockIndex[&MBB], BlockIndex[Succ]);
- JumpCounts[Edge] = EdgeFreq.getFrequency();
+ BlockFrequency JumpFreq = BlockFreq * EP;
+ auto Jump = std::make_pair(BlockIndex[&MBB], BlockIndex[Succ]);
+ JumpCounts.push_back(std::make_pair(Jump, JumpFreq.getFrequency()));
}
}