Skip to content

Commit 1b8c008

Browse files
alexeyvoronov-intelvladimirlaz
authored andcommitted
[SYCL] Enable ext_vector_type of boolean type for SYCL language.
Signed-off-by: Vladimir Lazarev <[email protected]> Signed-off-by: Alexey Voronov <[email protected]>
1 parent 7858474 commit 1b8c008

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

clang/lib/Sema/SemaType.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,7 @@ QualType Sema::BuildExtVectorType(QualType T, Expr *ArraySize,
23672367
// of bool aren't allowed.
23682368
if ((!T->isDependentType() && !T->isIntegerType() &&
23692369
!T->isRealFloatingType()) ||
2370-
T->isBooleanType()) {
2370+
(!Context.getLangOpts().SYCLIsDevice && T->isBooleanType())) {
23712371
Diag(AttrLoc, diag::err_attribute_invalid_vector_type) << T;
23722372
return QualType();
23732373
}
+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// RUN: %clang_cc1 -triple spir64-unknown-linux-sycldevice -std=c++11 -fsycl-is-device -disable-llvm-passes -emit-llvm -x c++ %s -o - | opt -asfix -S -o - | FileCheck %s
2+
3+
template <typename name, typename Func>
4+
__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
5+
kernelFunc();
6+
}
7+
using bool1 = bool;
8+
using bool2 = bool __attribute__((ext_vector_type(2)));
9+
using bool3 = bool __attribute__((ext_vector_type(3)));
10+
using bool4 = bool __attribute__((ext_vector_type(4)));
11+
using bool8 = bool __attribute__((ext_vector_type(8)));
12+
using bool16 = bool __attribute__((ext_vector_type(16)));
13+
14+
extern bool1 foo1();
15+
// CHECK-DAG: declare spir_func zeroext i1 @[[FOO1:[a-zA-Z0-9_]+]]()
16+
extern bool2 foo2();
17+
// CHECK-DAG: declare spir_func <2 x i1> @[[FOO2:[a-zA-Z0-9_]+]]()
18+
extern bool3 foo3();
19+
// CHECK-DAG: declare spir_func <3 x i1> @[[FOO3:[a-zA-Z0-9_]+]]()
20+
extern bool4 foo4();
21+
// CHECK-DAG: declare spir_func <4 x i1> @[[FOO4:[a-zA-Z0-9_]+]]()
22+
extern bool8 foo8();
23+
// CHECK-DAG: declare spir_func <8 x i1> @[[FOO8:[a-zA-Z0-9_]+]]()
24+
extern bool16 foo16();
25+
// CHECK-DAG: declare spir_func <16 x i1> @[[FOO16:[a-zA-Z0-9_]+]]()
26+
27+
void bar (bool1 b) {};
28+
// CHECK-DAG: define spir_func void @[[BAR1:[a-zA-Z0-9_]+]](i1 zeroext %
29+
void bar (bool2 b) {};
30+
// CHECK-DAG: define spir_func void @[[BAR2:[a-zA-Z0-9_]+]](<2 x i1> %
31+
void bar (bool3 b) {};
32+
// CHECK-DAG: define spir_func void @[[BAR3:[a-zA-Z0-9_]+]](<3 x i1> %
33+
void bar (bool4 b) {};
34+
// CHECK-DAG: define spir_func void @[[BAR4:[a-zA-Z0-9_]+]](<4 x i1> %
35+
void bar (bool8 b) {};
36+
// CHECK-DAG: define spir_func void @[[BAR8:[a-zA-Z0-9_]+]](<8 x i1> %
37+
void bar (bool16 b) {};
38+
// CHECK-DAG: define spir_func void @[[BAR16:[a-zA-Z0-9_]+]](<16 x i1> %
39+
40+
int main() {
41+
kernel<class kernel_function>(
42+
[=]() {
43+
bool1 b1 = foo1();
44+
// CHECK-DAG: [[B1:%[a-zA-Z0-9_]+]] = alloca i8, align 1
45+
// CHECK-DAG: [[CALL1:%[a-zA-Z0-9_]+]] = call spir_func zeroext i1 @[[FOO1]]
46+
bar(b1);
47+
// CHECK-DAG: call spir_func void @[[BAR1]](i1 zeroext [[B1_ARG:%[a-zA-Z0-9_]+]]
48+
bool2 b2 = foo2();
49+
// CHECK-DAG: [[B2:%[a-zA-Z0-9_]+]] = alloca <2 x i1>, align 2
50+
// CHECK-DAG: [[CALL2:%[a-zA-Z0-9_]+]] = call spir_func <2 x i1> @[[FOO2]]
51+
bar(b2);
52+
// CHECK-DAG: call spir_func void @[[BAR2]](<2 x i1> [[B2_ARG:%[a-zA-Z0-9_]+]]
53+
bool3 b3 = foo3();
54+
// CHECK-DAG: [[B3:%[a-zA-Z0-9_]+]] = alloca <3 x i1>, align 4
55+
// CHECK-DAG: [[CALL3:%[a-zA-Z0-9_]+]] = call spir_func <3 x i1> @[[FOO3]]
56+
bar(b3);
57+
// CHECK-DAG: call spir_func void @[[BAR3]](<3 x i1> [[B3_ARG:%[a-zA-Z0-9_]+]]
58+
bool4 b4 = foo4();
59+
// CHECK-DAG: [[B4:%[a-zA-Z0-9_]+]] = alloca <4 x i1>, align 4
60+
// CHECK-DAG: [[CALL4:%[a-zA-Z0-9_]+]] = call spir_func <4 x i1> @[[FOO4]]
61+
bar(b4);
62+
// CHECK-DAG: call spir_func void @[[BAR4]](<4 x i1> [[B4_ARG:%[a-zA-Z0-9_]+]]
63+
bool8 b8 = foo8();
64+
// CHECK-DAG: [[B8:%[a-zA-Z0-9_]+]] = alloca <8 x i1>, align 8
65+
// CHECK-DAG: [[CALL8:%[a-zA-Z0-9_]+]] = call spir_func <8 x i1> @[[FOO8]]
66+
bar(b8);
67+
// CHECK-DAG: call spir_func void @[[BAR8]](<8 x i1> [[B8_ARG:%[a-zA-Z0-9_]+]]
68+
bool16 b16 = foo16();
69+
// CHECK-DAG: [[B16:%[a-zA-Z0-9_]+]] = alloca <16 x i1>, align 16
70+
// CHECK-DAG: [[CALL16:%[a-zA-Z0-9_]+]] = call spir_func <16 x i1> @[[FOO16]]
71+
bar(b16);
72+
// CHECK-DAG: call spir_func void @[[BAR16]](<16 x i1> [[B16_ARG:%[a-zA-Z0-9_]+]]
73+
});
74+
return 0;
75+
}

clang/test/SemaSYCL/bool-vectors.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -fsyntax-only -verify %s
2+
// expected-no-diagnostics
3+
4+
template <typename name, typename Func>
5+
__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
6+
kernelFunc();
7+
}
8+
using bool1 = bool;
9+
using bool2 = bool __attribute__((ext_vector_type(2)));
10+
using bool3 = bool __attribute__((ext_vector_type(3)));
11+
using bool4 = bool __attribute__((ext_vector_type(4)));
12+
using bool8 = bool __attribute__((ext_vector_type(8)));
13+
using bool16 = bool __attribute__((ext_vector_type(16)));
14+
15+
int main() {
16+
kernel<class kernel_function>(
17+
[=]() {
18+
bool1 b1;
19+
bool2 b2;
20+
bool3 b3;
21+
bool4 b4;
22+
bool8 b8;
23+
bool16 b16;
24+
});
25+
return 0;
26+
}
27+

0 commit comments

Comments
 (0)