Skip to content

Commit 03919ef

Browse files
authored
[Clang][OpenCL] Declare cl_amd_media_ops/cl_amd_media_ops2 builtins with -fdeclare-opencl-builtins (#143507)
cl_amd_media_ops/cl_amd_media_ops2 builtins are currently not declared with -fdeclare-opencl-builtins. This patch adds support for these builtins.
1 parent 4db8ce7 commit 03919ef

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed

clang/lib/Sema/OpenCLBuiltins.td

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ def ArmIntegerDotProductAccumulateInt8 : FunctionExtension<"cl_arm_integ
139139
def ArmIntegerDotProductAccumulateInt16 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int16">;
140140
def ArmIntegerDotProductAccumulateSaturateInt8 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_saturate_int8">;
141141

142+
// AMD extensions.
143+
def AMDMediaOps : FunctionExtension<"cl_amd_media_ops">;
144+
def AMDMediaOps2 : FunctionExtension<"cl_amd_media_ops2">;
145+
142146
// Qualified Type. These map to ASTContext::QualType.
143147
class QualType<string _TypeExpr, bit _IsAbstract=0> {
144148
// Expression to obtain the QualType inside OCL2Qual.
@@ -1904,3 +1908,31 @@ let Extension = ArmIntegerDotProductAccumulateSaturateInt8 in {
19041908
def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>;
19051909
}
19061910
}
1911+
1912+
//--------------------------------------------------------------------
1913+
// AMD extensions.
1914+
let Extension = AMDMediaOps in {
1915+
foreach name = ["amd_bitalign", "amd_bytealign", "amd_lerp", "amd_sadhi", "amd_sad"] in {
1916+
def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar]>;
1917+
}
1918+
foreach name = ["amd_unpack0", "amd_unpack1", "amd_unpack2", "amd_unpack3"] in {
1919+
def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar]>;
1920+
}
1921+
def : Builtin<"amd_pack", [UInt, VectorType<Float, 4>]>;
1922+
def : Builtin<"amd_sad4", [UInt, VectorType<UInt, 4>, VectorType<UInt, 4>, UInt]>;
1923+
}
1924+
1925+
let Extension = AMDMediaOps2 in {
1926+
def : Builtin<"amd_bfe", [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar]>;
1927+
foreach name = ["amd_bfe", "amd_msad", "amd_sadd", "amd_sadw"] in {
1928+
def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar]>;
1929+
}
1930+
def : Builtin<"amd_bfm", [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar]>;
1931+
foreach name = ["amd_max3", "amd_median3", "amd_min3"] in {
1932+
foreach gentype = [GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar] in {
1933+
def : Builtin<name, [gentype, gentype, gentype, gentype]>;
1934+
}
1935+
}
1936+
def : Builtin<"amd_mqsad", [GenTypeULongVecAndScalar, GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeULongVecAndScalar]>;
1937+
def : Builtin<"amd_qsad", [GenTypeULongVecAndScalar, GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeULongVecAndScalar]>;
1938+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// RUN: %clang_cc1 %s -triple amdgcn-unknown-unknown -cl-ext=-all,+cl_amd_media_ops,+cl_amd_media_ops2 -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -finclude-default-header
2+
// RUN: %clang_cc1 %s -triple amdgcn-unknown-unknown -cl-ext=-all,+cl_amd_media_ops,+cl_amd_media_ops2 -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -finclude-default-header -fdeclare-opencl-builtins
3+
// expected-no-diagnostics
4+
// RUN: %clang_cc1 %s -triple amdgcn-unknown-unknown -cl-ext=-all,+cl_amd_media_ops2 -verify=ops -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -finclude-default-header
5+
// RUN: %clang_cc1 %s -triple amdgcn-unknown-unknown -cl-ext=-all,+cl_amd_media_ops -verify=ops2 -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -finclude-default-header
6+
// RUN: %clang_cc1 %s -triple amdgcn-unknown-unknown -cl-ext=-all,+cl_amd_media_ops2 -verify=ops -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -finclude-default-header -fdeclare-opencl-builtins
7+
// RUN: %clang_cc1 %s -triple amdgcn-unknown-unknown -cl-ext=-all,+cl_amd_media_ops -verify=ops2 -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL -finclude-default-header -fdeclare-opencl-builtins
8+
9+
#define TEST_1ARG_BUILTIN_WITH_TYPE(builtin, ret, type) \
10+
ret test_ ## builtin ## _ ## ret ## _## type (type a) { \
11+
return builtin(a); \
12+
}
13+
14+
#define TEST_2ARG_BUILTIN_WITH_TYPE(builtin, ret, type) \
15+
ret test_ ## builtin ## _ ## ret ## _## type (type a, type b) { \
16+
return builtin(a, b); \
17+
}
18+
19+
#define TEST_3ARG_BUILTIN_WITH_TYPE(builtin, ret, type) \
20+
ret test_ ## builtin ## _ ## ret ## _ ## type (type a, type b, type c) { \
21+
return builtin(a, b, c); \
22+
}
23+
24+
#define TEST_1ARG_BUILTIN(builtin, ret, type) \
25+
TEST_1ARG_BUILTIN_WITH_TYPE(builtin, ret, type) \
26+
TEST_1ARG_BUILTIN_WITH_TYPE(builtin, ret ## 2, type ## 2) \
27+
TEST_1ARG_BUILTIN_WITH_TYPE(builtin, ret ## 3, type ## 3) \
28+
TEST_1ARG_BUILTIN_WITH_TYPE(builtin, ret ## 4, type ## 4) \
29+
TEST_1ARG_BUILTIN_WITH_TYPE(builtin, ret ## 8, type ## 8) \
30+
TEST_1ARG_BUILTIN_WITH_TYPE(builtin, ret ## 16, type ## 16)
31+
32+
#define TEST_2ARG_BUILTIN(builtin, ret, type) \
33+
TEST_2ARG_BUILTIN_WITH_TYPE(builtin, ret, type) \
34+
TEST_2ARG_BUILTIN_WITH_TYPE(builtin, ret ## 2, type ## 2) \
35+
TEST_2ARG_BUILTIN_WITH_TYPE(builtin, ret ## 3, type ## 3) \
36+
TEST_2ARG_BUILTIN_WITH_TYPE(builtin, ret ## 4, type ## 4) \
37+
TEST_2ARG_BUILTIN_WITH_TYPE(builtin, ret ## 8, type ## 8) \
38+
TEST_2ARG_BUILTIN_WITH_TYPE(builtin, ret ## 16, type ## 16)
39+
40+
#define TEST_3ARG_BUILTIN(builtin, ret, type) \
41+
TEST_3ARG_BUILTIN_WITH_TYPE(builtin, ret, type) \
42+
TEST_3ARG_BUILTIN_WITH_TYPE(builtin, ret ## 2, type ## 2) \
43+
TEST_3ARG_BUILTIN_WITH_TYPE(builtin, ret ## 3, type ## 3) \
44+
TEST_3ARG_BUILTIN_WITH_TYPE(builtin, ret ## 4, type ## 4) \
45+
TEST_3ARG_BUILTIN_WITH_TYPE(builtin, ret ## 8, type ## 8) \
46+
TEST_3ARG_BUILTIN_WITH_TYPE(builtin, ret ## 16, type ## 16)
47+
48+
#define TEST_3ARG_BUILTIN_WITH_TYPES(builtin, ret, type_a, type_b, type_c) \
49+
ret test_ ## builtin ## _ ## ret ## _ ## type_a ## _ ## type_b ## _ ## type_c (type_a a, type_b b, type_c c) { \
50+
return builtin(a, b, c); \
51+
}
52+
53+
#define TEST_3ARG_WITH_TYPES_BUILTIN(builtin, ret, type_a, type_b, type_c) \
54+
TEST_3ARG_BUILTIN_WITH_TYPES(builtin, ret, type_a, type_b, type_c) \
55+
TEST_3ARG_BUILTIN_WITH_TYPES(builtin, ret ## 2, type_a ## 2, type_b ## 2, type_c ## 2) \
56+
TEST_3ARG_BUILTIN_WITH_TYPES(builtin, ret ## 3, type_a ## 3, type_b ## 3, type_c ## 3) \
57+
TEST_3ARG_BUILTIN_WITH_TYPES(builtin, ret ## 4, type_a ## 4, type_b ## 4, type_c ## 4) \
58+
TEST_3ARG_BUILTIN_WITH_TYPES(builtin, ret ## 8, type_a ## 8, type_b ## 8, type_c ## 8) \
59+
TEST_3ARG_BUILTIN_WITH_TYPES(builtin, ret ## 16, type_a ## 16, type_b ## 16, type_c ## 16)
60+
61+
TEST_3ARG_BUILTIN(amd_bitalign, uint, uint) // ops-error 6 {{use of undeclared identifier}}
62+
TEST_3ARG_BUILTIN(amd_bytealign, uint, uint) // ops-error 6 {{use of undeclared identifier}}
63+
TEST_3ARG_BUILTIN(amd_lerp, uint, uint) // ops-error 6 {{use of undeclared identifier}}
64+
65+
uint test_amd_pack(float4 a) {
66+
return amd_pack(a); // ops-error{{use of undeclared identifier}}
67+
}
68+
69+
uint test_amd_sad4(uint4 a, uint4 b, uint c) {
70+
return amd_sad4(a, b, c); // ops-error{{use of undeclared identifier}}
71+
}
72+
73+
TEST_3ARG_BUILTIN(amd_sadhi, uint, uint)// ops-error 6 {{use of undeclared identifier}}
74+
TEST_3ARG_BUILTIN(amd_sad, uint, uint) // ops-error 6 {{use of undeclared identifier}}
75+
76+
77+
TEST_1ARG_BUILTIN(amd_unpack0, float, uint) // ops-error 6 {{use of undeclared identifier}}
78+
TEST_1ARG_BUILTIN(amd_unpack1, float, uint) // ops-error 6 {{use of undeclared identifier}}
79+
TEST_1ARG_BUILTIN(amd_unpack2, float, uint) // ops-error 6 {{use of undeclared identifier}}
80+
TEST_1ARG_BUILTIN(amd_unpack3, float, uint) // ops-error 6 {{use of undeclared identifier}}
81+
82+
TEST_3ARG_WITH_TYPES_BUILTIN(amd_bfe, int, int, uint, uint) // ops2-error 6 {{use of undeclared identifier}} #amd_bfe0
83+
TEST_3ARG_BUILTIN(amd_bfe, uint, uint) // ops2-error 6 {{use of undeclared identifier}} #amd_bfe1
84+
TEST_2ARG_BUILTIN(amd_bfm, uint, uint) // ops2-error 6 {{use of undeclared identifier}}
85+
86+
TEST_3ARG_BUILTIN(amd_max3, float, float) // ops2-error 6 {{use of undeclared identifier}}
87+
TEST_3ARG_BUILTIN(amd_max3, int, int) // ops2-error 6 {{use of undeclared identifier}}
88+
TEST_3ARG_BUILTIN(amd_max3, uint, uint) // ops2-error 6 {{use of undeclared identifier}}
89+
90+
TEST_3ARG_BUILTIN(amd_median3, float, float) // ops2-error 6 {{use of undeclared identifier}}
91+
TEST_3ARG_BUILTIN(amd_median3, int, int) // ops2-error 6 {{use of undeclared identifier}}
92+
TEST_3ARG_BUILTIN(amd_median3, uint, uint) // ops2-error 6 {{use of undeclared identifier}}
93+
94+
TEST_3ARG_BUILTIN(amd_min3, float, float) // ops2-error 6 {{use of undeclared identifier}}
95+
TEST_3ARG_BUILTIN(amd_min3, int, int) // ops2-error 6 {{use of undeclared identifier}}
96+
TEST_3ARG_BUILTIN(amd_min3, uint, uint) // ops2-error 6 {{use of undeclared identifier}}
97+
98+
TEST_3ARG_WITH_TYPES_BUILTIN(amd_mqsad, ulong, ulong, uint, ulong) // ops2-error 6 {{use of undeclared identifier}}
99+
TEST_3ARG_WITH_TYPES_BUILTIN(amd_qsad, ulong, ulong, uint, ulong) // ops2-error 6 {{use of undeclared identifier}}
100+
101+
TEST_3ARG_BUILTIN(amd_msad, uint, uint) // ops2-error 6 {{use of undeclared identifier}}
102+
TEST_3ARG_BUILTIN(amd_sadd, uint, uint) // ops2-error 6 {{use of undeclared identifier}}
103+
TEST_3ARG_BUILTIN(amd_sadw, uint, uint) // ops2-error 6 {{use of undeclared identifier}}

0 commit comments

Comments
 (0)