-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Target][KernelInfo] Fix kernel-info remarks missing from YAML optimization records #145603
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
base: main
Are you sure you want to change the base?
Conversation
The fix provides meaningful source locations by falling back to the containing function's subprogram information instead of showing unknown locations.
06bb439 to
131546e
Compare
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
… for YAML remark output The kernel-info pass was registered using FullLinkTimeOptimizationLastEPCallback, which runs after the optimization record YAML files have been finalized. This caused kernel-info remarks to appear in terminal output but not in YAML files when using -fsave-optimization-record. Move kernel-info registration to OptimizerLastEPCallback, which runs during the LTO optimization pipeline while the remark streamer is still active. This ensures kernel-info remarks (including NVVM GPU intrinsics like @llvm.nvvm.read.ptx.sreg.tid.x) are captured in both terminal output and YAML optimization record files. Affects NVPTX and AMDGPU targets.
131546e to
9f77d27
Compare
|
@jdoerfert had suggested I place KernelInfo as late in the pipeline as possible. I'm concerned that moving the pass earlier will change remarks not to as closely reflect the hardware instructions that will actually execute. Instead, we can try to tell offload LTO to generate the yaml. @miguelcsx Do these clang command-line options work for you? That's a bit ugly. In the future, maybe we need some way for clang's |
Shouldn't this be forwarded automatically via https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/Clang.cpp#L9117? |
|
Adding |
|
Well, it's generating |
As discussed in PR llvm#145603, the following command fails to produce a YAML remarks file for offload LTO passes and thus for kernel-info: ``` clang -O2 -g -fopenmp --offload-arch=native test.c -foffload-lto \ -Rpass=kernel-info -fsave-optimization-record ``` The problem is that, in clang-linker-wrapper's clang call, clang names the file based on clang's main output file (from `-o`). That is a temporary file, so the YAML file becomes a temporary file, which the user never sees. This patch: - Extends clang with a hidden `-foutput-file-base=BASE` option that overrides the main output file as the base for other output files. - Makes clang honor that option only for the default YAML remarks file, but future patches could use it for other output files too. - Extends clang-linker-wrapper to specify that option to clang.
As discussed in PR #145603, the following command seems to fail to produce a YAML remarks file for offload LTO passes and thus for kernel-info: ``` clang -O2 -g -fopenmp --offload-arch=native test.c -foffload-lto \ -Rpass=kernel-info -fsave-optimization-record ``` The problem is that, in clang-linker-wrapper's clang call, clang names the file based on clang's main output file (from `-o`). That is a temporary file, so the YAML file becomes a temporary file, which the user never sees. This patch: - Makes clang honor `-dumpdir` for the default YAML remarks file in the case of LTO. - Extends clang-linker-wrapper to specify that option to clang. To demonstrate the appeal of the generality of `-dumpdir` (as opposed to a one-off `-fsave-optimization-record` solution in clang-linker-wrapper), this patch also fixes `-gsplit-dwarf`. Without this patch, when using `-gsplit-dwarf` and later debugging using rocgdb, the dwo directory for offload is a temporary file, so temporary file cleanup causes rocgdb to lose debug symbols for offload code. WARNING: The clang driver passes `-dumpdir` to various clang frontend calls. For LTO, that was previously being ignored, and now it's not. That changes some auxiliary file names, as revealed by changes in some existing tests' expected output: `clang/test/Driver/opt-record.c` and `clang/test/Driver/lto-dwo.c`. Hopefully this change does not introduce a backward compatibility issue for users.
Summary
Fixes an issue where kernel-info pass remarks were not being saved to YAML optimization record files when using
-fsave-optimization-record, despite appearing in terminal output.Problem
The kernel-info pass was registered using
FullLinkTimeOptimizationLastEPCallback, which runs after the LTO pipeline completes and after the remark streamer has been finalized. This timing issue caused:Solution
Move kernel-info pass registration from
FullLinkTimeOptimizationLastEPCallbacktoOptimizerLastEPCallback, which runs during the LTO optimization pipeline while the remark streamer is still active.Resulting Diff in YAML Output
Example of YAML output before and after this change:
Targets Affected
Testing
Tested with: