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
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cmd/internal/ssa/types" // TODO: use golang.org/x/tools/go/types instead
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func applyRewrite(f *Func, r func(*Value) bool) {
|
|
|
|
|
// repeat rewrites until we find no more rewrites
|
|
|
|
|
for {
|
|
|
|
|
change := false
|
|
|
|
|
for _, b := range f.Blocks {
|
|
|
|
|
for _, v := range b.Values {
|
|
|
|
|
if r(v) {
|
|
|
|
|
change = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !change {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Common functions called from rewriting rules
|
|
|
|
|
|
|
|
|
|
func is64BitInt(t Type) bool {
|
2015-03-26 10:49:03 -07:00
|
|
|
if b, ok := t.Underlying().(*types.Basic); ok {
|
|
|
|
|
switch b.Kind() {
|
|
|
|
|
case types.Int64, types.Uint64:
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
2015-03-23 17:02:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func is32BitInt(t Type) bool {
|
2015-03-26 10:49:03 -07:00
|
|
|
if b, ok := t.Underlying().(*types.Basic); ok {
|
|
|
|
|
switch b.Kind() {
|
|
|
|
|
case types.Int32, types.Uint32:
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
2015-03-23 17:02:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isSigned(t Type) bool {
|
2015-03-26 10:49:03 -07:00
|
|
|
if b, ok := t.Underlying().(*types.Basic); ok {
|
|
|
|
|
switch b.Kind() {
|
|
|
|
|
case types.Int8, types.Int16, types.Int32, types.Int64:
|
|
|
|
|
return true
|
2015-03-23 17:02:11 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-03-26 10:49:03 -07:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sizer types.Sizes = &types.StdSizes{int64(ptrSize), int64(ptrSize)} // TODO(khr): from config
|
|
|
|
|
func typeSize(t Type) int64 {
|
|
|
|
|
return sizer.Sizeof(t)
|
2015-03-23 17:02:11 -07:00
|
|
|
}
|