Commit 89cfdda4 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: replace Order's use of NodeLists with slices

Order's "temp" and "free" fields use NodeLists in a rather
non-idiomatic way.  Instead of using the "list" or "concat" functions,
it manipulates them directly and without the normal invariants (e.g.,
it doesn't maintain the "End" field).

Rather than convert it to more typical usage, just replace with a
slice, which ends up much simpler anyway.

Passes toolstash/buildall.

Change-Id: Ibd0f24324bd674c0d5bb1bc40d073b01e7824ad5
Reviewed-on: https://go-review.googlesource.com/19776
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent d70c04cf
...@@ -42,8 +42,7 @@ import ( ...@@ -42,8 +42,7 @@ import (
// Order holds state during the ordering process. // Order holds state during the ordering process.
type Order struct { type Order struct {
out *NodeList // list of generated statements out *NodeList // list of generated statements
temp *NodeList // head of stack of temporary variables temp []*Node // stack of temporary variables
free *NodeList // free list of NodeList* structs (for use in temp)
} }
// Order rewrites fn->nbody to apply the ordering constraints // Order rewrites fn->nbody to apply the ordering constraints
...@@ -68,14 +67,7 @@ func ordertemp(t *Type, order *Order, clear bool) *Node { ...@@ -68,14 +67,7 @@ func ordertemp(t *Type, order *Order, clear bool) *Node {
order.out = list(order.out, a) order.out = list(order.out, a)
} }
l := order.free order.temp = append(order.temp, var_)
if l == nil {
l = new(NodeList)
}
order.free = l.Next
l.Next = order.temp
l.N = var_
order.temp = l
return var_ return var_
} }
...@@ -215,41 +207,34 @@ func orderaddrtemp(np **Node, order *Order) { ...@@ -215,41 +207,34 @@ func orderaddrtemp(np **Node, order *Order) {
*np = ordercopyexpr(n, n.Type, order, 0) *np = ordercopyexpr(n, n.Type, order, 0)
} }
type ordermarker int
// Marktemp returns the top of the temporary variable stack. // Marktemp returns the top of the temporary variable stack.
func marktemp(order *Order) *NodeList { func marktemp(order *Order) ordermarker {
return order.temp return ordermarker(len(order.temp))
} }
// Poptemp pops temporaries off the stack until reaching the mark, // Poptemp pops temporaries off the stack until reaching the mark,
// which must have been returned by marktemp. // which must have been returned by marktemp.
func poptemp(mark *NodeList, order *Order) { func poptemp(mark ordermarker, order *Order) {
var l *NodeList order.temp = order.temp[:mark]
for {
l = order.temp
if l == mark {
break
}
order.temp = l.Next
l.Next = order.free
order.free = l
}
} }
// Cleantempnopop emits to *out VARKILL instructions for each temporary // Cleantempnopop emits to *out VARKILL instructions for each temporary
// above the mark on the temporary stack, but it does not pop them // above the mark on the temporary stack, but it does not pop them
// from the stack. // from the stack.
func cleantempnopop(mark *NodeList, order *Order, out **NodeList) { func cleantempnopop(mark ordermarker, order *Order, out **NodeList) {
var kill *Node var kill *Node
for l := order.temp; l != mark; l = l.Next { for i := len(order.temp) - 1; i >= int(mark); i-- {
if l.N.Name.Keepalive { n := order.temp[i]
l.N.Name.Keepalive = false if n.Name.Keepalive {
kill = Nod(OVARLIVE, l.N, nil) n.Name.Keepalive = false
kill = Nod(OVARLIVE, n, nil)
typecheck(&kill, Etop) typecheck(&kill, Etop)
*out = list(*out, kill) *out = list(*out, kill)
} }
kill = Nod(OVARKILL, l.N, nil) kill = Nod(OVARKILL, n, nil)
typecheck(&kill, Etop) typecheck(&kill, Etop)
*out = list(*out, kill) *out = list(*out, kill)
} }
...@@ -257,7 +242,7 @@ func cleantempnopop(mark *NodeList, order *Order, out **NodeList) { ...@@ -257,7 +242,7 @@ func cleantempnopop(mark *NodeList, order *Order, out **NodeList) {
// Cleantemp emits VARKILL instructions for each temporary above the // Cleantemp emits VARKILL instructions for each temporary above the
// mark on the temporary stack and removes them from the stack. // mark on the temporary stack and removes them from the stack.
func cleantemp(top *NodeList, order *Order) { func cleantemp(top ordermarker, order *Order) {
cleantempnopop(top, order, &order.out) cleantempnopop(top, order, &order.out)
poptemp(top, order) poptemp(top, order)
} }
...@@ -289,13 +274,7 @@ func orderexprinplace(np **Node, outer *Order) { ...@@ -289,13 +274,7 @@ func orderexprinplace(np **Node, outer *Order) {
// insert new temporaries from order // insert new temporaries from order
// at head of outer list. // at head of outer list.
lp := &order.temp outer.temp = append(outer.temp, order.temp...)
for *lp != nil {
lp = &(*lp).Next
}
*lp = outer.temp
outer.temp = order.temp
*np = n *np = n
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment