[dev.ssa] cmd/compile: enhance command line option processing for SSA
The -d compiler flag can also specify ssa phase and flag,
for example -d=ssa/generic_cse/time,ssa/generic_cse/stats
Spaces in the phase names can be specified with an
underscore. Flags currently parsed (not necessarily
recognized by the phases yet) are:
on, off, mem, time, debug, stats, and test
On, off and time are handled in the harness,
debug, stats, and test are interpreted by the phase itself.
The pass is now attached to the Func being compiled, and a
new method logStats(key, ...value) on *Func to encourage a
semi-standardized format for that output. Output fields
are separated by tabs to ease digestion by awk and
spreadsheets. For example,
if f.pass.stats > 0 {
f.logStat("CSE REWRITES", rewrites)
}
Change-Id: I16db2b5af64c50ca9a47efeb51d961147a903abc
Reviewed-on: https://go-review.googlesource.com/19885
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Todd Neal <todd@tneal.org>
diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go
index 4d381e5..a463f9d 100644
--- a/src/cmd/compile/internal/gc/ssa.go
+++ b/src/cmd/compile/internal/gc/ssa.go
@@ -6,7 +6,6 @@
import (
"bytes"
- "crypto/sha1"
"fmt"
"html"
"math"
@@ -24,6 +23,15 @@
var ssaConfig *ssa.Config
var ssaExp ssaExport
+func initssa() *ssa.Config {
+ ssaExp.unimplemented = false
+ ssaExp.mustImplement = true
+ if ssaConfig == nil {
+ ssaConfig = ssa.NewConfig(Thearch.Thestring, &ssaExp, Ctxt, Debug['N'] == 0)
+ }
+ return ssaConfig
+}
+
func shouldssa(fn *Node) bool {
if Thearch.Thestring != "amd64" {
return false
@@ -67,42 +75,7 @@
return localpkg.Name == pkg
}
- gossahash := os.Getenv("GOSSAHASH")
- if gossahash == "" || gossahash == "y" || gossahash == "Y" {
- return true
- }
- if gossahash == "n" || gossahash == "N" {
- return false
- }
-
- // Check the hash of the name against a partial input hash.
- // We use this feature to do a binary search within a package to
- // find a function that is incorrectly compiled.
- hstr := ""
- for _, b := range sha1.Sum([]byte(name)) {
- hstr += fmt.Sprintf("%08b", b)
- }
-
- if strings.HasSuffix(hstr, gossahash) {
- fmt.Printf("GOSSAHASH triggered %s\n", name)
- return true
- }
-
- // Iteratively try additional hashes to allow tests for multi-point
- // failure.
- for i := 0; true; i++ {
- ev := fmt.Sprintf("GOSSAHASH%d", i)
- evv := os.Getenv(ev)
- if evv == "" {
- break
- }
- if strings.HasSuffix(hstr, evv) {
- fmt.Printf("%s triggered %s\n", ev, name)
- return true
- }
- }
-
- return false
+ return initssa().DebugHashMatch("GOSSAHASH", name)
}
// buildssa builds an SSA function.
@@ -123,12 +96,8 @@
// TODO(khr): build config just once at the start of the compiler binary
ssaExp.log = printssa
- ssaExp.unimplemented = false
- ssaExp.mustImplement = true
- if ssaConfig == nil {
- ssaConfig = ssa.NewConfig(Thearch.Thestring, &ssaExp, Ctxt, Debug['N'] == 0)
- }
- s.config = ssaConfig
+
+ s.config = initssa()
s.f = s.config.NewFunc()
s.f.Name = name
s.exitCode = fn.Func.Exit