various bugfixes, especially concerning frame allocation and offset calculation

This commit is contained in:
Joel Dice 2009-02-25 20:49:42 -07:00
parent 6957492c7a
commit d7d3dd5055
5 changed files with 30 additions and 14 deletions

View File

@ -266,6 +266,7 @@ class Assembler {
virtual bool reserved(int register_) = 0; virtual bool reserved(int register_) = 0;
virtual unsigned argumentFootprint(unsigned footprint) = 0;
virtual unsigned argumentRegisterCount() = 0; virtual unsigned argumentRegisterCount() = 0;
virtual int argumentRegister(unsigned index) = 0; virtual int argumentRegister(unsigned index) = 0;

View File

@ -345,8 +345,7 @@ alignedFrameSize(MyThread* t, object method)
(localSize(t, method) (localSize(t, method)
- methodParameterFootprint(t, method) - methodParameterFootprint(t, method)
+ codeMaxStack(t, methodCode(t, method)) + codeMaxStack(t, methodCode(t, method))
+ MaxNativeCallFootprint + t->arch->argumentFootprint(MaxNativeCallFootprint));
- min(MaxNativeCallFootprint, t->arch->argumentRegisterCount()));
} }
unsigned unsigned

View File

@ -635,20 +635,25 @@ class Event {
unsigned readCount; unsigned readCount;
}; };
unsigned
usableFrameSize(Context* c)
{
return c->alignedFrameSize - c->arch->frameFooterSize();
}
int int
frameIndex(Context* c, int index) frameIndex(Context* c, int index)
{ {
assert(c, static_cast<int> assert(c, static_cast<int>
(c->alignedFrameSize + c->parameterFootprint - index - 1) (usableFrameSize(c) + c->parameterFootprint - index - 1) >= 0);
>= 0);
return c->alignedFrameSize + c->parameterFootprint - index - 1; return usableFrameSize(c) + c->parameterFootprint - index - 1;
} }
unsigned unsigned
frameIndexToOffset(Context* c, unsigned frameIndex) frameIndexToOffset(Context* c, unsigned frameIndex)
{ {
return ((frameIndex >= c->alignedFrameSize) ? return ((frameIndex >= usableFrameSize(c)) ?
(frameIndex (frameIndex
+ (c->arch->frameFooterSize() * 2) + (c->arch->frameFooterSize() * 2)
+ c->arch->frameHeaderSize()) : + c->arch->frameHeaderSize()) :
@ -662,7 +667,7 @@ offsetToFrameIndex(Context* c, unsigned offset)
unsigned normalizedOffset = offset / BytesPerWord; unsigned normalizedOffset = offset / BytesPerWord;
return ((normalizedOffset return ((normalizedOffset
>= c->alignedFrameSize >= usableFrameSize(c)
+ c->arch->frameFooterSize()) ? + c->arch->frameFooterSize()) ?
(normalizedOffset (normalizedOffset
- (c->arch->frameFooterSize() * 2) - (c->arch->frameFooterSize() * 2)
@ -2187,7 +2192,7 @@ saveLocals(Context* c, Event* e)
if (DebugReads) { if (DebugReads) {
fprintf(stderr, "local save read %p at %d of %d\n", fprintf(stderr, "local save read %p at %d of %d\n",
local->value, ::frameIndex(c, li), local->value, ::frameIndex(c, li),
c->alignedFrameSize + c->parameterFootprint); usableFrameSize(c) + c->parameterFootprint);
} }
addRead(c, e, local->value, read addRead(c, e, local->value, read
@ -2272,7 +2277,7 @@ class CallEvent: public Event {
if (DebugReads) { if (DebugReads) {
fprintf(stderr, "stack arg read %p at %d of %d\n", fprintf(stderr, "stack arg read %p at %d of %d\n",
s->value, frameIndex, s->value, frameIndex,
c->alignedFrameSize + c->parameterFootprint); usableFrameSize(c) + c->parameterFootprint);
} }
addRead(c, this, s->value, read addRead(c, this, s->value, read
@ -2284,7 +2289,7 @@ class CallEvent: public Event {
if (DebugReads) { if (DebugReads) {
fprintf(stderr, "stack save read %p at %d of %d\n", fprintf(stderr, "stack save read %p at %d of %d\n",
s->value, logicalIndex, s->value, logicalIndex,
c->alignedFrameSize + c->parameterFootprint); usableFrameSize(c) + c->parameterFootprint);
} }
addRead(c, this, s->value, read addRead(c, this, s->value, read
@ -2307,7 +2312,7 @@ class CallEvent: public Event {
} }
popIndex popIndex
= c->alignedFrameSize = usableFrameSize(c)
+ c->parameterFootprint + c->parameterFootprint
- (stackBefore ? stackBefore->index + 1 - stackArgumentFootprint : 0) - (stackBefore ? stackBefore->index + 1 - stackArgumentFootprint : 0)
- c->localFootprint; - c->localFootprint;
@ -4540,7 +4545,7 @@ class MyCompiler: public Compiler {
c.localFootprint = localFootprint; c.localFootprint = localFootprint;
c.alignedFrameSize = alignedFrameSize; c.alignedFrameSize = alignedFrameSize;
unsigned frameResourceCount = alignedFrameSize + parameterFootprint; unsigned frameResourceCount = usableFrameSize(&c) + parameterFootprint;
c.frameResources = static_cast<FrameResource*> c.frameResources = static_cast<FrameResource*>
(c.zone->allocate(sizeof(FrameResource) * frameResourceCount)); (c.zone->allocate(sizeof(FrameResource) * frameResourceCount));

View File

@ -651,6 +651,8 @@ void remainderR(Context* con, unsigned size, Reg* a, Reg* b, Reg* t) {
void andC(Context* c, unsigned size, Assembler::Constant* a, void andC(Context* c, unsigned size, Assembler::Constant* a,
Assembler::Register* b, Assembler::Register* dst) Assembler::Register* b, Assembler::Register* dst)
{ {
abort(c); // todo
int64_t v = a->value->value(); int64_t v = a->value->value();
if(size == 8) { if(size == 8) {
@ -667,7 +669,7 @@ void andC(Context* c, unsigned size, Assembler::Constant* a,
andC(c, 4, &ah, &bh, &dh); andC(c, 4, &ah, &bh, &dh);
} else { } else {
issue(c, andi(dst->low, b->low, v)); issue(c, andi(dst->low, b->low, v));
if (not isInt16(v)) { if (v >> 16) {
issue(c, andis(dst->low, b->low, v >> 16)); issue(c, andis(dst->low, b->low, v >> 16));
} }
} }
@ -1209,6 +1211,10 @@ class MyArchitecture: public Assembler::Architecture {
} }
} }
virtual unsigned argumentFootprint(unsigned footprint) {
return footprint;
}
virtual unsigned argumentRegisterCount() { virtual unsigned argumentRegisterCount() {
return 8; return 8;
} }
@ -1266,7 +1272,7 @@ class MyArchitecture: public Assembler::Architecture {
unsigned, uint8_t* aTypeMask, uint64_t* aRegisterMask, unsigned, uint8_t* aTypeMask, uint64_t* aRegisterMask,
bool* thunk) bool* thunk)
{ {
*aTypeMask = (1 << RegisterOperand); *aTypeMask = (1 << RegisterOperand) | (1 << ConstantOperand);
*aRegisterMask = ~static_cast<uint64_t>(0); *aRegisterMask = ~static_cast<uint64_t>(0);
*thunk = false; *thunk = false;
} }

View File

@ -2021,6 +2021,11 @@ class MyArchitecture: public Assembler::Architecture {
} }
} }
virtual unsigned argumentFootprint(unsigned footprint) {
return footprint > argumentRegisterCount() ?
footprint - argumentRegisterCount() : 0;
}
virtual unsigned argumentRegisterCount() { virtual unsigned argumentRegisterCount() {
return (BytesPerWord == 4 ? 0 : 6); return (BytesPerWord == 4 ? 0 : 6);
} }