merge Compiler::load and Compiler::loadz

This commit is contained in:
Joshua Warner 2014-05-01 11:13:52 -06:00
parent 85f114ea0f
commit 99fa560257
4 changed files with 80 additions and 62 deletions

View File

@ -110,14 +110,11 @@ class Compiler {
virtual void store(ir::Type srcType, virtual void store(ir::Type srcType,
Operand* src, Operand* src,
Operand* dst) = 0; Operand* dst) = 0;
virtual Operand* load(ir::Type srcType, virtual Operand* load(ir::SignExtendMode signExtend,
ir::Type srcType,
ir::Type srcSelectType, ir::Type srcSelectType,
Operand* src, Operand* src,
ir::Type dstType) = 0; ir::Type dstType) = 0;
virtual Operand* loadz(ir::Type srcType,
ir::Type srcSelectType,
Operand* src,
ir::Type dstType) = 0;
virtual void condJump(lir::TernaryOperation op, virtual void condJump(lir::TernaryOperation op,
unsigned size, unsigned size,

View File

@ -113,6 +113,8 @@ class Types {
} }
}; };
enum SignExtendMode { SignExtend, ZeroExtend };
} // namespace ir } // namespace ir
} // namespace codegen } // namespace codegen
} // namespace avian } // namespace avian

View File

@ -2627,7 +2627,8 @@ class MyCompiler: public Compiler {
static_cast<Value*>(dst)); static_cast<Value*>(dst));
} }
virtual Operand* load(ir::Type srcType, virtual Operand* load(ir::SignExtendMode signExtend,
ir::Type srcType,
ir::Type srcSelectType, ir::Type srcSelectType,
Operand* src, Operand* src,
ir::Type dstType) ir::Type dstType)
@ -2638,27 +2639,7 @@ class MyCompiler: public Compiler {
Value* dst = value(&c, static_cast<Value*>(src)->type); Value* dst = value(&c, static_cast<Value*>(src)->type);
appendMove(&c, appendMove(&c,
lir::Move, signExtend == ir::SignExtend ? lir::Move : lir::MoveZ,
srcType.size(),
srcSelectType.size(),
static_cast<Value*>(src),
dstType.size(),
dst);
return dst;
}
virtual Operand* loadz(ir::Type srcType,
ir::Type srcSelectType,
Operand* src,
ir::Type dstType)
{
assert(&c, dstType.size() >= TargetBytesPerWord);
assert(&c, srcType.flavor() == srcSelectType.flavor());
assert(&c, srcType.flavor() == dstType.flavor());
Value* dst = value(&c, static_cast<Value*>(src)->type);
appendMove(&c,
lir::MoveZ,
srcType.size(), srcType.size(),
srcSelectType.size(), srcSelectType.size(),
static_cast<Value*>(src), static_cast<Value*>(src),

View File

@ -3713,10 +3713,12 @@ Compiler::Operand*
popLongAddress(Frame* frame) popLongAddress(Frame* frame)
{ {
ir::Types types(TargetBytesPerWord); ir::Types types(TargetBytesPerWord);
return TargetBytesPerWord == 8 return TargetBytesPerWord == 8 ? frame->popLong()
? frame->popLong() : frame->c->load(ir::SignExtend,
: frame->c->load( types.i8,
types.i8, types.i8, frame->popLong(), types.address); types.i8,
frame->popLong(),
types.address);
} }
bool bool
@ -3757,8 +3759,11 @@ intrinsic(MyThread* t, Frame* frame, object target)
{ {
Compiler::Operand* address = popLongAddress(frame); Compiler::Operand* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
frame->pushInt(c->load( frame->pushInt(c->load(ir::SignExtend,
types.i1, types.i1, c->memory(address, types.i1), types.address)); types.i1,
types.i1,
c->memory(address, types.i1),
types.address));
return true; return true;
} 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"))
@ -3775,8 +3780,11 @@ intrinsic(MyThread* t, Frame* frame, object target)
{ {
Compiler::Operand* address = popLongAddress(frame); Compiler::Operand* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
frame->pushInt(c->load( frame->pushInt(c->load(ir::SignExtend,
types.i2, types.i2, c->memory(address, types.i2), types.address)); types.i2,
types.i2,
c->memory(address, types.i2),
types.address));
return true; return true;
} else if ((MATCH(methodName(t, target), "putShort") } else if ((MATCH(methodName(t, target), "putShort")
and MATCH(methodSpec(t, target), "(JS)V")) and MATCH(methodSpec(t, target), "(JS)V"))
@ -3796,7 +3804,8 @@ intrinsic(MyThread* t, Frame* frame, object target)
Compiler::Operand* address = popLongAddress(frame); Compiler::Operand* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
frame->pushInt( frame->pushInt(
c->load(types.i4, c->load(ir::SignExtend,
types.i4,
types.i4, types.i4,
c->memory(address, c->memory(address,
MATCH(methodName(t, target), "getInt") ? types.i4 MATCH(methodName(t, target), "getInt") ? types.i4
@ -3823,7 +3832,8 @@ intrinsic(MyThread* t, Frame* frame, object target)
Compiler::Operand* address = popLongAddress(frame); Compiler::Operand* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
frame->pushLong( frame->pushLong(
c->load(types.i8, c->load(ir::SignExtend,
types.i8,
types.i8, types.i8,
c->memory(address, c->memory(address,
MATCH(methodName(t, target), "getLong") ? types.i8 MATCH(methodName(t, target), "getLong") ? types.i8
@ -3847,7 +3857,8 @@ intrinsic(MyThread* t, Frame* frame, object target)
{ {
Compiler::Operand* address = popLongAddress(frame); Compiler::Operand* address = popLongAddress(frame);
frame->popObject(); frame->popObject();
frame->pushLong(c->load(types.address, frame->pushLong(c->load(ir::SignExtend,
types.address,
types.address, types.address,
c->memory(address, types.address), c->memory(address, types.address),
types.i8)); types.i8));
@ -4102,7 +4113,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
switch (instruction) { switch (instruction) {
case aaload: case aaload:
frame->pushObject( frame->pushObject(
c->load(types.address, c->load(ir::SignExtend,
types.address,
types.address, types.address,
c->memory(array, types.object, TargetArrayBody, index), c->memory(array, types.object, TargetArrayBody, index),
types.address)); types.address));
@ -4110,7 +4122,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case faload: case faload:
frame->pushInt( frame->pushInt(
c->load(types.f4, c->load(ir::SignExtend,
types.f4,
types.f4, types.f4,
c->memory(array, types.f4, TargetArrayBody, index), c->memory(array, types.f4, TargetArrayBody, index),
types.f8)); types.f8));
@ -4118,7 +4131,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case iaload: case iaload:
frame->pushInt( frame->pushInt(
c->load(types.i4, c->load(ir::SignExtend,
types.i4,
types.i4, types.i4,
c->memory(array, types.i4, TargetArrayBody, index), c->memory(array, types.i4, TargetArrayBody, index),
types.address)); types.address));
@ -4126,7 +4140,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case baload: case baload:
frame->pushInt( frame->pushInt(
c->load(types.i1, c->load(ir::SignExtend,
types.i1,
types.i1, types.i1,
c->memory(array, types.i1, TargetArrayBody, index), c->memory(array, types.i1, TargetArrayBody, index),
types.address)); types.address));
@ -4134,15 +4149,17 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case caload: case caload:
frame->pushInt( frame->pushInt(
c->loadz(types.i2, c->load(ir::ZeroExtend,
types.i2, types.i2,
c->memory(array, types.i2, TargetArrayBody, index), types.i2,
types.address)); c->memory(array, types.i2, TargetArrayBody, index),
types.address));
break; break;
case daload: case daload:
frame->pushLong( frame->pushLong(
c->load(types.f8, c->load(ir::SignExtend,
types.f8,
types.f8, types.f8,
c->memory(array, types.f8, TargetArrayBody, index), c->memory(array, types.f8, TargetArrayBody, index),
types.f8)); types.f8));
@ -4150,7 +4167,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case laload: case laload:
frame->pushLong( frame->pushLong(
c->load(types.i8, c->load(ir::SignExtend,
types.i8,
types.i8, types.i8,
c->memory(array, types.i8, TargetArrayBody, index), c->memory(array, types.i8, TargetArrayBody, index),
types.i8)); types.i8));
@ -4158,7 +4176,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case saload: case saload:
frame->pushInt( frame->pushInt(
c->load(types.i2, c->load(ir::SignExtend,
types.i2,
types.i2, types.i2,
c->memory(array, types.i2, TargetArrayBody, index), c->memory(array, types.i2, TargetArrayBody, index),
types.address)); types.address));
@ -4317,7 +4336,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case arraylength: { case arraylength: {
frame->pushInt( frame->pushInt(
c->load(types.address, c->load(ir::SignExtend,
types.address,
types.address, types.address,
c->memory(frame->popObject(), types.i4, TargetArrayLength), c->memory(frame->popObject(), types.i4, TargetArrayLength),
types.address)); types.address));
@ -4631,6 +4651,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case ByteField: case ByteField:
case BooleanField: case BooleanField:
frame->pushInt(c->load( frame->pushInt(c->load(
ir::SignExtend,
types.i1, types.i1,
types.i1, types.i1,
c->memory(table, types.i4, targetFieldOffset(context, field)), c->memory(table, types.i4, targetFieldOffset(context, field)),
@ -4638,7 +4659,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
break; break;
case CharField: case CharField:
frame->pushInt(c->loadz( frame->pushInt(c->load(
ir::ZeroExtend,
types.i2, types.i2,
types.i2, types.i2,
c->memory(table, types.i4, targetFieldOffset(context, field)), c->memory(table, types.i4, targetFieldOffset(context, field)),
@ -4647,6 +4669,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case ShortField: case ShortField:
frame->pushInt(c->load( frame->pushInt(c->load(
ir::SignExtend,
types.i2, types.i2,
types.i2, types.i2,
c->memory(table, types.i4, targetFieldOffset(context, field)), c->memory(table, types.i4, targetFieldOffset(context, field)),
@ -4655,6 +4678,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case FloatField: case FloatField:
frame->pushInt(c->load( frame->pushInt(c->load(
ir::SignExtend,
types.f4, types.f4,
types.f4, types.f4,
c->memory(table, types.f4, targetFieldOffset(context, field)), c->memory(table, types.f4, targetFieldOffset(context, field)),
@ -4663,6 +4687,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case IntField: case IntField:
frame->pushInt(c->load( frame->pushInt(c->load(
ir::SignExtend,
types.i4, types.i4,
types.i4, types.i4,
c->memory(table, types.i4, targetFieldOffset(context, field)), c->memory(table, types.i4, targetFieldOffset(context, field)),
@ -4671,6 +4696,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case DoubleField: case DoubleField:
frame->pushLong(c->load( frame->pushLong(c->load(
ir::SignExtend,
types.f8, types.f8,
types.f8, types.f8,
c->memory(table, types.f8, targetFieldOffset(context, field)), c->memory(table, types.f8, targetFieldOffset(context, field)),
@ -4679,6 +4705,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case LongField: case LongField:
frame->pushLong(c->load( frame->pushLong(c->load(
ir::SignExtend,
types.i8, types.i8,
types.i8, types.i8,
c->memory(table, types.i8, targetFieldOffset(context, field)), c->memory(table, types.i8, targetFieldOffset(context, field)),
@ -4687,6 +4714,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case ObjectField: case ObjectField:
frame->pushObject(c->load( frame->pushObject(c->load(
ir::SignExtend,
types.address, types.address,
types.address, types.address,
c->memory(table, types.object, targetFieldOffset(context, field)), c->memory(table, types.object, targetFieldOffset(context, field)),
@ -4779,13 +4807,19 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} break; } break;
case i2b: { case i2b: {
frame->pushInt( frame->pushInt(c->load(ir::SignExtend,
c->load(types.address, types.i1, frame->popInt(), types.address)); types.address,
types.i1,
frame->popInt(),
types.address));
} break; } break;
case i2c: { case i2c: {
frame->pushInt( frame->pushInt(c->load(ir::ZeroExtend,
c->loadz(types.address, types.i2, frame->popInt(), types.address)); types.address,
types.i2,
frame->popInt(),
types.address));
} break; } break;
case i2d: { case i2d: {
@ -4797,13 +4831,16 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} break; } break;
case i2l: case i2l:
frame->pushLong( frame->pushLong(c->load(
c->load(types.address, types.i4, frame->popInt(), types.i8)); ir::SignExtend, types.address, types.i4, frame->popInt(), types.i8));
break; break;
case i2s: { case i2s: {
frame->pushInt( frame->pushInt(c->load(ir::SignExtend,
c->load(types.address, types.i2, frame->popInt(), types.address)); types.address,
types.i2,
frame->popInt(),
types.address));
} break; } break;
case iadd: case iadd:
@ -5294,8 +5331,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
} break; } break;
case l2i: case l2i:
frame->pushInt( frame->pushInt(c->load(
c->load(types.i8, types.i8, frame->popLong(), types.address)); ir::SignExtend, types.i8, types.i8, frame->popLong(), types.address));
break; break;
case ladd: case ladd:
@ -6149,7 +6186,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
0, 0,
normalizedKey); normalizedKey);
c->jmp(c->load(types.address, c->jmp(c->load(ir::SignExtend,
types.address,
types.address, types.address,
context->bootContext context->bootContext
? c->binaryOp(lir::Add, ? c->binaryOp(lir::Add,