2015-03-23 17:02:11 -07:00
|
|
|
// 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
|
|
|
|
|
|
2015-04-15 15:51:25 -07:00
|
|
|
import "fmt"
|
2015-03-23 17:02:11 -07:00
|
|
|
|
|
|
|
|
func applyRewrite(f *Func, r func(*Value) bool) {
|
|
|
|
|
// repeat rewrites until we find no more rewrites
|
2015-04-15 15:51:25 -07:00
|
|
|
var curv *Value
|
|
|
|
|
defer func() {
|
|
|
|
|
if curv != nil {
|
|
|
|
|
fmt.Printf("panic during rewrite of %s\n", curv.LongString())
|
|
|
|
|
// TODO(khr): print source location also
|
|
|
|
|
}
|
|
|
|
|
}()
|
2015-03-23 17:02:11 -07:00
|
|
|
for {
|
|
|
|
|
change := false
|
|
|
|
|
for _, b := range f.Blocks {
|
|
|
|
|
for _, v := range b.Values {
|
2015-04-15 15:51:25 -07:00
|
|
|
curv = v
|
2015-03-23 17:02:11 -07:00
|
|
|
if r(v) {
|
|
|
|
|
change = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !change {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Common functions called from rewriting rules
|
|
|
|
|
|
|
|
|
|
func is64BitInt(t Type) bool {
|
2015-04-15 15:51:25 -07:00
|
|
|
return t.Size() == 8 && t.IsInteger()
|
2015-03-23 17:02:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func is32BitInt(t Type) bool {
|
2015-04-15 15:51:25 -07:00
|
|
|
return t.Size() == 4 && t.IsInteger()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isPtr(t Type) bool {
|
|
|
|
|
return t.IsPtr()
|
2015-03-23 17:02:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isSigned(t Type) bool {
|
2015-04-15 15:51:25 -07:00
|
|
|
return t.IsSigned()
|
2015-03-26 10:49:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func typeSize(t Type) int64 {
|
2015-04-15 15:51:25 -07:00
|
|
|
return t.Size()
|
2015-03-23 17:02:11 -07:00
|
|
|
}
|