From 2d444830d0ce8ecfc9c18dbca4cfbd6c02e07fe2 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Wed, 30 Apr 2014 22:11:49 -0600 Subject: [PATCH] use ir::Type in Compiler::unaryOp and Compiler::binaryOp --- include/avian/codegen/compiler.h | 17 ++++-- src/codegen/compiler.cpp | 91 ++++++++++++++++++++++---------- src/compile.cpp | 68 +++++++++++++----------- 3 files changed, 114 insertions(+), 62 deletions(-) diff --git a/include/avian/codegen/compiler.h b/include/avian/codegen/compiler.h index c38636161d..28502e3dfd 100644 --- a/include/avian/codegen/compiler.h +++ b/include/avian/codegen/compiler.h @@ -117,15 +117,22 @@ class Compiler { virtual Operand* loadz(unsigned size, unsigned srcSelectSize, Operand* src, unsigned dstSize) = 0; - - virtual void condJump(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b, Operand* address) = 0; + virtual void condJump(lir::TernaryOperation op, + unsigned size, + Operand* a, + Operand* b, + Operand* address) = 0; virtual void jmp(Operand* address) = 0; virtual void exit(Operand* address) = 0; - virtual Operand* binaryOp(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b) = 0; - virtual Operand* unaryOp(lir::BinaryOperation type, unsigned size, Operand* a) = 0; - virtual void nullaryOp(lir::Operation type) = 0; + virtual Operand* binaryOp(lir::TernaryOperation op, + ir::Type type, + 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* f2i(ir::Type aType, ir::Type resType, Operand* a) = 0; diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index d298b24c70..0fbb0dc142 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -735,10 +735,14 @@ saveLocals(Context* c, Event* e) } } -void -maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, - unsigned srcSelectSize, Value* srcValue, unsigned dstSize, Value* dstValue, - const SiteMask& dstMask) +void maybeMove(Context* c, + lir::BinaryOperation op, + unsigned srcSize, + unsigned srcSelectSize, + Value* srcValue, + unsigned dstSize, + Value* dstValue, + const SiteMask& dstMask) { Read* read = live(c, dstValue); bool isStore = read == 0; @@ -790,8 +794,14 @@ maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, srcValue->source->freeze(c, srcValue); - apply(c, type, min(srcSelectSize, dstSize), srcValue->source, srcValue->source, - dstSize, target, target); + apply(c, + op, + min(srcSelectSize, dstSize), + srcValue->source, + srcValue->source, + dstSize, + target, + target); srcValue->source->thaw(c, srcValue); } else { @@ -803,7 +813,7 @@ maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, bool thunk; OperandMask src; - c->arch->planSource(type, dstSize, src, dstSize, &thunk); + c->arch->planSource(op, dstSize, src, dstSize, &thunk); if (isGeneralValue(srcValue)) { src.registerMask &= c->regFile->generalRegisters.mask; @@ -828,8 +838,14 @@ maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, srcb, dstb, srcValue, dstValue); } - apply(c, type, srcSelectSize, srcValue->source, srcValue->source, - dstSize, tmpTarget, tmpTarget); + apply(c, + op, + srcSelectSize, + srcValue->source, + srcValue->source, + dstSize, + tmpTarget, + tmpTarget); tmpTarget->thaw(c, dstValue); @@ -2610,15 +2626,22 @@ class MyCompiler: public Compiler { return dst; } - virtual void condJump(lir::TernaryOperation type, unsigned size, Operand* a, Operand* b, - Operand* address) + virtual void condJump(lir::TernaryOperation op, + unsigned size, + Operand* a, + Operand* b, + Operand* address) { assert(&c, - (isGeneralBranch(type) and isGeneralValue(a) and isGeneralValue(b)) - or (isFloatBranch(type) and isFloatValue(a) and isFloatValue(b))); + (isGeneralBranch(op) and isGeneralValue(a) and isGeneralValue(b))or( + isFloatBranch(op) and isFloatValue(a) and isFloatValue(b))); - appendBranch(&c, type, size, static_cast(a), - static_cast(b), static_cast(address)); + appendBranch(&c, + op, + size, + static_cast(a), + static_cast(b), + static_cast(address)); } virtual void jmp(Operand* address) { @@ -2629,23 +2652,36 @@ class MyCompiler: public Compiler { appendJump(&c, lir::Jump, static_cast(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, - (isGeneralBinaryOp(type) and isGeneralValue(a) and isGeneralValue(b)) - or (isFloatBinaryOp(type) and isFloatValue(a) and isFloatValue(b))); + (isGeneralBinaryOp(op) and isGeneralValue(a) and isGeneralValue(b)) + or(isFloatBinaryOp(op) and isFloatValue(a) and isFloatValue(b))); Value* result = value(&c, static_cast(a)->type); - - appendCombine(&c, type, size, static_cast(a), - size, static_cast(b), size, result); + + appendCombine(&c, + op, + type.size(), + static_cast(a), + type.size(), + static_cast(b), + type.size(), + result); return result; } - virtual Operand* unaryOp(lir::BinaryOperation type, unsigned size, Operand* a) { - assert(&c, (isGeneralUnaryOp(type) and isGeneralValue(a))or( - isFloatUnaryOp(type) and isFloatValue(a))); + virtual Operand* unaryOp(lir::BinaryOperation op, ir::Type type, Operand* a) + { + assert(&c, + (isGeneralUnaryOp(op) and isGeneralValue(a))or(isFloatUnaryOp(op) + and isFloatValue(a))); Value* result = value(&c, static_cast(a)->type); - appendTranslate(&c, type, size, static_cast(a), size, result); + appendTranslate( + &c, op, type.size(), static_cast(a), type.size(), result); return result; } @@ -2699,8 +2735,9 @@ class MyCompiler: public Compiler { return result; } - virtual void nullaryOp(lir::Operation type) { - appendOperation(&c, type); + virtual void nullaryOp(lir::Operation op) + { + appendOperation(&c, op); } virtual void compile(uintptr_t stackOverflowHandler, diff --git a/src/compile.cpp b/src/compile.cpp index 5cc52c3f56..e5b64670b4 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -1411,7 +1411,7 @@ class Frame { bc->constants = makeTriple(t, o, pointer, bc->constants); return c->binaryOp(lir::Add, - TargetBytesPerWord, + types.address, c->memory(c->register_(t->arch->thread()), types.address, TARGET_THREAD_HEAPIMAGE), @@ -1643,7 +1643,7 @@ class Frame { return context->bootContext ? c->binaryOp( lir::Add, - TargetBytesPerWord, + types.address, c->memory(c->register_(t->arch->thread()), types.address, TARGET_THREAD_CODEIMAGE), @@ -3732,17 +3732,19 @@ intrinsic(MyThread* t, Frame* frame, object target) if (MATCH(methodName(t, target), "sqrt") 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; } else if (MATCH(methodName(t, target), "abs")) { 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; } 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; } 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; } } @@ -4224,10 +4226,10 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, array, c->binaryOp( lir::Add, - 4, + types.i4, c->constant(TargetArrayBody, types.i4), c->binaryOp(lir::ShiftLeft, - 4, + types.i4, c->constant(log(TargetBytesPerWord), types.i4), index)), value); @@ -4436,7 +4438,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = 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; case dcmpg: { @@ -4490,7 +4493,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case dneg: { - frame->pushLong(c->unaryOp(lir::FloatNegate, 8, frame->popLong())); + frame->pushLong(c->unaryOp(lir::FloatNegate, types.f8, frame->popLong())); } break; case dup: @@ -4537,7 +4540,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* a = 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; case fcmpg: { @@ -4591,7 +4595,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case fneg: { - frame->pushInt(c->unaryOp(lir::FloatNegate, 4, frame->popInt())); + frame->pushInt(c->unaryOp(lir::FloatNegate, types.f4, frame->popInt())); } break; case getfield: @@ -4855,7 +4859,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case imul: { Compiler::Operand* a = 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; case iconst_m1: @@ -4895,7 +4900,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->trace(0, 0); } - frame->pushInt(c->binaryOp(lir::Divide, 4, a, b)); + frame->pushInt(c->binaryOp(lir::Divide, types.i4, a, b)); } break; case if_acmpeq: @@ -4982,7 +4987,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, storeLocal(context, 1, c->binaryOp(lir::Add, - 4, + types.i4, c->constant(count, types.i4), loadLocal(context, 1, index)), index); @@ -5014,7 +5019,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case ineg: { - frame->pushInt(c->unaryOp(lir::Negate, 4, frame->popInt())); + frame->pushInt(c->unaryOp(lir::Negate, types.i4, frame->popInt())); } break; case instanceof: { @@ -5203,7 +5208,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* result = c->stackCall( c->memory( c->binaryOp(lir::And, - TargetBytesPerWord, + types.address, c->constant(TargetPointerMask, types.i4), c->memory(instance, types.object, 0, 0, 1)), types.object, @@ -5265,7 +5270,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->trace(0, 0); } - frame->pushInt(c->binaryOp(lir::Remainder, 4, a, b)); + frame->pushInt(c->binaryOp(lir::Remainder, types.i4, a, b)); } break; case ireturn: { @@ -5350,7 +5355,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case lmul: { Compiler::Operand* a = 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; case lcmp: { @@ -5464,7 +5470,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->trace(0, 0); } - frame->pushLong(c->binaryOp(lir::Divide, 8, a, b)); + frame->pushLong(c->binaryOp(lir::Divide, types.i8, a, b)); } break; case lload: @@ -5493,7 +5499,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, break; case lneg: - frame->pushLong(c->unaryOp(lir::Negate, 8, frame->popLong())); + frame->pushLong(c->unaryOp(lir::Negate, types.i8, frame->popLong())); break; case lookupswitch: { @@ -5546,7 +5552,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->jmp(context->bootContext ? c->binaryOp(lir::Add, - TargetBytesPerWord, + types.address, c->memory(c->register_(t->arch->thread()), types.address, TARGET_THREAD_CODEIMAGE), @@ -5573,7 +5579,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, frame->trace(0, 0); } - frame->pushLong(c->binaryOp(lir::Remainder, 8, a, b)); + frame->pushLong(c->binaryOp(lir::Remainder, types.i8, a, b)); } break; case lreturn: { @@ -5592,7 +5598,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, case lushr: { Compiler::Operand* a = frame->popInt(); 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; case lstore: @@ -6130,7 +6137,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, storeLocal(context, 1, c->binaryOp(lir::Add, - 4, + types.i4, c->constant(count, types.i4), loadLocal(context, 1, index)), index); @@ -6209,10 +6216,11 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, c->restoreState(s->state); Compiler::Operand* normalizedKey - = (s->bottom - ? c->binaryOp( - lir::Subtract, 4, c->constant(s->bottom, types.i4), s->key) - : s->key); + = (s->bottom ? c->binaryOp(lir::Subtract, + types.i4, + c->constant(s->bottom, types.i4), + s->key) + : s->key); Compiler::Operand* entry = c->memory(frame->absoluteAddressOperand(s->start), @@ -6225,7 +6233,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, TargetBytesPerWord, context->bootContext ? c->binaryOp(lir::Add, - TargetBytesPerWord, + types.address, c->memory(c->register_(t->arch->thread()), types.address, TARGET_THREAD_CODEIMAGE),