|
10 | 10 | #include "runtime/host_threads.h" |
11 | 11 | #include "collections/internal.h" /* make_fn */ |
12 | 12 |
|
| 13 | +#ifdef MINO_REDUCE_STEP_COUNTS |
| 14 | +#include <stdio.h> |
| 15 | +#include <stdlib.h> |
| 16 | + |
| 17 | +/* Tally of reduce_step invocations bucketed by reducer prim identity. |
| 18 | + * Populated when the binary is built with -DMINO_REDUCE_STEP_COUNTS=1. |
| 19 | + * Dumped to stderr at process exit. Used to gate item A of the pre-JIT |
| 20 | + * sweep: confirm canonical numeric reducers (+, *, etc.) dominate |
| 21 | + * real-workload reduce_step traffic. Not for production. */ |
| 22 | +static size_t g_rstep_add; |
| 23 | +static size_t g_rstep_mul; |
| 24 | +static size_t g_rstep_sub; |
| 25 | +static size_t g_rstep_band; |
| 26 | +static size_t g_rstep_bor; |
| 27 | +static size_t g_rstep_bxor; |
| 28 | +static size_t g_rstep_other_prim; |
| 29 | +static size_t g_rstep_user_fn; |
| 30 | +static int g_rstep_atexit_done; |
| 31 | + |
| 32 | +static void rstep_counts_dump(void) |
| 33 | +{ |
| 34 | + size_t total = g_rstep_add + g_rstep_mul + g_rstep_sub |
| 35 | + + g_rstep_band + g_rstep_bor + g_rstep_bxor |
| 36 | + + g_rstep_other_prim + g_rstep_user_fn; |
| 37 | + fprintf(stderr, "reduce-step-counts: total = %zu\n", total); |
| 38 | + if (total == 0) return; |
| 39 | +#define ROW(name, c) \ |
| 40 | + fprintf(stderr, " %-20s %12zu %6.2f%%\n", (name), (c), \ |
| 41 | + 100.0 * (double)(c) / (double)total) |
| 42 | + ROW("prim_add", g_rstep_add); |
| 43 | + ROW("prim_mul", g_rstep_mul); |
| 44 | + ROW("prim_sub", g_rstep_sub); |
| 45 | + ROW("prim_bit_and", g_rstep_band); |
| 46 | + ROW("prim_bit_or", g_rstep_bor); |
| 47 | + ROW("prim_bit_xor", g_rstep_bxor); |
| 48 | + ROW("other_prim", g_rstep_other_prim); |
| 49 | + ROW("user_fn", g_rstep_user_fn); |
| 50 | +#undef ROW |
| 51 | +} |
| 52 | + |
| 53 | +static void rstep_count(mino_val_t *fn) |
| 54 | +{ |
| 55 | + if (!g_rstep_atexit_done) { |
| 56 | + atexit(rstep_counts_dump); |
| 57 | + g_rstep_atexit_done = 1; |
| 58 | + } |
| 59 | + if (fn != NULL && mino_type_of(fn) == MINO_PRIM |
| 60 | + && fn->as.prim.fn != NULL) { |
| 61 | + mino_prim_fn p = fn->as.prim.fn; |
| 62 | + if (p == prim_add) g_rstep_add++; |
| 63 | + else if (p == prim_mul) g_rstep_mul++; |
| 64 | + else if (p == prim_sub) g_rstep_sub++; |
| 65 | + else if (p == prim_bit_and) g_rstep_band++; |
| 66 | + else if (p == prim_bit_or) g_rstep_bor++; |
| 67 | + else if (p == prim_bit_xor) g_rstep_bxor++; |
| 68 | + else g_rstep_other_prim++; |
| 69 | + } else { |
| 70 | + g_rstep_user_fn++; |
| 71 | + } |
| 72 | +} |
| 73 | +#endif |
| 74 | + |
13 | 75 | /* ------------------------------------------------------------------------- */ |
14 | 76 | /* seq and realized? */ |
15 | 77 | /* ------------------------------------------------------------------------- */ |
@@ -505,6 +567,9 @@ static int reduce_step(mino_state_t *S, mino_val_t *fn, mino_val_t **acc_io, |
505 | 567 | mino_val_t *elem, mino_env_t *env) |
506 | 568 | { |
507 | 569 | mino_val_t *acc = *acc_io; |
| 570 | +#ifdef MINO_REDUCE_STEP_COUNTS |
| 571 | + rstep_count(fn); |
| 572 | +#endif |
508 | 573 | if (fn != NULL && mino_type_of(fn) == MINO_PRIM |
509 | 574 | && fn->as.prim.fn != NULL |
510 | 575 | && acc != NULL && mino_val_int_p(acc) |
|
0 commit comments