-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang][SPIRV] Add builtin for OpGenericCastToPtrExplicit and its SPIR-V friendly binding #137805
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
VyacheslavLevytskyy
merged 2 commits into
llvm:main
from
Naghasan:generic_cast_to_ptr_explicit_builtin
May 29, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| /*===---- spirv_builtin_vars.h - SPIR-V built-in ---------------------------=== | ||
| * | ||
| * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| * See https://llvm.org/LICENSE.txt for license information. | ||
| * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| * | ||
| *===-----------------------------------------------------------------------=== | ||
| */ | ||
|
|
||
| #ifndef __SPIRV_BUILTIN_VARS_H | ||
| #define __SPIRV_BUILTIN_VARS_H | ||
|
|
||
| #if __cplusplus >= 201103L | ||
| #define __SPIRV_NOEXCEPT noexcept | ||
| #else | ||
| #define __SPIRV_NOEXCEPT | ||
| #endif | ||
|
|
||
| #define __SPIRV_overloadable __attribute__((overloadable)) | ||
| #define __SPIRV_convergent __attribute__((convergent)) | ||
| #define __SPIRV_inline __attribute__((always_inline)) | ||
|
|
||
| #define __global __attribute__((opencl_global)) | ||
| #define __local __attribute__((opencl_local)) | ||
| #define __private __attribute__((opencl_private)) | ||
| #define __constant __attribute__((opencl_constant)) | ||
| #ifdef __SYCL_DEVICE_ONLY__ | ||
| #define __generic | ||
| #else | ||
| #define __generic __attribute__((opencl_generic)) | ||
| #endif | ||
|
|
||
| // Check if SPIR-V builtins are supported. | ||
| // As the translator doesn't use the LLVM intrinsics (which would be emitted if | ||
| // we use the SPIR-V builtins) we can't rely on the SPIRV32/SPIRV64 etc macros | ||
| // to establish if we can use the builtin alias. We disable builtin altogether | ||
| // if we do not intent to use the backend. So instead of use target macros, rely | ||
| // on a __has_builtin test. | ||
| #if (__has_builtin(__builtin_spirv_generic_cast_to_ptr_explicit)) | ||
| #define __SPIRV_BUILTIN_ALIAS(builtin) \ | ||
| __attribute__((clang_builtin_alias(builtin))) | ||
| #else | ||
| #define __SPIRV_BUILTIN_ALIAS(builtin) | ||
| #endif | ||
|
|
||
| // OpGenericCastToPtrExplicit | ||
|
|
||
| extern __SPIRV_overloadable | ||
| __SPIRV_BUILTIN_ALIAS(__builtin_spirv_generic_cast_to_ptr_explicit) | ||
| __global void *__spirv_GenericCastToPtrExplicit_ToGlobal(__generic void *, | ||
| int) __SPIRV_NOEXCEPT; | ||
| extern __SPIRV_overloadable | ||
| __SPIRV_BUILTIN_ALIAS(__builtin_spirv_generic_cast_to_ptr_explicit) | ||
| __global const void * | ||
| __spirv_GenericCastToPtrExplicit_ToGlobal(__generic const void *, | ||
| int) __SPIRV_NOEXCEPT; | ||
| extern __SPIRV_overloadable | ||
| __SPIRV_BUILTIN_ALIAS(__builtin_spirv_generic_cast_to_ptr_explicit) | ||
| __global volatile void * | ||
| __spirv_GenericCastToPtrExplicit_ToGlobal(__generic volatile void *, | ||
| int) __SPIRV_NOEXCEPT; | ||
| extern __SPIRV_overloadable | ||
| __SPIRV_BUILTIN_ALIAS(__builtin_spirv_generic_cast_to_ptr_explicit) | ||
| __global const volatile void * | ||
| __spirv_GenericCastToPtrExplicit_ToGlobal(__generic const volatile void *, | ||
| int) __SPIRV_NOEXCEPT; | ||
| extern __SPIRV_overloadable | ||
| __SPIRV_BUILTIN_ALIAS(__builtin_spirv_generic_cast_to_ptr_explicit) | ||
| __local void *__spirv_GenericCastToPtrExplicit_ToLocal(__generic void *, | ||
| int) __SPIRV_NOEXCEPT; | ||
| extern __SPIRV_overloadable | ||
| __SPIRV_BUILTIN_ALIAS(__builtin_spirv_generic_cast_to_ptr_explicit) | ||
| __local const void * | ||
| __spirv_GenericCastToPtrExplicit_ToLocal(__generic const void *, | ||
| int) __SPIRV_NOEXCEPT; | ||
| extern __SPIRV_overloadable | ||
| __SPIRV_BUILTIN_ALIAS(__builtin_spirv_generic_cast_to_ptr_explicit) | ||
| __local volatile void * | ||
| __spirv_GenericCastToPtrExplicit_ToLocal(__generic volatile void *, | ||
| int) __SPIRV_NOEXCEPT; | ||
| extern __SPIRV_overloadable | ||
| __SPIRV_BUILTIN_ALIAS(__builtin_spirv_generic_cast_to_ptr_explicit) | ||
| __local const volatile void * | ||
| __spirv_GenericCastToPtrExplicit_ToLocal(__generic const volatile void *, | ||
| int) __SPIRV_NOEXCEPT; | ||
| extern __SPIRV_overloadable | ||
| __SPIRV_BUILTIN_ALIAS(__builtin_spirv_generic_cast_to_ptr_explicit) | ||
| __private void * | ||
| __spirv_GenericCastToPtrExplicit_ToPrivate(__generic void *, | ||
| int) __SPIRV_NOEXCEPT; | ||
| extern __SPIRV_overloadable | ||
| __SPIRV_BUILTIN_ALIAS(__builtin_spirv_generic_cast_to_ptr_explicit) | ||
| __private const void * | ||
| __spirv_GenericCastToPtrExplicit_ToPrivate(__generic const void *, | ||
| int) __SPIRV_NOEXCEPT; | ||
| extern __SPIRV_overloadable | ||
| __SPIRV_BUILTIN_ALIAS(__builtin_spirv_generic_cast_to_ptr_explicit) | ||
| __private volatile void * | ||
| __spirv_GenericCastToPtrExplicit_ToPrivate(__generic volatile void *, | ||
| int) __SPIRV_NOEXCEPT; | ||
| extern __SPIRV_overloadable | ||
| __SPIRV_BUILTIN_ALIAS(__builtin_spirv_generic_cast_to_ptr_explicit) | ||
| __private const volatile void * | ||
| __spirv_GenericCastToPtrExplicit_ToPrivate(__generic const volatile void *, | ||
| int) __SPIRV_NOEXCEPT; | ||
|
|
||
| // OpGenericCastToPtr | ||
|
|
||
| static __SPIRV_overloadable __SPIRV_inline __global void * | ||
| __spirv_GenericCastToPtr_ToGlobal(__generic void *p, int) __SPIRV_NOEXCEPT { | ||
| return (__global void *)p; | ||
| } | ||
| static __SPIRV_overloadable __SPIRV_inline __global const void * | ||
| __spirv_GenericCastToPtr_ToGlobal(__generic const void *p, | ||
| int) __SPIRV_NOEXCEPT { | ||
| return (__global const void *)p; | ||
| } | ||
| static __SPIRV_overloadable __SPIRV_inline __global volatile void * | ||
| __spirv_GenericCastToPtr_ToGlobal(__generic volatile void *p, | ||
| int) __SPIRV_NOEXCEPT { | ||
| return (__global volatile void *)p; | ||
| } | ||
| static __SPIRV_overloadable __SPIRV_inline __global const volatile void * | ||
| __spirv_GenericCastToPtr_ToGlobal(__generic const volatile void *p, | ||
| int) __SPIRV_NOEXCEPT { | ||
| return (__global const volatile void *)p; | ||
| } | ||
| static __SPIRV_overloadable __SPIRV_inline __local void * | ||
| __spirv_GenericCastToPtr_ToLocal(__generic void *p, int) __SPIRV_NOEXCEPT { | ||
| return (__local void *)p; | ||
| } | ||
| static __SPIRV_overloadable __SPIRV_inline __local const void * | ||
| __spirv_GenericCastToPtr_ToLocal(__generic const void *p, | ||
| int) __SPIRV_NOEXCEPT { | ||
| return (__local const void *)p; | ||
| } | ||
| static __SPIRV_overloadable __SPIRV_inline __local volatile void * | ||
| __spirv_GenericCastToPtr_ToLocal(__generic volatile void *p, | ||
| int) __SPIRV_NOEXCEPT { | ||
| return (__local volatile void *)p; | ||
| } | ||
| static __SPIRV_overloadable __SPIRV_inline __local const volatile void * | ||
| __spirv_GenericCastToPtr_ToLocal(__generic const volatile void *p, | ||
| int) __SPIRV_NOEXCEPT { | ||
| return (__local const volatile void *)p; | ||
| } | ||
| static __SPIRV_overloadable __SPIRV_inline __private void * | ||
| __spirv_GenericCastToPtr_ToPrivate(__generic void *p, int) __SPIRV_NOEXCEPT { | ||
| return (__private void *)p; | ||
| } | ||
| static __SPIRV_overloadable __SPIRV_inline __private const void * | ||
| __spirv_GenericCastToPtr_ToPrivate(__generic const void *p, | ||
| int) __SPIRV_NOEXCEPT { | ||
| return (__private const void *)p; | ||
| } | ||
| static __SPIRV_overloadable __SPIRV_inline __private volatile void * | ||
| __spirv_GenericCastToPtr_ToPrivate(__generic volatile void *p, | ||
| int) __SPIRV_NOEXCEPT { | ||
| return (__private volatile void *)p; | ||
| } | ||
| static __SPIRV_overloadable __SPIRV_inline __private const volatile void * | ||
| __spirv_GenericCastToPtr_ToPrivate(__generic const volatile void *p, | ||
| int) __SPIRV_NOEXCEPT { | ||
| return (__private const volatile void *)p; | ||
| } | ||
|
|
||
| #undef __SPIRV_overloadable | ||
| #undef __SPIRV_convergent | ||
| #undef __SPIRV_inline | ||
|
|
||
| #undef __global | ||
| #undef __local | ||
| #undef __constant | ||
| #undef __generic | ||
|
|
||
| #undef __SPIRV_BUILTIN_ALIAS | ||
| #undef __SPIRV_NOEXCEPT | ||
|
|
||
| #endif /* __SPIRV_BUILTIN_VARS_H */ |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ | |
| #include "clang/Sema/SemaOpenCL.h" | ||
| #include "clang/Sema/SemaOpenMP.h" | ||
| #include "clang/Sema/SemaRISCV.h" | ||
| #include "clang/Sema/SemaSPIRV.h" | ||
| #include "clang/Sema/SemaSYCL.h" | ||
| #include "clang/Sema/SemaSwift.h" | ||
| #include "clang/Sema/SemaWasm.h" | ||
|
|
@@ -5837,12 +5838,13 @@ static void handleBuiltinAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |
| bool IsAArch64 = S.Context.getTargetInfo().getTriple().isAArch64(); | ||
| bool IsARM = S.Context.getTargetInfo().getTriple().isARM(); | ||
| bool IsRISCV = S.Context.getTargetInfo().getTriple().isRISCV(); | ||
| bool IsSPIRV = S.Context.getTargetInfo().getTriple().isSPIRV(); | ||
| bool IsHLSL = S.Context.getLangOpts().HLSL; | ||
| if ((IsAArch64 && !S.ARM().SveAliasValid(BuiltinID, AliasName)) || | ||
| (IsARM && !S.ARM().MveAliasValid(BuiltinID, AliasName) && | ||
| !S.ARM().CdeAliasValid(BuiltinID, AliasName)) || | ||
| (IsRISCV && !S.RISCV().isAliasValid(BuiltinID, AliasName)) || | ||
| (!IsAArch64 && !IsARM && !IsRISCV && !IsHLSL)) { | ||
| (!IsAArch64 && !IsARM && !IsRISCV && !IsHLSL && !IsSPIRV)) { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not affecting HLSL in any way here. |
||
| S.Diag(AL.getLoc(), diag::err_attribute_builtin_alias) << AL; | ||
| return; | ||
| } | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.