1
2
3
4
5 package ssa
6
7
8
9 func copyelim(f *Func) {
10
11
12 for _, b := range f.Blocks {
13 for _, v := range b.Values {
14 copyelimValue(v)
15 }
16 }
17
18
19 for _, b := range f.Blocks {
20 for i, v := range b.ControlValues() {
21 if v.Op == OpCopy {
22 b.ReplaceControl(i, v.Args[0])
23 }
24 }
25 }
26
27
28 for _, name := range f.Names {
29 values := f.NamedValues[*name]
30 for i, v := range values {
31 if v.Op == OpCopy {
32 values[i] = v.Args[0]
33 }
34 }
35 }
36 }
37
38
39
40 func copySource(v *Value) *Value {
41 w := v.Args[0]
42
43
44
45
46
47
48
49
50
51 slow := w
52 var advance bool
53 for w.Op == OpCopy {
54 w = w.Args[0]
55 if w == slow {
56 w.reset(OpUnknown)
57 break
58 }
59 if advance {
60 slow = slow.Args[0]
61 }
62 advance = !advance
63 }
64
65
66
67
68
69 for v != w {
70 x := v.Args[0]
71 v.SetArg(0, w)
72 v = x
73 }
74 return w
75 }
76
77
78 func copyelimValue(v *Value) {
79 for i, a := range v.Args {
80 if a.Op == OpCopy {
81 v.SetArg(i, copySource(a))
82 }
83 }
84 }
85
View as plain text