mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
This replaces the compiler's legacy constant representation with go/constant, which is used by go/types. This should ease integrating with the new go/types-based type checker in the future. Performance difference is mixed, but there's still room for improvement. name old time/op new time/op delta Template 280ms ± 6% 281ms ± 6% ~ (p=0.488 n=592+587) Unicode 132ms ±11% 129ms ±11% -2.61% (p=0.000 n=592+591) GoTypes 865ms ± 3% 866ms ± 3% +0.16% (p=0.019 n=572+577) Compiler 3.60s ± 3% 3.60s ± 3% ~ (p=0.083 n=578+582) SSA 8.27s ± 2% 8.28s ± 2% +0.14% (p=0.002 n=575+580) Flate 177ms ± 8% 176ms ± 8% ~ (p=0.133 n=580+590) GoParser 238ms ± 7% 237ms ± 6% ~ (p=0.569 n=587+591) Reflect 542ms ± 4% 543ms ± 4% ~ (p=0.064 n=581+579) Tar 244ms ± 6% 244ms ± 6% ~ (p=0.880 n=586+584) XML 322ms ± 5% 322ms ± 5% ~ (p=0.449 n=589+590) LinkCompiler 454ms ± 6% 453ms ± 6% ~ (p=0.249 n=585+583) ExternalLinkCompiler 1.35s ± 4% 1.35s ± 4% ~ (p=0.968 n=590+588) LinkWithoutDebugCompiler 279ms ± 7% 280ms ± 7% ~ (p=0.270 n=589+586) [Geo mean] 535ms 534ms -0.17% name old user-time/op new user-time/op delta Template 599ms ±22% 602ms ±21% ~ (p=0.377 n=588+590) Unicode 410ms ±43% 376ms ±39% -8.36% (p=0.000 n=596+586) GoTypes 1.96s ±15% 1.97s ±17% +0.70% (p=0.031 n=596+594) Compiler 7.47s ± 9% 7.50s ± 8% +0.38% (p=0.031 n=591+583) SSA 16.2s ± 4% 16.2s ± 5% ~ (p=0.617 n=531+531) Flate 298ms ±25% 292ms ±30% -2.14% (p=0.001 n=594+596) GoParser 379ms ±20% 381ms ±21% ~ (p=0.312 n=578+584) Reflect 1.24s ±20% 1.25s ±23% +0.88% (p=0.031 n=592+596) Tar 471ms ±23% 473ms ±21% ~ (p=0.616 n=593+587) XML 674ms ±20% 681ms ±21% +1.03% (p=0.050 n=584+587) LinkCompiler 842ms ±10% 839ms ±10% ~ (p=0.074 n=587+590) ExternalLinkCompiler 1.65s ± 7% 1.65s ± 7% ~ (p=0.767 n=590+585) LinkWithoutDebugCompiler 378ms ±11% 379ms ±12% ~ (p=0.677 n=591+586) [Geo mean] 1.02s 1.02s -0.52% name old alloc/op new alloc/op delta Template 37.4MB ± 0% 37.4MB ± 0% +0.06% (p=0.000 n=589+585) Unicode 29.6MB ± 0% 28.6MB ± 0% -3.11% (p=0.000 n=574+566) GoTypes 120MB ± 0% 120MB ± 0% -0.01% (p=0.000 n=594+593) Compiler 568MB ± 0% 568MB ± 0% -0.02% (p=0.000 n=588+591) SSA 1.45GB ± 0% 1.45GB ± 0% -0.16% (p=0.000 n=596+592) Flate 22.6MB ± 0% 22.5MB ± 0% -0.36% (p=0.000 n=593+595) GoParser 30.1MB ± 0% 30.1MB ± 0% -0.01% (p=0.000 n=590+594) Reflect 77.8MB ± 0% 77.8MB ± 0% ~ (p=0.631 n=584+591) Tar 34.1MB ± 0% 34.1MB ± 0% -0.04% (p=0.000 n=584+588) XML 43.6MB ± 0% 43.6MB ± 0% +0.07% (p=0.000 n=593+591) LinkCompiler 98.6MB ± 0% 98.6MB ± 0% ~ (p=0.096 n=590+589) ExternalLinkCompiler 89.6MB ± 0% 89.6MB ± 0% ~ (p=0.695 n=590+587) LinkWithoutDebugCompiler 57.2MB ± 0% 57.2MB ± 0% ~ (p=0.674 n=590+589) [Geo mean] 78.5MB 78.3MB -0.28% name old allocs/op new allocs/op delta Template 379k ± 0% 380k ± 0% +0.33% (p=0.000 n=593+590) Unicode 344k ± 0% 338k ± 0% -1.67% (p=0.000 n=594+589) GoTypes 1.30M ± 0% 1.31M ± 0% +0.19% (p=0.000 n=592+591) Compiler 5.40M ± 0% 5.41M ± 0% +0.23% (p=0.000 n=587+585) SSA 14.2M ± 0% 14.2M ± 0% +0.08% (p=0.000 n=594+591) Flate 231k ± 0% 230k ± 0% -0.42% (p=0.000 n=588+589) GoParser 314k ± 0% 315k ± 0% +0.16% (p=0.000 n=587+594) Reflect 975k ± 0% 976k ± 0% +0.10% (p=0.000 n=590+594) Tar 344k ± 0% 345k ± 0% +0.24% (p=0.000 n=595+590) XML 422k ± 0% 424k ± 0% +0.57% (p=0.000 n=590+589) LinkCompiler 538k ± 0% 538k ± 0% -0.00% (p=0.045 n=592+587) ExternalLinkCompiler 593k ± 0% 593k ± 0% ~ (p=0.171 n=588+587) LinkWithoutDebugCompiler 172k ± 0% 172k ± 0% ~ (p=0.996 n=590+585) [Geo mean] 685k 685k -0.02% name old maxRSS/op new maxRSS/op delta Template 53.7M ± 8% 53.8M ± 8% ~ (p=0.666 n=576+574) Unicode 54.4M ±12% 55.0M ±10% +1.15% (p=0.000 n=591+588) GoTypes 95.1M ± 4% 95.1M ± 4% ~ (p=0.948 n=589+591) Compiler 334M ± 6% 334M ± 6% ~ (p=0.875 n=592+593) SSA 792M ± 5% 791M ± 5% ~ (p=0.067 n=592+591) Flate 39.9M ±11% 40.0M ±10% ~ (p=0.131 n=596+596) GoParser 45.2M ±11% 45.3M ±11% ~ (p=0.353 n=592+590) Reflect 76.1M ± 5% 76.2M ± 5% ~ (p=0.114 n=594+594) Tar 49.4M ±10% 49.6M ± 9% +0.57% (p=0.015 n=590+593) XML 57.4M ± 9% 57.7M ± 8% +0.67% (p=0.000 n=592+580) LinkCompiler 183M ± 2% 183M ± 2% ~ (p=0.229 n=587+591) ExternalLinkCompiler 187M ± 2% 187M ± 3% ~ (p=0.362 n=571+562) LinkWithoutDebugCompiler 143M ± 3% 143M ± 3% ~ (p=0.350 n=584+586) [Geo mean] 103M 103M +0.23% Passes toolstash-check. Fixes #4617. Change-Id: Id4f6759b4afc5e002770091d0d4f6e272ee6cbdd Reviewed-on: https://go-review.googlesource.com/c/go/+/272654 Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Matthew Dempsky <mdempsky@google.com>
233 lines
5.3 KiB
Go
233 lines
5.3 KiB
Go
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package gc
|
|
|
|
import (
|
|
"cmd/compile/internal/types"
|
|
"cmd/internal/bio"
|
|
"cmd/internal/src"
|
|
"fmt"
|
|
"go/constant"
|
|
)
|
|
|
|
var (
|
|
Debug_export int // if set, print debugging information about export data
|
|
)
|
|
|
|
func exportf(bout *bio.Writer, format string, args ...interface{}) {
|
|
fmt.Fprintf(bout, format, args...)
|
|
if Debug_export != 0 {
|
|
fmt.Printf(format, args...)
|
|
}
|
|
}
|
|
|
|
var asmlist []*Node
|
|
|
|
// exportsym marks n for export (or reexport).
|
|
func exportsym(n *Node) {
|
|
if n.Sym.OnExportList() {
|
|
return
|
|
}
|
|
n.Sym.SetOnExportList(true)
|
|
|
|
if Debug.E != 0 {
|
|
fmt.Printf("export symbol %v\n", n.Sym)
|
|
}
|
|
|
|
exportlist = append(exportlist, n)
|
|
}
|
|
|
|
func initname(s string) bool {
|
|
return s == "init"
|
|
}
|
|
|
|
func autoexport(n *Node, ctxt Class) {
|
|
if n.Sym.Pkg != localpkg {
|
|
return
|
|
}
|
|
if (ctxt != PEXTERN && ctxt != PFUNC) || dclcontext != PEXTERN {
|
|
return
|
|
}
|
|
if n.Type != nil && n.Type.IsKind(TFUNC) && n.IsMethod() {
|
|
return
|
|
}
|
|
|
|
if types.IsExported(n.Sym.Name) || initname(n.Sym.Name) {
|
|
exportsym(n)
|
|
}
|
|
if asmhdr != "" && !n.Sym.Asm() {
|
|
n.Sym.SetAsm(true)
|
|
asmlist = append(asmlist, n)
|
|
}
|
|
}
|
|
|
|
func dumpexport(bout *bio.Writer) {
|
|
// The linker also looks for the $$ marker - use char after $$ to distinguish format.
|
|
exportf(bout, "\n$$B\n") // indicate binary export format
|
|
off := bout.Offset()
|
|
iexport(bout.Writer)
|
|
size := bout.Offset() - off
|
|
exportf(bout, "\n$$\n")
|
|
|
|
if Debug_export != 0 {
|
|
fmt.Printf("BenchmarkExportSize:%s 1 %d bytes\n", myimportpath, size)
|
|
}
|
|
}
|
|
|
|
func importsym(ipkg *types.Pkg, s *types.Sym, op Op) *Node {
|
|
n := asNode(s.PkgDef())
|
|
if n == nil {
|
|
// iimport should have created a stub ONONAME
|
|
// declaration for all imported symbols. The exception
|
|
// is declarations for Runtimepkg, which are populated
|
|
// by loadsys instead.
|
|
if s.Pkg != Runtimepkg {
|
|
Fatalf("missing ONONAME for %v\n", s)
|
|
}
|
|
|
|
n = dclname(s)
|
|
s.SetPkgDef(asTypesNode(n))
|
|
s.Importdef = ipkg
|
|
}
|
|
if n.Op != ONONAME && n.Op != op {
|
|
redeclare(lineno, s, fmt.Sprintf("during import %q", ipkg.Path))
|
|
}
|
|
return n
|
|
}
|
|
|
|
// importtype returns the named type declared by symbol s.
|
|
// If no such type has been declared yet, a forward declaration is returned.
|
|
// ipkg is the package being imported
|
|
func importtype(ipkg *types.Pkg, pos src.XPos, s *types.Sym) *types.Type {
|
|
n := importsym(ipkg, s, OTYPE)
|
|
if n.Op != OTYPE {
|
|
t := types.New(TFORW)
|
|
t.Sym = s
|
|
t.Nod = asTypesNode(n)
|
|
|
|
n.Op = OTYPE
|
|
n.Pos = pos
|
|
n.Type = t
|
|
n.SetClass(PEXTERN)
|
|
}
|
|
|
|
t := n.Type
|
|
if t == nil {
|
|
Fatalf("importtype %v", s)
|
|
}
|
|
return t
|
|
}
|
|
|
|
// importobj declares symbol s as an imported object representable by op.
|
|
// ipkg is the package being imported
|
|
func importobj(ipkg *types.Pkg, pos src.XPos, s *types.Sym, op Op, ctxt Class, t *types.Type) *Node {
|
|
n := importsym(ipkg, s, op)
|
|
if n.Op != ONONAME {
|
|
if n.Op == op && (n.Class() != ctxt || !types.Identical(n.Type, t)) {
|
|
redeclare(lineno, s, fmt.Sprintf("during import %q", ipkg.Path))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
n.Op = op
|
|
n.Pos = pos
|
|
n.SetClass(ctxt)
|
|
if ctxt == PFUNC {
|
|
n.Sym.SetFunc(true)
|
|
}
|
|
n.Type = t
|
|
return n
|
|
}
|
|
|
|
// importconst declares symbol s as an imported constant with type t and value val.
|
|
// ipkg is the package being imported
|
|
func importconst(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type, val constant.Value) {
|
|
n := importobj(ipkg, pos, s, OLITERAL, PEXTERN, t)
|
|
if n == nil { // TODO: Check that value matches.
|
|
return
|
|
}
|
|
|
|
n.SetVal(val)
|
|
|
|
if Debug.E != 0 {
|
|
fmt.Printf("import const %v %L = %v\n", s, t, val)
|
|
}
|
|
}
|
|
|
|
// importfunc declares symbol s as an imported function with type t.
|
|
// ipkg is the package being imported
|
|
func importfunc(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type) {
|
|
n := importobj(ipkg, pos, s, ONAME, PFUNC, t)
|
|
if n == nil {
|
|
return
|
|
}
|
|
|
|
n.Func = new(Func)
|
|
|
|
if Debug.E != 0 {
|
|
fmt.Printf("import func %v%S\n", s, t)
|
|
}
|
|
}
|
|
|
|
// importvar declares symbol s as an imported variable with type t.
|
|
// ipkg is the package being imported
|
|
func importvar(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type) {
|
|
n := importobj(ipkg, pos, s, ONAME, PEXTERN, t)
|
|
if n == nil {
|
|
return
|
|
}
|
|
|
|
if Debug.E != 0 {
|
|
fmt.Printf("import var %v %L\n", s, t)
|
|
}
|
|
}
|
|
|
|
// importalias declares symbol s as an imported type alias with type t.
|
|
// ipkg is the package being imported
|
|
func importalias(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type) {
|
|
n := importobj(ipkg, pos, s, OTYPE, PEXTERN, t)
|
|
if n == nil {
|
|
return
|
|
}
|
|
|
|
if Debug.E != 0 {
|
|
fmt.Printf("import type %v = %L\n", s, t)
|
|
}
|
|
}
|
|
|
|
func dumpasmhdr() {
|
|
b, err := bio.Create(asmhdr)
|
|
if err != nil {
|
|
Fatalf("%v", err)
|
|
}
|
|
fmt.Fprintf(b, "// generated by compile -asmhdr from package %s\n\n", localpkg.Name)
|
|
for _, n := range asmlist {
|
|
if n.Sym.IsBlank() {
|
|
continue
|
|
}
|
|
switch n.Op {
|
|
case OLITERAL:
|
|
t := n.Val().Kind()
|
|
if t == constant.Float || t == constant.Complex {
|
|
break
|
|
}
|
|
fmt.Fprintf(b, "#define const_%s %#v\n", n.Sym.Name, n.Val())
|
|
|
|
case OTYPE:
|
|
t := n.Type
|
|
if !t.IsStruct() || t.StructType().Map != nil || t.IsFuncArgStruct() {
|
|
break
|
|
}
|
|
fmt.Fprintf(b, "#define %s__size %d\n", n.Sym.Name, int(t.Width))
|
|
for _, f := range t.Fields().Slice() {
|
|
if !f.Sym.IsBlank() {
|
|
fmt.Fprintf(b, "#define %s_%s %d\n", n.Sym.Name, f.Sym.Name, int(f.Offset))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
b.Close()
|
|
}
|