Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Experimental API for may-happen in parallel parallelism #39773

Open
wants to merge 97 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
1b65c4e
Experimental API for may-happen in parallel parallelism
tkf Feb 21, 2021
832840e
Fix miscompilation due to SROA
tkf Feb 24, 2021
0cff766
Lower Tapir after inlining
tkf Mar 3, 2021
8033f9a
Merge branch 'master' into tkf/jltapir-pr
tkf Jun 25, 2021
95b7f4b
Fix unremoved syncregion in outlined tasks
tkf Apr 23, 2021
2e89f46
Merge branch 'master' into tkf/jltapir-pr
tkf Jun 25, 2021
97e1ab2
Dispatchable Tapir.sync!
tkf Jun 22, 2021
02bbe8b
Lower Tapir.Output to Upsilon
tkf Jun 22, 2021
551d38f
Handle possibly-unset upsilon nodes
tkf Jun 22, 2021
8bb9124
Support SROA via PhiC
tkf Jun 24, 2021
a3a5c4a
Add lower_tapir_to_ircode
tkf Jun 25, 2021
65a5441
Minor refactoring
tkf Jun 26, 2021
312131e
Use compact! in fixup_tapir_phi!
tkf Jun 26, 2021
c2f9ef4
Don't remove unreachables
tkf Jun 26, 2021
25b928c
Catch exception in continuations
tkf Jun 25, 2021
a663092
Fix an exception thrown in inference
tkf Jun 26, 2021
551f483
Fix a bug with unreachable spawns
tkf Jun 27, 2021
3345af7
Don't spawn trivial thunk
tkf Jun 28, 2021
9c0f54c
Support nested spawns
tkf Jun 28, 2021
6214038
Analyze nested tasks in one pass
tkf Jun 28, 2021
bb12053
Don't spawn when continuation is trivial
tkf Jun 28, 2021
d5a1c80
Support pre-defined output
tkf Jun 29, 2021
d9a0c1c
Support conditional output
tkf Jun 29, 2021
37d6036
Cleanup
tkf Jun 29, 2021
5a9ad86
Don't spawn tasks that always throw
tkf Jun 29, 2021
3c50fc8
Use primary_world
tkf Jun 30, 2021
b381848
Static dispatch to runtime
tkf Jun 30, 2021
7d485dc
Fall-through detach for easier serial projection
tkf Jun 30, 2021
9197c06
Use mutable struct for task output
tkf Jul 1, 2021
b435bcb
Remove spawn late
tkf Jul 1, 2021
62e0c6f
Fix/add some comments
tkf Jul 2, 2021
6127a1c
Fix SROA
tkf Jul 2, 2021
a2376e2
Improve detected racy error
tkf Jul 2, 2021
a9338a2
Avoid explicit recursion for task tree traversal
tkf Jul 2, 2021
29d8e0a
Worklistify
tkf Jul 2, 2021
1b2b580
Keep task output slots in IRCode
tkf Jul 3, 2021
3da5359
Support conditionally defined task outputs
tkf Jul 4, 2021
46d1e72
Use a new AST node for declaring task outputs
tkf Jul 4, 2021
3225567
Fix race detection
tkf Jul 5, 2021
13fea8f
Fix spellings
tkf Jul 6, 2021
72e40a3
Cleanup
tkf Jul 6, 2021
0ae349a
Stop using insert_new_nodes
tkf Jul 6, 2021
5903aab
Document allocate_new_blocks! etc.
tkf Jul 6, 2021
d3c6f1a
Cleanup
tkf Jul 6, 2021
687fe6c
Remove a stale workaround in check_op
tkf Jul 6, 2021
fff7019
Remove is_sequential; properly define has_tapir
tkf Jul 6, 2021
cae8666
Implement verify_ir for Tapir
tkf Jul 6, 2021
460fac7
Remove remove_tapir!(src::CodeInfo)
tkf Jul 6, 2021
0e42c3e
Cleanup
tkf Jul 7, 2021
b12a3bc
Merge branch 'master'
tkf Jul 12, 2021
f6c263a
Handle deleted syncregion
tkf Jul 6, 2021
c58dc7f
Allow slot in typ_for_val
tkf Jul 6, 2021
f5ea99f
Remove PhiC/Upsilon-based task output lowering
tkf Jul 8, 2021
11bd862
Try not to allocate TaskGroup if possible
tkf Jul 8, 2021
8d32706
Root newly created src in jl_emit_code
tkf Jul 9, 2021
0ce4bbb
Null out some GC roots
tkf Jul 10, 2021
bcd19f4
Specify taskgroup in frontend
tkf Jul 11, 2021
fd4bd89
Dispatch Tapir.spawn on TaskGroup type
tkf Jul 12, 2021
fb42845
Fix verify_ir return type
tkf Jul 12, 2021
8db2fc9
Infer Tapir.spawn output type
tkf Jul 13, 2021
989612e
Test outputs set before spawn
tkf Jul 13, 2021
a76bbc8
Specify TaskGroup via `Tapir.@sync`
tkf Jul 13, 2021
ea93844
Fix optimize_taskgroups!
tkf Jul 14, 2021
2db948e
Merge branch 'master'
tkf Jul 14, 2021
2177d1a
Fix sync_return_type
tkf Jul 14, 2021
061b7e3
Use stmt_effect_free in is_trivial_for_spawn
tkf Jul 16, 2021
d0e73dc
Fix a typo
tkf Jul 16, 2021
59923d0
Ad-hoc remark API
tkf Jul 16, 2021
6e52f92
Use the effect free flag
tkf Jul 16, 2021
cdb6ad7
Add Tapir.dontoptimize
tkf Jul 16, 2021
15f7f3c
Fix a typo
tkf Jul 17, 2021
ebfe83d
Implement "SROA" on task output
tkf Jul 17, 2021
b2cb2a3
Implement dead store elimination for task output
tkf Jul 17, 2021
11c4afd
Set inferred flag
tkf Jul 19, 2021
c385087
Use GlobalRef
tkf Jul 20, 2021
0218d76
Enhance/fix documentation and comments
tkf Jul 21, 2021
a4435b0
Fix a typo in stmt_effect_free usage
tkf Jul 22, 2021
b40e220
Disambiguate synctasks
tkf Jul 23, 2021
c799255
Merge branch 'master' into tkf/jltapir-pr
tkf Jul 23, 2021
bb9e95a
Fix a stale docstring
tkf Jul 24, 2021
43b2013
Formatting
tkf Jul 24, 2021
c0b7da7
Remove unintended merge artifact
tkf Jul 24, 2021
cf0b0c7
Use Tuple as opaque closure self type
tkf Jul 24, 2021
3efd899
Merge branch 'master' into tkf/jltapir-pr
tkf Oct 25, 2021
3c25b37
Post-merge fixups
tkf Oct 21, 2021
c0e3d23
Example for disallow_detach_after_sync!
tkf Oct 26, 2021
30416fe
More robust invoke_escaped_spawn test
tkf Oct 26, 2021
368024f
Fix a bug in resolve_syncregion
tkf Oct 26, 2021
36eafe0
Merge branch 'master' into tkf/jltapir-pr
tkf Nov 8, 2021
de252be
Post-merge fix: convert_to_ircode signature
tkf Nov 8, 2021
2baa44f
Fix Tapir DSE for half-constructed Tapir module
tkf Nov 9, 2021
fd1f826
Merge branch 'master' into tkf/jltapir-pr
tkf Nov 18, 2021
54b8c59
Merge branch 'master' into tkf/jltapir-pr
tkf Nov 18, 2021
298da7d
Merge branch 'master' into tkf/jltapir-pr
tkf Dec 7, 2021
97d3cec
Fix a typo (not `slot2ref`)
tkf Dec 7, 2021
d43027d
Rename parallel_getfield_elim_checker -> parallel_sroa_checker
tkf Dec 7, 2021
3bbc6e1
Merge branch 'master' into tkf/jltapir-pr
tkf Dec 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@
# name::Symbol
#end

#struct DetachNode
# syncregion
# label::Int
# reattach::Int
#end

#struct ReattachNode
# syncregion
# label::Int
#end

#struct SyncNode
# syncregion
#end

#mutable struct Task
# parent::Task
# storage::Any
Expand Down Expand Up @@ -415,6 +430,11 @@ eval(Core, :(PiNode(val, typ) = $(Expr(:new, :PiNode, :val, :typ))))
eval(Core, :(PhiCNode(values::Array{Any, 1}) = $(Expr(:new, :PhiCNode, :values))))
eval(Core, :(UpsilonNode(val) = $(Expr(:new, :UpsilonNode, :val))))
eval(Core, :(UpsilonNode() = $(Expr(:new, :UpsilonNode))))
eval(Core, :(LineInfoNode(@nospecialize(method), file::Symbol, line::Int, inlined_at::Int) =
tkf marked this conversation as resolved.
Show resolved Hide resolved
$(Expr(:new, :LineInfoNode, :method, :file, :line, :inlined_at))))
eval(Core, :(SyncNode(token) = $(Expr(:new, :SyncNode, :token))))
eval(Core, :(DetachNode(token, bb::Int, reattach::Int) = $(Expr(:new, :DetachNode, :token, :bb, :reattach))))
eval(Core, :(ReattachNode(token, bb::Int) = $(Expr(:new, :ReattachNode, :token, :bb))))
eval(Core, :(LineInfoNode(mod::Module, @nospecialize(method), file::Symbol, line::Int, inlined_at::Int) =
$(Expr(:new, :LineInfoNode, :mod, :method, :file, :line, :inlined_at))))
eval(Core, :(CodeInstance(mi::MethodInstance, @nospecialize(rettype), @nospecialize(inferred_const),
Expand Down Expand Up @@ -497,11 +517,13 @@ module IR
export CodeInfo, MethodInstance, CodeInstance, GotoNode, GotoIfNot, ReturnNode,
NewvarNode, SSAValue, Slot, SlotNumber, TypedSlot, Argument,
PiNode, PhiNode, PhiCNode, UpsilonNode, LineInfoNode,
DetachNode, ReattachNode, SyncNode,
Const, PartialStruct

import Core: CodeInfo, MethodInstance, CodeInstance, GotoNode, GotoIfNot, ReturnNode,
NewvarNode, SSAValue, Slot, SlotNumber, TypedSlot, Argument,
PiNode, PhiNode, PhiCNode, UpsilonNode, LineInfoNode,
DetachNode, ReattachNode, SyncNode,
Const, PartialStruct

end
Expand Down
18 changes: 17 additions & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,21 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState)
changes[sn] = VarState(Bottom, true)
elseif isa(stmt, GotoNode)
pc´ = (stmt::GotoNode).label
elseif isa(stmt, DetachNode)
# A detach node has two edges we need to add
# the reattach edge to the work queue
l = (stmt::DetachNode).reattach
newstate_reattach = stupdate!(s[l], changes)
if newstate_reattach !== nothing
if l < frame.pc´´
frame.pc´´ = l
end
push!(W, l)
s[l] = newstate_reattach
end
pc´ = (stmt::DetachNode).label
elseif isa(stmt, ReattachNode)
pc´ = (stmt::ReattachNode).label
elseif isa(stmt, GotoIfNot)
condt = abstract_eval_value(interp, stmt.cond, changes, frame)
if condt === Bottom
Expand Down Expand Up @@ -1536,7 +1551,8 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState)
if isa(fname, Slot)
changes = StateUpdate(fname, VarState(Any, false), changes)
end
elseif hd === :inbounds || hd === :meta || hd === :loopinfo || hd === :code_coverage_effect
elseif hd === :inbounds || hd === :meta || hd === :loopinfo || hd === :code_coverage_effect ||
(stmt isa SyncNode)
# these do not generate code
else
t = abstract_eval_statement(interp, stmt, changes, frame)
Expand Down
17 changes: 17 additions & 0 deletions base/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ ntuple(f, ::Val{3}) = (@_inline_meta; (f(1), f(2), f(3)))
ntuple(f, ::Val{n}) where {n} = ntuple(f, n::Int)
ntuple(f, n) = (Any[f(i) for i = 1:n]...,)

all(xs) = all(identity, xs)
function all(f, xs)
for x in xs
f(x) || return false
end
return true
end

any(xs) = any(identity, xs)
function any(f, xs)
for x in xs
f(x) && return true
end
return false
end

# core docsystem
include("docs/core.jl")

Expand Down Expand Up @@ -121,6 +137,7 @@ include("compiler/stmtinfo.jl")
include("compiler/abstractinterpretation.jl")
include("compiler/typeinfer.jl")
include("compiler/optimize.jl") # TODO: break this up further + extract utilities
include("compiler/tapirpasses.jl")

include("compiler/bootstrap.jl")
ccall(:jl_set_typeinf_func, Cvoid, (Any,), typeinf_ext_toplevel)
Expand Down
24 changes: 23 additions & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ end
# if there is no usage within the function), but don't affect the purity
# of the function as a whole.
function stmt_affects_purity(@nospecialize(stmt), ir)
if isa(stmt, GotoNode) || isa(stmt, ReturnNode)
if isa(stmt, GotoNode) || isa(stmt, ReturnNode) ||
isa(stmt, DetachNode) || isa(stmt, ReattachNode) || isa(stmt, SyncNode)
tkf marked this conversation as resolved.
Show resolved Hide resolved
return false
end
if isa(stmt, GotoIfNot)
Expand Down Expand Up @@ -469,6 +470,27 @@ function renumber_ir_elements!(body::Vector{Any}, ssachangemap::Vector{Int}, lab
if isdefined(el, :val) && isa(el.val, SSAValue)
body[i] = ReturnNode(SSAValue(el.val.id + ssachangemap[el.val.id]))
end
elseif isa(el, DetachNode)
syncregion = el.syncregion
if isa(syncregion, SSAValue)
syncregion = SSAValue(syncregion.id + ssachangemap[syncregion.id])
tkf marked this conversation as resolved.
Show resolved Hide resolved
end
label = el.label + labelchangemap[el.label]
reattach = el.reattach + labelchangemap[el.reattach]
body[i] = DetachNode(syncregion, label, reattach)
elseif isa(el, ReattachNode)
syncregion = el.syncregion
if isa(syncregion, SSAValue)
syncregion = SSAValue(syncregion.id + ssachangemap[syncregion.id])
tkf marked this conversation as resolved.
Show resolved Hide resolved
end
label = el.label + labelchangemap[el.label]
body[i] = ReattachNode(syncregion, label)
elseif isa(el, SyncNode)
syncregion = el.syncregion
if isa(syncregion, SSAValue)
syncregion = SSAValue(syncregion.id + ssachangemap[syncregion.id])
tkf marked this conversation as resolved.
Show resolved Hide resolved
end
body[i] = SyncNode(syncregion)
elseif isa(el, SSAValue)
body[i] = SSAValue(el.id + ssachangemap[el.id])
elseif isa(el, Expr)
Expand Down
2 changes: 2 additions & 0 deletions base/compiler/ssair/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function run_passes(ci::CodeInfo, nargs::Int, sv::OptimizationState)
ir = slot2reg(ir, ci, nargs, sv)
#@Base.show ("after_construct", ir)
# TODO: Domsorting can produce an updated domtree - no need to recompute here
@timeit "Early tapir" ir = early_tapir_pass!(ir)
@timeit "compact 1" ir = compact!(ir)
@timeit "Inlining" ir = ssa_inlining_pass!(ir, ir.linetable, sv.inlining, ci.propagate_inbounds)
#@timeit "verify 2" verify_ir(ir)
Expand All @@ -138,6 +139,7 @@ function run_passes(ci::CodeInfo, nargs::Int, sv::OptimizationState)
@timeit "type lift" ir = type_lift_pass!(ir)
@timeit "compact 3" ir = compact!(ir)
#@Base.show ir
@timeit "tapir" ir = lower_tapir!(ir)
if JLOptions().debug_level == 2
@timeit "verify 3" (verify_ir(ir); verify_linetable(ir.linetable))
end
Expand Down
8 changes: 8 additions & 0 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
end
elseif isa(stmt′, GotoNode)
stmt′ = GotoNode(stmt′.label + bb_offset)
elseif isa(stmt′, DetachNode)
stmt′ = DetachNode(stmt′.syncregion, stmt′.label + bb_offset, stmt′.reattach + bb_offset)
elseif isa(stmt′, ReattachNode)
stmt′ = ReattachNode(stmt′.syncregion, stmt′.label + bb_offset)
elseif isa(stmt′, Expr) && stmt′.head === :enter
stmt′ = Expr(:enter, stmt′.args[1] + bb_offset)
elseif isa(stmt′, GotoIfNot)
Expand Down Expand Up @@ -559,6 +563,10 @@ function batch_inline!(todo::Vector{Pair{Int, Any}}, ir::IRCode, linetable::Vect
end
elseif isa(stmt, GotoNode)
compact[idx] = GotoNode(state.bb_rename[stmt.label])
elseif isa(stmt, DetachNode)
compact[idx] = DetachNode(stmt.syncregion, state.bb_rename[stmt.label], state.bb_rename[stmt.reattach])
elseif isa(stmt, ReattachNode)
compact[idx] = ReattachNode(stmt.syncregion, state.bb_rename[stmt.label])
elseif isa(stmt, Expr) && stmt.head === :enter
compact[idx] = Expr(:enter, state.bb_rename[stmt.args[1]])
elseif isa(stmt, GotoIfNot)
Expand Down
62 changes: 60 additions & 2 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@inline isexpr(@nospecialize(stmt), head::Symbol) = isa(stmt, Expr) && stmt.head === head
Core.PhiNode() = Core.PhiNode(Int32[], Any[])

# TODO: add detach/reattach?
isterminator(@nospecialize(stmt)) = isa(stmt, GotoNode) || isa(stmt, GotoIfNot) || isa(stmt, ReturnNode)

struct CFG
Expand Down Expand Up @@ -50,6 +51,13 @@ function basic_blocks_starts(stmts::Vector{Any})
# This is a fake dest to force the next stmt to start a bb
idx < length(stmts) && push!(jump_dests, idx+1)
push!(jump_dests, stmt.label)
elseif isa(stmt, DetachNode)
push!(jump_dests, stmt.label)
push!(jump_dests, stmt.reattach)
elseif isa(stmt, ReattachNode)
push!(jump_dests, stmt.label)
elseif isa(stmt, SyncNode)
push!(jump_dests, idx+1)
elseif isa(stmt, Expr)
if stmt.head === :leave
# :leave terminates a BB
Expand Down Expand Up @@ -100,12 +108,22 @@ function compute_basic_blocks(stmts::Vector{Any})
# return never has any successors
continue
end
if isa(terminator, GotoNode)
if isa(terminator, GotoNode) || isa(terminator, ReattachNode)
block′ = block_for_inst(basic_block_index, terminator.label)
push!(blocks[block′].preds, num)
push!(b.succs, block′)
continue
end
if isa(terminator, DetachNode)
block′ = block_for_inst(basic_block_index, terminator.label)
push!(blocks[block′].preds, num)
push!(b.succs, block′)

block′ = block_for_inst(basic_block_index, terminator.reattach)
push!(blocks[block′].preds, num)
push!(b.succs, block′)
continue
end
# Conditional Branch
if isa(terminator, GotoIfNot)
block′ = block_for_inst(basic_block_index, terminator.dest)
Expand Down Expand Up @@ -290,6 +308,9 @@ function setindex!(x::IRCode, @nospecialize(repl), s::SSAValue)
return x
end

first_insert_for_bb(ir::IRCode, block::Int) =
first_insert_for_bb(ir.stmts.inst, ir.cfg, block)

# SSA values that need renaming
struct OldSSAValue
id::Int
Expand Down Expand Up @@ -347,6 +368,9 @@ function getindex(x::UseRef)
elseif isa(stmt, GotoIfNot)
x.op == 1 || return OOBToken()
return stmt.cond
elseif isa(stmt, DetachNode) || isa(stmt, ReattachNode) || isa(stmt, SyncNode)
x.op == 1 || return OOBToken()
return stmt.syncregion
elseif isa(stmt, ReturnNode)
isdefined(stmt, :val) || return OOBToken()
x.op == 1 || return OOBToken()
Expand Down Expand Up @@ -378,6 +402,7 @@ function is_relevant_expr(e::Expr)
:foreigncall, :isdefined, :copyast,
:undefcheck, :throw_undef_if_not,
:cfunction, :method, :pop_exception,
:syncregion,
:new_opaque_closure)
end

Expand All @@ -400,6 +425,15 @@ function setindex!(x::UseRef, @nospecialize(v))
elseif isa(stmt, GotoIfNot)
x.op == 1 || throw(BoundsError())
x.stmt = GotoIfNot(v, stmt.dest)
elseif isa(stmt, DetachNode)
x.op == 1 || throw(BoundsError())
x.stmt = DetachNode(v, stmt.label, stmt.reattach)
elseif isa(stmt, ReattachNode)
x.op == 1 || throw(BoundsError())
x.stmt = ReattachNode(v, stmt.label)
elseif isa(stmt, SyncNode)
x.op == 1 || throw(BoundsError())
x.stmt = SyncNode(v)
elseif isa(stmt, ReturnNode)
x.op == 1 || throw(BoundsError())
x.stmt = typeof(stmt)(v)
Expand All @@ -426,7 +460,8 @@ end
function userefs(@nospecialize(x))
relevant = (isa(x, Expr) && is_relevant_expr(x)) ||
isa(x, GotoIfNot) || isa(x, ReturnNode) ||
isa(x, PiNode) || isa(x, PhiNode) || isa(x, PhiCNode) || isa(x, UpsilonNode)
isa(x, PiNode) || isa(x, PhiNode) || isa(x, PhiCNode) || isa(x, UpsilonNode) ||
isa(x, DetachNode) || isa(x, ReattachNode) || isa(x, SyncNode)
return UseRefIterator(x, relevant)
end

Expand Down Expand Up @@ -489,6 +524,14 @@ function foreachssa(f, @nospecialize(stmt))
end
end

"""
insert_node!(ir::IRCode, postion::Int, type, statement, [attach_after=false])

Insert a `statement` that results in a value of given `type` before/after
`postion` if `attach_after` is `false`/ `true`. If called with the same
`position` multiple times with `attach_after=false`, the order of the calls
is reflected to the order of the statements that appear in the resulting IR.
"""
function insert_node!(ir::IRCode, pos::Int, @nospecialize(typ), @nospecialize(val), attach_after::Bool=false)
line = ir.stmts[pos][:line]
node = add!(ir.new_nodes, pos, attach_after)
Expand Down Expand Up @@ -956,6 +999,21 @@ function process_node!(compact::IncrementalCompact, result_idx::Int, inst::Instr
elseif isa(stmt, GlobalRef) || isa(stmt, GotoNode)
result[result_idx][:inst] = stmt
result_idx += 1
elseif isa(stmt, DetachNode) || isa(stmt, ReattachNode) || isa(stmt, SyncNode)
stmt = renumber_ssa2!(stmt, ssa_rename, used_ssas, late_fixup, result_idx, do_rename_ssa)
if compact.cfg_transforms_enabled
if isa(stmt, DetachNode)
stmt = DetachNode(
stmt.syncregion,
compact.bb_rename_succ[stmt.label],
compact.bb_rename_succ[stmt.reattach],
)
elseif isa(stmt, ReattachNode)
stmt = ReattachNode(stmt.syncregion, compact.bb_rename_succ[stmt.label])
end
end
result[result_idx][:inst] = stmt
result_idx += 1
elseif isa(stmt, GotoIfNot) && compact.cfg_transforms_enabled
stmt = renumber_ssa2!(stmt, ssa_rename, used_ssas, late_fixup, result_idx, do_rename_ssa)::GotoIfNot
result[result_idx][:inst] = stmt
Expand Down
10 changes: 10 additions & 0 deletions base/compiler/ssair/legacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ function inflate_ir(ci::CodeInfo, sptypes::Vector{Any}, argtypes::Vector{Any})
# Translate statement edges to bb_edges
if isa(stmt, GotoNode)
code[i] = GotoNode(block_for_inst(cfg, stmt.label))
elseif isa(stmt, DetachNode)
code[i] = DetachNode(stmt.syncregion, block_for_inst(cfg, stmt.label),
block_for_inst(cfg, stmt.reattach))
elseif isa(stmt, ReattachNode)
code[i] = ReattachNode(stmt.syncregion, block_for_inst(cfg, stmt.label))
elseif isa(stmt, GotoIfNot)
code[i] = GotoIfNot(stmt.cond, block_for_inst(cfg, stmt.dest))
elseif isa(stmt, PhiNode)
Expand Down Expand Up @@ -56,6 +61,11 @@ function replace_code_newstyle!(ci::CodeInfo, ir::IRCode, nargs::Int)
stmt = ci.code[i]
if isa(stmt, GotoNode)
stmt = GotoNode(first(ir.cfg.blocks[stmt.label].stmts))
elseif isa(stmt, DetachNode)
stmt = DetachNode(stmt.syncregion, first(ir.cfg.blocks[stmt.label].stmts),
first(ir.cfg.blocks[stmt.reattach].stmts))
elseif isa(stmt, ReattachNode)
stmt = ReattachNode(stmt.syncregion, first(ir.cfg.blocks[stmt.label].stmts))
elseif isa(stmt, GotoIfNot)
stmt = GotoIfNot(stmt.cond, first(ir.cfg.blocks[stmt.dest].stmts))
elseif isa(stmt, PhiNode)
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1146,12 +1146,12 @@ function cfg_simplify!(ir::IRCode)
# Compute (renamed) successors and predecessors given (renamed) block
function compute_succs(i)
orig_bb = follow_merged_succ(result_bbs[i])
return map(i -> bb_rename_succ[i], bbs[orig_bb].succs)
return Int[bb_rename_succ[i] for i in bbs[orig_bb].succs]
tkf marked this conversation as resolved.
Show resolved Hide resolved
end
function compute_preds(i)
orig_bb = result_bbs[i]
preds = bbs[orig_bb].preds
return map(pred -> bb_rename_pred[pred], preds)
return Int[bb_rename_pred[pred] for pred in preds]
end

BasicBlock[
Expand Down
3 changes: 3 additions & 0 deletions base/compiler/ssair/queries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ function stmt_effect_free(@nospecialize(stmt), @nospecialize(rt), src, sptypes::
isa(stmt, ReturnNode) && return false
isa(stmt, GotoNode) && return false
isa(stmt, GotoIfNot) && return false
isa(stmt, DetachNode) && return false
isa(stmt, ReattachNode) && return false
isa(stmt, SyncNode) && return false
isa(stmt, Slot) && return false # Slots shouldn't occur in the IR at this point, but let's be defensive here
isa(stmt, GlobalRef) && return isdefined(stmt.mod, stmt.name)
if isa(stmt, Expr)
Expand Down
Loading