2015-03-03 13:38:14 -08: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-08-24 02:16:19 -07:00
|
|
|
import (
|
2015-10-23 12:34:03 -04:00
|
|
|
"cmd/internal/obj"
|
2015-08-24 02:16:19 -07:00
|
|
|
"testing"
|
|
|
|
|
)
|
2015-06-12 11:01:13 -07:00
|
|
|
|
2015-03-03 13:38:14 -08:00
|
|
|
var CheckFunc = checkFunc
|
|
|
|
|
var PrintFunc = printFunc
|
2015-05-28 16:45:33 -07:00
|
|
|
var Opt = opt
|
2015-03-03 13:38:14 -08:00
|
|
|
var Deadcode = deadcode
|
2015-06-04 15:18:27 -07:00
|
|
|
|
2015-07-30 11:03:05 -07:00
|
|
|
func testConfig(t *testing.T) *Config {
|
2015-10-23 12:34:03 -04:00
|
|
|
testCtxt := &obj.Link{}
|
2016-01-27 16:47:23 -08:00
|
|
|
return NewConfig("amd64", DummyFrontend{t}, testCtxt, true)
|
2015-07-30 11:03:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DummyFrontend is a test-only frontend.
|
|
|
|
|
// It assumes 64 bit integers and pointers.
|
2015-06-12 11:01:13 -07:00
|
|
|
type DummyFrontend struct {
|
2015-06-25 14:04:55 -07:00
|
|
|
t testing.TB
|
2015-06-12 11:01:13 -07:00
|
|
|
}
|
2015-06-04 15:18:27 -07:00
|
|
|
|
2015-07-24 11:28:12 -07:00
|
|
|
func (DummyFrontend) StringData(s string) interface{} {
|
2015-06-04 15:18:27 -07:00
|
|
|
return nil
|
|
|
|
|
}
|
2015-10-22 14:22:38 -07:00
|
|
|
func (DummyFrontend) Auto(t Type) GCNode {
|
2015-08-24 02:16:19 -07:00
|
|
|
return nil
|
|
|
|
|
}
|
cmd/compile: better job of naming compound types
Compound AUTO types weren't named previously. That was because live
variable analysis (plive.go) doesn't handle spilling to compound types.
It can't handle them because there is no valid place to put VARDEFs when
regalloc is spilling compound types.
compound types = multiword builtin types: complex, string, slice, and
interface.
Instead, we split named AUTOs into individual one-word variables. For
example, a string s gets split into a byte ptr s.ptr and an integer
s.len. Those two variables can be spilled to / restored from
independently. As a result, live variable analysis can handle them
because they are one-word objects.
This CL will change how AUTOs are described in DWARF information.
Consider the code:
func f(s string, i int) int {
x := s[i:i+5]
g()
return lookup(x)
}
The old compiler would spill x to two consecutive slots on the stack,
both named x (at offsets 0 and 8). The new compiler spills the pointer
of x to a slot named x.ptr. It doesn't spill x.len at all, as it is a
constant (5) and can be rematerialized for the call to lookup.
So compound objects may not be spilled in their entirety, and even if
they are they won't necessarily be contiguous. Such is the price of
optimization.
Re-enable live variable analysis tests. One test remains disabled, it
fails because of #14904.
Change-Id: I8ef2b5ab91e43a0d2136bfc231c05d100ec0b801
Reviewed-on: https://go-review.googlesource.com/21233
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2016-03-28 11:25:17 -07:00
|
|
|
func (d DummyFrontend) SplitString(s LocalSlot) (LocalSlot, LocalSlot) {
|
|
|
|
|
return LocalSlot{s.N, d.TypeBytePtr(), s.Off}, LocalSlot{s.N, d.TypeInt(), s.Off + 8}
|
|
|
|
|
}
|
|
|
|
|
func (d DummyFrontend) SplitInterface(s LocalSlot) (LocalSlot, LocalSlot) {
|
|
|
|
|
return LocalSlot{s.N, d.TypeBytePtr(), s.Off}, LocalSlot{s.N, d.TypeBytePtr(), s.Off + 8}
|
|
|
|
|
}
|
|
|
|
|
func (d DummyFrontend) SplitSlice(s LocalSlot) (LocalSlot, LocalSlot, LocalSlot) {
|
|
|
|
|
return LocalSlot{s.N, s.Type.ElemType().PtrTo(), s.Off},
|
|
|
|
|
LocalSlot{s.N, d.TypeInt(), s.Off + 8},
|
|
|
|
|
LocalSlot{s.N, d.TypeInt(), s.Off + 16}
|
|
|
|
|
}
|
|
|
|
|
func (d DummyFrontend) SplitComplex(s LocalSlot) (LocalSlot, LocalSlot) {
|
|
|
|
|
if s.Type.Size() == 16 {
|
|
|
|
|
return LocalSlot{s.N, d.TypeFloat64(), s.Off}, LocalSlot{s.N, d.TypeFloat64(), s.Off + 8}
|
|
|
|
|
}
|
|
|
|
|
return LocalSlot{s.N, d.TypeFloat32(), s.Off}, LocalSlot{s.N, d.TypeFloat32(), s.Off + 4}
|
|
|
|
|
}
|
2016-03-31 21:24:10 -07:00
|
|
|
func (d DummyFrontend) SplitStruct(s LocalSlot, i int) LocalSlot {
|
|
|
|
|
return LocalSlot{s.N, s.Type.FieldType(i), s.Off + s.Type.FieldOff(i)}
|
|
|
|
|
}
|
2016-01-14 16:02:23 -08:00
|
|
|
func (DummyFrontend) Line(line int32) string {
|
|
|
|
|
return "unknown.go:0"
|
|
|
|
|
}
|
2015-06-12 11:01:13 -07:00
|
|
|
|
2016-01-13 11:14:57 -08:00
|
|
|
func (d DummyFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, args...) }
|
2016-01-29 14:44:15 -05:00
|
|
|
func (d DummyFrontend) Log() bool { return true }
|
2016-01-13 11:14:57 -08:00
|
|
|
|
|
|
|
|
func (d DummyFrontend) Fatalf(line int32, msg string, args ...interface{}) { d.t.Fatalf(msg, args...) }
|
|
|
|
|
func (d DummyFrontend) Unimplementedf(line int32, msg string, args ...interface{}) {
|
|
|
|
|
d.t.Fatalf(msg, args...)
|
|
|
|
|
}
|
2016-03-13 23:04:31 -05:00
|
|
|
func (d DummyFrontend) Warnl(line int32, msg string, args ...interface{}) { d.t.Logf(msg, args...) }
|
|
|
|
|
func (d DummyFrontend) Debug_checknil() bool { return false }
|
2015-07-30 11:03:05 -07:00
|
|
|
|
|
|
|
|
func (d DummyFrontend) TypeBool() Type { return TypeBool }
|
|
|
|
|
func (d DummyFrontend) TypeInt8() Type { return TypeInt8 }
|
|
|
|
|
func (d DummyFrontend) TypeInt16() Type { return TypeInt16 }
|
|
|
|
|
func (d DummyFrontend) TypeInt32() Type { return TypeInt32 }
|
|
|
|
|
func (d DummyFrontend) TypeInt64() Type { return TypeInt64 }
|
|
|
|
|
func (d DummyFrontend) TypeUInt8() Type { return TypeUInt8 }
|
|
|
|
|
func (d DummyFrontend) TypeUInt16() Type { return TypeUInt16 }
|
|
|
|
|
func (d DummyFrontend) TypeUInt32() Type { return TypeUInt32 }
|
|
|
|
|
func (d DummyFrontend) TypeUInt64() Type { return TypeUInt64 }
|
2015-08-28 14:24:10 -04:00
|
|
|
func (d DummyFrontend) TypeFloat32() Type { return TypeFloat32 }
|
|
|
|
|
func (d DummyFrontend) TypeFloat64() Type { return TypeFloat64 }
|
2015-07-30 11:03:05 -07:00
|
|
|
func (d DummyFrontend) TypeInt() Type { return TypeInt64 }
|
|
|
|
|
func (d DummyFrontend) TypeUintptr() Type { return TypeUInt64 }
|
|
|
|
|
func (d DummyFrontend) TypeString() Type { panic("unimplemented") }
|
|
|
|
|
func (d DummyFrontend) TypeBytePtr() Type { return TypeBytePtr }
|
2015-09-18 22:58:10 -07:00
|
|
|
|
|
|
|
|
func (d DummyFrontend) CanSSA(t Type) bool {
|
|
|
|
|
// There are no un-SSAable types in dummy land.
|
|
|
|
|
return true
|
|
|
|
|
}
|