@@ -19,7 +19,7 @@ module TestRuntime
1919end
2020
2121struct TestCompilerParams <: AbstractCompilerParams end
22- GPUCompiler. runtime_module (:: CompilerJob{<:Any,TestCompilerParams} ) = TestRuntime
22+ GPUCompiler. runtime_module (:: CompilerJob{<:Any, TestCompilerParams} ) = TestRuntime
2323
2424
2525# # JIT integration
@@ -58,8 +58,8 @@ const jit = Ref{CompilerInstance}()
5858function get_trampoline (job)
5959 compiler = jit[]
6060 lljit = compiler. jit
61- lctm = compiler. lctm
62- ism = compiler. ism
61+ lctm = compiler. lctm
62+ ism = compiler. ism
6363
6464 # We could also use one dylib per job
6565 jd = JITDylib (lljit)
@@ -68,11 +68,14 @@ function get_trampoline(job)
6868 target_sym = String (gensym (:target ))
6969 flags = LLVM. API. LLVMJITSymbolFlags (
7070 LLVM. API. LLVMJITSymbolGenericFlagsCallable |
71- LLVM. API. LLVMJITSymbolGenericFlagsExported, 0 )
71+ LLVM. API. LLVMJITSymbolGenericFlagsExported, 0
72+ )
7273 entry = LLVM. API. LLVMOrcCSymbolAliasMapPair (
7374 mangle (lljit, entry_sym),
7475 LLVM. API. LLVMOrcCSymbolAliasMapEntry (
75- mangle (lljit, target_sym), flags))
76+ mangle (lljit, target_sym), flags
77+ )
78+ )
7679
7780 mu = LLVM. reexports (lctm, ism, jd, Ref (entry))
7881 LLVM. define (jd, mu)
@@ -85,7 +88,7 @@ function get_trampoline(job)
8588
8689 function materialize (mr)
8790 buf = JuliaContext () do ctx
88- ir, meta = GPUCompiler. compile (:llvm , job; validate= false )
91+ ir, meta = GPUCompiler. compile (:llvm , job; validate = false )
8992
9093 # Rename entry to match target_sym
9194 LLVM. name! (meta. entry, target_sym)
@@ -117,14 +120,14 @@ function get_trampoline(job)
117120end
118121
119122import GPUCompiler: deferred_codegen_jobs
120- @generated function deferred_codegen (f:: F , :: Val{tt} , :: Val{world} ) where {F,tt,world}
123+ @generated function deferred_codegen (f:: F , :: Val{tt} , :: Val{world} ) where {F, tt, world}
121124 # manual version of native_job because we have a function type
122125 source = methodinstance (F, Base. to_tuple_type (tt), world)
123- target = NativeCompilerTarget (; jlruntime= true , llvm_always_inline= true )
126+ target = NativeCompilerTarget (; jlruntime = true , llvm_always_inline = true )
124127 # XXX : do we actually require the Julia runtime?
125128 # with jlruntime=false, we reach an unreachable.
126129 params = TestCompilerParams ()
127- config = CompilerConfig (target, params; kernel= false )
130+ config = CompilerConfig (target, params; kernel = false )
128131 job = CompilerJob (source, config, world)
129132 # XXX : invoking GPUCompiler from a generated function is not allowed!
130133 # for things to work, we need to forward the correct world, at least.
@@ -135,16 +138,16 @@ import GPUCompiler: deferred_codegen_jobs
135138
136139 deferred_codegen_jobs[id] = job
137140
138- quote
141+ return quote
139142 ptr = ccall (" extern deferred_codegen" , llvmcall, Ptr{Cvoid}, (Ptr{Cvoid},), $ trampoline)
140143 assume (ptr != C_NULL )
141144 return ptr
142145 end
143146end
144147
145148@generated function abi_call (f:: Ptr{Cvoid} , rt:: Type{RT} , tt:: Type{T} , func:: F , args:: Vararg{Any, N} ) where {T, RT, F, N}
146- argtt = tt. parameters[1 ]
147- rettype = rt. parameters[1 ]
149+ argtt = tt. parameters[1 ]
150+ rettype = rt. parameters[1 ]
148151 argtypes = DataType[argtt. parameters... ]
149152
150153 argexprs = Union{Expr, Symbol}[]
199202 if GPUCompiler. isghosttype (rettype) || Core. Compiler. isconstType (rettype)
200203 # Do nothing...
201204 # In theory we could set `rettype` to `T_void`, but ccall will do that for us
202- # elseif jl_is_uniontype?
205+ # elseif jl_is_uniontype?
203206 elseif ! GPUCompiler. deserves_retbox (rettype)
204207 rt = convert (LLVMType, rettype)
205208 if ! isa (rt, LLVM. VoidType) && GPUCompiler. deserves_sret (rettype, rt)
@@ -214,26 +217,26 @@ end
214217 end
215218 end
216219
217- quote
220+ return quote
218221 $ before
219222 ret = ccall (f, $ rettype, ($ (ccall_types... ),), $ (argexprs... ))
220223 $ after
221224 end
222225end
223226
224- @inline function call_delayed (f:: F , args... ) where F
227+ @inline function call_delayed (f:: F , args... ) where {F}
225228 tt = Tuple{map (Core. Typeof, args)... }
226229 rt = Core. Compiler. return_type (f, tt)
227230 world = GPUCompiler. tls_world_age ()
228231 ptr = deferred_codegen (f, Val (tt), Val (world))
229- abi_call (ptr, rt, tt, f, args... )
232+ return abi_call (ptr, rt, tt, f, args... )
230233end
231234
232235optlevel = LLVM. API. LLVMCodeGenLevelDefault
233- tm = GPUCompiler. JITTargetMachine (optlevel= optlevel)
236+ tm = GPUCompiler. JITTargetMachine (optlevel = optlevel)
234237LLVM. asm_verbosity! (tm, true )
235238
236- lljit = LLJIT (;tm)
239+ lljit = LLJIT (; tm)
237240
238241jd_main = JITDylib (lljit)
239242
@@ -267,36 +270,36 @@ using Test
267270f (A) = (A[] += 42 ; nothing )
268271global flag = [0 ]
269272function caller ()
270- call_delayed (f, flag:: Vector{Int} )
273+ return call_delayed (f, flag:: Vector{Int} )
271274end
272275@test caller () === nothing
273276@test flag[] == 42
274277
275278# test that we can call a function with a return value
276- add (x, y) = x+ y
279+ add (x, y) = x + y
277280function call_add (x, y)
278- call_delayed (add, x, y)
281+ return call_delayed (add, x, y)
279282end
280283@test call_add (1 , 3 ) == 4
281284
282285incr (r) = r[] += 1
283286function call_incr (r)
284- call_delayed (incr, r)
287+ return call_delayed (incr, r)
285288end
286289r = Ref {Int} (0 )
287290@test call_incr (r) == 1
288291@test r[] == 1
289292
290293function call_real (c)
291- call_delayed (real, c)
294+ return call_delayed (real, c)
292295end
293- @test call_real (1.0 + im) == 1.0
296+ @test call_real (1.0 + im) == 1.0
294297
295298# tests struct return
296299if Sys. ARCH != :aarch64
297- @test call_delayed (complex, 1.0 , 2.0 ) == 1.0 + 2.0im
300+ @test call_delayed (complex, 1.0 , 2.0 ) == 1.0 + 2.0im
298301else
299- @test_broken call_delayed (complex, 1.0 , 2.0 ) == 1.0 + 2.0im
302+ @test_broken call_delayed (complex, 1.0 , 2.0 ) == 1.0 + 2.0im
300303end
301304
302305throws (arr, i) = arr[i]
@@ -306,11 +309,11 @@ throws(arr, i) = arr[i]
306309struct Closure
307310 x:: Int64
308311end
309- (c:: Closure )(b) = c. x+ b
312+ (c:: Closure )(b) = c. x + b
310313@test call_delayed (Closure (3 ), 5 ) == 8
311314
312315struct Closure2
313316 x:: Integer
314317end
315- (c:: Closure2 )(b) = c. x+ b
318+ (c:: Closure2 )(b) = c. x + b
316319@test call_delayed (Closure2 (3 ), 5 ) == 8
0 commit comments