Commit ca5da31f authored by Russ Cox's avatar Russ Cox

6g: fix out of registers bug

Fix it twice: reuse registers more aggressively in cgen abop,
and also release R14 and R15, which are no longer m and g.

Fixes #2669.

R=ken2
CC=golang-dev
https://golang.org/cl/5655056
parent 76a1cb5a
...@@ -387,9 +387,9 @@ abop: // asymmetric binary ...@@ -387,9 +387,9 @@ abop: // asymmetric binary
regalloc(&n2, nr->type, N); regalloc(&n2, nr->type, N);
cgen(nr, &n2); cgen(nr, &n2);
} else { } else {
regalloc(&n2, nr->type, N); regalloc(&n2, nr->type, res);
cgen(nr, &n2); cgen(nr, &n2);
regalloc(&n1, nl->type, res); regalloc(&n1, nl->type, N);
cgen(nl, &n1); cgen(nl, &n1);
} }
gins(a, &n2, &n1); gins(a, &n2, &n1);
......
...@@ -287,8 +287,6 @@ static int resvd[] = ...@@ -287,8 +287,6 @@ static int resvd[] =
D_CX, // for shift D_CX, // for shift
D_DX, // for divide D_DX, // for divide
D_SP, // for stack D_SP, // for stack
D_R14, // reserved for m
D_R15, // reserved for u
}; };
void void
...@@ -340,6 +338,8 @@ anyregalloc(void) ...@@ -340,6 +338,8 @@ anyregalloc(void)
return 0; return 0;
} }
static uintptr regpc[D_R15+1 - D_AX];
/* /*
* allocate register of type t, leave in n. * allocate register of type t, leave in n.
* if o != N, o is desired fixed register. * if o != N, o is desired fixed register.
...@@ -372,11 +372,15 @@ regalloc(Node *n, Type *t, Node *o) ...@@ -372,11 +372,15 @@ regalloc(Node *n, Type *t, Node *o)
goto out; goto out;
} }
for(i=D_AX; i<=D_R15; i++) for(i=D_AX; i<=D_R15; i++)
if(reg[i] == 0) if(reg[i] == 0) {
regpc[i-D_AX] = (uintptr)getcallerpc(&n);
goto out; goto out;
}
yyerror("out of fixed registers"); flusherrors();
goto err; for(i=0; i+D_AX<=D_R15; i++)
print("%d %p\n", i, regpc[i]);
fatal("out of fixed registers");
case TFLOAT32: case TFLOAT32:
case TFLOAT64: case TFLOAT64:
...@@ -388,18 +392,14 @@ regalloc(Node *n, Type *t, Node *o) ...@@ -388,18 +392,14 @@ regalloc(Node *n, Type *t, Node *o)
for(i=D_X0; i<=D_X7; i++) for(i=D_X0; i<=D_X7; i++)
if(reg[i] == 0) if(reg[i] == 0)
goto out; goto out;
yyerror("out of floating registers"); fatal("out of floating registers");
goto err;
case TCOMPLEX64: case TCOMPLEX64:
case TCOMPLEX128: case TCOMPLEX128:
tempname(n, t); tempname(n, t);
return; return;
} }
yyerror("regalloc: unknown type %T", t); fatal("regalloc: unknown type %T", t);
err:
nodreg(n, t, 0);
return; return;
out: out:
...@@ -424,6 +424,8 @@ regfree(Node *n) ...@@ -424,6 +424,8 @@ regfree(Node *n)
if(reg[i] <= 0) if(reg[i] <= 0)
fatal("regfree: reg not allocated"); fatal("regfree: reg not allocated");
reg[i]--; reg[i]--;
if(reg[i] == 0 && D_AX <= i && i <= D_R15)
regpc[i - D_AX] = 0;
} }
/* /*
......
// $G $D/$F.go
// Copyright 2012 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.
// Used to run 6g out of registers. Issue 2669.
package p
type y struct {
num int
}
func zzz () {
k := make([]byte, 10)
arr := make ([]*y, 0)
for s := range arr {
x := make([]byte, 10)
for i := 0; i < 100 ; i++ {
x[i] ^= k[i-arr[s].num%0]
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment