Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support emitting debuginfo w.r.t. LLVM IR #56792

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

topolarity
Copy link
Member

@topolarity topolarity commented Dec 10, 2024

This change adds two new environmental variables:

  • JULIA_DUMP_IR - when provided, this is a path that all emitted LLVM IR (post-optimization, just before machine code generation) will be saved to
  • JULIA_DEBUGINFO - when set to "LLVM-IR" this will run an additional pass on any emitted functions to rewrite their debuginfo to refer to the LLVM source, rather than the Julia source it was generated from

This allows gdb to open the dumped IR and means you can step through LLVM IR line-by-line, print SSA values, etc. which can be very useful for debugging segfaults, or issues in codegen:
image

The debugir pass that rewrites the debuginfo is vendored from: https://github.com/vaivaswatha/debugir. For simplicity, this is just a copy of the one file that we need for the pass.

@@ -567,6 +567,8 @@ static void buildCleanupPipeline(ModulePassManager &MPM, PassBuilder *PB, Optimi
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
}
}
// TODO: This should be conditionally enabled depending on the emission mode for the Execution engine
MPM.addPass(createModuleToFunctionPassAdaptor(InstructionNamerPass()));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gbaraldi Do you know where else I need to add this pass to get complete coverage?

It also needs to be turned on / off depending on the debuginfo mode, but I think I can probably pipe that through the OptimizationOptions maybe

Copy link
Member

@gbaraldi gbaraldi Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should only be here. Though yeah make it conditional on the options. Similar to #55407 and maybe an llvmpasses test. Not sure if it's super worth it but 🤷

@topolarity topolarity force-pushed the ct/debugir branch 2 times, most recently from 29679d0 to b2bdd73 Compare December 10, 2024 20:38
This change adds two new environmental variables:
  - `JULIA_DUMP_IR` - when provided, this is a path that all emitted
    LLVM IR (post-optimization, just before machine code generation)
    will be saved to
  - `JULIA_DEBUGINFO` - when set to "LLVM-IR" this will run an additional
    pass on any emitted functions to rewrite their debuginfo to refer to
    the LLVM source, rather than the Julia source it was generated from

The `debugir` pass that rewrites the debuginfo is vendored from:
  https://github.com/vaivaswatha/debugir. For simplicity, this is just a
copy of the one file that we need for the pass.

Using both of these together allows `gdb` to open the dumped IR and means
you can step through LLVM IR line-by-line, print SSA values, etc. This can
be very useful for debugging segfaults, or issues in codegen.
@topolarity topolarity changed the title Support (optionally) emitting debuginfo w.r.t. LLVM source Support emitting debuginfo with LLVM IR as source Dec 10, 2024
@topolarity topolarity changed the title Support emitting debuginfo with LLVM IR as source Support emitting debuginfo w.r.t. LLVM IR Dec 10, 2024
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.

2 participants