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>
}
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...)
}
}
+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.
}
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...) }
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"
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 {
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)
}
}
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{})
}
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...)
}
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{}) {
}
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...)
}
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...)
}