mirror of
https://github.com/golang/go
synced 2024-11-17 11:04:53 -07:00
cmd/compile: remove large intermediate slice from gc.scopePCs
Three loops can be converted into one. Minor reviewer-recommended refactoring. Passes toolstash-check. Updates #27739. Change-Id: Ia87a11d88ae3ce56fcc4267fe6c5a9c13bf7f533 Reviewed-on: https://go-review.googlesource.com/c/go/+/176577 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Alessandro Arzilli <alessandro.arzilli@gmail.com>
This commit is contained in:
parent
2fd97ee25e
commit
d41a0a0690
@ -55,14 +55,6 @@ func scopeVariables(dwarfVars []*dwarf.Var, varScopes []ScopeID, dwarfScopes []d
|
||||
}
|
||||
}
|
||||
|
||||
// A scopedPCs represents a non-empty half-open interval of PCs that
|
||||
// share a common source position.
|
||||
type scopedPCs struct {
|
||||
start, end int64
|
||||
pos src.XPos
|
||||
scope ScopeID
|
||||
}
|
||||
|
||||
// scopePCs assigns PC ranges to their scopes.
|
||||
func scopePCs(fnsym *obj.LSym, marks []Mark, dwarfScopes []dwarf.Scope) {
|
||||
// If there aren't any child scopes (in particular, when scope
|
||||
@ -70,36 +62,18 @@ func scopePCs(fnsym *obj.LSym, marks []Mark, dwarfScopes []dwarf.Scope) {
|
||||
if len(marks) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// Break function text into scopedPCs.
|
||||
var pcs []scopedPCs
|
||||
p0 := fnsym.Func.Text
|
||||
scope := findScope(marks, p0.Pos)
|
||||
for p := fnsym.Func.Text; p != nil; p = p.Link {
|
||||
if p.Pos == p0.Pos {
|
||||
continue
|
||||
}
|
||||
if p0.Pc < p.Pc {
|
||||
pcs = append(pcs, scopedPCs{start: p0.Pc, end: p.Pc, pos: p0.Pos})
|
||||
}
|
||||
dwarfScopes[scope].AppendRange(dwarf.Range{Start: p0.Pc, End: p.Pc})
|
||||
p0 = p
|
||||
scope = findScope(marks, p0.Pos)
|
||||
}
|
||||
if p0.Pc < fnsym.Size {
|
||||
pcs = append(pcs, scopedPCs{start: p0.Pc, end: fnsym.Size, pos: p0.Pos})
|
||||
}
|
||||
|
||||
// Assign scopes to each chunk of instructions.
|
||||
for i := range pcs {
|
||||
pcs[i].scope = findScope(marks, pcs[i].pos)
|
||||
}
|
||||
|
||||
// Create sorted PC ranges for each DWARF scope.
|
||||
for _, pc := range pcs {
|
||||
r := &dwarfScopes[pc.scope].Ranges
|
||||
if i := len(*r); i > 0 && (*r)[i-1].End == pc.start {
|
||||
(*r)[i-1].End = pc.end
|
||||
} else {
|
||||
*r = append(*r, dwarf.Range{Start: pc.start, End: pc.end})
|
||||
}
|
||||
dwarfScopes[scope].AppendRange(dwarf.Range{Start: p0.Pc, End: fnsym.Size})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,6 +145,20 @@ func (s *Scope) UnifyRanges(c *Scope) {
|
||||
s.Ranges = out
|
||||
}
|
||||
|
||||
// AppendRange adds r to s, if r is non-empty.
|
||||
// If possible, it extends the last Range in s.Ranges; if not, it creates a new one.
|
||||
func (s *Scope) AppendRange(r Range) {
|
||||
if r.End <= r.Start {
|
||||
return
|
||||
}
|
||||
i := len(s.Ranges)
|
||||
if i > 0 && s.Ranges[i-1].End == r.Start {
|
||||
s.Ranges[i-1].End = r.End
|
||||
return
|
||||
}
|
||||
s.Ranges = append(s.Ranges, r)
|
||||
}
|
||||
|
||||
type InlCalls struct {
|
||||
Calls []InlCall
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user