Skip to content

Commit 5d678fe

Browse files
MrSidimssvenvh
authored andcommitted
Add support for non-constant 'Scope' operand of OpMemoryBarrier
Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent bc0936f commit 5d678fe

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/SPIRV/SPIRVToOCL20.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ void SPIRVToOCL20::visitCallSPIRVMemoryBarrier(CallInst *CI) {
111111
M, CI,
112112
[=](CallInst *, std::vector<Value *> &Args) {
113113
Value *MemScope =
114-
getInt32(M, rmap<OCLScopeKind>(static_cast<Scope>(
115-
cast<ConstantInt>(Args[0])->getZExtValue())));
114+
SPIRV::transSPIRVMemoryScopeIntoOCLMemoryScope(Args[0], CI);
116115
Value *MemFenceFlags =
117116
SPIRV::transSPIRVMemorySemanticsIntoOCLMemFenceFlags(Args[1], CI);
118117
Value *MemOrder =

test/mem_fence_explicit_arguments.spt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@
66
3 MemoryModel 1 2
77
3 Source 3 102000
88
4 Name 5 "test"
9-
3 Name 6 "val"
9+
3 Name 6 "val1"
1010
4 Name 7 "entry"
11+
3 Name 9 "val2"
1112
6 Decorate 5 LinkageAttributes "test" Export
1213
4 TypeInt 3 32 0
1314
4 Constant 3 8 2
1415
2 TypeVoid 2
15-
4 TypeFunction 4 2 3
16+
5 TypeFunction 4 2 3 3
1617

1718
5 Function 2 5 0 4
1819
3 FunctionParameter 3 6
20+
3 FunctionParameter 3 9
1921

2022
2 Label 7
2123
3 MemoryBarrier 8 6
24+
3 MemoryBarrier 9 6
2225
1 Return
2326

2427
1 FunctionEnd
@@ -30,11 +33,17 @@
3033
; RUN: llvm-spirv -r %t.spv --spirv-target-env=CL2.0 -o %t.bc
3134
; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefixes CHECK,CHECK-20
3235

33-
; CHECK: define spir_func void @test(i32 %val)
34-
; CHECK: %call = call spir_func i32 @__translate_spirv_memory_fence(i32 %val)
36+
; CHECK: define spir_func void @test(i32 %[[VAL1:[a-zA-Z0-9]+]], i32 %[[VAL2:[a-zA-Z0-9]+]])
37+
; CHECK: %call = call spir_func i32 @__translate_spirv_memory_fence(i32 %[[VAL1]])
3538
; CHECK-12: call spir_func void @_Z9mem_fencej(i32 %call)
36-
; CHECK-20: %call1 = call spir_func i32 @__translate_spirv_memory_order(i32 %val)
39+
; CHECK-12: %call1 = call spir_func i32 @__translate_spirv_memory_fence(i32 %[[VAL1]])
40+
; CHECK-12: call spir_func void @_Z9mem_fencej(i32 %call1)
41+
; CHECK-20: %call1 = call spir_func i32 @__translate_spirv_memory_order(i32 %[[VAL1]])
3742
; CHECK-20: call spir_func void @_Z22atomic_work_item_fencej12memory_order12memory_scope(i32 %call, i32 %call1
43+
; CHECK-20: %call2 = call spir_func i32 @__translate_spirv_memory_scope(i32 %[[VAL2]])
44+
; CHECK-20: %call3 = call spir_func i32 @__translate_spirv_memory_fence(i32 %[[VAL1]])
45+
; CHECK-20: %call4 = call spir_func i32 @__translate_spirv_memory_order(i32 %[[VAL1]])
46+
; CHECK-20: call spir_func void @_Z22atomic_work_item_fencej12memory_order12memory_scope(i32 %call3, i32 %call4, i32 %call2)
3847
; CHECK: define private spir_func i32 @__translate_spirv_memory_fence(i32 %key)
3948
; CHECK: entry:
4049
; CHECK: %key.masked = and i32 2816, %key

0 commit comments

Comments
 (0)