The next CL will introduce a package ir to hold the IR definitions.
This CL adjusts a few names and makes a few other minor changes
to make the next CL - an automated one - smoother.
Change-Id: Ie787a34732efd5b3d171bf0c1220b6dd91994ce3
Reviewed-on: https://go-review.googlesource.com/c/go/+/272251
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
notes *EscNote
}
+func init() {
+ EscFmt = escFmt
+}
+
+// escFmt is called from node printing to print information about escape analysis results.
+func escFmt(n *Node, short bool) string {
+ text := ""
+ switch n.Esc {
+ case EscUnknown:
+ break
+
+ case EscHeap:
+ text = "esc(h)"
+
+ case EscNone:
+ text = "esc(no)"
+
+ case EscNever:
+ if !short {
+ text = "esc(N)"
+ }
+
+ default:
+ text = fmt.Sprintf("esc(%d)", n.Esc)
+ }
+
+ if e, ok := n.Opt().(*EscLocation); ok && e.loopDepth != 0 {
+ if text != "" {
+ text += " "
+ }
+ text += fmt.Sprintf("ld(%d)", e.loopDepth)
+ }
+ return text
+}
+
// escapeFuncs performs escape analysis on a minimal batch of
// functions.
func escapeFuncs(fns []*Node, recursive bool) {
}
}
+// EscFmt is set by the escape analysis code to add escape analysis details to the node print.
+var EscFmt func(n *Node, short bool) string
+
// *Node details
func (n *Node) jconv(s fmt.State, flag FmtFlag) {
- c := flag & FmtShort
+ short := flag&FmtShort != 0
- // Useful to see which nodes in a Node Dump/dumplist are actually identical
+ // Useful to see which nodes in an AST printout are actually identical
if Debug_dumpptrs != 0 {
fmt.Fprintf(s, " p(%p)", n)
}
- if c == 0 && n.Name != nil && n.Name.Vargen != 0 {
+ if !short && n.Name != nil && n.Name.Vargen != 0 {
fmt.Fprintf(s, " g(%d)", n.Name.Vargen)
}
- if Debug_dumpptrs != 0 && c == 0 && n.Name != nil && n.Name.Defn != nil {
+ if Debug_dumpptrs != 0 && !short && n.Name != nil && n.Name.Defn != nil {
// Useful to see where Defn is set and what node it points to
fmt.Fprintf(s, " defn(%p)", n.Name.Defn)
}
fmt.Fprintf(s, " l(%s%d)", pfx, n.Pos.Line())
}
- if c == 0 && n.Xoffset != BADWIDTH {
+ if !short && n.Xoffset != BADWIDTH {
fmt.Fprintf(s, " x(%d)", n.Xoffset)
}
fmt.Fprintf(s, " colas(%v)", n.Colas())
}
- switch n.Esc {
- case EscUnknown:
- break
-
- case EscHeap:
- fmt.Fprint(s, " esc(h)")
-
- case EscNone:
- fmt.Fprint(s, " esc(no)")
-
- case EscNever:
- if c == 0 {
- fmt.Fprint(s, " esc(N)")
+ if EscFmt != nil {
+ if esc := EscFmt(n, short); esc != "" {
+ fmt.Fprintf(s, " %s", esc)
}
-
- default:
- fmt.Fprintf(s, " esc(%d)", n.Esc)
- }
-
- if e, ok := n.Opt().(*EscLocation); ok && e.loopDepth != 0 {
- fmt.Fprintf(s, " ld(%d)", e.loopDepth)
}
- if c == 0 && n.Typecheck() != 0 {
+ if !short && n.Typecheck() != 0 {
fmt.Fprintf(s, " tc(%d)", n.Typecheck())
}
fmt.Fprint(s, " nonnil")
}
- if c == 0 && n.HasCall() {
+ if !short && n.HasCall() {
fmt.Fprint(s, " hascall")
}
- if c == 0 && n.Name != nil && n.Name.Used() {
+ if !short && n.Name != nil && n.Name.Used() {
fmt.Fprint(s, " used")
}
}
}
func iimport(pkg *types.Pkg, in *bio.Reader) (fingerprint goobj.FingerprintType) {
- ir := &intReader{in, pkg}
+ ird := &intReader{in, pkg}
- version := ir.uint64()
+ version := ird.uint64()
if version != iexportVersion {
yyerror("import %q: unknown export format version %d", pkg.Path, version)
errorexit()
}
- sLen := ir.uint64()
- dLen := ir.uint64()
+ sLen := ird.uint64()
+ dLen := ird.uint64()
// Map string (and data) section into memory as a single large
// string. This reduces heap fragmentation and allows
}
// Declaration index.
- for nPkgs := ir.uint64(); nPkgs > 0; nPkgs-- {
- pkg := p.pkgAt(ir.uint64())
- pkgName := p.stringAt(ir.uint64())
- pkgHeight := int(ir.uint64())
+ for nPkgs := ird.uint64(); nPkgs > 0; nPkgs-- {
+ pkg := p.pkgAt(ird.uint64())
+ pkgName := p.stringAt(ird.uint64())
+ pkgHeight := int(ird.uint64())
if pkg.Name == "" {
pkg.Name = pkgName
pkg.Height = pkgHeight
}
}
- for nSyms := ir.uint64(); nSyms > 0; nSyms-- {
- s := pkg.Lookup(p.stringAt(ir.uint64()))
- off := ir.uint64()
+ for nSyms := ird.uint64(); nSyms > 0; nSyms-- {
+ s := pkg.Lookup(p.stringAt(ird.uint64()))
+ off := ird.uint64()
if _, ok := declImporter[s]; ok {
continue
}
// Inline body index.
- for nPkgs := ir.uint64(); nPkgs > 0; nPkgs-- {
- pkg := p.pkgAt(ir.uint64())
+ for nPkgs := ird.uint64(); nPkgs > 0; nPkgs-- {
+ pkg := p.pkgAt(ird.uint64())
- for nSyms := ir.uint64(); nSyms > 0; nSyms-- {
- s := pkg.Lookup(p.stringAt(ir.uint64()))
- off := ir.uint64()
+ for nSyms := ird.uint64(); nSyms > 0; nSyms-- {
+ s := pkg.Lookup(p.stringAt(ird.uint64()))
+ off := ird.uint64()
if _, ok := inlineImporter[s]; ok {
continue
return n
}
-func (l Nodes) asblock() *Node {
- n := nod(OBLOCK, nil, nil)
- n.List = l
- if l.Len() != 0 {
- n.Pos = l.First().Pos
- }
- return n
-}
-
func ngotype(n *Node) *types.Sym {
if n.Type != nil {
return typenamesym(n.Type)
}
func deadcode(fn *Node) {
- deadcodeslice(fn.Nbody)
+ deadcodeslice(&fn.Nbody)
deadcodefn(fn)
}
fn.Nbody.Set([]*Node{nod(OEMPTY, nil, nil)})
}
-func deadcodeslice(nn Nodes) {
+func deadcodeslice(nn *Nodes) {
var lastLabel = -1
for i, n := range nn.Slice() {
if n != nil && n.Op == OLABEL {
}
}
- deadcodeslice(n.Ninit)
- deadcodeslice(n.Nbody)
- deadcodeslice(n.List)
- deadcodeslice(n.Rlist)
+ deadcodeslice(&n.Ninit)
+ deadcodeslice(&n.Nbody)
+ deadcodeslice(&n.List)
+ deadcodeslice(&n.Rlist)
if cut {
- *nn.slice = nn.Slice()[:i+1]
+ nn.Set(nn.Slice()[:i+1])
break
}
}