mirror of
https://github.com/golang/go
synced 2024-11-22 22:30:02 -07:00
[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:
parent
e37597f7f0
commit
228b732ad9
@ -140,6 +140,41 @@ type EscEdge struct {
|
||||
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) {
|
||||
|
@ -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
|
||||
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)
|
||||
}
|
||||
@ -443,7 +446,7 @@ func (n *Node) jconv(s fmt.State, flag FmtFlag) {
|
||||
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)
|
||||
}
|
||||
|
||||
@ -455,30 +458,13 @@ func (n *Node) jconv(s fmt.State, flag FmtFlag) {
|
||||
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())
|
||||
}
|
||||
|
||||
@ -518,11 +504,11 @@ func (n *Node) jconv(s fmt.State, flag FmtFlag) {
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
@ -98,16 +98,16 @@ func (r *intReader) uint64() uint64 {
|
||||
}
|
||||
|
||||
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
|
||||
@ -138,10 +138,10 @@ func iimport(pkg *types.Pkg, in *bio.Reader) (fingerprint goobj.FingerprintType)
|
||||
}
|
||||
|
||||
// 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
|
||||
@ -158,9 +158,9 @@ func iimport(pkg *types.Pkg, in *bio.Reader) (fingerprint goobj.FingerprintType)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
@ -177,12 +177,12 @@ func iimport(pkg *types.Pkg, in *bio.Reader) (fingerprint goobj.FingerprintType)
|
||||
}
|
||||
|
||||
// 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
|
||||
|
@ -1585,15 +1585,6 @@ func liststmt(l []*Node) *Node {
|
||||
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)
|
||||
|
@ -3867,7 +3867,7 @@ func checkreturn(fn *Node) {
|
||||
}
|
||||
|
||||
func deadcode(fn *Node) {
|
||||
deadcodeslice(fn.Nbody)
|
||||
deadcodeslice(&fn.Nbody)
|
||||
deadcodefn(fn)
|
||||
}
|
||||
|
||||
@ -3897,7 +3897,7 @@ func deadcodefn(fn *Node) {
|
||||
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 {
|
||||
@ -3939,12 +3939,12 @@ func deadcodeslice(nn Nodes) {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user