go/src/cmd/internal/ssa/lower.go
Keith Randall 149671dfc3 [dev.ssa] cmd/internal/ssa: add CSE pass
Implement a simple common-subexpression elimination.
It uses value numbering & a dominator tree to detect redundant computation.

Change-Id: Id0ff775e439c22f4d41bdd5976176017dd2a2086
Reviewed-on: https://go-review.googlesource.com/8172
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-03-31 21:51:15 +00:00

42 lines
1.1 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
var (
// TODO(khr): put arch configuration constants together somewhere
intSize = 8
ptrSize = 8
)
//go:generate go run rulegen/rulegen.go rulegen/lower_amd64.rules lowerAmd64 lowerAmd64.go
// convert to machine-dependent ops
func lower(f *Func) {
// repeat rewrites until we find no more rewrites
// TODO: pick the target arch from config
applyRewrite(f, lowerAmd64)
// TODO: check for unlowered opcodes, fail if we find one
// additional pass for 386/amd64, link condition codes directly to blocks
// TODO: do generically somehow? Special "block" rewrite rules?
for _, b := range f.Blocks {
switch b.Kind {
case BlockIf:
switch b.Control.Op {
case OpSETL:
b.Kind = BlockLT
b.Control = b.Control.Args[0]
// TODO: others
}
case BlockLT:
if b.Control.Op == OpInvertFlags {
b.Kind = BlockGE
b.Control = b.Control.Args[0]
}
// TODO: others
}
}
}