Skip to content

Commit 4a2aa28

Browse files
authored
[SYCL] Allow gcc asm statements in kernel code (#1366)
Signed-off-by: Premanand M Rao <[email protected]>
1 parent a3bd80c commit 4a2aa28

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

clang/lib/Sema/Sema.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,9 +1639,10 @@ Sema::DeviceDiagBuilder Sema::targetDiag(SourceLocation Loc, unsigned DiagID) {
16391639
if (getLangOpts().CUDA)
16401640
return getLangOpts().CUDAIsDevice ? CUDADiagIfDeviceCode(Loc, DiagID)
16411641
: CUDADiagIfHostCode(Loc, DiagID);
1642-
// TODO: analyze which usages of targetDiag could be reused for SYCL.
1643-
// if (getLangOpts().SYCLIsDevice)
1644-
// return SYCLDiagIfDeviceCode(Loc, DiagID);
1642+
1643+
if (getLangOpts().SYCLIsDevice)
1644+
return SYCLDiagIfDeviceCode(Loc, DiagID);
1645+
16451646
return DeviceDiagBuilder(DeviceDiagBuilder::K_Immediate, Loc, DiagID,
16461647
getCurFunctionDecl(), *this);
16471648
}

clang/test/SemaSYCL/inline-asm.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
11
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -verify %s -DLINUX_ASM
2+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -verify %s -DLINUX_ASM -DSPIR_CHECK -triple spir64-unknown-unknown-sycldevice
23
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -verify -triple x86_64-windows -fasm-blocks %s
34

4-
// expected-no-diagnostics
5+
#ifndef SPIR_CHECK
6+
//expected-no-diagnostics
7+
#endif // SPIR_CHECK
8+
9+
static __inline unsigned int
10+
asm_func(unsigned int __leaf, unsigned long __d[]) {
11+
unsigned int __result;
12+
#ifdef SPIR_CHECK
13+
__asm__("enclu"
14+
: "=a"(__result), "=b"(__d[0]), "=c"(__d[1]), "=d"(__d[2])
15+
: "a"(__leaf), "b"(__d[0]), "c"(__d[1]), "d"(__d[2])
16+
: "cc");
17+
#endif // SPIR_CHECK
18+
return __result;
19+
}
20+
21+
static __inline unsigned int
22+
asm_func_2(unsigned int __leaf, unsigned long __d[]) {
23+
unsigned int __result;
24+
#ifdef SPIR_CHECK
25+
//expected-error@+2 {{invalid output constraint '=a' in asm}}
26+
__asm__("enclu"
27+
: "=a"(__result), "=b"(__d[0]), "=c"(__d[1]), "=d"(__d[2])
28+
: "a"(__leaf), "b"(__d[0]), "c"(__d[1]), "d"(__d[2])
29+
: "cc");
30+
#endif // SPIR_CHECK
31+
return __result;
32+
}
533

634
void foo() {
735
int a;
@@ -26,6 +54,13 @@ __attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
2654
kernelFunc();
2755
#ifdef LINUX_ASM
2856
__asm__("int3");
57+
58+
#ifdef SPIR_CHECK
59+
unsigned int i = 3;
60+
unsigned long d[4];
61+
//expected-note@+1 {{called by 'kernel_single_task'}}
62+
asm_func_2(i, d);
63+
#endif // SPIR_CHECK
2964
#else
3065
__asm int 3
3166
#endif // LINUX_ASM

0 commit comments

Comments
 (0)