Skip to content

Add PrintTAFn flag for targeted type analysis printing #142809

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

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

Conversation

KMJ-007
Copy link

@KMJ-007 KMJ-007 commented Jun 20, 2025

Summary

This PR adds a new PrintTAFn flag to the -Z autodiff option that allows printing type analysis information for a specific function, rather than all functions.

Changes

New Flag

  • Added PrintTAFn=<function_name> option to -Z autodiff
  • Usage: -Z autodiff=Enable,PrintTAFn=my_function_name

Implementation Details

  • Rust side: Added PrintTAFn(String) variant to AutoDiff enum
  • Parser: Updated parse_autodiff to handle PrintTAFn=<function_name> syntax with proper error handling
  • FFI: Added set_print_type_fun function to interface with Enzyme's FunctionToAnalyze command line option
  • Documentation: Updated help text and documentation for the new flag

Files Modified

  • compiler/rustc_session/src/config.rs: Added PrintTAFn(String) variant
  • compiler/rustc_session/src/options.rs: Updated parser and help text (now shows PrintTAFn in the list)
  • compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs: Added FFI function and static variable
  • compiler/rustc_codegen_llvm/src/back/lto.rs: Added handling for new flag
  • src/doc/rustc-dev-guide/src/autodiff/flags.md: Updated documentation
  • src/doc/unstable-book/src/compiler-flags/autodiff.md: Updated documentation

Testing

The flag can be tested with:

rustc +enzyme -Z autodiff=Enable,PrintTAFn=square test.rs

This will print type analysis information only for the function named "square" instead of all functions.

Error Handling

The parser includes proper error handling:

  • Missing argument: PrintTAFn without =<function_name> will show an error
  • Unknown options: Invalid autodiff options will be reported

r? @ZuseZ4

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-rustc-dev-guide Area: rustc-dev-guide F-autodiff `#![feature(autodiff)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 20, 2025

Some changes occurred in compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

cc @ZuseZ4

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @jieyouxu, @Kobzol

Some changes occurred in src/doc/unstable-book/src/compiler-flags/autodiff.md

cc @ZuseZ4

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-tidy failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[TIMING] core::build_steps::tool::Tidy { compiler: Compiler { stage: 0, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu } -- 0.000
fmt check
Diff in /checkout/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:57:
 
 #[cfg(llvm_enzyme)]
 pub(crate) mod Enzyme_AD {
-    use libc::c_void;
     use std::ffi::{CString, c_char};
+
+    use libc::c_void;
 
     unsafe extern "C" {
         pub(crate) fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8);
fmt: checked 6077 files
Build completed unsuccessfully in 0:00:44
  local time: Fri Jun 20 20:59:03 UTC 2025
  network time: Fri, 20 Jun 2025 20:59:03 GMT
##[error]Process completed with exit code 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-rustc-dev-guide Area: rustc-dev-guide F-autodiff `#![feature(autodiff)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants