Skip to content

Commit adb96b0

Browse files
[SYCL][libclc] Revert signed char remangling simplications (#4207) (#4348)
Remangler tool introduced with #4207 also included simplifications to the use of `signed char` in libclc. These simplifications changed the generated SPIRV builtins in a way that causes previously passing CTS tests to fail. This PR reverts the `signed char` simplifications, preserving the remangler and the `long` simplifications. Signed-off-by: Steffen Larsen <[email protected]>
1 parent 7f21853 commit adb96b0

File tree

36 files changed

+251
-51
lines changed

36 files changed

+251
-51
lines changed

clang/lib/Sema/SPIRVBuiltins.td

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,9 @@ class ConstOCLSPVBuiltin<string _Name, list<Type> _Signature> :
321321

322322
// OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
323323
def Bool : IntType<"bool", QualType<"Context.BoolTy">, 1>;
324-
def Char : IntType<"char", QualType<"Context.CharTy", 0, 1>, 8>;
325-
def SChar : IntType<"schar", QualType<"Context.SignedCharTy", 0, 1>, 8>;
324+
def TrueChar : IntType<"_char", QualType<"Context.CharTy", 0, 1>, 8>;
325+
def Char : IntType<"char", QualType<"Context.SignedCharTy", 0, 1>, 8>;
326+
def SChar : IntType<"schar", QualType<"Context.SignedCharTy", 0, 1>, 8>;
326327
def UChar : UIntType<"uchar", QualType<"Context.UnsignedCharTy">, 8>;
327328
def Short : IntType<"short", QualType<"Context.ShortTy", 0, 1>, 16>;
328329
def UShort : UIntType<"ushort", QualType<"Context.UnsignedShortTy">, 16>;
@@ -355,13 +356,15 @@ def Vec16 : IntList<"Vec16", [16]>;
355356
def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;
356357

357358
// Type lists.
358-
def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
359+
def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
359360
def TLAllUnsigned : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>;
360361
def TLFloat : TypeList<[Float, Double, Half]>;
362+
// FIXME: handle properly char (signed or unsigned depending on host)
361363
def TLSignedInts : TypeList<[Char, Short, Int, Long]>;
362364
def TLUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>;
363365

364366
// Signed to Unsigned conversion
367+
// FIXME: handle properly char (signed or unsigned depending on host)
365368
def TLSToUSignedInts : TypeList<[Char, Short, Int, Long]>;
366369
def TLSToUUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>;
367370

@@ -372,7 +375,7 @@ def TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>;
372375
// uchar abs(uchar).
373376
def TLAllUIntsTwice : TypeList<[UChar, UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
374377

375-
def TLAllInts : TypeList<[Char, SChar, UChar, Short, UShort, Int, UInt, Long, ULong]>;
378+
def TLAllInts : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
376379

377380
// GenType definitions for multiple base types (e.g. all floating point types,
378381
// or all integer types).
@@ -399,7 +402,7 @@ def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats
399402

400403
// GenType definitions for every single base type (e.g. fp32 only).
401404
// Names are like: GenTypeFloatVecAndScalar.
402-
foreach Type = [Char, SChar, UChar, Short, UShort,
405+
foreach Type = [Char, UChar, SChar, Short, UShort,
403406
Int, UInt, Long, ULong,
404407
Float, Double, Half] in {
405408
foreach VecSizes = [VecAndScalar, VecNoScalar] in {
@@ -554,7 +557,6 @@ foreach name = ["s_clamp", "s_mad_hi", "s_mad_sat"] in {
554557

555558
foreach name = ["s_upsample"] in {
556559
def : ConstOCLSPVBuiltin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar]>;
557-
def : ConstOCLSPVBuiltin<name, [GenTypeShortVecAndScalar, GenTypeSCharVecAndScalar, GenTypeUCharVecAndScalar]>;
558560
def : ConstOCLSPVBuiltin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar]>;
559561
def : ConstOCLSPVBuiltin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar]>;
560562
}
@@ -722,7 +724,7 @@ foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
722724

723725
let IsVariadic = 1 in {
724726
foreach name = ["printf"] in {
725-
def : OCLSPVBuiltin<name, [Int, PointerType<ConstType<Char>, ConstantAS>]>;
727+
def : OCLSPVBuiltin<name, [Int, PointerType<ConstType<TrueChar>, ConstantAS>]>;
726728
}
727729
}
728730

libclc/generic/gen_convert_common.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# This file contains common variables and helper functions used by the
22
# `gen_convert.py` in both the libclc and libspirv libraries.
33

4-
types = ['char', 'uchar', 'short', 'ushort', 'int', 'uint', 'long', 'ulong', 'half', 'float', 'double']
5-
int_types = ['char', 'uchar', 'short', 'ushort', 'int', 'uint', 'long', 'ulong']
4+
types = ['char', 'schar', 'uchar', 'short', 'ushort', 'int', 'uint', 'long', 'ulong', 'half', 'float', 'double']
5+
int_types = ['char', 'schar', 'uchar', 'short', 'ushort', 'int', 'uint', 'long', 'ulong']
66
unsigned_types = ['uchar', 'ushort', 'uint', 'ulong']
7-
signed_types = ['char', 'short', 'int', 'long']
7+
signed_types = ['char', 'schar', 'short', 'int', 'long']
88
float_types = ['half', 'float', 'double']
99
int64_types = ['long', 'ulong']
1010
float64_types = ['double']
@@ -18,7 +18,8 @@
1818
float_suffix = {'float':'f', 'double':''}
1919

2020
bool_type = {'char' : 'char',
21-
'uchar' : 'char',
21+
'schar' : 'schar',
22+
'uchar' : 'schar',
2223
'short' : 'short',
2324
'ushort' : 'short',
2425
'int' : 'int',
@@ -30,6 +31,7 @@
3031
'double' : 'long'}
3132

3233
unsigned_type = {'char' : 'uchar',
34+
'schar' : 'uchar',
3335
'uchar' : 'uchar',
3436
'short' : 'ushort',
3537
'ushort': 'ushort',
@@ -38,14 +40,15 @@
3840
'long' : 'ulong',
3941
'ulong' : 'ulong'}
4042

41-
sizeof_type = {'char' : 1, 'uchar' : 1,
43+
sizeof_type = {'char' : 1, 'schar' : 1, 'uchar' : 1,
4244
'short' : 2, 'ushort' : 2,
4345
'int' : 4, 'uint' : 4,
4446
'long' : 8, 'ulong' : 8,
4547
'half' : 2, 'float' : 4,
4648
'double': 8}
4749

4850
limit_max = {'char' : 'CHAR_MAX',
51+
'schar' : 'CHAR_MAX',
4952
'uchar' : 'UCHAR_MAX',
5053
'short' : 'SHRT_MAX',
5154
'ushort': 'USHRT_MAX',
@@ -55,6 +58,7 @@
5558
'ulong' : 'ULONG_MAX'}
5659

5760
limit_min = {'char' : 'CHAR_MIN',
61+
'schar' : 'CHAR_MIN',
5862
'uchar' : '0',
5963
'short' : 'SHRT_MIN',
6064
'ushort': '0',

libclc/generic/include/as_type.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define CLC_AS_TYPE
33

44
#define as_char(x) __builtin_astype(x, char)
5+
#define as_schar(x) __builtin_astype(x, schar)
56
#define as_uchar(x) __builtin_astype(x, uchar)
67
#define as_short(x) __builtin_astype(x, short)
78
#define as_ushort(x) __builtin_astype(x, ushort)
@@ -12,6 +13,7 @@
1213
#define as_float(x) __builtin_astype(x, float)
1314

1415
#define as_char2(x) __builtin_astype(x, char2)
16+
#define as_schar2(x) __builtin_astype(x, schar2)
1517
#define as_uchar2(x) __builtin_astype(x, uchar2)
1618
#define as_short2(x) __builtin_astype(x, short2)
1719
#define as_ushort2(x) __builtin_astype(x, ushort2)
@@ -22,6 +24,7 @@
2224
#define as_float2(x) __builtin_astype(x, float2)
2325

2426
#define as_char3(x) __builtin_astype(x, char3)
27+
#define as_schar3(x) __builtin_astype(x, schar3)
2528
#define as_uchar3(x) __builtin_astype(x, uchar3)
2629
#define as_short3(x) __builtin_astype(x, short3)
2730
#define as_ushort3(x) __builtin_astype(x, ushort3)
@@ -32,6 +35,7 @@
3235
#define as_float3(x) __builtin_astype(x, float3)
3336

3437
#define as_char4(x) __builtin_astype(x, char4)
38+
#define as_schar4(x) __builtin_astype(x, schar4)
3539
#define as_uchar4(x) __builtin_astype(x, uchar4)
3640
#define as_short4(x) __builtin_astype(x, short4)
3741
#define as_ushort4(x) __builtin_astype(x, ushort4)
@@ -42,6 +46,7 @@
4246
#define as_float4(x) __builtin_astype(x, float4)
4347

4448
#define as_char8(x) __builtin_astype(x, char8)
49+
#define as_schar8(x) __builtin_astype(x, schar8)
4550
#define as_uchar8(x) __builtin_astype(x, uchar8)
4651
#define as_short8(x) __builtin_astype(x, short8)
4752
#define as_ushort8(x) __builtin_astype(x, ushort8)
@@ -52,6 +57,7 @@
5257
#define as_float8(x) __builtin_astype(x, float8)
5358

5459
#define as_char16(x) __builtin_astype(x, char16)
60+
#define as_schar16(x) __builtin_astype(x, schar16)
5561
#define as_uchar16(x) __builtin_astype(x, uchar16)
5662
#define as_short16(x) __builtin_astype(x, short16)
5763
#define as_ushort16(x) __builtin_astype(x, ushort16)

libclc/generic/include/clc/async/gentype.inc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,46 @@
3939
#undef __CLC_GENTYPE_MANGLED
4040
#undef __CLC_GENTYPE
4141

42+
#ifndef __CLC_NO_SCHAR
43+
#define __CLC_GENTYPE schar
44+
#define __CLC_GENTYPE_MANGLED a
45+
#include __CLC_BODY
46+
#undef __CLC_GENTYPE_MANGLED
47+
#undef __CLC_GENTYPE
48+
49+
#define __CLC_GENTYPE schar2
50+
#define __CLC_GENTYPE_MANGLED Dv2_a
51+
#include __CLC_BODY
52+
#undef __CLC_GENTYPE_MANGLED
53+
#undef __CLC_GENTYPE
54+
55+
#ifdef __CLC_GEN_VEC3
56+
#define __CLC_GENTYPE schar3
57+
#define __CLC_GENTYPE_MANGLED Dv3_a
58+
#include __CLC_BODY
59+
#undef __CLC_GENTYPE_MANGLED
60+
#undef __CLC_GENTYPE
61+
#endif
62+
63+
#define __CLC_GENTYPE schar4
64+
#define __CLC_GENTYPE_MANGLED Dv4_a
65+
#include __CLC_BODY
66+
#undef __CLC_GENTYPE_MANGLED
67+
#undef __CLC_GENTYPE
68+
69+
#define __CLC_GENTYPE schar8
70+
#define __CLC_GENTYPE_MANGLED Dv8_a
71+
#include __CLC_BODY
72+
#undef __CLC_GENTYPE_MANGLED
73+
#undef __CLC_GENTYPE
74+
75+
#define __CLC_GENTYPE schar16
76+
#define __CLC_GENTYPE_MANGLED Dv16_a
77+
#include __CLC_BODY
78+
#undef __CLC_GENTYPE_MANGLED
79+
#undef __CLC_GENTYPE
80+
#endif
81+
4282
#define __CLC_GENTYPE uchar
4383
#define __CLC_GENTYPE_MANGLED h
4484
#include __CLC_BODY

libclc/generic/include/clc/clc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
1313
#endif
1414

15+
#define __CLC_NO_SCHAR
16+
1517
/* Function Attributes */
1618
#include <func.h>
1719

0 commit comments

Comments
 (0)