Skip to content

[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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

miguelcsx
Copy link
Contributor

@miguelcsx miguelcsx commented Jun 24, 2025

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:

  • Kernel-info remarks appeared in terminal output
  • Kernel-info remarks were missing from YAML files

Solution

Move kernel-info pass registration from FullLinkTimeOptimizationLastEPCallback to OptimizerLastEPCallback, 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:

image

Sorry for the light theme hehe

Targets Affected

  • NVPTX
  • AMDGPU

Testing

Tested with:

clang -O2 -g -fopenmp --offload-arch=native main.c -foffload-lto \
  -Rpass=kernel-info -fsave-optimization-record

The fix provides meaningful source locations by falling back to the
containing function's subprogram information instead of showing unknown
locations.
@miguelcsx miguelcsx force-pushed the refac/kernel-info branch from 06bb439 to 131546e Compare June 25, 2025 00:38
@miguelcsx miguelcsx changed the title [Analysis] Improve KernelInfo debug location handling for compiler-generated code [Target][KernelInfo] Fix kernel-info remarks missing from YAML optimization records Jun 25, 2025
Copy link

github-actions bot commented Jun 25, 2025

✅ 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.
@miguelcsx miguelcsx force-pushed the refac/kernel-info branch from 131546e to 9f77d27 Compare June 25, 2025 00:46
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.

1 participant