aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2025-06-13 11:08:53 -0700
committerGopher Robot <gobot@golang.org>2025-07-24 09:04:29 -0700
commit2ddf542e4c30b2d4886482c44b57259f5b461158 (patch)
tree983b3fbfc49e60d30aff1339828bd812c7042384 /src/cmd/compile
parent6505fcbd0aaba2ab39915dcf437f01f1af83cd25 (diff)
downloadgo-2ddf542e4c30b2d4886482c44b57259f5b461158.tar.xz
cmd/compile: use ,ok return idiom for sparsemap.get
Change-Id: I89719b94de74a32402d02309515dffc4989484db Reviewed-on: https://go-review.googlesource.com/c/go/+/681575 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@google.com>
Diffstat (limited to 'src/cmd/compile')
-rw-r--r--src/cmd/compile/internal/ssa/biasedsparsemap.go14
-rw-r--r--src/cmd/compile/internal/ssa/deadcode.go2
-rw-r--r--src/cmd/compile/internal/ssa/deadstore.go3
-rw-r--r--src/cmd/compile/internal/ssa/nilcheck.go3
-rw-r--r--src/cmd/compile/internal/ssa/rewrite.go10
-rw-r--r--src/cmd/compile/internal/ssa/sparsemap.go6
-rw-r--r--src/cmd/compile/internal/ssa/xposmap.go4
7 files changed, 23 insertions, 19 deletions
diff --git a/src/cmd/compile/internal/ssa/biasedsparsemap.go b/src/cmd/compile/internal/ssa/biasedsparsemap.go
index c08efbf162..3032309b7a 100644
--- a/src/cmd/compile/internal/ssa/biasedsparsemap.go
+++ b/src/cmd/compile/internal/ssa/biasedsparsemap.go
@@ -56,21 +56,21 @@ func (s *biasedSparseMap) contains(x uint) bool {
return s.s.contains(ID(int(x) - s.first))
}
-// get returns the value s maps for key x, or -1 if
-// x is not mapped or is out of range for s.
-func (s *biasedSparseMap) get(x uint) int32 {
+// get returns the value s maps for key x and true, or
+// 0/false if x is not mapped or is out of range for s.
+func (s *biasedSparseMap) get(x uint) (int32, bool) {
if s == nil || s.s == nil {
- return -1
+ return 0, false
}
if int(x) < s.first {
- return -1
+ return 0, false
}
if int(x) >= s.cap() {
- return -1
+ return 0, false
}
k := ID(int(x) - s.first)
if !s.s.contains(k) {
- return -1 // TODO: push presence check to callers?
+ return 0, false
}
return s.s.get(k)
}
diff --git a/src/cmd/compile/internal/ssa/deadcode.go b/src/cmd/compile/internal/ssa/deadcode.go
index 1aa0f9e296..aa85097c29 100644
--- a/src/cmd/compile/internal/ssa/deadcode.go
+++ b/src/cmd/compile/internal/ssa/deadcode.go
@@ -257,7 +257,7 @@ func deadcode(f *Func) {
// Find new homes for lost lines -- require earliest in data flow with same line that is also in same block
for i := len(order) - 1; i >= 0; i-- {
w := order[i]
- if j := pendingLines.get(w.Pos); j > -1 && f.Blocks[j] == w.Block {
+ if j, ok := pendingLines.get(w.Pos); ok && f.Blocks[j] == w.Block {
w.Pos = w.Pos.WithIsStmt()
pendingLines.remove(w.Pos)
}
diff --git a/src/cmd/compile/internal/ssa/deadstore.go b/src/cmd/compile/internal/ssa/deadstore.go
index 40905bedcf..9e67e83399 100644
--- a/src/cmd/compile/internal/ssa/deadstore.go
+++ b/src/cmd/compile/internal/ssa/deadstore.go
@@ -118,7 +118,8 @@ func dse(f *Func) {
ptr = la
}
}
- sr := shadowRange(shadowed.get(ptr.ID))
+ srNum, _ := shadowed.get(ptr.ID)
+ sr := shadowRange(srNum)
if sr.contains(off, off+sz) {
// Modify the store/zero into a copy of the memory state,
// effectively eliding the store operation.
diff --git a/src/cmd/compile/internal/ssa/nilcheck.go b/src/cmd/compile/internal/ssa/nilcheck.go
index 9d43ec1991..467c7514ee 100644
--- a/src/cmd/compile/internal/ssa/nilcheck.go
+++ b/src/cmd/compile/internal/ssa/nilcheck.go
@@ -221,7 +221,8 @@ func nilcheckelim2(f *Func) {
// Iteration order means that first nilcheck in the chain wins, others
// are bumped into the ordinary statement preservation algorithm.
- u := b.Values[unnecessary.get(v.Args[0].ID)]
+ uid, _ := unnecessary.get(v.Args[0].ID)
+ u := b.Values[uid]
if !u.Type.IsMemory() && !u.Pos.SameFileAndLine(v.Pos) {
if u.Pos.IsStmt() == src.PosIsStmt {
pendingLines.add(u.Pos)
diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go
index eb2c3b31b8..0e7d354d6b 100644
--- a/src/cmd/compile/internal/ssa/rewrite.go
+++ b/src/cmd/compile/internal/ssa/rewrite.go
@@ -199,16 +199,18 @@ func applyRewrite(f *Func, rb blockRewriter, rv valueRewriter, deadcode deadValu
f.freeValue(v)
continue
}
- if v.Pos.IsStmt() != src.PosNotStmt && !notStmtBoundary(v.Op) && pendingLines.get(vl) == int32(b.ID) {
- pendingLines.remove(vl)
- v.Pos = v.Pos.WithIsStmt()
+ if v.Pos.IsStmt() != src.PosNotStmt && !notStmtBoundary(v.Op) {
+ if pl, ok := pendingLines.get(vl); ok && pl == int32(b.ID) {
+ pendingLines.remove(vl)
+ v.Pos = v.Pos.WithIsStmt()
+ }
}
if i != j {
b.Values[j] = v
}
j++
}
- if pendingLines.get(b.Pos) == int32(b.ID) {
+ if pl, ok := pendingLines.get(b.Pos); ok && pl == int32(b.ID) {
b.Pos = b.Pos.WithIsStmt()
pendingLines.remove(b.Pos)
}
diff --git a/src/cmd/compile/internal/ssa/sparsemap.go b/src/cmd/compile/internal/ssa/sparsemap.go
index b7363b36eb..255a346d37 100644
--- a/src/cmd/compile/internal/ssa/sparsemap.go
+++ b/src/cmd/compile/internal/ssa/sparsemap.go
@@ -41,13 +41,13 @@ func (s *genericSparseMap[K, V]) contains(k K) bool {
// get returns the value for key k, or the zero V
// if k does not appear in the map.
-func (s *genericSparseMap[K, V]) get(k K) V {
+func (s *genericSparseMap[K, V]) get(k K) (V, bool) {
i := s.sparse[k]
if i < int32(len(s.dense)) && s.dense[i].key == k {
- return s.dense[i].val
+ return s.dense[i].val, true
}
var v V
- return v
+ return v, false
}
func (s *genericSparseMap[K, V]) set(k K, v V) {
diff --git a/src/cmd/compile/internal/ssa/xposmap.go b/src/cmd/compile/internal/ssa/xposmap.go
index 93582e1373..382f916571 100644
--- a/src/cmd/compile/internal/ssa/xposmap.go
+++ b/src/cmd/compile/internal/ssa/xposmap.go
@@ -69,10 +69,10 @@ func (m *xposmap) set(p src.XPos, v int32) {
}
// get returns the int32 associated with the file index and line of p.
-func (m *xposmap) get(p src.XPos) int32 {
+func (m *xposmap) get(p src.XPos) (int32, bool) {
s := m.mapFor(p.FileIndex())
if s == nil {
- return -1
+ return 0, false
}
return s.get(p.Line())
}