Commit f85faefa authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

[dev.ssa] cmd/compile: move rewrite logging behind codegen flag

Generating logging code every time causes large
diffs for small changes.

Since the intent is to use this for debugging only,
generate logging code only when requested.
Committed generated code will be logging free.

Change-Id: I9ef9e29c88b76c2557bad4c6b424b9db1255ec8b
Reviewed-on: https://go-review.googlesource.com/13623Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent 867662da
......@@ -9,6 +9,7 @@ package main
import (
"bytes"
"flag"
"fmt"
"go/format"
"io/ioutil"
......@@ -59,6 +60,7 @@ func (a arch) regMaskComment(r regMask) string {
var archs []arch
func main() {
flag.Parse()
genOp()
genLower()
}
......
......@@ -13,6 +13,7 @@ import (
"bufio"
"bytes"
"crypto/md5"
"flag"
"fmt"
"go/format"
"io"
......@@ -45,6 +46,10 @@ import (
// If multiple rules match, the first one in file order is selected.
var (
genLog = flag.Bool("log", false, "generate code that logs; for debugging only")
)
type Rule struct {
rule string
lineno int
......@@ -134,7 +139,9 @@ func genRules(arch arch) {
fmt.Fprintf(w, "// autogenerated from gen/%s.rules: do not edit!\n", arch.name)
fmt.Fprintln(w, "// generated with: cd gen; go run *.go")
fmt.Fprintln(w, "package ssa")
fmt.Fprintln(w, "import \"fmt\"")
if *genLog {
fmt.Fprintln(w, "import \"fmt\"")
}
fmt.Fprintf(w, "func rewriteValue%s(v *Value, config *Config) bool {\n", arch.name)
fmt.Fprintln(w, "b := v.Block")
......@@ -169,9 +176,9 @@ func genRules(arch arch) {
}
genResult(w, arch, result)
fmt.Fprintf(w, "if logRewriteRules {\n")
fmt.Fprintf(w, " fmt.Println(\"rewrite %s.rules:%d\")", arch.name, rule.lineno)
fmt.Fprintf(w, "}\n")
if *genLog {
fmt.Fprintf(w, "fmt.Println(\"rewrite %s.rules:%d\")\n", arch.name, rule.lineno)
}
fmt.Fprintf(w, "return true\n")
fmt.Fprintf(w, "}\n")
......@@ -275,9 +282,9 @@ func genRules(arch arch) {
fmt.Fprintln(w, "b.Likely = BranchUnknown")
}
fmt.Fprintf(w, "if logRewriteRules {\n")
fmt.Fprintf(w, " fmt.Println(\"rewrite %s.rules:%d\")", arch.name, rule.lineno)
fmt.Fprintf(w, "}\n")
if *genLog {
fmt.Fprintf(w, "fmt.Println(\"rewrite %s.rules:%d\")\n", arch.name, rule.lineno)
}
fmt.Fprintf(w, "return true\n")
fmt.Fprintf(w, "}\n")
......@@ -291,13 +298,14 @@ func genRules(arch arch) {
// gofmt result
b := w.Bytes()
b, err = format.Source(b)
src, err := format.Source(b)
if err != nil {
fmt.Printf("%s\n", b)
panic(err)
}
// Write to file
err = ioutil.WriteFile("../rewrite"+arch.name+".go", b, 0666)
err = ioutil.WriteFile("../rewrite"+arch.name+".go", src, 0666)
if err != nil {
log.Fatalf("can't write output: %v\n", err)
}
......
......@@ -6,11 +6,6 @@ package ssa
import "fmt"
// Set to true to log all rewrite rules as they occur.
// This is useful for figuring out whether a rule is triggering
// and which rules are most heavily used.
const logRewriteRules = false
func applyRewrite(f *Func, rb func(*Block) bool, rv func(*Value, *Config) bool) {
// repeat rewrites until we find no more rewrites
var curb *Block
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment