mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
The branchelim pass works better after fuse. Running fuse before branchelim also increases the stability of generated code amidst other compiler changes, which was the original motivation behind this change. The fuse pass is not cheap enough to run in its entirety before branchelim, but the most important half of it is. This change makes it possible to run "plain fuse" independently and does so before branchelim. During make.bash, elimIf occurrences increase from 4244 to 4288 (1%), and elimIfElse occurrences increase from 989 to 1079 (9%). Toolspeed impact is marginal; plain fuse pays for itself. name old time/op new time/op delta Template 189ms ± 2% 189ms ± 2% ~ (p=0.890 n=45+46) Unicode 93.2ms ± 5% 93.4ms ± 7% ~ (p=0.790 n=48+48) GoTypes 662ms ± 4% 660ms ± 4% ~ (p=0.186 n=48+49) Compiler 2.89s ± 4% 2.91s ± 3% +0.89% (p=0.050 n=49+44) SSA 8.23s ± 2% 8.21s ± 1% ~ (p=0.165 n=46+44) Flate 123ms ± 4% 123ms ± 3% +0.58% (p=0.031 n=47+49) GoParser 154ms ± 4% 154ms ± 4% ~ (p=0.492 n=49+48) Reflect 430ms ± 4% 429ms ± 4% ~ (p=1.000 n=48+48) Tar 171ms ± 3% 170ms ± 4% ~ (p=0.122 n=48+48) XML 232ms ± 3% 232ms ± 2% ~ (p=0.850 n=46+49) [Geo mean] 394ms 394ms +0.02% name old user-time/op new user-time/op delta Template 236ms ± 5% 236ms ± 4% ~ (p=0.934 n=50+50) Unicode 132ms ± 7% 130ms ± 9% ~ (p=0.087 n=50+50) GoTypes 861ms ± 3% 867ms ± 4% ~ (p=0.124 n=48+50) Compiler 3.93s ± 4% 3.94s ± 3% ~ (p=0.584 n=49+44) SSA 12.2s ± 2% 12.3s ± 1% ~ (p=0.610 n=46+45) Flate 149ms ± 4% 150ms ± 4% ~ (p=0.194 n=48+49) GoParser 193ms ± 5% 191ms ± 6% ~ (p=0.239 n=49+50) Reflect 553ms ± 5% 556ms ± 5% ~ (p=0.091 n=49+49) Tar 218ms ± 5% 218ms ± 5% ~ (p=0.359 n=49+50) XML 299ms ± 5% 298ms ± 4% ~ (p=0.482 n=50+49) [Geo mean] 516ms 516ms -0.01% name old alloc/op new alloc/op delta Template 36.3MB ± 0% 36.3MB ± 0% -0.02% (p=0.000 n=49+49) Unicode 29.7MB ± 0% 29.7MB ± 0% ~ (p=0.270 n=50+50) GoTypes 126MB ± 0% 126MB ± 0% -0.34% (p=0.000 n=50+49) Compiler 534MB ± 0% 531MB ± 0% -0.50% (p=0.000 n=50+50) SSA 1.98GB ± 0% 1.98GB ± 0% -0.06% (p=0.000 n=49+49) Flate 24.6MB ± 0% 24.6MB ± 0% -0.29% (p=0.000 n=50+50) GoParser 29.5MB ± 0% 29.4MB ± 0% -0.15% (p=0.000 n=49+50) Reflect 87.3MB ± 0% 87.2MB ± 0% -0.13% (p=0.000 n=49+50) Tar 35.6MB ± 0% 35.5MB ± 0% -0.17% (p=0.000 n=50+50) XML 48.2MB ± 0% 48.0MB ± 0% -0.30% (p=0.000 n=48+50) [Geo mean] 83.1MB 82.9MB -0.20% name old allocs/op new allocs/op delta Template 352k ± 0% 352k ± 0% -0.01% (p=0.004 n=49+49) Unicode 341k ± 0% 341k ± 0% ~ (p=0.341 n=48+50) GoTypes 1.28M ± 0% 1.28M ± 0% -0.03% (p=0.000 n=50+49) Compiler 4.96M ± 0% 4.96M ± 0% -0.05% (p=0.000 n=50+49) SSA 15.5M ± 0% 15.5M ± 0% -0.01% (p=0.000 n=50+49) Flate 233k ± 0% 233k ± 0% +0.01% (p=0.032 n=49+49) GoParser 294k ± 0% 294k ± 0% ~ (p=0.052 n=46+48) Reflect 1.04M ± 0% 1.04M ± 0% ~ (p=0.171 n=50+47) Tar 343k ± 0% 343k ± 0% -0.03% (p=0.000 n=50+50) XML 429k ± 0% 429k ± 0% -0.04% (p=0.000 n=50+50) [Geo mean] 812k 812k -0.02% Object files grow slightly; branchelim often increases binary size, at least on amd64. name old object-bytes new object-bytes delta Template 509kB ± 0% 509kB ± 0% -0.01% (p=0.008 n=5+5) Unicode 224kB ± 0% 224kB ± 0% ~ (all equal) GoTypes 1.84MB ± 0% 1.84MB ± 0% +0.00% (p=0.008 n=5+5) Compiler 6.71MB ± 0% 6.71MB ± 0% +0.01% (p=0.008 n=5+5) SSA 21.2MB ± 0% 21.2MB ± 0% +0.01% (p=0.008 n=5+5) Flate 324kB ± 0% 324kB ± 0% -0.00% (p=0.008 n=5+5) GoParser 404kB ± 0% 404kB ± 0% -0.02% (p=0.008 n=5+5) Reflect 1.40MB ± 0% 1.40MB ± 0% +0.09% (p=0.008 n=5+5) Tar 452kB ± 0% 452kB ± 0% +0.06% (p=0.008 n=5+5) XML 596kB ± 0% 596kB ± 0% +0.00% (p=0.008 n=5+5) [Geo mean] 1.04MB 1.04MB +0.01% Change-Id: I535c711b85380ff657fc0f022bebd9cb14ddd07f Reviewed-on: https://go-review.googlesource.com/c/129378 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
496 lines
15 KiB
Go
496 lines
15 KiB
Go
// Copyright 2015 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ssa
|
|
|
|
import (
|
|
"cmd/internal/objabi"
|
|
"cmd/internal/src"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"regexp"
|
|
"runtime"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// Compile is the main entry point for this package.
|
|
// Compile modifies f so that on return:
|
|
// · all Values in f map to 0 or 1 assembly instructions of the target architecture
|
|
// · the order of f.Blocks is the order to emit the Blocks
|
|
// · the order of b.Values is the order to emit the Values in each Block
|
|
// · f has a non-nil regAlloc field
|
|
func Compile(f *Func) {
|
|
// TODO: debugging - set flags to control verbosity of compiler,
|
|
// which phases to dump IR before/after, etc.
|
|
if f.Log() {
|
|
f.Logf("compiling %s\n", f.Name)
|
|
}
|
|
|
|
// hook to print function & phase if panic happens
|
|
phaseName := "init"
|
|
defer func() {
|
|
if phaseName != "" {
|
|
err := recover()
|
|
stack := make([]byte, 16384)
|
|
n := runtime.Stack(stack, false)
|
|
stack = stack[:n]
|
|
f.Fatalf("panic during %s while compiling %s:\n\n%v\n\n%s\n", phaseName, f.Name, err, stack)
|
|
}
|
|
}()
|
|
|
|
// Run all the passes
|
|
if f.Log() {
|
|
printFunc(f)
|
|
}
|
|
f.HTMLWriter.WriteFunc("start", "start", f)
|
|
if BuildDump != "" && BuildDump == f.Name {
|
|
f.dumpFile("build")
|
|
}
|
|
if checkEnabled {
|
|
checkFunc(f)
|
|
}
|
|
const logMemStats = false
|
|
for _, p := range passes {
|
|
if !f.Config.optimize && !p.required || p.disabled {
|
|
continue
|
|
}
|
|
f.pass = &p
|
|
phaseName = 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 || p.mem {
|
|
runtime.ReadMemStats(&mStart)
|
|
}
|
|
|
|
tStart := time.Now()
|
|
p.fn(f)
|
|
tEnd := time.Now()
|
|
|
|
// Need something less crude than "Log the whole intermediate result".
|
|
if f.Log() || f.HTMLWriter != nil {
|
|
time := tEnd.Sub(tStart).Nanoseconds()
|
|
var stats string
|
|
if logMemStats {
|
|
var mEnd runtime.MemStats
|
|
runtime.ReadMemStats(&mEnd)
|
|
nBytes := mEnd.TotalAlloc - mStart.TotalAlloc
|
|
nAllocs := mEnd.Mallocs - mStart.Mallocs
|
|
stats = fmt.Sprintf("[%d ns %d allocs %d bytes]", time, nAllocs, nBytes)
|
|
} else {
|
|
stats = fmt.Sprintf("[%d ns]", time)
|
|
}
|
|
|
|
if f.Log() {
|
|
f.Logf(" pass %s end %s\n", p.name, stats)
|
|
printFunc(f)
|
|
}
|
|
f.HTMLWriter.WriteFunc(phaseName, fmt.Sprintf("%s <span class=\"stats\">%s</span>", phaseName, stats), f)
|
|
}
|
|
if p.time || p.mem {
|
|
// Surround timing information w/ enough context to allow comparisons.
|
|
time := tEnd.Sub(tStart).Nanoseconds()
|
|
if p.time {
|
|
f.LogStat("TIME(ns)", time)
|
|
}
|
|
if p.mem {
|
|
var mEnd runtime.MemStats
|
|
runtime.ReadMemStats(&mEnd)
|
|
nBytes := mEnd.TotalAlloc - mStart.TotalAlloc
|
|
nAllocs := mEnd.Mallocs - mStart.Mallocs
|
|
f.LogStat("TIME(ns):BYTES:ALLOCS", time, nBytes, nAllocs)
|
|
}
|
|
}
|
|
if p.dump != nil && p.dump[f.Name] {
|
|
// Dump function to appropriately named file
|
|
f.dumpFile(phaseName)
|
|
}
|
|
if checkEnabled {
|
|
checkFunc(f)
|
|
}
|
|
}
|
|
|
|
// Squash error printing defer
|
|
phaseName = ""
|
|
}
|
|
|
|
// TODO: should be a config field
|
|
var dumpFileSeq int
|
|
|
|
// dumpFile creates a file from the phase name and function name
|
|
// Dumping is done to files to avoid buffering huge strings before
|
|
// output.
|
|
func (f *Func) dumpFile(phaseName string) {
|
|
dumpFileSeq++
|
|
fname := fmt.Sprintf("%s_%02d__%s.dump", f.Name, dumpFileSeq, phaseName)
|
|
fname = strings.Replace(fname, " ", "_", -1)
|
|
fname = strings.Replace(fname, "/", "_", -1)
|
|
fname = strings.Replace(fname, ":", "_", -1)
|
|
|
|
fi, err := os.Create(fname)
|
|
if err != nil {
|
|
f.Warnl(src.NoXPos, "Unable to create after-phase dump file %s", fname)
|
|
return
|
|
}
|
|
|
|
p := stringFuncPrinter{w: fi}
|
|
fprintFunc(p, f)
|
|
fi.Close()
|
|
}
|
|
|
|
type pass struct {
|
|
name string
|
|
fn func(*Func)
|
|
required bool
|
|
disabled bool
|
|
time bool // report time to run pass
|
|
mem bool // report mem stats to run pass
|
|
stats int // pass reports own "stats" (e.g., branches removed)
|
|
debug int // pass performs some debugging. =1 should be in error-testing-friendly Warnl format.
|
|
test int // pass-specific ad-hoc option, perhaps useful in development
|
|
dump map[string]bool // dump if function name matches
|
|
}
|
|
|
|
func (p *pass) addDump(s string) {
|
|
if p.dump == nil {
|
|
p.dump = make(map[string]bool)
|
|
}
|
|
p.dump[s] = true
|
|
}
|
|
|
|
// Run consistency checker between each phase
|
|
var checkEnabled = false
|
|
|
|
// Debug output
|
|
var IntrinsicsDebug int
|
|
var IntrinsicsDisable bool
|
|
|
|
var BuildDebug int
|
|
var BuildTest int
|
|
var BuildStats int
|
|
var BuildDump string // name of function to dump after initial build of ssa
|
|
|
|
// 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.
|
|
// 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, valString string) string {
|
|
if phase == "help" {
|
|
lastcr := 0
|
|
phasenames := " check, all, build, intrinsics"
|
|
for _, p := range passes {
|
|
pn := strings.Replace(p.name, " ", "_", -1)
|
|
if len(pn)+len(phasenames)-lastcr > 70 {
|
|
phasenames += "\n "
|
|
lastcr = len(phasenames)
|
|
phasenames += pn
|
|
} else {
|
|
phasenames += ", " + pn
|
|
}
|
|
}
|
|
return `PhaseOptions usage:
|
|
|
|
go tool compile -d=ssa/<phase>/<flag>[=<value>|<function_name>]
|
|
|
|
where:
|
|
|
|
- <phase> is one of:
|
|
` + phasenames + `
|
|
|
|
- <flag> is one of:
|
|
on, off, debug, mem, time, test, stats, dump
|
|
|
|
- <value> defaults to 1
|
|
|
|
- <function_name> is required for the "dump" flag, and specifies the
|
|
name of function to dump after <phase>
|
|
|
|
Phase "all" supports flags "time", "mem", and "dump".
|
|
Phase "intrinsics" supports flags "on", "off", and "debug".
|
|
|
|
If the "dump" flag is specified, the output is written on a file named
|
|
<phase>__<function_name>_<seq>.dump; otherwise it is directed to stdout.
|
|
|
|
Examples:
|
|
|
|
-d=ssa/check/on
|
|
enables checking after each phase
|
|
|
|
-d=ssa/all/time
|
|
enables time reporting for all phases
|
|
|
|
-d=ssa/prove/debug=2
|
|
sets debugging level to 2 in the prove pass
|
|
|
|
Multiple flags can be passed at once, by separating them with
|
|
commas. For example:
|
|
|
|
-d=ssa/check/on,ssa/all/time
|
|
`
|
|
}
|
|
|
|
if phase == "check" && flag == "on" {
|
|
checkEnabled = val != 0
|
|
return ""
|
|
}
|
|
if phase == "check" && flag == "off" {
|
|
checkEnabled = val == 0
|
|
return ""
|
|
}
|
|
|
|
alltime := false
|
|
allmem := false
|
|
alldump := false
|
|
if phase == "all" {
|
|
if flag == "time" {
|
|
alltime = val != 0
|
|
} else if flag == "mem" {
|
|
allmem = val != 0
|
|
} else if flag == "dump" {
|
|
alldump = val != 0
|
|
if alldump {
|
|
BuildDump = valString
|
|
}
|
|
} else {
|
|
return fmt.Sprintf("Did not find a flag matching %s in -d=ssa/%s debug option", flag, phase)
|
|
}
|
|
}
|
|
|
|
if phase == "intrinsics" {
|
|
switch flag {
|
|
case "on":
|
|
IntrinsicsDisable = val == 0
|
|
case "off":
|
|
IntrinsicsDisable = val != 0
|
|
case "debug":
|
|
IntrinsicsDebug = val
|
|
default:
|
|
return fmt.Sprintf("Did not find a flag matching %s in -d=ssa/%s debug option", flag, phase)
|
|
}
|
|
return ""
|
|
}
|
|
if phase == "build" {
|
|
switch flag {
|
|
case "debug":
|
|
BuildDebug = val
|
|
case "test":
|
|
BuildTest = val
|
|
case "stats":
|
|
BuildStats = val
|
|
case "dump":
|
|
BuildDump = valString
|
|
default:
|
|
return fmt.Sprintf("Did not find a flag matching %s in -d=ssa/%s debug option", flag, phase)
|
|
}
|
|
return ""
|
|
}
|
|
|
|
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 phase == "all" {
|
|
p.time = alltime
|
|
p.mem = allmem
|
|
if alldump {
|
|
p.addDump(valString)
|
|
}
|
|
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
|
|
case "off":
|
|
p.disabled = val != 0
|
|
case "time":
|
|
p.time = val != 0
|
|
case "mem":
|
|
p.mem = val != 0
|
|
case "debug":
|
|
p.debug = val
|
|
case "stats":
|
|
p.stats = val
|
|
case "test":
|
|
p.test = val
|
|
case "dump":
|
|
p.addDump(valString)
|
|
default:
|
|
return fmt.Sprintf("Did not find a flag matching %s in -d=ssa/%s debug option", flag, phase)
|
|
}
|
|
if p.disabled && p.required {
|
|
return fmt.Sprintf("Cannot disable required SSA phase %s using -d=ssa/%s debug option", phase, phase)
|
|
}
|
|
passes[i] = p
|
|
matchedOne = true
|
|
}
|
|
}
|
|
if matchedOne {
|
|
return ""
|
|
}
|
|
return fmt.Sprintf("Did not find a phase matching %s in -d=ssa/... debug option", phase)
|
|
}
|
|
|
|
// list of passes for the compiler
|
|
var passes = [...]pass{
|
|
// TODO: combine phielim and copyelim into a single pass?
|
|
{name: "number lines", fn: numberLines, required: true},
|
|
{name: "early phielim", fn: phielim},
|
|
{name: "early copyelim", fn: copyelim},
|
|
{name: "early deadcode", fn: deadcode}, // remove generated dead code to avoid doing pointless work during opt
|
|
{name: "short circuit", fn: shortcircuit},
|
|
{name: "decompose user", fn: decomposeUser, required: true},
|
|
{name: "opt", fn: opt, required: true}, // TODO: split required rules and optimizing rules
|
|
{name: "zero arg cse", fn: zcse, required: true}, // required to merge OpSB values
|
|
{name: "opt deadcode", fn: deadcode, required: true}, // remove any blocks orphaned during opt
|
|
{name: "generic cse", fn: cse},
|
|
{name: "phiopt", fn: phiopt},
|
|
{name: "nilcheckelim", fn: nilcheckelim},
|
|
{name: "prove", fn: prove},
|
|
{name: "fuse plain", fn: fusePlain},
|
|
{name: "decompose builtin", fn: decomposeBuiltIn, required: true},
|
|
{name: "softfloat", fn: softfloat, required: true},
|
|
{name: "late opt", fn: opt, required: true}, // TODO: split required rules and optimizing rules
|
|
{name: "dead auto elim", fn: elimDeadAutosGeneric},
|
|
{name: "generic deadcode", fn: deadcode, required: true}, // remove dead stores, which otherwise mess up store chain
|
|
{name: "check bce", fn: checkbce},
|
|
{name: "branchelim", fn: branchelim},
|
|
{name: "fuse", fn: fuseAll},
|
|
{name: "dse", fn: dse},
|
|
{name: "writebarrier", fn: writebarrier, required: true}, // expand write barrier ops
|
|
{name: "insert resched checks", fn: insertLoopReschedChecks,
|
|
disabled: objabi.Preemptibleloops_enabled == 0}, // insert resched checks in loops.
|
|
{name: "lower", fn: lower, required: true},
|
|
{name: "lowered cse", fn: cse},
|
|
{name: "elim unread autos", fn: elimUnreadAutos},
|
|
{name: "lowered deadcode", fn: deadcode, required: true},
|
|
{name: "checkLower", fn: checkLower, required: true},
|
|
{name: "late phielim", fn: phielim},
|
|
{name: "late copyelim", fn: copyelim},
|
|
{name: "tighten", fn: tighten}, // move values closer to their uses
|
|
{name: "phi tighten", fn: phiTighten},
|
|
{name: "late deadcode", fn: deadcode},
|
|
{name: "critical", fn: critical, required: true}, // remove critical edges
|
|
{name: "likelyadjust", fn: likelyadjust},
|
|
{name: "layout", fn: layout, required: true}, // schedule blocks
|
|
{name: "schedule", fn: schedule, required: true}, // schedule values
|
|
{name: "late nilcheck", fn: nilcheckelim2},
|
|
{name: "flagalloc", fn: flagalloc, required: true}, // allocate flags register
|
|
{name: "regalloc", fn: regalloc, required: true}, // allocate int & float registers + stack slots
|
|
{name: "loop rotate", fn: loopRotate},
|
|
{name: "stackframe", fn: stackframe, required: true},
|
|
{name: "trim", fn: trim}, // remove empty blocks
|
|
}
|
|
|
|
// Double-check phase ordering constraints.
|
|
// This code is intended to document the ordering requirements
|
|
// between different phases. It does not override the passes
|
|
// list above.
|
|
type constraint struct {
|
|
a, b string // a must come before b
|
|
}
|
|
|
|
var passOrder = [...]constraint{
|
|
// "insert resched checks" uses mem, better to clean out stores first.
|
|
{"dse", "insert resched checks"},
|
|
// insert resched checks adds new blocks containing generic instructions
|
|
{"insert resched checks", "lower"},
|
|
{"insert resched checks", "tighten"},
|
|
|
|
// prove relies on common-subexpression elimination for maximum benefits.
|
|
{"generic cse", "prove"},
|
|
// deadcode after prove to eliminate all new dead blocks.
|
|
{"prove", "generic deadcode"},
|
|
// common-subexpression before dead-store elim, so that we recognize
|
|
// when two address expressions are the same.
|
|
{"generic cse", "dse"},
|
|
// cse substantially improves nilcheckelim efficacy
|
|
{"generic cse", "nilcheckelim"},
|
|
// allow deadcode to clean up after nilcheckelim
|
|
{"nilcheckelim", "generic deadcode"},
|
|
// nilcheckelim generates sequences of plain basic blocks
|
|
{"nilcheckelim", "fuse"},
|
|
// nilcheckelim relies on opt to rewrite user nil checks
|
|
{"opt", "nilcheckelim"},
|
|
// tighten will be most effective when as many values have been removed as possible
|
|
{"generic deadcode", "tighten"},
|
|
{"generic cse", "tighten"},
|
|
// checkbce needs the values removed
|
|
{"generic deadcode", "check bce"},
|
|
// don't run optimization pass until we've decomposed builtin objects
|
|
{"decompose builtin", "late opt"},
|
|
// decompose builtin is the last pass that may introduce new float ops, so run softfloat after it
|
|
{"decompose builtin", "softfloat"},
|
|
// don't layout blocks until critical edges have been removed
|
|
{"critical", "layout"},
|
|
// regalloc requires the removal of all critical edges
|
|
{"critical", "regalloc"},
|
|
// regalloc requires all the values in a block to be scheduled
|
|
{"schedule", "regalloc"},
|
|
// checkLower must run after lowering & subsequent dead code elim
|
|
{"lower", "checkLower"},
|
|
{"lowered deadcode", "checkLower"},
|
|
// late nilcheck needs instructions to be scheduled.
|
|
{"schedule", "late nilcheck"},
|
|
// flagalloc needs instructions to be scheduled.
|
|
{"schedule", "flagalloc"},
|
|
// regalloc needs flags to be allocated first.
|
|
{"flagalloc", "regalloc"},
|
|
// loopRotate will confuse regalloc.
|
|
{"regalloc", "loop rotate"},
|
|
// stackframe needs to know about spilled registers.
|
|
{"regalloc", "stackframe"},
|
|
// trim needs regalloc to be done first.
|
|
{"regalloc", "trim"},
|
|
}
|
|
|
|
func init() {
|
|
for _, c := range passOrder {
|
|
a, b := c.a, c.b
|
|
i := -1
|
|
j := -1
|
|
for k, p := range passes {
|
|
if p.name == a {
|
|
i = k
|
|
}
|
|
if p.name == b {
|
|
j = k
|
|
}
|
|
}
|
|
if i < 0 {
|
|
log.Panicf("pass %s not found", a)
|
|
}
|
|
if j < 0 {
|
|
log.Panicf("pass %s not found", b)
|
|
}
|
|
if i >= j {
|
|
log.Panicf("passes %s and %s out of order", a, b)
|
|
}
|
|
}
|
|
}
|