Skip to content

Add opt-in register-allocation tracing (AGBCC_TRACE_ALLOC) - #91

Open
SensanaMMZ wants to merge 1 commit into
pret:masterfrom
SensanaMMZ:feature/opt-in-alloc-trace
Open

Add opt-in register-allocation tracing (AGBCC_TRACE_ALLOC)#91
SensanaMMZ wants to merge 1 commit into
pret:masterfrom
SensanaMMZ:feature/opt-in-alloc-trace

Conversation

@SensanaMMZ

Copy link
Copy Markdown

Adds an opt-in diagnostic that makes the register allocator explain its decisions, which is very useful when reconstructing C for a byte-match and a value lands in an unexpected register.

When the AGBCC_TRACE_ALLOC environment variable is set, the compiler emits one line per hard-register assignment to stderr:

[lalloc] pseudo 42 -> r0  (qty 0, births 2, deaths 26, n_calls_crossed 0)
[galloc] pseudo 39 -> SPILL (allocno 9, calls_crossed 0)
[galloc] pseudo 39 -> r12  (allocno 9, size 1, calls_crossed 0, live_length 24, n_refs 3)

The numbers are exactly the priority inputs the allocator sorts on, so you can see why a pseudo lost the low-register race and got retried into a high register, rather than inferring it from the output.

  • 21 lines across gcc/global.c (the find_reg commit and spill paths) and gcc/local-alloc.c (quantity propagation).
  • Entirely gated on the environment variable; with it unset the compiler is unchanged. Verified that codegen is byte-identical with tracing off and on.
  • No new build flags, no header changes.

Emits one line per hard-register assignment in local and global allocation,
with the priority inputs (size, calls_crossed, live_length, n_refs). Gated on
the AGBCC_TRACE_ALLOC environment variable, so it is inert and does not affect
codegen unless explicitly enabled -- useful for understanding why the allocator
placed a value in a particular register when matching decompilations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant