|
2 | 2 | let worst-phi-length = 0_sz; |
3 | 3 |
|
4 | 4 | let phi-merge(tctx-globals: TypeContext?, tctx-primary: PBTree<U64,PhiContextRow>, tctx-secondary: PBTree<U64,PhiContextRow>, blame: AST): PBTree<U64,PhiContextRow> = ( |
5 | | - phi-merge-inner(tctx-globals, tctx-primary, tctx-secondary, blame, mk-vector(type(U64))).second.prune-moved |
| 5 | + phi-merge-inner(tctx-globals, tctx-primary, tctx-secondary, blame, mk-set(type(U64))).second |
6 | 6 | ); |
7 | 7 |
|
8 | | - |
9 | | -let phi-merge-inner(tctx-globals: TypeContext?, tctx-primary: PBTree<U64,PhiContextRow>, tctx-secondary: PBTree<U64,PhiContextRow>, blame: AST, seen: Vector<U64>): (Vector<U64>, PBTree<U64,PhiContextRow>) = ( |
| 8 | +let phi-merge-inner(tctx-globals: TypeContext?, tctx-primary: PBTree<U64,PhiContextRow>, tctx-secondary: PBTree<U64,PhiContextRow>, blame: AST, seen: Set<U64>): (Set<U64>, PBTree<U64,PhiContextRow>) = ( |
10 | 9 | match tctx-secondary { |
11 | 10 | PBLeaf{} => (seen, tctx-primary); |
12 | 11 | PBNode1{ k1=k1, tr=v1, left=left, right=right } => ( |
13 | | - (seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, left, blame, seen); |
14 | | - let sid = tr.phi-id-or-zero; |
| 12 | + let sid = k1; |
15 | 13 | let st = tr.phi-tt-or-zero; |
16 | 14 | let pblame = tr.blame-or-zero; |
17 | 15 | let sdead-on-arrival = tr.dead-on-arrival-or-zero; |
18 | 16 | let sis-global = tr.is-global-or-zero; |
19 | | - if not(seen.contains(sid)) { |
20 | | - let pt = tctx-primary.lookup(sid, NullPhiContextRow); |
21 | | - if not(non-zero(pt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,pblame,sdead-on-arrival,sis-global)); |
22 | | - else if sdead-on-arrival or pt.dead-on-arrival-or-zero |
23 | | - then { |
24 | | - # This case happens if an ethereal variable gets copied and merged somehow, it doesn't really matter which one you pick but we prefer the moved one |
25 | | - if not(pt.phi-tt-or-zero.is-linear-live) then () |
26 | | - else tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,blame,true,sis-global)); |
27 | | - } else ( |
28 | | - let rt = tctx-globals.phi-merge(pt.phi-tt-or-zero, st, blame); |
29 | | - if not(is(pt.phi-tt-or-zero,rt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,rt,blame,false,sis-global)); |
30 | | - ); |
31 | | - seen = seen.push(sid); |
| 17 | + if not(seen.has(sid)) { |
| 18 | + if not st.is-linear-dead { |
| 19 | + let pt = tctx-primary.lookup(sid, NullPhiContextRow); |
| 20 | + if not(non-zero(pt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,pblame,sdead-on-arrival,sis-global)); |
| 21 | + else if sdead-on-arrival or pt.dead-on-arrival-or-zero |
| 22 | + then { |
| 23 | + # This case happens if an ethereal variable gets copied and merged somehow, it doesn't really matter which one you pick but we prefer the moved one |
| 24 | + if not(pt.phi-tt-or-zero.is-linear-live) then () |
| 25 | + else tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,blame,true,sis-global)); |
| 26 | + } else ( |
| 27 | + let rt = tctx-globals.phi-merge(pt.phi-tt-or-zero, st, blame); |
| 28 | + if not(is(pt.phi-tt-or-zero,rt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,rt,blame,false,sis-global)); |
| 29 | + ); |
| 30 | + }; |
| 31 | + seen = seen.bind(sid); |
32 | 32 | }; |
| 33 | + (seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, left, blame, seen); |
33 | 34 | (seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, right, blame, seen); |
34 | 35 | (seen, tctx-primary) |
35 | 36 | ); |
36 | 37 | PBNode2{ k12=k1, tr=v1, k22=k2, tr2=v2, left=left, mid=mid, right=right } => ( |
37 | | - (seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, left, blame, seen); |
38 | | - let sid = tr.phi-id-or-zero; |
| 38 | + let sid = k12; |
39 | 39 | let st = tr.phi-tt-or-zero; |
40 | 40 | let pblame = tr.blame-or-zero; |
41 | 41 | let sdead-on-arrival = tr.dead-on-arrival-or-zero; |
42 | 42 | let sis-global = tr.is-global-or-zero; |
43 | | - if not(seen.contains(sid)) { |
44 | | - let pt = tctx-primary.lookup(sid, NullPhiContextRow); |
45 | | - if not(non-zero(pt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,pblame,sdead-on-arrival,sis-global)); |
46 | | - else if sdead-on-arrival or pt.dead-on-arrival-or-zero |
47 | | - then { |
48 | | - # This case happens if an ethereal variable gets copied and merged somehow, it doesn't really matter which one you pick but we prefer the moved one |
49 | | - if not(pt.phi-tt-or-zero.is-linear-live) then () |
50 | | - else tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,blame,true,sis-global)); |
51 | | - } else ( |
52 | | - let rt = tctx-globals.phi-merge(pt.phi-tt-or-zero, st, blame); |
53 | | - if not(is(pt.phi-tt-or-zero,rt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,rt,blame,false,sis-global)); |
54 | | - ); |
55 | | - seen = seen.push(sid); |
| 43 | + if not(seen.has(sid)) { |
| 44 | + if not st.is-linear-dead { |
| 45 | + let pt = tctx-primary.lookup(sid, NullPhiContextRow); |
| 46 | + if not(non-zero(pt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,pblame,sdead-on-arrival,sis-global)); |
| 47 | + else if sdead-on-arrival or pt.dead-on-arrival-or-zero |
| 48 | + then { |
| 49 | + # This case happens if an ethereal variable gets copied and merged somehow, it doesn't really matter which one you pick but we prefer the moved one |
| 50 | + if not(pt.phi-tt-or-zero.is-linear-live) then () |
| 51 | + else tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,blame,true,sis-global)); |
| 52 | + } else ( |
| 53 | + let rt = tctx-globals.phi-merge(pt.phi-tt-or-zero, st, blame); |
| 54 | + if not(is(pt.phi-tt-or-zero,rt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,rt,blame,false,sis-global)); |
| 55 | + ); |
| 56 | + }; |
| 57 | + seen = seen.bind(sid); |
56 | 58 | }; |
57 | | - (seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, mid, blame, seen); |
58 | 59 | tr = tr2; |
59 | | - sid = tr.phi-id-or-zero; |
| 60 | + sid = k22; |
60 | 61 | st = tr.phi-tt-or-zero; |
61 | 62 | pblame = tr.blame-or-zero; |
62 | 63 | sdead-on-arrival = tr.dead-on-arrival-or-zero; |
63 | 64 | sis-global = tr.is-global-or-zero; |
64 | | - if not(seen.contains(sid)) { |
65 | | - let pt = tctx-primary.lookup(sid, NullPhiContextRow); |
66 | | - if not(non-zero(pt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,pblame,sdead-on-arrival,sis-global)); |
67 | | - else if sdead-on-arrival or pt.dead-on-arrival-or-zero |
68 | | - then { |
69 | | - # This case happens if an ethereal variable gets copied and merged somehow, it doesn't really matter which one you pick but we prefer the moved one |
70 | | - if not(pt.phi-tt-or-zero.is-linear-live) then () |
71 | | - else tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,blame,true,sis-global)); |
72 | | - } else ( |
73 | | - let rt = tctx-globals.phi-merge(pt.phi-tt-or-zero, st, blame); |
74 | | - if not(is(pt.phi-tt-or-zero,rt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,rt,blame,false,sis-global)); |
75 | | - ); |
76 | | - seen = seen.push(sid); |
| 65 | + if not(seen.has(sid)) { |
| 66 | + if not st.is-linear-dead { |
| 67 | + let pt = tctx-primary.lookup(sid, NullPhiContextRow); |
| 68 | + if not(non-zero(pt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,pblame,sdead-on-arrival,sis-global)); |
| 69 | + else if sdead-on-arrival or pt.dead-on-arrival-or-zero |
| 70 | + then { |
| 71 | + # This case happens if an ethereal variable gets copied and merged somehow, it doesn't really matter which one you pick but we prefer the moved one |
| 72 | + if not(pt.phi-tt-or-zero.is-linear-live) then () |
| 73 | + else tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,st,blame,true,sis-global)); |
| 74 | + } else ( |
| 75 | + let rt = tctx-globals.phi-merge(pt.phi-tt-or-zero, st, blame); |
| 76 | + if not(is(pt.phi-tt-or-zero,rt)) then tctx-primary = tctx-primary.bind(sid, PhiContextRow(sid,rt,blame,false,sis-global)); |
| 77 | + ); |
| 78 | + }; |
| 79 | + seen = seen.bind(sid); |
77 | 80 | }; |
| 81 | + (seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, left, blame, seen); |
| 82 | + (seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, mid, blame, seen); |
78 | 83 | (seen, tctx-primary) = phi-merge-inner(tctx-globals, tctx-primary, right, blame, seen); |
79 | 84 | (seen, tctx-primary) |
80 | 85 | ); |
|
0 commit comments