Skip to content

[SYCL][libclc] Revert signed char remangling simplications (#4207) #4348

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
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
16 changes: 9 additions & 7 deletions clang/lib/Sema/SPIRVBuiltins.td
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ 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 Char : IntType<"char", QualType<"Context.CharTy", 0, 1>, 8>;
def SChar : IntType<"schar", QualType<"Context.SignedCharTy", 0, 1>, 8>;
def TrueChar : IntType<"_char", QualType<"Context.CharTy", 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 @@ -355,13 +356,15 @@ def Vec16 : IntList<"Vec16", [16]>;
def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;

// Type lists.
def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
def TLAllUnsigned : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>;
def TLFloat : TypeList<[Float, Double, Half]>;
// FIXME: handle properly char (signed or unsigned depending on host)
def TLSignedInts : TypeList<[Char, Short, Int, Long]>;
def TLUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>;

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

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

def TLAllInts : TypeList<[Char, SChar, UChar, Short, UShort, Int, UInt, Long, ULong]>;
def TLAllInts : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;

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

// GenType definitions for every single base type (e.g. fp32 only).
// Names are like: GenTypeFloatVecAndScalar.
foreach Type = [Char, SChar, 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 @@ -554,7 +557,6 @@ foreach name = ["s_clamp", "s_mad_hi", "s_mad_sat"] in {

foreach name = ["s_upsample"] in {
def : ConstOCLSPVBuiltin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar]>;
def : ConstOCLSPVBuiltin<name, [GenTypeShortVecAndScalar, GenTypeSCharVecAndScalar, GenTypeUCharVecAndScalar]>;
def : ConstOCLSPVBuiltin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar]>;
def : ConstOCLSPVBuiltin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar]>;
}
Expand Down Expand Up @@ -722,7 +724,7 @@ foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {

let IsVariadic = 1 in {
foreach name = ["printf"] in {
def : OCLSPVBuiltin<name, [Int, PointerType<ConstType<Char>, ConstantAS>]>;
def : OCLSPVBuiltin<name, [Int, PointerType<ConstType<TrueChar>, ConstantAS>]>;
}
}

Expand Down
14 changes: 9 additions & 5 deletions libclc/generic/gen_convert_common.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# This file contains common variables and helper functions used by the
# `gen_convert.py` in both the libclc and libspirv libraries.

types = ['char', 'uchar', 'short', 'ushort', 'int', 'uint', 'long', 'ulong', 'half', 'float', 'double']
int_types = ['char', 'uchar', 'short', 'ushort', 'int', 'uint', 'long', 'ulong']
types = ['char', 'schar', 'uchar', 'short', 'ushort', 'int', 'uint', 'long', 'ulong', 'half', 'float', 'double']
int_types = ['char', 'schar', 'uchar', 'short', 'ushort', 'int', 'uint', 'long', 'ulong']
unsigned_types = ['uchar', 'ushort', 'uint', 'ulong']
signed_types = ['char', 'short', 'int', 'long']
signed_types = ['char', 'schar', 'short', 'int', 'long']
float_types = ['half', 'float', 'double']
int64_types = ['long', 'ulong']
float64_types = ['double']
Expand All @@ -18,7 +18,8 @@
float_suffix = {'float':'f', 'double':''}

bool_type = {'char' : 'char',
'uchar' : 'char',
'schar' : 'schar',
'uchar' : 'schar',
'short' : 'short',
'ushort' : 'short',
'int' : 'int',
Expand All @@ -30,6 +31,7 @@
'double' : 'long'}

unsigned_type = {'char' : 'uchar',
'schar' : 'uchar',
'uchar' : 'uchar',
'short' : 'ushort',
'ushort': 'ushort',
Expand All @@ -38,14 +40,15 @@
'long' : 'ulong',
'ulong' : 'ulong'}

sizeof_type = {'char' : 1, 'uchar' : 1,
sizeof_type = {'char' : 1, 'schar' : 1, 'uchar' : 1,
'short' : 2, 'ushort' : 2,
'int' : 4, 'uint' : 4,
'long' : 8, 'ulong' : 8,
'half' : 2, 'float' : 4,
'double': 8}

limit_max = {'char' : 'CHAR_MAX',
'schar' : 'CHAR_MAX',
'uchar' : 'UCHAR_MAX',
'short' : 'SHRT_MAX',
'ushort': 'USHRT_MAX',
Expand All @@ -55,6 +58,7 @@
'ulong' : 'ULONG_MAX'}

limit_min = {'char' : 'CHAR_MIN',
'schar' : 'CHAR_MIN',
'uchar' : '0',
'short' : 'SHRT_MIN',
'ushort': '0',
Expand Down
6 changes: 6 additions & 0 deletions libclc/generic/include/as_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define CLC_AS_TYPE

#define as_char(x) __builtin_astype(x, char)
#define as_schar(x) __builtin_astype(x, schar)
#define as_uchar(x) __builtin_astype(x, uchar)
#define as_short(x) __builtin_astype(x, short)
#define as_ushort(x) __builtin_astype(x, ushort)
Expand All @@ -12,6 +13,7 @@
#define as_float(x) __builtin_astype(x, float)

#define as_char2(x) __builtin_astype(x, char2)
#define as_schar2(x) __builtin_astype(x, schar2)
#define as_uchar2(x) __builtin_astype(x, uchar2)
#define as_short2(x) __builtin_astype(x, short2)
#define as_ushort2(x) __builtin_astype(x, ushort2)
Expand All @@ -22,6 +24,7 @@
#define as_float2(x) __builtin_astype(x, float2)

#define as_char3(x) __builtin_astype(x, char3)
#define as_schar3(x) __builtin_astype(x, schar3)
#define as_uchar3(x) __builtin_astype(x, uchar3)
#define as_short3(x) __builtin_astype(x, short3)
#define as_ushort3(x) __builtin_astype(x, ushort3)
Expand All @@ -32,6 +35,7 @@
#define as_float3(x) __builtin_astype(x, float3)

#define as_char4(x) __builtin_astype(x, char4)
#define as_schar4(x) __builtin_astype(x, schar4)
#define as_uchar4(x) __builtin_astype(x, uchar4)
#define as_short4(x) __builtin_astype(x, short4)
#define as_ushort4(x) __builtin_astype(x, ushort4)
Expand All @@ -42,6 +46,7 @@
#define as_float4(x) __builtin_astype(x, float4)

#define as_char8(x) __builtin_astype(x, char8)
#define as_schar8(x) __builtin_astype(x, schar8)
#define as_uchar8(x) __builtin_astype(x, uchar8)
#define as_short8(x) __builtin_astype(x, short8)
#define as_ushort8(x) __builtin_astype(x, ushort8)
Expand All @@ -52,6 +57,7 @@
#define as_float8(x) __builtin_astype(x, float8)

#define as_char16(x) __builtin_astype(x, char16)
#define as_schar16(x) __builtin_astype(x, schar16)
#define as_uchar16(x) __builtin_astype(x, uchar16)
#define as_short16(x) __builtin_astype(x, short16)
#define as_ushort16(x) __builtin_astype(x, ushort16)
Expand Down
40 changes: 40 additions & 0 deletions libclc/generic/include/clc/async/gentype.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,46 @@
#undef __CLC_GENTYPE_MANGLED
#undef __CLC_GENTYPE

#ifndef __CLC_NO_SCHAR
#define __CLC_GENTYPE schar
#define __CLC_GENTYPE_MANGLED a
#include __CLC_BODY
#undef __CLC_GENTYPE_MANGLED
#undef __CLC_GENTYPE

#define __CLC_GENTYPE schar2
#define __CLC_GENTYPE_MANGLED Dv2_a
#include __CLC_BODY
#undef __CLC_GENTYPE_MANGLED
#undef __CLC_GENTYPE

#ifdef __CLC_GEN_VEC3
#define __CLC_GENTYPE schar3
#define __CLC_GENTYPE_MANGLED Dv3_a
#include __CLC_BODY
#undef __CLC_GENTYPE_MANGLED
#undef __CLC_GENTYPE
#endif

#define __CLC_GENTYPE schar4
#define __CLC_GENTYPE_MANGLED Dv4_a
#include __CLC_BODY
#undef __CLC_GENTYPE_MANGLED
#undef __CLC_GENTYPE

#define __CLC_GENTYPE schar8
#define __CLC_GENTYPE_MANGLED Dv8_a
#include __CLC_BODY
#undef __CLC_GENTYPE_MANGLED
#undef __CLC_GENTYPE

#define __CLC_GENTYPE schar16
#define __CLC_GENTYPE_MANGLED Dv16_a
#include __CLC_BODY
#undef __CLC_GENTYPE_MANGLED
#undef __CLC_GENTYPE
#endif

#define __CLC_GENTYPE uchar
#define __CLC_GENTYPE_MANGLED h
#include __CLC_BODY
Expand Down
2 changes: 2 additions & 0 deletions libclc/generic/include/clc/clc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
#endif

#define __CLC_NO_SCHAR

/* Function Attributes */
#include <func.h>

Expand Down
Loading