mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.ssa] cmd/internal/ssa: SSA backend compiler skeleton
First pass adding code for SSA backend. It is standalone for now. I've included just a few passes to make the review size manageable - I have more passes coming. cmd/internal/ssa is the library containing the ssa compiler proper. cmd/internal/ssa/ssac is a driver that loads an sexpr-based IR, converts it to SSA form, and calls the above library. It is essentially throwaway code - it will disappear once the Go compiler calls cmd/internal/ssa itself. The .goir files in ssac/ are dumps of fibonacci programs I made from a hacked-up compiler. They are just for testing. Change-Id: I5ee89356ec12c87cd916681097cd3c2cd591040c Reviewed-on: https://go-review.googlesource.com/6681 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
de7f6c77bc
commit
f52b234579
26 changed files with 2438 additions and 0 deletions
65
src/cmd/internal/ssa/compile.go
Normal file
65
src/cmd/internal/ssa/compile.go
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
// 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 "fmt"
|
||||
|
||||
// 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.
|
||||
fmt.Printf("compiling %s\n", f.Name)
|
||||
|
||||
// hook to print function & phase if panic happens
|
||||
phaseName := "init"
|
||||
defer func() {
|
||||
if phaseName != "" {
|
||||
fmt.Printf("panic during %s while compiling %s\n", phaseName, f.Name)
|
||||
}
|
||||
}()
|
||||
|
||||
// Run all the passes
|
||||
printFunc(f)
|
||||
checkFunc(f)
|
||||
for _, p := range passes {
|
||||
phaseName = p.name
|
||||
fmt.Printf(" pass %s begin\n", p.name)
|
||||
p.fn(f)
|
||||
fmt.Printf(" pass %s end\n", p.name)
|
||||
printFunc(f)
|
||||
checkFunc(f)
|
||||
}
|
||||
|
||||
// Squash error printing defer
|
||||
phaseName = ""
|
||||
}
|
||||
|
||||
type pass struct {
|
||||
name string
|
||||
fn func(*Func)
|
||||
}
|
||||
|
||||
// list of passes for the compiler
|
||||
var passes = [...]pass{
|
||||
{"phielim", phielim},
|
||||
{"copyelim", copyelim},
|
||||
//{"opt", opt},
|
||||
// cse
|
||||
{"deadcode", deadcode},
|
||||
//{"fuse", fuse},
|
||||
//{"lower", lower},
|
||||
// cse
|
||||
//{"critical", critical}, // remove critical edges
|
||||
//{"layout", layout}, // schedule blocks
|
||||
//{"schedule", schedule}, // schedule values
|
||||
// regalloc
|
||||
// stack slot alloc (+size stack frame)
|
||||
//{"cgen", cgen},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue