@@ -359,11 +359,17 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
359
359
boundscheck = :off
360
360
end
361
361
end
362
+ if ! validate_sparams (sparam_vals)
363
+ sparam_vals = insert_node_here! (compact,
364
+ effect_free (NewInstruction (Expr (:call , Core. _compute_sparams, item. mi. def, argexprs... ), SimpleVector, topline)))
365
+ end
362
366
# If the iterator already moved on to the next basic block,
363
367
# temporarily re-open in again.
364
368
local return_value
365
369
sig = def. sig
366
370
# Special case inlining that maintains the current basic block if there's only one BB in the target
371
+ new_new_offset = length (compact. new_new_nodes)
372
+ late_fixup_offset = length (compact. late_fixup)
367
373
if spec. linear_inline_eligible
368
374
# compact[idx] = nothing
369
375
inline_compact = IncrementalCompact (compact, spec. ir, compact. result_idx)
@@ -372,7 +378,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
372
378
# face of rename_arguments! mutating in place - should figure out
373
379
# something better eventually.
374
380
inline_compact[idx′] = nothing
375
- stmt′ = ssa_substitute! (idx′, stmt′, argexprs, sig, sparam_vals, linetable_offset, boundscheck, compact )
381
+ stmt′ = ssa_substitute! (idx′, stmt′, argexprs, sig, sparam_vals, linetable_offset, boundscheck, inline_compact )
376
382
if isa (stmt′, ReturnNode)
377
383
val = stmt′. val
378
384
return_value = SSAValue (idx′)
@@ -383,7 +389,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
383
389
end
384
390
inline_compact[idx′] = stmt′
385
391
end
386
- just_fixup! (inline_compact)
392
+ just_fixup! (inline_compact, new_new_offset, late_fixup_offset )
387
393
compact. result_idx = inline_compact. result_idx
388
394
else
389
395
bb_offset, post_bb_id = popfirst! (todo_bbs)
@@ -397,7 +403,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
397
403
inline_compact = IncrementalCompact (compact, spec. ir, compact. result_idx)
398
404
for ((_, idx′), stmt′) in inline_compact
399
405
inline_compact[idx′] = nothing
400
- stmt′ = ssa_substitute! (idx′, stmt′, argexprs, sig, sparam_vals, linetable_offset, boundscheck, compact )
406
+ stmt′ = ssa_substitute! (idx′, stmt′, argexprs, sig, sparam_vals, linetable_offset, boundscheck, inline_compact )
401
407
if isa (stmt′, ReturnNode)
402
408
if isdefined (stmt′, :val )
403
409
val = stmt′. val
@@ -428,7 +434,7 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
428
434
end
429
435
inline_compact[idx′] = stmt′
430
436
end
431
- just_fixup! (inline_compact)
437
+ just_fixup! (inline_compact, new_new_offset, late_fixup_offset )
432
438
compact. result_idx = inline_compact. result_idx
433
439
compact. active_result_bb = inline_compact. active_result_bb
434
440
if length (pn. edges) == 1
@@ -896,8 +902,7 @@ function analyze_method!(match::MethodMatch, argtypes::Vector{Any},
896
902
end
897
903
end
898
904
899
- # Bail out if any static parameters are left as TypeVar
900
- validate_sparams (match. sparams) || return nothing
905
+ # validate_sparams(match.sparams) || return nothing
901
906
902
907
et = state. et
903
908
@@ -1104,7 +1109,7 @@ function inline_invoke!(
1104
1109
argtypes = invoke_rewrite (sig. argtypes)
1105
1110
if isa (result, ConstPropResult)
1106
1111
(; mi) = item = InliningTodo (result. result, argtypes)
1107
- validate_sparams (mi. sparam_vals) || return nothing
1112
+ # validate_sparams(mi.sparam_vals) || return nothing
1108
1113
if argtypes_to_type (argtypes) <: mi.def.sig
1109
1114
state. mi_cache != = nothing && (item = resolve_todo (item, state, flag))
1110
1115
handle_single_case! (ir, idx, stmt, item, todo, state. params, true )
@@ -1327,7 +1332,7 @@ function handle_const_prop_result!(
1327
1332
(; mi) = item = InliningTodo (result. result, argtypes)
1328
1333
spec_types = mi. specTypes
1329
1334
allow_abstract || isdispatchtuple (spec_types) || return false
1330
- validate_sparams (mi. sparam_vals) || return false
1335
+ # validate_sparams(mi.sparam_vals) || return false
1331
1336
state. mi_cache != = nothing && (item = resolve_todo (item, state, flag))
1332
1337
item === nothing && return false
1333
1338
push! (cases, InliningCase (spec_types, item))
@@ -1365,7 +1370,6 @@ function handle_const_opaque_closure_call!(
1365
1370
sig:: Signature , state:: InliningState , todo:: Vector{Pair{Int, Any}} )
1366
1371
item = InliningTodo (result. result, sig. argtypes)
1367
1372
isdispatchtuple (item. mi. specTypes) || return
1368
- validate_sparams (item. mi. sparam_vals) || return
1369
1373
state. mi_cache != = nothing && (item = resolve_todo (item, state, flag))
1370
1374
handle_single_case! (ir, idx, stmt, item, todo, state. params)
1371
1375
return nothing
@@ -1545,38 +1549,49 @@ function late_inline_special_case!(
1545
1549
end
1546
1550
1547
1551
function ssa_substitute! (idx:: Int , @nospecialize (val), arg_replacements:: Vector{Any} ,
1548
- @nospecialize (spsig), spvals:: SimpleVector ,
1552
+ @nospecialize (spsig), spvals:: Union{ SimpleVector, SSAValue} ,
1549
1553
linetable_offset:: Int32 , boundscheck:: Symbol , compact:: IncrementalCompact )
1550
1554
compact. result[idx][:flag ] &= ~ IR_FLAG_INBOUNDS
1551
1555
compact. result[idx][:line ] += linetable_offset
1552
- return ssa_substitute_op! (val, arg_replacements, spsig, spvals, boundscheck)
1556
+ return ssa_substitute_op! (val, arg_replacements, spsig, spvals, boundscheck, compact, idx )
1553
1557
end
1554
1558
1555
1559
function ssa_substitute_op! (@nospecialize (val), arg_replacements:: Vector{Any} ,
1556
- @nospecialize (spsig), spvals:: SimpleVector , boundscheck:: Symbol )
1560
+ @nospecialize (spsig), spvals:: Union{SimpleVector, SSAValue} , boundscheck:: Symbol ,
1561
+ compact:: IncrementalCompact , idx:: Int )
1557
1562
if isa (val, Argument)
1558
1563
return arg_replacements[val. n]
1559
1564
end
1560
1565
if isa (val, Expr)
1561
1566
e = val:: Expr
1562
1567
head = e. head
1563
1568
if head === :static_parameter
1564
- return quoted (spvals[e. args[1 ]:: Int ])
1569
+ if isa (spvals, SimpleVector)
1570
+ return quoted (spvals[e. args[1 ]:: Int ])
1571
+ else
1572
+ ret = insert_node! (compact, SSAValue (idx),
1573
+ effect_free (NewInstruction (Expr (:call , Core. _svec_ref, false , spvals, e. args[1 ]), Any)))
1574
+ return ret
1575
+ end
1565
1576
elseif head === :cfunction
1566
- @assert ! isa (spsig, UnionAll) || ! isempty (spvals)
1567
- e. args[3 ] = ccall (:jl_instantiate_type_in_env , Any, (Any, Any, Ptr{Any}), e. args[3 ], spsig, spvals)
1568
- e. args[4 ] = svec (Any[
1569
- ccall (:jl_instantiate_type_in_env , Any, (Any, Any, Ptr{Any}), argt, spsig, spvals)
1570
- for argt in e. args[4 ]:: SimpleVector ]. .. )
1577
+ if isa (spvals, SimpleVector)
1578
+ @assert ! isa (spsig, UnionAll) || ! isempty (spvals)
1579
+ e. args[3 ] = ccall (:jl_instantiate_type_in_env , Any, (Any, Any, Ptr{Any}), e. args[3 ], spsig, spvals)
1580
+ e. args[4 ] = svec (Any[
1581
+ ccall (:jl_instantiate_type_in_env , Any, (Any, Any, Ptr{Any}), argt, spsig, spvals)
1582
+ for argt in e. args[4 ]:: SimpleVector ]. .. )
1583
+ end
1571
1584
elseif head === :foreigncall
1572
- @assert ! isa (spsig, UnionAll) || ! isempty (spvals)
1573
- for i = 1 : length (e. args)
1574
- if i == 2
1575
- e. args[2 ] = ccall (:jl_instantiate_type_in_env , Any, (Any, Any, Ptr{Any}), e. args[2 ], spsig, spvals)
1576
- elseif i == 3
1577
- e. args[3 ] = svec (Any[
1578
- ccall (:jl_instantiate_type_in_env , Any, (Any, Any, Ptr{Any}), argt, spsig, spvals)
1579
- for argt in e. args[3 ]:: SimpleVector ]. .. )
1585
+ if isa (spvals, SimpleVector)
1586
+ @assert ! isa (spsig, UnionAll) || ! isempty (spvals)
1587
+ for i = 1 : length (e. args)
1588
+ if i == 2
1589
+ e. args[2 ] = ccall (:jl_instantiate_type_in_env , Any, (Any, Any, Ptr{Any}), e. args[2 ], spsig, spvals)
1590
+ elseif i == 3
1591
+ e. args[3 ] = svec (Any[
1592
+ ccall (:jl_instantiate_type_in_env , Any, (Any, Any, Ptr{Any}), argt, spsig, spvals)
1593
+ for argt in e. args[3 ]:: SimpleVector ]. .. )
1594
+ end
1580
1595
end
1581
1596
end
1582
1597
elseif head === :boundscheck
@@ -1591,7 +1606,7 @@ function ssa_substitute_op!(@nospecialize(val), arg_replacements::Vector{Any},
1591
1606
end
1592
1607
urs = userefs (val)
1593
1608
for op in urs
1594
- op[] = ssa_substitute_op! (op[], arg_replacements, spsig, spvals, boundscheck)
1609
+ op[] = ssa_substitute_op! (op[], arg_replacements, spsig, spvals, boundscheck, compact, idx )
1595
1610
end
1596
1611
return urs[]
1597
1612
end
0 commit comments