Skip to content

Commit edca4cd

Browse files
committed
cmd/compile/internal/gc: remove remaining Nod(OXXX, ...)
Remove almost all the remaining Nod(OXXX, ... ) uses. The performance change is due entirely to the changes to func temp(*Type). The other cleanups have no effect, as expected. I'll address the remaining Nod(OXXX, ...) uses in a followup CL as they are very sensitive to change. lucky(~/go/src/cmd/compile) % benchstat /tmp/{old,new}.txt name old time/op new time/op delta Template 391ms ± 6% 385ms ± 6% ~ (p=0.127 n=19+20) GoTypes 1.27s ± 2% 1.27s ± 2% ~ (p=0.172 n=19+19) Compiler 6.17s ± 2% 6.15s ± 2% ~ (p=0.647 n=19+20) name old alloc/op new alloc/op delta Template 63.7MB ± 0% 63.4MB ± 0% -0.35% (p=0.000 n=16+20) GoTypes 219MB ± 0% 218MB ± 0% -0.38% (p=0.000 n=20+20) Compiler 980MB ± 0% 976MB ± 0% -0.38% (p=0.000 n=20+20) name old allocs/op new allocs/op delta Template 586k ± 0% 584k ± 0% -0.30% (p=0.000 n=20+20) GoTypes 1.80M ± 0% 1.79M ± 0% -0.31% (p=0.000 n=20+20) Compiler 7.74M ± 0% 7.71M ± 0% -0.34% (p=0.000 n=20+20) Change-Id: Ie21a5443c33a23ce30f987bdddec9fe350365d35 Reviewed-on: https://go-review.googlesource.com/21017 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent babc735 commit edca4cd

File tree

8 files changed

+57
-80
lines changed

8 files changed

+57
-80
lines changed

src/cmd/compile/internal/gc/const.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ func convlit1(n *Node, t *Type, explicit bool) *Node {
117117
}
118118

119119
if n.Op == OLITERAL {
120-
nn := Nod(OXXX, nil, nil)
121-
*nn = *n
122-
n = nn
120+
nn := *n
121+
n = &nn
123122
}
124123

125124
switch n.Op {
@@ -559,11 +558,10 @@ func evconst(n *Node) {
559558
i2++
560559
}
561560

562-
nl := Nod(OXXX, nil, nil)
563-
*nl = *s[i1]
564-
nl.Orig = nl
561+
nl := *s[i1]
562+
nl.Orig = &nl
565563
nl.SetVal(Val{strings.Join(strs, "")})
566-
s[i1] = nl
564+
s[i1] = &nl
567565
s = append(s[:i1+1], s[i2:]...)
568566
}
569567
}
@@ -1250,9 +1248,8 @@ func defaultlit(n *Node, t *Type) *Node {
12501248
}
12511249

12521250
if n.Op == OLITERAL {
1253-
nn := Nod(OXXX, nil, nil)
1254-
*nn = *n
1255-
n = nn
1251+
nn := *n
1252+
n = &nn
12561253
}
12571254

12581255
lno := setlineno(n)

src/cmd/compile/internal/gc/dcl.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,6 @@ func funcargs(nt *Node) {
605605
// declare the out arguments.
606606
gen := nt.List.Len()
607607
var i int = 0
608-
var nn *Node
609608
for _, n = range nt.Rlist.Slice() {
610609
if n.Op != ODCLFIELD {
611610
Fatalf("funcargs out %v", Oconv(n.Op, 0))
@@ -629,13 +628,11 @@ func funcargs(nt *Node) {
629628
// So the two cases must be distinguished.
630629
// We do not record a pointer to the original node (n->orig).
631630
// Having multiple names causes too much confusion in later passes.
632-
nn = Nod(OXXX, nil, nil)
633-
634-
*nn = *n.Left
635-
nn.Orig = nn
631+
nn := *n.Left
632+
nn.Orig = &nn
636633
nn.Sym = LookupN("~b", gen)
637634
gen++
638-
n.Left = nn
635+
n.Left = &nn
639636
}
640637

641638
n.Left.Name.Param.Ntype = n.Right

src/cmd/compile/internal/gc/export.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,8 @@ func importconst(s *Sym, t *Type, n *Node) {
522522
}
523523

524524
if n.Sym != nil {
525-
n1 := Nod(OXXX, nil, nil)
526-
*n1 = *n
527-
n = n1
525+
n1 := *n
526+
n = &n1
528527
}
529528

530529
n.Orig = newname(s)

src/cmd/compile/internal/gc/gen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,8 @@ func Tempname(nn *Node, t *Type) {
613613
}
614614

615615
func temp(t *Type) *Node {
616-
n := Nod(OXXX, nil, nil)
617-
Tempname(n, t)
616+
var n Node
617+
Tempname(&n, t)
618618
n.Sym.Def.Used = true
619619
return n.Orig
620620
}

src/cmd/compile/internal/gc/inl.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ func inlcopy(n *Node) *Node {
249249
return n
250250
}
251251

252-
m := Nod(OXXX, nil, nil)
253-
*m = *n
252+
m := *n
254253
if m.Func != nil {
255254
m.Func.Inl.Set(nil)
256255
}
@@ -261,7 +260,7 @@ func inlcopy(n *Node) *Node {
261260
m.Ninit.Set(inlcopylist(n.Ninit.Slice()))
262261
m.Nbody.Set(inlcopylist(n.Nbody.Slice()))
263262

264-
return m
263+
return &m
265264
}
266265

267266
// Inlcalls/nodelist/node walks fn's statements and expressions and substitutes any
@@ -968,24 +967,24 @@ func (subst *inlsubst) node(n *Node) *Node {
968967
m.Left = newname(Lookup(p))
969968

970969
return m
971-
}
972-
973-
m := Nod(OXXX, nil, nil)
974-
*m = *n
975-
m.Ninit.Set(nil)
970+
default:
971+
m := Nod(OXXX, nil, nil)
972+
*m = *n
973+
m.Ninit.Set(nil)
976974

977-
if n.Op == OCLOSURE {
978-
Fatalf("cannot inline function containing closure: %v", Nconv(n, FmtSign))
979-
}
975+
if n.Op == OCLOSURE {
976+
Fatalf("cannot inline function containing closure: %v", Nconv(n, FmtSign))
977+
}
980978

981-
m.Left = subst.node(n.Left)
982-
m.Right = subst.node(n.Right)
983-
m.List.Set(subst.list(n.List))
984-
m.Rlist.Set(subst.list(n.Rlist))
985-
m.Ninit.Set(append(m.Ninit.Slice(), subst.list(n.Ninit)...))
986-
m.Nbody.Set(subst.list(n.Nbody))
979+
m.Left = subst.node(n.Left)
980+
m.Right = subst.node(n.Right)
981+
m.List.Set(subst.list(n.List))
982+
m.Rlist.Set(subst.list(n.Rlist))
983+
m.Ninit.Set(append(m.Ninit.Slice(), subst.list(n.Ninit)...))
984+
m.Nbody.Set(subst.list(n.Nbody))
987985

988-
return m
986+
return m
987+
}
989988
}
990989

991990
// Plaster over linenumbers

src/cmd/compile/internal/gc/order.go

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,10 @@ func ordercheapexpr(n *Node, order *Order) *Node {
107107
if l == n.Left {
108108
return n
109109
}
110-
a := Nod(OXXX, nil, nil)
111-
*a = *n
112-
a.Orig = a
110+
a := *n
111+
a.Orig = &a
113112
a.Left = l
114-
a = typecheck(a, Erv)
115-
return a
113+
return typecheck(&a, Erv)
116114
}
117115

118116
return ordercopyexpr(n, n.Type, order, 0)
@@ -135,24 +133,20 @@ func ordersafeexpr(n *Node, order *Order) *Node {
135133
if l == n.Left {
136134
return n
137135
}
138-
a := Nod(OXXX, nil, nil)
139-
*a = *n
140-
a.Orig = a
136+
a := *n
137+
a.Orig = &a
141138
a.Left = l
142-
a = typecheck(a, Erv)
143-
return a
139+
return typecheck(&a, Erv)
144140

145141
case ODOTPTR, OIND:
146142
l := ordercheapexpr(n.Left, order)
147143
if l == n.Left {
148144
return n
149145
}
150-
a := Nod(OXXX, nil, nil)
151-
*a = *n
152-
a.Orig = a
146+
a := *n
147+
a.Orig = &a
153148
a.Left = l
154-
a = typecheck(a, Erv)
155-
return a
149+
return typecheck(&a, Erv)
156150

157151
case OINDEX, OINDEXMAP:
158152
var l *Node
@@ -165,17 +159,15 @@ func ordersafeexpr(n *Node, order *Order) *Node {
165159
if l == n.Left && r == n.Right {
166160
return n
167161
}
168-
a := Nod(OXXX, nil, nil)
169-
*a = *n
170-
a.Orig = a
162+
a := *n
163+
a.Orig = &a
171164
a.Left = l
172165
a.Right = r
173-
a = typecheck(a, Erv)
174-
return a
166+
return typecheck(&a, Erv)
167+
default:
168+
Fatalf("ordersafeexpr %v", Oconv(n.Op, 0))
169+
return nil // not reached
175170
}
176-
177-
Fatalf("ordersafeexpr %v", Oconv(n.Op, 0))
178-
return nil // not reached
179171
}
180172

181173
// Istemp reports whether n is a temporary variable.

src/cmd/compile/internal/gc/racewalk.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,10 @@ func instrument(fn *Node) {
6565
// nodpc is the PC of the caller as extracted by
6666
// getcallerpc. We use -widthptr(FP) for x86.
6767
// BUG: this will not work on arm.
68-
nodpc := Nod(OXXX, nil, nil)
69-
70-
*nodpc = *nodfp
68+
nodpc := *nodfp
7169
nodpc.Type = Types[TUINTPTR]
7270
nodpc.Xoffset = int64(-Widthptr)
73-
nd := mkcall("racefuncenter", nil, nil, nodpc)
71+
nd := mkcall("racefuncenter", nil, nil, &nodpc)
7472
fn.Func.Enter.Set(append([]*Node{nd}, fn.Func.Enter.Slice()...))
7573
nd = mkcall("racefuncexit", nil, nil)
7674
fn.Func.Exit.Append(nd)

src/cmd/compile/internal/gc/subr.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,10 @@ func treecopy(n *Node, lineno int32) *Node {
516516
return nil
517517
}
518518

519-
var m *Node
520519
switch n.Op {
521520
default:
522-
m = Nod(OXXX, nil, nil)
523-
*m = *n
524-
m.Orig = m
521+
m := *n
522+
m.Orig = &m
525523
m.Left = treecopy(n.Left, lineno)
526524
m.Right = treecopy(n.Right, lineno)
527525
m.List.Set(listtreecopy(n.List.Slice(), lineno))
@@ -532,30 +530,28 @@ func treecopy(n *Node, lineno int32) *Node {
532530
Dump("treecopy", n)
533531
Fatalf("treecopy Name")
534532
}
533+
return &m
535534

536535
case ONONAME:
537536
if n.Sym == Lookup("iota") {
538537
// Not sure yet whether this is the real iota,
539538
// but make a copy of the Node* just in case,
540539
// so that all the copies of this const definition
541540
// don't have the same iota value.
542-
m = Nod(OXXX, nil, nil)
543-
*m = *n
541+
m := *n
544542
if lineno != 0 {
545543
m.Lineno = lineno
546544
}
547545
m.Name = new(Name)
548546
*m.Name = *n.Name
549547
m.Name.Iota = iota_
550-
break
548+
return &m
551549
}
552-
fallthrough
550+
return n
553551

554552
case ONAME, OLITERAL, OTYPE:
555-
m = n
553+
return n
556554
}
557-
558-
return m
559555
}
560556

561557
// isnil reports whether n represents the universal untyped zero value "nil".
@@ -1085,8 +1081,7 @@ func assignconvfn(n *Node, t *Type, context func() string) *Node {
10851081
// The result of substArgTypes MUST be assigned back to old, e.g.
10861082
// n.Left = substArgTypes(n.Left, t1, t2)
10871083
func substArgTypes(old *Node, types ...*Type) *Node {
1088-
n := Nod(OXXX, nil, nil)
1089-
*n = *old // make shallow copy
1084+
n := *old // make shallow copy
10901085

10911086
for _, t := range types {
10921087
dowidth(t)
@@ -1095,7 +1090,7 @@ func substArgTypes(old *Node, types ...*Type) *Node {
10951090
if len(types) > 0 {
10961091
Fatalf("substArgTypes: too many argument types")
10971092
}
1098-
return n
1093+
return &n
10991094
}
11001095

11011096
// substAny walks t, replacing instances of "any" with successive

0 commit comments

Comments
 (0)