fix another local variable caching bug

This commit is contained in:
Joel Dice 2008-05-20 15:24:10 -06:00
parent d604efd8f5
commit 36dbf1ad14
2 changed files with 41 additions and 37 deletions

View File

@ -93,8 +93,10 @@ class State {
class Local { class Local {
public: public:
Local(unsigned size, unsigned index, Value* value, Site* site, Local* next): Local(unsigned size, unsigned index, Value* value, Site* site, Local* old,
size(size), index(index), reuse(true), value(value), site(site), next(next) Local* next):
size(size), index(index), reuse(true), value(value), site(site), old(old),
next(next)
{ } { }
unsigned size; unsigned size;
@ -102,6 +104,7 @@ class Local {
bool reuse; bool reuse;
Value* value; Value* value;
Site* site; Site* site;
Local* old;
Local* next; Local* next;
}; };
@ -2095,15 +2098,17 @@ class ClobberLocalEvent: public Event {
fprintf(stderr, "ClobberLocalEvent.compile\n"); fprintf(stderr, "ClobberLocalEvent.compile\n");
} }
Value* v = local->value; for (Local* l = local; l; l = l->old) {
Site* s = local->site; Value* v = l->value;
if (v->reads Site* s = l->site;
and v->sites->next == 0 if (v->reads
and v->sites == s) and v->sites->next == 0
{ and v->sites == s)
preserve(c, stack, size, v, s, v->reads); {
preserve(c, stack, size, v, s, v->reads);
}
removeSite(c, v, s);
} }
removeSite(c, v, s);
} }
unsigned size; unsigned size;
@ -2123,11 +2128,11 @@ appendClobberLocal(Context* c, unsigned size, Local* local)
class LocalEvent: public Event { class LocalEvent: public Event {
public: public:
LocalEvent(Context* c, unsigned size, Local* oldLocal, Local* newLocal): LocalEvent(Context* c, unsigned size, Local* local):
Event(c), size(size), oldLocal(oldLocal), newLocal(newLocal) Event(c), size(size), local(local)
{ {
if (oldLocal) { if (local->old) {
addRead(c, oldLocal->value, size, 0); addRead(c, local->old->value, size, 0);
} }
} }
@ -2137,43 +2142,41 @@ class LocalEvent: public Event {
} }
Site* sites = 0; Site* sites = 0;
if (oldLocal) { if (local->old) {
Value* v = oldLocal->value; Value* v = local->old->value;
if (oldLocal->reuse and v->reads->next == 0) { if (local->old->reuse and v->reads->next == 0) {
sites = v->sites; sites = v->sites;
} }
nextRead(c, v); nextRead(c, v);
} }
Value* v = newLocal->value; Value* v = local->value;
if (v->reads) { if (v->reads) {
for (Site* s = sites; s;) { for (Site* s = sites; s;) {
Site* t = s->next; Site* t = s->next;
if (s->type(c) != MemoryOperand) { if (s->type(c) != MemoryOperand) {
addSite(c, stack, size, v, s); addSite(c, 0, size, v, s);
} }
s = t; s = t;
} }
addSite(c, 0, size, v, newLocal->site); addSite(c, 0, size, v, local->site);
} }
} }
unsigned size; unsigned size;
Local* oldLocal; Local* local;
Local* newLocal;
}; };
void void
appendLocal(Context* c, unsigned size, Local* oldLocal, Local* newLocal) appendLocal(Context* c, unsigned size, Local* local)
{ {
if (DebugAppend) { if (DebugAppend) {
fprintf(stderr, "appendLocal\n"); fprintf(stderr, "appendLocal\n");
} }
new (c->zone->allocate(sizeof(LocalEvent))) new (c->zone->allocate(sizeof(LocalEvent))) LocalEvent(c, size, local);
LocalEvent(c, size, oldLocal, newLocal);
} }
Site* Site*
@ -2335,19 +2338,14 @@ push(Context* c, unsigned size, Value* v)
void void
addLocal(Context* c, unsigned size, unsigned index, Value* newValue) addLocal(Context* c, unsigned size, unsigned index, Value* newValue)
{ {
unsigned s = ceiling(size, BytesPerWord); unsigned sizeInWords = ceiling(size, BytesPerWord);
Local* local = c->localTable[index];
if (local) {
c->localTable[index] = c->locals = new (c->zone->allocate(sizeof(Local)))
Local(s, index, newValue, local->site, c->locals);
} else {
c->localTable[index] = c->locals = new (c->zone->allocate(sizeof(Local)))
Local(s, index, newValue, memorySite
(c, c->assembler->base(), localOffset(c, index)),
c->locals);
}
appendLocal(c, s * BytesPerWord, local, c->locals); c->localTable[index] = c->locals = new (c->zone->allocate(sizeof(Local)))
Local(sizeInWords, index, newValue, memorySite
(c, c->assembler->base(), localOffset(c, index)),
c->localTable[index], c->locals);
appendLocal(c, sizeInWords * BytesPerWord, c->locals);
} }
Value* Value*

View File

@ -82,6 +82,7 @@ public class Misc {
public int a; public int a;
public int b; public int b;
public int c; public int c;
public int[] array;
} }
private static int bar(int a, int b, int c) { private static int bar(int a, int b, int c) {
@ -299,5 +300,10 @@ public class Misc {
expect(c != d); expect(c != d);
} }
{ Foo foo = new Foo();
foo.array = new int[3];
foo.a = (foo.a + 1) % foo.array.length;
}
} }
} }