[dev.regabi] cmd/compile: prepare for package ir

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>
This commit is contained in:
Russ Cox 2020-11-16 12:18:09 -05:00
parent e37597f7f0
commit 228b732ad9
5 changed files with 72 additions and 60 deletions

View file

@ -140,6 +140,41 @@ type EscEdge struct {
notes *EscNote 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 // escapeFuncs performs escape analysis on a minimal batch of
// functions. // functions.
func escapeFuncs(fns []*Node, recursive bool) { func escapeFuncs(fns []*Node, recursive bool) {

View file

@ -415,19 +415,22 @@ func (n *Node) format(s fmt.State, verb rune, mode fmtMode) {
} }
} }
// 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 // *Node details
func (n *Node) jconv(s fmt.State, flag FmtFlag) { 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 { if Debug_dumpptrs != 0 {
fmt.Fprintf(s, " p(%p)", n) 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) 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 // Useful to see where Defn is set and what node it points to
fmt.Fprintf(s, " defn(%p)", n.Name.Defn) fmt.Fprintf(s, " defn(%p)", n.Name.Defn)
} }
@ -443,7 +446,7 @@ func (n *Node) jconv(s fmt.State, flag FmtFlag) {
fmt.Fprintf(s, " l(%s%d)", pfx, n.Pos.Line()) 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, " x(%d)", n.Xoffset)
} }
@ -455,30 +458,13 @@ func (n *Node) jconv(s fmt.State, flag FmtFlag) {
fmt.Fprintf(s, " colas(%v)", n.Colas()) fmt.Fprintf(s, " colas(%v)", n.Colas())
} }
switch n.Esc { if EscFmt != nil {
case EscUnknown: if esc := EscFmt(n, short); esc != "" {
break fmt.Fprintf(s, " %s", esc)
case EscHeap:
fmt.Fprint(s, " esc(h)")
case EscNone:
fmt.Fprint(s, " esc(no)")
case EscNever:
if c == 0 {
fmt.Fprint(s, " esc(N)")
} }
default:
fmt.Fprintf(s, " esc(%d)", n.Esc)
} }
if e, ok := n.Opt().(*EscLocation); ok && e.loopDepth != 0 { if !short && n.Typecheck() != 0 {
fmt.Fprintf(s, " ld(%d)", e.loopDepth)
}
if c == 0 && n.Typecheck() != 0 {
fmt.Fprintf(s, " tc(%d)", n.Typecheck()) fmt.Fprintf(s, " tc(%d)", n.Typecheck())
} }
@ -518,11 +504,11 @@ func (n *Node) jconv(s fmt.State, flag FmtFlag) {
fmt.Fprint(s, " nonnil") fmt.Fprint(s, " nonnil")
} }
if c == 0 && n.HasCall() { if !short && n.HasCall() {
fmt.Fprint(s, " 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") fmt.Fprint(s, " used")
} }
} }

View file

@ -98,16 +98,16 @@ func (r *intReader) uint64() uint64 {
} }
func iimport(pkg *types.Pkg, in *bio.Reader) (fingerprint goobj.FingerprintType) { 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 { if version != iexportVersion {
yyerror("import %q: unknown export format version %d", pkg.Path, version) yyerror("import %q: unknown export format version %d", pkg.Path, version)
errorexit() errorexit()
} }
sLen := ir.uint64() sLen := ird.uint64()
dLen := ir.uint64() dLen := ird.uint64()
// Map string (and data) section into memory as a single large // Map string (and data) section into memory as a single large
// string. This reduces heap fragmentation and allows // string. This reduces heap fragmentation and allows
@ -138,10 +138,10 @@ func iimport(pkg *types.Pkg, in *bio.Reader) (fingerprint goobj.FingerprintType)
} }
// Declaration index. // Declaration index.
for nPkgs := ir.uint64(); nPkgs > 0; nPkgs-- { for nPkgs := ird.uint64(); nPkgs > 0; nPkgs-- {
pkg := p.pkgAt(ir.uint64()) pkg := p.pkgAt(ird.uint64())
pkgName := p.stringAt(ir.uint64()) pkgName := p.stringAt(ird.uint64())
pkgHeight := int(ir.uint64()) pkgHeight := int(ird.uint64())
if pkg.Name == "" { if pkg.Name == "" {
pkg.Name = pkgName pkg.Name = pkgName
pkg.Height = pkgHeight pkg.Height = pkgHeight
@ -158,9 +158,9 @@ func iimport(pkg *types.Pkg, in *bio.Reader) (fingerprint goobj.FingerprintType)
} }
} }
for nSyms := ir.uint64(); nSyms > 0; nSyms-- { for nSyms := ird.uint64(); nSyms > 0; nSyms-- {
s := pkg.Lookup(p.stringAt(ir.uint64())) s := pkg.Lookup(p.stringAt(ird.uint64()))
off := ir.uint64() off := ird.uint64()
if _, ok := declImporter[s]; ok { if _, ok := declImporter[s]; ok {
continue continue
@ -177,12 +177,12 @@ func iimport(pkg *types.Pkg, in *bio.Reader) (fingerprint goobj.FingerprintType)
} }
// Inline body index. // Inline body index.
for nPkgs := ir.uint64(); nPkgs > 0; nPkgs-- { for nPkgs := ird.uint64(); nPkgs > 0; nPkgs-- {
pkg := p.pkgAt(ir.uint64()) pkg := p.pkgAt(ird.uint64())
for nSyms := ir.uint64(); nSyms > 0; nSyms-- { for nSyms := ird.uint64(); nSyms > 0; nSyms-- {
s := pkg.Lookup(p.stringAt(ir.uint64())) s := pkg.Lookup(p.stringAt(ird.uint64()))
off := ir.uint64() off := ird.uint64()
if _, ok := inlineImporter[s]; ok { if _, ok := inlineImporter[s]; ok {
continue continue

View file

@ -1585,15 +1585,6 @@ func liststmt(l []*Node) *Node {
return n 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 { func ngotype(n *Node) *types.Sym {
if n.Type != nil { if n.Type != nil {
return typenamesym(n.Type) return typenamesym(n.Type)

View file

@ -3867,7 +3867,7 @@ func checkreturn(fn *Node) {
} }
func deadcode(fn *Node) { func deadcode(fn *Node) {
deadcodeslice(fn.Nbody) deadcodeslice(&fn.Nbody)
deadcodefn(fn) deadcodefn(fn)
} }
@ -3897,7 +3897,7 @@ func deadcodefn(fn *Node) {
fn.Nbody.Set([]*Node{nod(OEMPTY, nil, nil)}) fn.Nbody.Set([]*Node{nod(OEMPTY, nil, nil)})
} }
func deadcodeslice(nn Nodes) { func deadcodeslice(nn *Nodes) {
var lastLabel = -1 var lastLabel = -1
for i, n := range nn.Slice() { for i, n := range nn.Slice() {
if n != nil && n.Op == OLABEL { if n != nil && n.Op == OLABEL {
@ -3939,12 +3939,12 @@ func deadcodeslice(nn Nodes) {
} }
} }
deadcodeslice(n.Ninit) deadcodeslice(&n.Ninit)
deadcodeslice(n.Nbody) deadcodeslice(&n.Nbody)
deadcodeslice(n.List) deadcodeslice(&n.List)
deadcodeslice(n.Rlist) deadcodeslice(&n.Rlist)
if cut { if cut {
*nn.slice = nn.Slice()[:i+1] nn.Set(nn.Slice()[:i+1])
break break
} }
} }