package ssa
import (
- "cmd/internal/src"
"math"
)
if int(x) < s.first || int(x) >= s.cap() {
return
}
- s.s.set(ID(int(x)-s.first), 0, src.NoXPos)
+ s.s.set(ID(int(x)-s.first), 0)
}
// add inserts x->v into s, provided that x is in the range of keys stored in s.
if int(x) < s.first || int(x) >= s.cap() {
return
}
- s.s.set(ID(int(x)-s.first), v, src.NoXPos)
+ s.s.set(ID(int(x)-s.first), v)
}
// remove removes key x from s.
// See stackalloc.go's {new,put}StackAllocState.
stackAllocState *stackAllocState
- domblockstore []ID // scratch space for computing dominators
- scrSparseSet []*sparseSet // scratch sparse sets to be re-used.
- scrSparseMap []*sparseMap // scratch sparse maps to be re-used.
- scrPoset []*poset // scratch poset to be reused
+ domblockstore []ID // scratch space for computing dominators
+ scrSparseSet []*sparseSet // scratch sparse sets to be re-used.
+ scrSparseMap []*sparseMap // scratch sparse maps to be re-used.
+ scrSparseMapPos []*sparseMapPos // scratch sparse maps to be re-used.
+ scrPoset []*poset // scratch poset to be reused
// deadcode contains reusable slices specifically for the deadcode pass.
// It gets special treatment because of the frequency with which it is run.
deadcode struct {
import (
"cmd/compile/internal/ir"
"cmd/compile/internal/types"
- "cmd/internal/src"
)
// dse does dead-store elimination on the Function.
if sz > 0x7fffffff { // work around sparseMap's int32 value type
sz = 0x7fffffff
}
- shadowed.set(v.Args[0].ID, int32(sz), src.NoXPos)
+ shadowed.set(v.Args[0].ID, int32(sz))
}
}
// walk to previous store
f.Cache.scrSparseMap = append(f.Cache.scrSparseMap, ss)
}
+// newSparseMapPos returns a sparse map that can store at least up to n integers.
+func (f *Func) newSparseMapPos(n int) *sparseMapPos {
+ for i, scr := range f.Cache.scrSparseMapPos {
+ if scr != nil && scr.cap() >= n {
+ f.Cache.scrSparseMapPos[i] = nil
+ scr.clear()
+ return scr
+ }
+ }
+ return newSparseMapPos(n)
+}
+
+// retSparseMapPos returns a sparse map to the config's cache of sparse
+// sets to be reused by f.newSparseMapPos.
+func (f *Func) retSparseMapPos(ss *sparseMapPos) {
+ for i, scr := range f.Cache.scrSparseMapPos {
+ if scr == nil {
+ f.Cache.scrSparseMapPos[i] = ss
+ return
+ }
+ }
+ f.Cache.scrSparseMapPos = append(f.Cache.scrSparseMapPos, ss)
+}
+
// newPoset returns a new poset from the internal cache
func (f *Func) newPoset() *poset {
if len(f.Cache.scrPoset) > 0 {
}
// This instruction is guaranteed to fault if ptr is nil.
// Any previous nil check op is unnecessary.
- unnecessary.set(ptr.ID, int32(i), src.NoXPos)
+ unnecessary.set(ptr.ID, int32(i))
}
}
// Remove values we've clobbered with OpUnknown.
s.desired = make([]desiredState, f.NumBlocks())
var phis []*Value
- live := f.newSparseMap(f.NumValues())
- defer f.retSparseMap(live)
- t := f.newSparseMap(f.NumValues())
- defer f.retSparseMap(t)
+ live := f.newSparseMapPos(f.NumValues())
+ defer f.retSparseMapPos(live)
+ t := f.newSparseMapPos(f.NumValues())
+ defer f.retSparseMapPos(t)
// Keep track of which value we want in each register.
var desired desiredState
d := e.val + delta
if !t.contains(e.key) || d < t.get(e.key) {
update = true
- t.set(e.key, d, e.aux)
+ t.set(e.key, d, e.pos)
}
}
// Also add the correct arg from the saved phi values.
l = make([]liveInfo, 0, t.size())
}
for _, e := range t.contents() {
- l = append(l, liveInfo{e.key, e.val, e.aux})
+ l = append(l, liveInfo{e.key, e.val, e.pos})
}
s.live[p.ID] = l
changed = true
package ssa
-import "cmd/internal/src"
-
// from https://research.swtch.com/sparse
// in turn, from Briggs and Torczon
type sparseEntry struct {
key ID
val int32
- aux src.XPos
}
type sparseMap struct {
return -1
}
-func (s *sparseMap) set(k ID, v int32, a src.XPos) {
+func (s *sparseMap) set(k ID, v int32) {
i := s.sparse[k]
if i < int32(len(s.dense)) && s.dense[i].key == k {
s.dense[i].val = v
- s.dense[i].aux = a
return
}
- s.dense = append(s.dense, sparseEntry{k, v, a})
+ s.dense = append(s.dense, sparseEntry{k, v})
s.sparse[k] = int32(len(s.dense)) - 1
}
s.dense[i].val |= 1 << v
return
}
- s.dense = append(s.dense, sparseEntry{k, 1 << v, src.NoXPos})
+ s.dense = append(s.dense, sparseEntry{k, 1 << v})
s.sparse[k] = int32(len(s.dense)) - 1
}
--- /dev/null
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ssa
+
+import "cmd/internal/src"
+
+// from https://research.swtch.com/sparse
+// in turn, from Briggs and Torczon
+
+type sparseEntryPos struct {
+ key ID
+ val int32
+ pos src.XPos
+}
+
+type sparseMapPos struct {
+ dense []sparseEntryPos
+ sparse []int32
+}
+
+// newSparseMapPos returns a sparseMapPos that can map
+// integers between 0 and n-1 to the pair <int32,src.XPos>.
+func newSparseMapPos(n int) *sparseMapPos {
+ return &sparseMapPos{dense: nil, sparse: make([]int32, n)}
+}
+
+func (s *sparseMapPos) cap() int {
+ return len(s.sparse)
+}
+
+func (s *sparseMapPos) size() int {
+ return len(s.dense)
+}
+
+func (s *sparseMapPos) contains(k ID) bool {
+ i := s.sparse[k]
+ return i < int32(len(s.dense)) && s.dense[i].key == k
+}
+
+// get returns the value for key k, or -1 if k does
+// not appear in the map.
+func (s *sparseMapPos) get(k ID) int32 {
+ i := s.sparse[k]
+ if i < int32(len(s.dense)) && s.dense[i].key == k {
+ return s.dense[i].val
+ }
+ return -1
+}
+
+func (s *sparseMapPos) set(k ID, v int32, a src.XPos) {
+ i := s.sparse[k]
+ if i < int32(len(s.dense)) && s.dense[i].key == k {
+ s.dense[i].val = v
+ s.dense[i].pos = a
+ return
+ }
+ s.dense = append(s.dense, sparseEntryPos{k, v, a})
+ s.sparse[k] = int32(len(s.dense)) - 1
+}
+
+func (s *sparseMapPos) remove(k ID) {
+ i := s.sparse[k]
+ if i < int32(len(s.dense)) && s.dense[i].key == k {
+ y := s.dense[len(s.dense)-1]
+ s.dense[i] = y
+ s.sparse[y.key] = i
+ s.dense = s.dense[:len(s.dense)-1]
+ }
+}
+
+func (s *sparseMapPos) clear() {
+ s.dense = s.dense[:0]
+}
+
+func (s *sparseMapPos) contents() []sparseEntryPos {
+ return s.dense
+}