Skip to content

Conversation

@wenju-he
Copy link
Contributor

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

Before this PR, SPIR-V built-in is represented as global variable for SPIR/SPIR-V targets and as function call for other targets in include/sycl/__spirv/spirv_vars.hpp.

According to https://github.com/llvm/llvm-project/blob/main/llvm/docs/SPIRVUsage.rst, SPIR-V built-in variable can be mapped to either function call or global variable. So function call representation should work for SPIR-V target as well.
The benefit of choosing function call over global variable is that
function call works better for AOT targets that bypass SPIR-V. It is
easier for these targets to implements SPIR-V built-in function via
built-in modules like libclc rather than special handling for lowering
global variable in a custom pass.

Add BuiltIn to the name to align with SPIR-V friendly IR and global variable name.

…ltIn` to the name

Before this PR, SPIR-V built-in is represented as global variable for
SPIR/SPIR-V targets and as function call for other targets in
include/sycl/__spirv/spirv_vars.hpp.

According to https://github.com/KhronosGroup/SPIRV-LLVM-Translator/blob/main/docs/SPIRVRepresentationInLLVM.rst,
SPIR-V built-in variable can be mapped to either function call or global
variable. So function call representation should work for SPIR-V target.

Add `BuiltIn` to the name to align with SPIR-V friendly IR.
wenju-he added a commit to wenju-he/llvm-project that referenced this pull request Jul 14, 2025
wenju-he added a commit to llvm/llvm-project that referenced this pull request Jul 18, 2025
…#148567)

The mapping ensures the function is lowered to SPIR-V built-in variables
in SPIR-V. This can fix pre-commit CI fail in intel/llvm#19359

Also add BuiltIn to SPIR-V Builtin function name in __clang_spirv_builtins.h to align with
https://github.com/llvm/llvm-project/blob/main/llvm/docs/SPIRVUsage.rst#builtin-variables
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 18, 2025
…n variables (#148567)

The mapping ensures the function is lowered to SPIR-V built-in variables
in SPIR-V. This can fix pre-commit CI fail in intel/llvm#19359

Also add BuiltIn to SPIR-V Builtin function name in __clang_spirv_builtins.h to align with
https://github.com/llvm/llvm-project/blob/main/llvm/docs/SPIRVUsage.rst#builtin-variables
wenju-he added a commit to wenju-he/llvm that referenced this pull request Jul 18, 2025
… (#148567)

The mapping ensures the function is lowered to SPIR-V built-in variables
in SPIR-V. This can fix pre-commit CI fail in intel#19359

(cherry picked from commit 64205ad)
This is a partial cherry-pick since 27c9b55 isn't in intel/llvm yet.
steffenlarsen pushed a commit that referenced this pull request Jul 18, 2025
…(#148567) (#19510)

The mapping ensures the function is lowered to SPIR-V built-in variables
in SPIR-V. This can fix pre-commit CI fail in
#19359

(cherry picked from commit 64205ad)
This is a partial cherry-pick since 27c9b55 isn't in intel/llvm
yet.
@wenju-he wenju-he marked this pull request as ready for review July 18, 2025 11:19
@wenju-he wenju-he requested review from a team as code owners July 18, 2025 11:19
@wenju-he
Copy link
Contributor Author

kindly ping @intel/llvm-reviewers-runtime @intel/dpcpp-esimd-reviewers @intel/dpcpp-sanitizers-review for review

Comment on lines 1 to 2


Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

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, thanks @uditagarwal97

Copy link
Contributor

@sarnex sarnex left a comment

Choose a reason for hiding this comment

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

lgtm minus one question

DEVICE_EXTERN_C_INLINE
int rand() {
size_t gid =
#if defined(__NVPTX__) || defined(__AMDGCN__)
Copy link
Contributor

Choose a reason for hiding this comment

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

The PR description says

According to https://github.com/llvm/llvm-project/blob/main/llvm/docs/SPIRVUsage.rst, SPIR-V built-in variable can be mapped to either function call or global variable. So function call representation should work for SPIR-V target as well.

So it sounds like both using a global and a function are valid in SPIR-V friendly IR.

Is there some benefit we get from changing it from a global variable to a function? I assume there is, but please add it to the PR description.

Copy link
Contributor Author

@wenju-he wenju-he Jul 30, 2025

Choose a reason for hiding this comment

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

Is there some benefit we get from changing it from a global variable to a function? I assume there is, but please add it to the PR description.

done, add following to PR description:

The benefit of choosing function call over global variable is that
function call works better for AOT targets that bypass SPIR-V. It is
easier for these targets to implements SPIR-V built-in function via
built-in modules like libclc rather than special handling for lowering
global variable in a custom pass.

Copy link
Contributor

@zhaomaosu zhaomaosu left a comment

Choose a reason for hiding this comment

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

sanitizer part lgtm

@wenju-he
Copy link
Contributor Author

@MrSidims please review new change to llvm/lib/SYCLLowerIR/SYCLOptimizeBarriers.cpp in 33546b4, thanks.

@wenju-he wenju-he requested a review from MrSidims July 30, 2025 03:42
Copy link
Contributor

@MrSidims MrSidims left a comment

Choose a reason for hiding this comment

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

Barrier pass modification is LGTM

Copy link
Contributor

@sarnex sarnex left a comment

Choose a reason for hiding this comment

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

lgtm as in my feedback was addressed, thanks!

@wenju-he
Copy link
Contributor Author

@intel/llvm-gatekeepers please merge, thanks

@uditagarwal97 uditagarwal97 merged commit 8fe0c4d into intel:sycl Jul 31, 2025
42 of 44 checks passed
@wenju-he wenju-he deleted the __spirv_BuiltIn branch July 31, 2025 22:57
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.

7 participants