Skip to content

[libspirv][remangler] Remangle pointer address space when target's default addrspace is private #18383

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

Merged
merged 7 commits into from
May 23, 2025

Conversation

wenju-he
Copy link
Contributor

@wenju-he wenju-he commented May 9, 2025

For target where default address space is private, pointer address space mangling in libclc is not compatible with SYCL mangling. Take spir64 target as example,
OpenCL mangling:
_Z17__spirv_ocl_fractfPU3AS4f(float, ptr addrspace(4))
_Z17__spirv_ocl_fractfPf(float, ptr)
SYCL mangling:
_Z17__spirv_ocl_fractfPf(float, ptr addrspace(4))
_Z17__spirv_ocl_fractfPU3AS0f(float, ptr)
This leads to issue when linking libclc built-ins to SYCL device code. This PR fixes the issue by remangling libclc built-ins to align with SYCL: Remangle _Z17__spirv_ocl_fractfPU3AS4f to _Z17__spirv_ocl_fractfPf. Remangle _Z17__spirv_ocl_fractfPf to _Z17__spirv_ocl_fractfPU3AS0f.

Relates to #16703

This PR is for targets whose default addrspace is private, such as
spir64/spirv. In intel/llvm repo, currently there is no such libspirv target.
In our downstream repo, we have a target of this kind.
Put this PR in this repo to avoid customization in the downstream repo.

…fault addrspace is private

For target where default address space is private, pointer address space
mangling in libclc is not compatible with SYCL mangling.
Take spir64 target as example,
OpenCL mangling:
  _Z17__spirv_ocl_fractfPU3AS4f(float, ptr addrspace(4))
  _Z17__spirv_ocl_fractfPf(float, ptr)
SYCL mangling:
  _Z17__spirv_ocl_fractfPf(float, ptr addrspace(4))
  _Z17__spirv_ocl_fractfPU3AS0f(float, ptr)
This leads to issue when linking libclc built-ins to SYCL device code.
This PR fixes the issue by remangling libclc built-ins to align with SYCL:
Remangle _Z17__spirv_ocl_fractfPU3AS4f to _Z17__spirv_ocl_fractfPf.
Remangle _Z17__spirv_ocl_fractfPf to _Z17__spirv_ocl_fractfPU3AS0f.

Relates to intel#16703
@wenju-he wenju-he requested a review from a team as a code owner May 9, 2025 10:34
@wenju-he wenju-he requested a review from npmiller May 9, 2025 10:34
@wenju-he wenju-he temporarily deployed to WindowsCILock May 9, 2025 10:35 — with GitHub Actions Inactive
@wenju-he wenju-he temporarily deployed to WindowsCILock May 9, 2025 11:01 — with GitHub Actions Inactive
@wenju-he wenju-he temporarily deployed to WindowsCILock May 9, 2025 11:01 — with GitHub Actions Inactive
@wenju-he wenju-he temporarily deployed to WindowsCILock May 21, 2025 08:11 — with GitHub Actions Inactive
@wenju-he
Copy link
Contributor Author

kindly ping @intel/llvm-reviewers-cuda for review, thanks

Copy link
Contributor

@frasercrmck frasercrmck left a comment

Choose a reason for hiding this comment

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

Are there any tests we can add for this?

Which targets does this alter codegen for?

// revert _Z1fPi$TmpSuffix back to _Z1fPi, a clash occurs because _Z1fPi
// still exists. Since _Z1fPi is no longer useful, it is renamed to
// _Z1fPi.old,
if (auto *Func = M->getFunction(Name))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we think about removing this function instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, deleted the function

@wenju-he
Copy link
Contributor Author

wenju-he commented May 22, 2025

Are there any tests we can add for this?
Which targets does this alter codegen for?

This PR is for targets whose default addrspace is private, such as spir64/spirv.
In intel/llvm repo, currently there is no such libspirv target. So it is not possible to test in this repo.
In our downstream repo, we have a target of this kind, which will be upstreamed.
I put this PR in this repo to avoid customization in the downstream repo.

@wenju-he wenju-he temporarily deployed to WindowsCILock May 22, 2025 01:46 — with GitHub Actions Inactive
@wenju-he wenju-he requested a review from frasercrmck May 22, 2025 01:47
@wenju-he wenju-he temporarily deployed to WindowsCILock May 22, 2025 02:08 — with GitHub Actions Inactive
@wenju-he wenju-he temporarily deployed to WindowsCILock May 22, 2025 02:08 — with GitHub Actions Inactive
@@ -271,6 +285,7 @@ class Remangler {
: AST(AST), Root(Root), TypeReplacements(TypeReplacements) {
MangleContext.reset(
ItaniumMangleContext::create(*AST, AST->getDiagnostics()));
TargetGenericAddrSpace = AST->getTargetAddressSpace(LangAS::Default);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be called TargetDefaultAddrSpace? I worry that 'generic' is an overloaded term.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be called TargetDefaultAddrSpace? I worry that 'generic' is an overloaded term.

done, thanks for the suggestion

@bader
Copy link
Contributor

bader commented May 23, 2025

CI is broken. Considering the latest commit just renamed the variable and before the renaming CI was green, it's safe to merge.

@bader bader merged commit 781b312 into intel:sycl May 23, 2025
20 of 23 checks passed
@wenju-he wenju-he deleted the libspirv-remangler-TargetGenericAddrSpace branch May 25, 2025 23:11
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