@@ -319,20 +319,59 @@ function overdub_pass!(reflection::Reflection,
319
319
end
320
320
321
321
#= == mark all `llvmcall`s as nooverdub ===#
322
- # TODO : this only works for: `Intrinsics.llvmcall` and not `Core.Intrinsics.llvmcall`
323
- # since there is a getproperty call in the way.
322
+ function unravel_intrinsics (x)
323
+ stmt = Base. Meta. isexpr (x, :(= )) ? x. args[2 ] : x
324
+ if Base. Meta. isexpr (stmt, :call )
325
+ applycall = is_ir_element (stmt. args[1 ], GlobalRef (Core, :_apply ), overdubbed_code)
326
+ f = applycall ? stmt. args[2 ] : stmt. args[1 ]
327
+ f = ir_element (f, overdubbed_code)
328
+ if f isa Expr && Base. Meta. isexpr (f, :call ) &&
329
+ is_ir_element (f. args[1 ], GlobalRef (Base, :getproperty ), overdubbed_code)
330
+
331
+ # resolve getproperty here
332
+ mod = ir_element (f. args[2 ], overdubbed_code)
333
+ if mod isa GlobalRef
334
+ mod = resolve_early (mod) # returns nothing if fails
335
+ mod === nothing && return nothing
336
+ end
337
+ fname = ir_element (f. args[3 ], overdubbed_code)
338
+ if fname isa QuoteNode
339
+ fname = fname. value
340
+ end
341
+ f = GlobalRef (mod, fname)
342
+ end
343
+ if f isa GlobalRef
344
+ f = resolve_early (f)
345
+ end
346
+ return f
347
+ end
348
+ return nothing
349
+ end
350
+
324
351
# TODO : Need to fix for `istaggingenabled == true`
352
+ # TODO : add user-facing flag to do this for all intrinsics
325
353
if ! iskwfunc && ! istaggingenabled
326
354
insert_statements! (overdubbed_code, overdubbed_codelocs,
327
355
(x, i) -> begin
328
- if Base. Meta. isexpr (x, :call ) &&
329
- is_ir_element (x. args[1 ], GlobalRef (Core. Intrinsics, :llvmcall ), overdubbed_code)
356
+ intrinsic = unravel_intrinsics (x)
357
+ if intrinsic === nothing
358
+ return nothing
359
+ end
360
+ if intrinsic === Core. Intrinsics. llvmcall
330
361
return 1
331
362
end
332
- return nothing
333
363
end ,
334
364
(x, i) -> begin
335
- [Expr (:call , Expr (:nooverdub , GlobalRef (Core. Intrinsics, :llvmcall )), x. args[2 : end ]. .. )]
365
+ stmt = Base. Meta. isexpr (x, :(= )) ? x. args[2 ] : x
366
+ applycall = is_ir_element (stmt. args[1 ], GlobalRef (Core, :_apply ), overdubbed_code)
367
+ intrinsic = unravel_intrinsics (x)
368
+ if applycall
369
+ # using stmt.args[2] instead of `intrinsic` leads to a bug
370
+ stmt. args[2 ] = Expr (:nooverdub , intrinsic)
371
+ else
372
+ stmt. args[1 ] = Expr (:nooverdub , intrinsic)
373
+ end
374
+ [x]
336
375
end )
337
376
end
338
377
0 commit comments