Skip to content
This repository has been archived by the owner on May 2, 2018. It is now read-only.

Commit

Permalink
cmd/compile: get gcflags to bootstrap; ssa debug opts for "all"
Browse files Browse the repository at this point in the history
This is intended to help debug compiler problems that pop
up in the bootstrap phase of make.bash.  GO_GCFLAGS does not
normally apply there.  Options-for-all phases is intended
to allow crude tracing (and full timing) by turning on timing
for all phases, not just one.

Phase names can also be specified using a regular expression,
for example
BOOT_GO_GCFLAGS=-d='ssa/~^.*scc$/off' \
GO_GCFLAGS='-d=ssa/~^.*scc$/off' ./make.bash

I just added this because it was the fastest way to get
me to a place where I could easily debug the compiler.

Change-Id: I0781f3e7c19651ae7452fa25c2d54c9a245ef62d
Reviewed-on: https://go-review.googlesource.com/20775
Reviewed-by: Keith Randall <[email protected]>
Run-TryBot: David Chase <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
dr2chase committed Mar 18, 2016
1 parent 2cc42cf commit 09a9ce6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
50 changes: 44 additions & 6 deletions src/cmd/compile/internal/ssa/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package ssa
import (
"fmt"
"log"
"regexp"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -121,10 +122,21 @@ var checkEnabled = false

// PhaseOption sets the specified flag in the specified ssa phase,
// returning empty string if this was successful or a string explaining
// the error if it was not. A version of the phase name with "_"
// replaced by " " is also checked for a match.
// See gc/lex.go for dissection of the option string. Example use:
// GO_GCFLAGS=-d=ssa/generic_cse/time,ssa/generic_cse/stats,ssa/generic_cse/debug=3 ./make.bash ...
// the error if it was not.
// A version of the phase name with "_" replaced by " " is also checked for a match.
// If the phase name begins a '~' then the rest of the underscores-replaced-with-blanks
// version is used as a regular expression to match the phase name(s).
//
// Special cases that have turned out to be useful:
// ssa/check/on enables checking after each phase
// ssa/all/time enables time reporting for all phases
//
// See gc/lex.go for dissection of the option string.
// Example uses:
//
// GO_GCFLAGS=-d=ssa/generic_cse/time,ssa/generic_cse/stats,ssa/generic_cse/debug=3 ./make.bash
//
// BOOT_GO_GCFLAGS=-d='ssa/~^.*scc$/off' GO_GCFLAGS='-d=ssa/~^.*scc$/off' ./make.bash
//
func PhaseOption(phase, flag string, val int) string {
if phase == "check" && flag == "on" {
Expand All @@ -135,9 +147,32 @@ func PhaseOption(phase, flag string, val int) string {
checkEnabled = val == 0
return ""
}

alltime := false
if phase == "all" {
if flag == "time" {
alltime = val != 0
} else {
return fmt.Sprintf("Did not find a flag matching %s in -d=ssa/%s debug option", flag, phase)
}
}

underphase := strings.Replace(phase, "_", " ", -1)
var re *regexp.Regexp
if phase[0] == '~' {
r, ok := regexp.Compile(underphase[1:])
if ok != nil {
return fmt.Sprintf("Error %s in regexp for phase %s, flag %s", ok.Error(), phase, flag)
}
re = r
}
matchedOne := false
for i, p := range passes {
if p.name == phase || p.name == underphase {
if phase == "all" {
p.time = alltime
passes[i] = p
matchedOne = true
} else if p.name == phase || p.name == underphase || re != nil && re.MatchString(p.name) {
switch flag {
case "on":
p.disabled = val == 0
Expand All @@ -160,9 +195,12 @@ func PhaseOption(phase, flag string, val int) string {
return fmt.Sprintf("Cannot disable required SSA phase %s using -d=ssa/%s debug option", phase, phase)
}
passes[i] = p
return ""
matchedOne = true
}
}
if matchedOne {
return ""
}
return fmt.Sprintf("Did not find a phase matching %s in -d=ssa/... debug option", phase)
}

Expand Down
6 changes: 6 additions & 0 deletions src/cmd/dist/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
goroot string
goroot_final string
goextlinkenabled string
gogcflags string // For running built compiler
workdir string
tooldir string
oldgoos string
Expand Down Expand Up @@ -166,6 +167,8 @@ func xinit() {
goextlinkenabled = b
}

gogcflags = os.Getenv("GO_GCFLAGS")

b = os.Getenv("CC")
if b == "" {
// Use clang on OS X, because gcc is deprecated there.
Expand Down Expand Up @@ -687,6 +690,9 @@ func install(dir string) {
archive = b
}
compile := []string{pathf("%s/compile", tooldir), "-pack", "-o", b, "-p", pkg}
if gogcflags != "" {
compile = append(compile, gogcflags)
}
if dir == "runtime" {
compile = append(compile, "-+", "-asmhdr", pathf("%s/go_asm.h", workdir))
}
Expand Down
3 changes: 2 additions & 1 deletion src/make.bash
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ if [ "$1" = "--no-clean" ]; then
buildall=""
shift
fi
./cmd/dist/dist bootstrap $buildall $GO_DISTFLAGS -v # builds go_bootstrap

GO_GCFLAGS="$BOOT_GO_GCFLAGS" ./cmd/dist/dist bootstrap $buildall $GO_DISTFLAGS -v # builds go_bootstrap
# Delay move of dist tool to now, because bootstrap may clear tool directory.
mv cmd/dist/dist "$GOTOOLDIR"/dist
echo
Expand Down

0 comments on commit 09a9ce6

Please sign in to comment.