pass: first attempt at register allocation

This commit is contained in:
Michael McLoughlin
2018-12-05 00:05:57 -08:00
parent 9376a230cf
commit 022cbb7792
9 changed files with 394 additions and 24 deletions

View File

@@ -2,11 +2,40 @@ package reg
import "testing"
func TestFamilyRegisterSets(t *testing.T) {
fs := []*Family{GeneralPurpose, SIMD}
for _, f := range fs {
if len(f.Set()) != len(f.Registers()) {
t.Fatal("family set and list should have same size")
}
func TestSetRegisterIdentity(t *testing.T) {
rs := []Register{
NewVirtual(42, GP, B32),
NewVirtual(43, GP, B32),
NewVirtual(42, SSEAVX, B32),
NewVirtual(42, GP, B64),
AL, AH, CL,
AX, R13W,
EDX, R9L,
RCX, R14,
X1, X7,
Y4, Y9,
Z13, Z31,
}
s := NewEmptySet()
for _, r := range rs {
s.Add(r)
s.Add(r)
}
if len(s) != len(rs) {
t.Fatalf("expected set to have same size as slice: got %d expect %d", len(s), len(rs))
}
}
func TestSetFamilyRegisters(t *testing.T) {
fs := []*Family{GeneralPurpose, SIMD}
s := NewEmptySet()
expect := 0
for _, f := range fs {
s.Update(f.Set())
s.Add(f.Virtual(42, B64))
expect += len(f.Registers()) + 1
}
if len(s) != expect {
t.Fatalf("set size mismatch: %d expected %d", len(s), expect)
}
}