Skip to content

compiler: emit finer grained codegen events to eventlog

We use withTiming in most codegen passes to report fine-grained timings both on stderr and in the event log.

Unlike many other passes from GHC's pipeline, the ones affected by this patch don't run as a single block. Instead, this part of the pipeline starts with groups of toplevel STG bindings being streamed down the code generation pipeline (STG -> Cmm, Cmm -> RawCmm, ...). This effectively means that the different passes are interleaved and that we cannot emit, say, "STG -> Cmm starts" and "STG -> Cmm ends" events once each, with just one continuous block of time assigned to that label.

Instead, this patch tries to emit many smaller events around the processing of each stream element, for all "passes", throughought the entire codegen pipeline.

One can then use threadscope, ghc-events-analyze or other tools to visualize the execution of GHC's code generation through its event log, to get the total time spent in each codegen pass, etc.

Note: I didn't instrument the LLVM backend because its LlvmM monad makes things less straightforward, and likely to be worth a discussion, so I thought a dedicated MR would be best.

Merge request reports