hello, world on amd64

This commit is contained in:
Joel Dice 2008-10-04 11:26:35 -06:00
parent d409f89d5d
commit 83aa342bc8
3 changed files with 241 additions and 108 deletions

View File

@ -3877,11 +3877,11 @@ finish(MyThread* t, Context* context)
strcmp strcmp
(reinterpret_cast<const char*> (reinterpret_cast<const char*>
(&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)), (&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)),
"Hello") == 0 and "java/lang/System") == 0 and
strcmp strcmp
(reinterpret_cast<const char*> (reinterpret_cast<const char*>
(&byteArrayBody(t, methodName(t, context->method), 0)), (&byteArrayBody(t, methodName(t, context->method), 0)),
"main") == 0) "<clinit>") == 0)
{ {
asm("int3"); asm("int3");
} }

View File

@ -15,10 +15,11 @@ using namespace vm;
namespace { namespace {
const bool DebugAppend = true; const bool DebugAppend = false;
const bool DebugCompile = true; const bool DebugCompile = false;
const bool DebugStack = false; const bool DebugStack = false;
const bool DebugRegisters = true; const bool DebugRegisters = false;
const bool DebugFrameIndexes = false;
const int AnyFrameIndex = -2; const int AnyFrameIndex = -2;
const int NoFrameIndex = -1; const int NoFrameIndex = -1;
@ -82,6 +83,8 @@ class Site {
virtual Site* readTarget(Context*, Read*) { return this; } virtual Site* readTarget(Context*, Read*) { return this; }
virtual void toString(Context*, char*, unsigned) = 0;
virtual unsigned copyCost(Context*, Site*) = 0; virtual unsigned copyCost(Context*, Site*) = 0;
virtual bool match(Context*, uint8_t, uint64_t, int) = 0; virtual bool match(Context*, uint8_t, uint64_t, int) = 0;
@ -98,6 +101,8 @@ class Site {
virtual Assembler::Operand* asAssemblerOperand(Context*) = 0; virtual Assembler::Operand* asAssemblerOperand(Context*) = 0;
virtual void makeSpecific(Context*) { }
Site* next; Site* next;
}; };
@ -464,10 +469,11 @@ class StubReadPair {
class Event { class Event {
public: public:
Event(Context* c): Event(Context* c):
next(0), stack(c->stack), locals(c->locals), promises(0), next(0), stackBefore(c->stack), localsBefore(c->locals),
reads(0), junctionSites(0), savedSites(0), predecessors(0), stackAfter(c->stack), localsAfter(c->locals), promises(0), reads(0),
successors(0), block(0), logicalInstruction(c->logicalCode[c->logicalIp]), junctionSites(0), savedSites(0), predecessors(0), successors(0), block(0),
state(c->state), junctionReads(0), readCount(0) logicalInstruction(c->logicalCode[c->logicalIp]), state(c->state),
junctionReads(0), readCount(0)
{ {
assert(c, c->logicalIp >= 0); assert(c, c->logicalIp >= 0);
@ -480,6 +486,9 @@ class Event {
Event* p = c->predecessor; Event* p = c->predecessor;
if (p) { if (p) {
p->stackAfter = stackBefore;
p->localsAfter = localsBefore;
predecessors = cons(c, p, 0); predecessors = cons(c, p, 0);
p->successors = cons(c, this, p->successors); p->successors = cons(c, this, p->successors);
} }
@ -502,8 +511,10 @@ class Event {
virtual void compilePostsync(Context*) { } virtual void compilePostsync(Context*) { }
Event* next; Event* next;
Stack* stack; Stack* stackBefore;
Local* locals; Local* localsBefore;
Stack* stackAfter;
Local* localsAfter;
CodePromise* promises; CodePromise* promises;
Read* reads; Read* reads;
Site** junctionSites; Site** junctionSites;
@ -655,6 +666,14 @@ class ConstantSite: public Site {
public: public:
ConstantSite(Promise* value): value(value) { } ConstantSite(Promise* value): value(value) { }
virtual void toString(Context*, char* buffer, unsigned bufferSize) {
if (value.value->resolved()) {
snprintf(buffer, bufferSize, "constant %ld", value.value->value());
} else {
snprintf(buffer, bufferSize, "constant unresolved");
}
}
virtual unsigned copyCost(Context*, Site* s) { virtual unsigned copyCost(Context*, Site* s) {
return (s == this ? 0 : 1); return (s == this ? 0 : 1);
} }
@ -697,6 +716,14 @@ class AddressSite: public Site {
public: public:
AddressSite(Promise* address): address(address) { } AddressSite(Promise* address): address(address) { }
virtual void toString(Context*, char* buffer, unsigned bufferSize) {
if (address.address->resolved()) {
snprintf(buffer, bufferSize, "address %ld", address.address->value());
} else {
snprintf(buffer, bufferSize, "address unresolved");
}
}
virtual unsigned copyCost(Context*, Site* s) { virtual unsigned copyCost(Context*, Site* s) {
return (s == this ? 0 : 3); return (s == this ? 0 : 3);
} }
@ -772,6 +799,17 @@ class RegisterSite: public Site {
register_.high = (high? high->number : NoRegister); register_.high = (high? high->number : NoRegister);
} }
virtual void toString(Context* c, char* buffer, unsigned bufferSize) {
if (low) {
sync(c);
snprintf(buffer, bufferSize, "register %d %d",
register_.low, register_.high);
} else {
snprintf(buffer, bufferSize, "register unacquired");
}
}
virtual unsigned copyCost(Context* c, Site* s) { virtual unsigned copyCost(Context* c, Site* s) {
sync(c); sync(c);
@ -850,6 +888,15 @@ class RegisterSite: public Site {
return &register_; return &register_;
} }
virtual void makeSpecific(Context* c UNUSED) {
assert(c, low);
mask = static_cast<uint64_t>(1) << low->number;
if (high) {
mask |= static_cast<uint64_t>(1) << (high->number + 32);
}
}
uint64_t mask; uint64_t mask;
Register* low; Register* low;
Register* high; Register* high;
@ -928,6 +975,17 @@ class MemorySite: public Site {
value.index = (index? index->number : NoRegister); value.index = (index? index->number : NoRegister);
} }
virtual void toString(Context* c, char* buffer, unsigned bufferSize) {
if (base) {
sync(c);
snprintf(buffer, bufferSize, "memory %d %d %d %d",
value.base, value.offset, value.index, value.scale);
} else {
snprintf(buffer, bufferSize, "memory unacquired");
}
}
virtual unsigned copyCost(Context* c, Site* s) { virtual unsigned copyCost(Context* c, Site* s) {
sync(c); sync(c);
@ -1071,7 +1129,6 @@ allocateSite(Context* c, uint8_t typeMask, uint64_t registerMask,
} else if (frameIndex >= 0) { } else if (frameIndex >= 0) {
return frameSite(c, frameIndex); return frameSite(c, frameIndex);
} else { } else {
fprintf(stderr, "type mask %02x reg mask %016lx frame index %d\n", typeMask, registerMask, frameIndex);
return 0; return 0;
} }
} }
@ -1521,7 +1578,7 @@ acquire(Context* c, uint32_t mask, Stack* stack, Local* locals,
if (r->reserved) return r; if (r->reserved) return r;
if (DebugRegisters) { if (DebugRegisters) {
fprintf(stderr, "acquire %d, value %p, site %p freeze count %d " fprintf(stderr, "acquire %d value %p site %p freeze count %d "
"ref count %d used %d used exclusively %d\n", "ref count %d used %d used exclusively %d\n",
r->number, newValue, newSite, r->freezeCount, r->refCount, r->number, newValue, newSite, r->freezeCount, r->refCount,
used(c, r), usedExclusively(c, r)); used(c, r), usedExclusively(c, r));
@ -1570,12 +1627,20 @@ validate(Context* c, uint32_t mask, Stack* stack, Local* locals,
} }
if (current->value == 0) { if (current->value == 0) {
if (DebugRegisters) {
fprintf(stderr,
"validate acquire %d value %p site %p freeze count %d "
"ref count %d\n",
current->number, value, site, current->freezeCount,
current->refCount);
}
current->size = size; current->size = size;
current->value = value; current->value = value;
current->site = site; current->site = site;
return current; return current;
} else { } else {
abort(c); removeSite(c, current->value, current->site);
} }
} }
@ -1600,8 +1665,15 @@ trySteal(Context* c, FrameResource* r, Stack*, Local*)
Value* v = r->value; Value* v = r->value;
assert(c, v->reads); assert(c, v->reads);
if (v->sites->next == 0) { // if (v->sites->next == 0) {
return false; // todo // return false; // todo
// }
if (DebugFrameIndexes) {
int index = r - c->frameResources;
fprintf(stderr,
"steal frame index %d offset 0x%x from value %p site %p\n",
index, localOffset(c, index), r->value, r->site);
} }
removeSite(c, v, r->site); removeSite(c, v, r->site);
@ -1618,6 +1690,12 @@ acquireFrameIndex(Context* c, int index, Stack* stack, Local* locals,
assert(c, index < static_cast<int> assert(c, index < static_cast<int>
(c->alignedFrameSize + c->parameterFootprint)); (c->alignedFrameSize + c->parameterFootprint));
if (DebugFrameIndexes) {
fprintf(stderr,
"acquire frame index %d offset 0x%x value %p site %p\n",
index, localOffset(c, index), newValue, newSite);
}
FrameResource* r = c->frameResources + index; FrameResource* r = c->frameResources + index;
if (recurse and newSize > BytesPerWord) { if (recurse and newSize > BytesPerWord) {
@ -1637,7 +1715,7 @@ acquireFrameIndex(Context* c, int index, Stack* stack, Local* locals,
r->size = newSize; r->size = newSize;
r->value = newValue; r->value = newValue;
r->site = 0; r->site = newSite;
} }
void void
@ -1647,6 +1725,11 @@ releaseFrameIndex(Context* c, int index, bool recurse)
assert(c, index < static_cast<int> assert(c, index < static_cast<int>
(c->alignedFrameSize + c->parameterFootprint)); (c->alignedFrameSize + c->parameterFootprint));
if (DebugFrameIndexes) {
fprintf(stderr, "release frame index %d offset 0x%x\n",
index, localOffset(c, index));
}
FrameResource* r = c->frameResources + index; FrameResource* r = c->frameResources + index;
if (recurse and r->size > BytesPerWord) { if (recurse and r->size > BytesPerWord) {
@ -1805,7 +1888,7 @@ class CallEvent: public Event {
AnyFrameIndex)); AnyFrameIndex));
int footprint = stackArgumentFootprint; int footprint = stackArgumentFootprint;
for (Stack* s = stack; s; s = s->next) { for (Stack* s = stackBefore; s; s = s->next) {
frameIndex -= s->size; frameIndex -= s->size;
if (footprint > 0) { if (footprint > 0) {
addRead(c, this, s->value, read addRead(c, this, s->value, read
@ -1824,7 +1907,7 @@ class CallEvent: public Event {
} }
for (unsigned i = 0; i < c->localFootprint; ++i) { for (unsigned i = 0; i < c->localFootprint; ++i) {
Local* local = locals + i; Local* local = localsBefore + i;
if (local->value) { if (local->value) {
addRead(c, this, local->value, read addRead(c, this, local->value, read
(c, local->size, 1 << MemoryOperand, 0, i)); (c, local->size, 1 << MemoryOperand, 0, i));
@ -1844,7 +1927,7 @@ class CallEvent: public Event {
traceHandler->handleTrace(codePromise(c, c->assembler->offset())); traceHandler->handleTrace(codePromise(c, c->assembler->offset()));
} }
clean(c, this, stack, locals, reads); clean(c, this, stackBefore, localsBefore, reads);
if (resultSize and live(result)) { if (resultSize and live(result)) {
addSite(c, 0, 0, resultSize, result, registerSite addSite(c, 0, 0, resultSize, result, registerSite
@ -1939,7 +2022,7 @@ class MoveEvent: public Event {
} }
if (not isStore) { if (not isStore) {
addSite(c, stack, locals, dstSize, dst, target); addSite(c, stackBefore, localsBefore, dstSize, dst, target);
} }
if (cost or type != Move) { if (cost or type != Move) {
@ -1948,20 +2031,27 @@ class MoveEvent: public Event {
int frameIndex = AnyFrameIndex; int frameIndex = AnyFrameIndex;
dstRead->intersect(&typeMask, &registerMask, &frameIndex); dstRead->intersect(&typeMask, &registerMask, &frameIndex);
if (target->match(c, typeMask, registerMask, frameIndex)) { bool memoryToMemory = (target->type(c) == MemoryOperand
and src->source->type(c) == MemoryOperand);
if (target->match(c, typeMask, registerMask, frameIndex)
and not memoryToMemory)
{
apply(c, type, srcSize, src->source, dstSize, target); apply(c, type, srcSize, src->source, dstSize, target);
} else { } else {
assert(c, typeMask & (1 << RegisterOperand)); assert(c, typeMask & (1 << RegisterOperand));
Site* tmpTarget = freeRegisterSite(c, registerMask); Site* tmpTarget = freeRegisterSite(c, registerMask);
addSite(c, stack, locals, dstSize, dst, tmpTarget); addSite(c, stackBefore, localsBefore, dstSize, dst, tmpTarget);
apply(c, type, srcSize, src->source, dstSize, tmpTarget); apply(c, type, srcSize, src->source, dstSize, tmpTarget);
if (isStore) { if (isStore) {
removeSite(c, dst, tmpTarget); removeSite(c, dst, tmpTarget);
}
if (memoryToMemory or isStore) {
apply(c, Move, dstSize, tmpTarget, dstSize, target); apply(c, Move, dstSize, tmpTarget, dstSize, target);
} else { } else {
removeSite(c, dst, target); removeSite(c, dst, target);
@ -2083,6 +2173,23 @@ appendCompare(Context* c, unsigned size, Value* first, Value* second)
read(c, size, secondTypeMask, secondRegisterMask, AnyFrameIndex)); read(c, size, secondTypeMask, secondRegisterMask, AnyFrameIndex));
} }
void
move(Context* c, Stack* stack, Local* locals, unsigned size, Value* value,
Site* src, Site* dst)
{
if (dst->type(c) == MemoryOperand
and src->type(c) == MemoryOperand)
{
Site* tmp = freeRegisterSite(c);
addSite(c, stack, locals, size, value, tmp);
apply(c, Move, size, src, size, tmp);
src = tmp;
}
addSite(c, stack, locals, size, value, dst);
apply(c, Move, size, src, size, dst);
}
void void
preserve(Context* c, Stack* stack, Local* locals, unsigned size, Value* v, preserve(Context* c, Stack* stack, Local* locals, unsigned size, Value* v,
Site* s, Read* read) Site* s, Read* read)
@ -2090,8 +2197,7 @@ preserve(Context* c, Stack* stack, Local* locals, unsigned size, Value* v,
assert(c, v->sites == s); assert(c, v->sites == s);
Site* r = targetOrNull(c, v, read); Site* r = targetOrNull(c, v, read);
if (r == 0 or r == s) r = freeRegisterSite(c); if (r == 0 or r == s) r = freeRegisterSite(c);
addSite(c, stack, locals, size, v, r); move(c, stack, locals, size, v, s, r);
apply(c, Move, size, s, size, r);
} }
void void
@ -2127,14 +2233,15 @@ class CombineEvent: public Event {
virtual void compile(Context* c) { virtual void compile(Context* c) {
Site* target; Site* target;
if (c->arch->condensedAddressing()) { if (c->arch->condensedAddressing()) {
maybePreserve(c, stack, locals, secondSize, second, second->source); maybePreserve(c, stackBefore, localsBefore, secondSize, second,
second->source);
target = second->source; target = second->source;
} else { } else {
target = resultRead->allocateSite(c); target = resultRead->allocateSite(c);
addSite(c, stack, locals, resultSize, result, target); addSite(c, stackBefore, localsBefore, resultSize, result, target);
} }
fprintf(stderr, "combine %p and %p into %p\n", first, second, result); // fprintf(stderr, "combine %p and %p into %p\n", first, second, result);
apply(c, type, firstSize, first->source, secondSize, second->source, apply(c, type, firstSize, first->source, secondSize, second->source,
resultSize, target); resultSize, target);
@ -2265,7 +2372,7 @@ class TranslateEvent: public Event {
} }
virtual void compile(Context* c) { virtual void compile(Context* c) {
maybePreserve(c, stack, locals, size, value, value->source); maybePreserve(c, stackBefore, localsBefore, size, value, value->source);
Site* target = targetOrRegister(c, result); Site* target = targetOrRegister(c, result);
apply(c, type, size, value->source, size, target); apply(c, type, size, value->source, size, target);
@ -2550,7 +2657,7 @@ class FrameSiteEvent: public Event {
} }
virtual void compile(Context* c) { virtual void compile(Context* c) {
addSite(c, stack, locals, size, value, frameSite(c, index)); addSite(c, stackBefore, localsBefore, size, value, frameSite(c, index));
} }
Value* value; Value* value;
@ -2570,8 +2677,8 @@ class DummyEvent: public Event {
DummyEvent(Context* c): DummyEvent(Context* c):
Event(c) Event(c)
{ {
stack = logicalInstruction->stack; stackBefore = stackAfter = logicalInstruction->stack;
locals = logicalInstruction->locals; localsBefore = localsAfter = logicalInstruction->locals;
} }
virtual const char* name() { virtual const char* name() {
@ -2603,9 +2710,7 @@ readSource(Context* c, Stack* stack, Local* locals, Read* r)
unsigned copyCost; unsigned copyCost;
site = pick(c, r->value->sites, target, &copyCost); site = pick(c, r->value->sites, target, &copyCost);
assert(c, copyCost); assert(c, copyCost);
move(c, stack, locals, r->size, r->value, site, target);
addSite(c, stack, locals, r->size, r->value, target);
apply(c, Move, r->size, site, r->size, target);
return target; return target;
} }
} }
@ -2615,9 +2720,17 @@ pickJunctionSite(Context* c, Value* v, Read* r, unsigned index)
{ {
if (c->availableRegisterCount > 1) { if (c->availableRegisterCount > 1) {
Site* s = r->pickSite(c, v); Site* s = r->pickSite(c, v);
if (s) return s; if (s
and ((1 << s->type(c))
& ((1 << MemoryOperand)
| (1 << RegisterOperand))))
{
return s;
}
s = r->allocateSite(c); s = r->allocateSite(c);
if (s) return s; if (s) return s;
return freeRegisterSite(c); return freeRegisterSite(c);
} else { } else {
return frameSite(c, index); return frameSite(c, index);
@ -2631,11 +2744,10 @@ frameFootprint(Context* c, Stack* s)
} }
unsigned unsigned
resolveJunctionSite(Context* c, Event* e, Event* successor, Value* v, resolveJunctionSite(Context* c, Event* e, Value* v, unsigned index,
unsigned index, Site** frozenSites, Site** frozenSites, unsigned frozenSiteIndex)
unsigned frozenSiteIndex)
{ {
assert(c, index < frameFootprint(c, successor->stack)); assert(c, index < frameFootprint(c, e->stackAfter));
if (live(v)) { if (live(v)) {
assert(c, v->sites); assert(c, v->sites);
@ -2651,12 +2763,16 @@ resolveJunctionSite(Context* c, Event* e, Event* successor, Value* v,
unsigned copyCost; unsigned copyCost;
Site* site = pick(c, v->sites, target, &copyCost); Site* site = pick(c, v->sites, target, &copyCost);
if (copyCost) { if (copyCost) {
addSite(c, successor->stack, successor->locals, r->size, v, target); move(c, e->stackAfter, e->localsAfter, r->size, v, site, target);
apply(c, Move, r->size, site, r->size, target);
} else { } else {
target = site; target = site;
} }
target->makeSpecific(c);
char buffer[256]; target->toString(c, buffer, 256);
// fprintf(stderr, "resolve junction site %d %s %p\n", index, buffer, target);
if (original == 0) { if (original == 0) {
frozenSites[frozenSiteIndex++] = target; frozenSites[frozenSiteIndex++] = target;
target->freeze(c); target->freeze(c);
@ -2684,19 +2800,28 @@ propagateJunctionSites(Context* c, Event* e, Site** sites)
void void
populateSiteTables(Context* c, Event* e) populateSiteTables(Context* c, Event* e)
{ {
Event* successor = static_cast<Event*>(e->successors->value); unsigned frameFootprint = ::frameFootprint(c, e->stackAfter);
unsigned frameFootprint = ::frameFootprint(c, successor->stack);
{ Site* frozenSites[frameFootprint]; { Site* frozenSites[frameFootprint];
unsigned frozenSiteIndex = 0; unsigned frozenSiteIndex = 0;
if (e->junctionSites) { if (e->junctionSites) {
for (unsigned i = 0; i < frameFootprint; ++i) { if (e->stackAfter) {
Site* site = e->junctionSites[i]; unsigned i = e->stackAfter->index + c->localFootprint;
if (site) { for (Stack* stack = e->stackAfter; stack; stack = stack->next) {
frozenSites[frozenSiteIndex++] = site; if (e->junctionSites[i]) {
site->freeze(c); frozenSiteIndex = resolveJunctionSite
(c, e, stack->value, i, frozenSites, frozenSiteIndex);
i -= stack->size;
}
}
}
for (int i = c->localFootprint - 1; i >= 0; --i) {
if (e->localsAfter[i].value and e->junctionSites[i]) {
frozenSiteIndex = resolveJunctionSite
(c, e, e->localsAfter[i].value, i, frozenSites, frozenSiteIndex);
} }
} }
} else { } else {
@ -2715,21 +2840,22 @@ populateSiteTables(Context* c, Event* e)
} }
if (e->junctionSites) { if (e->junctionSites) {
for (unsigned i = 0; i < c->localFootprint; ++i) { if (e->stackAfter) {
if (successor->locals[i].value) { unsigned i = e->stackAfter->index + c->localFootprint;
frozenSiteIndex = resolveJunctionSite for (Stack* stack = e->stackAfter; stack; stack = stack->next) {
(c, e, successor, successor->locals[i].value, i, frozenSites, if (e->junctionSites[i] == 0) {
frozenSiteIndex); frozenSiteIndex = resolveJunctionSite
(c, e, stack->value, i, frozenSites, frozenSiteIndex);
i -= stack->size;
}
} }
} }
if (successor->stack) { for (int i = c->localFootprint - 1; i >= 0; --i) {
unsigned i = successor->stack->index + c->localFootprint; if (e->localsAfter[i].value and e->junctionSites[i] == 0) {
for (Stack* stack = successor->stack; stack; stack = stack->next) {
frozenSiteIndex = resolveJunctionSite frozenSiteIndex = resolveJunctionSite
(c, e, successor, stack->value, i, frozenSites, frozenSiteIndex); (c, e, e->localsAfter[i].value, i, frozenSites, frozenSiteIndex);
i -= stack->size;
} }
} }
} }
@ -2745,7 +2871,7 @@ populateSiteTables(Context* c, Event* e)
memset(savedSites, 0, size); memset(savedSites, 0, size);
for (unsigned i = 0; i < c->localFootprint; ++i) { for (unsigned i = 0; i < c->localFootprint; ++i) {
Value* v = successor->locals[i].value; Value* v = e->localsAfter[i].value;
if (v) { if (v) {
savedSites[i] = v->sites; savedSites[i] = v->sites;
@ -2753,9 +2879,9 @@ populateSiteTables(Context* c, Event* e)
} }
} }
if (successor->stack) { if (e->stackAfter) {
unsigned i = successor->stack->index + c->localFootprint; unsigned i = e->stackAfter->index + c->localFootprint;
for (Stack* stack = successor->stack; stack; stack = stack->next) { for (Stack* stack = e->stackAfter; stack; stack = stack->next) {
savedSites[i] = stack->value->sites; savedSites[i] = stack->value->sites;
// fprintf(stderr, "save %p for %p at %d\n", // fprintf(stderr, "save %p for %p at %d\n",
// savedSites[i], stack->value, i); // savedSites[i], stack->value, i);
@ -2772,7 +2898,7 @@ void
setSites(Context* c, Event* e, Site** sites) setSites(Context* c, Event* e, Site** sites)
{ {
for (unsigned i = 0; i < c->localFootprint; ++i) { for (unsigned i = 0; i < c->localFootprint; ++i) {
Value* v = e->locals[i].value; Value* v = e->localsBefore[i].value;
if (v) { if (v) {
clearSites(c, v); clearSites(c, v);
if (live(v)) { if (live(v)) {
@ -2783,9 +2909,9 @@ setSites(Context* c, Event* e, Site** sites)
} }
} }
if (e->stack) { if (e->stackBefore) {
unsigned i = e->stack->index + c->localFootprint; unsigned i = e->stackBefore->index + c->localFootprint;
for (Stack* stack = e->stack; stack; stack = stack->next) { for (Stack* stack = e->stackBefore; stack; stack = stack->next) {
Value* v = stack->value; Value* v = stack->value;
clearSites(c, v); clearSites(c, v);
if (live(v)) { if (live(v)) {
@ -2804,7 +2930,7 @@ populateSources(Context* c, Event* e)
Site* frozenSites[e->readCount]; Site* frozenSites[e->readCount];
unsigned frozenSiteIndex = 0; unsigned frozenSiteIndex = 0;
for (Read* r = e->reads; r; r = r->eventNext) { for (Read* r = e->reads; r; r = r->eventNext) {
r->value->source = readSource(c, e->stack, e->locals, r); r->value->source = readSource(c, e->stackBefore, e->localsBefore, r);
if (r->value->source) { if (r->value->source) {
assert(c, frozenSiteIndex < e->readCount); assert(c, frozenSiteIndex < e->readCount);
@ -2867,17 +2993,17 @@ updateStubRead(Context*, StubReadPair* p, Read* r)
} }
void void
updateJunctionReads(Context* c, Event* e, Event* successor) updateJunctionReads(Context* c, Event* e)
{ {
StubReadPair* reads = e->junctionReads; StubReadPair* reads = e->junctionReads;
for (unsigned i = 0; i < c->localFootprint; ++i) { for (unsigned i = 0; i < c->localFootprint; ++i) {
if (successor->locals[i].value) { if (e->localsAfter[i].value) {
updateStubRead(c, reads++, successor->locals[i].value->reads); updateStubRead(c, reads++, e->localsAfter[i].value->reads);
} }
} }
for (Stack* s = successor->stack; s; s = s->next) { for (Stack* s = e->stackAfter; s; s = s->next) {
updateStubRead(c, reads++, s->value->reads); updateStubRead(c, reads++, s->value->reads);
} }
} }
@ -2930,7 +3056,8 @@ compile(Context* c)
"compile %s at %d with %d preds, %d succs, %d stack\n", "compile %s at %d with %d preds, %d succs, %d stack\n",
e->name(), e->logicalInstruction->index, e->name(), e->logicalInstruction->index,
count(e->predecessors), count(e->successors), count(e->predecessors), count(e->successors),
e->stack ? e->stack->index + e->stack->size : 0); e->stackBefore ?
e->stackBefore->index + e->stackBefore->size : 0);
} }
if (e->logicalInstruction->machineOffset == 0) { if (e->logicalInstruction->machineOffset == 0) {
@ -2949,7 +3076,7 @@ compile(Context* c)
Event* predecessor = static_cast<Event*>(e->predecessors->value); Event* predecessor = static_cast<Event*>(e->predecessors->value);
if (e->predecessors->next) { if (e->predecessors->next) {
for (Cell* cell = e->predecessors; cell->next; cell = cell->next) { for (Cell* cell = e->predecessors; cell->next; cell = cell->next) {
updateJunctionReads(c, static_cast<Event*>(cell->value), e); updateJunctionReads(c, static_cast<Event*>(cell->value));
} }
setSites(c, e, predecessor->junctionSites); setSites(c, e, predecessor->junctionSites);
} else if (predecessor->successors->next) { } else if (predecessor->successors->next) {
@ -3164,10 +3291,14 @@ class MyCompiler: public Compiler {
Event* e = c.logicalCode[logicalIp]->firstEvent; Event* e = c.logicalCode[logicalIp]->firstEvent;
if (c.predecessor) { Event* p = c.predecessor;
c.predecessor->successors = cons(&c, e, c.predecessor->successors); if (p) {
populateJunctionReads(&c, c.predecessor); p->stackAfter = c.stack;
e->predecessors = cons(&c, c.predecessor, e->predecessors); p->localsAfter = c.locals;
p->successors = cons(&c, e, p->successors);
populateJunctionReads(&c, p);
e->predecessors = cons(&c, p, e->predecessors);
} }
} }
@ -3278,7 +3409,8 @@ class MyCompiler: public Compiler {
virtual void pushed() { virtual void pushed() {
Value* v = value(&c); Value* v = value(&c);
appendFrameSite appendFrameSite
(&c, v, BytesPerWord, (c.stack ? c.stack->index + c.stack->size : 0)); (&c, v, BytesPerWord,
(c.stack ? c.stack->index + c.stack->size : c.localFootprint));
c.stack = ::stack(&c, v, 1, c.stack); c.stack = ::stack(&c, v, 1, c.stack);
} }
@ -3395,7 +3527,7 @@ class MyCompiler: public Compiler {
Event* e = c.logicalCode[logicalIp]->firstEvent; Event* e = c.logicalCode[logicalIp]->firstEvent;
for (unsigned i = 0; i < c.localFootprint; ++i) { for (unsigned i = 0; i < c.localFootprint; ++i) {
Local* local = e->locals + i; Local* local = e->localsBefore + i;
if (local->value) { if (local->value) {
initLocal(local->size, i); initLocal(local->size, i);
} }

View File

@ -744,33 +744,33 @@ moveRM(Context* c, unsigned aSize, Assembler::Register* a,
} }
} }
void // void
moveMM(Context* c, unsigned aSize, Assembler::Memory* a, // moveMM(Context* c, unsigned aSize, Assembler::Memory* a,
unsigned bSize, Assembler::Memory* b) // unsigned bSize, Assembler::Memory* b)
{ // {
assert(c, aSize == bSize); // assert(c, aSize == bSize);
if (BytesPerWord == 8 or aSize <= 4) { // if (BytesPerWord == 8 or aSize <= 4) {
uint32_t mask; // uint32_t mask;
if (BytesPerWord == 4 and aSize == 1) { // if (BytesPerWord == 4 and aSize == 1) {
mask = (1 << rax) | (1 << rcx) | (1 << rdx) | (1 << rbx); // mask = (1 << rax) | (1 << rcx) | (1 << rdx) | (1 << rbx);
} else { // } else {
mask = ~static_cast<uint32_t>(0); // mask = ~static_cast<uint32_t>(0);
} // }
Assembler::Register tmp(c->client->acquireTemporary(mask)); // Assembler::Register tmp(c->client->acquireTemporary(mask));
moveMR(c, aSize, a, aSize, &tmp); // moveMR(c, aSize, a, aSize, &tmp);
moveRM(c, aSize, &tmp, bSize, b); // moveRM(c, aSize, &tmp, bSize, b);
c->client->releaseTemporary(tmp.low); // c->client->releaseTemporary(tmp.low);
} else { // } else {
Assembler::Register tmp(c->client->acquireTemporary(), // Assembler::Register tmp(c->client->acquireTemporary(),
c->client->acquireTemporary()); // c->client->acquireTemporary());
moveMR(c, aSize, a, aSize, &tmp); // moveMR(c, aSize, a, aSize, &tmp);
moveRM(c, aSize, &tmp, bSize, b); // moveRM(c, aSize, &tmp, bSize, b);
c->client->releaseTemporary(tmp.low); // c->client->releaseTemporary(tmp.low);
c->client->releaseTemporary(tmp.high); // c->client->releaseTemporary(tmp.high);
} // }
} // }
void void
moveAR(Context* c, unsigned aSize, Assembler::Address* a, moveAR(Context* c, unsigned aSize, Assembler::Address* a,
@ -1284,7 +1284,7 @@ populateTables(ArchitectureContext* c)
bo[index(Move, C, M)] = CAST2(moveCM); bo[index(Move, C, M)] = CAST2(moveCM);
bo[index(Move, A, M)] = CAST2(moveAM); bo[index(Move, A, M)] = CAST2(moveAM);
bo[index(Move, A, R)] = CAST2(moveAR); bo[index(Move, A, R)] = CAST2(moveAR);
bo[index(Move, M, M)] = CAST2(moveMM); // bo[index(Move, M, M)] = CAST2(moveMM);
bo[index(MoveZ, R, R)] = CAST2(moveZRR); bo[index(MoveZ, R, R)] = CAST2(moveZRR);
@ -1299,6 +1299,7 @@ populateTables(ArchitectureContext* c)
bo[index(Add, C, R)] = CAST2(addCR); bo[index(Add, C, R)] = CAST2(addCR);
bo[index(Subtract, C, R)] = CAST2(subtractCR); bo[index(Subtract, C, R)] = CAST2(subtractCR);
bo[index(Subtract, R, R)] = CAST2(subtractRR);
bo[index(And, C, R)] = CAST2(andCR); bo[index(And, C, R)] = CAST2(andCR);