[SYCL] Fix unconditional spir_func CC on printf declaration for non-SPIR targets - #22997
Open
jsji wants to merge 3 commits into
Open
[SYCL] Fix unconditional spir_func CC on printf declaration for non-SPIR targets#22997jsji wants to merge 3 commits into
jsji wants to merge 3 commits into
Conversation
…PIR targets SYCLMutatePrintfAddrspacePass unconditionally inserted a _Z18__spirv_ocl_printfPU3AS2Kcz declaration with SPIR_FUNC calling convention into every SYCL device module, even when no printf was used. Fix by (1) lazily creating the declaration only when a printf function actually needs transformation, and (2) only setting SPIR_FUNC CC when the target triple is SPIR/SPIR-V — other targets keep the default C convention which their backends accept. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents invalid SPIR_FUNC printf declarations in non-SPIR SYCL modules.
Changes:
- Lazily creates the constant-address-space printf declaration.
- Restricts
SPIR_FUNCto SPIR/SPIR-V targets.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+112
to
+114
| Triple TT(M.getTargetTriple()); | ||
| if (TT.isSPIROrSPIRV()) | ||
| CASPrintfFunc->setCallingConv(CallingConv::SPIR_FUNC); |
Comment on lines
+86
to
+87
| if (!CASPrintfFunc) | ||
| CASPrintfFunc = getCASPrintfFunction(M, CASLiteralType); |
Contributor
|
Please, add tests. |
Add LIT tests verifying that: - The pass does not set spir_func CC on non-SPIR/SPIR-V targets - No spurious printf declaration is inserted when no printf needs transformation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address Copilot review: defer getCASPrintfFunction until at least one call user exists, so the lazy-creation guarantee covers modules with unused printf declarations that have no CallInst users. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SYCLMutatePrintfAddrspacePass unconditionally inserted a
_Z18__spirv_ocl_printfPU3AS2Kcz declaration with SPIR_FUNC calling
convention into every SYCL device module, even when no printf was used.
Fix by (1) lazily creating the declaration only when a printf function
actually needs transformation, and (2) only setting SPIR_FUNC CC when
the target triple is SPIR/SPIR-V — other targets keep the default C
convention which their backends accept.
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com