]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/gc: shorten temporary lifetimes when possible
authorRuss Cox <rsc@golang.org>
Tue, 1 Apr 2014 17:31:38 +0000 (13:31 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 1 Apr 2014 17:31:38 +0000 (13:31 -0400)
commitb700cb4974c23a030775a311e6c60cf93b220a6f
tree146bbba24e04a40b76de34247a32369ad52fcfd6
parent1ec4d5e9e775b2adcf7dd2e464a10854bad09803
cmd/gc: shorten temporary lifetimes when possible

The new channel and map runtime routines take pointers
to values, typically temporaries. Without help, the compiler
cannot tell when those temporaries stop being needed,
because it isn't sure what happened to the pointer.
Arrange to insert explicit VARKILL instructions for these
temporaries so that the liveness analysis can avoid seeing
them as "ambiguously live".

The change is made in order.c, which was already in charge of
introducing temporaries to preserve the order-of-evaluation
guarantees. Now its job has expanded to include introducing
temporaries as needed by runtime routines, and then also
inserting the VARKILL annotations for all these temporaries,
so that their lifetimes can be shortened.

In order to do its job for the map runtime routines, order.c arranges
that all map lookups or map assignments have the form:

        x = m[k]
        x, y = m[k]
        m[k] = x

where x, y, and k are simple variables (often temporaries).
Likewise, receiving from a channel is now always:

        x = <-c

In order to provide the map guarantee, order.c is responsible for
rewriting x op= y into x = x op y, so that m[k] += z becomes

        t = m[k]
        t2 = t + z
        m[k] = t2

While here, fix a few bugs in order.c's traversal: it was failing to
walk into select and switch case bodies, so order of evaluation
guarantees were not preserved in those situations.
Added tests to test/reorder2.go.

Fixes #7671.

In gc/popt's temporary-merging optimization, allow merging
of temporaries with their address taken as long as the liveness
ranges do not intersect. (There is a good chance of that now
that we have VARKILL annotations to limit the liveness range.)

Explicitly killing temporaries cuts the number of ambiguously
live temporaries that must be zeroed in the godoc binary from
860 to 711, or -17%. There is more work to be done, but this
is a good checkpoint.

Update #7345

LGTM=khr
R=khr
CC=golang-codereviews
https://golang.org/cl/81940043
29 files changed:
src/cmd/5g/ggen.c
src/cmd/5g/peep.c
src/cmd/5g/prog.c
src/cmd/5g/reg.c
src/cmd/5l/5.out.h
src/cmd/6g/ggen.c
src/cmd/6g/peep.c
src/cmd/6g/prog.c
src/cmd/6g/reg.c
src/cmd/6l/6.out.h
src/cmd/8g/ggen.c
src/cmd/8g/peep.c
src/cmd/8g/prog.c
src/cmd/8g/reg.c
src/cmd/8l/8.out.h
src/cmd/gc/gen.c
src/cmd/gc/go.h
src/cmd/gc/order.c
src/cmd/gc/pgen.c
src/cmd/gc/plive.c
src/cmd/gc/popt.c
src/cmd/gc/racewalk.c
src/cmd/gc/range.c
src/cmd/gc/select.c
src/cmd/gc/sinit.c
src/cmd/gc/typecheck.c
src/cmd/gc/walk.c
test/live.go
test/reorder2.go