@@ -169,16 +169,15 @@ const OC_MISMATCH_WARNING =
169
169
# Printing code representations in IR and assembly
170
170
171
171
function _dump_function (@nospecialize (f), @nospecialize (t), native:: Bool , wrapper:: Bool ,
172
- strip_ir_metadata:: Bool , dump_module:: Bool , syntax:: Symbol ,
173
- optimize:: Bool , debuginfo:: Symbol , binary:: Bool ,
174
- safepoints:: Bool = false )
172
+ raw:: Bool , dump_module:: Bool , syntax:: Symbol ,
173
+ optimize:: Bool , debuginfo:: Symbol , binary:: Bool )
175
174
params = CodegenParams (debug_info_kind= Cint (0 ),
176
- safepoint_on_entry= safepoints )
177
- _dump_function (f, t, native, wrapper, strip_ir_metadata , dump_module, syntax,
175
+ safepoint_on_entry= raw )
176
+ _dump_function (f, t, native, wrapper, raw , dump_module, syntax,
178
177
optimize, debuginfo, binary, params)
179
178
end
180
179
function _dump_function (@nospecialize (f), @nospecialize (t), native:: Bool , wrapper:: Bool ,
181
- strip_ir_metadata :: Bool , dump_module:: Bool , syntax:: Symbol ,
180
+ raw :: Bool , dump_module:: Bool , syntax:: Symbol ,
182
181
optimize:: Bool , debuginfo:: Symbol , binary:: Bool , params:: CodegenParams )
183
182
ccall (:jl_is_in_pure_context , Bool, ()) && error (" code reflection cannot be used from generated functions" )
184
183
if isa (f, Core. Builtin)
@@ -189,21 +188,21 @@ function _dump_function(@nospecialize(f), @nospecialize(t), native::Bool, wrappe
189
188
if ! isa (f, Core. OpaqueClosure)
190
189
world = Base. get_world_counter ()
191
190
match = Base. _which (signature_type (f, t); world)
192
- linfo = Core. Compiler. specialize_method (match)
191
+ mi = Core. Compiler. specialize_method (match)
193
192
# TODO : use jl_is_cacheable_sig instead of isdispatchtuple
194
- isdispatchtuple (linfo . specTypes) || (warning = GENERIC_SIG_WARNING)
193
+ isdispatchtuple (mi . specTypes) || (warning = GENERIC_SIG_WARNING)
195
194
else
196
195
world = UInt64 (f. world)
197
196
if Core. Compiler. is_source_inferred (f. source. source)
198
197
# OC was constructed from inferred source. There's only one
199
198
# specialization and we can't infer anything more precise either.
200
199
world = f. source. primary_world
201
- linfo = f. source. specializations:: Core.MethodInstance
200
+ mi = f. source. specializations:: Core.MethodInstance
202
201
Core. Compiler. hasintersect (typeof (f). parameters[1 ], t) || (warning = OC_MISMATCH_WARNING)
203
202
else
204
- linfo = Core. Compiler. specialize_method (f. source, Tuple{typeof (f. captures), t. parameters... }, Core. svec ())
205
- actual = isdispatchtuple (linfo . specTypes)
206
- isdispatchtuple (linfo . specTypes) || (warning = GENERIC_SIG_WARNING)
203
+ mi = Core. Compiler. specialize_method (f. source, Tuple{typeof (f. captures), t. parameters... }, Core. svec ())
204
+ actual = isdispatchtuple (mi . specTypes)
205
+ isdispatchtuple (mi . specTypes) || (warning = GENERIC_SIG_WARNING)
207
206
end
208
207
end
209
208
# get the code for it
@@ -218,25 +217,24 @@ function _dump_function(@nospecialize(f), @nospecialize(t), native::Bool, wrappe
218
217
end
219
218
if dump_module
220
219
# we want module metadata, so use LLVM to generate assembly output
221
- str = _dump_function_linfo_native (linfo , world, wrapper, syntax, debuginfo, binary, params)
220
+ str = _dump_function_native_assembly (mi , world, wrapper, syntax, debuginfo, binary, raw , params)
222
221
else
223
- # if we don't want the module metadata, just disassemble what our JIT has.
224
- # TODO : make it possible to hide the safepoint prologue here too.
225
- # once that works, it would be good to default to dump_module=false
226
- # just like code_llvm does.
227
- str = _dump_function_linfo_native (linfo, world, wrapper, syntax, debuginfo, binary)
222
+ # if we don't want the module metadata, just disassemble what our JIT has
223
+ str = _dump_function_native_disassembly (mi, world, wrapper, syntax, debuginfo, binary)
228
224
end
229
225
else
230
- str = _dump_function_linfo_llvm (linfo , world, wrapper, strip_ir_metadata , dump_module, optimize, debuginfo, params)
226
+ str = _dump_function_llvm (mi , world, wrapper, ! raw , dump_module, optimize, debuginfo, params)
231
227
end
232
228
str = warning * str
233
229
return str
234
230
end
235
231
236
- function _dump_function_linfo_native (linfo:: Core.MethodInstance , world:: UInt , wrapper:: Bool , syntax:: Symbol , debuginfo:: Symbol , binary:: Bool )
237
- str = ccall (:jl_dump_method_asm , Ref{String},
238
- (Any, UInt, Bool, Bool, Ptr{UInt8}, Ptr{UInt8}, Bool),
239
- linfo, world, false , wrapper, syntax, debuginfo, binary)
232
+ function _dump_function_native_disassembly (mi:: Core.MethodInstance , world:: UInt ,
233
+ wrapper:: Bool , syntax:: Symbol ,
234
+ debuginfo:: Symbol , binary:: Bool )
235
+ str = @ccall jl_dump_method_asm (mi:: Any , world:: UInt , false :: Bool , wrapper:: Bool ,
236
+ syntax:: Ptr{UInt8} , debuginfo:: Ptr{UInt8} ,
237
+ wrapper:: Bool ):: Ref{String}
240
238
return str
241
239
end
242
240
@@ -245,27 +243,30 @@ struct LLVMFDump
245
243
f:: Ptr{Cvoid} # opaque
246
244
end
247
245
248
- function _dump_function_linfo_native (linfo:: Core.MethodInstance , world:: UInt , wrapper:: Bool , syntax:: Symbol , debuginfo:: Symbol , binary:: Bool , params:: CodegenParams )
246
+ function _dump_function_native_assembly (mi:: Core.MethodInstance , world:: UInt ,
247
+ wrapper:: Bool , syntax:: Symbol , debuginfo:: Symbol ,
248
+ binary:: Bool , raw:: Bool , params:: CodegenParams )
249
249
llvmf_dump = Ref {LLVMFDump} ()
250
- ccall (:jl_get_llvmf_defn , Cvoid, (Ptr{LLVMFDump}, Any, UInt, Bool, Bool, CodegenParams), llvmf_dump, linfo, world, wrapper, true , params)
250
+ @ccall jl_get_llvmf_defn (llvmf_dump:: Ptr{LLVMFDump} ,mi:: Any , world:: UInt , wrapper:: Bool ,
251
+ true :: Bool , params:: CodegenParams ):: Cvoid
251
252
llvmf_dump[]. f == C_NULL && error (" could not compile the specified method" )
252
- str = ccall ( :jl_dump_function_asm , Ref{String} ,
253
- (Ptr{LLVMFDump}, Bool, Ptr{UInt8}, Ptr{UInt8}, Bool) ,
254
- llvmf_dump, false , syntax, debuginfo, binary)
253
+ str = @ ccall jl_dump_function_asm (llvmf_dump :: Ptr{LLVMFDump} , false :: Bool ,
254
+ syntax :: Ptr{UInt8} , debuginfo :: Ptr{UInt8} ,
255
+ binary:: Bool , raw :: Bool ) :: Ref{String}
255
256
return str
256
257
end
257
258
258
- function _dump_function_linfo_llvm (
259
- linfo :: Core.MethodInstance , world:: UInt , wrapper:: Bool ,
259
+ function _dump_function_llvm (
260
+ mi :: Core.MethodInstance , world:: UInt , wrapper:: Bool ,
260
261
strip_ir_metadata:: Bool , dump_module:: Bool ,
261
262
optimize:: Bool , debuginfo:: Symbol ,
262
263
params:: CodegenParams )
263
264
llvmf_dump = Ref {LLVMFDump} ()
264
- ccall (:jl_get_llvmf_defn , Cvoid, (Ptr{LLVMFDump}, Any, UInt, Bool, Bool, CodegenParams), llvmf_dump, linfo, world, wrapper, optimize, params)
265
+ @ccall jl_get_llvmf_defn (llvmf_dump:: Ptr{LLVMFDump} , mi:: Any , world:: UInt ,
266
+ wrapper:: Bool , optimize:: Bool , params:: CodegenParams ):: Cvoid
265
267
llvmf_dump[]. f == C_NULL && error (" could not compile the specified method" )
266
- str = ccall (:jl_dump_function_ir , Ref{String},
267
- (Ptr{LLVMFDump}, Bool, Bool, Ptr{UInt8}),
268
- llvmf_dump, strip_ir_metadata, dump_module, debuginfo)
268
+ str = @ccall jl_dump_function_ir (llvmf_dump:: Ptr{LLVMFDump} , strip_ir_metadata:: Bool ,
269
+ dump_module:: Bool , debuginfo:: Ptr{UInt8} ):: Ref{String}
269
270
return str
270
271
end
271
272
@@ -282,7 +283,7 @@ Keyword argument `debuginfo` may be one of source (default) or none, to specify
282
283
"""
283
284
function code_llvm (io:: IO , @nospecialize (f), @nospecialize (types), raw:: Bool ,
284
285
dump_module:: Bool = false , optimize:: Bool = true , debuginfo:: Symbol = :default )
285
- d = _dump_function (f, types, false , false , ! raw, dump_module, :intel , optimize, debuginfo, false , raw )
286
+ d = _dump_function (f, types, false , false , raw, dump_module, :intel , optimize, debuginfo, false )
286
287
if highlighting[:llvm ] && get (io, :color , false ):: Bool
287
288
print_llvm (io, d)
288
289
else
@@ -304,14 +305,14 @@ generic function and type signature to `io`.
304
305
* Specify verbosity of code comments by setting `debuginfo` to `:source` (default) or `:none`.
305
306
* If `binary` is `true`, also print the binary machine code for each instruction precedented by an abbreviated address.
306
307
* If `dump_module` is `false`, do not print metadata such as rodata or directives.
307
- * If `raw` is `false`, unintesting instructions (like the safepoint function prologue) are elided.
308
+ * If `raw` is `false`, uninteresting instructions (like the safepoint function prologue) are elided.
308
309
309
310
See also: [`@code_native`](@ref), [`code_llvm`](@ref), [`code_typed`](@ref) and [`code_lowered`](@ref)
310
311
"""
311
312
function code_native (io:: IO , @nospecialize (f), @nospecialize (types= Base. default_tt (f));
312
313
dump_module:: Bool = true , syntax:: Symbol = :intel , raw:: Bool = false ,
313
314
debuginfo:: Symbol = :default , binary:: Bool = false )
314
- d = _dump_function (f, types, true , false , false , dump_module, syntax, true , debuginfo, binary, raw )
315
+ d = _dump_function (f, types, true , false , raw , dump_module, syntax, true , debuginfo, binary)
315
316
if highlighting[:native ] && get (io, :color , false ):: Bool
316
317
print_native (io, d)
317
318
else
0 commit comments