1
- From 8a7885884d8b7074f716332768ed957d849b9a72 Mon Sep 17 00:00:00 2001
1
+ From cc687f3c2399b83da0156ff24d09c24bab31e74e Mon Sep 17 00:00:00 2001
2
2
From: haonanya <
[email protected] >
3
3
Date: Wed, 28 Jul 2021 14:24:23 +0800
4
4
Subject: [PATCH] Add support for cl_ext_float_atomics in SPIRVWriter
7
7
---
8
8
include/LLVMSPIRVExtensions.inc | 1 +
9
9
lib/SPIRV/OCLToSPIRV.cpp | 27 +++++-
10
- lib/SPIRV/OCLUtil.cpp | 19 ++--
10
+ lib/SPIRV/OCLUtil.cpp | 15 ++--
11
11
lib/SPIRV/SPIRVToOCL.h | 3 +
12
12
lib/SPIRV/SPIRVToOCL12.cpp | 21 +++++
13
13
lib/SPIRV/SPIRVToOCL20.cpp | 28 +++++-
16
16
lib/SPIRV/libSPIRV/SPIRVOpCode.h | 8 +-
17
17
lib/SPIRV/libSPIRV/SPIRVOpCodeEnum.h | 2 +
18
18
lib/SPIRV/libSPIRV/spirv.hpp | 7 ++
19
- test/AtomicBuiltinsFloat.ll | 79 ++++++++++++++++
19
+ test/AtomicBuiltinsFloat.ll | 94 +++ ++++++++++++++++
20
20
test/AtomicFAddEXT.ll | 72 +++++++++++++++
21
21
test/AtomicFAddEXTForOCL.ll | 84 +++++++++++++++++
22
22
test/AtomicFAddExt.ll | 119 -------------------------
25
25
test/AtomicFMinEXT.ll | 73 +++++++++++++++
26
26
test/AtomicFMinEXTForOCL.ll | 81 +++++++++++++++++
27
27
test/negative/InvalidAtomicBuiltins.cl | 18 +---
28
- 20 files changed, 675 insertions(+), 148 deletions(-)
28
+ 20 files changed, 688 insertions(+), 146 deletions(-)
29
29
create mode 100644 test/AtomicBuiltinsFloat.ll
30
30
create mode 100644 test/AtomicFAddEXT.ll
31
31
create mode 100644 test/AtomicFAddEXTForOCL.ll
@@ -100,30 +100,28 @@ index 7c65b9e8..7ea350ff 100644
100
100
&Attrs);
101
101
}
102
102
diff --git a/lib/SPIRV/OCLUtil.cpp b/lib/SPIRV/OCLUtil.cpp
103
- index 2cc5d815..e4d7a7cf 100644
103
+ index 2cc5d815..89ae7fe7 100644
104
104
--- a/lib/SPIRV/OCLUtil.cpp
105
105
+++ b/lib/SPIRV/OCLUtil.cpp
106
106
@@ -655,29 +655,32 @@ size_t getSPIRVAtomicBuiltinNumMemoryOrderArgs(Op OC) {
107
107
return 1;
108
108
}
109
109
110
- + // atomic_fetch_[add, sub, min, max] and atomic_fetch_[add, sub, min,
111
- + // max]_explicit functions are defined on OpenCL headers, they are not
112
- + // translated to function call
110
+ + // atomic_fetch_[add, min, max] and atomic_fetch_[add, min, max]_explicit
111
+ + // functions declared in clang headers should be translated to corresponding
112
+ + // FP-typed Atomic Instructions
113
113
bool isComputeAtomicOCLBuiltin(StringRef DemangledName) {
114
114
if (!DemangledName.startswith(kOCLBuiltinName::AtomicPrefix) &&
115
115
!DemangledName.startswith(kOCLBuiltinName::AtomPrefix))
116
116
return false;
117
117
118
118
return llvm::StringSwitch<bool>(DemangledName)
119
119
- .EndsWith("add", true)
120
- - .EndsWith("sub", true)
120
+ .EndsWith("sub", true)
121
121
+ .EndsWith("atomic_add", true)
122
- + .EndsWith("atomic_sub", true)
123
122
+ .EndsWith("atomic_min", true)
124
123
+ .EndsWith("atomic_max", true)
125
124
+ .EndsWith("atom_add", true)
126
- + .EndsWith("atom_sub", true)
127
125
+ .EndsWith("atom_min", true)
128
126
+ .EndsWith("atom_max", true)
129
127
.EndsWith("inc", true)
@@ -135,7 +133,7 @@ index 2cc5d815..e4d7a7cf 100644
135
133
.EndsWith("or", true)
136
134
.EndsWith("xor", true)
137
135
- .EndsWith("add_explicit", true)
138
- - .EndsWith("sub_explicit", true)
136
+ .EndsWith("sub_explicit", true)
139
137
.EndsWith("or_explicit", true)
140
138
.EndsWith("xor_explicit", true)
141
139
.EndsWith("and_explicit", true)
@@ -385,11 +383,13 @@ index f0e311c6..2a86f32e 100644
385
383
case OpVmeImageINTEL: *hasResult = true; *hasResultType = true; break;
386
384
diff --git a/test/AtomicBuiltinsFloat.ll b/test/AtomicBuiltinsFloat.ll
387
385
new file mode 100644
388
- index 00000000..d9300558
386
+ index 00000000..778c0cb0
389
387
--- /dev/null
390
388
+++ b/test/AtomicBuiltinsFloat.ll
391
- @@ -0,0 +1,79 @@
389
+ @@ -0,0 +1,94 @@
392
390
+ ; Check that translator generate atomic instructions for atomic builtins
391
+ + ; FP-typed atomic_fetch_sub and atomic_fetch_sub_explicit should be translated
392
+ + ; to FunctionCall
393
393
+ ; RUN: llvm-as %s -o %t.bc
394
394
+ ; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s
395
395
+ ; RUN: llvm-spirv %t.bc -o %t.spv
@@ -400,12 +400,13 @@ index 00000000..d9300558
400
400
+ ; CHECK-COUNT-3: AtomicStore
401
401
+ ; CHECK-COUNT-3: AtomicLoad
402
402
+ ; CHECK-COUNT-3: AtomicExchange
403
+ + ; CHECK-COUNT-3: FunctionCall
403
404
+
404
405
+ target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
405
406
+ target triple = "spir-unknown-unknown"
406
407
+
407
408
+ ; Function Attrs: convergent norecurse nounwind
408
- + define dso_local spir_kernel void @test_atomic_kernel(float addrspace(3)* %ff, float addrspace(3)* nocapture readnone %a ) local_unnamed_addr #0 !kernel_arg_addr_space !3 !kernel_arg_access_qual !4 !kernel_arg_type !5 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 {
409
+ + define dso_local spir_kernel void @test_atomic_kernel(float addrspace(3)* %ff) local_unnamed_addr #0 !kernel_arg_addr_space !3 !kernel_arg_access_qual !4 !kernel_arg_type !5 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 {
409
410
+ entry:
410
411
+ %0 = addrspacecast float addrspace(3)* %ff to float addrspace(4)*
411
412
+ tail call spir_func void @_Z11atomic_initPU3AS4VU7_Atomicff(float addrspace(4)* %0, float 1.000000e+00) #2
@@ -418,6 +419,9 @@ index 00000000..d9300558
418
419
+ %call3 = tail call spir_func float @_Z15atomic_exchangePU3AS4VU7_Atomicff(float addrspace(4)* %0, float 1.000000e+00) #2
419
420
+ %call4 = tail call spir_func float @_Z24atomic_exchange_explicitPU3AS4VU7_Atomicff12memory_order(float addrspace(4)* %0, float 1.000000e+00, i32 0) #2
420
421
+ %call5 = tail call spir_func float @_Z24atomic_exchange_explicitPU3AS4VU7_Atomicff12memory_order12memory_scope(float addrspace(4)* %0, float 1.000000e+00, i32 0, i32 1) #2
422
+ + %call6 = tail call spir_func float @_Z16atomic_fetch_subPU3AS3VU7_Atomicff(float addrspace(3)* %ff, float 1.000000e+00) #2
423
+ + %call7 = tail call spir_func float @_Z25atomic_fetch_sub_explicitPU3AS3VU7_Atomicff12memory_order(float addrspace(3)* %ff, float 1.000000e+00, i32 0) #2
424
+ + %call8 = tail call spir_func float @_Z25atomic_fetch_sub_explicitPU3AS3VU7_Atomicff12memory_order12memory_scope(float addrspace(3)* %ff, float 1.000000e+00, i32 0, i32 1) #2
421
425
+ ret void
422
426
+ }
423
427
+
@@ -451,6 +455,15 @@ index 00000000..d9300558
451
455
+ ; Function Attrs: convergent
452
456
+ declare spir_func float @_Z24atomic_exchange_explicitPU3AS4VU7_Atomicff12memory_order12memory_scope(float addrspace(4)*, float, i32, i32) local_unnamed_addr #1
453
457
+
458
+ + ; Function Attrs: convergent
459
+ + declare spir_func float @_Z16atomic_fetch_subPU3AS3VU7_Atomicff(float addrspace(3)*, float) local_unnamed_addr #1
460
+ +
461
+ + ; Function Attrs: convergent
462
+ + declare spir_func float @_Z25atomic_fetch_sub_explicitPU3AS3VU7_Atomicff12memory_order(float addrspace(3)*, float, i32) local_unnamed_addr #1
463
+ +
464
+ + ; Function Attrs: convergent
465
+ + declare spir_func float @_Z25atomic_fetch_sub_explicitPU3AS3VU7_Atomicff12memory_order12memory_scope(float addrspace(3)*, float, i32, i32) local_unnamed_addr #1
466
+ +
454
467
+ attributes #0 = { convergent norecurse nounwind "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
455
468
+ attributes #1 = { convergent "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
456
469
+ attributes #2 = { convergent nounwind }
@@ -463,11 +476,11 @@ index 00000000..d9300558
463
476
+ !0 = !{i32 1, !"wchar_size", i32 4}
464
477
+ !1 = !{i32 2, i32 0}
465
478
+ !2 = !{!"clang version 12.0.1 (https://github.com/llvm/llvm-project.git 23fe7b104a0adaaaecd52108105f49297c420c9b)"}
466
- + !3 = !{i32 3, i32 3 }
467
- + !4 = !{!"none", !"none" }
468
- + !5 = !{!"atomic_float*", !"float*" }
469
- + !6 = !{!"_Atomic(float)*", !"float*" }
470
- + !7 = !{!"volatile", !"" }
479
+ + !3 = !{i32 3}
480
+ + !4 = !{!"none"}
481
+ + !5 = !{!"atomic_float*"}
482
+ + !6 = !{!"_Atomic(float)*"}
483
+ + !7 = !{!"volatile"}
471
484
diff --git a/test/AtomicFAddEXT.ll b/test/AtomicFAddEXT.ll
472
485
new file mode 100644
473
486
index 00000000..b012c904
0 commit comments