Commit 0153137a authored by Russ Cox's avatar Russ Cox

cmd/internal/gc: clean up liveness code

- use Bvec, not *Bvec, and bulk allocate backing store
- use range loops
- put Bvecs in BasicBlock struct instead of indexing into parallel slices

Change-Id: I5cb30f50dccb4d38cc18fae422f7f132c52876be
Reviewed-on: https://go-review.googlesource.com/6602Reviewed-by: default avatarRob Pike <r@golang.org>
parent 4492811c
...@@ -13,24 +13,51 @@ const ( ...@@ -13,24 +13,51 @@ const (
WORDSHIFT = 5 WORDSHIFT = 5
) )
// A Bvec is a bit vector.
type Bvec struct {
n int32 // number of bits in vector
b []uint32 // words holding bits
}
func bvsize(n uint32) uint32 { func bvsize(n uint32) uint32 {
return ((n + WORDBITS - 1) / WORDBITS) * WORDSIZE return ((n + WORDBITS - 1) / WORDBITS) * WORDSIZE
} }
func bvbits(bv *Bvec) int32 { func bvbits(bv Bvec) int32 {
return bv.n return bv.n
} }
func bvwords(bv *Bvec) int32 { func bvwords(bv Bvec) int32 {
return (bv.n + WORDBITS - 1) / WORDBITS return (bv.n + WORDBITS - 1) / WORDBITS
} }
func bvalloc(n int32) *Bvec { func bvalloc(n int32) Bvec {
return &Bvec{n, make([]uint32, bvsize(uint32(n))/4)} return Bvec{n, make([]uint32, bvsize(uint32(n))/4)}
}
type bulkBvec struct {
words []uint32
nbit int32
nword int32
}
func bvbulkalloc(nbit int32, count int32) bulkBvec {
nword := (nbit + WORDBITS - 1) / WORDBITS
return bulkBvec{
words: make([]uint32, nword*count),
nbit: nbit,
nword: nword,
}
}
func (b *bulkBvec) next() Bvec {
out := Bvec{b.nbit, b.words[:b.nword]}
b.words = b.words[b.nword:]
return out
} }
/* difference */ /* difference */
func bvandnot(dst *Bvec, src1 *Bvec, src2 *Bvec) { func bvandnot(dst Bvec, src1 Bvec, src2 Bvec) {
var i int32 var i int32
var w int32 var w int32
...@@ -44,7 +71,7 @@ func bvandnot(dst *Bvec, src1 *Bvec, src2 *Bvec) { ...@@ -44,7 +71,7 @@ func bvandnot(dst *Bvec, src1 *Bvec, src2 *Bvec) {
} }
} }
func bvcmp(bv1 *Bvec, bv2 *Bvec) int { func bvcmp(bv1 Bvec, bv2 Bvec) int {
if bv1.n != bv2.n { if bv1.n != bv2.n {
Fatal("bvequal: lengths %d and %d are not equal", bv1.n, bv2.n) Fatal("bvequal: lengths %d and %d are not equal", bv1.n, bv2.n)
} }
...@@ -56,13 +83,13 @@ func bvcmp(bv1 *Bvec, bv2 *Bvec) int { ...@@ -56,13 +83,13 @@ func bvcmp(bv1 *Bvec, bv2 *Bvec) int {
return 0 return 0
} }
func bvcopy(dst *Bvec, src *Bvec) { func bvcopy(dst Bvec, src Bvec) {
for i, x := range src.b { for i, x := range src.b {
dst.b[i] = x dst.b[i] = x
} }
} }
func bvconcat(src1 *Bvec, src2 *Bvec) *Bvec { func bvconcat(src1 Bvec, src2 Bvec) Bvec {
dst := bvalloc(src1.n + src2.n) dst := bvalloc(src1.n + src2.n)
for i := int32(0); i < src1.n; i++ { for i := int32(0); i < src1.n; i++ {
if bvget(src1, i) != 0 { if bvget(src1, i) != 0 {
...@@ -77,7 +104,7 @@ func bvconcat(src1 *Bvec, src2 *Bvec) *Bvec { ...@@ -77,7 +104,7 @@ func bvconcat(src1 *Bvec, src2 *Bvec) *Bvec {
return dst return dst
} }
func bvget(bv *Bvec, i int32) int { func bvget(bv Bvec, i int32) int {
if i < 0 || i >= bv.n { if i < 0 || i >= bv.n {
Fatal("bvget: index %d is out of bounds with length %d\n", i, bv.n) Fatal("bvget: index %d is out of bounds with length %d\n", i, bv.n)
} }
...@@ -86,7 +113,7 @@ func bvget(bv *Bvec, i int32) int { ...@@ -86,7 +113,7 @@ func bvget(bv *Bvec, i int32) int {
// bvnext returns the smallest index >= i for which bvget(bv, i) == 1. // bvnext returns the smallest index >= i for which bvget(bv, i) == 1.
// If there is no such index, bvnext returns -1. // If there is no such index, bvnext returns -1.
func bvnext(bv *Bvec, i int32) int { func bvnext(bv Bvec, i int32) int {
if i >= bv.n { if i >= bv.n {
return -1 return -1
} }
...@@ -115,7 +142,7 @@ func bvnext(bv *Bvec, i int32) int { ...@@ -115,7 +142,7 @@ func bvnext(bv *Bvec, i int32) int {
return int(i) return int(i)
} }
func bvisempty(bv *Bvec) bool { func bvisempty(bv Bvec) bool {
for i := int32(0); i < bv.n; i += WORDBITS { for i := int32(0); i < bv.n; i += WORDBITS {
if bv.b[i>>WORDSHIFT] != 0 { if bv.b[i>>WORDSHIFT] != 0 {
return false return false
...@@ -124,7 +151,7 @@ func bvisempty(bv *Bvec) bool { ...@@ -124,7 +151,7 @@ func bvisempty(bv *Bvec) bool {
return true return true
} }
func bvnot(bv *Bvec) { func bvnot(bv Bvec) {
var i int32 var i int32
var w int32 var w int32
...@@ -136,7 +163,7 @@ func bvnot(bv *Bvec) { ...@@ -136,7 +163,7 @@ func bvnot(bv *Bvec) {
} }
/* union */ /* union */
func bvor(dst *Bvec, src1 *Bvec, src2 *Bvec) { func bvor(dst Bvec, src1 Bvec, src2 Bvec) {
var i int32 var i int32
var w int32 var w int32
...@@ -151,7 +178,7 @@ func bvor(dst *Bvec, src1 *Bvec, src2 *Bvec) { ...@@ -151,7 +178,7 @@ func bvor(dst *Bvec, src1 *Bvec, src2 *Bvec) {
} }
/* intersection */ /* intersection */
func bvand(dst *Bvec, src1 *Bvec, src2 *Bvec) { func bvand(dst Bvec, src1 Bvec, src2 Bvec) {
var i int32 var i int32
var w int32 var w int32
...@@ -165,14 +192,14 @@ func bvand(dst *Bvec, src1 *Bvec, src2 *Bvec) { ...@@ -165,14 +192,14 @@ func bvand(dst *Bvec, src1 *Bvec, src2 *Bvec) {
} }
} }
func bvprint(bv *Bvec) { func bvprint(bv Bvec) {
fmt.Printf("#*") fmt.Printf("#*")
for i := int32(0); i < bv.n; i++ { for i := int32(0); i < bv.n; i++ {
fmt.Printf("%d", bvget(bv, i)) fmt.Printf("%d", bvget(bv, i))
} }
} }
func bvreset(bv *Bvec, i int32) { func bvreset(bv Bvec, i int32) {
if i < 0 || i >= bv.n { if i < 0 || i >= bv.n {
Fatal("bvreset: index %d is out of bounds with length %d\n", i, bv.n) Fatal("bvreset: index %d is out of bounds with length %d\n", i, bv.n)
} }
...@@ -180,13 +207,13 @@ func bvreset(bv *Bvec, i int32) { ...@@ -180,13 +207,13 @@ func bvreset(bv *Bvec, i int32) {
bv.b[i/WORDBITS] &= mask bv.b[i/WORDBITS] &= mask
} }
func bvresetall(bv *Bvec) { func bvresetall(bv Bvec) {
for i := range bv.b { for i := range bv.b {
bv.b[i] = 0 bv.b[i] = 0
} }
} }
func bvset(bv *Bvec, i int32) { func bvset(bv Bvec, i int32) {
if i < 0 || i >= bv.n { if i < 0 || i >= bv.n {
Fatal("bvset: index %d is out of bounds with length %d\n", i, bv.n) Fatal("bvset: index %d is out of bounds with length %d\n", i, bv.n)
} }
......
...@@ -100,11 +100,6 @@ type Array struct { ...@@ -100,11 +100,6 @@ type Array struct {
data string data string
} }
type Bvec struct {
n int32
b []uint32
}
type Pkg struct { type Pkg struct {
Name string Name string
Path string Path string
......
This diff is collapsed.
...@@ -2196,7 +2196,7 @@ func needwritebarrier(l *Node, r *Node) bool { ...@@ -2196,7 +2196,7 @@ func needwritebarrier(l *Node, r *Node) bool {
// TODO(rsc): Perhaps componentgen should run before this. // TODO(rsc): Perhaps componentgen should run before this.
var applywritebarrier_bv *Bvec var applywritebarrier_bv Bvec
func applywritebarrier(n *Node, init **NodeList) *Node { func applywritebarrier(n *Node, init **NodeList) *Node {
if n.Left != nil && n.Right != nil && needwritebarrier(n.Left, n.Right) { if n.Left != nil && n.Right != nil && needwritebarrier(n.Left, n.Right) {
...@@ -2216,7 +2216,7 @@ func applywritebarrier(n *Node, init **NodeList) *Node { ...@@ -2216,7 +2216,7 @@ func applywritebarrier(n *Node, init **NodeList) *Node {
n = mkcall1(writebarrierfn("writebarrieriface", t, n.Right.Type), nil, init, l, n.Right) n = mkcall1(writebarrierfn("writebarrieriface", t, n.Right.Type), nil, init, l, n.Right)
} else if t.Width <= int64(4*Widthptr) { } else if t.Width <= int64(4*Widthptr) {
x := int64(0) x := int64(0)
if applywritebarrier_bv == nil { if applywritebarrier_bv.b == nil {
applywritebarrier_bv = bvalloc(obj.BitsPerPointer * 4) applywritebarrier_bv = bvalloc(obj.BitsPerPointer * 4)
} }
bvresetall(applywritebarrier_bv) bvresetall(applywritebarrier_bv)
......
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