Commit c46ebec3 authored by Keith Randall's avatar Keith Randall Committed by Keith Randall

cmd/compile: get rid of unnecessary inline marks

If no other instruction mentions an inline mark, we can get rid of it.
This normally happens when the inlined function is empty, or when all
of its code is folded into other instructions.

Also use consistent statement-ness for inline mark positions, so that
more of them can be removed in favor of existing instructions.

Update #29571
Fixes #31172

Change-Id: I71f84d355101f37a27960d9e8528f42f92767496
Reviewed-on: https://go-review.googlesource.com/c/go/+/170445
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 7bb8fc10
...@@ -1054,7 +1054,7 @@ func mkinlcall(n, fn *Node, maxCost int32) *Node { ...@@ -1054,7 +1054,7 @@ func mkinlcall(n, fn *Node, maxCost int32) *Node {
// to put a breakpoint. Not sure if that's really necessary or not // to put a breakpoint. Not sure if that's really necessary or not
// (in which case it could go at the end of the function instead). // (in which case it could go at the end of the function instead).
inlMark := nod(OINLMARK, nil, nil) inlMark := nod(OINLMARK, nil, nil)
inlMark.Pos = n.Pos inlMark.Pos = n.Pos.WithDefaultStmt()
inlMark.Xoffset = int64(newIndex) inlMark.Xoffset = int64(newIndex)
ninit.Append(inlMark) ninit.Append(inlMark)
......
...@@ -76,6 +76,30 @@ func liveValues(f *Func, reachable []bool) (live []bool, liveOrderStmts []*Value ...@@ -76,6 +76,30 @@ func liveValues(f *Func, reachable []bool) (live []bool, liveOrderStmts []*Value
return return
} }
// Record all the inline indexes we need
var liveInlIdx map[int]bool
pt := f.Config.ctxt.PosTable
for _, b := range f.Blocks {
for _, v := range b.Values {
i := pt.Pos(v.Pos).Base().InliningIndex()
if i < 0 {
continue
}
if liveInlIdx == nil {
liveInlIdx = map[int]bool{}
}
liveInlIdx[i] = true
}
i := pt.Pos(b.Pos).Base().InliningIndex()
if i < 0 {
continue
}
if liveInlIdx == nil {
liveInlIdx = map[int]bool{}
}
liveInlIdx[i] = true
}
// Find all live values // Find all live values
q := f.Cache.deadcode.q[:0] q := f.Cache.deadcode.q[:0]
defer func() { f.Cache.deadcode.q = q }() defer func() { f.Cache.deadcode.q = q }()
...@@ -103,6 +127,13 @@ func liveValues(f *Func, reachable []bool) (live []bool, liveOrderStmts []*Value ...@@ -103,6 +127,13 @@ func liveValues(f *Func, reachable []bool) (live []bool, liveOrderStmts []*Value
} }
if v.Type.IsVoid() && !live[v.ID] { if v.Type.IsVoid() && !live[v.ID] {
// The only Void ops are nil checks and inline marks. We must keep these. // The only Void ops are nil checks and inline marks. We must keep these.
if v.Op == OpInlMark && !liveInlIdx[int(v.AuxInt)] {
// We don't need marks for bodies that
// have been completely optimized away.
// TODO: save marks only for bodies which
// have a faulting instruction or a call?
continue
}
live[v.ID] = true live[v.ID] = true
q = append(q, v) q = append(q, v)
if v.Pos.IsStmt() != src.PosNotStmt { if v.Pos.IsStmt() != src.PosNotStmt {
......
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