Skip to content

Commit 34f27e1

Browse files
committed
Update IR
IR commit: cd6fe296e8f39af70d5532d955add261899f2639
1 parent a541b95 commit 34f27e1

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

ext/opcache/jit/ir/ir_cfg.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,9 +1856,15 @@ static int ir_edge_info_cmp(const void *b1, const void *b2)
18561856
if (e1->freq != e2->freq) {
18571857
return e1->freq < e2->freq ? 1 : -1;
18581858
}
1859-
/* In case of equal frequences prefer to keep the existing order */
1859+
/* In case of equal frequencies, try to avoid penalization of one of the "equal" paths by
1860+
* preferring the first RPO successor (in conditional branches) and the last RPO predecessor
1861+
* (in merge points).
1862+
*
1863+
* See "Static Basic Block Reordering Heuristics for Implicit Control Flow in Baseline JITs"
1864+
* Polito Guillermo, Ducasse Stephane, and Tesone Pablo (2021)
1865+
*/
18601866
if (e1->from != e2->from) {
1861-
return e1->from - e2->from;
1867+
return e2->from - e1->from;
18621868
} else {
18631869
return e1->to - e2->to;
18641870
}
@@ -2037,7 +2043,7 @@ static int ir_schedule_blocks_bottom_up(ir_ctx *ctx)
20372043
chains[b].prev = b;
20382044
}
20392045

2040-
/* 2. Collect information about BBs and EDGEs freqeuncies */
2046+
/* 2. Collect information about BBs and EDGEs frequencies */
20412047
edges = ir_mem_malloc(sizeof(ir_edge_info) * max_edges_count);
20422048
bb_freq = ir_mem_calloc(ctx->cfg_blocks_count + 1, sizeof(float));
20432049
bb_freq[1] = 1.0f;
@@ -2052,8 +2058,8 @@ static int ir_schedule_blocks_bottom_up(ir_ctx *ctx)
20522058
uint32_t *p = ctx->cfg_edges + bb->predecessors;
20532059
for (; n > 0; p++, n--) {
20542060
uint32_t predecessor = *p;
2055-
/* Basic Blocks are ordered in a way that usual predecessors ids are less then successors.
2056-
* So we may comapre blocks ids (predecessor < b) instead of a more expensive check for back edge
2061+
/* Basic Blocks are ordered in a way that usual predecessors ids are less than successors.
2062+
* So we may compare blocks ids (predecessor < b) instead of a more expensive check for back edge
20572063
* (b != predecessor && ctx->cfg_blocks[predecessor].loop_header != b)
20582064
*/
20592065
if (predecessor < b) {
@@ -2255,14 +2261,14 @@ static int ir_schedule_blocks_bottom_up(ir_ctx *ctx)
22552261
ir_bitqueue_free(&worklist);
22562262
ir_mem_free(visited);
22572263

2258-
/* 2. Sort EDGEs according to their frequentcies */
2264+
/* 2. Sort EDGEs according to their frequencies */
22592265
qsort(edges, edges_count, sizeof(ir_edge_info), ir_edge_info_cmp);
22602266

22612267
#if IR_DEBUG_BB_SCHEDULE_EDGES
22622268
ir_dump_edges(ctx, edges_count, edges);
22632269
#endif
22642270

2265-
/* 3. Process EDGEs in the decrising frequentcy order and join the connected chains */
2271+
/* 3. Process EDGEs in the decreasing frequency order and join the connected chains */
22662272
for (e = edges, i = edges_count; i > 0; e++, i--) {
22672273
uint32_t dst = chains[e->to].head;
22682274
if (dst == e->to) {
@@ -2341,8 +2347,8 @@ static int ir_schedule_blocks_bottom_up(ir_ctx *ctx)
23412347
#endif
23422348
}
23432349

2344-
/* 5. Group chains accoring to the most frequnt edge between them */
2345-
// TODO: Try to find a better heuristc
2350+
/* 5. Group chains according to the most frequent edge between them */
2351+
// TODO: Try to find a better heuristic
23462352
for (e = edges, i = edges_count; i > 0; e++, i--) {
23472353
#if !IR_DEBUG_BB_SCHEDULE_GRAPH
23482354
if (!e->from) continue;
@@ -2525,8 +2531,14 @@ int ir_schedule_blocks(ir_ctx *ctx)
25252531
{
25262532
if (ctx->cfg_blocks_count <= 2) {
25272533
return 1;
2528-
// TODO: make the choise between top-down and bottom-up algorithm configurable
2529-
} else if (UNEXPECTED(ctx->flags2 & IR_IRREDUCIBLE_CFG) || ctx->cfg_blocks_count > 256) {
2534+
}
2535+
2536+
/* The bottom-up Pettis-Hansen algorithm is expensive - O(n^3),
2537+
* use it only for relatively small functions.
2538+
*
2539+
* TODO: make the choice between top-down and bottom-up algorithm configurable
2540+
*/
2541+
if (UNEXPECTED(ctx->flags2 & IR_IRREDUCIBLE_CFG) || ctx->cfg_blocks_count > 256) {
25302542
return ir_schedule_blocks_top_down(ctx);
25312543
} else {
25322544
return ir_schedule_blocks_bottom_up(ctx);

0 commit comments

Comments
 (0)