]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: exposed do-log boolean to reduce allocations
authorDavid Chase <drchase@google.com>
Fri, 29 Jan 2016 19:44:15 +0000 (14:44 -0500)
committerDavid Chase <drchase@google.com>
Fri, 29 Jan 2016 21:30:29 +0000 (21:30 +0000)
From memory profiling, about 3% reduction in allocation count.

Change-Id: I4b662d55b8a94fe724759a2b22f05a08d0bf40f8
Reviewed-on: https://go-review.googlesource.com/19103
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/ssa/block.go
src/cmd/compile/internal/ssa/compile.go
src/cmd/compile/internal/ssa/config.go
src/cmd/compile/internal/ssa/export_test.go
src/cmd/compile/internal/ssa/func.go
src/cmd/compile/internal/ssa/value.go

index 89286f43566b405503062d3b4f145fe31b51b49c..c5be3496c37c5625b7aa1149c2d5fc89242af86f 100644 (file)
@@ -327,6 +327,7 @@ func (s *state) label(sym *Sym) *ssaLabel {
 }
 
 func (s *state) Logf(msg string, args ...interface{})   { s.config.Logf(msg, args...) }
+func (s *state) Log() bool                              { return s.config.Log() }
 func (s *state) Fatalf(msg string, args ...interface{}) { s.config.Fatalf(s.peekLine(), msg, args...) }
 func (s *state) Unimplementedf(msg string, args ...interface{}) {
        s.config.Unimplementedf(s.peekLine(), msg, args...)
@@ -4885,6 +4886,10 @@ func (e *ssaExport) Logf(msg string, args ...interface{}) {
        }
 }
 
+func (e *ssaExport) Log() bool {
+       return e.log
+}
+
 // Fatal reports a compiler error and exits.
 func (e *ssaExport) Fatalf(line int32, msg string, args ...interface{}) {
        // If e was marked as unimplemented, anything could happen. Ignore.
index 6585528b28b25da2532a483a6351239fcd41c7f0..7641811a5fad0c01d35dde5ea9f76d0f949bb75a 100644 (file)
@@ -105,6 +105,7 @@ func (b *Block) AddEdgeTo(c *Block) {
 }
 
 func (b *Block) Logf(msg string, args ...interface{})           { b.Func.Logf(msg, args...) }
+func (b *Block) Log() bool                                      { return b.Func.Log() }
 func (b *Block) Fatalf(msg string, args ...interface{})         { b.Func.Fatalf(msg, args...) }
 func (b *Block) Unimplementedf(msg string, args ...interface{}) { b.Func.Unimplementedf(msg, args...) }
 
index 75c73eb24f329242344f11bc31dddac889f1956f..99e3c2b01e1421c74195bd7152dbd94d26608ebb 100644 (file)
@@ -20,7 +20,9 @@ import (
 func Compile(f *Func) {
        // TODO: debugging - set flags to control verbosity of compiler,
        // which phases to dump IR before/after, etc.
-       f.Logf("compiling %s\n", f.Name)
+       if f.Log() {
+               f.Logf("compiling %s\n", f.Name)
+       }
 
        // hook to print function & phase if panic happens
        phaseName := "init"
@@ -44,7 +46,9 @@ func Compile(f *Func) {
                        continue
                }
                phaseName = p.name
-               f.Logf("  pass %s begin\n", p.name)
+               if f.Log() {
+                       f.Logf("  pass %s begin\n", p.name)
+               }
                // TODO: capture logging during this pass, add it to the HTML
                var mStart runtime.MemStats
                if logMemStats {
@@ -67,9 +71,13 @@ func Compile(f *Func) {
                        stats = fmt.Sprintf("[%d ns]", time)
                }
 
-               f.Logf("  pass %s end %s\n", p.name, stats)
+               if f.Log() {
+                       f.Logf("  pass %s end %s\n", p.name, stats)
+               }
                printFunc(f)
-               f.Config.HTML.WriteFunc(fmt.Sprintf("after %s <span class=\"stats\">%s</span>", phaseName, stats), f)
+               if f.Config.HTML != nil {
+                       f.Config.HTML.WriteFunc(fmt.Sprintf("after %s <span class=\"stats\">%s</span>", phaseName, stats), f)
+               }
                checkFunc(f)
        }
 
index 52e772ce81050496c8b82055307260e989a7b6d6..060eec233585b41feb06e238e8242d2806c71529 100644 (file)
@@ -46,9 +46,13 @@ type TypeSource interface {
 }
 
 type Logger interface {
-       // Log logs a message from the compiler.
+       // Logf logs a message from the compiler.
        Logf(string, ...interface{})
 
+       // Log returns true if logging is not a no-op
+       // some logging calls account for more than a few heap allocations.
+       Log() bool
+
        // Fatal reports a compiler error and exits.
        Fatalf(line int32, msg string, args ...interface{})
 
@@ -131,6 +135,7 @@ func (c *Config) NewFunc() *Func {
 }
 
 func (c *Config) Logf(msg string, args ...interface{})               { c.fe.Logf(msg, args...) }
+func (c *Config) Log() bool                                          { return c.fe.Log() }
 func (c *Config) Fatalf(line int32, msg string, args ...interface{}) { c.fe.Fatalf(line, msg, args...) }
 func (c *Config) Unimplementedf(line int32, msg string, args ...interface{}) {
        c.fe.Unimplementedf(line, msg, args...)
index 962dc52a5faff6dba69618cbc84203fa131a8ef6..dae9ed7de0031e0336b95751972585a6c8157035 100644 (file)
@@ -36,6 +36,7 @@ func (DummyFrontend) Line(line int32) string {
 }
 
 func (d DummyFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, args...) }
+func (d DummyFrontend) Log() bool                            { return true }
 
 func (d DummyFrontend) Fatalf(line int32, msg string, args ...interface{}) { d.t.Fatalf(msg, args...) }
 func (d DummyFrontend) Unimplementedf(line int32, msg string, args ...interface{}) {
index 6d20a2797df87dc6ea98d245cbe3993ca25ce044..a28484010d0be1a9d8c90fc54413ed651e80020b 100644 (file)
@@ -264,6 +264,7 @@ func (f *Func) ConstFloat64(line int32, t Type, c float64) *Value {
 }
 
 func (f *Func) Logf(msg string, args ...interface{})   { f.Config.Logf(msg, args...) }
+func (f *Func) Log() bool                              { return f.Config.Log() }
 func (f *Func) Fatalf(msg string, args ...interface{}) { f.Config.Fatalf(f.Entry.Line, msg, args...) }
 func (f *Func) Unimplementedf(msg string, args ...interface{}) {
        f.Config.Unimplementedf(f.Entry.Line, msg, args...)
index 7e6e544e26f54f53ad57815a369388197e8e1f59..e338c4435bfce9d4beac7ab16528ce432f909258 100644 (file)
@@ -147,6 +147,7 @@ func (v *Value) copyInto(b *Block) *Value {
 }
 
 func (v *Value) Logf(msg string, args ...interface{}) { v.Block.Logf(msg, args...) }
+func (v *Value) Log() bool                            { return v.Block.Log() }
 func (v *Value) Fatalf(msg string, args ...interface{}) {
        v.Block.Func.Config.Fatalf(v.Line, msg, args...)
 }