Skip to content

Commit 23584c1

Browse files
authored
[libspirv] Define schar overloads via remangling; not source (#18626)
We were previously achieving the signed char builtin definitions in libspirv via one of two ways. The first was explicitly definining schar overloads of builtins in the source. The second was by remangling 'char' builtins to one of schar or uchar, depending on the host platform. Since we are defining our builtins in OpenCL C, the plain 'char' type is already a signed type. This presents us with the opportunity to achieve our desired schar builtins solely through remangling. The primary idea is to reduce our libclc/libspirv diff with upstream. We also have the option to introduce signed char builtins upstream. As it stands the schar problem isn't far from the 'half' mangling problem that we also now deal with purely in the remangler.
1 parent 73ff319 commit 23584c1

File tree

43 files changed

+89
-430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+89
-430
lines changed

clang/lib/Sema/SPIRVBuiltins.td

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ class ConstOCLSPVBuiltin<string _Name, list<Type> _Signature> :
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>;
324324
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>;
325+
def Char : IntType<"char", QualTypeFromFunction<"GetCharType", 0, 1>, 8>;
327326
def UChar : UIntType<"uchar", QualType<"Context.UnsignedCharTy">, 8>;
328327
def Short : IntType<"short", QualType<"Context.ShortTy", 0, 1>, 16>;
329328
def UShort : UIntType<"ushort", QualType<"Context.UnsignedShortTy">, 16>;
@@ -412,7 +411,7 @@ def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats
412411

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

874873
foreach name = ["Any", "All"] in {
875-
def : SPVBuiltin<name, [Bool, GenTypeSCharVecNoScalar], Attr.Const>;
874+
def : SPVBuiltin<name, [Bool, GenTypeCharVecNoScalar], Attr.Const>;
876875
}
877876

878877
foreach name = ["IsNan", "IsInf", "IsFinite", "IsNormal", "SignBitSet"] in {
879878
def : SPVBuiltin<name, [Bool, Float], Attr.Const>;
880879
def : SPVBuiltin<name, [Bool, Double], Attr.Const>;
881880
def : SPVBuiltin<name, [Bool, Half], Attr.Const>;
882-
def : SPVBuiltin<name, [GenTypeSCharVecNoScalar, GenTypeFloatVecNoScalar], Attr.Const>;
883-
def : SPVBuiltin<name, [GenTypeSCharVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
884-
def : SPVBuiltin<name, [GenTypeSCharVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
881+
def : SPVBuiltin<name, [GenTypeCharVecNoScalar, GenTypeFloatVecNoScalar], Attr.Const>;
882+
def : SPVBuiltin<name, [GenTypeCharVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
883+
def : SPVBuiltin<name, [GenTypeCharVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
885884
}
886885

887886
foreach name = ["LessOrGreater",
@@ -895,9 +894,9 @@ foreach name = ["LessOrGreater",
895894
def : SPVBuiltin<name, [Bool, Float, Float], Attr.Const>;
896895
def : SPVBuiltin<name, [Bool, Double, Double], Attr.Const>;
897896
def : SPVBuiltin<name, [Bool, Half, Half], Attr.Const>;
898-
def : SPVBuiltin<name, [GenTypeSCharVecNoScalar, GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar], Attr.Const>;
899-
def : SPVBuiltin<name, [GenTypeSCharVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
900-
def : SPVBuiltin<name, [GenTypeSCharVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
897+
def : SPVBuiltin<name, [GenTypeCharVecNoScalar, GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar], Attr.Const>;
898+
def : SPVBuiltin<name, [GenTypeCharVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
899+
def : SPVBuiltin<name, [GenTypeCharVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
901900
}
902901

903902
foreach name = ["BitCount"] in {

clang/lib/Sema/SemaLookup.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <utility>
5252
#include <vector>
5353

54+
static inline clang::QualType GetCharType(clang::ASTContext &Context);
5455
static inline clang::QualType GetFloat16Type(clang::ASTContext &Context);
5556

5657
#include "OpenCLBuiltins.inc"
@@ -701,6 +702,10 @@ LLVM_DUMP_METHOD void LookupResult::dump() {
701702
D->dump();
702703
}
703704

705+
static inline QualType GetCharType(clang::ASTContext &Context) {
706+
return Context.getLangOpts().OpenCL ? Context.CharTy : Context.SignedCharTy;
707+
}
708+
704709
static inline QualType GetFloat16Type(clang::ASTContext &Context) {
705710
return Context.getLangOpts().OpenCL ? Context.HalfTy : Context.Float16Ty;
706711
}

clang/test/CodeGenSPIRV/spirv-builtin-lookup-group.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bool group_any(bool predicate) {
2727

2828
char group_broad_cast(char a) {
2929
// CHECK-LABEL: @group_broad_cast(
30-
// CHECK: call spir_func i32 @_Z22__spirv_GroupBroadcastiij(
30+
// CHECK: call spir_func signext i8 @_Z22__spirv_GroupBroadcasticj(
3131
return __spirv_GroupBroadcast(2, a, 0u);
3232
}
3333

@@ -87,7 +87,7 @@ unsigned long group_umax(unsigned long a) {
8787

8888
char group_smin(char a) {
8989
// CHECK-LABEL: @group_smin(
90-
// CHECK: call spir_func i32 @_Z17__spirv_GroupSMiniii(
90+
// CHECK: call spir_func signext i8 @_Z17__spirv_GroupSMiniic(
9191
return __spirv_GroupSMin(2, 0, a);
9292
}
9393

libclc/clc/include/clc/clc_as_type.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define __CLC_CLC_AS_TYPE_H__
1111

1212
#define __clc_as_char(x) __builtin_astype(x, char)
13-
#define __clc_as_schar(x) __builtin_astype(x, schar)
1413
#define __clc_as_uchar(x) __builtin_astype(x, uchar)
1514
#define __clc_as_short(x) __builtin_astype(x, short)
1615
#define __clc_as_ushort(x) __builtin_astype(x, ushort)
@@ -21,7 +20,6 @@
2120
#define __clc_as_float(x) __builtin_astype(x, float)
2221

2322
#define __clc_as_char2(x) __builtin_astype(x, char2)
24-
#define __clc_as_schar2(x) __builtin_astype(x, schar2)
2523
#define __clc_as_uchar2(x) __builtin_astype(x, uchar2)
2624
#define __clc_as_short2(x) __builtin_astype(x, short2)
2725
#define __clc_as_ushort2(x) __builtin_astype(x, ushort2)
@@ -32,7 +30,6 @@
3230
#define __clc_as_float2(x) __builtin_astype(x, float2)
3331

3432
#define __clc_as_char3(x) __builtin_astype(x, char3)
35-
#define __clc_as_schar3(x) __builtin_astype(x, schar3)
3633
#define __clc_as_uchar3(x) __builtin_astype(x, uchar3)
3734
#define __clc_as_short3(x) __builtin_astype(x, short3)
3835
#define __clc_as_ushort3(x) __builtin_astype(x, ushort3)
@@ -43,7 +40,6 @@
4340
#define __clc_as_float3(x) __builtin_astype(x, float3)
4441

4542
#define __clc_as_char4(x) __builtin_astype(x, char4)
46-
#define __clc_as_schar4(x) __builtin_astype(x, schar4)
4743
#define __clc_as_uchar4(x) __builtin_astype(x, uchar4)
4844
#define __clc_as_short4(x) __builtin_astype(x, short4)
4945
#define __clc_as_ushort4(x) __builtin_astype(x, ushort4)
@@ -54,9 +50,7 @@
5450
#define __clc_as_float4(x) __builtin_astype(x, float4)
5551

5652
#define __clc_as_char8(x) __builtin_astype(x, char8)
57-
#define __clc_as_schar8(x) __builtin_astype(x, schar8)
5853
#define __clc_as_uchar8(x) __builtin_astype(x, uchar8)
59-
#define __clc_as_schar8(x) __builtin_astype(x, schar8)
6054
#define __clc_as_short8(x) __builtin_astype(x, short8)
6155
#define __clc_as_ushort8(x) __builtin_astype(x, ushort8)
6256
#define __clc_as_int8(x) __builtin_astype(x, int8)
@@ -66,7 +60,6 @@
6660
#define __clc_as_float8(x) __builtin_astype(x, float8)
6761

6862
#define __clc_as_char16(x) __builtin_astype(x, char16)
69-
#define __clc_as_schar16(x) __builtin_astype(x, schar16)
7063
#define __clc_as_uchar16(x) __builtin_astype(x, uchar16)
7164
#define __clc_as_short16(x) __builtin_astype(x, short16)
7265
#define __clc_as_ushort16(x) __builtin_astype(x, ushort16)

libclc/clc/include/clc/clc_convert.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#define _CLC_VECTOR_CONVERT_FROM1(FROM_TYPE, SUFFIX) \
2626
_CLC_VECTOR_CONVERT_DECL(FROM_TYPE, char, SUFFIX) \
27-
_CLC_VECTOR_CONVERT_DECL(FROM_TYPE, schar, SUFFIX) \
2827
_CLC_VECTOR_CONVERT_DECL(FROM_TYPE, uchar, SUFFIX) \
2928
_CLC_VECTOR_CONVERT_DECL(FROM_TYPE, int, SUFFIX) \
3029
_CLC_VECTOR_CONVERT_DECL(FROM_TYPE, uint, SUFFIX) \
@@ -58,7 +57,6 @@
5857

5958
#define _CLC_VECTOR_CONVERT_TO1(SUFFIX) \
6059
_CLC_VECTOR_CONVERT_FROM(char, SUFFIX) \
61-
_CLC_VECTOR_CONVERT_FROM(schar, SUFFIX) \
6260
_CLC_VECTOR_CONVERT_FROM(uchar, SUFFIX) \
6361
_CLC_VECTOR_CONVERT_FROM(int, SUFFIX) \
6462
_CLC_VECTOR_CONVERT_FROM(uint, SUFFIX) \

libclc/clc/include/clc/clctypes.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
/* 6.1.1 Built-in Scalar Data Types */
1313

14-
typedef signed char schar;
1514
typedef unsigned char uchar;
1615
typedef unsigned short ushort;
1716
typedef unsigned int uint;
@@ -40,12 +39,6 @@ typedef __attribute__((ext_vector_type(4))) char char4;
4039
typedef __attribute__((ext_vector_type(8))) char char8;
4140
typedef __attribute__((ext_vector_type(16))) char char16;
4241

43-
typedef __attribute__((ext_vector_type(2))) schar schar2;
44-
typedef __attribute__((ext_vector_type(3))) schar schar3;
45-
typedef __attribute__((ext_vector_type(4))) schar schar4;
46-
typedef __attribute__((ext_vector_type(8))) schar schar8;
47-
typedef __attribute__((ext_vector_type(16))) schar schar16;
48-
4942
typedef __attribute__((ext_vector_type(2))) uchar uchar2;
5043
typedef __attribute__((ext_vector_type(3))) uchar uchar3;
5144
typedef __attribute__((ext_vector_type(4))) uchar uchar4;

0 commit comments

Comments
 (0)