Commit 0d73f1e3 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: change liveness-related functions into methods

No functional change; just making the code slightly more idiomatic.

Passes toolstash-check.

Change-Id: I66d14a8410bbecf260d0ea5683564aa413ce5747
Reviewed-on: https://go-review.googlesource.com/65070
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 39983cf4
...@@ -417,20 +417,20 @@ func onebitwalktype1(t *types.Type, off int64, bv bvec) { ...@@ -417,20 +417,20 @@ func onebitwalktype1(t *types.Type, off int64, bv bvec) {
} }
} }
// Returns the number of words of local variables. // localWords returns the number of words of local variables.
func localswords(lv *Liveness) int32 { func (lv *Liveness) localWords() int32 {
return int32(lv.stkptrsize / int64(Widthptr)) return int32(lv.stkptrsize / int64(Widthptr))
} }
// Returns the number of words of in and out arguments. // argWords returns the number of words of in and out arguments.
func argswords(lv *Liveness) int32 { func (lv *Liveness) argWords() int32 {
return int32(lv.fn.Type.ArgWidth() / int64(Widthptr)) return int32(lv.fn.Type.ArgWidth() / int64(Widthptr))
} }
// Generates live pointer value maps for arguments and local variables. The // Generates live pointer value maps for arguments and local variables. The
// this argument and the in arguments are always assumed live. The vars // this argument and the in arguments are always assumed live. The vars
// argument is a slice of *Nodes. // argument is a slice of *Nodes.
func onebitlivepointermap(lv *Liveness, liveout bvec, vars []*Node, args bvec, locals bvec) { func (lv *Liveness) pointerMap(liveout bvec, vars []*Node, args, locals bvec) {
for i := int32(0); ; i++ { for i := int32(0); ; i++ {
i = liveout.Next(i) i = liveout.Next(i)
if i < 0 { if i < 0 {
...@@ -456,7 +456,7 @@ func issafepoint(v *ssa.Value) bool { ...@@ -456,7 +456,7 @@ func issafepoint(v *ssa.Value) bool {
// Initializes the sets for solving the live variables. Visits all the // Initializes the sets for solving the live variables. Visits all the
// instructions in each basic block to summarizes the information at each basic // instructions in each basic block to summarizes the information at each basic
// block // block
func livenessprologue(lv *Liveness) { func (lv *Liveness) prologue() {
lv.initcache() lv.initcache()
for _, b := range lv.f.Blocks { for _, b := range lv.f.Blocks {
...@@ -490,7 +490,7 @@ func livenessprologue(lv *Liveness) { ...@@ -490,7 +490,7 @@ func livenessprologue(lv *Liveness) {
} }
// Solve the liveness dataflow equations. // Solve the liveness dataflow equations.
func livenesssolve(lv *Liveness) { func (lv *Liveness) solve() {
// These temporary bitvectors exist to avoid successive allocations and // These temporary bitvectors exist to avoid successive allocations and
// frees within the loop. // frees within the loop.
newlivein := bvalloc(int32(len(lv.vars))) newlivein := bvalloc(int32(len(lv.vars)))
...@@ -590,7 +590,7 @@ func livenesssolve(lv *Liveness) { ...@@ -590,7 +590,7 @@ func livenesssolve(lv *Liveness) {
// Visits all instructions in a basic block and computes a bit vector of live // Visits all instructions in a basic block and computes a bit vector of live
// variables at each safe point locations. // variables at each safe point locations.
func livenessepilogue(lv *Liveness) { func (lv *Liveness) epilogue() {
nvars := int32(len(lv.vars)) nvars := int32(len(lv.vars))
liveout := bvalloc(nvars) liveout := bvalloc(nvars)
any := bvalloc(nvars) any := bvalloc(nvars)
...@@ -954,7 +954,7 @@ func hashbitmap(h uint32, bv bvec) uint32 { ...@@ -954,7 +954,7 @@ func hashbitmap(h uint32, bv bvec) uint32 {
// is actually a net loss: we save about 50k of argument bitmaps but the new // is actually a net loss: we save about 50k of argument bitmaps but the new
// PCDATA tables cost about 100k. So for now we keep using a single index for // PCDATA tables cost about 100k. So for now we keep using a single index for
// both bitmap lists. // both bitmap lists.
func livenesscompact(lv *Liveness) { func (lv *Liveness) compact() {
// Linear probing hash table of bitmaps seen so far. // Linear probing hash table of bitmaps seen so far.
// The hash table has 4n entries to keep the linear // The hash table has 4n entries to keep the linear
// scan short. An entry of -1 indicates an empty slot. // scan short. An entry of -1 indicates an empty slot.
...@@ -1104,7 +1104,7 @@ func (lv *Liveness) printeffect(printed bool, name string, pos int32, x bool) bo ...@@ -1104,7 +1104,7 @@ func (lv *Liveness) printeffect(printed bool, name string, pos int32, x bool) bo
// Prints the computed liveness information and inputs, for debugging. // Prints the computed liveness information and inputs, for debugging.
// This format synthesizes the information used during the multiple passes // This format synthesizes the information used during the multiple passes
// into a single presentation. // into a single presentation.
func livenessprintdebug(lv *Liveness) { func (lv *Liveness) printDebug() {
fmt.Printf("liveness: %s\n", lv.fn.funcname()) fmt.Printf("liveness: %s\n", lv.fn.funcname())
pcdata := 0 pcdata := 0
...@@ -1216,12 +1216,12 @@ func livenessprintdebug(lv *Liveness) { ...@@ -1216,12 +1216,12 @@ func livenessprintdebug(lv *Liveness) {
// first word dumped is the total number of bitmaps. The second word is the // first word dumped is the total number of bitmaps. The second word is the
// length of the bitmaps. All bitmaps are assumed to be of equal length. The // length of the bitmaps. All bitmaps are assumed to be of equal length. The
// remaining bytes are the raw bitmaps. // remaining bytes are the raw bitmaps.
func livenessemit(lv *Liveness, argssym, livesym *obj.LSym) { func (lv *Liveness) emit(argssym, livesym *obj.LSym) {
args := bvalloc(argswords(lv)) args := bvalloc(lv.argWords())
aoff := duint32(argssym, 0, uint32(len(lv.livevars))) // number of bitmaps aoff := duint32(argssym, 0, uint32(len(lv.livevars))) // number of bitmaps
aoff = duint32(argssym, aoff, uint32(args.n)) // number of bits in each bitmap aoff = duint32(argssym, aoff, uint32(args.n)) // number of bits in each bitmap
locals := bvalloc(localswords(lv)) locals := bvalloc(lv.localWords())
loff := duint32(livesym, 0, uint32(len(lv.livevars))) // number of bitmaps loff := duint32(livesym, 0, uint32(len(lv.livevars))) // number of bitmaps
loff = duint32(livesym, loff, uint32(locals.n)) // number of bits in each bitmap loff = duint32(livesym, loff, uint32(locals.n)) // number of bits in each bitmap
...@@ -1229,7 +1229,7 @@ func livenessemit(lv *Liveness, argssym, livesym *obj.LSym) { ...@@ -1229,7 +1229,7 @@ func livenessemit(lv *Liveness, argssym, livesym *obj.LSym) {
args.Clear() args.Clear()
locals.Clear() locals.Clear()
onebitlivepointermap(lv, live, lv.vars, args, locals) lv.pointerMap(live, lv.vars, args, locals)
aoff = dbvec(argssym, aoff, args) aoff = dbvec(argssym, aoff, args)
loff = dbvec(livesym, loff, locals) loff = dbvec(livesym, loff, locals)
...@@ -1254,18 +1254,18 @@ func liveness(e *ssafn, f *ssa.Func) map[*ssa.Value]int { ...@@ -1254,18 +1254,18 @@ func liveness(e *ssafn, f *ssa.Func) map[*ssa.Value]int {
lv := newliveness(e.curfn, f, vars, idx, e.stkptrsize) lv := newliveness(e.curfn, f, vars, idx, e.stkptrsize)
// Run the dataflow framework. // Run the dataflow framework.
livenessprologue(lv) lv.prologue()
livenesssolve(lv) lv.solve()
livenessepilogue(lv) lv.epilogue()
livenesscompact(lv) lv.compact()
lv.clobber() lv.clobber()
if debuglive >= 2 { if debuglive >= 2 {
livenessprintdebug(lv) lv.printDebug()
} }
// Emit the live pointer map data structures // Emit the live pointer map data structures
if ls := e.curfn.Func.lsym; ls != nil { if ls := e.curfn.Func.lsym; ls != nil {
livenessemit(lv, &ls.Func.GCArgs, &ls.Func.GCLocals) lv.emit(&ls.Func.GCArgs, &ls.Func.GCLocals)
} }
return lv.stackMapIndex return lv.stackMapIndex
} }
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