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

View File

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

View File

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

View File

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

View File

@ -1221,56 +1221,60 @@ class Context {
MyThread* t;
};
Context(MyThread* t, BootContext* bootContext, object method):
thread(t),
zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes),
assembler(t->arch->makeAssembler(t->m->heap, &zone)),
client(t),
compiler(makeCompiler(t->m->system, assembler, &zone, &client)),
method(method),
bootContext(bootContext),
objectPool(0),
subroutines(0),
traceLog(0),
visitTable(makeVisitTable(t, &zone, method)),
rootTable(makeRootTable(t, &zone, method)),
subroutineTable(0),
executableAllocator(0),
executableStart(0),
executableSize(0),
objectPoolCount(0),
traceLogCount(0),
dirtyRoots(false),
leaf(true),
eventLog(t->m->system, t->m->heap, 1024),
protector(this),
resource(this)
Context(MyThread* t, BootContext* bootContext, object method)
: thread(t),
zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes),
assembler(t->arch->makeAssembler(t->m->heap, &zone)),
client(t),
compiler(makeCompiler(t->m->system, assembler, &zone, &client)),
method(method),
bootContext(bootContext),
objectPool(0),
subroutines(0),
traceLog(0),
visitTable(makeVisitTable(t, &zone, method)),
rootTable(makeRootTable(t, &zone, method)),
subroutineTable(0),
executableAllocator(0),
executableStart(0),
executableSize(0),
objectPoolCount(0),
traceLogCount(0),
dirtyRoots(false),
leaf(true),
eventLog(t->m->system, t->m->heap, 1024),
protector(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):
thread(t),
zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes),
assembler(t->arch->makeAssembler(t->m->heap, &zone)),
client(t),
compiler(0),
method(0),
bootContext(0),
objectPool(0),
subroutines(0),
traceLog(0),
visitTable(0),
rootTable(0),
subroutineTable(0),
executableAllocator(0),
executableStart(0),
executableSize(0),
objectPoolCount(0),
traceLogCount(0),
dirtyRoots(false),
leaf(true),
eventLog(t->m->system, t->m->heap, 0),
protector(this),
resource(this)
Context(MyThread* t)
: thread(t),
zone(t->m->system, t->m->heap, InitialZoneCapacityInBytes),
assembler(t->arch->makeAssembler(t->m->heap, &zone)),
client(t),
compiler(0),
method(0),
bootContext(0),
objectPool(0),
subroutines(0),
traceLog(0),
visitTable(0),
rootTable(0),
subroutineTable(0),
executableAllocator(0),
executableStart(0),
executableSize(0),
objectPoolCount(0),
traceLogCount(0),
dirtyRoots(false),
leaf(true),
eventLog(t->m->system, t->m->heap, 0),
protector(this),
resource(this),
argumentBuffer(0, 0)
{ }
~Context() {
@ -1291,6 +1295,10 @@ class Context {
eventLog.dispose();
zone.dispose();
if (argumentBuffer.begin()) {
thread->m->heap->free(argumentBuffer.begin(), 256 * sizeof(ir::Value*));
}
}
MyThread* thread;
@ -1316,6 +1324,7 @@ class Context {
Vector eventLog;
MyProtector protector;
MyResource resource;
Slice<ir::Value*> argumentBuffer;
};
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,
object methodObject,
unsigned flags,
@ -2035,7 +2055,8 @@ class Frame {
flags,
trace,
operandTypeForFieldCode(t, returnCode),
footprint);
footprint,
peekMethodArguments(footprint));
pop(footprint);
@ -2057,7 +2078,8 @@ class Frame {
flags,
trace,
operandTypeForFieldCode(t, returnCode),
footprint);
footprint,
peekMethodArguments(footprint));
pop(footprint);
@ -5087,7 +5109,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
tailCall ? Compiler::TailJump : 0,
frame->trace(0, 0),
operandTypeForFieldCode(t, returnCode),
parameterFootprint);
parameterFootprint,
frame->peekMethodArguments(parameterFootprint));
frame->pop(parameterFootprint);