55
66const JL_MAX_TAGS = 64 # see `enum jl_small_typeof_tags` in julia.h
77
8+ function unbind (@nospecialize (val))
9+ if val isa Core. Binding
10+ return val. value
11+ else
12+ return val
13+ end
14+ end
15+
816function absint (@nospecialize (arg:: LLVM.Value ), partial:: Bool = false , istracked:: Bool = false , typetag:: Bool = false ):: Tuple{Bool, Any}
917 if (value_type (arg) == LLVM. PointerType (LLVM. StructType (LLVMType[]), Tracked)) || (value_type (arg) == LLVM. PointerType (LLVM. StructType (LLVMType[]), Derived)) || istracked
1018 ce, _ = get_base_and_offset (arg; offsetAllowed = false , inttoptr = true )
@@ -455,12 +463,14 @@ function abs_typeof(
455463 nm == " jl_gc_alloc_typed" ||
456464 nm == " ijl_gc_alloc_typed"
457465 vals = absint (operands (arg)[3 ], partial, false , #= typetag=# true )
466+ @assert ! (vals[2 ] isa Core. Binding)
458467 return (vals[1 ], vals[2 ], vals[1 ] ? GPUCompiler. BITS_REF : nothing )
459468 end
460469 # Type tag is arg 3
461470 if nm == " jl_alloc_genericmemory_unchecked" ||
462471 nm == " ijl_alloc_genericmemory_unchecked"
463472 vals = absint (operands (arg)[3 ], partial, true , #= typetag=# true )
473+ @assert ! (vals[2 ] isa Core. Binding)
464474 return (vals[1 ], vals[2 ], vals[1 ] ? GPUCompiler. MUT_REF : nothing )
465475 end
466476 # Type tag is arg 1
@@ -475,11 +485,13 @@ function abs_typeof(
475485 nm == " jl_alloc_genericmemory" ||
476486 nm == " ijl_alloc_genericmemory"
477487 vals = absint (operands (arg)[1 ], partial, false , #= typetag=# true )
488+ @assert ! (vals[2 ] isa Core. Binding)
478489 return (vals[1 ], vals[2 ], vals[1 ] ? GPUCompiler. MUT_REF : nothing )
479490 end
480491
481492 if nm == " jl_new_structt" || nm == " ijl_new_structt"
482493 vals = absint (operands (arg)[1 ], partial, false , #= typetag=# true )
494+ @assert ! (vals[2 ] isa Core. Binding)
483495 return (vals[1 ], vals[2 ], vals[1 ] ? GPUCompiler. MUT_REF : nothing )
484496 end
485497
@@ -498,6 +510,7 @@ function abs_typeof(
498510 if nm == " jl_new_structv" || nm == " ijl_new_structv"
499511 @assert index == 2
500512 vals = absint (operands (arg)[index], partial, false , #= typetag=# true )
513+ @assert ! (vals[2 ] isa Core. Binding)
501514 return (vals[1 ], vals[2 ], vals[1 ] ? GPUCompiler. MUT_REF : nothing )
502515 end
503516
@@ -531,9 +544,11 @@ function abs_typeof(
531544 if nm == " jl_f__apply_iterate" || nm == " ijl_f__apply_iterate"
532545 index += 1
533546 legal, iterfn = absint (operands (arg)[index])
547+ iterfn = unbind (iterfn)
534548 index += 1
535549 if legal && iterfn == Base. iterate
536550 legal0, combfn = absint (operands (arg)[index])
551+ combfn = unbind (combfn)
537552 index += 1
538553 if legal0 && combfn == Core. apply_type && partial
539554 return (true , Type, GPUCompiler. BITS_REF)
@@ -871,6 +886,7 @@ function abs_typeof(
871886
872887 legal, val = absint (arg, partial)
873888 if legal
889+ val = unbind (val)
874890 return (true , Core. Typeof (val), GPUCompiler. BITS_REF)
875891 end
876892 return (false , nothing , nothing )
0 commit comments