Skip to content

[SYCL] Fix unconditional spir_func CC on printf declaration for non-SPIR targets - #22997

Open
jsji wants to merge 3 commits into
intel:syclfrom
jsji:printfdeclrix
Open

[SYCL] Fix unconditional spir_func CC on printf declaration for non-SPIR targets#22997
jsji wants to merge 3 commits into
intel:syclfrom
jsji:printfdeclrix

Conversation

@jsji

@jsji jsji commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

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

…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>
@jsji
jsji requested a review from a team as a code owner August 22, 2026 14:24
@jsji jsji self-assigned this Aug 22, 2026
@bader
bader requested a balanced review from Copilot August 22, 2026 17:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_FUNC to 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);
@bader

bader commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Please, add tests.

jsji and others added 2 commits August 22, 2026 21:12
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>
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.

3 participants