Skip to content

Commit a6ee31b

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

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

clang/lib/Sema/SemaStmtAsm.cpp

Lines changed: 0 additions & 13 deletions
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

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

clang/test/SemaSYCL/inline-asm.cpp

Lines changed: 6 additions & 6 deletions
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)