@@ -11,10 +11,11 @@ struct GotoIfNot
11
11
GotoIfNot (@nospecialize (cond), dest:: Int ) = new (cond, dest)
12
12
end
13
13
14
- struct ReturnNode{T}
15
- val:: T
16
- ReturnNode {T} (@nospecialize (val)) where {T} = new {T} (val:: T )
17
- ReturnNode {T} () where {T} = new {T} ()
14
+ struct ReturnNode
15
+ val
16
+ ReturnNode (@nospecialize (val)) = new (val)
17
+ # unassigned val indicates unreachable
18
+ ReturnNode () = new ()
18
19
end
19
20
20
21
"""
@@ -31,6 +32,8 @@ start(r::StmtRange) = 0
31
32
done (r:: StmtRange , state) = r. last - r. first < state
32
33
next (r:: StmtRange , state) = (r. first + state, state + 1 )
33
34
35
+ StmtRange (range:: UnitRange{Int} ) = StmtRange (first (range), last (range))
36
+
34
37
struct BasicBlock
35
38
stmts:: StmtRange
36
39
preds:: Vector{Int}
@@ -264,7 +267,7 @@ function done(it::UseRefIterator, use)
264
267
false
265
268
end
266
269
267
- function scan_ssa_use! (used:: IdSet{Int64} , @nospecialize (stmt))
270
+ function scan_ssa_use! (used, @nospecialize (stmt))
268
271
if isa (stmt, SSAValue)
269
272
push! (used, stmt. id)
270
273
end
@@ -340,9 +343,9 @@ mutable struct IncrementalCompact
340
343
end
341
344
342
345
struct TypesView
343
- compact :: IncrementalCompact
346
+ ir :: Union{IRCode, IncrementalCompact}
344
347
end
345
- types (compact :: IncrementalCompact ) = TypesView (compact )
348
+ types (ir :: Union{IRCode, IncrementalCompact} ) = TypesView (ir )
346
349
347
350
function getindex (compact:: IncrementalCompact , idx)
348
351
if idx < compact. result_idx
@@ -368,10 +371,16 @@ function setindex!(compact::IncrementalCompact, v, idx)
368
371
end
369
372
370
373
function getindex (view:: TypesView , idx)
371
- if idx < view. compact. result_idx
374
+ isa (idx, SSAValue) && (idx = idx. id)
375
+ if isa (view. ir, IncrementalCompact) && idx < view. compact. result_idx
372
376
return view. compact. result_types[idx]
373
377
else
374
- return view. compact. ir. types[idx]
378
+ ir = isa (view. ir, IncrementalCompact) ? view. ir. ir : view. ir
379
+ if idx <= length (ir. types)
380
+ return ir. types[idx]
381
+ else
382
+ return ir. new_nodes[idx - length (ir. types)][2 ]
383
+ end
375
384
end
376
385
end
377
386
@@ -457,7 +466,7 @@ function next(compact::IncrementalCompact, (idx, active_bb, old_result_idx)::Tup
457
466
compact. result_types[old_result_idx] = typ
458
467
compact. result_lines[old_result_idx] = new_line
459
468
result_idx = process_node! (compact, old_result_idx, new_node, new_idx, idx)
460
- (old_result_idx == result_idx) && return next (compact, (idx, result_idx))
469
+ (old_result_idx == result_idx) && return next (compact, (idx, active_bb, result_idx))
461
470
compact. result_idx = result_idx
462
471
return (old_result_idx, compact. result[old_result_idx]), (compact. idx, active_bb, compact. result_idx)
463
472
end
0 commit comments