Skip to content

Comments

codegen: Add llvm_options parameter to code_llvm for pass instrumentation#60698

Open
gbaraldi wants to merge 1 commit intomasterfrom
gb/print-options-llvm
Open

codegen: Add llvm_options parameter to code_llvm for pass instrumentation#60698
gbaraldi wants to merge 1 commit intomasterfrom
gb/print-options-llvm

Conversation

@gbaraldi
Copy link
Member

@gbaraldi gbaraldi commented Jan 15, 2026

Add the ability to pass LLVM pass manager options directly to code_llvm() for debugging and analysis purposes. This allows users to inspect IR at various stages of the optimization pipeline without needing to set environment variables.

Supported options include:

  • -print-after-all: Print IR after each pass
  • -print-before-all: Print IR before each pass
  • -print-after=<passname>: Print IR after a specific pass
  • -print-before=<passname>: Print IR before a specific pass
  • -print-module-scope: Print entire module instead of just the function
  • -filter-print-funcs=<name>: Filter output to specific functions

Example usage:
code_llvm(+, (Int, Int); llvm_options="-print-after=loop-vectorize")

@gbaraldi gbaraldi requested review from vchuravy and vtjnash January 15, 2026 12:22
@gbaraldi gbaraldi force-pushed the gb/print-options-llvm branch 5 times, most recently from 9be33d6 to e363be3 Compare January 15, 2026 15:39
@oscardssmith
Copy link
Member

This is amazing! Thank you so much!

@oscardssmith
Copy link
Member

The only UI question IMO is whether we want the string interface or to use a kwarg interface (e.g. print-after=:allocopt)

@gbaraldi
Copy link
Member Author

I initially had something like that but to me it felt weird. This is very much a LLVM api and I think users of this are probably familiar with that syntax. (it's also much simpler to plumb through)

@gbaraldi gbaraldi force-pushed the gb/print-options-llvm branch 2 times, most recently from 6e72b9d to 12d1b7e Compare January 15, 2026 19:14
@gbaraldi gbaraldi force-pushed the gb/print-options-llvm branch from 7678a81 to 7ddc6e3 Compare January 16, 2026 19:20
@gbaraldi gbaraldi force-pushed the gb/print-options-llvm branch 3 times, most recently from 2bc0119 to d083a17 Compare January 19, 2026 19:18
@gbaraldi gbaraldi force-pushed the gb/print-options-llvm branch from 3d99c05 to 4d73f42 Compare February 3, 2026 15:34
@gbaraldi gbaraldi force-pushed the gb/print-options-llvm branch 3 times, most recently from 99b0868 to cabf404 Compare February 23, 2026 22:24
…tion

Add an `llvm_options` keyword argument to `code_llvm` that accepts
LLVM-style option strings for controlling pass instrumentation output.
This enables printing IR before/after optimization passes, filtering
by pass name and function name, and printing at module scope.

Supported options:
  -print-before-all / -print-after-all
  -print-before=<pass> / -print-after=<pass> (comma-separated or repeated)
  -filter-print-funcs=<name> (comma-separated or repeated)
  -print-module-scope

Options are parsed using LLVM's TokenizeGNUCommandLine. Pass output is
captured and prepended to the final IR output. The filter-print-funcs
option supports comma-separated lists matching LLVM's
CommaSeparateAndAddOccurrence behavior, and properly suppresses output
for non-Function IR when a filter is set.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gbaraldi gbaraldi force-pushed the gb/print-options-llvm branch from 56c1479 to 1a5b5c0 Compare February 24, 2026 23:19
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.

4 participants