@@ -122,17 +122,8 @@ function fixemup!(@specialize(slot_filter), @specialize(rename_slot), ir::IRCode
122
122
val = stmt. args[1 ]
123
123
if isa (val, SlotNumber)
124
124
slot = slot_id (val)
125
- if (ci. slotflags[slot] & SLOT_USEDUNDEF) == 0
126
- return true
127
- else
128
- ssa, undef_ssa = rename_slot (val)
129
- if ssa === UNDEF_TOKEN
130
- return false
131
- elseif ! isa (ssa, SSAValue) && ! isa (ssa, NewSSAValue)
132
- return true
133
- end
134
- return undef_ssa
135
- end
125
+ ssa, undef_ssa = rename_slot (val)
126
+ return undef_ssa
136
127
end
137
128
return stmt
138
129
end
569
560
struct NewSlotPhi{Phi}
570
561
ssaval:: NewSSAValue
571
562
node:: Phi
572
- undef_ssaval:: Union{NewSSAValue, Nothing }
563
+ undef_ssaval:: Union{NewSSAValue, Bool }
573
564
undef_node:: Union{Phi, Nothing}
574
565
end
575
566
@@ -646,11 +637,18 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, sv::OptimizationState,
646
637
# an upsilon node in the corresponding enter block
647
638
node = PhiCNode (Any[])
648
639
insertpoint = first_insert_for_bb (code, cfg, li)
640
+ @assert sv. bb_vartables[li] != = nothing
641
+ vt = sv. bb_vartables[li][idx]
642
+ typ = widenslotwrapper (ignorelimited (vt. typ))
649
643
phic_ssa = NewSSAValue (
650
644
insert_node! (ir, insertpoint,
651
- NewInstruction (node, Union{} )). id - length (ir. stmts))
645
+ NewInstruction (node, typ )). id - length (ir. stmts))
652
646
undef_node = undef_ssaval = nothing
653
- if (ci. slotflags[idx] & SLOT_USEDUNDEF) != 0
647
+ if vt. typ === Union{}
648
+ undef_ssaval = false
649
+ elseif ! vt. undef
650
+ undef_ssaval = true
651
+ else
654
652
undef_node = PhiCNode (Any[])
655
653
undef_ssaval = NewSSAValue (insert_node! (ir,
656
654
insertpoint, NewInstruction (undef_node, Bool)). id - length (ir. stmts))
@@ -667,14 +665,17 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, sv::OptimizationState,
667
665
for block in phiblocks
668
666
push! (phi_slots[block], idx)
669
667
node = PhiNode ()
670
- typ = sv. slottypes[idx]
671
- if sv. bb_vartables[block] != = nothing
672
- typ = widenslotwrapper (ignorelimited (sv. bb_vartables[block][idx]. typ))
673
- end
668
+ @assert sv. bb_vartables[block] != = nothing
669
+ vt = sv. bb_vartables[block][idx]
670
+ typ = widenslotwrapper (ignorelimited (vt. typ))
674
671
ssaval = NewSSAValue (insert_node! (ir,
675
672
first_insert_for_bb (code, cfg, block), NewInstruction (node, typ)). id - length (ir. stmts))
676
673
undef_node = undef_ssaval = nothing
677
- if (ci. slotflags[idx] & SLOT_USEDUNDEF) != 0
674
+ if vt. typ === Union{}
675
+ undef_ssaval = false
676
+ elseif ! vt. undef
677
+ undef_ssaval = true
678
+ else
678
679
undef_node = PhiNode ()
679
680
undef_ssaval = NewSSAValue (insert_node! (ir,
680
681
first_insert_for_bb (code, cfg, block), NewInstruction (undef_node, Bool)). id - length (ir. stmts))
@@ -728,38 +729,38 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, sv::OptimizationState,
728
729
else
729
730
push! (node. values, incoming_val)
730
731
end
731
- outgoing_def = true
732
- if (ci. slotflags[slot] & SLOT_USEDUNDEF) != 0
732
+ if undef_node != = nothing
733
733
push! (undef_node. edges, pred)
734
734
push! (undef_node. values, incoming_def)
735
- outgoing_def = undef_ssaval
736
735
end
737
736
738
- incoming_vals[slot] = Pair {Any, Any} (ssaval, outgoing_def )
737
+ incoming_vals[slot] = Pair {Any, Any} (ssaval, undef_ssaval )
739
738
end
740
739
(item in visited) && continue
741
- # Record Pi nodes if necessary
742
- if sv. bb_vartables[item] != = nothing
743
- for slot in 1 : length (sv. slottypes)
744
- (ival, idef) = incoming_vals[slot]
745
- (ival === SSAValue (- 1 )) && continue
746
- (ival === SSAValue (- 2 )) && continue
747
-
748
- varstate = sv. bb_vartables[item][slot]
749
- typ = widenslotwrapper (ignorelimited (varstate. typ))
750
- if ! ⊑ (𝕃ₒ, sv. slottypes[slot], typ)
751
- node = PiNode (ival, typ)
752
- ival = NewSSAValue (insert_node! (ir,
753
- first_insert_for_bb (code, cfg, item), NewInstruction (node, typ)). id - length (ir. stmts))
754
- incoming_vals[slot] = Pair {Any, Any} (ival, idef)
755
- end
756
- end
757
- end
758
740
# Record phi_C nodes if necessary
759
741
if haskey (new_phic_nodes, item)
760
742
for (; slot, insert) in new_phic_nodes[item]
761
743
(; ssaval, undef_ssaval) = insert
762
- incoming_vals[slot_id (slot)] = Pair {Any, Any} (ssaval, undef_ssaval === nothing ? true : undef_ssaval)
744
+ incoming_vals[slot_id (slot)] = Pair {Any, Any} (ssaval, undef_ssaval)
745
+ end
746
+ end
747
+ # Record Pi nodes if necessary
748
+ has_pinode = fill (false , length (sv. slottypes))
749
+ for slot in 1 : length (sv. slottypes)
750
+ (ival, idef) = incoming_vals[slot]
751
+ (ival === SSAValue (- 1 )) && continue
752
+ (ival === SSAValue (- 2 )) && continue
753
+ (ival === UNDEF_TOKEN) && continue
754
+
755
+ @assert sv. bb_vartables[item] != = nothing
756
+ varstate = sv. bb_vartables[item][slot]
757
+ typ = widenslotwrapper (ignorelimited (varstate. typ))
758
+ if ! ⊑ (𝕃ₒ, sv. slottypes[slot], typ)
759
+ node = PiNode (ival, typ)
760
+ ival = NewSSAValue (insert_node! (ir,
761
+ first_insert_for_bb (code, cfg, item), NewInstruction (node, typ)). id - length (ir. stmts))
762
+ incoming_vals[slot] = Pair {Any, Any} (ival, idef)
763
+ has_pinode[slot] = true
763
764
end
764
765
end
765
766
# Record initial upsilon nodes if necessary
@@ -788,6 +789,7 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, sv::OptimizationState,
788
789
(isa (stmt, PhiNode) || (isexpr (stmt, :(= )) && isa (stmt. args[2 ], PhiNode))) && continue
789
790
if isa (stmt, NewvarNode)
790
791
incoming_vals[slot_id (stmt. slot)] = Pair {Any, Any} (UNDEF_TOKEN, false )
792
+ has_pinode[slot_id (stmt. slot)] = false
791
793
code[idx] = nothing
792
794
else
793
795
stmt = rename_uses! (ir, ci, idx, stmt, incoming_vals)
@@ -814,6 +816,7 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, sv::OptimizationState,
814
816
thisdef = false
815
817
end
816
818
incoming_vals[id] = Pair {Any, Any} (thisval, thisdef)
819
+ has_pinode[id] = false
817
820
enter_block = item
818
821
while haskey (exc_handlers, enter_block)
819
822
(; enter_block, leave_block) = exc_handlers[enter_block]
@@ -840,11 +843,9 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, sv::OptimizationState,
840
843
# Unwrap any PiNodes before continuing, since they weren't considered during our
841
844
# dominance frontier calculation and so have to be used locally in each BB.
842
845
for (i, (ival, idef)) in enumerate (incoming_vals)
843
- if ival isa NewSSAValue
846
+ if has_pinode[i]
844
847
stmt = ir[new_to_regular (ival:: NewSSAValue , length (ir. stmts))][:stmt ]
845
- if stmt isa PiNode
846
- incoming_vals[i] = Pair {Any, Any} (stmt. val, idef)
847
- end
848
+ incoming_vals[i] = Pair {Any, Any} (stmt. val, idef)
848
849
end
849
850
end
850
851
for succ in cfg. blocks[item]. succs
@@ -896,20 +897,6 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, sv::OptimizationState,
896
897
end
897
898
end
898
899
end
899
- for (_, nodes) in new_phic_nodes
900
- for (; insert) in nodes
901
- (; node, ssaval) = insert
902
- new_typ = Union{}
903
- new_idx = ssaval. id
904
- node = new_nodes. stmts[new_idx]
905
- phic_values = (node[:stmt ]:: PhiCNode ). values
906
- for i = 1 : length (phic_values)
907
- typ = typ_for_val (phic_values[i], ci, ir, - 1 , sv. slottypes)
908
- new_typ = tmerge (𝕃ₒ, new_typ, typ)
909
- end
910
- node[:type ] = new_typ
911
- end
912
- end
913
900
# Renumber SSA values
914
901
@assert isempty (ir. stmts. type)
915
902
resize! (ir. stmts. type, nstmts)
0 commit comments