move Compiler::Operand to ir::Value

This commit is contained in:
Joshua Warner 2014-05-01 12:44:42 -06:00
parent 865041b688
commit 479c056b2c
6 changed files with 351 additions and 328 deletions

View File

@ -40,15 +40,6 @@ class Compiler {
static const unsigned TailJump = 1 << 2; static const unsigned TailJump = 1 << 2;
static const unsigned LongJumpOrCall = 1 << 3; static const unsigned LongJumpOrCall = 1 << 3;
class Operand {
public:
ir::Type type;
Operand(ir::Type type) : type(type)
{
}
};
class State { }; class State { };
class Subroutine { }; class Subroutine { };
@ -56,7 +47,7 @@ class Compiler {
virtual void restoreState(State* state) = 0; virtual void restoreState(State* state) = 0;
virtual Subroutine* startSubroutine() = 0; virtual Subroutine* startSubroutine() = 0;
virtual void returnFromSubroutine(Subroutine* subroutine, Operand* address) virtual void returnFromSubroutine(Subroutine* subroutine, ir::Value* address)
= 0; = 0;
virtual void linkSubroutine(Subroutine* subroutine) = 0; virtual void linkSubroutine(Subroutine* subroutine) = 0;
@ -71,83 +62,84 @@ class Compiler {
virtual Promise* poolAppend(intptr_t value) = 0; virtual Promise* poolAppend(intptr_t value) = 0;
virtual Promise* poolAppendPromise(Promise* value) = 0; virtual Promise* poolAppendPromise(Promise* value) = 0;
virtual Operand* constant(int64_t value, ir::Type type) = 0; virtual ir::Value* constant(int64_t value, ir::Type type) = 0;
virtual Operand* promiseConstant(Promise* value, ir::Type type) = 0; virtual ir::Value* promiseConstant(Promise* value, ir::Type type) = 0;
virtual Operand* address(ir::Type type, Promise* address) = 0; virtual ir::Value* address(ir::Type type, Promise* address) = 0;
virtual Operand* memory(Operand* base, virtual ir::Value* memory(ir::Value* base,
ir::Type type, ir::Type type,
int displacement = 0, int displacement = 0,
Operand* index = 0) = 0; ir::Value* index = 0) = 0;
virtual Operand* threadRegister() = 0; virtual ir::Value* threadRegister() = 0;
virtual void push(ir::Type type, Operand* value) = 0; virtual void push(ir::Type type, ir::Value* value) = 0;
virtual void save(ir::Type type, Operand* value) = 0; virtual void save(ir::Type type, ir::Value* value) = 0;
virtual Operand* pop(ir::Type type) = 0; virtual ir::Value* pop(ir::Type type) = 0;
virtual void pushed() = 0; virtual void pushed() = 0;
virtual void popped(unsigned footprint) = 0; virtual void popped(unsigned footprint) = 0;
virtual unsigned topOfStack() = 0; virtual unsigned topOfStack() = 0;
virtual Operand* peek(unsigned footprint, unsigned index) = 0; virtual ir::Value* peek(unsigned footprint, unsigned index) = 0;
virtual Operand* call(Operand* address, virtual ir::Value* call(ir::Value* address,
unsigned flags, unsigned flags,
TraceHandler* traceHandler, TraceHandler* traceHandler,
ir::Type resultType, ir::Type resultType,
unsigned argumentCount, unsigned argumentCount,
...) = 0; ...) = 0;
virtual Operand* stackCall(Operand* address, virtual ir::Value* stackCall(ir::Value* address,
unsigned flags, unsigned flags,
TraceHandler* traceHandler, TraceHandler* traceHandler,
ir::Type resultType, ir::Type resultType,
unsigned argumentFootprint) = 0; unsigned argumentFootprint) = 0;
virtual void return_(ir::Type type, Operand* value) = 0; virtual void return_(ir::Type type, ir::Value* value) = 0;
virtual void return_() = 0; virtual void return_() = 0;
virtual void initLocal(unsigned size, unsigned index, ir::Type type) = 0; virtual void initLocal(unsigned size, unsigned index, ir::Type type) = 0;
virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0; virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0;
virtual void storeLocal(unsigned footprint, Operand* src, virtual void storeLocal(unsigned footprint, ir::Value* src, unsigned index)
unsigned index) = 0; = 0;
virtual Operand* loadLocal(ir::Type type, unsigned index) = 0; virtual ir::Value* loadLocal(ir::Type type, unsigned index) = 0;
virtual void saveLocals() = 0; virtual void saveLocals() = 0;
virtual void checkBounds(Operand* object, unsigned lengthOffset, virtual void checkBounds(ir::Value* object,
Operand* index, intptr_t handler) = 0; unsigned lengthOffset,
ir::Value* index,
intptr_t handler) = 0;
virtual Operand* truncateThenExtend(ir::SignExtendMode signExtend, virtual ir::Value* truncateThenExtend(ir::SignExtendMode signExtend,
ir::Type extendType, ir::Type extendType,
ir::Type truncateType, ir::Type truncateType,
Operand* src) = 0; ir::Value* src) = 0;
virtual void store(ir::Type srcType, virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst) = 0;
Operand* src, virtual ir::Value* load(ir::SignExtendMode signExtend,
Operand* dst) = 0;
virtual Operand* load(ir::SignExtendMode signExtend,
ir::Type srcType, ir::Type srcType,
Operand* src, ir::Value* src,
ir::Type dstType) = 0; ir::Type dstType) = 0;
virtual void condJump(lir::TernaryOperation op, virtual void condJump(lir::TernaryOperation op,
ir::Type type, ir::Type type,
Operand* a, ir::Value* a,
Operand* b, ir::Value* b,
Operand* address) = 0; ir::Value* address) = 0;
virtual void jmp(Operand* address) = 0; virtual void jmp(ir::Value* address) = 0;
virtual void exit(Operand* address) = 0; virtual void exit(ir::Value* address) = 0;
virtual Operand* binaryOp(lir::TernaryOperation op, virtual ir::Value* binaryOp(lir::TernaryOperation op,
ir::Type type, ir::Type type,
Operand* a, ir::Value* a,
Operand* b) = 0; ir::Value* b) = 0;
virtual Operand* unaryOp(lir::BinaryOperation op, ir::Type type, Operand* a) virtual ir::Value* unaryOp(lir::BinaryOperation op,
= 0; ir::Type type,
ir::Value* a) = 0;
virtual void nullaryOp(lir::Operation op) = 0; virtual void nullaryOp(lir::Operation op) = 0;
virtual Operand* f2f(ir::Type aType, ir::Type resType, Operand* a) = 0; virtual ir::Value* f2f(ir::Type aType, ir::Type resType, ir::Value* a) = 0;
virtual Operand* f2i(ir::Type aType, ir::Type resType, Operand* a) = 0; virtual ir::Value* f2i(ir::Type aType, ir::Type resType, ir::Value* a) = 0;
virtual Operand* i2f(ir::Type aType, ir::Type resType, Operand* a) = 0; virtual ir::Value* i2f(ir::Type aType, ir::Type resType, ir::Value* a) = 0;
virtual void compile(uintptr_t stackOverflowHandler, virtual void compile(uintptr_t stackOverflowHandler,
unsigned stackLimitOffset) = 0; unsigned stackLimitOffset) = 0;

View File

@ -115,6 +115,15 @@ class Types {
enum SignExtendMode { SignExtend, ZeroExtend }; enum SignExtendMode { SignExtend, ZeroExtend };
class Value {
public:
ir::Type type;
Value(ir::Type type) : type(type)
{
}
};
} // namespace ir } // namespace ir
} // namespace codegen } // namespace codegen
} // namespace avian } // namespace avian

View File

@ -2151,7 +2151,8 @@ class MyCompiler: public Compiler {
return c.subroutine = new(c.zone) MySubroutine; return c.subroutine = new(c.zone) MySubroutine;
} }
virtual void returnFromSubroutine(Subroutine* subroutine, Operand* address) { virtual void returnFromSubroutine(Subroutine* subroutine, ir::Value* address)
{
appendSaveLocals(&c); appendSaveLocals(&c);
appendJump(&c, lir::Jump, static_cast<Value*>(address), false, true); appendJump(&c, lir::Jump, static_cast<Value*>(address), false, true);
static_cast<MySubroutine*>(subroutine)->forkState = compiler::saveState(&c); static_cast<MySubroutine*>(subroutine)->forkState = compiler::saveState(&c);
@ -2308,25 +2309,25 @@ class MyCompiler: public Compiler {
return p; return p;
} }
virtual Operand* constant(int64_t value, ir::Type type) virtual ir::Value* constant(int64_t value, ir::Type type)
{ {
return promiseConstant(resolvedPromise(&c, value), type); return promiseConstant(resolvedPromise(&c, value), type);
} }
virtual Operand* promiseConstant(Promise* value, ir::Type type) virtual ir::Value* promiseConstant(Promise* value, ir::Type type)
{ {
return compiler::value(&c, type, compiler::constantSite(&c, value)); return compiler::value(&c, type, compiler::constantSite(&c, value));
} }
virtual Operand* address(ir::Type type, Promise* address) virtual ir::Value* address(ir::Type type, Promise* address)
{ {
return value(&c, type, compiler::addressSite(&c, address)); return value(&c, type, compiler::addressSite(&c, address));
} }
virtual Operand* memory(Operand* base, virtual ir::Value* memory(ir::Value* base,
ir::Type type, ir::Type type,
int displacement = 0, int displacement = 0,
Operand* index = 0) ir::Value* index = 0)
{ {
Value* result = value(&c, type); Value* result = value(&c, type);
@ -2340,7 +2341,7 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* threadRegister() virtual ir::Value* threadRegister()
{ {
return compiler::threadRegister(&c); return compiler::threadRegister(&c);
} }
@ -2349,7 +2350,7 @@ class MyCompiler: public Compiler {
return c.logicalCode[c.logicalIp]->lastEvent->makeCodePromise(&c); return c.logicalCode[c.logicalIp]->lastEvent->makeCodePromise(&c);
} }
virtual void push(ir::Type type, Operand* value) virtual void push(ir::Type type, ir::Value* value)
{ {
// TODO: once type information is flowed properly, enable this assert. // TODO: once type information is flowed properly, enable this assert.
// Some time later, we can remove the parameter. // Some time later, we can remove the parameter.
@ -2357,7 +2358,7 @@ class MyCompiler: public Compiler {
compiler::push(&c, typeFootprint(&c, type), static_cast<Value*>(value)); compiler::push(&c, typeFootprint(&c, type), static_cast<Value*>(value));
} }
virtual void save(ir::Type type, Operand* value) virtual void save(ir::Type type, ir::Value* value)
{ {
// TODO: once type information is flowed properly, enable this assert. // TODO: once type information is flowed properly, enable this assert.
// Some time later, we can remove the parameter. // Some time later, we can remove the parameter.
@ -2373,9 +2374,9 @@ class MyCompiler: public Compiler {
} }
} }
virtual Operand* pop(ir::Type type) virtual ir::Value* pop(ir::Type type)
{ {
Operand* value = compiler::pop(&c, typeFootprint(&c, type)); ir::Value* value = compiler::pop(&c, typeFootprint(&c, type));
// TODO: once type information is flowed properly, enable this assert. // TODO: once type information is flowed properly, enable this assert.
// Some time later, we can remove the parameter. // Some time later, we can remove the parameter.
// assert(&c, static_cast<Value*>(value)->type == type); // assert(&c, static_cast<Value*>(value)->type == type);
@ -2409,7 +2410,8 @@ class MyCompiler: public Compiler {
return c.stack->index; return c.stack->index;
} }
virtual Operand* peek(unsigned footprint, unsigned index) { virtual ir::Value* peek(unsigned footprint, unsigned index)
{
Stack* s = c.stack; Stack* s = c.stack;
for (unsigned i = index; i > 0; --i) { for (unsigned i = index; i > 0; --i) {
s = s->next; s = s->next;
@ -2445,7 +2447,7 @@ class MyCompiler: public Compiler {
return s->value; return s->value;
} }
virtual Operand* call(Operand* address, virtual ir::Value* call(ir::Value* address,
unsigned flags, unsigned flags,
TraceHandler* traceHandler, TraceHandler* traceHandler,
ir::Type resultType, ir::Type resultType,
@ -2500,7 +2502,7 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* stackCall(Operand* address, virtual ir::Value* stackCall(ir::Value* address,
unsigned flags, unsigned flags,
TraceHandler* traceHandler, TraceHandler* traceHandler,
ir::Type resultType, ir::Type resultType,
@ -2519,7 +2521,7 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual void return_(ir::Type type, Operand* value) virtual void return_(ir::Type type, ir::Value* value)
{ {
// TODO: once type information is flowed properly, enable this assert. // TODO: once type information is flowed properly, enable this assert.
// Some time later, we can remove the parameter. // Some time later, we can remove the parameter.
@ -2595,11 +2597,12 @@ class MyCompiler: public Compiler {
linkLocals(&c, e->locals(), newLocals); linkLocals(&c, e->locals(), newLocals);
} }
virtual void storeLocal(unsigned footprint, Operand* src, unsigned index) { virtual void storeLocal(unsigned footprint, ir::Value* src, unsigned index)
{
compiler::storeLocal(&c, footprint, static_cast<Value*>(src), index, true); compiler::storeLocal(&c, footprint, static_cast<Value*>(src), index, true);
} }
virtual Operand* loadLocal(ir::Type type, unsigned index) virtual ir::Value* loadLocal(ir::Type type, unsigned index)
{ {
return compiler::loadLocal(&c, type, index); return compiler::loadLocal(&c, type, index);
} }
@ -2608,17 +2611,19 @@ class MyCompiler: public Compiler {
appendSaveLocals(&c); appendSaveLocals(&c);
} }
virtual void checkBounds(Operand* object, unsigned lengthOffset, virtual void checkBounds(ir::Value* object,
Operand* index, intptr_t handler) unsigned lengthOffset,
ir::Value* index,
intptr_t handler)
{ {
appendBoundsCheck(&c, static_cast<Value*>(object), lengthOffset, appendBoundsCheck(&c, static_cast<Value*>(object), lengthOffset,
static_cast<Value*>(index), handler); static_cast<Value*>(index), handler);
} }
virtual Operand* truncateThenExtend(ir::SignExtendMode signExtend, virtual ir::Value* truncateThenExtend(ir::SignExtendMode signExtend,
ir::Type extendType, ir::Type extendType,
ir::Type truncateType, ir::Type truncateType,
Operand* src) ir::Value* src)
{ {
Value* dst = value(&c, extendType); Value* dst = value(&c, extendType);
appendMove(&c, appendMove(&c,
@ -2631,9 +2636,7 @@ class MyCompiler: public Compiler {
return dst; return dst;
} }
virtual void store(ir::Type srcType, virtual void store(ir::Type srcType, ir::Value* src, ir::Value* dst)
Operand* src,
Operand* dst)
{ {
assert(&c, srcType.flavor() == static_cast<Value*>(src)->type.flavor()); assert(&c, srcType.flavor() == static_cast<Value*>(src)->type.flavor());
assert(&c, srcType.flavor() == static_cast<Value*>(dst)->type.flavor()); assert(&c, srcType.flavor() == static_cast<Value*>(dst)->type.flavor());
@ -2649,9 +2652,9 @@ class MyCompiler: public Compiler {
static_cast<Value*>(dst)); static_cast<Value*>(dst));
} }
virtual Operand* load(ir::SignExtendMode signExtend, virtual ir::Value* load(ir::SignExtendMode signExtend,
ir::Type srcType, ir::Type srcType,
Operand* src, ir::Value* src,
ir::Type dstType) ir::Type dstType)
{ {
assert(&c, dstType.size() >= TargetBytesPerWord); assert(&c, dstType.size() >= TargetBytesPerWord);
@ -2670,9 +2673,9 @@ class MyCompiler: public Compiler {
virtual void condJump(lir::TernaryOperation op, virtual void condJump(lir::TernaryOperation op,
ir::Type type, ir::Type type,
Operand* a, ir::Value* a,
Operand* b, ir::Value* b,
Operand* address) ir::Value* address)
{ {
assert(&c, assert(&c,
(isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or( (isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or(
@ -2692,18 +2695,20 @@ class MyCompiler: public Compiler {
static_cast<Value*>(address)); static_cast<Value*>(address));
} }
virtual void jmp(Operand* address) { virtual void jmp(ir::Value* address)
{
appendJump(&c, lir::Jump, static_cast<Value*>(address)); appendJump(&c, lir::Jump, static_cast<Value*>(address));
} }
virtual void exit(Operand* address) { virtual void exit(ir::Value* address)
{
appendJump(&c, lir::Jump, static_cast<Value*>(address), true); appendJump(&c, lir::Jump, static_cast<Value*>(address), true);
} }
virtual Operand* binaryOp(lir::TernaryOperation op, virtual ir::Value* binaryOp(lir::TernaryOperation op,
ir::Type type, ir::Type type,
Operand* a, ir::Value* a,
Operand* b) ir::Value* b)
{ {
assert(&c, assert(&c,
(isGeneralBinaryOp(op) and isGeneralValue(a) and isGeneralValue(b)) (isGeneralBinaryOp(op) and isGeneralValue(a) and isGeneralValue(b))
@ -2722,7 +2727,9 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* unaryOp(lir::BinaryOperation op, ir::Type type, Operand* a) virtual ir::Value* unaryOp(lir::BinaryOperation op,
ir::Type type,
ir::Value* a)
{ {
assert(&c, assert(&c,
(isGeneralUnaryOp(op) and isGeneralValue(a))or(isFloatUnaryOp(op) (isGeneralUnaryOp(op) and isGeneralValue(a))or(isFloatUnaryOp(op)
@ -2733,7 +2740,7 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* f2f(ir::Type aType, ir::Type resType, Operand* a) virtual ir::Value* f2f(ir::Type aType, ir::Type resType, ir::Value* a)
{ {
assert(&c, aType == static_cast<Value*>(a)->type); assert(&c, aType == static_cast<Value*>(a)->type);
assert(&c, isFloatValue(a)); assert(&c, isFloatValue(a));
@ -2749,7 +2756,7 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* f2i(ir::Type aType, ir::Type resType, Operand* a) virtual ir::Value* f2i(ir::Type aType, ir::Type resType, ir::Value* a)
{ {
// TODO: enable when possible // TODO: enable when possible
// assert(&c, aType == static_cast<Value*>(a)->type); // assert(&c, aType == static_cast<Value*>(a)->type);
@ -2766,7 +2773,7 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual Operand* i2f(ir::Type aType, ir::Type resType, Operand* a) virtual ir::Value* i2f(ir::Type aType, ir::Type resType, ir::Value* a)
{ {
// TODO: enable when possible // TODO: enable when possible
// assert(&c, aType == static_cast<Value*>(a)->type); // assert(&c, aType == static_cast<Value*>(a)->type);

View File

@ -18,7 +18,7 @@ namespace codegen {
namespace compiler { namespace compiler {
Value::Value(Site* site, Site* target, ir::Type type) Value::Value(Site* site, Site* target, ir::Type type)
: Compiler::Operand(type), : ir::Value(type),
reads(0), reads(0),
lastRead(0), lastRead(0),
sites(site), sites(site),

View File

@ -26,7 +26,7 @@ const int NoFrameIndex = -1;
const bool DebugSites = false; const bool DebugSites = false;
class Value: public Compiler::Operand { class Value : public ir::Value {
public: public:
Read* reads; Read* reads;
Read* lastRead; Read* lastRead;
@ -66,12 +66,12 @@ class Value: public Compiler::Operand {
}; };
inline bool isFloatValue(Compiler::Operand* a) inline bool isFloatValue(ir::Value* a)
{ {
return static_cast<Value*>(a)->type.flavor() == ir::Type::Float; return static_cast<Value*>(a)->type.flavor() == ir::Type::Float;
} }
inline bool isGeneralValue(Compiler::Operand* a) inline bool isGeneralValue(ir::Value* a)
{ {
return !isFloatValue(a); return !isFloatValue(a);
} }

View File

@ -1331,7 +1331,7 @@ translateLocalIndex(Context* context, unsigned footprint, unsigned index)
} }
} }
Compiler::Operand* loadLocal(Context* context, ir::Value* loadLocal(Context* context,
unsigned footprint, unsigned footprint,
ir::Type type, ir::Type type,
unsigned index) unsigned index)
@ -1340,8 +1340,9 @@ Compiler::Operand* loadLocal(Context* context,
type, translateLocalIndex(context, footprint, index)); type, translateLocalIndex(context, footprint, index));
} }
void void storeLocal(Context* context,
storeLocal(Context* context, unsigned footprint, Compiler::Operand* value, unsigned footprint,
ir::Value* value,
unsigned index) unsigned index)
{ {
context->compiler->storeLocal context->compiler->storeLocal
@ -1358,8 +1359,6 @@ class Frame {
Object Object
}; };
typedef Compiler::Operand* Value;
Frame(Context* context, uint8_t* stackMap) Frame(Context* context, uint8_t* stackMap)
: context(context), : context(context),
t(context->thread), t(context->thread),
@ -1403,7 +1402,8 @@ class Frame {
} }
} }
Value append(object o) { ir::Value* append(object o)
{
BootContext* bc = context->bootContext; BootContext* bc = context->bootContext;
if (bc) { if (bc) {
avian::codegen::Promise* p = new (bc->zone) avian::codegen::ListenPromise(t->m->system, bc->zone); avian::codegen::Promise* p = new (bc->zone) avian::codegen::ListenPromise(t->m->system, bc->zone);
@ -1637,11 +1637,13 @@ class Frame {
} }
} }
Value addressOperand(avian::codegen::Promise* p) { ir::Value* addressOperand(avian::codegen::Promise* p)
{
return c->promiseConstant(p, types.address); return c->promiseConstant(p, types.address);
} }
Value absoluteAddressOperand(avian::codegen::Promise* p) { ir::Value* absoluteAddressOperand(avian::codegen::Promise* p)
{
return context->bootContext return context->bootContext
? c->binaryOp( ? c->binaryOp(
lir::Add, lir::Add,
@ -1658,7 +1660,8 @@ class Frame {
: addressOperand(p); : addressOperand(p);
} }
Value machineIp(unsigned logicalIp) { ir::Value* machineIp(unsigned logicalIp)
{
return c->promiseConstant(c->machineIp(logicalIp), types.address); return c->promiseConstant(c->machineIp(logicalIp), types.address);
} }
@ -1682,35 +1685,40 @@ class Frame {
this->ip = ip; this->ip = ip;
} }
void pushQuiet(ir::Type type, Value o) void pushQuiet(ir::Type type, ir::Value* o)
{ {
c->push(type, o); c->push(type, o);
} }
void pushLongQuiet(Value o) { void pushLongQuiet(ir::Value* o)
{
pushQuiet(types.i8, o); pushQuiet(types.i8, o);
} }
Value popQuiet(ir::Type type) ir::Value* popQuiet(ir::Type type)
{ {
return c->pop(type); return c->pop(type);
} }
Value popLongQuiet() { ir::Value* popLongQuiet()
{
return popQuiet(types.i8); return popQuiet(types.i8);
} }
void pushInt(Value o) { void pushInt(ir::Value* o)
{
pushQuiet(types.i4, o); pushQuiet(types.i4, o);
pushedInt(); pushedInt();
} }
void pushAddress(Value o) { void pushAddress(ir::Value* o)
{
pushQuiet(types.i4, o); pushQuiet(types.i4, o);
pushedInt(); pushedInt();
} }
void pushObject(Value o) { void pushObject(ir::Value* o)
{
assert(t, o->type == types.object || o->type.flavor() == ir::Type::Address); assert(t, o->type == types.object || o->type.flavor() == ir::Type::Address);
pushQuiet(types.object, o); pushQuiet(types.object, o);
pushedObject(); pushedObject();
@ -1722,7 +1730,8 @@ class Frame {
pushedObject(); pushedObject();
} }
void pushLong(Value o) { void pushLong(ir::Value* o)
{
pushLongQuiet(o); pushLongQuiet(o);
pushedLong(); pushedLong();
} }
@ -1732,17 +1741,20 @@ class Frame {
c->popped(count); c->popped(count);
} }
Value popInt() { ir::Value* popInt()
{
poppedInt(); poppedInt();
return popQuiet(types.i4); return popQuiet(types.i4);
} }
Value popLong() { ir::Value* popLong()
{
poppedLong(); poppedLong();
return popLongQuiet(); return popLongQuiet();
} }
Value popObject() { ir::Value* popObject()
{
poppedObject(); poppedObject();
return popQuiet(types.object); return popQuiet(types.object);
} }
@ -1798,8 +1810,8 @@ class Frame {
} }
void dupX1() { void dupX1() {
Value s0 = popQuiet(types.i4); ir::Value* s0 = popQuiet(types.i4);
Value s1 = popQuiet(types.i4); ir::Value* s1 = popQuiet(types.i4);
pushQuiet(types.i4, s0); pushQuiet(types.i4, s0);
pushQuiet(types.i4, s1); pushQuiet(types.i4, s1);
@ -1809,17 +1821,17 @@ class Frame {
} }
void dupX2() { void dupX2() {
Value s0 = popQuiet(types.i4); ir::Value* s0 = popQuiet(types.i4);
if (get(sp - 2) == Long) { if (get(sp - 2) == Long) {
Value s1 = popLongQuiet(); ir::Value* s1 = popLongQuiet();
pushQuiet(types.i4, s0); pushQuiet(types.i4, s0);
pushLongQuiet(s1); pushLongQuiet(s1);
pushQuiet(types.i4, s0); pushQuiet(types.i4, s0);
} else { } else {
Value s1 = popQuiet(types.i4); ir::Value* s1 = popQuiet(types.i4);
Value s2 = popQuiet(types.i4); ir::Value* s2 = popQuiet(types.i4);
pushQuiet(types.i4, s0); pushQuiet(types.i4, s0);
pushQuiet(types.i4, s2); pushQuiet(types.i4, s2);
@ -1834,8 +1846,8 @@ class Frame {
if (get(sp - 1) == Long) { if (get(sp - 1) == Long) {
pushLongQuiet(c->peek(2, 0)); pushLongQuiet(c->peek(2, 0));
} else { } else {
Value s0 = popQuiet(types.i4); ir::Value* s0 = popQuiet(types.i4);
Value s1 = popQuiet(types.i4); ir::Value* s1 = popQuiet(types.i4);
pushQuiet(types.i4, s1); pushQuiet(types.i4, s1);
pushQuiet(types.i4, s0); pushQuiet(types.i4, s0);
@ -1848,16 +1860,16 @@ class Frame {
void dup2X1() { void dup2X1() {
if (get(sp - 1) == Long) { if (get(sp - 1) == Long) {
Value s0 = popLongQuiet(); ir::Value* s0 = popLongQuiet();
Value s1 = popQuiet(types.i4); ir::Value* s1 = popQuiet(types.i4);
pushLongQuiet(s0); pushLongQuiet(s0);
pushQuiet(types.i4, s1); pushQuiet(types.i4, s1);
pushLongQuiet(s0); pushLongQuiet(s0);
} else { } else {
Value s0 = popQuiet(types.i4); ir::Value* s0 = popQuiet(types.i4);
Value s1 = popQuiet(types.i4); ir::Value* s1 = popQuiet(types.i4);
Value s2 = popQuiet(types.i4); ir::Value* s2 = popQuiet(types.i4);
pushQuiet(types.i4, s1); pushQuiet(types.i4, s1);
pushQuiet(types.i4, s0); pushQuiet(types.i4, s0);
@ -1871,17 +1883,17 @@ class Frame {
void dup2X2() { void dup2X2() {
if (get(sp - 1) == Long) { if (get(sp - 1) == Long) {
Value s0 = popLongQuiet(); ir::Value* s0 = popLongQuiet();
if (get(sp - 3) == Long) { if (get(sp - 3) == Long) {
Value s1 = popLongQuiet(); ir::Value* s1 = popLongQuiet();
pushLongQuiet(s0); pushLongQuiet(s0);
pushLongQuiet(s1); pushLongQuiet(s1);
pushLongQuiet(s0); pushLongQuiet(s0);
} else { } else {
Value s1 = popQuiet(types.i4); ir::Value* s1 = popQuiet(types.i4);
Value s2 = popQuiet(types.i4); ir::Value* s2 = popQuiet(types.i4);
pushLongQuiet(s0); pushLongQuiet(s0);
pushQuiet(types.i4, s2); pushQuiet(types.i4, s2);
@ -1889,10 +1901,10 @@ class Frame {
pushLongQuiet(s0); pushLongQuiet(s0);
} }
} else { } else {
Value s0 = popQuiet(types.i4); ir::Value* s0 = popQuiet(types.i4);
Value s1 = popQuiet(types.i4); ir::Value* s1 = popQuiet(types.i4);
Value s2 = popQuiet(types.i4); ir::Value* s2 = popQuiet(types.i4);
Value s3 = popQuiet(types.i4); ir::Value* s3 = popQuiet(types.i4);
pushQuiet(types.i4, s1); pushQuiet(types.i4, s1);
pushQuiet(types.i4, s0); pushQuiet(types.i4, s0);
@ -1906,8 +1918,8 @@ class Frame {
} }
void swap() { void swap() {
Value s0 = popQuiet(types.i4); ir::Value* s0 = popQuiet(types.i4);
Value s1 = popQuiet(types.i4); ir::Value* s1 = popQuiet(types.i4);
pushQuiet(types.i4, s0); pushQuiet(types.i4, s0);
pushQuiet(types.i4, s1); pushQuiet(types.i4, s1);
@ -3065,9 +3077,10 @@ resultSize(MyThread* t, unsigned code)
} }
} }
void void pushReturnValue(MyThread* t,
pushReturnValue(MyThread* t, Frame* frame, unsigned code, Frame* frame,
Compiler::Operand* result) unsigned code,
ir::Value* result)
{ {
switch (code) { switch (code) {
case ByteField: case ByteField:
@ -3090,8 +3103,7 @@ pushReturnValue(MyThread* t, Frame* frame, unsigned code,
} }
} }
Compiler::Operand* ir::Value* popField(MyThread* t, Frame* frame, int code)
popField(MyThread* t, Frame* frame, int code)
{ {
switch (code) { switch (code) {
case ByteField: case ByteField:
@ -3169,7 +3181,7 @@ void compileSafePoint(MyThread* t, Compiler* c, Frame* frame) {
c->threadRegister()); c->threadRegister());
} }
Compiler::Operand* compileDirectInvoke(MyThread* t, ir::Value* compileDirectInvoke(MyThread* t,
Frame* frame, Frame* frame,
object target, object target,
bool tailCall, bool tailCall,
@ -3205,7 +3217,7 @@ Compiler::Operand* compileDirectInvoke(MyThread* t,
(frame->context->zone.allocate(sizeof(TraceElementPromise))) (frame->context->zone.allocate(sizeof(TraceElementPromise)))
TraceElementPromise(t->m->system, trace); TraceElementPromise(t->m->system, trace);
Compiler::Operand* result = c->stackCall( ir::Value* result = c->stackCall(
c->promiseConstant(returnAddressPromise, types.address), c->promiseConstant(returnAddressPromise, types.address),
flags, flags,
trace, trace,
@ -3233,7 +3245,7 @@ Compiler::Operand* compileDirectInvoke(MyThread* t,
methodParameterFootprint(t, target)); methodParameterFootprint(t, target));
} }
} else { } else {
Compiler::Operand* address ir::Value* address
= (addressPromise = (addressPromise
? c->promiseConstant(addressPromise, types.address) ? c->promiseConstant(addressPromise, types.address)
: c->constant(methodAddress(t, target), types.address)); : c->constant(methodAddress(t, target), types.address));
@ -3253,7 +3265,7 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall)
{ {
unsigned rSize = resultSize(t, methodReturnCode(t, target)); unsigned rSize = resultSize(t, methodReturnCode(t, target));
Compiler::Operand* result = 0; ir::Value* result = 0;
// don't bother calling an empty method unless calling it might // don't bother calling an empty method unless calling it might
// cause the class to be initialized, which may have side effects // cause the class to be initialized, which may have side effects
@ -3319,9 +3331,12 @@ methodReferenceReturnCode(Thread* t, object reference)
return returnCode; return returnCode;
} }
void void compileReferenceInvoke(MyThread* t,
compileReferenceInvoke(MyThread* t, Frame* frame, Compiler::Operand* method, Frame* frame,
object reference, bool isStatic, bool tailCall) ir::Value* method,
object reference,
bool isStatic,
bool tailCall)
{ {
unsigned parameterFootprint unsigned parameterFootprint
= methodReferenceParameterFootprint(t, reference, isStatic); = methodReferenceParameterFootprint(t, reference, isStatic);
@ -3330,8 +3345,8 @@ compileReferenceInvoke(MyThread* t, Frame* frame, Compiler::Operand* method,
unsigned rSize = resultSize(t, returnCode); unsigned rSize = resultSize(t, returnCode);
Compiler::Operand* result = frame->c->stackCall ir::Value* result
(method, = frame->c->stackCall(method,
tailCall ? Compiler::TailJump : 0, tailCall ? Compiler::TailJump : 0,
frame->trace(0, 0), frame->trace(0, 0),
operandTypeForFieldCode(t, returnCode), operandTypeForFieldCode(t, returnCode),
@ -3369,9 +3384,11 @@ compileDirectReferenceInvoke(MyThread* t, Frame* frame, Thunk thunk,
tailCall); tailCall);
} }
void void compileAbstractInvoke(MyThread* t,
compileAbstractInvoke(MyThread* t, Frame* frame, Compiler::Operand* method, Frame* frame,
object target, bool tailCall) ir::Value* method,
object target,
bool tailCall)
{ {
unsigned parameterFootprint = methodParameterFootprint(t, target); unsigned parameterFootprint = methodParameterFootprint(t, target);
ir::Types types(TargetBytesPerWord); ir::Types types(TargetBytesPerWord);
@ -3380,8 +3397,8 @@ compileAbstractInvoke(MyThread* t, Frame* frame, Compiler::Operand* method,
unsigned rSize = resultSize(t, returnCode); unsigned rSize = resultSize(t, returnCode);
Compiler::Operand* result = frame->c->stackCall ir::Value* result
(method, = frame->c->stackCall(method,
tailCall ? Compiler::TailJump : 0, tailCall ? Compiler::TailJump : 0,
frame->trace(0, 0), frame->trace(0, 0),
operandTypeForFieldCode(t, returnCode), operandTypeForFieldCode(t, returnCode),
@ -3422,7 +3439,7 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function)
object method = frame->context->method; object method = frame->context->method;
if (methodFlags(t, method) & ACC_SYNCHRONIZED) { if (methodFlags(t, method) & ACC_SYNCHRONIZED) {
Compiler::Operand* lock; ir::Value* lock;
if (methodFlags(t, method) & ACC_STATIC) { if (methodFlags(t, method) & ACC_STATIC) {
PROTECT(t, method); PROTECT(t, method);
@ -3601,8 +3618,8 @@ bool integerBranch(MyThread* t,
object code, object code,
unsigned& ip, unsigned& ip,
ir::Type type, ir::Type type,
Compiler::Operand* a, ir::Value* a,
Compiler::Operand* b, ir::Value* b,
unsigned* newIpp) unsigned* newIpp)
{ {
if (ip + 3 > codeLength(t, code)) { if (ip + 3 > codeLength(t, code)) {
@ -3615,7 +3632,7 @@ bool integerBranch(MyThread* t,
uint32_t newIp = (ip - 3) + offset; uint32_t newIp = (ip - 3) + offset;
assert(t, newIp < codeLength(t, code)); assert(t, newIp < codeLength(t, code));
Compiler::Operand* target = frame->machineIp(newIp); ir::Value* target = frame->machineIp(newIp);
switch (instruction) { switch (instruction) {
case ifeq: case ifeq:
@ -3680,8 +3697,8 @@ bool floatBranch(MyThread* t,
unsigned& ip, unsigned& ip,
ir::Type type, ir::Type type,
bool lessIfUnordered, bool lessIfUnordered,
Compiler::Operand* a, ir::Value* a,
Compiler::Operand* b, ir::Value* b,
unsigned* newIpp) unsigned* newIpp)
{ {
if (ip + 3 > codeLength(t, code)) { if (ip + 3 > codeLength(t, code)) {
@ -3694,7 +3711,7 @@ bool floatBranch(MyThread* t,
uint32_t newIp = (ip - 3) + offset; uint32_t newIp = (ip - 3) + offset;
assert(t, newIp < codeLength(t, code)); assert(t, newIp < codeLength(t, code));
Compiler::Operand* target = frame->machineIp(newIp); ir::Value* target = frame->machineIp(newIp);
switch (instruction) { switch (instruction) {
case ifeq: case ifeq:
@ -3719,8 +3736,7 @@ bool floatBranch(MyThread* t,
return true; return true;
} }
Compiler::Operand* ir::Value* popLongAddress(Frame* frame)
popLongAddress(Frame* frame)
{ {
ir::Types types(TargetBytesPerWord); ir::Types types(TargetBytesPerWord);
return TargetBytesPerWord == 8 ? frame->popLong() return TargetBytesPerWord == 8 ? frame->popLong()
@ -3766,7 +3782,7 @@ intrinsic(MyThread* t, Frame* frame, object target)
if (MATCH(methodName(t, target), "getByte") if (MATCH(methodName(t, target), "getByte")
and MATCH(methodSpec(t, target), "(J)B")) and MATCH(methodSpec(t, target), "(J)B"))
{ {
Compiler::Operand* address = popLongAddress(frame); ir::Value* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
frame->pushInt(c->load(ir::SignExtend, frame->pushInt(c->load(ir::SignExtend,
types.i1, types.i1,
@ -3776,8 +3792,8 @@ intrinsic(MyThread* t, Frame* frame, object target)
} else if (MATCH(methodName(t, target), "putByte") } else if (MATCH(methodName(t, target), "putByte")
and MATCH(methodSpec(t, target), "(JB)V")) and MATCH(methodSpec(t, target), "(JB)V"))
{ {
Compiler::Operand* value = frame->popInt(); ir::Value* value = frame->popInt();
Compiler::Operand* address = popLongAddress(frame); ir::Value* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
c->store(types.address, value, c->memory(address, types.i1)); c->store(types.address, value, c->memory(address, types.i1));
return true; return true;
@ -3786,7 +3802,7 @@ intrinsic(MyThread* t, Frame* frame, object target)
or (MATCH(methodName(t, target), "getChar") or (MATCH(methodName(t, target), "getChar")
and MATCH(methodSpec(t, target), "(J)C"))) and MATCH(methodSpec(t, target), "(J)C")))
{ {
Compiler::Operand* address = popLongAddress(frame); ir::Value* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
frame->pushInt(c->load(ir::SignExtend, frame->pushInt(c->load(ir::SignExtend,
types.i2, types.i2,
@ -3798,8 +3814,8 @@ intrinsic(MyThread* t, Frame* frame, object target)
or (MATCH(methodName(t, target), "putChar") or (MATCH(methodName(t, target), "putChar")
and MATCH(methodSpec(t, target), "(JC)V"))) and MATCH(methodSpec(t, target), "(JC)V")))
{ {
Compiler::Operand* value = frame->popInt(); ir::Value* value = frame->popInt();
Compiler::Operand* address = popLongAddress(frame); ir::Value* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
c->store(types.address, value, c->memory(address, types.i2)); c->store(types.address, value, c->memory(address, types.i2));
return true; return true;
@ -3808,7 +3824,7 @@ intrinsic(MyThread* t, Frame* frame, object target)
or (MATCH(methodName(t, target), "getFloat") or (MATCH(methodName(t, target), "getFloat")
and MATCH(methodSpec(t, target), "(J)F"))) and MATCH(methodSpec(t, target), "(J)F")))
{ {
Compiler::Operand* address = popLongAddress(frame); ir::Value* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
frame->pushInt( frame->pushInt(
c->load(ir::SignExtend, c->load(ir::SignExtend,
@ -3823,8 +3839,8 @@ intrinsic(MyThread* t, Frame* frame, object target)
or (MATCH(methodName(t, target), "putFloat") or (MATCH(methodName(t, target), "putFloat")
and MATCH(methodSpec(t, target), "(JF)V"))) and MATCH(methodSpec(t, target), "(JF)V")))
{ {
Compiler::Operand* value = frame->popInt(); ir::Value* value = frame->popInt();
Compiler::Operand* address = popLongAddress(frame); ir::Value* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
ir::Type type = MATCH(methodName(t, target), "putInt") ? types.i4 ir::Type type = MATCH(methodName(t, target), "putInt") ? types.i4
: types.f4; : types.f4;
@ -3835,7 +3851,7 @@ intrinsic(MyThread* t, Frame* frame, object target)
or (MATCH(methodName(t, target), "getDouble") or (MATCH(methodName(t, target), "getDouble")
and MATCH(methodSpec(t, target), "(J)D"))) and MATCH(methodSpec(t, target), "(J)D")))
{ {
Compiler::Operand* address = popLongAddress(frame); ir::Value* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
frame->pushLong( frame->pushLong(
c->load(ir::SignExtend, c->load(ir::SignExtend,
@ -3850,8 +3866,8 @@ intrinsic(MyThread* t, Frame* frame, object target)
or (MATCH(methodName(t, target), "putDouble") or (MATCH(methodName(t, target), "putDouble")
and MATCH(methodSpec(t, target), "(JD)V"))) and MATCH(methodSpec(t, target), "(JD)V")))
{ {
Compiler::Operand* value = frame->popLong(); ir::Value* value = frame->popLong();
Compiler::Operand* address = popLongAddress(frame); ir::Value* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
ir::Type type = MATCH(methodName(t, target), "putLong") ? types.i8 ir::Type type = MATCH(methodName(t, target), "putLong") ? types.i8
: types.f8; : types.f8;
@ -3860,7 +3876,7 @@ intrinsic(MyThread* t, Frame* frame, object target)
} else if (MATCH(methodName(t, target), "getAddress") } else if (MATCH(methodName(t, target), "getAddress")
and MATCH(methodSpec(t, target), "(J)J")) and MATCH(methodSpec(t, target), "(J)J"))
{ {
Compiler::Operand* address = popLongAddress(frame); ir::Value* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
frame->pushLong(c->load(ir::SignExtend, frame->pushLong(c->load(ir::SignExtend,
types.address, types.address,
@ -3870,8 +3886,8 @@ intrinsic(MyThread* t, Frame* frame, object target)
} else if (MATCH(methodName(t, target), "putAddress") } else if (MATCH(methodName(t, target), "putAddress")
and MATCH(methodSpec(t, target), "(JJ)V")) and MATCH(methodSpec(t, target), "(JJ)V"))
{ {
Compiler::Operand* value = frame->popLong(); ir::Value* value = frame->popLong();
Compiler::Operand* address = popLongAddress(frame); ir::Value* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
c->store(types.i8, value, c->memory(address, types.address)); c->store(types.i8, value, c->memory(address, types.address));
return true; return true;
@ -3949,11 +3965,11 @@ class SwitchState {
SwitchState(Compiler::State* state, SwitchState(Compiler::State* state,
unsigned count, unsigned count,
unsigned defaultIp, unsigned defaultIp,
Compiler::Operand* key, ir::Value* key,
avian::codegen::Promise* start, avian::codegen::Promise* start,
int bottom, int bottom,
int top): int top)
state(state), : state(state),
count(count), count(count),
defaultIp(defaultIp), defaultIp(defaultIp),
key(key), key(key),
@ -3976,7 +3992,7 @@ class SwitchState {
Compiler::State* state; Compiler::State* state;
unsigned count; unsigned count;
unsigned defaultIp; unsigned defaultIp;
Compiler::Operand* key; ir::Value* key;
avian::codegen::Promise* start; avian::codegen::Promise* start;
int bottom; int bottom;
int top; int top;
@ -4102,8 +4118,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case iaload: case iaload:
case laload: case laload:
case saload: { case saload: {
Compiler::Operand* index = frame->popInt(); ir::Value* index = frame->popInt();
Compiler::Operand* array = frame->popObject(); ir::Value* array = frame->popObject();
if (inTryBlock(t, code, ip - 1)) { if (inTryBlock(t, code, ip - 1)) {
c->saveLocals(); c->saveLocals();
@ -4189,7 +4205,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case iastore: case iastore:
case lastore: case lastore:
case sastore: { case sastore: {
Compiler::Operand* value; ir::Value* value;
if (instruction == dastore or instruction == lastore) { if (instruction == dastore or instruction == lastore) {
value = frame->popLong(); value = frame->popLong();
} else if (instruction == aastore) { } else if (instruction == aastore) {
@ -4198,8 +4214,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
value = frame->popInt(); value = frame->popInt();
} }
Compiler::Operand* index = frame->popInt(); ir::Value* index = frame->popInt();
Compiler::Operand* array = frame->popObject(); ir::Value* array = frame->popObject();
if (inTryBlock(t, code, ip - 1)) { if (inTryBlock(t, code, ip - 1)) {
c->saveLocals(); c->saveLocals();
@ -4303,7 +4319,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
object class_ = resolveClassInPool(t, context->method, index - 1, false); object class_ = resolveClassInPool(t, context->method, index - 1, false);
Compiler::Operand* length = frame->popInt(); ir::Value* length = frame->popInt();
object argument; object argument;
Thunk thunk; Thunk thunk;
@ -4359,7 +4375,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
break; break;
case athrow: { case athrow: {
Compiler::Operand* target = frame->popObject(); ir::Value* target = frame->popObject();
c->call(c->constant(getThunk(t, throw_Thunk), types.address), c->call(c->constant(getThunk(t, throw_Thunk), types.address),
Compiler::NoReturn, Compiler::NoReturn,
frame->trace(0, 0), frame->trace(0, 0),
@ -4396,7 +4412,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
thunk = checkCastFromReferenceThunk; thunk = checkCastFromReferenceThunk;
} }
Compiler::Operand* instance = c->peek(1, 0); ir::Value* instance = c->peek(1, 0);
c->call(c->constant(getThunk(t, thunk), types.address), c->call(c->constant(getThunk(t, thunk), types.address),
0, 0,
@ -4425,16 +4441,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case dmul: case dmul:
case ddiv: case ddiv:
case vm::drem: { case vm::drem: {
Compiler::Operand* a = frame->popLong(); ir::Value* a = frame->popLong();
Compiler::Operand* b = frame->popLong(); ir::Value* b = frame->popLong();
frame->pushLong( frame->pushLong(
c->binaryOp(toCompilerBinaryOp(t, instruction), types.f8, a, b)); c->binaryOp(toCompilerBinaryOp(t, instruction), types.f8, a, b));
} break; } break;
case dcmpg: { case dcmpg: {
Compiler::Operand* a = frame->popLong(); ir::Value* a = frame->popLong();
Compiler::Operand* b = frame->popLong(); ir::Value* b = frame->popLong();
if (floatBranch(t, frame, code, ip, types.f8, false, a, b, &newIp)) { if (floatBranch(t, frame, code, ip, types.f8, false, a, b, &newIp)) {
goto branch; goto branch;
@ -4445,16 +4461,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
0, 0,
types.i4, types.i4,
4, 4,
static_cast<Compiler::Operand*>(0), static_cast<ir::Value*>(0),
a, a,
static_cast<Compiler::Operand*>(0), static_cast<ir::Value*>(0),
b)); b));
} }
} break; } break;
case dcmpl: { case dcmpl: {
Compiler::Operand* a = frame->popLong(); ir::Value* a = frame->popLong();
Compiler::Operand* b = frame->popLong(); ir::Value* b = frame->popLong();
if (floatBranch(t, frame, code, ip, types.f8, true, a, b, &newIp)) { if (floatBranch(t, frame, code, ip, types.f8, true, a, b, &newIp)) {
goto branch; goto branch;
@ -4465,9 +4481,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
0, 0,
types.i4, types.i4,
4, 4,
static_cast<Compiler::Operand*>(0), static_cast<ir::Value*>(0),
a, a,
static_cast<Compiler::Operand*>(0), static_cast<ir::Value*>(0),
b)); b));
} }
} break; } break;
@ -4525,16 +4541,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case fmul: case fmul:
case fdiv: case fdiv:
case frem: { case frem: {
Compiler::Operand* a = frame->popInt(); ir::Value* a = frame->popInt();
Compiler::Operand* b = frame->popInt(); ir::Value* b = frame->popInt();
frame->pushInt( frame->pushInt(
c->binaryOp(toCompilerBinaryOp(t, instruction), types.f4, a, b)); c->binaryOp(toCompilerBinaryOp(t, instruction), types.f4, a, b));
} break; } break;
case fcmpg: { case fcmpg: {
Compiler::Operand* a = frame->popInt(); ir::Value* a = frame->popInt();
Compiler::Operand* b = frame->popInt(); ir::Value* b = frame->popInt();
if (floatBranch(t, frame, code, ip, types.f4, false, a, b, &newIp)) { if (floatBranch(t, frame, code, ip, types.f4, false, a, b, &newIp)) {
goto branch; goto branch;
@ -4551,8 +4567,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} break; } break;
case fcmpl: { case fcmpl: {
Compiler::Operand* a = frame->popInt(); ir::Value* a = frame->popInt();
Compiler::Operand* b = frame->popInt(); ir::Value* b = frame->popInt();
if (floatBranch(t, frame, code, ip, types.f4, true, a, b, &newIp)) { if (floatBranch(t, frame, code, ip, types.f4, true, a, b, &newIp)) {
goto branch; goto branch;
@ -4613,7 +4629,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
frame->append(field)); frame->append(field));
} }
Compiler::Operand* table; ir::Value* table;
if (instruction == getstatic) { if (instruction == getstatic) {
checkField(t, field, true); checkField(t, field, true);
@ -4737,7 +4753,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
ir::Type rType = operandTypeForFieldCode(t, fieldCode); ir::Type rType = operandTypeForFieldCode(t, fieldCode);
Compiler::Operand* result; ir::Value* result;
if (instruction == getstatic) { if (instruction == getstatic) {
result = c->call( result = c->call(
c->constant(getThunk(t, getStaticFieldValueFromReferenceThunk), c->constant(getThunk(t, getStaticFieldValueFromReferenceThunk),
@ -4749,7 +4765,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
c->threadRegister(), c->threadRegister(),
frame->append(pair)); frame->append(pair));
} else { } else {
Compiler::Operand* instance = frame->popObject(); ir::Value* instance = frame->popObject();
result = c->call( result = c->call(
c->constant(getThunk(t, getFieldValueFromReferenceThunk), c->constant(getThunk(t, getFieldValueFromReferenceThunk),
@ -4830,8 +4846,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case isub: case isub:
case ixor: case ixor:
case imul: { case imul: {
Compiler::Operand* a = frame->popInt(); ir::Value* a = frame->popInt();
Compiler::Operand* b = frame->popInt(); ir::Value* b = frame->popInt();
frame->pushInt( frame->pushInt(
c->binaryOp(toCompilerBinaryOp(t, instruction), types.i4, a, b)); c->binaryOp(toCompilerBinaryOp(t, instruction), types.i4, a, b));
} break; } break;
@ -4865,8 +4881,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
break; break;
case idiv: { case idiv: {
Compiler::Operand* a = frame->popInt(); ir::Value* a = frame->popInt();
Compiler::Operand* b = frame->popInt(); ir::Value* b = frame->popInt();
if (inTryBlock(t, code, ip - 1)) { if (inTryBlock(t, code, ip - 1)) {
c->saveLocals(); c->saveLocals();
@ -4886,9 +4902,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
compileSafePoint(t, c, frame); compileSafePoint(t, c, frame);
} }
Compiler::Operand* a = frame->popObject(); ir::Value* a = frame->popObject();
Compiler::Operand* b = frame->popObject(); ir::Value* b = frame->popObject();
Compiler::Operand* target = frame->machineIp(newIp); ir::Value* target = frame->machineIp(newIp);
c->condJump(toCompilerJumpOp(t, instruction), types.object, a, b, target); c->condJump(toCompilerJumpOp(t, instruction), types.object, a, b, target);
} goto branch; } goto branch;
@ -4907,9 +4923,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
compileSafePoint(t, c, frame); compileSafePoint(t, c, frame);
} }
Compiler::Operand* a = frame->popInt(); ir::Value* a = frame->popInt();
Compiler::Operand* b = frame->popInt(); ir::Value* b = frame->popInt();
Compiler::Operand* target = frame->machineIp(newIp); ir::Value* target = frame->machineIp(newIp);
c->condJump(toCompilerJumpOp(t, instruction), types.i4, a, b, target); c->condJump(toCompilerJumpOp(t, instruction), types.i4, a, b, target);
} goto branch; } goto branch;
@ -4924,14 +4940,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
newIp = (ip - 3) + offset; newIp = (ip - 3) + offset;
assert(t, newIp < codeLength(t, code)); assert(t, newIp < codeLength(t, code));
Compiler::Operand* target = frame->machineIp(newIp); ir::Value* target = frame->machineIp(newIp);
if(newIp <= ip) { if(newIp <= ip) {
compileSafePoint(t, c, frame); compileSafePoint(t, c, frame);
} }
Compiler::Operand* a = c->constant(0, types.i4); ir::Value* a = c->constant(0, types.i4);
Compiler::Operand* b = frame->popInt(); ir::Value* b = frame->popInt();
c->condJump(toCompilerJumpOp(t, instruction), types.i4, a, b, target); c->condJump(toCompilerJumpOp(t, instruction), types.i4, a, b, target);
} goto branch; } goto branch;
@ -4946,9 +4962,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
compileSafePoint(t, c, frame); compileSafePoint(t, c, frame);
} }
Compiler::Operand* a = c->constant(0, types.object); ir::Value* a = c->constant(0, types.object);
Compiler::Operand* b = frame->popObject(); ir::Value* b = frame->popObject();
Compiler::Operand* target = frame->machineIp(newIp); ir::Value* target = frame->machineIp(newIp);
c->condJump(toCompilerJumpOp(t, instruction), types.object, a, b, target); c->condJump(toCompilerJumpOp(t, instruction), types.object, a, b, target);
} goto branch; } goto branch;
@ -5005,7 +5021,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
object class_ = resolveClassInPool(t, context->method, index - 1, false); object class_ = resolveClassInPool(t, context->method, index - 1, false);
Compiler::Operand* instance = frame->popObject(); ir::Value* instance = frame->popObject();
object argument; object argument;
Thunk thunk; Thunk thunk;
@ -5065,7 +5081,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
unsigned rSize = resultSize(t, returnCode); unsigned rSize = resultSize(t, returnCode);
Compiler::Operand* result ir::Value* result
= c->stackCall(c->call(c->constant(getThunk(t, thunk), types.address), = c->stackCall(c->call(c->constant(getThunk(t, thunk), types.address),
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
@ -5171,11 +5187,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
unsigned offset = TargetClassVtable unsigned offset = TargetClassVtable
+ (methodOffset(t, target) * TargetBytesPerWord); + (methodOffset(t, target) * TargetBytesPerWord);
Compiler::Operand* instance = c->peek(1, parameterFootprint - 1); ir::Value* instance = c->peek(1, parameterFootprint - 1);
unsigned rSize = resultSize(t, methodReturnCode(t, target)); unsigned rSize = resultSize(t, methodReturnCode(t, target));
Compiler::Operand* result = c->stackCall( ir::Value* result = c->stackCall(
c->memory(c->binaryOp(lir::And, c->memory(c->binaryOp(lir::And,
types.address, types.address,
c->constant(TargetPointerMask, types.i4), c->constant(TargetPointerMask, types.i4),
@ -5227,8 +5243,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} break; } break;
case irem: { case irem: {
Compiler::Operand* a = frame->popInt(); ir::Value* a = frame->popInt();
Compiler::Operand* b = frame->popInt(); ir::Value* b = frame->popInt();
if (inTryBlock(t, code, ip - 1)) { if (inTryBlock(t, code, ip - 1)) {
c->saveLocals(); c->saveLocals();
@ -5319,15 +5335,15 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case lsub: case lsub:
case lxor: case lxor:
case lmul: { case lmul: {
Compiler::Operand* a = frame->popLong(); ir::Value* a = frame->popLong();
Compiler::Operand* b = frame->popLong(); ir::Value* b = frame->popLong();
frame->pushLong( frame->pushLong(
c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b)); c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b));
} break; } break;
case lcmp: { case lcmp: {
Compiler::Operand* a = frame->popLong(); ir::Value* a = frame->popLong();
Compiler::Operand* b = frame->popLong(); ir::Value* b = frame->popLong();
if (integerBranch(t, frame, code, ip, types.i8, a, b, &newIp)) { if (integerBranch(t, frame, code, ip, types.i8, a, b, &newIp)) {
goto branch; goto branch;
@ -5338,9 +5354,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
0, 0,
types.i4, types.i4,
4, 4,
static_cast<Compiler::Operand*>(0), static_cast<ir::Value*>(0),
a, a,
static_cast<Compiler::Operand*>(0), static_cast<ir::Value*>(0),
b)); b));
} }
} break; } break;
@ -5425,8 +5441,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} break; } break;
case ldiv_: { case ldiv_: {
Compiler::Operand* a = frame->popLong(); ir::Value* a = frame->popLong();
Compiler::Operand* b = frame->popLong(); ir::Value* b = frame->popLong();
if (inTryBlock(t, code, ip - 1)) { if (inTryBlock(t, code, ip - 1)) {
c->saveLocals(); c->saveLocals();
@ -5470,7 +5486,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
ip = (ip + 3) & ~3; // pad to four byte boundary ip = (ip + 3) & ~3; // pad to four byte boundary
Compiler::Operand* key = frame->popInt(); ir::Value* key = frame->popInt();
uint32_t defaultIp = base + codeReadInt32(t, code, ip); uint32_t defaultIp = base + codeReadInt32(t, code, ip);
assert(t, defaultIp < codeLength(t, code)); assert(t, defaultIp < codeLength(t, code));
@ -5478,8 +5494,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
int32_t pairCount = codeReadInt32(t, code, ip); int32_t pairCount = codeReadInt32(t, code, ip);
if (pairCount) { if (pairCount) {
Compiler::Operand* default_ = frame->addressOperand ir::Value* default_ = frame->addressOperand(
(frame->addressPromise(c->machineIp(defaultIp))); frame->addressPromise(c->machineIp(defaultIp)));
avian::codegen::Promise* start = 0; avian::codegen::Promise* start = 0;
uint32_t* ipTable = static_cast<uint32_t*> uint32_t* ipTable = static_cast<uint32_t*>
@ -5501,7 +5517,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} }
assert(t, start); assert(t, start);
Compiler::Operand* address = c->call( ir::Value* address = c->call(
c->constant(getThunk(t, lookUpAddressThunk), types.address), c->constant(getThunk(t, lookUpAddressThunk), types.address),
0, 0,
0, 0,
@ -5533,8 +5549,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} break; } break;
case lrem: { case lrem: {
Compiler::Operand* a = frame->popLong(); ir::Value* a = frame->popLong();
Compiler::Operand* b = frame->popLong(); ir::Value* b = frame->popLong();
if (inTryBlock(t, code, ip - 1)) { if (inTryBlock(t, code, ip - 1)) {
c->saveLocals(); c->saveLocals();
@ -5558,8 +5574,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case lshl: case lshl:
case lshr: case lshr:
case lushr: { case lushr: {
Compiler::Operand* a = frame->popInt(); ir::Value* a = frame->popInt();
Compiler::Operand* b = frame->popLong(); ir::Value* b = frame->popLong();
frame->pushLong( frame->pushLong(
c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b)); c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b));
} break; } break;
@ -5590,7 +5606,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
break; break;
case monitorenter: { case monitorenter: {
Compiler::Operand* target = frame->popObject(); ir::Value* target = frame->popObject();
c->call( c->call(
c->constant(getThunk(t, acquireMonitorForObjectThunk), types.address), c->constant(getThunk(t, acquireMonitorForObjectThunk), types.address),
0, 0,
@ -5602,7 +5618,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} break; } break;
case monitorexit: { case monitorexit: {
Compiler::Operand* target = frame->popObject(); ir::Value* target = frame->popObject();
c->call( c->call(
c->constant(getThunk(t, releaseMonitorForObjectThunk), types.address), c->constant(getThunk(t, releaseMonitorForObjectThunk), types.address),
0, 0,
@ -5639,7 +5655,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
(t, localSize(t, context->method) + c->topOfStack(), context->method) (t, localSize(t, context->method) + c->topOfStack(), context->method)
+ t->arch->frameReturnAddressSize(); + t->arch->frameReturnAddressSize();
Compiler::Operand* result ir::Value* result
= c->call(c->constant(getThunk(t, thunk), types.address), = c->call(c->constant(getThunk(t, thunk), types.address),
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
@ -5690,7 +5706,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case newarray: { case newarray: {
uint8_t type = codeBody(t, code, ip++); uint8_t type = codeBody(t, code, ip++);
Compiler::Operand* length = frame->popInt(); ir::Value* length = frame->popInt();
frame->pushObject( frame->pushObject(
c->call(c->constant(getThunk(t, makeBlankArrayThunk), types.address), c->call(c->constant(getThunk(t, makeBlankArrayThunk), types.address),
@ -5773,9 +5789,9 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} }
} }
Compiler::Operand* value = popField(t, frame, fieldCode); ir::Value* value = popField(t, frame, fieldCode);
Compiler::Operand* table; ir::Value* table;
if (instruction == putstatic) { if (instruction == putstatic) {
PROTECT(t, field); PROTECT(t, field);
@ -5877,7 +5893,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
int fieldCode = vm::fieldCode int fieldCode = vm::fieldCode
(t, byteArrayBody(t, referenceSpec(t, reference), 0)); (t, byteArrayBody(t, referenceSpec(t, reference), 0));
Compiler::Operand* value = popField(t, frame, fieldCode); ir::Value* value = popField(t, frame, fieldCode);
ir::Type rType = operandTypeForFieldCode(t, fieldCode); ir::Type rType = operandTypeForFieldCode(t, fieldCode);
object pair = makePair(t, context->method, reference); object pair = makePair(t, context->method, reference);
@ -5901,7 +5917,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
frame->append(pair), frame->append(pair),
value); value);
} else { } else {
Compiler::Operand* instance = frame->popObject(); ir::Value* instance = frame->popObject();
c->call(c->constant(getThunk(t, setFieldValueFromReferenceThunk), c->call(c->constant(getThunk(t, setFieldValueFromReferenceThunk),
types.address), types.address),
@ -5928,10 +5944,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
4, 4,
c->threadRegister(), c->threadRegister(),
frame->append(pair), frame->append(pair),
static_cast<Compiler::Operand*>(0), static_cast<ir::Value*>(0),
value); value);
} else { } else {
Compiler::Operand* instance = frame->popObject(); ir::Value* instance = frame->popObject();
c->call( c->call(
c->constant(getThunk(t, setLongFieldValueFromReferenceThunk), c->constant(getThunk(t, setLongFieldValueFromReferenceThunk),
@ -5943,7 +5959,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
c->threadRegister(), c->threadRegister(),
frame->append(pair), frame->append(pair),
instance, instance,
static_cast<Compiler::Operand*>(0), static_cast<ir::Value*>(0),
value); value);
} }
} break; } break;
@ -5962,7 +5978,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
frame->append(pair), frame->append(pair),
value); value);
} else { } else {
Compiler::Operand* instance = frame->popObject(); ir::Value* instance = frame->popObject();
c->call( c->call(
c->constant(getThunk(t, setObjectFieldValueFromReferenceThunk), c->constant(getThunk(t, setObjectFieldValueFromReferenceThunk),
@ -6036,7 +6052,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} }
assert(t, start); assert(t, start);
Compiler::Operand* key = frame->popInt(); ir::Value* key = frame->popInt();
c->condJump(lir::JumpIfLess, c->condJump(lir::JumpIfLess,
types.i4, types.i4,
@ -6151,15 +6167,14 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
c->restoreState(s->state); c->restoreState(s->state);
Compiler::Operand* normalizedKey ir::Value* normalizedKey
= (s->bottom ? c->binaryOp(lir::Subtract, = (s->bottom ? c->binaryOp(lir::Subtract,
types.i4, types.i4,
c->constant(s->bottom, types.i4), c->constant(s->bottom, types.i4),
s->key) s->key)
: s->key); : s->key);
Compiler::Operand* entry ir::Value* entry = c->memory(frame->absoluteAddressOperand(s->start),
= c->memory(frame->absoluteAddressOperand(s->start),
types.address, types.address,
0, 0,
normalizedKey); normalizedKey);