pass CallEvent arguments in Slice as well

This commit is contained in:
Joshua Warner 2014-05-01 16:40:57 -06:00
parent 4e00a1e304
commit 97ce7d2b4e
5 changed files with 147 additions and 92 deletions

View File

@ -12,6 +12,7 @@
#define AVIAN_CODEGEN_COMPILER_H #define AVIAN_CODEGEN_COMPILER_H
#include <avian/system/system.h> #include <avian/system/system.h>
#include <avian/util/slice.h>
#include "avian/zone.h" #include "avian/zone.h"
#include "assembler.h" #include "assembler.h"
#include "ir.h" #include "ir.h"
@ -91,8 +92,8 @@ class Compiler {
unsigned flags, unsigned flags,
TraceHandler* traceHandler, TraceHandler* traceHandler,
ir::Type resultType, ir::Type resultType,
unsigned argumentFootprint /*, unsigned argumentFootprint,
util::Slice<ir::Value*> arguments*/) = 0; util::Slice<ir::Value*> arguments) = 0;
virtual void return_(ir::Type type, ir::Value* value) = 0; virtual void return_(ir::Type type, ir::Value* value) = 0;
virtual void return_() = 0; virtual void return_() = 0;

View File

@ -2497,7 +2497,8 @@ class MyCompiler: public Compiler {
resultType.size(), resultType.size(),
argumentStack, argumentStack,
index, index,
0); 0,
util::Slice<ir::Value*>(0, 0));
return result; return result;
} }
@ -2506,7 +2507,8 @@ class MyCompiler: public Compiler {
unsigned flags, unsigned flags,
TraceHandler* traceHandler, TraceHandler* traceHandler,
ir::Type resultType, ir::Type resultType,
unsigned argumentFootprint) unsigned argumentFootprint,
Slice<ir::Value*> arguments)
{ {
Value* result = value(&c, resultType); Value* result = value(&c, resultType);
appendCall(&c, appendCall(&c,
@ -2517,7 +2519,8 @@ class MyCompiler: public Compiler {
resultType.size(), resultType.size(),
c.stack, c.stack,
0, 0,
argumentFootprint); argumentFootprint,
arguments);
return result; return result;
} }

View File

@ -187,21 +187,27 @@ Link* link(Context* c, Event* predecessor, Link* nextPredecessor, Event* success
class CallEvent: public Event { class CallEvent: public Event {
public: public:
CallEvent(Context* c, Value* address, unsigned flags, CallEvent(Context* c,
TraceHandler* traceHandler, Value* result, unsigned resultSize, Value* address,
Stack* argumentStack, unsigned argumentCount, unsigned flags,
unsigned stackArgumentFootprint): TraceHandler* traceHandler,
Event(c), Value* result,
address(address), unsigned resultSize,
traceHandler(traceHandler), Stack* argumentStack,
result(result), unsigned argumentCount,
returnAddressSurrogate(0), unsigned stackArgumentFootprint,
framePointerSurrogate(0), util::Slice<ir::Value*> arguments UNUSED)
popIndex(0), : Event(c),
stackArgumentIndex(0), address(address),
flags(flags), traceHandler(traceHandler),
resultSize(resultSize), result(result),
stackArgumentFootprint(stackArgumentFootprint) returnAddressSurrogate(0),
framePointerSurrogate(0),
popIndex(0),
stackArgumentIndex(0),
flags(flags),
resultSize(resultSize),
stackArgumentFootprint(stackArgumentFootprint)
{ {
uint32_t registerMask = c->regFile->generalRegisters.mask; uint32_t registerMask = c->regFile->generalRegisters.mask;
@ -280,10 +286,12 @@ class CallEvent: public Event {
Stack* stack = stackBefore; Stack* stack = stackBefore;
if (stackArgumentFootprint) { if (stackArgumentFootprint) {
RUNTIME_ARRAY(Value*, arguments, stackArgumentFootprint); RUNTIME_ARRAY(Value*, argsArr, stackArgumentFootprint);
for (int i = stackArgumentFootprint - 1; i >= 0; --i) { for (int i = stackArgumentFootprint - 1; i >= 0; --i) {
Value* v = stack->value; Value* v = stack->value;
ir::Value* v2 UNUSED = arguments[i];
stack = stack->next; stack = stack->next;
assert(c, v == v2);
if ((vm::TargetBytesPerWord == 8 if ((vm::TargetBytesPerWord == 8
and (v == 0 or (i >= 1 and stack->value == 0))) and (v == 0 or (i >= 1 and stack->value == 0)))
@ -291,10 +299,10 @@ class CallEvent: public Event {
{ {
assert(c, vm::TargetBytesPerWord == 8 or v->nextWord == stack->value); assert(c, vm::TargetBytesPerWord == 8 or v->nextWord == stack->value);
RUNTIME_ARRAY_BODY(arguments)[i--] = stack->value; RUNTIME_ARRAY_BODY(argsArr)[i--] = stack->value;
stack = stack->next; stack = stack->next;
} }
RUNTIME_ARRAY_BODY(arguments)[i] = v; RUNTIME_ARRAY_BODY(argsArr)[i] = v;
} }
int returnAddressIndex; int returnAddressIndex;
@ -321,7 +329,7 @@ class CallEvent: public Event {
} }
for (unsigned i = 0; i < stackArgumentFootprint; ++i) { for (unsigned i = 0; i < stackArgumentFootprint; ++i) {
Value* v = RUNTIME_ARRAY_BODY(arguments)[i]; Value* v = RUNTIME_ARRAY_BODY(argsArr)[i];
if (v) { if (v) {
int frameIndex = i + frameOffset; int frameIndex = i + frameOffset;
@ -493,16 +501,28 @@ class CallEvent: public Event {
unsigned stackArgumentFootprint; unsigned stackArgumentFootprint;
}; };
void void appendCall(Context* c,
appendCall(Context* c, Value* address, unsigned flags, Value* address,
TraceHandler* traceHandler, Value* result, unsigned resultSize, unsigned flags,
Stack* argumentStack, unsigned argumentCount, TraceHandler* traceHandler,
unsigned stackArgumentFootprint) Value* result,
unsigned resultSize,
Stack* argumentStack,
unsigned argumentCount,
unsigned stackArgumentFootprint,
util::Slice<ir::Value*> arguments)
{ {
append(c, new(c->zone) append(c,
CallEvent(c, address, flags, traceHandler, result, new (c->zone) CallEvent(c,
resultSize, argumentStack, argumentCount, address,
stackArgumentFootprint)); flags,
traceHandler,
result,
resultSize,
argumentStack,
argumentCount,
stackArgumentFootprint,
arguments));
} }
@ -944,7 +964,8 @@ appendCombine(Context* c, lir::TernaryOperation type,
resultSize, resultSize,
argumentStack, argumentStack,
stackSize, stackSize,
0); 0,
util::Slice<ir::Value*>(0, 0));
} else { } else {
append append
(c, new(c->zone) (c, new(c->zone)
@ -1067,7 +1088,8 @@ appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize,
resultSize, resultSize,
argumentStack, argumentStack,
ceilingDivide(firstSize, vm::TargetBytesPerWord), ceilingDivide(firstSize, vm::TargetBytesPerWord),
0); 0,
util::Slice<ir::Value*>(0, 0));
} else { } else {
append(c, new(c->zone) append(c, new(c->zone)
TranslateEvent TranslateEvent
@ -1432,7 +1454,8 @@ appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first
4, 4,
argumentStack, argumentStack,
ceilingDivide(size, vm::TargetBytesPerWord) * 2, ceilingDivide(size, vm::TargetBytesPerWord) * 2,
0); 0,
util::Slice<ir::Value*>(0, 0));
appendBranch(c, appendBranch(c,
thunkBranch(c, type), thunkBranch(c, type),

View File

@ -113,11 +113,16 @@ Link*
link(Context* c, Event* predecessor, Link* nextPredecessor, Event* successor, link(Context* c, Event* predecessor, Link* nextPredecessor, Event* successor,
Link* nextSuccessor, ForkState* forkState); Link* nextSuccessor, ForkState* forkState);
void void appendCall(Context* c,
appendCall(Context* c, Value* address, unsigned flags, Value* address,
TraceHandler* traceHandler, Value* result, unsigned resultSize, unsigned flags,
Stack* argumentStack, unsigned argumentCount, TraceHandler* traceHandler,
unsigned stackArgumentFootprint); Value* result,
unsigned resultSize,
Stack* argumentStack,
unsigned argumentCount,
unsigned stackArgumentFootprint,
util::Slice<ir::Value*> arguments);
void void
appendReturn(Context* c, unsigned size, Value* value); appendReturn(Context* c, unsigned size, Value* value);

View File

@ -1221,56 +1221,60 @@ class Context {
MyThread* t; MyThread* t;
}; };
Context(MyThread* t, BootContext* bootContext, object method): Context(MyThread* t, BootContext* bootContext, object method)
thread(t), : thread(t),
zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes),
assembler(t->arch->makeAssembler(t->m->heap, &zone)), assembler(t->arch->makeAssembler(t->m->heap, &zone)),
client(t), client(t),
compiler(makeCompiler(t->m->system, assembler, &zone, &client)), compiler(makeCompiler(t->m->system, assembler, &zone, &client)),
method(method), method(method),
bootContext(bootContext), bootContext(bootContext),
objectPool(0), objectPool(0),
subroutines(0), subroutines(0),
traceLog(0), traceLog(0),
visitTable(makeVisitTable(t, &zone, method)), visitTable(makeVisitTable(t, &zone, method)),
rootTable(makeRootTable(t, &zone, method)), rootTable(makeRootTable(t, &zone, method)),
subroutineTable(0), subroutineTable(0),
executableAllocator(0), executableAllocator(0),
executableStart(0), executableStart(0),
executableSize(0), executableSize(0),
objectPoolCount(0), objectPoolCount(0),
traceLogCount(0), traceLogCount(0),
dirtyRoots(false), dirtyRoots(false),
leaf(true), leaf(true),
eventLog(t->m->system, t->m->heap, 1024), eventLog(t->m->system, t->m->heap, 1024),
protector(this), protector(this),
resource(this) resource(this),
argumentBuffer(
(ir::Value**)t->m->heap->allocate(256 * sizeof(ir::Value*)),
256) // below the maximal allowed parameter count for Java
{ } { }
Context(MyThread* t): Context(MyThread* t)
thread(t), : thread(t),
zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes), zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes),
assembler(t->arch->makeAssembler(t->m->heap, &zone)), assembler(t->arch->makeAssembler(t->m->heap, &zone)),
client(t), client(t),
compiler(0), compiler(0),
method(0), method(0),
bootContext(0), bootContext(0),
objectPool(0), objectPool(0),
subroutines(0), subroutines(0),
traceLog(0), traceLog(0),
visitTable(0), visitTable(0),
rootTable(0), rootTable(0),
subroutineTable(0), subroutineTable(0),
executableAllocator(0), executableAllocator(0),
executableStart(0), executableStart(0),
executableSize(0), executableSize(0),
objectPoolCount(0), objectPoolCount(0),
traceLogCount(0), traceLogCount(0),
dirtyRoots(false), dirtyRoots(false),
leaf(true), leaf(true),
eventLog(t->m->system, t->m->heap, 0), eventLog(t->m->system, t->m->heap, 0),
protector(this), protector(this),
resource(this) resource(this),
argumentBuffer(0, 0)
{ } { }
~Context() { ~Context() {
@ -1291,6 +1295,10 @@ class Context {
eventLog.dispose(); eventLog.dispose();
zone.dispose(); zone.dispose();
if (argumentBuffer.begin()) {
thread->m->heap->free(argumentBuffer.begin(), 256 * sizeof(ir::Value*));
}
} }
MyThread* thread; MyThread* thread;
@ -1316,6 +1324,7 @@ class Context {
Vector eventLog; Vector eventLog;
MyProtector protector; MyProtector protector;
MyResource resource; MyResource resource;
Slice<ir::Value*> argumentBuffer;
}; };
unsigned unsigned
@ -2024,6 +2033,17 @@ class Frame {
} }
} }
Slice<ir::Value*> peekMethodArguments(unsigned footprint UNUSED)
{
ir::Value** ptr = context->argumentBuffer.items;
for (unsigned i = 0; i < footprint; i++) {
*(ptr++) = c->peek(1, footprint - i - 1);
}
return Slice<ir::Value*>(context->argumentBuffer.items, footprint);
}
void stackCall(ir::Value* methodValue, void stackCall(ir::Value* methodValue,
object methodObject, object methodObject,
unsigned flags, unsigned flags,
@ -2035,7 +2055,8 @@ class Frame {
flags, flags,
trace, trace,
operandTypeForFieldCode(t, returnCode), operandTypeForFieldCode(t, returnCode),
footprint); footprint,
peekMethodArguments(footprint));
pop(footprint); pop(footprint);
@ -2057,7 +2078,8 @@ class Frame {
flags, flags,
trace, trace,
operandTypeForFieldCode(t, returnCode), operandTypeForFieldCode(t, returnCode),
footprint); footprint,
peekMethodArguments(footprint));
pop(footprint); pop(footprint);
@ -5087,7 +5109,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
tailCall ? Compiler::TailJump : 0, tailCall ? Compiler::TailJump : 0,
frame->trace(0, 0), frame->trace(0, 0),
operandTypeForFieldCode(t, returnCode), operandTypeForFieldCode(t, returnCode),
parameterFootprint); parameterFootprint,
frame->peekMethodArguments(parameterFootprint));
frame->pop(parameterFootprint); frame->pop(parameterFootprint);