Skip to content

Revert "[libspirv] Define schar overloads via remangling; not source … #18821

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions clang/lib/Sema/SPIRVBuiltins.td
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ class ConstOCLSPVBuiltin<string _Name, list<Type> _Signature> :
// OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
def Bool : IntType<"bool", QualType<"Context.BoolTy">, 1>;
def TrueChar : IntType<"_char", QualType<"Context.CharTy", 0, 1>, 8>;
def Char : IntType<"char", QualTypeFromFunction<"GetCharType", 0, 1>, 8>;
def Char : IntType<"char", QualType<"Context.SignedCharTy", 0, 1>, 8>;
def SChar : IntType<"schar", QualType<"Context.SignedCharTy", 0, 1>, 8>;
def UChar : UIntType<"uchar", QualType<"Context.UnsignedCharTy">, 8>;
def Short : IntType<"short", QualType<"Context.ShortTy", 0, 1>, 16>;
def UShort : UIntType<"ushort", QualType<"Context.UnsignedShortTy">, 16>;
Expand Down Expand Up @@ -411,7 +412,7 @@ def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats

// GenType definitions for every single base type (e.g. fp32 only).
// Names are like: GenTypeFloatVecAndScalar.
foreach Type = [Char, UChar, Short, UShort,
foreach Type = [Char, UChar, SChar, Short, UShort,
Int, UInt, Long, ULong,
Float, Double, Half] in {
foreach VecSizes = [VecAndScalar, VecNoScalar] in {
Expand Down Expand Up @@ -871,16 +872,16 @@ foreach name = ["Dot"] in {
}

foreach name = ["Any", "All"] in {
def : SPVBuiltin<name, [Bool, GenTypeCharVecNoScalar], Attr.Const>;
def : SPVBuiltin<name, [Bool, GenTypeSCharVecNoScalar], Attr.Const>;
}

foreach name = ["IsNan", "IsInf", "IsFinite", "IsNormal", "SignBitSet"] in {
def : SPVBuiltin<name, [Bool, Float], Attr.Const>;
def : SPVBuiltin<name, [Bool, Double], Attr.Const>;
def : SPVBuiltin<name, [Bool, Half], Attr.Const>;
def : SPVBuiltin<name, [GenTypeCharVecNoScalar, GenTypeFloatVecNoScalar], Attr.Const>;
def : SPVBuiltin<name, [GenTypeCharVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
def : SPVBuiltin<name, [GenTypeCharVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
def : SPVBuiltin<name, [GenTypeSCharVecNoScalar, GenTypeFloatVecNoScalar], Attr.Const>;
def : SPVBuiltin<name, [GenTypeSCharVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
def : SPVBuiltin<name, [GenTypeSCharVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
}

foreach name = ["LessOrGreater",
Expand All @@ -894,9 +895,9 @@ foreach name = ["LessOrGreater",
def : SPVBuiltin<name, [Bool, Float, Float], Attr.Const>;
def : SPVBuiltin<name, [Bool, Double, Double], Attr.Const>;
def : SPVBuiltin<name, [Bool, Half, Half], Attr.Const>;
def : SPVBuiltin<name, [GenTypeCharVecNoScalar, GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar], Attr.Const>;
def : SPVBuiltin<name, [GenTypeCharVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
def : SPVBuiltin<name, [GenTypeCharVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
def : SPVBuiltin<name, [GenTypeSCharVecNoScalar, GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar], Attr.Const>;
def : SPVBuiltin<name, [GenTypeSCharVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
def : SPVBuiltin<name, [GenTypeSCharVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
}

foreach name = ["BitCount"] in {
Expand Down
5 changes: 0 additions & 5 deletions clang/lib/Sema/SemaLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include <utility>
#include <vector>

static inline clang::QualType GetCharType(clang::ASTContext &Context);
static inline clang::QualType GetFloat16Type(clang::ASTContext &Context);

#include "OpenCLBuiltins.inc"
Expand Down Expand Up @@ -702,10 +701,6 @@ LLVM_DUMP_METHOD void LookupResult::dump() {
D->dump();
}

static inline QualType GetCharType(clang::ASTContext &Context) {
return Context.getLangOpts().OpenCL ? Context.CharTy : Context.SignedCharTy;
}

static inline QualType GetFloat16Type(clang::ASTContext &Context) {
return Context.getLangOpts().OpenCL ? Context.HalfTy : Context.Float16Ty;
}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CodeGenSPIRV/spirv-builtin-lookup-group.cl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool group_any(bool predicate) {

char group_broad_cast(char a) {
// CHECK-LABEL: @group_broad_cast(
// CHECK: call spir_func signext i8 @_Z22__spirv_GroupBroadcasticj(
// CHECK: call spir_func i32 @_Z22__spirv_GroupBroadcastiij(
return __spirv_GroupBroadcast(2, a, 0u);
}

Expand Down Expand Up @@ -87,7 +87,7 @@ unsigned long group_umax(unsigned long a) {

char group_smin(char a) {
// CHECK-LABEL: @group_smin(
// CHECK: call spir_func signext i8 @_Z17__spirv_GroupSMiniic(
// CHECK: call spir_func i32 @_Z17__spirv_GroupSMiniii(
return __spirv_GroupSMin(2, 0, a);
}

Expand Down
7 changes: 7 additions & 0 deletions libclc/clc/include/clc/clc_as_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define __CLC_CLC_AS_TYPE_H__

#define __clc_as_char(x) __builtin_astype(x, char)
#define __clc_as_schar(x) __builtin_astype(x, schar)
#define __clc_as_uchar(x) __builtin_astype(x, uchar)
#define __clc_as_short(x) __builtin_astype(x, short)
#define __clc_as_ushort(x) __builtin_astype(x, ushort)
Expand All @@ -20,6 +21,7 @@
#define __clc_as_float(x) __builtin_astype(x, float)

#define __clc_as_char2(x) __builtin_astype(x, char2)
#define __clc_as_schar2(x) __builtin_astype(x, schar2)
#define __clc_as_uchar2(x) __builtin_astype(x, uchar2)
#define __clc_as_short2(x) __builtin_astype(x, short2)
#define __clc_as_ushort2(x) __builtin_astype(x, ushort2)
Expand All @@ -30,6 +32,7 @@
#define __clc_as_float2(x) __builtin_astype(x, float2)

#define __clc_as_char3(x) __builtin_astype(x, char3)
#define __clc_as_schar3(x) __builtin_astype(x, schar3)
#define __clc_as_uchar3(x) __builtin_astype(x, uchar3)
#define __clc_as_short3(x) __builtin_astype(x, short3)
#define __clc_as_ushort3(x) __builtin_astype(x, ushort3)
Expand All @@ -40,6 +43,7 @@
#define __clc_as_float3(x) __builtin_astype(x, float3)

#define __clc_as_char4(x) __builtin_astype(x, char4)
#define __clc_as_schar4(x) __builtin_astype(x, schar4)
#define __clc_as_uchar4(x) __builtin_astype(x, uchar4)
#define __clc_as_short4(x) __builtin_astype(x, short4)
#define __clc_as_ushort4(x) __builtin_astype(x, ushort4)
Expand All @@ -50,7 +54,9 @@
#define __clc_as_float4(x) __builtin_astype(x, float4)

#define __clc_as_char8(x) __builtin_astype(x, char8)
#define __clc_as_schar8(x) __builtin_astype(x, schar8)
#define __clc_as_uchar8(x) __builtin_astype(x, uchar8)
#define __clc_as_schar8(x) __builtin_astype(x, schar8)
#define __clc_as_short8(x) __builtin_astype(x, short8)
#define __clc_as_ushort8(x) __builtin_astype(x, ushort8)
#define __clc_as_int8(x) __builtin_astype(x, int8)
Expand All @@ -60,6 +66,7 @@
#define __clc_as_float8(x) __builtin_astype(x, float8)

#define __clc_as_char16(x) __builtin_astype(x, char16)
#define __clc_as_schar16(x) __builtin_astype(x, schar16)
#define __clc_as_uchar16(x) __builtin_astype(x, uchar16)
#define __clc_as_short16(x) __builtin_astype(x, short16)
#define __clc_as_ushort16(x) __builtin_astype(x, ushort16)
Expand Down
2 changes: 2 additions & 0 deletions libclc/clc/include/clc/clc_convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#define _CLC_VECTOR_CONVERT_FROM1(FROM_TYPE, SUFFIX) \
_CLC_VECTOR_CONVERT_DECL(FROM_TYPE, char, SUFFIX) \
_CLC_VECTOR_CONVERT_DECL(FROM_TYPE, schar, SUFFIX) \
_CLC_VECTOR_CONVERT_DECL(FROM_TYPE, uchar, SUFFIX) \
_CLC_VECTOR_CONVERT_DECL(FROM_TYPE, int, SUFFIX) \
_CLC_VECTOR_CONVERT_DECL(FROM_TYPE, uint, SUFFIX) \
Expand Down Expand Up @@ -57,6 +58,7 @@

#define _CLC_VECTOR_CONVERT_TO1(SUFFIX) \
_CLC_VECTOR_CONVERT_FROM(char, SUFFIX) \
_CLC_VECTOR_CONVERT_FROM(schar, SUFFIX) \
_CLC_VECTOR_CONVERT_FROM(uchar, SUFFIX) \
_CLC_VECTOR_CONVERT_FROM(int, SUFFIX) \
_CLC_VECTOR_CONVERT_FROM(uint, SUFFIX) \
Expand Down
7 changes: 7 additions & 0 deletions libclc/clc/include/clc/clctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

/* 6.1.1 Built-in Scalar Data Types */

typedef signed char schar;
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
Expand Down Expand Up @@ -39,6 +40,12 @@ typedef __attribute__((ext_vector_type(4))) char char4;
typedef __attribute__((ext_vector_type(8))) char char8;
typedef __attribute__((ext_vector_type(16))) char char16;

typedef __attribute__((ext_vector_type(2))) schar schar2;
typedef __attribute__((ext_vector_type(3))) schar schar3;
typedef __attribute__((ext_vector_type(4))) schar schar4;
typedef __attribute__((ext_vector_type(8))) schar schar8;
typedef __attribute__((ext_vector_type(16))) schar schar16;

typedef __attribute__((ext_vector_type(2))) uchar uchar2;
typedef __attribute__((ext_vector_type(3))) uchar uchar3;
typedef __attribute__((ext_vector_type(4))) uchar uchar4;
Expand Down
Loading