@@ -122,7 +122,7 @@ function code_llvm(io::IO, @nospecialize(job::CompilerJob); optimize::Bool=true,
122
122
debuginfo:: Symbol = :default , dump_module:: Bool = false , kwargs... )
123
123
# NOTE: jl_dump_function_ir supports stripping metadata, so don't do it in the driver
124
124
str = JuliaContext () do ctx
125
- ir, meta = codegen (:llvm , job; optimize= optimize, strip= false , validate= false , ctx, kwargs... )
125
+ ir, meta = compile (:llvm , job; optimize= optimize, strip= false , validate= false , ctx, kwargs... )
126
126
@static if VERSION >= v " 1.9.0-DEV.516"
127
127
ts_mod = ThreadSafeModule (ir; ctx)
128
128
if VERSION >= v " 1.9.0-DEV.672"
@@ -169,7 +169,7 @@ The following keyword arguments are supported:
169
169
See also: [`@device_code_native`](@ref), `InteractiveUtils.code_llvm`
170
170
"""
171
171
function code_native (io:: IO , @nospecialize (job:: CompilerJob ); raw:: Bool = false , dump_module:: Bool = false )
172
- asm, meta = codegen (:asm , job; strip= ! raw, only_entry= ! dump_module, validate= false )
172
+ asm, meta = compile (:asm , job; strip= ! raw, only_entry= ! dump_module, validate= false )
173
173
highlight (io, asm, source_code (job. config. target))
174
174
end
175
175
code_native (@nospecialize (job:: CompilerJob ); kwargs... ) =
@@ -184,25 +184,31 @@ function emit_hooked_compilation(inner_hook, ex...)
184
184
user_code = ex[end ]
185
185
user_kwargs = ex[1 : end - 1 ]
186
186
quote
187
- local kernels = Set ()
187
+ # we only want to invoke the hook once for every compilation job
188
+ jobs = Set ()
188
189
function outer_hook (job)
189
- if ! in (job, kernels)
190
- $ inner_hook (job; $ (map (esc, user_kwargs)... ))
191
- push! (kernels, job)
190
+ if ! in (job, jobs)
191
+ # the user hook might invoke the compiler again, so disable the hook
192
+ old_hook = $ compile_hook[]
193
+ try
194
+ $ compile_hook[] = nothing
195
+ $ inner_hook (job; $ (map (esc, user_kwargs)... ))
196
+ finally
197
+ $ compile_hook[] = old_hook
198
+ end
199
+ push! (jobs, job)
192
200
end
193
201
end
194
202
195
- if $ compile_hook[] != = nothing
196
- error (" Chaining multiple @device_code calls is unsupported" )
197
- end
203
+ # now invoke the user code with this hook in place
198
204
try
199
205
$ compile_hook[] = outer_hook
200
206
$ (esc (user_code))
201
207
finally
202
208
$ compile_hook[] = nothing
203
209
end
204
210
205
- if isempty (kernels )
211
+ if isempty (jobs )
206
212
error (" no kernels executed while evaluating the given expression" )
207
213
end
208
214
0 commit comments