From ad3ec1abf3e704d38aa0bcc844b86923810684a9 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 1 May 2014 13:56:39 -0600 Subject: [PATCH] introduce Frame::stackCall util --- include/avian/codegen/compiler.h | 3 +- src/compile.cpp | 125 ++++++++++++++++--------------- 2 files changed, 68 insertions(+), 60 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index a86b8cb309..31d0535082 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -91,7 +91,8 @@ class Compiler { unsigned flags, TraceHandler* traceHandler, ir::Type resultType, - unsigned argumentFootprint) = 0; + unsigned argumentFootprint /*, + util::Slice arguments*/) = 0; virtual void return_(ir::Type type, ir::Value* value) = 0; virtual void return_() = 0; diff --git a/src/compile.cpp b/src/compile.cpp index 6d156e9083..b89ea7aaf5 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1351,6 +1351,38 @@ void storeLocal(Context* context, avian::util::FixedAllocator* codeAllocator(MyThread* t); +ir::Type operandTypeForFieldCode(Thread* t, unsigned code) +{ + ir::Types types(TargetBytesPerWord); + + switch (code) { + case ByteField: + case BooleanField: + return types.i1; + case CharField: + case ShortField: + return types.i2; + case IntField: + return types.i4; + case LongField: + return types.i8; + + case ObjectField: + return types.object; + + case FloatField: + return types.f4; + case DoubleField: + return types.f8; + + case VoidField: + return types.void_; + + default: + abort(t); + } +} + class Frame { public: enum StackType { @@ -1942,6 +1974,21 @@ class Frame { return e; } + ir::Value* stackCall(ir::Value* methodValue, + object methodObject, + unsigned flags, + TraceElement* trace) + { + ir::Value* result = c->stackCall( + methodValue, + flags, + trace, + operandTypeForFieldCode(t, methodReturnCode(t, methodObject)), + methodParameterFootprint(t, methodObject)); + + return result; + } + unsigned startSubroutine(unsigned ip, avian::codegen::Promise* returnAddress) { pushAddress(absoluteAddressOperand(returnAddress)); @@ -3125,38 +3172,6 @@ ir::Value* popField(MyThread* t, Frame* frame, int code) } } -ir::Type operandTypeForFieldCode(Thread* t, unsigned code) -{ - ir::Types types(TargetBytesPerWord); - - switch (code) { - case ByteField: - case BooleanField: - return types.i1; - case CharField: - case ShortField: - return types.i2; - case IntField: - return types.i4; - case LongField: - return types.i8; - - case ObjectField: - return types.object; - - case FloatField: - return types.f4; - case DoubleField: - return types.f8; - - case VoidField: - return types.void_; - - default: - abort(t); - } -} - bool useLongJump(MyThread* t, uintptr_t target) { @@ -3217,12 +3232,11 @@ ir::Value* compileDirectInvoke(MyThread* t, (frame->context->zone.allocate(sizeof(TraceElementPromise))) TraceElementPromise(t->m->system, trace); - ir::Value* result = c->stackCall( + ir::Value* result = frame->stackCall( c->promiseConstant(returnAddressPromise, types.address), + target, flags, - trace, - operandTypeForFieldCode(t, methodReturnCode(t, target)), - methodParameterFootprint(t, target)); + trace); c->store( types.address, @@ -3237,12 +3251,10 @@ ir::Value* compileDirectInvoke(MyThread* t, return result; } else { - return c->stackCall( - c->constant(defaultThunk(t), types.address), - flags, - frame->trace(target, traceFlags), - operandTypeForFieldCode(t, methodReturnCode(t, target)), - methodParameterFootprint(t, target)); + return frame->stackCall(c->constant(defaultThunk(t), types.address), + target, + flags, + frame->trace(target, traceFlags)); } } else { ir::Value* address @@ -3250,13 +3262,13 @@ ir::Value* compileDirectInvoke(MyThread* t, ? c->promiseConstant(addressPromise, types.address) : c->constant(methodAddress(t, target), types.address)); - return c->stackCall - (address, - flags, - tailCall ? 0 : frame->trace - ((methodFlags(t, target) & ACC_NATIVE) ? target : 0, 0), - operandTypeForFieldCode(t, methodReturnCode(t, target)), - methodParameterFootprint(t, target)); + return frame->stackCall( + address, + target, + flags, + tailCall ? 0 + : frame->trace( + (methodFlags(t, target) & ACC_NATIVE) ? target : 0, 0)); } } @@ -3397,12 +3409,8 @@ void compileAbstractInvoke(MyThread* t, unsigned rSize = resultSize(t, returnCode); - ir::Value* result - = frame->c->stackCall(method, - tailCall ? Compiler::TailJump : 0, - frame->trace(0, 0), - operandTypeForFieldCode(t, returnCode), - parameterFootprint); + ir::Value* result = frame->stackCall( + method, target, tailCall ? Compiler::TailJump : 0, frame->trace(0, 0)); frame->pop(parameterFootprint); @@ -5191,17 +5199,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, unsigned rSize = resultSize(t, methodReturnCode(t, target)); - ir::Value* result = c->stackCall( + ir::Value* result = frame->stackCall( c->memory(c->binaryOp(lir::And, types.address, c->constant(TargetPointerMask, types.i4), c->memory(instance, types.object)), types.object, offset), + target, tailCall ? Compiler::TailJump : 0, - frame->trace(0, 0), - operandTypeForFieldCode(t, methodReturnCode(t, target)), - parameterFootprint); + frame->trace(0, 0)); frame->pop(parameterFootprint);