use same code to spill registers and stack frame slots

This commit is contained in:
Joel Dice 2008-10-16 18:10:35 -06:00
parent 5391c68efd
commit 26614e2182

View File

@ -1375,7 +1375,6 @@ class MultiRead: public Read {
void allocateTarget(Context* c) { void allocateTarget(Context* c) {
Cell* cell = cons(c, 0, 0); Cell* cell = cons(c, 0, 0);
fprintf(stderr, "allocate target %p in %p\n", cell, this);
if (lastTarget) { if (lastTarget) {
lastTarget->next = cell; lastTarget->next = cell;
} else { } else {
@ -1385,7 +1384,6 @@ class MultiRead: public Read {
} }
Read* nextTarget() { Read* nextTarget() {
fprintf(stderr, "next target %p in %p\n", firstTarget, this);
Read* r = static_cast<Read*>(firstTarget->value); Read* r = static_cast<Read*>(firstTarget->value);
firstTarget = firstTarget->next; firstTarget = firstTarget->next;
return r; return r;
@ -1581,18 +1579,9 @@ releaseRegister(Context* c, int r)
} }
bool bool
trySteal(Context* c, Register* r, Stack* stack, Local* locals) trySteal(Context* c, Site* site, Value* v, unsigned size, Stack* stack,
Local* locals)
{ {
assert(c, r->refCount == 0);
Value* v = r->value;
assert(c, v->reads);
if (DebugRegisters) {
fprintf(stderr, "try steal %d from %p: next: %p\n",
r->number, v, v->sites->next);
}
if (v->sites->next == 0) { if (v->sites->next == 0) {
Site* saveSite = 0; Site* saveSite = 0;
for (unsigned i = 0; i < c->localFootprint; ++i) { for (unsigned i = 0; i < c->localFootprint; ++i) {
@ -1621,20 +1610,36 @@ trySteal(Context* c, Register* r, Stack* stack, Local* locals)
} }
if (saveSite) { if (saveSite) {
move(c, stack, locals, r->size, v, r->site, saveSite); move(c, stack, locals, size, v, site, saveSite);
} else { } else {
if (DebugRegisters) { if (DebugRegisters) {
fprintf(stderr, "unable to steal %d from %p\n", r->number, v); fprintf(stderr, "unable to steal %p from %p\n", site, v);
} }
return false; return false;
} }
} }
removeSite(c, v, r->site); removeSite(c, v, site);
return true; return true;
} }
bool
trySteal(Context* c, Register* r, Stack* stack, Local* locals)
{
assert(c, r->refCount == 0);
Value* v = r->value;
assert(c, v->reads);
if (DebugRegisters) {
fprintf(stderr, "try steal %d from %p: next: %p\n",
r->number, v, v->sites->next);
}
return trySteal(c, r->site, r->value, r->size, stack, locals);
}
bool bool
used(Context* c, Register* r) used(Context* c, Register* r)
{ {
@ -1823,25 +1828,18 @@ validate(Context* c, uint32_t mask, Stack* stack, Local* locals,
} }
bool bool
trySteal(Context* c, FrameResource* r, Stack*, Local*) trySteal(Context* c, FrameResource* r, Stack* stack, Local* locals)
{ {
Value* v = r->value; assert(c, r->value->reads);
assert(c, v->reads);
if (v->sites->next == 0) {
return false; // todo
}
if (DebugFrameIndexes) { if (DebugFrameIndexes) {
int index = r - c->frameResources; int index = r - c->frameResources;
fprintf(stderr, fprintf(stderr,
"steal frame index %d offset 0x%x from value %p site %p\n", "try steal frame index %d offset 0x%x from value %p site %p\n",
index, localOffset(c, index), r->value, r->site); index, localOffset(c, index), r->value, r->site);
} }
removeSite(c, v, r->site); return trySteal(c, r->site, r->value, r->size, stack, locals);
return true;
} }
void void
@ -1952,7 +1950,7 @@ apply(Context* c, TernaryOperation op,
void void
addRead(Context* c, Event* e, Value* v, Read* r) addRead(Context* c, Event* e, Value* v, Read* r)
{ {
fprintf(stderr, "add read %p to %p last %p event %p (%s)\n", r, v, v->lastRead, e, (e ? e->name() : 0)); // fprintf(stderr, "add read %p to %p last %p event %p (%s)\n", r, v, v->lastRead, e, (e ? e->name() : 0));
r->value = v; r->value = v;
if (e) { if (e) {
@ -2867,9 +2865,9 @@ skipRead(Context* c, Value* v, StubReadPair* p)
void void
visit(Context* c, Link* link) visit(Context* c, Link* link)
{ {
fprintf(stderr, "visit link from %d to %d\n", // fprintf(stderr, "visit link from %d to %d\n",
link->predecessor->logicalInstruction->index, // link->predecessor->logicalInstruction->index,
link->successor->logicalInstruction->index); // link->successor->logicalInstruction->index);
ForkState* forkState = link->forkState; ForkState* forkState = link->forkState;
if (forkState) { if (forkState) {
@ -2877,7 +2875,7 @@ visit(Context* c, Link* link)
MultiReadPair* p = forkState->reads + i; MultiReadPair* p = forkState->reads + i;
Value* v = p->value; Value* v = p->value;
v->reads = p->read->nextTarget(); v->reads = p->read->nextTarget();
fprintf(stderr, "next read %p for %p\n", v->reads, v); // fprintf(stderr, "next read %p for %p\n", v->reads, v);
if (not live(v)) { if (not live(v)) {
clearSites(c, v); clearSites(c, v);
} }
@ -3413,7 +3411,6 @@ compile(Context* c)
Event* first = e->predecessors->predecessor; Event* first = e->predecessors->predecessor;
if (e->predecessors->nextPredecessor) { if (e->predecessors->nextPredecessor) {
fprintf(stderr, "ima junction\n");
for (Link* pl = e->predecessors; for (Link* pl = e->predecessors;
pl->nextPredecessor; pl->nextPredecessor;
pl = pl->nextPredecessor) pl = pl->nextPredecessor)
@ -3422,8 +3419,6 @@ compile(Context* c)
} }
setSites(c, e, first->junctionSites); setSites(c, e, first->junctionSites);
} else if (first->successors->nextSuccessor) { } else if (first->successors->nextSuccessor) {
fprintf(stderr, "ima fork from %d\n",
first->logicalInstruction->index);
setSites(c, e, first->savedSites); setSites(c, e, first->savedSites);
} }
} }