Skip to content

Commit

Permalink
Add "--debug-bb-schedule" option
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed May 3, 2024
1 parent 08fceaf commit ab0ab62
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
1 change: 1 addition & 0 deletions ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ void ir_strtab_free(ir_strtab *strtab);
# define IR_DEBUG_GCM_SPLIT (1<<28)
# define IR_DEBUG_SCHEDULE (1<<29)
# define IR_DEBUG_RA (1<<30)
# define IR_DEBUG_BB_SCHEDULE (1U<<31)
#endif

typedef struct _ir_ctx ir_ctx;
Expand Down
47 changes: 26 additions & 21 deletions ir_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,13 +1151,11 @@ static void ir_insert_chain_before(ir_chain *chains, uint32_t c, uint32_t before
}

#ifndef IR_DEBUG_BB_SCHEDULE_GRAPH
# define IR_DEBUG_BB_SCHEDULE_GRAPH 0
#endif
#ifndef IR_DEBUG_BB_SCHEDULE_EDGES
# define IR_DEBUG_BB_SCHEDULE_EDGES 0
#endif
#ifndef IR_DEBUG_BB_SCHEDULE_CHAINS
# define IR_DEBUG_BB_SCHEDULE_CHAINS 0
# ifdef IR_DEBUG
# define IR_DEBUG_BB_SCHEDULE_GRAPH 1
# else
# define IR_DEBUG_BB_SCHEDULE_GRAPH 0
# endif
#endif

#if IR_DEBUG_BB_SCHEDULE_GRAPH
Expand Down Expand Up @@ -1210,20 +1208,17 @@ static void ir_dump_cfg_freq_graph(ir_ctx *ctx, float *bb_freq, uint32_t edges_c
}
#endif

#if IR_DEBUG_BB_SCHEDULE_EDGES
#ifdef IR_DEBUG
static void ir_dump_edges(ir_ctx *ctx, uint32_t edges_count, ir_edge_info *edges)
{
uint32_t i;

fprintf(stderr, "Edges:\n");
for (i = 0; i < edges_count; i++) {
fprintf(stderr, "\tBB%d -> BB%d [label=\"%0.3f\"]\n", edges[i].from, edges[i].to, edges[i].freq);
fprintf(stderr, "\tBB%d -> BB%d %0.3f\n", edges[i].from, edges[i].to, edges[i].freq);
}
fprintf(stderr, "}\n");
}
#endif

#if IR_DEBUG_BB_SCHEDULE_CHAINS
static void ir_dump_chains(ir_ctx *ctx, ir_chain *chains)
{
uint32_t b, tail, i;
Expand Down Expand Up @@ -1507,8 +1502,10 @@ static int ir_schedule_blocks_bottom_up(ir_ctx *ctx)
/* 2. Sort EDGEs according to their frequencies */
qsort(edges, edges_count, sizeof(ir_edge_info), ir_edge_info_cmp);

#if IR_DEBUG_BB_SCHEDULE_EDGES
ir_dump_edges(ctx, edges_count, edges);
#ifdef IR_DEBUG
if (ctx->flags & IR_DEBUG_BB_SCHEDULE) {
ir_dump_edges(ctx, edges_count, edges);
}
#endif

/* 3. Process EDGEs in the decreasing frequency order and join the connected chains */
Expand Down Expand Up @@ -1555,13 +1552,17 @@ static int ir_schedule_blocks_bottom_up(ir_ctx *ctx)
}

#if IR_DEBUG_BB_SCHEDULE_GRAPH
ir_dump_cfg_freq_graph(ctx, bb_freq, edges_count, edges, chains);
if (ctx->flags & IR_DEBUG_BB_SCHEDULE) {
ir_dump_cfg_freq_graph(ctx, bb_freq, edges_count, edges, chains);
}
#endif

ir_mem_free(bb_freq);

#if IR_DEBUG_BB_SCHEDULE_CHAINS
ir_dump_chains(ctx, chains);
#ifdef IR_DEBUG
if (ctx->flags & IR_DEBUG_BB_SCHEDULE) {
ir_dump_chains(ctx, chains);
}
#endif

/* 4. Merge empty entry blocks */
Expand All @@ -1585,8 +1586,10 @@ static int ir_schedule_blocks_bottom_up(ir_ctx *ctx)
}
}

#if IR_DEBUG_BB_SCHEDULE_CHAINS
ir_dump_chains(ctx, chains);
#ifdef IR_DEBUG
if (ctx->flags & IR_DEBUG_BB_SCHEDULE) {
ir_dump_chains(ctx, chains);
}
#endif
}

Expand Down Expand Up @@ -1619,8 +1622,10 @@ static int ir_schedule_blocks_bottom_up(ir_ctx *ctx)
}
}

#if IR_DEBUG_BB_SCHEDULE_CHAINS
ir_dump_chains(ctx, chains);
#ifdef IR_DEBUG
if (ctx->flags & IR_DEBUG_BB_SCHEDULE) {
ir_dump_chains(ctx, chains);
}
#endif

/* 7. Form a final BB order */
Expand Down
3 changes: 3 additions & 0 deletions ir_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ static void help(const char *cmd)
" --debug-schedule - debug SCHEDULE optimization pass\n"
" --debug-ra - debug register allocator\n"
" --debug-regset <bit-mask> - restrict available register set\n"
" --debug-bb-schedule - debug BB PLCEMENT optimization pass\n"
#endif
" --disable-gdb - disable JIT code registration in GDB\n"
" --target - print JIT target\n"
Expand Down Expand Up @@ -1181,6 +1182,8 @@ int main(int argc, char **argv)
flags |= IR_DEBUG_SCHEDULE;
} else if (strcmp(argv[i], "--debug-ra") == 0) {
flags |= IR_DEBUG_RA;
} else if (strcmp(argv[i], "--debug-bb-schedule") == 0) {
flags |= IR_DEBUG_BB_SCHEDULE;
#endif
} else if (strcmp(argv[i], "--debug-regset") == 0) {
if (i + 1 == argc || argv[i + 1][0] == '-') {
Expand Down

0 comments on commit ab0ab62

Please sign in to comment.