Skip to content

Commit 13599d9

Browse files
committed
[SYCL] Allow gcc asm statements in kernel code.
Signed-off-by: Premanand M Rao <[email protected]>
1 parent a038480 commit 13599d9

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

clang/lib/Sema/SemaStmtAsm.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,6 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
256256
// The parser verifies that there is a string literal here.
257257
assert(AsmString->isAscii());
258258

259-
// Skip all the checks if we are compiling SYCL device code, but the function
260-
// is not marked to be used on device, this code won't be codegen'ed anyway.
261-
if (getLangOpts().SYCLIsDevice) {
262-
SYCLDiagIfDeviceCode(AsmLoc, diag::err_sycl_restrict) << KernelUseAssembly;
263-
return new (Context)
264-
GCCAsmStmt(Context, AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs,
265-
Names, Constraints, Exprs.data(), AsmString, NumClobbers,
266-
Clobbers, NumLabels, RParenLoc);
267-
}
268-
269259
FunctionDecl *FD = dyn_cast<FunctionDecl>(getCurLexicalContext());
270260
llvm::StringMap<bool> FeatureMap;
271261
Context.getFunctionFeatureMap(FeatureMap, FD);
@@ -902,9 +892,6 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
902892
SourceLocation EndLoc) {
903893
bool IsSimple = (NumOutputs != 0 || NumInputs != 0);
904894
setFunctionHasBranchProtectedScope();
905-
if (getLangOpts().SYCLIsDevice)
906-
SYCLDiagIfDeviceCode(AsmLoc, diag::err_sycl_restrict)
907-
<< KernelUseAssembly;
908895
MSAsmStmt *NS =
909896
new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc, IsSimple,
910897
/*IsVolatile*/ true, AsmToks, NumOutputs, NumInputs,

clang/test/CodeGenSYCL/inline_asm.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -emit-llvm -x c++ %s -o - | FileCheck %s
2+
3+
class kernel;
4+
5+
template <typename name, typename Func>
6+
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
7+
// CHECK: %[[ARRAY_A:[0-9a-z]+]] = alloca [100 x i32], align 4
8+
// CHECK: %[[IDX:.*]] = getelementptr inbounds [100 x i32], [100 x i32]* %[[ARRAY_A]], i64 0, i64 0
9+
int a[100], i = 0;
10+
// CHECK-NEXT: call void asm sideeffect
11+
// CHECK: ".decl V52 v_type=G type=d num_elts=16 align=GRF
12+
// CHECK: svm_gather.4.1 (M1, 16) $0.0 V52.0
13+
// CHECK: add(M1, 16) V52(0, 0)<1> V52(0, 0)<1; 1, 0> 0x1
14+
// CHECK: svm_scatter.4.1 (M1, 16) $0.0 V52.0",
15+
// CHECK: "rw"(i32* nonnull %[[IDX]])
16+
asm volatile(".decl V52 v_type=G type=d num_elts=16 align=GRF\n"
17+
"svm_gather.4.1 (M1, 16) %0.0 V52.0\n"
18+
"add(M1, 16) V52(0, 0)<1> V52(0, 0)<1; 1, 0> 0x1\n"
19+
"svm_scatter.4.1 (M1, 16) %0.0 V52.0"
20+
:
21+
: "rw"(&a[i]));
22+
}
23+
24+
int main() {
25+
kernel_single_task<class kernel>([]() {});
26+
return 0;
27+
}

clang/test/SemaSYCL/inline-asm.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -verify %s -DLINUX_ASM
22
// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -verify -triple x86_64-windows -fasm-blocks %s
33

4+
// expected-no-diagnostics
5+
46
void foo() {
57
int a;
68
#ifdef LINUX_ASM
@@ -13,26 +15,24 @@ void foo() {
1315
void bar() {
1416
int a;
1517
#ifdef LINUX_ASM
16-
__asm__("int3"); // expected-error {{SYCL kernel cannot use inline assembly}}
18+
__asm__("int3");
1719
#else
18-
__asm int 3 // expected-error {{SYCL kernel cannot use inline assembly}}
20+
__asm int 3
1921
#endif // LINUX_ASM
2022
}
2123

2224
template <typename Name, typename Func>
2325
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
24-
// expected-note@+1 {{called by 'kernel_single_task<fake_kernel, (lambda}}
2526
kernelFunc();
2627
#ifdef LINUX_ASM
27-
__asm__("int3"); // expected-error {{SYCL kernel cannot use inline assembly}}
28+
__asm__("int3");
2829
#else
29-
__asm int 3 // expected-error {{SYCL kernel cannot use inline assembly}}
30+
__asm int 3
3031
#endif // LINUX_ASM
3132
}
3233

3334
int main() {
3435
foo();
35-
// expected-note@+1 {{called by 'operator()'}}
3636
kernel_single_task<class fake_kernel>([]() { bar(); });
3737
return 0;
3838
}

0 commit comments

Comments
 (0)