mirror of
https://github.com/golang/go.git
synced 2025-05-30 03:41:33 +00:00
Bake the bit width and signedness into opcodes. Pro: Rewrite rules become easier. Less chance for confusion. Con: Lots more opcodes. Let me know what you think. I'm leaning towards this, but I could be convinced otherwise if people think this is too ugly. Update #11467 Change-Id: Icf1b894268cdf73515877bb123839800d97b9df9 Reviewed-on: https://go-review.googlesource.com/12362 Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
58 lines
1.4 KiB
Go
58 lines
1.4 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
|
|
|
|
import "testing"
|
|
|
|
func TestSchedule(t *testing.T) {
|
|
c := NewConfig("amd64", DummyFrontend{t})
|
|
cases := []fun{
|
|
Fun(c, "entry",
|
|
Bloc("entry",
|
|
Valu("mem0", OpArg, TypeMem, 0, ".mem"),
|
|
Valu("ptr", OpConst, TypeInt64, 0xABCD, nil),
|
|
Valu("v", OpConst, TypeInt64, 12, nil),
|
|
Valu("mem1", OpStore, TypeMem, 0, nil, "ptr", "v", "mem0"),
|
|
Valu("mem2", OpStore, TypeMem, 0, nil, "ptr", "v", "mem1"),
|
|
Valu("mem3", OpStore, TypeInt64, 0, nil, "ptr", "sum", "mem2"),
|
|
Valu("l1", OpLoad, TypeInt64, 0, nil, "ptr", "mem1"),
|
|
Valu("l2", OpLoad, TypeInt64, 0, nil, "ptr", "mem2"),
|
|
Valu("sum", OpAdd64, TypeInt64, 0, nil, "l1", "l2"),
|
|
Goto("exit")),
|
|
Bloc("exit",
|
|
Exit("mem3"))),
|
|
}
|
|
for _, c := range cases {
|
|
schedule(c.f)
|
|
if !isSingleLiveMem(c.f) {
|
|
t.Error("single-live-mem restriction not enforced by schedule for func:")
|
|
printFunc(c.f)
|
|
}
|
|
}
|
|
}
|
|
|
|
func isSingleLiveMem(f *Func) bool {
|
|
for _, b := range f.Blocks {
|
|
var liveMem *Value
|
|
for _, v := range b.Values {
|
|
for _, w := range v.Args {
|
|
if w.Type.IsMemory() {
|
|
if liveMem == nil {
|
|
liveMem = w
|
|
continue
|
|
}
|
|
if w != liveMem {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
if v.Type.IsMemory() {
|
|
liveMem = v
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|