use ir::Type in Compiler::unaryOp and Compiler::binaryOp

This commit is contained in:
Joshua Warner 2014-04-30 22:11:49 -06:00 committed by Joshua Warner
parent 6ed7681dc0
commit 2d444830d0
3 changed files with 114 additions and 62 deletions

View File

@ -117,15 +117,22 @@ class Compiler {
virtual Operand* loadz(unsigned size, unsigned srcSelectSize, Operand* src, virtual Operand* loadz(unsigned size, unsigned srcSelectSize, Operand* src,
unsigned dstSize) = 0; unsigned dstSize) = 0;
virtual void condJump(lir::TernaryOperation op,
virtual void condJump(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b, Operand* address) = 0; unsigned size,
Operand* a,
Operand* b,
Operand* address) = 0;
virtual void jmp(Operand* address) = 0; virtual void jmp(Operand* address) = 0;
virtual void exit(Operand* address) = 0; virtual void exit(Operand* address) = 0;
virtual Operand* binaryOp(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b) = 0; virtual Operand* binaryOp(lir::TernaryOperation op,
virtual Operand* unaryOp(lir::BinaryOperation type, unsigned size, Operand* a) = 0; ir::Type type,
virtual void nullaryOp(lir::Operation type) = 0; Operand* a,
Operand* b) = 0;
virtual Operand* unaryOp(lir::BinaryOperation op, ir::Type type, Operand* a)
= 0;
virtual void nullaryOp(lir::Operation op) = 0;
virtual Operand* f2f(ir::Type aType, ir::Type resType, Operand* a) = 0; virtual Operand* f2f(ir::Type aType, ir::Type resType, Operand* a) = 0;
virtual Operand* f2i(ir::Type aType, ir::Type resType, Operand* a) = 0; virtual Operand* f2i(ir::Type aType, ir::Type resType, Operand* a) = 0;

View File

@ -735,10 +735,14 @@ saveLocals(Context* c, Event* e)
} }
} }
void void maybeMove(Context* c,
maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, lir::BinaryOperation op,
unsigned srcSelectSize, Value* srcValue, unsigned dstSize, Value* dstValue, unsigned srcSize,
const SiteMask& dstMask) unsigned srcSelectSize,
Value* srcValue,
unsigned dstSize,
Value* dstValue,
const SiteMask& dstMask)
{ {
Read* read = live(c, dstValue); Read* read = live(c, dstValue);
bool isStore = read == 0; bool isStore = read == 0;
@ -790,8 +794,14 @@ maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize,
srcValue->source->freeze(c, srcValue); srcValue->source->freeze(c, srcValue);
apply(c, type, min(srcSelectSize, dstSize), srcValue->source, srcValue->source, apply(c,
dstSize, target, target); op,
min(srcSelectSize, dstSize),
srcValue->source,
srcValue->source,
dstSize,
target,
target);
srcValue->source->thaw(c, srcValue); srcValue->source->thaw(c, srcValue);
} else { } else {
@ -803,7 +813,7 @@ maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize,
bool thunk; bool thunk;
OperandMask src; OperandMask src;
c->arch->planSource(type, dstSize, src, dstSize, &thunk); c->arch->planSource(op, dstSize, src, dstSize, &thunk);
if (isGeneralValue(srcValue)) { if (isGeneralValue(srcValue)) {
src.registerMask &= c->regFile->generalRegisters.mask; src.registerMask &= c->regFile->generalRegisters.mask;
@ -828,8 +838,14 @@ maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize,
srcb, dstb, srcValue, dstValue); srcb, dstb, srcValue, dstValue);
} }
apply(c, type, srcSelectSize, srcValue->source, srcValue->source, apply(c,
dstSize, tmpTarget, tmpTarget); op,
srcSelectSize,
srcValue->source,
srcValue->source,
dstSize,
tmpTarget,
tmpTarget);
tmpTarget->thaw(c, dstValue); tmpTarget->thaw(c, dstValue);
@ -2610,15 +2626,22 @@ class MyCompiler: public Compiler {
return dst; return dst;
} }
virtual void condJump(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b, virtual void condJump(lir::TernaryOperation op,
Operand* address) unsigned size,
Operand* a,
Operand* b,
Operand* address)
{ {
assert(&c, assert(&c,
(isGeneralBranch(type) and isGeneralValue(a) and isGeneralValue(b)) (isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or(
or (isFloatBranch(type) and isFloatValue(a) and isFloatValue(b))); isFloatBranch(op) and isFloatValue(a) and isFloatValue(b)));
appendBranch(&c, type, size, static_cast<Value*>(a), appendBranch(&c,
static_cast<Value*>(b), static_cast<Value*>(address)); op,
size,
static_cast<Value*>(a),
static_cast<Value*>(b),
static_cast<Value*>(address));
} }
virtual void jmp(Operand* address) { virtual void jmp(Operand* address) {
@ -2629,23 +2652,36 @@ class MyCompiler: public Compiler {
appendJump(&c, lir::Jump, static_cast<Value*>(address), true); appendJump(&c, lir::Jump, static_cast<Value*>(address), true);
} }
virtual Operand* binaryOp(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b) { virtual Operand* binaryOp(lir::TernaryOperation op,
ir::Type type,
Operand* a,
Operand* b)
{
assert(&c, assert(&c,
(isGeneralBinaryOp(type) and isGeneralValue(a) and isGeneralValue(b)) (isGeneralBinaryOp(op) and isGeneralValue(a) and isGeneralValue(b))
or (isFloatBinaryOp(type) and isFloatValue(a) and isFloatValue(b))); or(isFloatBinaryOp(op) and isFloatValue(a) and isFloatValue(b)));
Value* result = value(&c, static_cast<Value*>(a)->type); Value* result = value(&c, static_cast<Value*>(a)->type);
appendCombine(&c, type, size, static_cast<Value*>(a), appendCombine(&c,
size, static_cast<Value*>(b), size, result); op,
type.size(),
static_cast<Value*>(a),
type.size(),
static_cast<Value*>(b),
type.size(),
result);
return result; return result;
} }
virtual Operand* unaryOp(lir::BinaryOperation type, unsigned size, Operand* a) { virtual Operand* unaryOp(lir::BinaryOperation op, ir::Type type, Operand* a)
assert(&c, (isGeneralUnaryOp(type) and isGeneralValue(a))or( {
isFloatUnaryOp(type) and isFloatValue(a))); assert(&c,
(isGeneralUnaryOp(op) and isGeneralValue(a))or(isFloatUnaryOp(op)
and isFloatValue(a)));
Value* result = value(&c, static_cast<Value*>(a)->type); Value* result = value(&c, static_cast<Value*>(a)->type);
appendTranslate(&c, type, size, static_cast<Value*>(a), size, result); appendTranslate(
&c, op, type.size(), static_cast<Value*>(a), type.size(), result);
return result; return result;
} }
@ -2699,8 +2735,9 @@ class MyCompiler: public Compiler {
return result; return result;
} }
virtual void nullaryOp(lir::Operation type) { virtual void nullaryOp(lir::Operation op)
appendOperation(&c, type); {
appendOperation(&c, op);
} }
virtual void compile(uintptr_t stackOverflowHandler, virtual void compile(uintptr_t stackOverflowHandler,

View File

@ -1411,7 +1411,7 @@ class Frame {
bc->constants = makeTriple(t, o, pointer, bc->constants); bc->constants = makeTriple(t, o, pointer, bc->constants);
return c->binaryOp(lir::Add, return c->binaryOp(lir::Add,
TargetBytesPerWord, types.address,
c->memory(c->register_(t->arch->thread()), c->memory(c->register_(t->arch->thread()),
types.address, types.address,
TARGET_THREAD_HEAPIMAGE), TARGET_THREAD_HEAPIMAGE),
@ -1643,7 +1643,7 @@ class Frame {
return context->bootContext return context->bootContext
? c->binaryOp( ? c->binaryOp(
lir::Add, lir::Add,
TargetBytesPerWord, types.address,
c->memory(c->register_(t->arch->thread()), c->memory(c->register_(t->arch->thread()),
types.address, types.address,
TARGET_THREAD_CODEIMAGE), TARGET_THREAD_CODEIMAGE),
@ -3732,17 +3732,19 @@ intrinsic(MyThread* t, Frame* frame, object target)
if (MATCH(methodName(t, target), "sqrt") if (MATCH(methodName(t, target), "sqrt")
and MATCH(methodSpec(t, target), "(D)D")) and MATCH(methodSpec(t, target), "(D)D"))
{ {
frame->pushLong(c->unaryOp(lir::FloatSquareRoot, 8, frame->popLong())); frame->pushLong(
c->unaryOp(lir::FloatSquareRoot, types.f8, frame->popLong()));
return true; return true;
} else if (MATCH(methodName(t, target), "abs")) { } else if (MATCH(methodName(t, target), "abs")) {
if (MATCH(methodSpec(t, target), "(I)I")) { if (MATCH(methodSpec(t, target), "(I)I")) {
frame->pushInt(c->unaryOp(lir::Absolute, 4, frame->popInt())); frame->pushInt(c->unaryOp(lir::Absolute, types.i4, frame->popInt()));
return true; return true;
} else if (MATCH(methodSpec(t, target), "(J)J")) { } else if (MATCH(methodSpec(t, target), "(J)J")) {
frame->pushLong(c->unaryOp(lir::Absolute, 8, frame->popLong())); frame->pushLong(c->unaryOp(lir::Absolute, types.i8, frame->popLong()));
return true; return true;
} else if (MATCH(methodSpec(t, target), "(F)F")) { } else if (MATCH(methodSpec(t, target), "(F)F")) {
frame->pushInt(c->unaryOp(lir::FloatAbsolute, 4, frame->popInt())); frame->pushInt(
c->unaryOp(lir::FloatAbsolute, types.f4, frame->popInt()));
return true; return true;
} }
} }
@ -4224,10 +4226,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
array, array,
c->binaryOp( c->binaryOp(
lir::Add, lir::Add,
4, types.i4,
c->constant(TargetArrayBody, types.i4), c->constant(TargetArrayBody, types.i4),
c->binaryOp(lir::ShiftLeft, c->binaryOp(lir::ShiftLeft,
4, types.i4,
c->constant(log(TargetBytesPerWord), types.i4), c->constant(log(TargetBytesPerWord), types.i4),
index)), index)),
value); value);
@ -4436,7 +4438,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
Compiler::Operand* a = frame->popLong(); Compiler::Operand* a = frame->popLong();
Compiler::Operand* b = frame->popLong(); Compiler::Operand* b = frame->popLong();
frame->pushLong(c->binaryOp(toCompilerBinaryOp(t, instruction), 8, a, b)); frame->pushLong(
c->binaryOp(toCompilerBinaryOp(t, instruction), types.f8, a, b));
} break; } break;
case dcmpg: { case dcmpg: {
@ -4490,7 +4493,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
break; break;
case dneg: { case dneg: {
frame->pushLong(c->unaryOp(lir::FloatNegate, 8, frame->popLong())); frame->pushLong(c->unaryOp(lir::FloatNegate, types.f8, frame->popLong()));
} break; } break;
case dup: case dup:
@ -4537,7 +4540,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
Compiler::Operand* a = frame->popInt(); Compiler::Operand* a = frame->popInt();
Compiler::Operand* b = frame->popInt(); Compiler::Operand* b = frame->popInt();
frame->pushInt(c->binaryOp(toCompilerBinaryOp(t, instruction), 4, a, b)); frame->pushInt(
c->binaryOp(toCompilerBinaryOp(t, instruction), types.f4, a, b));
} break; } break;
case fcmpg: { case fcmpg: {
@ -4591,7 +4595,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
break; break;
case fneg: { case fneg: {
frame->pushInt(c->unaryOp(lir::FloatNegate, 4, frame->popInt())); frame->pushInt(c->unaryOp(lir::FloatNegate, types.f4, frame->popInt()));
} break; } break;
case getfield: case getfield:
@ -4855,7 +4859,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case imul: { case imul: {
Compiler::Operand* a = frame->popInt(); Compiler::Operand* a = frame->popInt();
Compiler::Operand* b = frame->popInt(); Compiler::Operand* b = frame->popInt();
frame->pushInt(c->binaryOp(toCompilerBinaryOp(t, instruction), 4, a, b)); frame->pushInt(
c->binaryOp(toCompilerBinaryOp(t, instruction), types.i4, a, b));
} break; } break;
case iconst_m1: case iconst_m1:
@ -4895,7 +4900,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
frame->trace(0, 0); frame->trace(0, 0);
} }
frame->pushInt(c->binaryOp(lir::Divide, 4, a, b)); frame->pushInt(c->binaryOp(lir::Divide, types.i4, a, b));
} break; } break;
case if_acmpeq: case if_acmpeq:
@ -4982,7 +4987,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
storeLocal(context, storeLocal(context,
1, 1,
c->binaryOp(lir::Add, c->binaryOp(lir::Add,
4, types.i4,
c->constant(count, types.i4), c->constant(count, types.i4),
loadLocal(context, 1, index)), loadLocal(context, 1, index)),
index); index);
@ -5014,7 +5019,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
break; break;
case ineg: { case ineg: {
frame->pushInt(c->unaryOp(lir::Negate, 4, frame->popInt())); frame->pushInt(c->unaryOp(lir::Negate, types.i4, frame->popInt()));
} break; } break;
case instanceof: { case instanceof: {
@ -5203,7 +5208,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
Compiler::Operand* result = c->stackCall( Compiler::Operand* result = c->stackCall(
c->memory( c->memory(
c->binaryOp(lir::And, c->binaryOp(lir::And,
TargetBytesPerWord, types.address,
c->constant(TargetPointerMask, types.i4), c->constant(TargetPointerMask, types.i4),
c->memory(instance, types.object, 0, 0, 1)), c->memory(instance, types.object, 0, 0, 1)),
types.object, types.object,
@ -5265,7 +5270,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
frame->trace(0, 0); frame->trace(0, 0);
} }
frame->pushInt(c->binaryOp(lir::Remainder, 4, a, b)); frame->pushInt(c->binaryOp(lir::Remainder, types.i4, a, b));
} break; } break;
case ireturn: { case ireturn: {
@ -5350,7 +5355,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case lmul: { case lmul: {
Compiler::Operand* a = frame->popLong(); Compiler::Operand* a = frame->popLong();
Compiler::Operand* b = frame->popLong(); Compiler::Operand* b = frame->popLong();
frame->pushLong(c->binaryOp(toCompilerBinaryOp(t, instruction), 8, a, b)); frame->pushLong(
c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b));
} break; } break;
case lcmp: { case lcmp: {
@ -5464,7 +5470,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
frame->trace(0, 0); frame->trace(0, 0);
} }
frame->pushLong(c->binaryOp(lir::Divide, 8, a, b)); frame->pushLong(c->binaryOp(lir::Divide, types.i8, a, b));
} break; } break;
case lload: case lload:
@ -5493,7 +5499,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
break; break;
case lneg: case lneg:
frame->pushLong(c->unaryOp(lir::Negate, 8, frame->popLong())); frame->pushLong(c->unaryOp(lir::Negate, types.i8, frame->popLong()));
break; break;
case lookupswitch: { case lookupswitch: {
@ -5546,7 +5552,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
c->jmp(context->bootContext c->jmp(context->bootContext
? c->binaryOp(lir::Add, ? c->binaryOp(lir::Add,
TargetBytesPerWord, types.address,
c->memory(c->register_(t->arch->thread()), c->memory(c->register_(t->arch->thread()),
types.address, types.address,
TARGET_THREAD_CODEIMAGE), TARGET_THREAD_CODEIMAGE),
@ -5573,7 +5579,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
frame->trace(0, 0); frame->trace(0, 0);
} }
frame->pushLong(c->binaryOp(lir::Remainder, 8, a, b)); frame->pushLong(c->binaryOp(lir::Remainder, types.i8, a, b));
} break; } break;
case lreturn: { case lreturn: {
@ -5592,7 +5598,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
case lushr: { case lushr: {
Compiler::Operand* a = frame->popInt(); Compiler::Operand* a = frame->popInt();
Compiler::Operand* b = frame->popLong(); Compiler::Operand* b = frame->popLong();
frame->pushLong(c->binaryOp(toCompilerBinaryOp(t, instruction), 8, a, b)); frame->pushLong(
c->binaryOp(toCompilerBinaryOp(t, instruction), types.i8, a, b));
} break; } break;
case lstore: case lstore:
@ -6130,7 +6137,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
storeLocal(context, storeLocal(context,
1, 1,
c->binaryOp(lir::Add, c->binaryOp(lir::Add,
4, types.i4,
c->constant(count, types.i4), c->constant(count, types.i4),
loadLocal(context, 1, index)), loadLocal(context, 1, index)),
index); index);
@ -6209,10 +6216,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
c->restoreState(s->state); c->restoreState(s->state);
Compiler::Operand* normalizedKey Compiler::Operand* normalizedKey
= (s->bottom = (s->bottom ? c->binaryOp(lir::Subtract,
? c->binaryOp( types.i4,
lir::Subtract, 4, c->constant(s->bottom, types.i4), s->key) c->constant(s->bottom, types.i4),
: s->key); s->key)
: s->key);
Compiler::Operand* entry Compiler::Operand* entry
= c->memory(frame->absoluteAddressOperand(s->start), = c->memory(frame->absoluteAddressOperand(s->start),
@ -6225,7 +6233,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
TargetBytesPerWord, TargetBytesPerWord,
context->bootContext context->bootContext
? c->binaryOp(lir::Add, ? c->binaryOp(lir::Add,
TargetBytesPerWord, types.address,
c->memory(c->register_(t->arch->thread()), c->memory(c->register_(t->arch->thread()),
types.address, types.address,
TARGET_THREAD_CODEIMAGE), TARGET_THREAD_CODEIMAGE),