From d7f088c9e7bf64041fe88d7520454aa368e8307c Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Mon, 11 Feb 2013 08:07:46 -0700 Subject: [PATCH] adjust package structure in codegen (vm -> avian::codegen and avian::codegen::lir) The eventual intent with the lir namespace is to formalize some of the important bits of Assembler interface, to be tested, debug-printed, and potentially, serialized. Also, group arguments to apply(...) in OperandInfos --- src/codegen/arm/assembler.cpp | 872 ++++++++++---------- src/codegen/assembler.h | 341 +------- src/codegen/compiler.cpp | 791 +++++++++--------- src/codegen/compiler.h | 14 +- src/codegen/lir-ops.inc.cpp | 62 ++ src/codegen/lir.cpp | 35 + src/codegen/lir.h | 174 ++++ src/codegen/powerpc/assembler.cpp | 783 +++++++++--------- src/codegen/promise.h | 159 ++++ src/codegen/targets.cpp | 2 +- src/codegen/targets.h | 8 +- src/codegen/x86/assembler.cpp | 1235 ++++++++++++++--------------- src/compile.cpp | 416 +++++----- src/processor.h | 10 +- 14 files changed, 2530 insertions(+), 2372 deletions(-) create mode 100644 src/codegen/lir-ops.inc.cpp create mode 100644 src/codegen/lir.cpp create mode 100644 src/codegen/lir.h create mode 100644 src/codegen/promise.h diff --git a/src/codegen/arm/assembler.cpp b/src/codegen/arm/assembler.cpp index 849a53b0cd..ecaad31007 100644 --- a/src/codegen/arm/assembler.cpp +++ b/src/codegen/arm/assembler.cpp @@ -20,6 +20,7 @@ #define CAST_BRANCH(x) reinterpret_cast(x) using namespace vm; +using namespace avian::codegen; namespace local { @@ -208,14 +209,14 @@ const uint64_t GPR_MASK64 = GPR_MASK | (uint64_t)GPR_MASK << 32; // making the following const somehow breaks debug symbol output in GDB /* const */ uint64_t FPR_MASK64 = FPR_MASK | (uint64_t)FPR_MASK << 32; -inline bool isFpr(Assembler::Register* reg) { +inline bool isFpr(lir::Register* reg) { return reg->low >= N_GPRS; } inline int fpr64(int reg) { return reg - N_GPRS; } -inline int fpr64(Assembler::Register* reg) { return fpr64(reg->low); } +inline int fpr64(lir::Register* reg) { return fpr64(reg->low); } inline int fpr32(int reg) { return fpr64(reg) << 1; } -inline int fpr32(Assembler::Register* reg) { return fpr64(reg) << 1; } +inline int fpr32(lir::Register* reg) { return fpr64(reg) << 1; } const unsigned FrameHeaderSize = 1; @@ -310,33 +311,33 @@ class Task { typedef void (*OperationType)(Context*); -typedef void (*UnaryOperationType)(Context*, unsigned, Assembler::Operand*); +typedef void (*UnaryOperationType)(Context*, unsigned, lir::Operand*); typedef void (*BinaryOperationType) -(Context*, unsigned, Assembler::Operand*, unsigned, Assembler::Operand*); +(Context*, unsigned, lir::Operand*, unsigned, lir::Operand*); typedef void (*TernaryOperationType) -(Context*, unsigned, Assembler::Operand*, Assembler::Operand*, - Assembler::Operand*); +(Context*, unsigned, lir::Operand*, lir::Operand*, + lir::Operand*); typedef void (*BranchOperationType) -(Context*, TernaryOperation, unsigned, Assembler::Operand*, - Assembler::Operand*, Assembler::Operand*); +(Context*, lir::TernaryOperation, unsigned, lir::Operand*, + lir::Operand*, lir::Operand*); class ArchitectureContext { public: ArchitectureContext(System* s): s(s) { } System* s; - OperationType operations[OperationCount]; - UnaryOperationType unaryOperations[UnaryOperationCount - * OperandTypeCount]; + OperationType operations[lir::OperationCount]; + UnaryOperationType unaryOperations[lir::UnaryOperationCount + * lir::OperandTypeCount]; BinaryOperationType binaryOperations - [BinaryOperationCount * OperandTypeCount * OperandTypeCount]; + [lir::BinaryOperationCount * lir::OperandTypeCount * lir::OperandTypeCount]; TernaryOperationType ternaryOperations - [NonBranchTernaryOperationCount * OperandTypeCount]; + [lir::NonBranchTernaryOperationCount * lir::OperandTypeCount]; BranchOperationType branchOperations - [BranchOperationCount * OperandTypeCount * OperandTypeCount]; + [lir::BranchOperationCount * lir::OperandTypeCount * lir::OperandTypeCount]; }; inline void NO_RETURN @@ -469,49 +470,37 @@ appendOffsetTask(Context* con, Promise* promise, Promise* instructionOffset) } inline unsigned -index(ArchitectureContext*, UnaryOperation operation, OperandType operand) +index(ArchitectureContext*, lir::UnaryOperation operation, lir::OperandType operand) { - return operation + (UnaryOperationCount * operand); + return operation + (lir::UnaryOperationCount * operand); } inline unsigned index(ArchitectureContext*, - BinaryOperation operation, - OperandType operand1, - OperandType operand2) + lir::BinaryOperation operation, + lir::OperandType operand1, + lir::OperandType operand2) { return operation - + (BinaryOperationCount * operand1) - + (BinaryOperationCount * OperandTypeCount * operand2); -} - -bool -isBranch(TernaryOperation op) -{ - return op > FloatMin; -} - -bool UNUSED -isFloatBranch(TernaryOperation op) -{ - return op > JumpIfNotEqual; + + (lir::BinaryOperationCount * operand1) + + (lir::BinaryOperationCount * lir::OperandTypeCount * operand2); } inline unsigned index(ArchitectureContext* con UNUSED, - TernaryOperation operation, - OperandType operand1) + lir::TernaryOperation operation, + lir::OperandType operand1) { assert(con, not isBranch(operation)); - return operation + (NonBranchTernaryOperationCount * operand1); + return operation + (lir::NonBranchTernaryOperationCount * operand1); } unsigned -branchIndex(ArchitectureContext* con UNUSED, OperandType operand1, - OperandType operand2) +branchIndex(ArchitectureContext* con UNUSED, lir::OperandType operand1, + lir::OperandType operand2) { - return operand1 + (OperandTypeCount * operand2); + return operand1 + (lir::OperandTypeCount * operand2); } // BEGIN OPERATION COMPILERS @@ -533,23 +522,23 @@ inline void freeTemp(Context* con, int r) { con->client->releaseTemporary(r); } -inline int64_t getValue(Assembler::Constant* con) { +inline int64_t getValue(lir::Constant* con) { return con->value->value(); } -inline Assembler::Register makeTemp(Context* con) { - Assembler::Register tmp(newTemp(con)); +inline lir::Register makeTemp(Context* con) { + lir::Register tmp(newTemp(con)); return tmp; } -inline Assembler::Register makeTemp64(Context* con) { - Assembler::Register tmp(newTemp(con), newTemp(con)); +inline lir::Register makeTemp64(Context* con) { + lir::Register tmp(newTemp(con), newTemp(con)); return tmp; } -inline void freeTemp(Context* con, const Assembler::Register& tmp) { - if (tmp.low != NoRegister) freeTemp(con, tmp.low); - if (tmp.high != NoRegister) freeTemp(con, tmp.high); +inline void freeTemp(Context* con, const lir::Register& tmp) { + if (tmp.low != lir::NoRegister) freeTemp(con, tmp.low); + if (tmp.high != lir::NoRegister) freeTemp(con, tmp.high); } inline void @@ -559,16 +548,16 @@ write4(uint8_t* dst, uint32_t v) } void -andC(Context* con, unsigned size, Assembler::Constant* a, - Assembler::Register* b, Assembler::Register* dst); +andC(Context* con, unsigned size, lir::Constant* a, + lir::Register* b, lir::Register* dst); -void shiftLeftR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) +void shiftLeftR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if (size == 8) { int tmp1 = newTemp(con), tmp2 = newTemp(con), tmp3 = newTemp(con); ResolvedPromise maskPromise(0x3F); - Assembler::Constant mask(&maskPromise); - Assembler::Register dst(tmp3); + lir::Constant mask(&maskPromise); + lir::Register dst(tmp3); andC(con, 4, &mask, a, &dst); emit(con, lsl(tmp1, b->high, tmp3)); emit(con, rsbi(tmp2, tmp3, 32)); @@ -581,8 +570,8 @@ void shiftLeftR(Context* con, unsigned size, Assembler::Register* a, Assembler:: } else { int tmp = newTemp(con); ResolvedPromise maskPromise(0x1F); - Assembler::Constant mask(&maskPromise); - Assembler::Register dst(tmp); + lir::Constant mask(&maskPromise); + lir::Register dst(tmp); andC(con, size, &mask, a, &dst); emit(con, lsl(t->low, b->low, tmp)); freeTemp(con, tmp); @@ -590,10 +579,10 @@ void shiftLeftR(Context* con, unsigned size, Assembler::Register* a, Assembler:: } void -moveRR(Context* con, unsigned srcSize, Assembler::Register* src, - unsigned dstSize, Assembler::Register* dst); +moveRR(Context* con, unsigned srcSize, lir::Register* src, + unsigned dstSize, lir::Register* dst); -void shiftLeftC(Context* con, unsigned size UNUSED, Assembler::Constant* a, Assembler::Register* b, Assembler::Register* t) +void shiftLeftC(Context* con, unsigned size UNUSED, lir::Constant* a, lir::Register* b, lir::Register* t) { assert(con, size == TargetBytesPerWord); if (getValue(a) & 0x1F) { @@ -603,13 +592,13 @@ void shiftLeftC(Context* con, unsigned size UNUSED, Assembler::Constant* a, Asse } } -void shiftRightR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) +void shiftRightR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if (size == 8) { int tmp1 = newTemp(con), tmp2 = newTemp(con), tmp3 = newTemp(con); ResolvedPromise maskPromise(0x3F); - Assembler::Constant mask(&maskPromise); - Assembler::Register dst(tmp3); + lir::Constant mask(&maskPromise); + lir::Register dst(tmp3); andC(con, 4, &mask, a, &dst); emit(con, lsr(tmp1, b->low, tmp3)); emit(con, rsbi(tmp2, tmp3, 32)); @@ -622,15 +611,15 @@ void shiftRightR(Context* con, unsigned size, Assembler::Register* a, Assembler: } else { int tmp = newTemp(con); ResolvedPromise maskPromise(0x1F); - Assembler::Constant mask(&maskPromise); - Assembler::Register dst(tmp); + lir::Constant mask(&maskPromise); + lir::Register dst(tmp); andC(con, size, &mask, a, &dst); emit(con, asr(t->low, b->low, tmp)); freeTemp(con, tmp); } } -void shiftRightC(Context* con, unsigned size UNUSED, Assembler::Constant* a, Assembler::Register* b, Assembler::Register* t) +void shiftRightC(Context* con, unsigned size UNUSED, lir::Constant* a, lir::Register* b, lir::Register* t) { assert(con, size == TargetBytesPerWord); if (getValue(a) & 0x1F) { @@ -640,12 +629,12 @@ void shiftRightC(Context* con, unsigned size UNUSED, Assembler::Constant* a, Ass } } -void unsignedShiftRightR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) +void unsignedShiftRightR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { int tmpShift = newTemp(con); ResolvedPromise maskPromise(size == 8 ? 0x3F : 0x1F); - Assembler::Constant mask(&maskPromise); - Assembler::Register dst(tmpShift); + lir::Constant mask(&maskPromise); + lir::Register dst(tmpShift); andC(con, 4, &mask, a, &dst); emit(con, lsr(t->low, b->low, tmpShift)); if (size == 8) { @@ -662,7 +651,7 @@ void unsignedShiftRightR(Context* con, unsigned size, Assembler::Register* a, As freeTemp(con, tmpShift); } -void unsignedShiftRightC(Context* con, unsigned size UNUSED, Assembler::Constant* a, Assembler::Register* b, Assembler::Register* t) +void unsignedShiftRightC(Context* con, unsigned size UNUSED, lir::Constant* a, lir::Register* b, lir::Register* t) { assert(con, size == TargetBytesPerWord); if (getValue(a) & 0x1F) { @@ -873,20 +862,20 @@ resolve(MyBlock* b) } void -jumpR(Context* con, unsigned size UNUSED, Assembler::Register* target) +jumpR(Context* con, unsigned size UNUSED, lir::Register* target) { assert(con, size == TargetBytesPerWord); emit(con, bx(target->low)); } void -swapRR(Context* con, unsigned aSize, Assembler::Register* a, - unsigned bSize, Assembler::Register* b) +swapRR(Context* con, unsigned aSize, lir::Register* a, + unsigned bSize, lir::Register* b) { assert(con, aSize == TargetBytesPerWord); assert(con, bSize == TargetBytesPerWord); - Assembler::Register tmp(con->client->acquireTemporary(GPR_MASK)); + lir::Register tmp(con->client->acquireTemporary(GPR_MASK)); moveRR(con, aSize, a, bSize, &tmp); moveRR(con, bSize, b, aSize, a); moveRR(con, bSize, &tmp, bSize, b); @@ -894,8 +883,8 @@ swapRR(Context* con, unsigned aSize, Assembler::Register* a, } void -moveRR(Context* con, unsigned srcSize, Assembler::Register* src, - unsigned dstSize, Assembler::Register* dst) +moveRR(Context* con, unsigned srcSize, lir::Register* src, + unsigned dstSize, lir::Register* dst) { bool srcIsFpr = isFpr(src); bool dstIsFpr = isFpr(dst); @@ -932,8 +921,8 @@ moveRR(Context* con, unsigned srcSize, Assembler::Register* src, moveRR(con, 4, src, 4, dst); emit(con, asri(dst->high, src->low, 31)); } else if (srcSize == 8 and dstSize == 8) { - Assembler::Register srcHigh(src->high); - Assembler::Register dstHigh(dst->high); + lir::Register srcHigh(src->high); + lir::Register dstHigh(dst->high); if (src->high == dst->low) { if (src->low == dst->high) { @@ -956,8 +945,8 @@ moveRR(Context* con, unsigned srcSize, Assembler::Register* src, } void -moveZRR(Context* con, unsigned srcSize, Assembler::Register* src, - unsigned, Assembler::Register* dst) +moveZRR(Context* con, unsigned srcSize, lir::Register* src, + unsigned, lir::Register* dst) { switch (srcSize) { case 2: @@ -969,15 +958,15 @@ moveZRR(Context* con, unsigned srcSize, Assembler::Register* src, } } -void moveCR(Context* con, unsigned size, Assembler::Constant* src, - unsigned, Assembler::Register* dst); +void moveCR(Context* con, unsigned size, lir::Constant* src, + unsigned, lir::Register* dst); void -moveCR2(Context* con, unsigned size, Assembler::Constant* src, - Assembler::Register* dst, Promise* callOffset) +moveCR2(Context* con, unsigned size, lir::Constant* src, + lir::Register* dst, Promise* callOffset) { if (isFpr(dst)) { // floating-point - Assembler::Register tmp = size > 4 ? makeTemp64(con) : + lir::Register tmp = size > 4 ? makeTemp64(con) : makeTemp(con); moveCR(con, size, src, size, &tmp); moveRR(con, size, &tmp, size, dst); @@ -985,10 +974,10 @@ moveCR2(Context* con, unsigned size, Assembler::Constant* src, } else if (size > 4) { uint64_t value = (uint64_t)src->value->value(); ResolvedPromise loBits(value & MASK_LO32); - Assembler::Constant srcLo(&loBits); + lir::Constant srcLo(&loBits); ResolvedPromise hiBits(value >> 32); - Assembler::Constant srcHi(&hiBits); - Assembler::Register dstHi(dst->high); + lir::Constant srcHi(&hiBits); + lir::Register dstHi(dst->high); moveCR(con, 4, &srcLo, 4, dst); moveCR(con, 4, &srcHi, 4, &dstHi); } else if (src->value->resolved() and isOfWidth(getValue(src), 8)) { @@ -1000,13 +989,13 @@ moveCR2(Context* con, unsigned size, Assembler::Constant* src, } void -moveCR(Context* con, unsigned size, Assembler::Constant* src, - unsigned, Assembler::Register* dst) +moveCR(Context* con, unsigned size, lir::Constant* src, + unsigned, lir::Register* dst) { moveCR2(con, size, src, dst, 0); } -void addR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) { +void addR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if (size == 8) { emit(con, SETS(add(t->low, a->low, b->low))); emit(con, adc(t->high, a->high, b->high)); @@ -1015,7 +1004,7 @@ void addR(Context* con, unsigned size, Assembler::Register* a, Assembler::Regist } } -void subR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) { +void subR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if (size == 8) { emit(con, SETS(rsb(t->low, a->low, b->low))); emit(con, rsc(t->high, a->high, b->high)); @@ -1025,8 +1014,8 @@ void subR(Context* con, unsigned size, Assembler::Register* a, Assembler::Regist } void -addC(Context* con, unsigned size, Assembler::Constant* a, - Assembler::Register* b, Assembler::Register* dst) +addC(Context* con, unsigned size, lir::Constant* a, + lir::Register* b, lir::Register* dst) { assert(con, size == TargetBytesPerWord); @@ -1046,8 +1035,8 @@ addC(Context* con, unsigned size, Assembler::Constant* a, } void -subC(Context* con, unsigned size, Assembler::Constant* a, - Assembler::Register* b, Assembler::Register* dst) +subC(Context* con, unsigned size, lir::Constant* a, + lir::Register* b, lir::Register* dst) { assert(con, size == TargetBytesPerWord); @@ -1066,7 +1055,7 @@ subC(Context* con, unsigned size, Assembler::Constant* a, } } -void multiplyR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) { +void multiplyR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if (size == 8) { bool useTemporaries = b->low == t->low; int tmpLow = useTemporaries ? con->client->acquireTemporary(GPR_MASK) : t->low; @@ -1087,7 +1076,7 @@ void multiplyR(Context* con, unsigned size, Assembler::Register* a, Assembler::R } } -void floatAbsoluteRR(Context* con, unsigned size, Assembler::Register* a, unsigned, Assembler::Register* b) { +void floatAbsoluteRR(Context* con, unsigned size, lir::Register* a, unsigned, lir::Register* b) { if (size == 8) { emit(con, fabsd(fpr64(b), fpr64(a))); } else { @@ -1095,7 +1084,7 @@ void floatAbsoluteRR(Context* con, unsigned size, Assembler::Register* a, unsign } } -void floatNegateRR(Context* con, unsigned size, Assembler::Register* a, unsigned, Assembler::Register* b) { +void floatNegateRR(Context* con, unsigned size, lir::Register* a, unsigned, lir::Register* b) { if (size == 8) { emit(con, fnegd(fpr64(b), fpr64(a))); } else { @@ -1103,7 +1092,7 @@ void floatNegateRR(Context* con, unsigned size, Assembler::Register* a, unsigned } } -void float2FloatRR(Context* con, unsigned size, Assembler::Register* a, unsigned, Assembler::Register* b) { +void float2FloatRR(Context* con, unsigned size, lir::Register* a, unsigned, lir::Register* b) { if (size == 8) { emit(con, fcvtsd(fpr32(b), fpr64(a))); } else { @@ -1111,7 +1100,7 @@ void float2FloatRR(Context* con, unsigned size, Assembler::Register* a, unsigned } } -void float2IntRR(Context* con, unsigned size, Assembler::Register* a, unsigned, Assembler::Register* b) { +void float2IntRR(Context* con, unsigned size, lir::Register* a, unsigned, lir::Register* b) { int tmp = newTemp(con, FPR_MASK); int ftmp = fpr32(tmp); if (size == 8) { // double to int @@ -1123,7 +1112,7 @@ void float2IntRR(Context* con, unsigned size, Assembler::Register* a, unsigned, freeTemp(con, tmp); } -void int2FloatRR(Context* con, unsigned, Assembler::Register* a, unsigned size, Assembler::Register* b) { +void int2FloatRR(Context* con, unsigned, lir::Register* a, unsigned size, lir::Register* b) { emit(con, fmsr(fpr32(b), a->low)); if (size == 8) { // int to double emit(con, fsitod(fpr64(b), fpr32(b))); @@ -1132,7 +1121,7 @@ void int2FloatRR(Context* con, unsigned, Assembler::Register* a, unsigned size, } // else thunked } -void floatSqrtRR(Context* con, unsigned size, Assembler::Register* a, unsigned, Assembler::Register* b) { +void floatSqrtRR(Context* con, unsigned size, lir::Register* a, unsigned, lir::Register* b) { if (size == 8) { emit(con, fsqrtd(fpr64(b), fpr64(a))); } else { @@ -1140,7 +1129,7 @@ void floatSqrtRR(Context* con, unsigned size, Assembler::Register* a, unsigned, } } -void floatAddR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) { +void floatAddR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if (size == 8) { emit(con, faddd(fpr64(t), fpr64(a), fpr64(b))); } else { @@ -1148,7 +1137,7 @@ void floatAddR(Context* con, unsigned size, Assembler::Register* a, Assembler::R } } -void floatSubtractR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) { +void floatSubtractR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if (size == 8) { emit(con, fsubd(fpr64(t), fpr64(b), fpr64(a))); } else { @@ -1156,7 +1145,7 @@ void floatSubtractR(Context* con, unsigned size, Assembler::Register* a, Assembl } } -void floatMultiplyR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) { +void floatMultiplyR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if (size == 8) { emit(con, fmuld(fpr64(t), fpr64(a), fpr64(b))); } else { @@ -1164,7 +1153,7 @@ void floatMultiplyR(Context* con, unsigned size, Assembler::Register* a, Assembl } } -void floatDivideR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) { +void floatDivideR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if (size == 8) { emit(con, fdivd(fpr64(t), fpr64(b), fpr64(a))); } else { @@ -1177,7 +1166,7 @@ normalize(Context* con, int offset, int index, unsigned scale, bool* preserveIndex, bool* release) { if (offset != 0 or scale != 1) { - Assembler::Register normalizedIndex + lir::Register normalizedIndex (*preserveIndex ? con->client->acquireTemporary(GPR_MASK) : index); if (*preserveIndex) { @@ -1190,10 +1179,10 @@ normalize(Context* con, int offset, int index, unsigned scale, int scaled; if (scale != 1) { - Assembler::Register unscaledIndex(index); + lir::Register unscaledIndex(index); ResolvedPromise scalePromise(log(scale)); - Assembler::Constant scaleConstant(&scalePromise); + lir::Constant scaleConstant(&scalePromise); shiftLeftC(con, TargetBytesPerWord, &scaleConstant, &unscaledIndex, &normalizedIndex); @@ -1204,12 +1193,12 @@ normalize(Context* con, int offset, int index, unsigned scale, } if (offset != 0) { - Assembler::Register untranslatedIndex(scaled); + lir::Register untranslatedIndex(scaled); ResolvedPromise offsetPromise(offset); - Assembler::Constant offsetConstant(&offsetPromise); + lir::Constant offsetConstant(&offsetPromise); - Assembler::Register tmp(con->client->acquireTemporary(GPR_MASK)); + lir::Register tmp(con->client->acquireTemporary(GPR_MASK)); moveCR(con, TargetBytesPerWord, &offsetConstant, TargetBytesPerWord, &tmp); addR(con, TargetBytesPerWord, &tmp, &untranslatedIndex, &normalizedIndex); con->client->releaseTemporary(tmp.low); @@ -1223,10 +1212,10 @@ normalize(Context* con, int offset, int index, unsigned scale, } void -store(Context* con, unsigned size, Assembler::Register* src, +store(Context* con, unsigned size, lir::Register* src, int base, int offset, int index, unsigned scale, bool preserveIndex) { - if (index != NoRegister) { + if (index != lir::NoRegister) { bool release; int normalized = normalize (con, offset, index, scale, &preserveIndex, &release); @@ -1246,7 +1235,7 @@ store(Context* con, unsigned size, Assembler::Register* src, break; case 8: { // split into 2 32-bit stores - Assembler::Register srcHigh(src->high); + lir::Register srcHigh(src->high); store(con, 4, &srcHigh, base, 0, normalized, 1, preserveIndex); store(con, 4, src, base, 4, normalized, 1, preserveIndex); } break; @@ -1254,7 +1243,7 @@ store(Context* con, unsigned size, Assembler::Register* src, default: abort(con); } } else { // FPR store - Assembler::Register base_(base), + lir::Register base_(base), normalized_(normalized), absAddr = makeTemp(con); // FPR stores have only bases, so we must add the index @@ -1286,9 +1275,9 @@ store(Context* con, unsigned size, Assembler::Register* src, break; case 8: { // split into 2 32-bit stores - Assembler::Register srcHigh(src->high); - store(con, 4, &srcHigh, base, offset, NoRegister, 1, false); - store(con, 4, src, base, offset + 4, NoRegister, 1, false); + lir::Register srcHigh(src->high); + store(con, 4, &srcHigh, base, offset, lir::NoRegister, 1, false); + store(con, 4, src, base, offset + 4, lir::NoRegister, 1, false); } break; default: abort(con); @@ -1300,9 +1289,9 @@ store(Context* con, unsigned size, Assembler::Register* src, else emit(con, fsts(fpr32(src), base, offset)); } } else { - Assembler::Register tmp(con->client->acquireTemporary(GPR_MASK)); + lir::Register tmp(con->client->acquireTemporary(GPR_MASK)); ResolvedPromise offsetPromise(offset); - Assembler::Constant offsetConstant(&offsetPromise); + lir::Constant offsetConstant(&offsetPromise); moveCR(con, TargetBytesPerWord, &offsetConstant, TargetBytesPerWord, &tmp); @@ -1313,8 +1302,8 @@ store(Context* con, unsigned size, Assembler::Register* src, } void -moveRM(Context* con, unsigned srcSize, Assembler::Register* src, - unsigned dstSize UNUSED, Assembler::Memory* dst) +moveRM(Context* con, unsigned srcSize, lir::Register* src, + unsigned dstSize UNUSED, lir::Memory* dst) { assert(con, srcSize == dstSize); @@ -1323,10 +1312,10 @@ moveRM(Context* con, unsigned srcSize, Assembler::Register* src, void load(Context* con, unsigned srcSize, int base, int offset, int index, - unsigned scale, unsigned dstSize, Assembler::Register* dst, + unsigned scale, unsigned dstSize, lir::Register* dst, bool preserveIndex, bool signExtend) { - if (index != NoRegister) { + if (index != lir::NoRegister) { bool release; int normalized = normalize (con, offset, index, scale, &preserveIndex, &release); @@ -1356,7 +1345,7 @@ load(Context* con, unsigned srcSize, int base, int offset, int index, false); moveRR(con, 4, dst, 8, dst); } else if (srcSize == 8 and dstSize == 8) { - Assembler::Register dstHigh(dst->high); + lir::Register dstHigh(dst->high); load(con, 4, base, 0, normalized, 1, 4, &dstHigh, preserveIndex, false); load(con, 4, base, 4, normalized, 1, 4, dst, preserveIndex, @@ -1369,7 +1358,7 @@ load(Context* con, unsigned srcSize, int base, int offset, int index, default: abort(con); } } else { // FPR load - Assembler::Register base_(base), + lir::Register base_(base), normalized_(normalized), absAddr = makeTemp(con); // VFP loads only have bases, so we must add the index @@ -1412,10 +1401,10 @@ load(Context* con, unsigned srcSize, int base, int offset, int index, case 8: { if (dstSize == 8) { - Assembler::Register dstHigh(dst->high); - load(con, 4, base, offset, NoRegister, 1, 4, &dstHigh, false, + lir::Register dstHigh(dst->high); + load(con, 4, base, offset, lir::NoRegister, 1, 4, &dstHigh, false, false); - load(con, 4, base, offset + 4, NoRegister, 1, 4, dst, false, + load(con, 4, base, offset + 4, lir::NoRegister, 1, 4, dst, false, false); } else { emit(con, ldri(dst->low, base, offset)); @@ -1431,9 +1420,9 @@ load(Context* con, unsigned srcSize, int base, int offset, int index, else emit(con, flds(fpr32(dst), base, offset)); } } else { - Assembler::Register tmp(con->client->acquireTemporary(GPR_MASK)); + lir::Register tmp(con->client->acquireTemporary(GPR_MASK)); ResolvedPromise offsetPromise(offset); - Assembler::Constant offsetConstant(&offsetPromise); + lir::Constant offsetConstant(&offsetPromise); moveCR(con, TargetBytesPerWord, &offsetConstant, TargetBytesPerWord, &tmp); @@ -1445,44 +1434,44 @@ load(Context* con, unsigned srcSize, int base, int offset, int index, } void -moveMR(Context* con, unsigned srcSize, Assembler::Memory* src, - unsigned dstSize, Assembler::Register* dst) +moveMR(Context* con, unsigned srcSize, lir::Memory* src, + unsigned dstSize, lir::Register* dst) { load(con, srcSize, src->base, src->offset, src->index, src->scale, dstSize, dst, true, true); } void -moveZMR(Context* con, unsigned srcSize, Assembler::Memory* src, - unsigned dstSize, Assembler::Register* dst) +moveZMR(Context* con, unsigned srcSize, lir::Memory* src, + unsigned dstSize, lir::Register* dst) { load(con, srcSize, src->base, src->offset, src->index, src->scale, dstSize, dst, true, false); } void -andR(Context* con, unsigned size, Assembler::Register* a, - Assembler::Register* b, Assembler::Register* dst) +andR(Context* con, unsigned size, lir::Register* a, + lir::Register* b, lir::Register* dst) { if (size == 8) emit(con, and_(dst->high, a->high, b->high)); emit(con, and_(dst->low, a->low, b->low)); } void -andC(Context* con, unsigned size, Assembler::Constant* a, - Assembler::Register* b, Assembler::Register* dst) +andC(Context* con, unsigned size, lir::Constant* a, + lir::Register* b, lir::Register* dst) { int64_t v = a->value->value(); if (size == 8) { ResolvedPromise high((v >> 32) & 0xFFFFFFFF); - Assembler::Constant ah(&high); + lir::Constant ah(&high); ResolvedPromise low(v & 0xFFFFFFFF); - Assembler::Constant al(&low); + lir::Constant al(&low); - Assembler::Register bh(b->high); - Assembler::Register dh(dst->high); + lir::Register bh(b->high); + lir::Register dh(dst->high); andC(con, 4, &al, b, dst); andC(con, 4, &ah, &bh, &dh); @@ -1498,7 +1487,7 @@ andC(Context* con, unsigned size, Assembler::Constant* a, // instruction bool useTemporary = b->low == dst->low; - Assembler::Register tmp(dst->low); + lir::Register tmp(dst->low); if (useTemporary) { tmp.low = con->client->acquireTemporary(GPR_MASK); } @@ -1517,44 +1506,44 @@ andC(Context* con, unsigned size, Assembler::Constant* a, } void -orR(Context* con, unsigned size, Assembler::Register* a, - Assembler::Register* b, Assembler::Register* dst) +orR(Context* con, unsigned size, lir::Register* a, + lir::Register* b, lir::Register* dst) { if (size == 8) emit(con, orr(dst->high, a->high, b->high)); emit(con, orr(dst->low, a->low, b->low)); } void -xorR(Context* con, unsigned size, Assembler::Register* a, - Assembler::Register* b, Assembler::Register* dst) +xorR(Context* con, unsigned size, lir::Register* a, + lir::Register* b, lir::Register* dst) { if (size == 8) emit(con, eor(dst->high, a->high, b->high)); emit(con, eor(dst->low, a->low, b->low)); } void -moveAR2(Context* con, unsigned srcSize, Assembler::Address* src, - unsigned dstSize, Assembler::Register* dst) +moveAR2(Context* con, unsigned srcSize, lir::Address* src, + unsigned dstSize, lir::Register* dst) { assert(con, srcSize == 4 and dstSize == 4); - Assembler::Constant constant(src->address); + lir::Constant constant(src->address); moveCR(con, srcSize, &constant, dstSize, dst); - Assembler::Memory memory(dst->low, 0, -1, 0); + lir::Memory memory(dst->low, 0, -1, 0); moveMR(con, dstSize, &memory, dstSize, dst); } void -moveAR(Context* con, unsigned srcSize, Assembler::Address* src, - unsigned dstSize, Assembler::Register* dst) +moveAR(Context* con, unsigned srcSize, lir::Address* src, + unsigned dstSize, lir::Register* dst) { moveAR2(con, srcSize, src, dstSize, dst); } void -compareRR(Context* con, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +compareRR(Context* con, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(con, !(isFpr(a) ^ isFpr(b))); // regs must be of the same type @@ -1571,8 +1560,8 @@ compareRR(Context* con, unsigned aSize, Assembler::Register* a, } void -compareCR(Context* con, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +compareCR(Context* con, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { assert(con, aSize == 4 and bSize == 4); @@ -1580,7 +1569,7 @@ compareCR(Context* con, unsigned aSize, Assembler::Constant* a, isOfWidth(a->value->value(), 8)) { emit(con, cmpi(b->low, a->value->value())); } else { - Assembler::Register tmp(con->client->acquireTemporary(GPR_MASK)); + lir::Register tmp(con->client->acquireTemporary(GPR_MASK)); moveCR(con, aSize, a, bSize, &tmp); compareRR(con, bSize, &tmp, bSize, b); con->client->releaseTemporary(tmp.low); @@ -1588,63 +1577,63 @@ compareCR(Context* con, unsigned aSize, Assembler::Constant* a, } void -compareCM(Context* con, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Memory* b) +compareCM(Context* con, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Memory* b) { assert(con, aSize == 4 and bSize == 4); - Assembler::Register tmp(con->client->acquireTemporary(GPR_MASK)); + lir::Register tmp(con->client->acquireTemporary(GPR_MASK)); moveMR(con, bSize, b, bSize, &tmp); compareCR(con, aSize, a, bSize, &tmp); con->client->releaseTemporary(tmp.low); } void -compareRM(Context* con, unsigned aSize, Assembler::Register* a, - unsigned bSize, Assembler::Memory* b) +compareRM(Context* con, unsigned aSize, lir::Register* a, + unsigned bSize, lir::Memory* b) { assert(con, aSize == 4 and bSize == 4); - Assembler::Register tmp(con->client->acquireTemporary(GPR_MASK)); + lir::Register tmp(con->client->acquireTemporary(GPR_MASK)); moveMR(con, bSize, b, bSize, &tmp); compareRR(con, aSize, a, bSize, &tmp); con->client->releaseTemporary(tmp.low); } int32_t -branch(Context* con, TernaryOperation op) +branch(Context* con, lir::TernaryOperation op) { switch (op) { - case JumpIfEqual: - case JumpIfFloatEqual: + case lir::JumpIfEqual: + case lir::JumpIfFloatEqual: return beq(0); - case JumpIfNotEqual: - case JumpIfFloatNotEqual: + case lir::JumpIfNotEqual: + case lir::JumpIfFloatNotEqual: return bne(0); - case JumpIfLess: - case JumpIfFloatLess: - case JumpIfFloatLessOrUnordered: + case lir::JumpIfLess: + case lir::JumpIfFloatLess: + case lir::JumpIfFloatLessOrUnordered: return blt(0); - case JumpIfGreater: - case JumpIfFloatGreater: + case lir::JumpIfGreater: + case lir::JumpIfFloatGreater: return bgt(0); - case JumpIfLessOrEqual: - case JumpIfFloatLessOrEqual: - case JumpIfFloatLessOrEqualOrUnordered: + case lir::JumpIfLessOrEqual: + case lir::JumpIfFloatLessOrEqual: + case lir::JumpIfFloatLessOrEqualOrUnordered: return ble(0); - case JumpIfGreaterOrEqual: - case JumpIfFloatGreaterOrEqual: + case lir::JumpIfGreaterOrEqual: + case lir::JumpIfFloatGreaterOrEqual: return bge(0); - case JumpIfFloatGreaterOrUnordered: + case lir::JumpIfFloatGreaterOrUnordered: return bhi(0); - case JumpIfFloatGreaterOrEqualOrUnordered: + case lir::JumpIfFloatGreaterOrEqualOrUnordered: return bpl(0); default: @@ -1653,22 +1642,22 @@ branch(Context* con, TernaryOperation op) } void -conditional(Context* con, int32_t branch, Assembler::Constant* target) +conditional(Context* con, int32_t branch, lir::Constant* target) { appendOffsetTask(con, target->value, offset(con)); emit(con, branch); } void -branch(Context* con, TernaryOperation op, Assembler::Constant* target) +branch(Context* con, lir::TernaryOperation op, lir::Constant* target) { conditional(con, branch(con, op), target); } void -branchLong(Context* con, TernaryOperation op, Assembler::Operand* al, - Assembler::Operand* ah, Assembler::Operand* bl, - Assembler::Operand* bh, Assembler::Constant* target, +branchLong(Context* con, lir::TernaryOperation op, lir::Operand* al, + lir::Operand* ah, lir::Operand* bl, + lir::Operand* bh, lir::Constant* target, BinaryOperationType compareSigned, BinaryOperationType compareUnsigned) { @@ -1677,8 +1666,8 @@ branchLong(Context* con, TernaryOperation op, Assembler::Operand* al, unsigned next = 0; switch (op) { - case JumpIfEqual: - case JumpIfFloatEqual: + case lir::JumpIfEqual: + case lir::JumpIfFloatEqual: next = con->code.length(); emit(con, bne(0)); @@ -1686,16 +1675,16 @@ branchLong(Context* con, TernaryOperation op, Assembler::Operand* al, conditional(con, beq(0), target); break; - case JumpIfNotEqual: - case JumpIfFloatNotEqual: + case lir::JumpIfNotEqual: + case lir::JumpIfFloatNotEqual: conditional(con, bne(0), target); compareSigned(con, 4, al, 4, bl); conditional(con, bne(0), target); break; - case JumpIfLess: - case JumpIfFloatLess: + case lir::JumpIfLess: + case lir::JumpIfFloatLess: conditional(con, blt(0), target); next = con->code.length(); @@ -1705,8 +1694,8 @@ branchLong(Context* con, TernaryOperation op, Assembler::Operand* al, conditional(con, blo(0), target); break; - case JumpIfGreater: - case JumpIfFloatGreater: + case lir::JumpIfGreater: + case lir::JumpIfFloatGreater: conditional(con, bgt(0), target); next = con->code.length(); @@ -1716,8 +1705,8 @@ branchLong(Context* con, TernaryOperation op, Assembler::Operand* al, conditional(con, bhi(0), target); break; - case JumpIfLessOrEqual: - case JumpIfFloatLessOrEqual: + case lir::JumpIfLessOrEqual: + case lir::JumpIfFloatLessOrEqual: conditional(con, blt(0), target); next = con->code.length(); @@ -1727,8 +1716,8 @@ branchLong(Context* con, TernaryOperation op, Assembler::Operand* al, conditional(con, bls(0), target); break; - case JumpIfGreaterOrEqual: - case JumpIfFloatGreaterOrEqual: + case lir::JumpIfGreaterOrEqual: + case lir::JumpIfFloatGreaterOrEqual: conditional(con, bgt(0), target); next = con->code.length(); @@ -1750,13 +1739,13 @@ branchLong(Context* con, TernaryOperation op, Assembler::Operand* al, } void -branchRR(Context* con, TernaryOperation op, unsigned size, - Assembler::Register* a, Assembler::Register* b, - Assembler::Constant* target) +branchRR(Context* con, lir::TernaryOperation op, unsigned size, + lir::Register* a, lir::Register* b, + lir::Constant* target) { if (!isFpr(a) && size > TargetBytesPerWord) { - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); + lir::Register ah(a->high); + lir::Register bh(b->high); branchLong(con, op, a, &ah, b, &bh, target, CAST2(compareRR), CAST2(compareRR)); @@ -1767,9 +1756,9 @@ branchRR(Context* con, TernaryOperation op, unsigned size, } void -branchCR(Context* con, TernaryOperation op, unsigned size, - Assembler::Constant* a, Assembler::Register* b, - Assembler::Constant* target) +branchCR(Context* con, lir::TernaryOperation op, unsigned size, + lir::Constant* a, lir::Register* b, + lir::Constant* target) { assert(con, !isFloatBranch(op)); @@ -1777,12 +1766,12 @@ branchCR(Context* con, TernaryOperation op, unsigned size, int64_t v = a->value->value(); ResolvedPromise low(v & ~static_cast(0)); - Assembler::Constant al(&low); + lir::Constant al(&low); ResolvedPromise high((v >> 32) & ~static_cast(0)); - Assembler::Constant ah(&high); + lir::Constant ah(&high); - Assembler::Register bh(b->high); + lir::Register bh(b->high); branchLong(con, op, &al, &ah, b, &bh, target, CAST2(compareCR), CAST2(compareCR)); @@ -1793,9 +1782,9 @@ branchCR(Context* con, TernaryOperation op, unsigned size, } void -branchRM(Context* con, TernaryOperation op, unsigned size, - Assembler::Register* a, Assembler::Memory* b, - Assembler::Constant* target) +branchRM(Context* con, lir::TernaryOperation op, unsigned size, + lir::Register* a, lir::Memory* b, + lir::Constant* target) { assert(con, !isFloatBranch(op)); assert(con, size <= TargetBytesPerWord); @@ -1805,9 +1794,9 @@ branchRM(Context* con, TernaryOperation op, unsigned size, } void -branchCM(Context* con, TernaryOperation op, unsigned size, - Assembler::Constant* a, Assembler::Memory* b, - Assembler::Constant* target) +branchCM(Context* con, lir::TernaryOperation op, unsigned size, + lir::Constant* a, lir::Memory* b, + lir::Constant* target) { assert(con, !isFloatBranch(op)); assert(con, size <= TargetBytesPerWord); @@ -1823,17 +1812,17 @@ shiftMaskPromise(Context* con, Promise* base, unsigned shift, int64_t mask) } void -moveCM(Context* con, unsigned srcSize, Assembler::Constant* src, - unsigned dstSize, Assembler::Memory* dst) +moveCM(Context* con, unsigned srcSize, lir::Constant* src, + unsigned dstSize, lir::Memory* dst) { switch (dstSize) { case 8: { - Assembler::Constant srcHigh + lir::Constant srcHigh (shiftMaskPromise(con, src->value, 32, 0xFFFFFFFF)); - Assembler::Constant srcLow + lir::Constant srcLow (shiftMaskPromise(con, src->value, 0, 0xFFFFFFFF)); - Assembler::Memory dstLow + lir::Memory dstLow (dst->base, dst->offset + 4, dst->index, dst->scale); moveCM(con, 4, &srcLow, 4, &dstLow); @@ -1841,7 +1830,7 @@ moveCM(Context* con, unsigned srcSize, Assembler::Constant* src, } break; default: - Assembler::Register tmp(con->client->acquireTemporary(GPR_MASK)); + lir::Register tmp(con->client->acquireTemporary(GPR_MASK)); moveCR(con, srcSize, src, dstSize, &tmp); moveRM(con, dstSize, &tmp, dstSize, dst); con->client->releaseTemporary(tmp.low); @@ -1849,8 +1838,8 @@ moveCM(Context* con, unsigned srcSize, Assembler::Constant* src, } void -negateRR(Context* con, unsigned srcSize, Assembler::Register* src, - unsigned dstSize UNUSED, Assembler::Register* dst) +negateRR(Context* con, unsigned srcSize, lir::Register* src, + unsigned dstSize UNUSED, lir::Register* dst) { assert(con, srcSize == dstSize); @@ -1863,14 +1852,14 @@ negateRR(Context* con, unsigned srcSize, Assembler::Register* src, } void -callR(Context* con, unsigned size UNUSED, Assembler::Register* target) +callR(Context* con, unsigned size UNUSED, lir::Register* target) { assert(con, size == TargetBytesPerWord); emit(con, blx(target->low)); } void -callC(Context* con, unsigned size UNUSED, Assembler::Constant* target) +callC(Context* con, unsigned size UNUSED, lir::Constant* target) { assert(con, size == TargetBytesPerWord); @@ -1879,27 +1868,27 @@ callC(Context* con, unsigned size UNUSED, Assembler::Constant* target) } void -longCallC(Context* con, unsigned size UNUSED, Assembler::Constant* target) +longCallC(Context* con, unsigned size UNUSED, lir::Constant* target) { assert(con, size == TargetBytesPerWord); - Assembler::Register tmp(4); + lir::Register tmp(4); moveCR2(con, TargetBytesPerWord, target, &tmp, offset(con)); callR(con, TargetBytesPerWord, &tmp); } void -longJumpC(Context* con, unsigned size UNUSED, Assembler::Constant* target) +longJumpC(Context* con, unsigned size UNUSED, lir::Constant* target) { assert(con, size == TargetBytesPerWord); - Assembler::Register tmp(4); // a non-arg reg that we don't mind clobbering + lir::Register tmp(4); // a non-arg reg that we don't mind clobbering moveCR2(con, TargetBytesPerWord, target, &tmp, offset(con)); jumpR(con, TargetBytesPerWord, &tmp); } void -jumpC(Context* con, unsigned size UNUSED, Assembler::Constant* target) +jumpC(Context* con, unsigned size UNUSED, lir::Constant* target) { assert(con, size == TargetBytesPerWord); @@ -1991,10 +1980,10 @@ nextFrame(ArchitectureContext* con, uint32_t* start, unsigned size UNUSED, void populateTables(ArchitectureContext* con) { - const OperandType C = ConstantOperand; - const OperandType A = AddressOperand; - const OperandType R = RegisterOperand; - const OperandType M = MemoryOperand; + const lir::OperandType C = lir::ConstantOperand; + const lir::OperandType A = lir::AddressOperand; + const lir::OperandType R = lir::RegisterOperand; + const lir::OperandType M = lir::MemoryOperand; OperationType* zo = con->operations; UnaryOperationType* uo = con->unaryOperations; @@ -2002,78 +1991,78 @@ populateTables(ArchitectureContext* con) TernaryOperationType* to = con->ternaryOperations; BranchOperationType* bro = con->branchOperations; - zo[Return] = return_; - zo[LoadBarrier] = memoryBarrier; - zo[StoreStoreBarrier] = memoryBarrier; - zo[StoreLoadBarrier] = memoryBarrier; - zo[Trap] = trap; + zo[lir::Return] = return_; + zo[lir::LoadBarrier] = memoryBarrier; + zo[lir::StoreStoreBarrier] = memoryBarrier; + zo[lir::StoreLoadBarrier] = memoryBarrier; + zo[lir::Trap] = trap; - uo[index(con, LongCall, C)] = CAST1(longCallC); + uo[index(con, lir::LongCall, C)] = CAST1(longCallC); - uo[index(con, AlignedLongCall, C)] = CAST1(longCallC); + uo[index(con, lir::AlignedLongCall, C)] = CAST1(longCallC); - uo[index(con, LongJump, C)] = CAST1(longJumpC); + uo[index(con, lir::LongJump, C)] = CAST1(longJumpC); - uo[index(con, AlignedLongJump, C)] = CAST1(longJumpC); + uo[index(con, lir::AlignedLongJump, C)] = CAST1(longJumpC); - uo[index(con, Jump, R)] = CAST1(jumpR); - uo[index(con, Jump, C)] = CAST1(jumpC); + uo[index(con, lir::Jump, R)] = CAST1(jumpR); + uo[index(con, lir::Jump, C)] = CAST1(jumpC); - uo[index(con, AlignedJump, R)] = CAST1(jumpR); - uo[index(con, AlignedJump, C)] = CAST1(jumpC); + uo[index(con, lir::AlignedJump, R)] = CAST1(jumpR); + uo[index(con, lir::AlignedJump, C)] = CAST1(jumpC); - uo[index(con, Call, C)] = CAST1(callC); - uo[index(con, Call, R)] = CAST1(callR); + uo[index(con, lir::Call, C)] = CAST1(callC); + uo[index(con, lir::Call, R)] = CAST1(callR); - uo[index(con, AlignedCall, C)] = CAST1(callC); - uo[index(con, AlignedCall, R)] = CAST1(callR); + uo[index(con, lir::AlignedCall, C)] = CAST1(callC); + uo[index(con, lir::AlignedCall, R)] = CAST1(callR); - bo[index(con, Move, R, R)] = CAST2(moveRR); - bo[index(con, Move, C, R)] = CAST2(moveCR); - bo[index(con, Move, C, M)] = CAST2(moveCM); - bo[index(con, Move, M, R)] = CAST2(moveMR); - bo[index(con, Move, R, M)] = CAST2(moveRM); - bo[index(con, Move, A, R)] = CAST2(moveAR); + bo[index(con, lir::Move, R, R)] = CAST2(moveRR); + bo[index(con, lir::Move, C, R)] = CAST2(moveCR); + bo[index(con, lir::Move, C, M)] = CAST2(moveCM); + bo[index(con, lir::Move, M, R)] = CAST2(moveMR); + bo[index(con, lir::Move, R, M)] = CAST2(moveRM); + bo[index(con, lir::Move, A, R)] = CAST2(moveAR); - bo[index(con, MoveZ, R, R)] = CAST2(moveZRR); - bo[index(con, MoveZ, M, R)] = CAST2(moveZMR); - bo[index(con, MoveZ, C, R)] = CAST2(moveCR); + bo[index(con, lir::MoveZ, R, R)] = CAST2(moveZRR); + bo[index(con, lir::MoveZ, M, R)] = CAST2(moveZMR); + bo[index(con, lir::MoveZ, C, R)] = CAST2(moveCR); - bo[index(con, Negate, R, R)] = CAST2(negateRR); + bo[index(con, lir::Negate, R, R)] = CAST2(negateRR); - bo[index(con, FloatAbsolute, R, R)] = CAST2(floatAbsoluteRR); - bo[index(con, FloatNegate, R, R)] = CAST2(floatNegateRR); - bo[index(con, Float2Float, R, R)] = CAST2(float2FloatRR); - bo[index(con, Float2Int, R, R)] = CAST2(float2IntRR); - bo[index(con, Int2Float, R, R)] = CAST2(int2FloatRR); - bo[index(con, FloatSquareRoot, R, R)] = CAST2(floatSqrtRR); + bo[index(con, lir::FloatAbsolute, R, R)] = CAST2(floatAbsoluteRR); + bo[index(con, lir::FloatNegate, R, R)] = CAST2(floatNegateRR); + bo[index(con, lir::Float2Float, R, R)] = CAST2(float2FloatRR); + bo[index(con, lir::Float2Int, R, R)] = CAST2(float2IntRR); + bo[index(con, lir::Int2Float, R, R)] = CAST2(int2FloatRR); + bo[index(con, lir::FloatSquareRoot, R, R)] = CAST2(floatSqrtRR); - to[index(con, Add, R)] = CAST3(addR); + to[index(con, lir::Add, R)] = CAST3(addR); - to[index(con, Subtract, R)] = CAST3(subR); + to[index(con, lir::Subtract, R)] = CAST3(subR); - to[index(con, Multiply, R)] = CAST3(multiplyR); + to[index(con, lir::Multiply, R)] = CAST3(multiplyR); - to[index(con, FloatAdd, R)] = CAST3(floatAddR); - to[index(con, FloatSubtract, R)] = CAST3(floatSubtractR); - to[index(con, FloatMultiply, R)] = CAST3(floatMultiplyR); - to[index(con, FloatDivide, R)] = CAST3(floatDivideR); + to[index(con, lir::FloatAdd, R)] = CAST3(floatAddR); + to[index(con, lir::FloatSubtract, R)] = CAST3(floatSubtractR); + to[index(con, lir::FloatMultiply, R)] = CAST3(floatMultiplyR); + to[index(con, lir::FloatDivide, R)] = CAST3(floatDivideR); - to[index(con, ShiftLeft, R)] = CAST3(shiftLeftR); - to[index(con, ShiftLeft, C)] = CAST3(shiftLeftC); + to[index(con, lir::ShiftLeft, R)] = CAST3(shiftLeftR); + to[index(con, lir::ShiftLeft, C)] = CAST3(shiftLeftC); - to[index(con, ShiftRight, R)] = CAST3(shiftRightR); - to[index(con, ShiftRight, C)] = CAST3(shiftRightC); + to[index(con, lir::ShiftRight, R)] = CAST3(shiftRightR); + to[index(con, lir::ShiftRight, C)] = CAST3(shiftRightC); - to[index(con, UnsignedShiftRight, R)] = CAST3(unsignedShiftRightR); - to[index(con, UnsignedShiftRight, C)] = CAST3(unsignedShiftRightC); + to[index(con, lir::UnsignedShiftRight, R)] = CAST3(unsignedShiftRightR); + to[index(con, lir::UnsignedShiftRight, C)] = CAST3(unsignedShiftRightC); - to[index(con, And, R)] = CAST3(andR); - to[index(con, And, C)] = CAST3(andC); + to[index(con, lir::And, R)] = CAST3(andR); + to[index(con, lir::And, C)] = CAST3(andC); - to[index(con, Or, R)] = CAST3(orR); + to[index(con, lir::Or, R)] = CAST3(orR); - to[index(con, Xor, R)] = CAST3(xorR); + to[index(con, lir::Xor, R)] = CAST3(xorR); bro[branchIndex(con, R, R)] = CAST_BRANCH(branchRR); bro[branchIndex(con, C, R)] = CAST_BRANCH(branchCR); @@ -2198,23 +2187,23 @@ class MyArchitecture: public Assembler::Architecture { - reinterpret_cast(instruction))); } - virtual void updateCall(UnaryOperation op UNUSED, + virtual void updateCall(lir::UnaryOperation op UNUSED, void* returnAddress, void* newTarget) { switch (op) { - case Call: - case Jump: - case AlignedCall: - case AlignedJump: { + case lir::Call: + case lir::Jump: + case lir::AlignedCall: + case lir::AlignedJump: { updateOffset(con.s, static_cast(returnAddress) - 4, reinterpret_cast(newTarget)); } break; - case LongCall: - case LongJump: - case AlignedLongCall: - case AlignedLongJump: { + case lir::LongCall: + case lir::LongJump: + case lir::AlignedLongCall: + case lir::AlignedLongJump: { uint32_t* p = static_cast(returnAddress) - 2; *reinterpret_cast(p + (((*p & PoolOffsetMask) + 8) / 4)) = newTarget; @@ -2270,34 +2259,34 @@ class MyArchitecture: public Assembler::Architecture { return 0; } - virtual BinaryOperation hasBinaryIntrinsic(Thread*, object) { - return NoBinaryOperation; + virtual lir::BinaryOperation hasBinaryIntrinsic(Thread*, object) { + return lir::NoBinaryOperation; } - virtual TernaryOperation hasTernaryIntrinsic(Thread*, object) { - return NoTernaryOperation; + virtual lir::TernaryOperation hasTernaryIntrinsic(Thread*, object) { + return lir::NoTernaryOperation; } - virtual bool alwaysCondensed(BinaryOperation) { + virtual bool alwaysCondensed(lir::BinaryOperation) { return false; } - virtual bool alwaysCondensed(TernaryOperation) { + virtual bool alwaysCondensed(lir::TernaryOperation) { return false; } virtual void plan - (UnaryOperation, + (lir::UnaryOperation, unsigned, uint8_t* aTypeMask, uint64_t* aRegisterMask, bool* thunk) { - *aTypeMask = (1 << RegisterOperand) | (1 << ConstantOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::ConstantOperand); *aRegisterMask = ~static_cast(0); *thunk = false; } virtual void planSource - (BinaryOperation op, + (lir::BinaryOperation op, unsigned aSize, uint8_t* aTypeMask, uint64_t* aRegisterMask, unsigned bSize, bool* thunk) { @@ -2306,43 +2295,43 @@ class MyArchitecture: public Assembler::Architecture { *aRegisterMask = GPR_MASK64; switch (op) { - case Negate: - *aTypeMask = (1 << RegisterOperand); + case lir::Negate: + *aTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = GPR_MASK64; break; - case Absolute: + case lir::Absolute: *thunk = true; break; - case FloatAbsolute: - case FloatSquareRoot: - case FloatNegate: - case Float2Float: + case lir::FloatAbsolute: + case lir::FloatSquareRoot: + case lir::FloatNegate: + case lir::Float2Float: if (vfpSupported()) { - *aTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = FPR_MASK64; } else { *thunk = true; } break; - case Float2Int: + case lir::Float2Int: // todo: Java requires different semantics than SSE for // converting floats to integers, we we need to either use // thunks or produce inline machine code which handles edge // cases properly. if (false && vfpSupported() && bSize == 4) { - *aTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = FPR_MASK64; } else { *thunk = true; } break; - case Int2Float: + case lir::Int2Float: if (vfpSupported() && aSize == 4) { - *aTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = GPR_MASK64; } else { *thunk = true; @@ -2355,36 +2344,36 @@ class MyArchitecture: public Assembler::Architecture { } virtual void planDestination - (BinaryOperation op, + (lir::BinaryOperation op, unsigned, uint8_t aTypeMask, uint64_t, unsigned , uint8_t* bTypeMask, uint64_t* bRegisterMask) { - *bTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); + *bTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand); *bRegisterMask = GPR_MASK64; switch (op) { - case Negate: - *bTypeMask = (1 << RegisterOperand); + case lir::Negate: + *bTypeMask = (1 << lir::RegisterOperand); *bRegisterMask = GPR_MASK64; break; - case FloatAbsolute: - case FloatSquareRoot: - case FloatNegate: - case Float2Float: - case Int2Float: - *bTypeMask = (1 << RegisterOperand); + case lir::FloatAbsolute: + case lir::FloatSquareRoot: + case lir::FloatNegate: + case lir::Float2Float: + case lir::Int2Float: + *bTypeMask = (1 << lir::RegisterOperand); *bRegisterMask = FPR_MASK64; break; - case Float2Int: - *bTypeMask = (1 << RegisterOperand); + case lir::Float2Int: + *bTypeMask = (1 << lir::RegisterOperand); *bRegisterMask = GPR_MASK64; break; - case Move: - if (!(aTypeMask & 1 << RegisterOperand)) { - *bTypeMask = 1 << RegisterOperand; + case lir::Move: + if (!(aTypeMask & 1 << lir::RegisterOperand)) { + *bTypeMask = 1 << lir::RegisterOperand; } break; @@ -2404,79 +2393,79 @@ class MyArchitecture: public Assembler::Architecture { *tmpTypeMask = 0; *tmpRegisterMask = 0; - if (dstTypeMask & (1 << MemoryOperand)) { + if (dstTypeMask & (1 << lir::MemoryOperand)) { // can't move directly from memory or constant to memory - *srcTypeMask = 1 << RegisterOperand; - *tmpTypeMask = 1 << RegisterOperand; + *srcTypeMask = 1 << lir::RegisterOperand; + *tmpTypeMask = 1 << lir::RegisterOperand; *tmpRegisterMask = GPR_MASK64; } else if (vfpSupported() && - dstTypeMask & 1 << RegisterOperand && + dstTypeMask & 1 << lir::RegisterOperand && dstRegisterMask & FPR_MASK) { - *srcTypeMask = *tmpTypeMask = 1 << RegisterOperand | - 1 << MemoryOperand; + *srcTypeMask = *tmpTypeMask = 1 << lir::RegisterOperand | + 1 << lir::MemoryOperand; *tmpRegisterMask = ~static_cast(0); } } virtual void planSource - (TernaryOperation op, + (lir::TernaryOperation op, unsigned, uint8_t* aTypeMask, uint64_t* aRegisterMask, unsigned bSize, uint8_t* bTypeMask, uint64_t* bRegisterMask, unsigned, bool* thunk) { - *aTypeMask = (1 << RegisterOperand) | (1 << ConstantOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::ConstantOperand); *aRegisterMask = GPR_MASK64; - *bTypeMask = (1 << RegisterOperand); + *bTypeMask = (1 << lir::RegisterOperand); *bRegisterMask = GPR_MASK64; *thunk = false; switch (op) { - case ShiftLeft: - case ShiftRight: - case UnsignedShiftRight: - if (bSize == 8) *aTypeMask = *bTypeMask = (1 << RegisterOperand); + case lir::ShiftLeft: + case lir::ShiftRight: + case lir::UnsignedShiftRight: + if (bSize == 8) *aTypeMask = *bTypeMask = (1 << lir::RegisterOperand); break; - case Add: - case Subtract: - case Or: - case Xor: - case Multiply: - *aTypeMask = *bTypeMask = (1 << RegisterOperand); + case lir::Add: + case lir::Subtract: + case lir::Or: + case lir::Xor: + case lir::Multiply: + *aTypeMask = *bTypeMask = (1 << lir::RegisterOperand); break; - case Divide: - case Remainder: - case FloatRemainder: + case lir::Divide: + case lir::Remainder: + case lir::FloatRemainder: *thunk = true; break; - case FloatAdd: - case FloatSubtract: - case FloatMultiply: - case FloatDivide: + case lir::FloatAdd: + case lir::FloatSubtract: + case lir::FloatMultiply: + case lir::FloatDivide: if (vfpSupported()) { - *aTypeMask = *bTypeMask = (1 << RegisterOperand); + *aTypeMask = *bTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = *bRegisterMask = FPR_MASK64; } else { *thunk = true; } break; - case JumpIfFloatEqual: - case JumpIfFloatNotEqual: - case JumpIfFloatLess: - case JumpIfFloatGreater: - case JumpIfFloatLessOrEqual: - case JumpIfFloatGreaterOrEqual: - case JumpIfFloatLessOrUnordered: - case JumpIfFloatGreaterOrUnordered: - case JumpIfFloatLessOrEqualOrUnordered: - case JumpIfFloatGreaterOrEqualOrUnordered: + case lir::JumpIfFloatEqual: + case lir::JumpIfFloatNotEqual: + case lir::JumpIfFloatLess: + case lir::JumpIfFloatGreater: + case lir::JumpIfFloatLessOrEqual: + case lir::JumpIfFloatGreaterOrEqual: + case lir::JumpIfFloatLessOrUnordered: + case lir::JumpIfFloatGreaterOrUnordered: + case lir::JumpIfFloatLessOrEqualOrUnordered: + case lir::JumpIfFloatGreaterOrEqualOrUnordered: if (vfpSupported()) { - *aTypeMask = *bTypeMask = (1 << RegisterOperand); + *aTypeMask = *bTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = *bRegisterMask = FPR_MASK64; } else { *thunk = true; @@ -2489,16 +2478,16 @@ class MyArchitecture: public Assembler::Architecture { } virtual void planDestination - (TernaryOperation op, + (lir::TernaryOperation op, unsigned, uint8_t, uint64_t, unsigned, uint8_t, const uint64_t bRegisterMask, unsigned, uint8_t* cTypeMask, uint64_t* cRegisterMask) { if (isBranch(op)) { - *cTypeMask = (1 << ConstantOperand); + *cTypeMask = (1 << lir::ConstantOperand); *cRegisterMask = 0; } else { - *cTypeMask = (1 << RegisterOperand); + *cTypeMask = (1 << lir::RegisterOperand); *cRegisterMask = bRegisterMask; } } @@ -2537,28 +2526,28 @@ class MyAssembler: public Assembler { virtual void checkStackOverflow(uintptr_t handler, unsigned stackLimitOffsetFromThread) { - Register stack(StackRegister); - Memory stackLimit(ThreadRegister, stackLimitOffsetFromThread); - Constant handlerConstant(new(con.zone) ResolvedPromise(handler)); - branchRM(&con, JumpIfGreaterOrEqual, TargetBytesPerWord, &stack, &stackLimit, + lir::Register stack(StackRegister); + lir::Memory stackLimit(ThreadRegister, stackLimitOffsetFromThread); + lir::Constant handlerConstant(new(con.zone) ResolvedPromise(handler)); + branchRM(&con, lir::JumpIfGreaterOrEqual, TargetBytesPerWord, &stack, &stackLimit, &handlerConstant); } virtual void saveFrame(unsigned stackOffset, unsigned ipOffset) { - Register link(LinkRegister); - Memory linkDst(ThreadRegister, ipOffset); + lir::Register link(LinkRegister); + lir::Memory linkDst(ThreadRegister, ipOffset); moveRM(&con, TargetBytesPerWord, &link, TargetBytesPerWord, &linkDst); - Register stack(StackRegister); - Memory stackDst(ThreadRegister, stackOffset); + lir::Register stack(StackRegister); + lir::Memory stackDst(ThreadRegister, stackOffset); moveRM(&con, TargetBytesPerWord, &stack, TargetBytesPerWord, &stackDst); } virtual void pushFrame(unsigned argumentCount, ...) { struct Argument { unsigned size; - OperandType type; - Operand* operand; + lir::OperandType type; + lir::Operand* operand; }; RUNTIME_ARRAY(Argument, arguments, argumentCount); @@ -2566,8 +2555,8 @@ class MyAssembler: public Assembler { unsigned footprint = 0; for (unsigned i = 0; i < argumentCount; ++i) { RUNTIME_ARRAY_BODY(arguments)[i].size = va_arg(a, unsigned); - RUNTIME_ARRAY_BODY(arguments)[i].type = static_cast(va_arg(a, int)); - RUNTIME_ARRAY_BODY(arguments)[i].operand = va_arg(a, Operand*); + RUNTIME_ARRAY_BODY(arguments)[i].type = static_cast(va_arg(a, int)); + RUNTIME_ARRAY_BODY(arguments)[i].operand = va_arg(a, lir::Operand*); footprint += ceilingDivide(RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord); } va_end(a); @@ -2577,24 +2566,27 @@ class MyAssembler: public Assembler { unsigned offset = 0; for (unsigned i = 0; i < argumentCount; ++i) { if (i < arch_->argumentRegisterCount()) { - Register dst(arch_->argumentRegister(i)); + lir::Register dst(arch_->argumentRegister(i)); - apply(Move, - RUNTIME_ARRAY_BODY(arguments)[i].size, - RUNTIME_ARRAY_BODY(arguments)[i].type, - RUNTIME_ARRAY_BODY(arguments)[i].operand, - pad(RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord), RegisterOperand, - &dst); + apply(lir::Move, + OperandInfo( + RUNTIME_ARRAY_BODY(arguments)[i].size, + RUNTIME_ARRAY_BODY(arguments)[i].type, + RUNTIME_ARRAY_BODY(arguments)[i].operand), + OperandInfo( + pad(RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord), lir::RegisterOperand, &dst)); offset += ceilingDivide(RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord); } else { - Memory dst(StackRegister, offset * TargetBytesPerWord); + lir::Memory dst(StackRegister, offset * TargetBytesPerWord); - apply(Move, - RUNTIME_ARRAY_BODY(arguments)[i].size, - RUNTIME_ARRAY_BODY(arguments)[i].type, - RUNTIME_ARRAY_BODY(arguments)[i].operand, - pad(RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord), MemoryOperand, &dst); + apply(lir::Move, + OperandInfo( + RUNTIME_ARRAY_BODY(arguments)[i].size, + RUNTIME_ARRAY_BODY(arguments)[i].type, + RUNTIME_ARRAY_BODY(arguments)[i].operand), + OperandInfo( + pad(RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord), lir::MemoryOperand, &dst)); offset += ceilingDivide(RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord); } @@ -2609,37 +2601,37 @@ class MyAssembler: public Assembler { // how to handle them: assert(&con, footprint < 256); - Register stack(StackRegister); + lir::Register stack(StackRegister); ResolvedPromise footprintPromise(footprint * TargetBytesPerWord); - Constant footprintConstant(&footprintPromise); + lir::Constant footprintConstant(&footprintPromise); subC(&con, TargetBytesPerWord, &footprintConstant, &stack, &stack); - Register returnAddress(LinkRegister); - Memory returnAddressDst + lir::Register returnAddress(LinkRegister); + lir::Memory returnAddressDst (StackRegister, (footprint - 1) * TargetBytesPerWord); moveRM(&con, TargetBytesPerWord, &returnAddress, TargetBytesPerWord, &returnAddressDst); } virtual void adjustFrame(unsigned difference) { - Register stack(StackRegister); + lir::Register stack(StackRegister); ResolvedPromise differencePromise(difference * TargetBytesPerWord); - Constant differenceConstant(&differencePromise); + lir::Constant differenceConstant(&differencePromise); subC(&con, TargetBytesPerWord, &differenceConstant, &stack, &stack); } virtual void popFrame(unsigned footprint) { footprint += FrameHeaderSize; - Register returnAddress(LinkRegister); - Memory returnAddressSrc + lir::Register returnAddress(LinkRegister); + lir::Memory returnAddressSrc (StackRegister, (footprint - 1) * TargetBytesPerWord); moveMR(&con, TargetBytesPerWord, &returnAddressSrc, TargetBytesPerWord, &returnAddress); - Register stack(StackRegister); + lir::Register stack(StackRegister); ResolvedPromise footprintPromise(footprint * TargetBytesPerWord); - Constant footprintConstant(&footprintPromise); + lir::Constant footprintConstant(&footprintPromise); addC(&con, TargetBytesPerWord, &footprintConstant, &stack, &stack); } @@ -2648,29 +2640,29 @@ class MyAssembler: public Assembler { int returnAddressSurrogate, int framePointerSurrogate UNUSED) { - assert(&con, framePointerSurrogate == NoRegister); + assert(&con, framePointerSurrogate == lir::NoRegister); if (TailCalls) { if (offset) { footprint += FrameHeaderSize; - Register link(LinkRegister); - Memory returnAddressSrc + lir::Register link(LinkRegister); + lir::Memory returnAddressSrc (StackRegister, (footprint - 1) * TargetBytesPerWord); moveMR(&con, TargetBytesPerWord, &returnAddressSrc, TargetBytesPerWord, &link); - Register stack(StackRegister); + lir::Register stack(StackRegister); ResolvedPromise footprintPromise ((footprint - offset) * TargetBytesPerWord); - Constant footprintConstant(&footprintPromise); + lir::Constant footprintConstant(&footprintPromise); addC(&con, TargetBytesPerWord, &footprintConstant, &stack, &stack); - if (returnAddressSurrogate != NoRegister) { + if (returnAddressSurrogate != lir::NoRegister) { assert(&con, offset > 0); - Register ras(returnAddressSurrogate); - Memory dst(StackRegister, (offset - 1) * TargetBytesPerWord); + lir::Register ras(returnAddressSurrogate); + lir::Memory dst(StackRegister, (offset - 1) * TargetBytesPerWord); moveRM(&con, TargetBytesPerWord, &ras, TargetBytesPerWord, &dst); } } else { @@ -2693,9 +2685,9 @@ class MyAssembler: public Assembler { if (TailCalls and argumentFootprint > StackAlignmentInWords) { offset = argumentFootprint - StackAlignmentInWords; - Register stack(StackRegister); + lir::Register stack(StackRegister); ResolvedPromise adjustmentPromise(offset * TargetBytesPerWord); - Constant adjustment(&adjustmentPromise); + lir::Constant adjustment(&adjustmentPromise); addC(&con, TargetBytesPerWord, &adjustment, &stack, &stack); } else { offset = 0; @@ -2709,53 +2701,45 @@ class MyAssembler: public Assembler { { popFrame(frameFootprint); - Register stack(StackRegister); - Memory newStackSrc(ThreadRegister, stackOffsetFromThread); + lir::Register stack(StackRegister); + lir::Memory newStackSrc(ThreadRegister, stackOffsetFromThread); moveMR(&con, TargetBytesPerWord, &newStackSrc, TargetBytesPerWord, &stack); return_(&con); } - virtual void apply(Operation op) { + virtual void apply(lir::Operation op) { arch_->con.operations[op](&con); } - virtual void apply(UnaryOperation op, - unsigned aSize, OperandType aType, Operand* aOperand) + virtual void apply(lir::UnaryOperation op, OperandInfo a) { - arch_->con.unaryOperations[index(&(arch_->con), op, aType)] - (&con, aSize, aOperand); + arch_->con.unaryOperations[index(&(arch_->con), op, a.type)] + (&con, a.size, a.operand); } - virtual void apply(BinaryOperation op, - unsigned aSize, OperandType aType, Operand* aOperand, - unsigned bSize, OperandType bType, Operand* bOperand) + virtual void apply(lir::BinaryOperation op, OperandInfo a, OperandInfo b) { - arch_->con.binaryOperations[index(&(arch_->con), op, aType, bType)] - (&con, aSize, aOperand, bSize, bOperand); + arch_->con.binaryOperations[index(&(arch_->con), op, a.type, b.type)] + (&con, a.size, a.operand, b.size, b.operand); } - virtual void apply(TernaryOperation op, - unsigned aSize, OperandType aType, Operand* aOperand, - unsigned bSize, OperandType bType UNUSED, - Operand* bOperand, - unsigned cSize UNUSED, OperandType cType UNUSED, - Operand* cOperand) + virtual void apply(lir::TernaryOperation op, OperandInfo a, OperandInfo b, OperandInfo c) { if (isBranch(op)) { - assert(&con, aSize == bSize); - assert(&con, cSize == TargetBytesPerWord); - assert(&con, cType == ConstantOperand); + assert(&con, a.size == b.size); + assert(&con, c.size == TargetBytesPerWord); + assert(&con, c.type == lir::ConstantOperand); - arch_->con.branchOperations[branchIndex(&(arch_->con), aType, bType)] - (&con, op, aSize, aOperand, bOperand, cOperand); + arch_->con.branchOperations[branchIndex(&(arch_->con), a.type, b.type)] + (&con, op, a.size, a.operand, b.operand, c.operand); } else { - assert(&con, bSize == cSize); - assert(&con, bType == RegisterOperand); - assert(&con, cType == RegisterOperand); + assert(&con, b.size == c.size); + assert(&con, b.type == lir::RegisterOperand); + assert(&con, c.type == lir::RegisterOperand); - arch_->con.ternaryOperations[index(&(arch_->con), op, aType)] - (&con, bSize, aOperand, bOperand, cOperand); + arch_->con.ternaryOperations[index(&(arch_->con), op, a.type)] + (&con, b.size, a.operand, b.operand, c.operand); } } diff --git a/src/codegen/assembler.h b/src/codegen/assembler.h index fbe03b70ac..d6ef7dd262 100644 --- a/src/codegen/assembler.h +++ b/src/codegen/assembler.h @@ -8,13 +8,30 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#ifndef ASSEMBLER_H -#define ASSEMBLER_H +#ifndef AVIAN_CODEGEN_ASSEMBLER_H +#define AVIAN_CODEGEN_ASSEMBLER_H #include "system.h" #include "zone.h" -namespace vm { +#include "codegen/lir.h" +#include "codegen/promise.h" + +namespace avian { +namespace codegen { + +class OperandInfo { +public: + const unsigned size; + const lir::OperandType type; + lir::Operand* const operand; + + inline OperandInfo(unsigned size, lir::OperandType type, lir::Operand* operand): + size(size), + type(type), + operand(operand) + { } +}; #ifdef AVIAN_TAILS const bool TailCalls = true; @@ -28,286 +45,8 @@ const bool UseFramePointer = true; const bool UseFramePointer = false; #endif -enum Operation { - Return, - LoadBarrier, - StoreStoreBarrier, - StoreLoadBarrier, - Trap -}; - -const unsigned OperationCount = Trap + 1; - -enum UnaryOperation { - Call, - LongCall, - AlignedLongCall, - AlignedCall, - Jump, - LongJump, - AlignedLongJump, - AlignedJump, - - NoUnaryOperation = -1 -}; - -const unsigned UnaryOperationCount = AlignedJump + 1; - -enum BinaryOperation { - Move, - MoveLow, - MoveHigh, - MoveZ, - Negate, - FloatNegate, - Float2Float, - Float2Int, - Int2Float, - FloatSquareRoot, - FloatAbsolute, - Absolute, - - NoBinaryOperation = -1 -}; - -const unsigned BinaryOperationCount = Absolute + 1; - -enum TernaryOperation { - Add, - Subtract, - Multiply, - Divide, - Remainder, - ShiftLeft, - ShiftRight, - UnsignedShiftRight, - And, - Or, - Xor, - FloatAdd, - FloatSubtract, - FloatMultiply, - FloatDivide, - FloatRemainder, - FloatMax, - FloatMin, - JumpIfLess, - JumpIfGreater, - JumpIfLessOrEqual, - JumpIfGreaterOrEqual, - JumpIfEqual, - JumpIfNotEqual, - JumpIfFloatEqual, - JumpIfFloatNotEqual, - JumpIfFloatLess, - JumpIfFloatGreater, - JumpIfFloatLessOrEqual, - JumpIfFloatGreaterOrEqual, - JumpIfFloatLessOrUnordered, - JumpIfFloatGreaterOrUnordered, - JumpIfFloatLessOrEqualOrUnordered, - JumpIfFloatGreaterOrEqualOrUnordered, - - NoTernaryOperation = -1 -}; - -const unsigned TernaryOperationCount -= JumpIfFloatGreaterOrEqualOrUnordered + 1; - -const unsigned NonBranchTernaryOperationCount = FloatMin + 1; -const unsigned BranchOperationCount -= JumpIfFloatGreaterOrEqualOrUnordered - FloatMin; - -enum OperandType { - ConstantOperand, - AddressOperand, - RegisterOperand, - MemoryOperand -}; - -enum ValueType { - ValueGeneral, - ValueFloat -}; - -const unsigned OperandTypeCount = MemoryOperand + 1; - -const int NoRegister = -1; - -class Promise { - public: - class Listener { - public: - virtual bool resolve(int64_t value, void** location) = 0; - - Listener* next; - }; - - virtual int64_t value() = 0; - virtual bool resolved() = 0; - virtual Listener* listen(unsigned) { return 0; } -}; - -class ResolvedPromise: public Promise { - public: - ResolvedPromise(int64_t value): value_(value) { } - - virtual int64_t value() { - return value_; - } - - virtual bool resolved() { - return true; - } - - int64_t value_; -}; - -class ShiftMaskPromise: public Promise { - public: - ShiftMaskPromise(Promise* base, unsigned shift, int64_t mask): - base(base), shift(shift), mask(mask) - { } - - virtual int64_t value() { - return (base->value() >> shift) & mask; - } - - virtual bool resolved() { - return base->resolved(); - } - - Promise* base; - unsigned shift; - int64_t mask; -}; - -class CombinedPromise: public Promise { - public: - CombinedPromise(Promise* low, Promise* high): - low(low), high(high) - { } - - virtual int64_t value() { - return low->value() | (high->value() << 32); - } - - virtual bool resolved() { - return low->resolved() and high->resolved(); - } - - Promise* low; - Promise* high; -}; - -class OffsetPromise: public Promise { - public: - OffsetPromise(Promise* base, int64_t offset): - base(base), offset(offset) - { } - - virtual int64_t value() { - return base->value() + offset; - } - - virtual bool resolved() { - return base->resolved(); - } - - Promise* base; - int64_t offset; -}; - -class ListenPromise: public Promise { - public: - ListenPromise(System* s, Allocator* allocator): - s(s), allocator(allocator), listener(0) - { } - - virtual int64_t value() { - abort(s); - } - - virtual bool resolved() { - return false; - } - - virtual Listener* listen(unsigned sizeInBytes) { - Listener* l = static_cast(allocator->allocate(sizeInBytes)); - l->next = listener; - listener = l; - return l; - } - - System* s; - Allocator* allocator; - Listener* listener; - Promise* promise; -}; - -class DelayedPromise: public ListenPromise { - public: - DelayedPromise(System* s, Allocator* allocator, Promise* basis, - DelayedPromise* next): - ListenPromise(s, allocator), basis(basis), next(next) - { } - - virtual int64_t value() { - abort(s); - } - - virtual bool resolved() { - return false; - } - - virtual Listener* listen(unsigned sizeInBytes) { - Listener* l = static_cast(allocator->allocate(sizeInBytes)); - l->next = listener; - listener = l; - return l; - } - - Promise* basis; - DelayedPromise* next; -}; - class Assembler { public: - class Operand { }; - - class Constant: public Operand { - public: - Constant(Promise* value): value(value) { } - - Promise* value; - }; - - class Address: public Operand { - public: - Address(Promise* address): address(address) { } - - Promise* address; - }; - - class Register: public Operand { - public: - Register(int low, int high = NoRegister): low(low), high(high) { } - - int low; - int high; - }; - - class Memory: public Operand { - public: - Memory(int base, int offset, int index = NoRegister, unsigned scale = 1): - base(base), offset(offset), index(index), scale(scale) - { } - - int base; - int offset; - int index; - unsigned scale; - }; class Client { public: @@ -342,8 +81,8 @@ class Assembler { virtual uintptr_t maximumImmediateJump() = 0; - virtual bool alwaysCondensed(BinaryOperation op) = 0; - virtual bool alwaysCondensed(TernaryOperation op) = 0; + virtual bool alwaysCondensed(lir::BinaryOperation op) = 0; + virtual bool alwaysCondensed(lir::TernaryOperation op) = 0; virtual bool reserved(int register_) = 0; @@ -360,7 +99,7 @@ class Assembler { virtual bool matchCall(void* returnAddress, void* target) = 0; - virtual void updateCall(UnaryOperation op, void* returnAddress, + virtual void updateCall(lir::UnaryOperation op, void* returnAddress, void* newTarget) = 0; virtual void setConstant(void* dst, uint64_t constant) = 0; @@ -379,17 +118,17 @@ class Assembler { virtual int framePointerOffset() = 0; virtual void plan - (UnaryOperation op, + (lir::UnaryOperation op, unsigned aSize, uint8_t* aTypeMask, uint64_t* aRegisterMask, bool* thunk) = 0; virtual void planSource - (BinaryOperation op, + (lir::BinaryOperation op, unsigned aSize, uint8_t* aTypeMask, uint64_t* aRegisterMask, unsigned bSize, bool* thunk) = 0; virtual void planDestination - (BinaryOperation op, + (lir::BinaryOperation op, unsigned aSize, uint8_t aTypeMask, uint64_t aRegisterMask, unsigned bSize, uint8_t* bTypeMask, uint64_t* bRegisterMask) = 0; @@ -399,18 +138,18 @@ class Assembler { uint8_t dstTypeMask, uint64_t dstRegisterMask) = 0; virtual void planSource - (TernaryOperation op, + (lir::TernaryOperation op, unsigned aSize, uint8_t* aTypeMask, uint64_t* aRegisterMask, unsigned bSize, uint8_t* bTypeMask, uint64_t* bRegisterMask, unsigned cSize, bool* thunk) = 0; virtual void planDestination - (TernaryOperation op, + (lir::TernaryOperation op, unsigned aSize, uint8_t aTypeMask, uint64_t aRegisterMask, unsigned bSize, uint8_t bTypeMask, uint64_t bRegisterMask, unsigned cSize, uint8_t* cTypeMask, uint64_t* cRegisterMask) = 0; - virtual Assembler* makeAssembler(Allocator*, Zone*) = 0; + virtual Assembler* makeAssembler(vm::Allocator*, vm::Zone*) = 0; virtual void acquire() = 0; virtual void release() = 0; @@ -437,19 +176,10 @@ class Assembler { unsigned stackOffsetFromThread) = 0; - virtual void apply(Operation op) = 0; - - virtual void apply(UnaryOperation op, - unsigned aSize, OperandType aType, Operand* aOperand) = 0; - - virtual void apply(BinaryOperation op, - unsigned aSize, OperandType aType, Operand* aOperand, - unsigned bSize, OperandType bType, Operand* bOperand) = 0; - - virtual void apply(TernaryOperation op, - unsigned aSize, OperandType aType, Operand* aOperand, - unsigned bSize, OperandType bType, Operand* bOperand, - unsigned cSize, OperandType cType, Operand* cOperand) = 0; + virtual void apply(lir::Operation op) = 0; + virtual void apply(lir::UnaryOperation op, OperandInfo a) = 0; + virtual void apply(lir::BinaryOperation op, OperandInfo a, OperandInfo b) = 0; + virtual void apply(lir::TernaryOperation op, OperandInfo a, OperandInfo b, OperandInfo c) = 0; virtual void setDestination(uint8_t* dst) = 0; @@ -468,6 +198,7 @@ class Assembler { virtual void dispose() = 0; }; -} // namespace vm +} // namespace codegen +} // namespace avian -#endif//ASSEMBLER_H +#endif // AVIAN_CODEGEN_ASSEMBLER_H diff --git a/src/codegen/compiler.cpp b/src/codegen/compiler.cpp index 90efb622b8..ae8e6dd269 100644 --- a/src/codegen/compiler.cpp +++ b/src/codegen/compiler.cpp @@ -15,6 +15,7 @@ #include "util/runtime-array.h" using namespace vm; +using namespace avian::codegen; namespace { @@ -64,16 +65,16 @@ class Snapshot; void NO_RETURN abort(Context*); void -apply(Context* c, UnaryOperation op, +apply(Context* c, lir::UnaryOperation op, unsigned s1Size, Site* s1Low, Site* s1High); void -apply(Context* c, BinaryOperation op, +apply(Context* c, lir::BinaryOperation op, unsigned s1Size, Site* s1Low, Site* s1High, unsigned s2Size, Site* s2Low, Site* s2High); void -apply(Context* c, TernaryOperation op, +apply(Context* c, lir::TernaryOperation op, unsigned s1Size, Site* s1Low, Site* s1High, unsigned s2Size, Site* s2Low, Site* s2High, unsigned s3Size, Site* s3Low, Site* s3High); @@ -130,9 +131,9 @@ class Site { virtual bool frozen(Context*) { return false; } - virtual OperandType type(Context*) = 0; + virtual lir::OperandType type(Context*) = 0; - virtual void asAssemblerOperand(Context*, Site*, Assembler::Operand*) = 0; + virtual void asAssemblerOperand(Context*, Site*, lir::Operand*) = 0; virtual Site* copy(Context*) = 0; @@ -320,7 +321,7 @@ intersect(const SiteMask& a, const SiteMask& b) class Value: public Compiler::Operand { public: - Value(Site* site, Site* target, ValueType type): + Value(Site* site, Site* target, lir::ValueType type): reads(0), lastRead(0), sites(site), source(0), target(target), buddy(this), nextWord(this), home(NoFrameIndex), type(type), wordIndex(0) { } @@ -333,7 +334,7 @@ class Value: public Compiler::Operand { Value* buddy; Value* nextWord; int16_t home; - ValueType type; + lir::ValueType type; uint8_t wordIndex; }; @@ -1279,16 +1280,16 @@ class Target { Target(): cost(Impossible) { } - Target(int index, OperandType type, unsigned cost): + Target(int index, lir::OperandType type, unsigned cost): index(index), type(type), cost(cost) { } int16_t index; - OperandType type; + lir::OperandType type; uint8_t cost; }; -ValueType +lir::ValueType valueType(Context* c, Compiler::OperandType type) { switch (type) { @@ -1296,9 +1297,9 @@ valueType(Context* c, Compiler::OperandType type) case Compiler::AddressType: case Compiler::IntegerType: case Compiler::VoidType: - return ValueGeneral; + return lir::ValueGeneral; case Compiler::FloatType: - return ValueFloat; + return lir::ValueFloat; default: abort(c); } @@ -1344,7 +1345,7 @@ pickRegisterTarget(Context* c, int i, Value* v, uint32_t mask, int* target, if ((1 << i) & mask) { RegisterResource* r = c->registerResources + i; unsigned myCost = resourceCost - (c, v, r, 1 << RegisterOperand, 1 << i, NoFrameIndex, costCalculator) + (c, v, r, 1 << lir::RegisterOperand, 1 << i, NoFrameIndex, costCalculator) + Target::MinimumRegisterCost; if ((static_cast(1) << i) == mask) { @@ -1362,7 +1363,7 @@ int pickRegisterTarget(Context* c, Value* v, uint32_t mask, unsigned* cost, CostCalculator* costCalculator = 0) { - int target = NoRegister; + int target = lir::NoRegister; *cost = Target::Impossible; if (mask & c->arch->generalRegisterMask()) { @@ -1394,14 +1395,14 @@ pickRegisterTarget(Context* c, Value* v, uint32_t mask, { unsigned cost; int number = pickRegisterTarget(c, v, mask, &cost, costCalculator); - return Target(number, RegisterOperand, cost); + return Target(number, lir::RegisterOperand, cost); } unsigned frameCost(Context* c, Value* v, int frameIndex, CostCalculator* costCalculator) { return resourceCost - (c, v, c->frameResources + frameIndex, 1 << MemoryOperand, 0, frameIndex, + (c, v, c->frameResources + frameIndex, 1 << lir::MemoryOperand, 0, frameIndex, costCalculator) + Target::MinimumFrameCost; } @@ -1415,7 +1416,7 @@ pickFrameTarget(Context* c, Value* v, CostCalculator* costCalculator) do { if (p->home >= 0) { Target mine - (p->home, MemoryOperand, frameCost(c, v, p->home, costCalculator)); + (p->home, lir::MemoryOperand, frameCost(c, v, p->home, costCalculator)); if (mine.cost == Target::MinimumFrameCost) { return mine; @@ -1436,7 +1437,7 @@ pickAnyFrameTarget(Context* c, Value* v, CostCalculator* costCalculator) unsigned count = totalFrameSize(c); for (unsigned i = 0; i < count; ++i) { - Target mine(i, MemoryOperand, frameCost(c, v, i, costCalculator)); + Target mine(i, lir::MemoryOperand, frameCost(c, v, i, costCalculator)); if (mine.cost == Target::MinimumFrameCost) { return mine; } else if (mine.cost < best.cost) { @@ -1452,7 +1453,7 @@ pickTarget(Context* c, Value* value, const SiteMask& mask, unsigned registerPenalty, Target best, CostCalculator* costCalculator) { - if (mask.typeMask & (1 << RegisterOperand)) { + if (mask.typeMask & (1 << lir::RegisterOperand)) { Target mine = pickRegisterTarget (c, value, mask.registerMask, costCalculator); @@ -1464,9 +1465,9 @@ pickTarget(Context* c, Value* value, const SiteMask& mask, } } - if (mask.typeMask & (1 << MemoryOperand)) { + if (mask.typeMask & (1 << lir::MemoryOperand)) { if (mask.frameIndex >= 0) { - Target mine(mask.frameIndex, MemoryOperand, + Target mine(mask.frameIndex, lir::MemoryOperand, frameCost(c, value, mask.frameIndex, costCalculator)); if (mine.cost == Target::MinimumFrameCost) { return mine; @@ -1497,12 +1498,12 @@ pickTarget(Context* c, Read* read, bool intersectRead, Value* value = read->value; uint32_t registerMask - = (value->type == ValueFloat ? ~0 : c->arch->generalRegisterMask()); + = (value->type == lir::ValueFloat ? ~0 : c->arch->generalRegisterMask()); SiteMask mask(~0, registerMask, AnyFrameIndex); read->intersect(&mask); - if (value->type == ValueFloat) { + if (value->type == lir::ValueFloat) { uint32_t floatMask = mask.registerMask & c->arch->floatRegisterMask(); if (floatMask) { mask.registerMask = floatMask; @@ -1616,7 +1617,7 @@ class ConstantSite: public Site { } virtual bool match(Context*, const SiteMask& mask) { - return mask.typeMask & (1 << ConstantOperand); + return mask.typeMask & (1 << lir::ConstantOperand); } virtual bool loneMatch(Context*, const SiteMask&) { @@ -1624,21 +1625,21 @@ class ConstantSite: public Site { } virtual bool matchNextWord(Context* c, Site* s, unsigned) { - return s->type(c) == ConstantOperand; + return s->type(c) == lir::ConstantOperand; } - virtual OperandType type(Context*) { - return ConstantOperand; + virtual lir::OperandType type(Context*) { + return lir::ConstantOperand; } virtual void asAssemblerOperand(Context* c, Site* high, - Assembler::Operand* result) + lir::Operand* result) { Promise* v = value; if (high != this) { v = combinedPromise(c, value, static_cast(high)->value); } - new (result) Assembler::Constant(v); + new (result) lir::Constant(v); } virtual Site* copy(Context* c) { @@ -1658,11 +1659,11 @@ class ConstantSite: public Site { } virtual SiteMask mask(Context*) { - return SiteMask(1 << ConstantOperand, 0, NoFrameIndex); + return SiteMask(1 << lir::ConstantOperand, 0, NoFrameIndex); } virtual SiteMask nextWordMask(Context*, unsigned) { - return SiteMask(1 << ConstantOperand, 0, NoFrameIndex); + return SiteMask(1 << lir::ConstantOperand, 0, NoFrameIndex); } Promise* value; @@ -1707,7 +1708,7 @@ class AddressSite: public Site { } virtual bool match(Context*, const SiteMask& mask) { - return mask.typeMask & (1 << AddressOperand); + return mask.typeMask & (1 << lir::AddressOperand); } virtual bool loneMatch(Context*, const SiteMask&) { @@ -1718,16 +1719,16 @@ class AddressSite: public Site { abort(c); } - virtual OperandType type(Context*) { - return AddressOperand; + virtual lir::OperandType type(Context*) { + return lir::AddressOperand; } virtual void asAssemblerOperand(Context* c UNUSED, Site* high UNUSED, - Assembler::Operand* result) + lir::Operand* result) { assert(c, high == this); - new (result) Assembler::Address(address); + new (result) lir::Address(address); } virtual Site* copy(Context* c) { @@ -1747,7 +1748,7 @@ class AddressSite: public Site { } virtual SiteMask mask(Context*) { - return SiteMask(1 << AddressOperand, 0, NoFrameIndex); + return SiteMask(1 << lir::AddressOperand, 0, NoFrameIndex); } virtual SiteMask nextWordMask(Context* c, unsigned) { @@ -1773,7 +1774,7 @@ class RegisterSite: public Site { { } virtual unsigned toString(Context*, char* buffer, unsigned bufferSize) { - if (number != NoRegister) { + if (number != lir::NoRegister) { return vm::snprintf(buffer, bufferSize, "%p register %d", this, number); } else { return vm::snprintf(buffer, bufferSize, @@ -1782,11 +1783,11 @@ class RegisterSite: public Site { } virtual unsigned copyCost(Context* c, Site* s) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); if (s and (this == s or - (s->type(c) == RegisterOperand + (s->type(c) == lir::RegisterOperand and (static_cast(s)->mask_ & (1 << number))))) { return 0; @@ -1796,9 +1797,9 @@ class RegisterSite: public Site { } virtual bool match(Context* c UNUSED, const SiteMask& mask) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); - if ((mask.typeMask & (1 << RegisterOperand))) { + if ((mask.typeMask & (1 << lir::RegisterOperand))) { return ((static_cast(1) << number) & mask.registerMask); } else { return false; @@ -1806,9 +1807,9 @@ class RegisterSite: public Site { } virtual bool loneMatch(Context* c UNUSED, const SiteMask& mask) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); - if ((mask.typeMask & (1 << RegisterOperand))) { + if ((mask.typeMask & (1 << lir::RegisterOperand))) { return ((static_cast(1) << number) == mask.registerMask); } else { return false; @@ -1816,16 +1817,16 @@ class RegisterSite: public Site { } virtual bool matchNextWord(Context* c, Site* s, unsigned) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); - if (s->type(c) != RegisterOperand) { + if (s->type(c) != lir::RegisterOperand) { return false; } RegisterSite* rs = static_cast(s); unsigned size = rs->registerSize(c); if (size > TargetBytesPerWord) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); return number == rs->number; } else { uint32_t mask = c->arch->generalRegisterMask(); @@ -1835,8 +1836,8 @@ class RegisterSite: public Site { virtual void acquire(Context* c, Value* v) { Target target; - if (number != NoRegister) { - target = Target(number, RegisterOperand, 0); + if (number != lir::NoRegister) { + target = Target(number, lir::RegisterOperand, 0); } else { target = pickRegisterTarget(c, v, mask_); expect(c, target.cost < Target::Impossible); @@ -1849,53 +1850,53 @@ class RegisterSite: public Site { } virtual void release(Context* c, Value* v) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); local::release(c, c->registerResources + number, v, this); } virtual void freeze(Context* c, Value* v) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); c->registerResources[number].freeze(c, v); } virtual void thaw(Context* c, Value* v) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); c->registerResources[number].thaw(c, v); } virtual bool frozen(Context* c UNUSED) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); return c->registerResources[number].freezeCount != 0; } - virtual OperandType type(Context*) { - return RegisterOperand; + virtual lir::OperandType type(Context*) { + return lir::RegisterOperand; } virtual void asAssemblerOperand(Context* c UNUSED, Site* high, - Assembler::Operand* result) + lir::Operand* result) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); int highNumber; if (high != this) { highNumber = static_cast(high)->number; - assert(c, highNumber != NoRegister); + assert(c, highNumber != lir::NoRegister); } else { - highNumber = NoRegister; + highNumber = lir::NoRegister; } - new (result) Assembler::Register(number, highNumber); + new (result) lir::Register(number, highNumber); } virtual Site* copy(Context* c) { uint32_t mask; - if (number != NoRegister) { + if (number != lir::NoRegister) { mask = 1 << number; } else { mask = mask_; @@ -1913,30 +1914,30 @@ class RegisterSite: public Site { } virtual Site* makeNextWord(Context* c, unsigned) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); assert(c, ((1 << number) & c->arch->generalRegisterMask())); return freeRegisterSite(c, c->arch->generalRegisterMask()); } virtual SiteMask mask(Context* c UNUSED) { - return SiteMask(1 << RegisterOperand, mask_, NoFrameIndex); + return SiteMask(1 << lir::RegisterOperand, mask_, NoFrameIndex); } virtual SiteMask nextWordMask(Context* c, unsigned) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); if (registerSize(c) > TargetBytesPerWord) { return SiteMask - (1 << RegisterOperand, number, NoFrameIndex); + (1 << lir::RegisterOperand, number, NoFrameIndex); } else { return SiteMask - (1 << RegisterOperand, c->arch->generalRegisterMask(), NoFrameIndex); + (1 << lir::RegisterOperand, c->arch->generalRegisterMask(), NoFrameIndex); } } virtual unsigned registerSize(Context* c) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); if ((1 << number) & c->arch->floatRegisterMask()) { return c->arch->floatRegisterSize(); @@ -1946,7 +1947,7 @@ class RegisterSite: public Site { } virtual unsigned registerMask(Context* c UNUSED) { - assert(c, number != NoRegister); + assert(c, number != lir::NoRegister); return 1 << number; } @@ -1968,11 +1969,11 @@ registerSite(Context* c, int number) RegisterSite* freeRegisterSite(Context* c, uint32_t mask) { - return new(c->zone) RegisterSite(mask, NoRegister); + return new(c->zone) RegisterSite(mask, lir::NoRegister); } MemorySite* -memorySite(Context* c, int base, int offset = 0, int index = NoRegister, +memorySite(Context* c, int base, int offset = 0, int index = lir::NoRegister, unsigned scale = 1); class MemorySite: public Site { @@ -1995,7 +1996,7 @@ class MemorySite: public Site { if (s and (this == s or - (s->type(c) == MemoryOperand + (s->type(c) == lir::MemoryOperand and static_cast(s)->base == base and static_cast(s)->offset == offset and static_cast(s)->index == index @@ -2008,19 +2009,19 @@ class MemorySite: public Site { } bool conflicts(const SiteMask& mask) { - return (mask.typeMask & (1 << RegisterOperand)) != 0 + return (mask.typeMask & (1 << lir::RegisterOperand)) != 0 and (((1 << base) & mask.registerMask) == 0 - or (index != NoRegister + or (index != lir::NoRegister and ((1 << index) & mask.registerMask) == 0)); } virtual bool match(Context* c, const SiteMask& mask) { assert(c, acquired); - if (mask.typeMask & (1 << MemoryOperand)) { + if (mask.typeMask & (1 << lir::MemoryOperand)) { if (mask.frameIndex >= 0) { if (base == c->arch->stack()) { - assert(c, index == NoRegister); + assert(c, index == lir::NoRegister); return static_cast(frameIndexToOffset(c, mask.frameIndex)) == offset; } else { @@ -2037,9 +2038,9 @@ class MemorySite: public Site { virtual bool loneMatch(Context* c, const SiteMask& mask) { assert(c, acquired); - if (mask.typeMask & (1 << MemoryOperand)) { + if (mask.typeMask & (1 << lir::MemoryOperand)) { if (base == c->arch->stack()) { - assert(c, index == NoRegister); + assert(c, index == lir::NoRegister); if (mask.frameIndex == AnyFrameIndex) { return false; @@ -2052,7 +2053,7 @@ class MemorySite: public Site { } virtual bool matchNextWord(Context* c, Site* s, unsigned index) { - if (s->type(c) == MemoryOperand) { + if (s->type(c) == lir::MemoryOperand) { MemorySite* ms = static_cast(s); return ms->base == this->base and ((index == 1 and ms->offset == static_cast @@ -2068,12 +2069,12 @@ class MemorySite: public Site { virtual void acquire(Context* c, Value* v) { increment(c, c->registerResources + base); - if (index != NoRegister) { + if (index != lir::NoRegister) { increment(c, c->registerResources + index); } if (base == c->arch->stack()) { - assert(c, index == NoRegister); + assert(c, index == lir::NoRegister); assert (c, not c->frameResources[offsetToFrameIndex(c, offset)].reserved); @@ -2086,7 +2087,7 @@ class MemorySite: public Site { virtual void release(Context* c, Value* v) { if (base == c->arch->stack()) { - assert(c, index == NoRegister); + assert(c, index == lir::NoRegister); assert (c, not c->frameResources[offsetToFrameIndex(c, offset)].reserved); @@ -2095,7 +2096,7 @@ class MemorySite: public Site { } decrement(c, c->registerResources + base); - if (index != NoRegister) { + if (index != lir::NoRegister) { decrement(c, c->registerResources + index); } @@ -2107,7 +2108,7 @@ class MemorySite: public Site { c->frameResources[offsetToFrameIndex(c, offset)].freeze(c, v); } else { increment(c, c->registerResources + base); - if (index != NoRegister) { + if (index != lir::NoRegister) { increment(c, c->registerResources + index); } } @@ -2118,7 +2119,7 @@ class MemorySite: public Site { c->frameResources[offsetToFrameIndex(c, offset)].thaw(c, v); } else { decrement(c, c->registerResources + base); - if (index != NoRegister) { + if (index != lir::NoRegister) { decrement(c, c->registerResources + index); } } @@ -2129,12 +2130,12 @@ class MemorySite: public Site { and c->frameResources[offsetToFrameIndex(c, offset)].freezeCount != 0; } - virtual OperandType type(Context*) { - return MemoryOperand; + virtual lir::OperandType type(Context*) { + return lir::MemoryOperand; } virtual void asAssemblerOperand(Context* c UNUSED, Site* high UNUSED, - Assembler::Operand* result) + lir::Operand* result) { // todo: endianness? assert(c, high == this @@ -2146,7 +2147,7 @@ class MemorySite: public Site { assert(c, acquired); - new (result) Assembler::Memory(base, offset, index, scale); + new (result) lir::Memory(base, offset, index, scale); } virtual Site* copy(Context* c) { @@ -2177,7 +2178,7 @@ class MemorySite: public Site { } virtual SiteMask mask(Context* c) { - return SiteMask(1 << MemoryOperand, 0, (base == c->arch->stack()) + return SiteMask(1 << lir::MemoryOperand, 0, (base == c->arch->stack()) ? static_cast(offsetToFrameIndex(c, offset)) : NoFrameIndex); } @@ -2185,13 +2186,13 @@ class MemorySite: public Site { virtual SiteMask nextWordMask(Context* c, unsigned index) { int frameIndex; if (base == c->arch->stack()) { - assert(c, this->index == NoRegister); + assert(c, this->index == lir::NoRegister); frameIndex = static_cast(offsetToFrameIndex(c, offset)) + ((index == 1) xor c->arch->bigEndian() ? 1 : -1); } else { frameIndex = NoFrameIndex; } - return SiteMask(1 << MemoryOperand, 0, frameIndex); + return SiteMask(1 << lir::MemoryOperand, 0, frameIndex); } virtual bool isVolatile(Context* c) { @@ -2216,7 +2217,7 @@ frameSite(Context* c, int frameIndex) { assert(c, frameIndex >= 0); return memorySite - (c, c->arch->stack(), frameIndexToOffset(c, frameIndex), NoRegister, 0); + (c, c->arch->stack(), frameIndexToOffset(c, frameIndex), lir::NoRegister, 0); } void @@ -2278,7 +2279,7 @@ pickTargetSite(Context* c, Read* read, bool intersectRead = false, expect(c, target.cost < Target::Impossible); - if (target.type == MemoryOperand) { + if (target.type == lir::MemoryOperand) { return frameSite(c, target.index); } else { return registerSite(c, target.index); @@ -2327,7 +2328,7 @@ class SingleRead: public Read { SingleRead* read(Context* c, const SiteMask& mask, Value* successor = 0) { - assert(c, (mask.typeMask != 1 << MemoryOperand) or mask.frameIndex >= 0); + assert(c, (mask.typeMask != 1 << lir::MemoryOperand) or mask.frameIndex >= 0); return new(c->zone) SingleRead(mask, successor); } @@ -2630,21 +2631,21 @@ SiteMask generalRegisterMask(Context* c) { return SiteMask - (1 << RegisterOperand, c->arch->generalRegisterMask(), NoFrameIndex); + (1 << lir::RegisterOperand, c->arch->generalRegisterMask(), NoFrameIndex); } SiteMask generalRegisterOrConstantMask(Context* c) { return SiteMask - ((1 << RegisterOperand) | (1 << ConstantOperand), + ((1 << lir::RegisterOperand) | (1 << lir::ConstantOperand), c->arch->generalRegisterMask(), NoFrameIndex); } SiteMask fixedRegisterMask(int number) { - return SiteMask(1 << RegisterOperand, 1 << number, NoFrameIndex); + return SiteMask(1 << lir::RegisterOperand, 1 << number, NoFrameIndex); } class MultiRead: public Read { @@ -2884,10 +2885,10 @@ bool acceptForResolve(Context* c, Site* s, Read* read, const SiteMask& mask) { if (acceptMatch(c, s, read, mask) and (not s->frozen(c))) { - if (s->type(c) == RegisterOperand) { + if (s->type(c) == lir::RegisterOperand) { return c->availableGeneralRegisterCount > ResolveRegisterReserveCount; } else { - assert(c, s->match(c, SiteMask(1 << MemoryOperand, 0, AnyFrameIndex))); + assert(c, s->match(c, SiteMask(1 << lir::MemoryOperand, 0, AnyFrameIndex))); return isHome(read->value, offsetToFrameIndex (c, static_cast(s)->offset)); @@ -2923,19 +2924,19 @@ move(Context* c, Value* value, Site* src, Site* dst) } if (srcSize == dstSize) { - apply(c, Move, srcSize, src, src, dstSize, dst, dst); + apply(c, lir::Move, srcSize, src, src, dstSize, dst, dst); } else if (srcSize > TargetBytesPerWord) { Site* low, *high, *other = pickSiteOrGrow(c, value, dst, &low, &high); other->freeze(c, value->nextWord); - apply(c, Move, srcSize, src, src, srcSize, low, high); + apply(c, lir::Move, srcSize, src, src, srcSize, low, high); other->thaw(c, value->nextWord); } else { Site* low, *high, *other = pickSiteOrMove(c, value, src, &low, &high); other->freeze(c, value->nextWord); - apply(c, Move, dstSize, low, high, dstSize, dst, dst); + apply(c, lir::Move, dstSize, low, high, dstSize, dst, dst); other->thaw(c, value->nextWord); } @@ -2946,12 +2947,12 @@ move(Context* c, Value* value, Site* src, Site* dst) void asAssemblerOperand(Context* c, Site* low, Site* high, - Assembler::Operand* result) + lir::Operand* result) { low->asAssemblerOperand(c, high, result); } -class OperandUnion: public Assembler::Operand { +class OperandUnion: public lir::Operand { // must be large enough and aligned properly to hold any operand // type (we'd use an actual union type here, except that classes // with constructors cannot be used in a union): @@ -2959,37 +2960,39 @@ class OperandUnion: public Assembler::Operand { }; void -apply(Context* c, UnaryOperation op, +apply(Context* c, lir::UnaryOperation op, unsigned s1Size, Site* s1Low, Site* s1High) { assert(c, s1Low->type(c) == s1High->type(c)); - OperandType s1Type = s1Low->type(c); + lir::OperandType s1Type = s1Low->type(c); OperandUnion s1Union; asAssemblerOperand(c, s1Low, s1High, &s1Union); - c->assembler->apply(op, s1Size, s1Type, &s1Union); + c->assembler->apply(op, + OperandInfo(s1Size, s1Type, &s1Union)); } void -apply(Context* c, BinaryOperation op, +apply(Context* c, lir::BinaryOperation op, unsigned s1Size, Site* s1Low, Site* s1High, unsigned s2Size, Site* s2Low, Site* s2High) { assert(c, s1Low->type(c) == s1High->type(c)); assert(c, s2Low->type(c) == s2High->type(c)); - OperandType s1Type = s1Low->type(c); + lir::OperandType s1Type = s1Low->type(c); OperandUnion s1Union; asAssemblerOperand(c, s1Low, s1High, &s1Union); - OperandType s2Type = s2Low->type(c); + lir::OperandType s2Type = s2Low->type(c); OperandUnion s2Union; asAssemblerOperand(c, s2Low, s2High, &s2Union); - c->assembler->apply(op, s1Size, s1Type, &s1Union, - s2Size, s2Type, &s2Union); + c->assembler->apply(op, + OperandInfo(s1Size, s1Type, &s1Union), + OperandInfo(s2Size, s2Type, &s2Union)); } void -apply(Context* c, TernaryOperation op, +apply(Context* c, lir::TernaryOperation op, unsigned s1Size, Site* s1Low, Site* s1High, unsigned s2Size, Site* s2Low, Site* s2High, unsigned s3Size, Site* s3Low, Site* s3High) @@ -2998,18 +3001,19 @@ apply(Context* c, TernaryOperation op, assert(c, s2Low->type(c) == s2High->type(c)); assert(c, s3Low->type(c) == s3High->type(c)); - OperandType s1Type = s1Low->type(c); + lir::OperandType s1Type = s1Low->type(c); OperandUnion s1Union; asAssemblerOperand(c, s1Low, s1High, &s1Union); - OperandType s2Type = s2Low->type(c); + lir::OperandType s2Type = s2Low->type(c); OperandUnion s2Union; asAssemblerOperand(c, s2Low, s2High, &s2Union); - OperandType s3Type = s3Low->type(c); + lir::OperandType s3Type = s3Low->type(c); OperandUnion s3Union; asAssemblerOperand(c, s3Low, s3High, &s3Union); - c->assembler->apply(op, s1Size, s1Type, &s1Union, - s2Size, s2Type, &s2Union, - s3Size, s3Type, &s3Union); + c->assembler->apply(op, + OperandInfo(s1Size, s1Type, &s1Union), + OperandInfo(s2Size, s2Type, &s2Union), + OperandInfo(s3Size, s3Type, &s3Union)); } void @@ -3072,13 +3076,13 @@ clean(Context* c, Value* v, unsigned popIndex) { for (SiteIterator it(c, v); it.hasMore();) { Site* s = it.next(); - if (not (s->match(c, SiteMask(1 << MemoryOperand, 0, AnyFrameIndex)) + if (not (s->match(c, SiteMask(1 << lir::MemoryOperand, 0, AnyFrameIndex)) and offsetToFrameIndex (c, static_cast(s)->offset) >= popIndex)) { if (false and - s->match(c, SiteMask(1 << MemoryOperand, 0, AnyFrameIndex))) + s->match(c, SiteMask(1 << lir::MemoryOperand, 0, AnyFrameIndex))) { char buffer[256]; s->toString(c, buffer, 256); fprintf(stderr, "remove %s from %p at %d pop offset 0x%x\n", @@ -3132,7 +3136,7 @@ saveLocals(Context* c, Event* e) } addRead(c, e, local->value, SiteMask - (1 << MemoryOperand, 0, local::frameIndex(c, li))); + (1 << lir::MemoryOperand, 0, local::frameIndex(c, li))); } } } @@ -3198,7 +3202,7 @@ class CallEvent: public Event { fprintf(stderr, "stack %d arg read %p\n", frameIndex, s->value); } - targetMask = SiteMask(1 << MemoryOperand, 0, frameIndex); + targetMask = SiteMask(1 << lir::MemoryOperand, 0, frameIndex); } addRead(c, this, s->value, targetMask); @@ -3221,7 +3225,7 @@ class CallEvent: public Event { uint8_t typeMask; uint64_t planRegisterMask; c->arch->plan - ((flags & Compiler::Aligned) ? AlignedCall : Call, TargetBytesPerWord, + ((flags & Compiler::Aligned) ? lir::AlignedCall : lir::Call, TargetBytesPerWord, &typeMask, &planRegisterMask, &thunk); assert(c, not thunk); @@ -3290,7 +3294,7 @@ class CallEvent: public Event { framePointerSurrogate = v; addRead(c, this, v, generalRegisterMask(c)); } else { - addRead(c, this, v, SiteMask(1 << MemoryOperand, 0, frameIndex)); + addRead(c, this, v, SiteMask(1 << lir::MemoryOperand, 0, frameIndex)); } } } @@ -3321,7 +3325,7 @@ class CallEvent: public Event { } addRead(c, this, stack->value, SiteMask - (1 << MemoryOperand, 0, logicalIndex)); + (1 << lir::MemoryOperand, 0, logicalIndex)); } stack = stack->next; @@ -3336,25 +3340,25 @@ class CallEvent: public Event { } virtual void compile(Context* c) { - UnaryOperation op; + lir::UnaryOperation op; if (TailCalls and (flags & Compiler::TailJump)) { if (flags & Compiler::LongJumpOrCall) { if (flags & Compiler::Aligned) { - op = AlignedLongJump; + op = lir::AlignedLongJump; } else { - op = LongJump; + op = lir::LongJump; } } else if (flags & Compiler::Aligned) { - op = AlignedJump; + op = lir::AlignedJump; } else { - op = Jump; + op = lir::Jump; } assert(c, returnAddressSurrogate == 0 - or returnAddressSurrogate->source->type(c) == RegisterOperand); + or returnAddressSurrogate->source->type(c) == lir::RegisterOperand); assert(c, framePointerSurrogate == 0 - or framePointerSurrogate->source->type(c) == RegisterOperand); + or framePointerSurrogate->source->type(c) == lir::RegisterOperand); int ras; if (returnAddressSurrogate) { @@ -3363,7 +3367,7 @@ class CallEvent: public Event { ras = static_cast (returnAddressSurrogate->source)->number; } else { - ras = NoRegister; + ras = lir::NoRegister; } int fps; @@ -3373,7 +3377,7 @@ class CallEvent: public Event { fps = static_cast (framePointerSurrogate->source)->number; } else { - fps = NoRegister; + fps = lir::NoRegister; } int offset @@ -3383,14 +3387,14 @@ class CallEvent: public Event { c->assembler->popFrameForTailCall(c->alignedFrameSize, offset, ras, fps); } else if (flags & Compiler::LongJumpOrCall) { if (flags & Compiler::Aligned) { - op = AlignedLongCall; + op = lir::AlignedLongCall; } else { - op = LongCall; + op = lir::LongCall; } } else if (flags & Compiler::Aligned) { - op = AlignedCall; + op = lir::AlignedCall; } else { - op = Call; + op = lir::Call; } apply(c, op, TargetBytesPerWord, address->source, address->source); @@ -3504,7 +3508,7 @@ appendReturn(Context* c, unsigned size, Value* value) } void -maybeMove(Context* c, BinaryOperation type, unsigned srcSize, +maybeMove(Context* c, lir::BinaryOperation type, unsigned srcSize, unsigned srcSelectSize, Value* src, unsigned dstSize, Value* dst, const SiteMask& dstMask) { @@ -3526,10 +3530,10 @@ maybeMove(Context* c, BinaryOperation type, unsigned srcSize, if (cost) { // todo: let c->arch->planMove decide this: - bool useTemporary = ((target->type(c) == MemoryOperand - and src->source->type(c) == MemoryOperand) + bool useTemporary = ((target->type(c) == lir::MemoryOperand + and src->source->type(c) == lir::MemoryOperand) or (srcSelectSize < dstSize - and target->type(c) != RegisterOperand)); + and target->type(c) != lir::RegisterOperand)); src->source->freeze(c, src); @@ -3539,7 +3543,7 @@ maybeMove(Context* c, BinaryOperation type, unsigned srcSize, bool addOffset = srcSize != srcSelectSize and c->arch->bigEndian() - and src->source->type(c) == MemoryOperand; + and src->source->type(c) == lir::MemoryOperand; if (addOffset) { static_cast(src->source)->offset @@ -3575,12 +3579,12 @@ maybeMove(Context* c, BinaryOperation type, unsigned srcSize, c->arch->planSource(type, dstSize, &srcTypeMask, &srcRegisterMask, dstSize, &thunk); - if (src->type == ValueGeneral) { + if (src->type == lir::ValueGeneral) { srcRegisterMask &= c->arch->generalRegisterMask(); } assert(c, thunk == 0); - assert(c, dstMask.typeMask & srcTypeMask & (1 << RegisterOperand)); + assert(c, dstMask.typeMask & srcTypeMask & (1 << lir::RegisterOperand)); Site* tmpTarget = freeRegisterSite (c, dstMask.registerMask & srcRegisterMask); @@ -3617,7 +3621,7 @@ maybeMove(Context* c, BinaryOperation type, unsigned srcSize, tmpTarget->freeze(c, dst); - apply(c, Move, dstSize, tmpTarget, tmpTarget, dstSize, target, target); + apply(c, lir::Move, dstSize, tmpTarget, tmpTarget, dstSize, target, target); tmpTarget->thaw(c, dst); @@ -3696,7 +3700,7 @@ pickSiteOrMove(Context* c, Value* src, Value* dst, Site* nextWord, } Value* -value(Context* c, ValueType type, Site* site = 0, Site* target = 0) +value(Context* c, lir::ValueType type, Site* site = 0, Site* target = 0) { return new(c->zone) Value(site, target, type); } @@ -3735,7 +3739,7 @@ maybeSplit(Context* c, Value* v) class MoveEvent: public Event { public: - MoveEvent(Context* c, BinaryOperation type, unsigned srcSize, + MoveEvent(Context* c, lir::BinaryOperation type, unsigned srcSize, unsigned srcSelectSize, Value* src, unsigned dstSize, Value* dst, const SiteMask& srcLowMask, const SiteMask& srcHighMask): Event(c), type(type), srcSize(srcSize), srcSelectSize(srcSelectSize), @@ -3786,7 +3790,7 @@ class MoveEvent: public Event { if (dst->target) { if (dstSize > TargetBytesPerWord) { if (src->source->registerSize(c) > TargetBytesPerWord) { - apply(c, Move, srcSelectSize, src->source, src->source, + apply(c, lir::Move, srcSelectSize, src->source, src->source, dstSize, dst->target, dst->target); if (live(c, dst) == 0) { @@ -3798,17 +3802,17 @@ class MoveEvent: public Event { } else { src->nextWord->source->freeze(c, src->nextWord); - maybeMove(c, Move, TargetBytesPerWord, TargetBytesPerWord, src, + maybeMove(c, lir::Move, TargetBytesPerWord, TargetBytesPerWord, src, TargetBytesPerWord, dst, dstLowMask); src->nextWord->source->thaw(c, src->nextWord); maybeMove - (c, Move, TargetBytesPerWord, TargetBytesPerWord, src->nextWord, + (c, lir::Move, TargetBytesPerWord, TargetBytesPerWord, src->nextWord, TargetBytesPerWord, dst->nextWord, dstHighMask); } } else { - maybeMove(c, Move, TargetBytesPerWord, TargetBytesPerWord, src, + maybeMove(c, lir::Move, TargetBytesPerWord, TargetBytesPerWord, src, TargetBytesPerWord, dst, dstLowMask); } } else { @@ -3827,7 +3831,7 @@ class MoveEvent: public Event { assert(c, srcSelectSize == TargetBytesPerWord); if (dst->nextWord->target or live(c, dst->nextWord)) { - assert(c, dstLowMask.typeMask & (1 << RegisterOperand)); + assert(c, dstLowMask.typeMask & (1 << lir::RegisterOperand)); Site* low = freeRegisterSite(c, dstLowMask.registerMask); @@ -3844,14 +3848,14 @@ class MoveEvent: public Event { srcb, dstb, src); } - apply(c, Move, TargetBytesPerWord, src->source, src->source, + apply(c, lir::Move, TargetBytesPerWord, src->source, src->source, TargetBytesPerWord, low, low); low->thaw(c, dst); src->source->thaw(c, src); - assert(c, dstHighMask.typeMask & (1 << RegisterOperand)); + assert(c, dstHighMask.typeMask & (1 << lir::RegisterOperand)); Site* high = freeRegisterSite(c, dstHighMask.registerMask); @@ -3868,7 +3872,7 @@ class MoveEvent: public Event { srcb, dstb, dst, dst->nextWord); } - apply(c, Move, TargetBytesPerWord, low, low, dstSize, low, high); + apply(c, lir::Move, TargetBytesPerWord, low, low, dstSize, low, high); high->thaw(c, dst->nextWord); @@ -3883,7 +3887,7 @@ class MoveEvent: public Event { } } - BinaryOperation type; + lir::BinaryOperation type; unsigned srcSize; unsigned srcSelectSize; Value* src; @@ -3892,7 +3896,7 @@ class MoveEvent: public Event { }; void -appendMove(Context* c, BinaryOperation type, unsigned srcSize, +appendMove(Context* c, lir::BinaryOperation type, unsigned srcSize, unsigned srcSelectSize, Value* src, unsigned dstSize, Value* dst) { bool thunk; @@ -3916,7 +3920,7 @@ findConstantSite(Context* c, Value* v) { for (SiteIterator it(c, v); it.hasMore();) { Site* s = it.next(); - if (s->type(c) == ConstantOperand) { + if (s->type(c) == lir::ConstantOperand) { return static_cast(s); } } @@ -3985,7 +3989,7 @@ thawSource(Context* c, unsigned size, Value* v) class CombineEvent: public Event { public: - CombineEvent(Context* c, TernaryOperation type, + CombineEvent(Context* c, lir::TernaryOperation type, unsigned firstSize, Value* first, unsigned secondSize, Value* second, unsigned resultSize, Value* result, @@ -4084,7 +4088,7 @@ class CombineEvent: public Event { } } - TernaryOperation type; + lir::TernaryOperation type; unsigned firstSize; Value* first; unsigned secondSize; @@ -4390,14 +4394,14 @@ register_(Context* c, int number) | c->arch->floatRegisterMask())); Site* s = registerSite(c, number); - ValueType type = ((1 << number) & c->arch->floatRegisterMask()) - ? ValueFloat: ValueGeneral; + lir::ValueType type = ((1 << number) & c->arch->floatRegisterMask()) + ? lir::ValueFloat: lir::ValueGeneral; return value(c, type, s, s); } void -appendCombine(Context* c, TernaryOperation type, +appendCombine(Context* c, lir::TernaryOperation type, unsigned firstSize, Value* first, unsigned secondSize, Value* second, unsigned resultSize, Value* result) @@ -4435,7 +4439,7 @@ appendCombine(Context* c, TernaryOperation type, c->stack = oldStack; appendCall - (c, value(c, ValueGeneral, constantSite(c, handler)), 0, 0, result, + (c, value(c, lir::ValueGeneral, constantSite(c, handler)), 0, 0, result, resultSize, argumentStack, stackSize, 0); } else { append @@ -4454,7 +4458,7 @@ appendCombine(Context* c, TernaryOperation type, class TranslateEvent: public Event { public: - TranslateEvent(Context* c, BinaryOperation type, unsigned valueSize, + TranslateEvent(Context* c, lir::BinaryOperation type, unsigned valueSize, Value* value, unsigned resultSize, Value* result, const SiteMask& valueLowMask, const SiteMask& valueHighMask): @@ -4521,7 +4525,7 @@ class TranslateEvent: public Event { } } - BinaryOperation type; + lir::BinaryOperation type; unsigned valueSize; unsigned resultSize; Value* value; @@ -4532,7 +4536,7 @@ class TranslateEvent: public Event { }; void -appendTranslate(Context* c, BinaryOperation type, unsigned firstSize, +appendTranslate(Context* c, lir::BinaryOperation type, unsigned firstSize, Value* first, unsigned resultSize, Value* result) { bool thunk; @@ -4552,7 +4556,7 @@ appendTranslate(Context* c, BinaryOperation type, unsigned firstSize, appendCall (c, value - (c, ValueGeneral, constantSite + (c, lir::ValueGeneral, constantSite (c, c->client->getThunk(type, firstSize, resultSize))), 0, 0, result, resultSize, argumentStack, ceilingDivide(firstSize, TargetBytesPerWord), 0); @@ -4567,7 +4571,7 @@ appendTranslate(Context* c, BinaryOperation type, unsigned firstSize, class OperationEvent: public Event { public: - OperationEvent(Context* c, Operation op): + OperationEvent(Context* c, lir::Operation op): Event(c), op(op) { } @@ -4579,11 +4583,11 @@ class OperationEvent: public Event { c->assembler->apply(op); } - Operation op; + lir::Operation op; }; void -appendOperation(Context* c, Operation op) +appendOperation(Context* c, lir::Operation op) { append(c, new(c->zone) OperationEvent(c, op)); } @@ -4592,7 +4596,7 @@ void moveIfConflict(Context* c, Value* v, MemorySite* s) { if (v->reads) { - SiteMask mask(1 << RegisterOperand, ~0, AnyFrameIndex); + SiteMask mask(1 << lir::RegisterOperand, ~0, AnyFrameIndex); v->reads->intersect(&mask); if (s->conflicts(mask)) { maybeMove(c, v->reads, true, false); @@ -4626,23 +4630,23 @@ class MemoryEvent: public Event { ConstantSite* constant = findConstantSite(c, index); if (constant) { - indexRegister = NoRegister; + indexRegister = lir::NoRegister; displacement += (constant->value->value() * scale); scale = 1; } else { - assert(c, index->source->type(c) == RegisterOperand); + assert(c, index->source->type(c) == lir::RegisterOperand); indexRegister = static_cast(index->source)->number; } } else { - indexRegister = NoRegister; + indexRegister = lir::NoRegister; } - assert(c, base->source->type(c) == RegisterOperand); + assert(c, base->source->type(c) == lir::RegisterOperand); int baseRegister = static_cast(base->source)->number; popRead(c, this, base); if (index) { - if (TargetBytesPerWord == 8 and indexRegister != NoRegister) { - apply(c, Move, 4, index->source, index->source, + if (TargetBytesPerWord == 8 and indexRegister != lir::NoRegister) { + apply(c, lir::Move, 4, index->source, index->source, 8, index->source, index->source); } @@ -4701,59 +4705,59 @@ unordered(double a, double b) } bool -shouldJump(Context* c, TernaryOperation type, unsigned size, int64_t b, +shouldJump(Context* c, lir::TernaryOperation type, unsigned size, int64_t b, int64_t a) { switch (type) { - case JumpIfEqual: + case lir::JumpIfEqual: return a == b; - case JumpIfNotEqual: + case lir::JumpIfNotEqual: return a != b; - case JumpIfLess: + case lir::JumpIfLess: return a < b; - case JumpIfGreater: + case lir::JumpIfGreater: return a > b; - case JumpIfLessOrEqual: + case lir::JumpIfLessOrEqual: return a <= b; - case JumpIfGreaterOrEqual: + case lir::JumpIfGreaterOrEqual: return a >= b; - case JumpIfFloatEqual: + case lir::JumpIfFloatEqual: return asFloat(size, a) == asFloat(size, b); - case JumpIfFloatNotEqual: + case lir::JumpIfFloatNotEqual: return asFloat(size, a) != asFloat(size, b); - case JumpIfFloatLess: + case lir::JumpIfFloatLess: return asFloat(size, a) < asFloat(size, b); - case JumpIfFloatGreater: + case lir::JumpIfFloatGreater: return asFloat(size, a) > asFloat(size, b); - case JumpIfFloatLessOrEqual: + case lir::JumpIfFloatLessOrEqual: return asFloat(size, a) <= asFloat(size, b); - case JumpIfFloatGreaterOrEqual: + case lir::JumpIfFloatGreaterOrEqual: return asFloat(size, a) >= asFloat(size, b); - case JumpIfFloatLessOrUnordered: + case lir::JumpIfFloatLessOrUnordered: return asFloat(size, a) < asFloat(size, b) or unordered(asFloat(size, a), asFloat(size, b)); - case JumpIfFloatGreaterOrUnordered: + case lir::JumpIfFloatGreaterOrUnordered: return asFloat(size, a) > asFloat(size, b) or unordered(asFloat(size, a), asFloat(size, b)); - case JumpIfFloatLessOrEqualOrUnordered: + case lir::JumpIfFloatLessOrEqualOrUnordered: return asFloat(size, a) <= asFloat(size, b) or unordered(asFloat(size, a), asFloat(size, b)); - case JumpIfFloatGreaterOrEqualOrUnordered: + case lir::JumpIfFloatGreaterOrEqualOrUnordered: return asFloat(size, a) >= asFloat(size, b) or unordered(asFloat(size, a), asFloat(size, b)); @@ -4762,31 +4766,31 @@ shouldJump(Context* c, TernaryOperation type, unsigned size, int64_t b, } } -TernaryOperation -thunkBranch(Context* c, TernaryOperation type) +lir::TernaryOperation +thunkBranch(Context* c, lir::TernaryOperation type) { switch (type) { - case JumpIfFloatEqual: - return JumpIfEqual; + case lir::JumpIfFloatEqual: + return lir::JumpIfEqual; - case JumpIfFloatNotEqual: - return JumpIfNotEqual; + case lir::JumpIfFloatNotEqual: + return lir::JumpIfNotEqual; - case JumpIfFloatLess: - case JumpIfFloatLessOrUnordered: - return JumpIfLess; + case lir::JumpIfFloatLess: + case lir::JumpIfFloatLessOrUnordered: + return lir::JumpIfLess; - case JumpIfFloatGreater: - case JumpIfFloatGreaterOrUnordered: - return JumpIfGreater; + case lir::JumpIfFloatGreater: + case lir::JumpIfFloatGreaterOrUnordered: + return lir::JumpIfGreater; - case JumpIfFloatLessOrEqual: - case JumpIfFloatLessOrEqualOrUnordered: - return JumpIfLessOrEqual; + case lir::JumpIfFloatLessOrEqual: + case lir::JumpIfFloatLessOrEqualOrUnordered: + return lir::JumpIfLessOrEqual; - case JumpIfFloatGreaterOrEqual: - case JumpIfFloatGreaterOrEqualOrUnordered: - return JumpIfGreaterOrEqual; + case lir::JumpIfFloatGreaterOrEqual: + case lir::JumpIfFloatGreaterOrEqualOrUnordered: + return lir::JumpIfGreaterOrEqual; default: abort(c); @@ -4795,7 +4799,7 @@ thunkBranch(Context* c, TernaryOperation type) class BranchEvent: public Event { public: - BranchEvent(Context* c, TernaryOperation type, unsigned size, + BranchEvent(Context* c, lir::TernaryOperation type, unsigned size, Value* first, Value* second, Value* address, const SiteMask& firstLowMask, const SiteMask& firstHighMask, @@ -4840,7 +4844,7 @@ class BranchEvent: public Event { } if (shouldJump(c, type, size, firstValue, secondValue)) { - apply(c, Jump, TargetBytesPerWord, address->source, address->source); + apply(c, lir::Jump, TargetBytesPerWord, address->source, address->source); } } else { freezeSource(c, size, first); @@ -4864,7 +4868,7 @@ class BranchEvent: public Event { virtual bool isBranch() { return true; } - TernaryOperation type; + lir::TernaryOperation type; unsigned size; Value* first; Value* second; @@ -4872,7 +4876,7 @@ class BranchEvent: public Event { }; void -appendBranch(Context* c, TernaryOperation type, unsigned size, Value* first, +appendBranch(Context* c, lir::TernaryOperation type, unsigned size, Value* first, Value* second, Value* address) { bool thunk; @@ -4900,14 +4904,14 @@ appendBranch(Context* c, TernaryOperation type, unsigned size, Value* first, Stack* argumentStack = c->stack; c->stack = oldStack; - Value* result = value(c, ValueGeneral); + Value* result = value(c, lir::ValueGeneral); appendCall (c, value - (c, ValueGeneral, constantSite(c, handler)), 0, 0, result, 4, + (c, lir::ValueGeneral, constantSite(c, handler)), 0, 0, result, 4, argumentStack, ceilingDivide(size, TargetBytesPerWord) * 2, 0); appendBranch(c, thunkBranch(c, type), 4, value - (c, ValueGeneral, constantSite(c, static_cast(0))), + (c, lir::ValueGeneral, constantSite(c, static_cast(0))), result, address); } else { append @@ -4923,7 +4927,7 @@ appendBranch(Context* c, TernaryOperation type, unsigned size, Value* first, class JumpEvent: public Event { public: - JumpEvent(Context* c, UnaryOperation type, Value* address, bool exit, + JumpEvent(Context* c, lir::UnaryOperation type, Value* address, bool exit, bool cleanLocals): Event(c), type(type), address(address), exit(exit), cleanLocals(cleanLocals) @@ -4965,14 +4969,14 @@ class JumpEvent: public Event { return exit or unreachable(this); } - UnaryOperation type; + lir::UnaryOperation type; Value* address; bool exit; bool cleanLocals; }; void -appendJump(Context* c, UnaryOperation type, Value* address, bool exit = false, +appendJump(Context* c, lir::UnaryOperation type, Value* address, bool exit = false, bool cleanLocals = false) { append(c, new(c->zone) JumpEvent(c, type, address, exit, cleanLocals)); @@ -5001,22 +5005,25 @@ class BoundsCheckEvent: public Event { if (constant) { if (constant->value->value() < 0) { - Assembler::Constant handlerConstant(resolved(c, handler)); - a->apply(Call, TargetBytesPerWord, ConstantOperand, &handlerConstant); + lir::Constant handlerConstant(resolved(c, handler)); + a->apply(lir::Call, + OperandInfo(TargetBytesPerWord, lir::ConstantOperand, &handlerConstant)); } } else { outOfBoundsPromise = codePromise(c, static_cast(0)); ConstantSite zero(resolved(c, 0)); ConstantSite oob(outOfBoundsPromise); - apply(c, JumpIfLess, 4, &zero, &zero, 4, index->source, index->source, - TargetBytesPerWord, &oob, &oob); + apply(c, lir::JumpIfLess, + 4, &zero, &zero, + 4, index->source, index->source, + TargetBytesPerWord, &oob, &oob); } if (constant == 0 or constant->value->value() >= 0) { - assert(c, object->source->type(c) == RegisterOperand); + assert(c, object->source->type(c) == lir::RegisterOperand); MemorySite length(static_cast(object->source)->number, - lengthOffset, NoRegister, 1); + lengthOffset, lir::NoRegister, 1); length.acquired = true; CodePromise* nextPromise = codePromise(c, static_cast(0)); @@ -5024,8 +5031,10 @@ class BoundsCheckEvent: public Event { freezeSource(c, TargetBytesPerWord, index); ConstantSite next(nextPromise); - apply(c, JumpIfGreater, 4, index->source, index->source, 4, &length, - &length, TargetBytesPerWord, &next, &next); + apply(c, lir::JumpIfGreater, + 4, index->source, + index->source, 4, &length, + &length, TargetBytesPerWord, &next, &next); thawSource(c, TargetBytesPerWord, index); @@ -5033,8 +5042,9 @@ class BoundsCheckEvent: public Event { outOfBoundsPromise->offset = a->offset(); } - Assembler::Constant handlerConstant(resolved(c, handler)); - a->apply(Call, TargetBytesPerWord, ConstantOperand, &handlerConstant); + lir::Constant handlerConstant(resolved(c, handler)); + a->apply(lir::Call, + OperandInfo(TargetBytesPerWord, lir::ConstantOperand, &handlerConstant)); nextPromise->offset = a->offset(); } @@ -5400,7 +5410,7 @@ resolveOriginalSites(Context* c, Event* e, SiteRecordList* frozen, buffer, v, el.localIndex, frameIndex(c, &el)); } - Value dummy(0, 0, ValueGeneral); + Value dummy(0, 0, lir::ValueGeneral); addSite(c, &dummy, s); removeSite(c, &dummy, s); freeze(c, frozen, s, 0); @@ -5420,7 +5430,7 @@ resolveSourceSites(Context* c, Event* e, SiteRecordList* frozen, Site** sites) Read* r = live(c, v); if (r and sites[el.localIndex] == 0) { - SiteMask mask((1 << RegisterOperand) | (1 << MemoryOperand), + SiteMask mask((1 << lir::RegisterOperand) | (1 << lir::MemoryOperand), c->arch->generalRegisterMask(), AnyFrameIndex); Site* s = pickSourceSite @@ -5454,7 +5464,7 @@ resolveTargetSites(Context* c, Event* e, SiteRecordList* frozen, Site** sites) Read* r = live(c, v); if (r and sites[el.localIndex] == 0) { - SiteMask mask((1 << RegisterOperand) | (1 << MemoryOperand), + SiteMask mask((1 << lir::RegisterOperand) | (1 << lir::MemoryOperand), c->arch->generalRegisterMask(), AnyFrameIndex); Site* s = pickSourceSite @@ -6057,7 +6067,7 @@ class MyCompiler: public Compiler { virtual void returnFromSubroutine(Subroutine* subroutine, Operand* address) { appendSaveLocals(&c); - appendJump(&c, Jump, static_cast(address), false, true); + appendJump(&c, lir::Jump, static_cast(address), false, true); static_cast(subroutine)->forkState = local::saveState(&c); } @@ -6216,17 +6226,17 @@ class MyCompiler: public Compiler { return p; } - virtual Operand* constant(int64_t value, OperandType type) { + virtual Operand* constant(int64_t value, Compiler::OperandType type) { return promiseConstant(resolved(&c, value), type); } - virtual Operand* promiseConstant(Promise* value, OperandType type) { + virtual Operand* promiseConstant(Promise* value, Compiler::OperandType type) { return local::value (&c, valueType(&c, type), local::constantSite(&c, value)); } virtual Operand* address(Promise* address) { - return value(&c, ValueGeneral, local::addressSite(&c, address)); + return value(&c, lir::ValueGeneral, local::addressSite(&c, address)); } virtual Operand* memory(Operand* base, @@ -6254,7 +6264,7 @@ class MyCompiler: public Compiler { virtual void push(unsigned footprint UNUSED) { assert(&c, footprint == 1); - Value* v = value(&c, ValueGeneral); + Value* v = value(&c, lir::ValueGeneral); Stack* s = local::stack(&c, v, c.stack); v->home = frameIndex(&c, s->index + c.localFootprint); @@ -6280,7 +6290,7 @@ class MyCompiler: public Compiler { } virtual void pushed() { - Value* v = value(&c, ValueGeneral); + Value* v = value(&c, lir::ValueGeneral); appendFrameSite (&c, v, frameIndex (&c, (c.stack ? c.stack->index : 0) + c.localFootprint)); @@ -6463,7 +6473,7 @@ class MyCompiler: public Compiler { Local* local = e->locals() + i; if (local->value) { initLocal - (1, i, local->value->type == ValueGeneral ? IntegerType : FloatType); + (1, i, local->value->type == lir::ValueGeneral ? IntegerType : FloatType); } } @@ -6492,7 +6502,7 @@ class MyCompiler: public Compiler { virtual void store(unsigned srcSize, Operand* src, unsigned dstSize, Operand* dst) { - appendMove(&c, Move, srcSize, srcSize, static_cast(src), + appendMove(&c, lir::Move, srcSize, srcSize, static_cast(src), dstSize, static_cast(dst)); } @@ -6502,7 +6512,7 @@ class MyCompiler: public Compiler { assert(&c, dstSize >= TargetBytesPerWord); Value* dst = value(&c, static_cast(src)->type); - appendMove(&c, Move, srcSize, srcSelectSize, static_cast(src), + appendMove(&c, lir::Move, srcSize, srcSelectSize, static_cast(src), dstSize, dst); return dst; } @@ -6513,7 +6523,7 @@ class MyCompiler: public Compiler { assert(&c, dstSize >= TargetBytesPerWord); Value* dst = value(&c, static_cast(src)->type); - appendMove(&c, MoveZ, srcSize, srcSelectSize, static_cast(src), + appendMove(&c, lir::MoveZ, srcSize, srcSelectSize, static_cast(src), dstSize, dst); return dst; } @@ -6521,140 +6531,140 @@ class MyCompiler: public Compiler { virtual void jumpIfEqual(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueGeneral - and static_cast(b)->type == ValueGeneral); + assert(&c, static_cast(a)->type == lir::ValueGeneral + and static_cast(b)->type == lir::ValueGeneral); - appendBranch(&c, JumpIfEqual, size, static_cast(a), + appendBranch(&c, lir::JumpIfEqual, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfNotEqual(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueGeneral - and static_cast(b)->type == ValueGeneral); + assert(&c, static_cast(a)->type == lir::ValueGeneral + and static_cast(b)->type == lir::ValueGeneral); - appendBranch(&c, JumpIfNotEqual, size, static_cast(a), + appendBranch(&c, lir::JumpIfNotEqual, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfLess(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueGeneral - and static_cast(b)->type == ValueGeneral); + assert(&c, static_cast(a)->type == lir::ValueGeneral + and static_cast(b)->type == lir::ValueGeneral); - appendBranch(&c, JumpIfLess, size, static_cast(a), + appendBranch(&c, lir::JumpIfLess, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfGreater(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueGeneral - and static_cast(b)->type == ValueGeneral); + assert(&c, static_cast(a)->type == lir::ValueGeneral + and static_cast(b)->type == lir::ValueGeneral); - appendBranch(&c, JumpIfGreater, size, static_cast(a), + appendBranch(&c, lir::JumpIfGreater, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfLessOrEqual(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueGeneral - and static_cast(b)->type == ValueGeneral); + assert(&c, static_cast(a)->type == lir::ValueGeneral + and static_cast(b)->type == lir::ValueGeneral); - appendBranch(&c, JumpIfLessOrEqual, size, static_cast(a), + appendBranch(&c, lir::JumpIfLessOrEqual, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfGreaterOrEqual(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueGeneral - and static_cast(b)->type == ValueGeneral); + assert(&c, static_cast(a)->type == lir::ValueGeneral + and static_cast(b)->type == lir::ValueGeneral); - appendBranch(&c, JumpIfGreaterOrEqual, size, static_cast(a), + appendBranch(&c, lir::JumpIfGreaterOrEqual, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfFloatEqual(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); - appendBranch(&c, JumpIfFloatEqual, size, static_cast(a), + appendBranch(&c, lir::JumpIfFloatEqual, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfFloatNotEqual(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); - appendBranch(&c, JumpIfFloatNotEqual, size, static_cast(a), + appendBranch(&c, lir::JumpIfFloatNotEqual, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfFloatLess(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); - appendBranch(&c, JumpIfFloatLess, size, static_cast(a), + appendBranch(&c, lir::JumpIfFloatLess, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfFloatGreater(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); - appendBranch(&c, JumpIfFloatGreater, size, static_cast(a), + appendBranch(&c, lir::JumpIfFloatGreater, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfFloatLessOrEqual(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); - appendBranch(&c, JumpIfFloatLessOrEqual, size, static_cast(a), + appendBranch(&c, lir::JumpIfFloatLessOrEqual, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfFloatGreaterOrEqual(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); - appendBranch(&c, JumpIfFloatGreaterOrEqual, size, static_cast(a), + appendBranch(&c, lir::JumpIfFloatGreaterOrEqual, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfFloatLessOrUnordered(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); - appendBranch(&c, JumpIfFloatLessOrUnordered, size, static_cast(a), + appendBranch(&c, lir::JumpIfFloatLessOrUnordered, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jumpIfFloatGreaterOrUnordered(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); - appendBranch(&c, JumpIfFloatGreaterOrUnordered, size, + appendBranch(&c, lir::JumpIfFloatGreaterOrUnordered, size, static_cast(a), static_cast(b), static_cast(address)); } @@ -6662,10 +6672,10 @@ class MyCompiler: public Compiler { virtual void jumpIfFloatLessOrEqualOrUnordered(unsigned size, Operand* a, Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); - appendBranch(&c, JumpIfFloatLessOrEqualOrUnordered, size, + appendBranch(&c, lir::JumpIfFloatLessOrEqualOrUnordered, size, static_cast(a), static_cast(b), static_cast(address)); } @@ -6674,240 +6684,239 @@ class MyCompiler: public Compiler { Operand* b, Operand* address) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); - appendBranch(&c, JumpIfFloatGreaterOrEqualOrUnordered, size, + appendBranch(&c, lir::JumpIfFloatGreaterOrEqualOrUnordered, size, static_cast(a), static_cast(b), static_cast(address)); } virtual void jmp(Operand* address) { - appendJump(&c, Jump, static_cast(address)); + appendJump(&c, lir::Jump, static_cast(address)); } virtual void exit(Operand* address) { - appendJump(&c, Jump, static_cast(address), true); + appendJump(&c, lir::Jump, static_cast(address), true); } virtual Operand* add(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueGeneral - and static_cast(b)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); - appendCombine(&c, Add, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueGeneral + and static_cast(b)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); + appendCombine(&c, lir::Add, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* sub(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueGeneral - and static_cast(b)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); - appendCombine(&c, Subtract, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueGeneral + and static_cast(b)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); + appendCombine(&c, lir::Subtract, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* mul(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueGeneral - and static_cast(b)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); - appendCombine(&c, Multiply, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueGeneral + and static_cast(b)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); + appendCombine(&c, lir::Multiply, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* div(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueGeneral - and static_cast(b)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); - appendCombine(&c, Divide, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueGeneral + and static_cast(b)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); + appendCombine(&c, lir::Divide, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* rem(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueGeneral - and static_cast(b)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); - appendCombine(&c, Remainder, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueGeneral + and static_cast(b)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); + appendCombine(&c, lir::Remainder, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* fadd(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); - Value* result = value(&c, ValueFloat); - static_cast(a)->type = static_cast(b)->type = ValueFloat; - appendCombine(&c, FloatAdd, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); + Value* result = value(&c, lir::ValueFloat); + static_cast(a)->type = static_cast(b)->type = lir::ValueFloat; + appendCombine(&c, lir::FloatAdd, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* fsub(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); - Value* result = value(&c, ValueFloat); - static_cast(a)->type = static_cast(b)->type = ValueFloat; - appendCombine(&c, FloatSubtract, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); + Value* result = value(&c, lir::ValueFloat); + static_cast(a)->type = static_cast(b)->type = lir::ValueFloat; + appendCombine(&c, lir::FloatSubtract, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* fmul(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); - Value* result = value(&c, ValueFloat); - static_cast(a)->type = static_cast(b)->type = ValueFloat; - appendCombine(&c, FloatMultiply, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); + Value* result = value(&c, lir::ValueFloat); + static_cast(a)->type = static_cast(b)->type = lir::ValueFloat; + appendCombine(&c, lir::FloatMultiply, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* fdiv(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); - Value* result = value(&c, ValueFloat); - appendCombine(&c, FloatDivide, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); + Value* result = value(&c, lir::ValueFloat); + appendCombine(&c, lir::FloatDivide, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* frem(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueFloat - and static_cast(b)->type == ValueFloat); - Value* result = value(&c, ValueFloat); - appendCombine(&c, FloatRemainder, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueFloat + and static_cast(b)->type == lir::ValueFloat); + Value* result = value(&c, lir::ValueFloat); + appendCombine(&c, lir::FloatRemainder, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* shl(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); - appendCombine(&c, ShiftLeft, TargetBytesPerWord, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); + appendCombine(&c, lir::ShiftLeft, TargetBytesPerWord, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* shr(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); - appendCombine(&c, ShiftRight, TargetBytesPerWord, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); + appendCombine(&c, lir::ShiftRight, TargetBytesPerWord, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* ushr(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); + assert(&c, static_cast(a)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); appendCombine - (&c, UnsignedShiftRight, TargetBytesPerWord, static_cast(a), + (&c, lir::UnsignedShiftRight, TargetBytesPerWord, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* and_(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); - appendCombine(&c, And, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); + appendCombine(&c, lir::And, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* or_(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); - appendCombine(&c, Or, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); + appendCombine(&c, lir::Or, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* xor_(unsigned size, Operand* a, Operand* b) { - assert(&c, static_cast(a)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); - appendCombine(&c, Xor, size, static_cast(a), + assert(&c, static_cast(a)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); + appendCombine(&c, lir::Xor, size, static_cast(a), size, static_cast(b), size, result); return result; } virtual Operand* neg(unsigned size, Operand* a) { - assert(&c, static_cast(a)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); - appendTranslate(&c, Negate, size, static_cast(a), size, result); + assert(&c, static_cast(a)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); + appendTranslate(&c, lir::Negate, size, static_cast(a), size, result); return result; } virtual Operand* fneg(unsigned size, Operand* a) { - assert(&c, static_cast(a)->type == ValueFloat); - Value* result = value(&c, ValueFloat); - appendTranslate - (&c, FloatNegate, size, static_cast(a), size, result); + assert(&c, static_cast(a)->type == lir::ValueFloat); + Value* result = value(&c, lir::ValueFloat); + appendTranslate(&c, lir::FloatNegate, size, static_cast(a), size, result); return result; } virtual Operand* abs(unsigned size, Operand* a) { - assert(&c, static_cast(a)->type == ValueGeneral); - Value* result = value(&c, ValueGeneral); - appendTranslate(&c, Absolute, size, static_cast(a), size, result); + assert(&c, static_cast(a)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueGeneral); + appendTranslate(&c, lir::Absolute, size, static_cast(a), size, result); return result; } virtual Operand* fabs(unsigned size, Operand* a) { - assert(&c, static_cast(a)->type == ValueFloat); - Value* result = value(&c, ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat); + Value* result = value(&c, lir::ValueFloat); appendTranslate - (&c, FloatAbsolute, size, static_cast(a), size, result); + (&c, lir::FloatAbsolute, size, static_cast(a), size, result); return result; } virtual Operand* fsqrt(unsigned size, Operand* a) { - assert(&c, static_cast(a)->type == ValueFloat); - Value* result = value(&c, ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat); + Value* result = value(&c, lir::ValueFloat); appendTranslate - (&c, FloatSquareRoot, size, static_cast(a), size, result); + (&c, lir::FloatSquareRoot, size, static_cast(a), size, result); return result; } virtual Operand* f2f(unsigned aSize, unsigned resSize, Operand* a) { - assert(&c, static_cast(a)->type == ValueFloat); - Value* result = value(&c, ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueFloat); + Value* result = value(&c, lir::ValueFloat); appendTranslate - (&c, Float2Float, aSize, static_cast(a), resSize, result); + (&c, lir::Float2Float, aSize, static_cast(a), resSize, result); return result; } virtual Operand* f2i(unsigned aSize, unsigned resSize, Operand* a) { - assert(&c, static_cast(a)->type == ValueFloat); - Value* result = value(&c, ValueGeneral); + assert(&c, static_cast(a)->type == lir::ValueFloat); + Value* result = value(&c, lir::ValueGeneral); appendTranslate - (&c, Float2Int, aSize, static_cast(a), resSize, result); + (&c, lir::Float2Int, aSize, static_cast(a), resSize, result); return result; } virtual Operand* i2f(unsigned aSize, unsigned resSize, Operand* a) { - assert(&c, static_cast(a)->type == ValueGeneral); - Value* result = value(&c, ValueFloat); + assert(&c, static_cast(a)->type == lir::ValueGeneral); + Value* result = value(&c, lir::ValueFloat); appendTranslate - (&c, Int2Float, aSize, static_cast(a), resSize, result); + (&c, lir::Int2Float, aSize, static_cast(a), resSize, result); return result; } virtual void trap() { - appendOperation(&c, Trap); + appendOperation(&c, lir::Trap); } virtual void loadBarrier() { - appendOperation(&c, LoadBarrier); + appendOperation(&c, lir::LoadBarrier); } virtual void storeStoreBarrier() { - appendOperation(&c, StoreStoreBarrier); + appendOperation(&c, lir::StoreStoreBarrier); } virtual void storeLoadBarrier() { - appendOperation(&c, StoreLoadBarrier); + appendOperation(&c, lir::StoreLoadBarrier); } virtual void compile(uintptr_t stackOverflowHandler, @@ -6982,7 +6991,8 @@ class MyCompiler: public Compiler { } // namespace -namespace vm { +namespace avian { +namespace codegen { Compiler* makeCompiler(System* system, Assembler* assembler, Zone* zone, @@ -6991,4 +7001,5 @@ makeCompiler(System* system, Assembler* assembler, Zone* zone, return new(zone) local::MyCompiler(system, assembler, zone, client); } -} // namespace vm +} // namespace codegen +} // namespace avian diff --git a/src/codegen/compiler.h b/src/codegen/compiler.h index e66c69a67c..fbaad83791 100644 --- a/src/codegen/compiler.h +++ b/src/codegen/compiler.h @@ -15,7 +15,8 @@ #include "zone.h" #include "assembler.h" -namespace vm { +namespace avian { +namespace codegen { class TraceHandler { public: @@ -26,10 +27,10 @@ class Compiler { public: class Client { public: - virtual intptr_t getThunk(UnaryOperation op, unsigned size) = 0; - virtual intptr_t getThunk(BinaryOperation op, unsigned size, + virtual intptr_t getThunk(lir::UnaryOperation op, unsigned size) = 0; + virtual intptr_t getThunk(lir::BinaryOperation op, unsigned size, unsigned resultSize) = 0; - virtual intptr_t getThunk(TernaryOperation op, unsigned size, + virtual intptr_t getThunk(lir::TernaryOperation op, unsigned size, unsigned resultSize, bool* threadParameter) = 0; }; @@ -200,9 +201,10 @@ class Compiler { }; Compiler* -makeCompiler(System* system, Assembler* assembler, Zone* zone, +makeCompiler(vm::System* system, Assembler* assembler, vm::Zone* zone, Compiler::Client* client); -} // namespace vm +} // namespace codegen +} // namespace avian #endif//COMPILER_H diff --git a/src/codegen/lir-ops.inc.cpp b/src/codegen/lir-ops.inc.cpp new file mode 100644 index 0000000000..cf038c6647 --- /dev/null +++ b/src/codegen/lir-ops.inc.cpp @@ -0,0 +1,62 @@ +LIR_OP_0(Return) +LIR_OP_0(LoadBarrier) +LIR_OP_0(StoreStoreBarrier) +LIR_OP_0(StoreLoadBarrier) +LIR_OP_0(Trap) + +LIR_OP_1(Call) +LIR_OP_1(LongCall) +LIR_OP_1(AlignedLongCall) +LIR_OP_1(AlignedCall) +LIR_OP_1(Jump) +LIR_OP_1(LongJump) +LIR_OP_1(AlignedLongJump) +LIR_OP_1(AlignedJump) + +LIR_OP_2(Move) +LIR_OP_2(MoveLow) +LIR_OP_2(MoveHigh) +LIR_OP_2(MoveZ) +LIR_OP_2(Negate) +LIR_OP_2(FloatNegate) +LIR_OP_2(Float2Float) +LIR_OP_2(Float2Int) +LIR_OP_2(Int2Float) +LIR_OP_2(FloatSquareRoot) +LIR_OP_2(FloatAbsolute) +LIR_OP_2(Absolute) + +LIR_OP_3(Add) +LIR_OP_3(Subtract) +LIR_OP_3(Multiply) +LIR_OP_3(Divide) +LIR_OP_3(Remainder) +LIR_OP_3(ShiftLeft) +LIR_OP_3(ShiftRight) +LIR_OP_3(UnsignedShiftRight) +LIR_OP_3(And) +LIR_OP_3(Or) +LIR_OP_3(Xor) +LIR_OP_3(FloatAdd) +LIR_OP_3(FloatSubtract) +LIR_OP_3(FloatMultiply) +LIR_OP_3(FloatDivide) +LIR_OP_3(FloatRemainder) +LIR_OP_3(FloatMax) +LIR_OP_3(FloatMin) +LIR_OP_3(JumpIfLess) +LIR_OP_3(JumpIfGreater) +LIR_OP_3(JumpIfLessOrEqual) +LIR_OP_3(JumpIfGreaterOrEqual) +LIR_OP_3(JumpIfEqual) +LIR_OP_3(JumpIfNotEqual) +LIR_OP_3(JumpIfFloatEqual) +LIR_OP_3(JumpIfFloatNotEqual) +LIR_OP_3(JumpIfFloatLess) +LIR_OP_3(JumpIfFloatGreater) +LIR_OP_3(JumpIfFloatLessOrEqual) +LIR_OP_3(JumpIfFloatGreaterOrEqual) +LIR_OP_3(JumpIfFloatLessOrUnordered) +LIR_OP_3(JumpIfFloatGreaterOrUnordered) +LIR_OP_3(JumpIfFloatLessOrEqualOrUnordered) +LIR_OP_3(JumpIfFloatGreaterOrEqualOrUnordered) diff --git a/src/codegen/lir.cpp b/src/codegen/lir.cpp new file mode 100644 index 0000000000..86c0839743 --- /dev/null +++ b/src/codegen/lir.cpp @@ -0,0 +1,35 @@ +/* Copyright (c) 2008-2012, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#include "lir.h" + +namespace { + +const char* lirOpcodeNames[] = { + #define LIR_OP_0(x) #x + #define LIR_OP_1(x) #x + #define LIR_OP_2(x) #x + #define LIR_OP_3(x) #x + #include "lir-ops.inc.cpp" + #undef LIR_OP_0 + #undef LIR_OP_1 + #undef LIR_OP_2 + #undef LIR_OP_3 +}; + +} + +namespace vm { + +const char* LirInstr::opcodeName(Opcode op) { + return lirOpcodeNames[op]; +} + +} \ No newline at end of file diff --git a/src/codegen/lir.h b/src/codegen/lir.h new file mode 100644 index 0000000000..b95e736f06 --- /dev/null +++ b/src/codegen/lir.h @@ -0,0 +1,174 @@ +/* Copyright (c) 2008-2012, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#ifndef AVIAN_CODEGEN_LIR_H +#define AVIAN_CODEGEN_LIR_H + +namespace avian { +namespace codegen { +class Promise; + +namespace lir { +enum Operation { + #define LIR_OP_0(x) x, + #define LIR_OP_1(x) + #define LIR_OP_2(x) + #define LIR_OP_3(x) + #include "lir-ops.inc.cpp" + #undef LIR_OP_0 + #undef LIR_OP_1 + #undef LIR_OP_2 + #undef LIR_OP_3 +}; + +const unsigned OperationCount = Trap + 1; + +enum UnaryOperation { + #define LIR_OP_0(x) + #define LIR_OP_1(x) x, + #define LIR_OP_2(x) + #define LIR_OP_3(x) + #include "lir-ops.inc.cpp" + #undef LIR_OP_0 + #undef LIR_OP_1 + #undef LIR_OP_2 + #undef LIR_OP_3 + + NoUnaryOperation = -1 +}; + +const unsigned UnaryOperationCount = AlignedJump + 1; + +enum BinaryOperation { + #define LIR_OP_0(x) + #define LIR_OP_1(x) + #define LIR_OP_2(x) x, + #define LIR_OP_3(x) + #include "lir-ops.inc.cpp" + #undef LIR_OP_0 + #undef LIR_OP_1 + #undef LIR_OP_2 + #undef LIR_OP_3 + + NoBinaryOperation = -1 +}; + +const unsigned BinaryOperationCount = Absolute + 1; + +enum TernaryOperation { + #define LIR_OP_0(x) + #define LIR_OP_1(x) + #define LIR_OP_2(x) + #define LIR_OP_3(x) x, + #include "lir-ops.inc.cpp" + #undef LIR_OP_0 + #undef LIR_OP_1 + #undef LIR_OP_2 + #undef LIR_OP_3 + + NoTernaryOperation = -1 +}; + +const unsigned TernaryOperationCount += JumpIfFloatGreaterOrEqualOrUnordered + 1; + +const unsigned NonBranchTernaryOperationCount = FloatMin + 1; +const unsigned BranchOperationCount += JumpIfFloatGreaterOrEqualOrUnordered - FloatMin; + +enum OperandType { + ConstantOperand, + AddressOperand, + RegisterOperand, + MemoryOperand +}; + +enum ValueType { + ValueGeneral, + ValueFloat +}; + +const unsigned OperandTypeCount = MemoryOperand + 1; + +const int NoRegister = -1; + + +inline bool isBranch(lir::TernaryOperation op) { + return op > FloatMin; +} + +inline bool isFloatBranch(lir::TernaryOperation op) { + return op > JumpIfNotEqual; +} + +class Operand { }; + +class Constant: public Operand { + public: + Constant(Promise* value): value(value) { } + + Promise* value; +}; + +class Address: public Operand { + public: + Address(Promise* address): address(address) { } + + Promise* address; +}; + +class Register: public Operand { + public: + Register(int low, int high = NoRegister): low(low), high(high) { } + + int low; + int high; +}; + +class Memory: public Operand { + public: + Memory(int base, int offset, int index = NoRegister, unsigned scale = 1): + base(base), offset(offset), index(index), scale(scale) + { } + + int base; + int offset; + int index; + unsigned scale; +}; + +class Instr { +public: + + enum Opcode { + #define LIR_OP_0(x) OP_##x, + #define LIR_OP_1(x) OP_##x, + #define LIR_OP_2(x) OP_##x, + #define LIR_OP_3(x) OP_##x, + #include "lir-ops.inc.cpp" + #undef LIR_OP_0 + #undef LIR_OP_1 + #undef LIR_OP_2 + #undef LIR_OP_3 + }; + + static const char* opcodeName(Opcode op); + + static Opcode opcodeFromNullary(Operation op); + static Opcode opcodeFromUnary(UnaryOperation op); + static Opcode opcodeFromBinary(BinaryOperation op); + static Opcode opcodeFromTernary(TernaryOperation op); +}; + +} // namespace lir +} // namespace codegen +} // namespace avian + +#endif // AVIAN_CODEGEN_LIR_H diff --git a/src/codegen/powerpc/assembler.cpp b/src/codegen/powerpc/assembler.cpp index 6517e59264..ee263b25bc 100644 --- a/src/codegen/powerpc/assembler.cpp +++ b/src/codegen/powerpc/assembler.cpp @@ -17,6 +17,7 @@ #define CAST_BRANCH(x) reinterpret_cast(x) using namespace vm; +using namespace avian::codegen; namespace { @@ -263,33 +264,33 @@ class Task { typedef void (*OperationType)(Context*); -typedef void (*UnaryOperationType)(Context*, unsigned, Assembler::Operand*); +typedef void (*UnaryOperationType)(Context*, unsigned, lir::Operand*); typedef void (*BinaryOperationType) -(Context*, unsigned, Assembler::Operand*, unsigned, Assembler::Operand*); +(Context*, unsigned, lir::Operand*, unsigned, lir::Operand*); typedef void (*TernaryOperationType) -(Context*, unsigned, Assembler::Operand*, Assembler::Operand*, - Assembler::Operand*); +(Context*, unsigned, lir::Operand*, lir::Operand*, + lir::Operand*); typedef void (*BranchOperationType) -(Context*, TernaryOperation, unsigned, Assembler::Operand*, - Assembler::Operand*, Assembler::Operand*); +(Context*, lir::TernaryOperation, unsigned, lir::Operand*, + lir::Operand*, lir::Operand*); class ArchitectureContext { public: ArchitectureContext(System* s): s(s) { } System* s; - OperationType operations[OperationCount]; - UnaryOperationType unaryOperations[UnaryOperationCount - * OperandTypeCount]; + OperationType operations[lir::OperationCount]; + UnaryOperationType unaryOperations[lir::UnaryOperationCount + * lir::OperandTypeCount]; BinaryOperationType binaryOperations - [BinaryOperationCount * OperandTypeCount * OperandTypeCount]; + [lir::BinaryOperationCount * lir::OperandTypeCount * lir::OperandTypeCount]; TernaryOperationType ternaryOperations - [NonBranchTernaryOperationCount * OperandTypeCount]; + [lir::NonBranchTernaryOperationCount * lir::OperandTypeCount]; BranchOperationType branchOperations - [BranchOperationCount * OperandTypeCount * OperandTypeCount]; + [lir::BranchOperationCount * lir::OperandTypeCount * lir::OperandTypeCount]; }; inline void NO_RETURN @@ -612,43 +613,37 @@ resolve(MyBlock* b) } inline unsigned -index(ArchitectureContext*, UnaryOperation operation, OperandType operand) +index(ArchitectureContext*, lir::UnaryOperation operation, lir::OperandType operand) { - return operation + (UnaryOperationCount * operand); + return operation + (lir::UnaryOperationCount * operand); } inline unsigned index(ArchitectureContext*, - BinaryOperation operation, - OperandType operand1, - OperandType operand2) + lir::BinaryOperation operation, + lir::OperandType operand1, + lir::OperandType operand2) { return operation - + (BinaryOperationCount * operand1) - + (BinaryOperationCount * OperandTypeCount * operand2); -} - -bool -isBranch(TernaryOperation op) -{ - return op > FloatMin; + + (lir::BinaryOperationCount * operand1) + + (lir::BinaryOperationCount * lir::OperandTypeCount * operand2); } inline unsigned index(ArchitectureContext* c UNUSED, - TernaryOperation operation, - OperandType operand1) + lir::TernaryOperation operation, + lir::OperandType operand1) { assert(c, not isBranch(operation)); - return operation + (NonBranchTernaryOperationCount * operand1); + return operation + (lir::NonBranchTernaryOperationCount * operand1); } unsigned -branchIndex(ArchitectureContext* c UNUSED, OperandType operand1, - OperandType operand2) +branchIndex(ArchitectureContext* c UNUSED, lir::OperandType operand1, + lir::OperandType operand2) { - return operand1 + (OperandTypeCount * operand2); + return operand1 + (lir::OperandTypeCount * operand2); } // BEGIN OPERATION COMPILERS @@ -658,7 +653,7 @@ using namespace isa; inline void emit(Context* con, int code) { con->code.append4(targetV4(code)); } inline int newTemp(Context* con) { return con->client->acquireTemporary(); } inline void freeTemp(Context* con, int r) { con->client->releaseTemporary(r); } -inline int64_t getValue(Assembler::Constant* c) { return c->value->value(); } +inline int64_t getValue(lir::Constant* c) { return c->value->value(); } inline void write4(uint8_t* dst, uint32_t v) @@ -667,13 +662,13 @@ write4(uint8_t* dst, uint32_t v) } void -andC(Context* c, unsigned size, Assembler::Constant* a, - Assembler::Register* b, Assembler::Register* dst); +andC(Context* c, unsigned size, lir::Constant* a, + lir::Register* b, lir::Register* dst); -void shiftLeftR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) +void shiftLeftR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if(size == 8) { - Assembler::Register Tmp(newTemp(con), newTemp(con)); Assembler::Register* tmp = &Tmp; + lir::Register Tmp(newTemp(con), newTemp(con)); lir::Register* tmp = &Tmp; emit(con, subfic(tmp->high, a->low, 32)); emit(con, slw(t->high, b->high, a->low)); emit(con, srw(tmp->low, b->low, tmp->high)); @@ -689,10 +684,10 @@ void shiftLeftR(Context* con, unsigned size, Assembler::Register* a, Assembler:: } void -moveRR(Context* c, unsigned srcSize, Assembler::Register* src, - unsigned dstSize, Assembler::Register* dst); +moveRR(Context* c, unsigned srcSize, lir::Register* src, + unsigned dstSize, lir::Register* dst); -void shiftLeftC(Context* con, unsigned size, Assembler::Constant* a, Assembler::Register* b, Assembler::Register* t) +void shiftLeftC(Context* con, unsigned size, lir::Constant* a, lir::Register* b, lir::Register* t) { int sh = getValue(a); if (size == 8) { @@ -714,10 +709,10 @@ void shiftLeftC(Context* con, unsigned size, Assembler::Constant* a, Assembler:: } } -void shiftRightR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) +void shiftRightR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if(size == 8) { - Assembler::Register Tmp(newTemp(con), newTemp(con)); Assembler::Register* tmp = &Tmp; + lir::Register Tmp(newTemp(con), newTemp(con)); lir::Register* tmp = &Tmp; emit(con, subfic(tmp->high, a->low, 32)); emit(con, srw(t->low, b->low, a->low)); emit(con, slw(tmp->low, b->high, tmp->high)); @@ -733,7 +728,7 @@ void shiftRightR(Context* con, unsigned size, Assembler::Register* a, Assembler: } } -void shiftRightC(Context* con, unsigned size, Assembler::Constant* a, Assembler::Register* b, Assembler::Register* t) +void shiftRightC(Context* con, unsigned size, lir::Constant* a, lir::Register* b, lir::Register* t) { int sh = getValue(a); if(size == 8) { @@ -755,11 +750,11 @@ void shiftRightC(Context* con, unsigned size, Assembler::Constant* a, Assembler: } } -void unsignedShiftRightR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) +void unsignedShiftRightR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { emit(con, srw(t->low, b->low, a->low)); if(size == 8) { - Assembler::Register Tmp(newTemp(con), newTemp(con)); Assembler::Register* tmp = &Tmp; + lir::Register Tmp(newTemp(con), newTemp(con)); lir::Register* tmp = &Tmp; emit(con, subfic(tmp->high, a->low, 32)); emit(con, slw(tmp->low, b->high, tmp->high)); emit(con, or_(t->low, t->low, tmp->low)); @@ -771,13 +766,13 @@ void unsignedShiftRightR(Context* con, unsigned size, Assembler::Register* a, As } } -void unsignedShiftRightC(Context* con, unsigned size, Assembler::Constant* a, Assembler::Register* b, Assembler::Register* t) +void unsignedShiftRightC(Context* con, unsigned size, lir::Constant* a, lir::Register* b, lir::Register* t) { int sh = getValue(a); if (size == 8) { if (sh & 0x3F) { if (sh == 32) { - Assembler::Register high(b->high); + lir::Register high(b->high); moveRR(con, 4, &high, 4, t); emit(con, li(t->high,0)); } else if (sh < 32) { @@ -909,7 +904,7 @@ appendConstantPoolEntry(Context* c, Promise* constant) } void -jumpR(Context* c, unsigned size UNUSED, Assembler::Register* target) +jumpR(Context* c, unsigned size UNUSED, lir::Register* target) { assert(c, size == TargetBytesPerWord); @@ -918,13 +913,13 @@ jumpR(Context* c, unsigned size UNUSED, Assembler::Register* target) } void -swapRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize, Assembler::Register* b) +swapRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize, lir::Register* b) { assert(c, aSize == TargetBytesPerWord); assert(c, bSize == TargetBytesPerWord); - Assembler::Register tmp(c->client->acquireTemporary()); + lir::Register tmp(c->client->acquireTemporary()); moveRR(c, aSize, a, bSize, &tmp); moveRR(c, bSize, b, aSize, a); moveRR(c, bSize, &tmp, bSize, b); @@ -932,8 +927,8 @@ swapRR(Context* c, unsigned aSize, Assembler::Register* a, } void -moveRR(Context* c, unsigned srcSize, Assembler::Register* src, - unsigned dstSize, Assembler::Register* dst) +moveRR(Context* c, unsigned srcSize, lir::Register* src, + unsigned dstSize, lir::Register* dst) { switch (srcSize) { case 1: @@ -950,8 +945,8 @@ moveRR(Context* c, unsigned srcSize, Assembler::Register* src, moveRR(c, 4, src, 4, dst); emit(c, srawi(dst->high, src->low, 31)); } else if (srcSize == 8 and dstSize == 8) { - Assembler::Register srcHigh(src->high); - Assembler::Register dstHigh(dst->high); + lir::Register srcHigh(src->high); + lir::Register dstHigh(dst->high); if (src->high == dst->low) { if (src->low == dst->high) { @@ -974,8 +969,8 @@ moveRR(Context* c, unsigned srcSize, Assembler::Register* src, } void -moveZRR(Context* c, unsigned srcSize, Assembler::Register* src, - unsigned, Assembler::Register* dst) +moveZRR(Context* c, unsigned srcSize, lir::Register* src, + unsigned, lir::Register* dst) { switch (srcSize) { case 2: @@ -987,8 +982,8 @@ moveZRR(Context* c, unsigned srcSize, Assembler::Register* src, } void -moveCR2(Context* c, unsigned, Assembler::Constant* src, - unsigned dstSize, Assembler::Register* dst, unsigned promiseOffset) +moveCR2(Context* c, unsigned, lir::Constant* src, + unsigned dstSize, lir::Register* dst, unsigned promiseOffset) { if (dstSize <= 4) { if (src->value->resolved()) { @@ -1011,13 +1006,13 @@ moveCR2(Context* c, unsigned, Assembler::Constant* src, } void -moveCR(Context* c, unsigned srcSize, Assembler::Constant* src, - unsigned dstSize, Assembler::Register* dst) +moveCR(Context* c, unsigned srcSize, lir::Constant* src, + unsigned dstSize, lir::Register* dst) { moveCR2(c, srcSize, src, dstSize, dst, 0); } -void addR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) { +void addR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if(size == 8) { emit(con, addc(t->low, a->low, b->low)); emit(con, adde(t->high, a->high, b->high)); @@ -1026,7 +1021,7 @@ void addR(Context* con, unsigned size, Assembler::Register* a, Assembler::Regist } } -void addC(Context* con, unsigned size, Assembler::Constant* a, Assembler::Register* b, Assembler::Register* t) { +void addC(Context* con, unsigned size, lir::Constant* a, lir::Register* b, lir::Register* t) { assert(con, size == TargetBytesPerWord); int32_t i = getValue(a); @@ -1039,7 +1034,7 @@ void addC(Context* con, unsigned size, Assembler::Constant* a, Assembler::Regist } } -void subR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) { +void subR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if(size == 8) { emit(con, subfc(t->low, a->low, b->low)); emit(con, subfe(t->high, a->high, b->high)); @@ -1048,15 +1043,15 @@ void subR(Context* con, unsigned size, Assembler::Register* a, Assembler::Regist } } -void subC(Context* c, unsigned size, Assembler::Constant* a, Assembler::Register* b, Assembler::Register* t) { +void subC(Context* c, unsigned size, lir::Constant* a, lir::Register* b, lir::Register* t) { assert(c, size == TargetBytesPerWord); ResolvedPromise promise(- a->value->value()); - Assembler::Constant constant(&promise); + lir::Constant constant(&promise); addC(c, size, &constant, b, t); } -void multiplyR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) { +void multiplyR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { if(size == 8) { bool useTemporaries = b->low == t->low; int tmpLow; @@ -1085,14 +1080,14 @@ void multiplyR(Context* con, unsigned size, Assembler::Register* a, Assembler::R } } -void divideR(Context* con, unsigned size UNUSED, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) { +void divideR(Context* con, unsigned size UNUSED, lir::Register* a, lir::Register* b, lir::Register* t) { assert(con, size == 4); emit(con, divw(t->low, b->low, a->low)); } -void remainderR(Context* con, unsigned size, Assembler::Register* a, Assembler::Register* b, Assembler::Register* t) { +void remainderR(Context* con, unsigned size, lir::Register* a, lir::Register* b, lir::Register* t) { bool useTemporary = b->low == t->low; - Assembler::Register tmp(t->low); + lir::Register tmp(t->low); if (useTemporary) { tmp.low = con->client->acquireTemporary(); } @@ -1111,7 +1106,7 @@ normalize(Context* c, int offset, int index, unsigned scale, bool* preserveIndex, bool* release) { if (offset != 0 or scale != 1) { - Assembler::Register normalizedIndex + lir::Register normalizedIndex (*preserveIndex ? c->client->acquireTemporary() : index); if (*preserveIndex) { @@ -1124,10 +1119,10 @@ normalize(Context* c, int offset, int index, unsigned scale, int scaled; if (scale != 1) { - Assembler::Register unscaledIndex(index); + lir::Register unscaledIndex(index); ResolvedPromise scalePromise(log(scale)); - Assembler::Constant scaleConstant(&scalePromise); + lir::Constant scaleConstant(&scalePromise); shiftLeftC(c, TargetBytesPerWord, &scaleConstant, &unscaledIndex, &normalizedIndex); @@ -1138,10 +1133,10 @@ normalize(Context* c, int offset, int index, unsigned scale, } if (offset != 0) { - Assembler::Register untranslatedIndex(scaled); + lir::Register untranslatedIndex(scaled); ResolvedPromise offsetPromise(offset); - Assembler::Constant offsetConstant(&offsetPromise); + lir::Constant offsetConstant(&offsetPromise); addC(c, TargetBytesPerWord, &offsetConstant, &untranslatedIndex, &normalizedIndex); @@ -1155,10 +1150,10 @@ normalize(Context* c, int offset, int index, unsigned scale, } void -store(Context* c, unsigned size, Assembler::Register* src, +store(Context* c, unsigned size, lir::Register* src, int base, int offset, int index, unsigned scale, bool preserveIndex) { - if (index != NoRegister) { + if (index != lir::NoRegister) { bool release; int normalized = normalize (c, offset, index, scale, &preserveIndex, &release); @@ -1177,7 +1172,7 @@ store(Context* c, unsigned size, Assembler::Register* src, break; case 8: { - Assembler::Register srcHigh(src->high); + lir::Register srcHigh(src->high); store(c, 4, &srcHigh, base, 0, normalized, 1, preserveIndex); store(c, 4, src, base, 4, normalized, 1, preserveIndex); } break; @@ -1201,9 +1196,9 @@ store(Context* c, unsigned size, Assembler::Register* src, break; case 8: { - Assembler::Register srcHigh(src->high); - store(c, 4, &srcHigh, base, offset, NoRegister, 1, false); - store(c, 4, src, base, offset + 4, NoRegister, 1, false); + lir::Register srcHigh(src->high); + store(c, 4, &srcHigh, base, offset, lir::NoRegister, 1, false); + store(c, 4, src, base, offset + 4, lir::NoRegister, 1, false); } break; default: abort(c); @@ -1212,8 +1207,8 @@ store(Context* c, unsigned size, Assembler::Register* src, } void -moveRM(Context* c, unsigned srcSize, Assembler::Register* src, - unsigned dstSize UNUSED, Assembler::Memory* dst) +moveRM(Context* c, unsigned srcSize, lir::Register* src, + unsigned dstSize UNUSED, lir::Memory* dst) { assert(c, srcSize == dstSize); @@ -1221,13 +1216,13 @@ moveRM(Context* c, unsigned srcSize, Assembler::Register* src, } void -moveAndUpdateRM(Context* c, unsigned srcSize UNUSED, Assembler::Register* src, - unsigned dstSize UNUSED, Assembler::Memory* dst) +moveAndUpdateRM(Context* c, unsigned srcSize UNUSED, lir::Register* src, + unsigned dstSize UNUSED, lir::Memory* dst) { assert(c, srcSize == TargetBytesPerWord); assert(c, dstSize == TargetBytesPerWord); - if (dst->index == NoRegister) { + if (dst->index == lir::NoRegister) { emit(c, stwu(src->low, dst->base, dst->offset)); } else { assert(c, dst->offset == 0); @@ -1239,10 +1234,10 @@ moveAndUpdateRM(Context* c, unsigned srcSize UNUSED, Assembler::Register* src, void load(Context* c, unsigned srcSize, int base, int offset, int index, - unsigned scale, unsigned dstSize, Assembler::Register* dst, + unsigned scale, unsigned dstSize, lir::Register* dst, bool preserveIndex, bool signExtend) { - if (index != NoRegister) { + if (index != lir::NoRegister) { bool release; int normalized = normalize (c, offset, index, scale, &preserveIndex, &release); @@ -1269,7 +1264,7 @@ load(Context* c, unsigned srcSize, int base, int offset, int index, load(c, 4, base, 0, normalized, 1, 4, dst, preserveIndex, false); moveRR(c, 4, dst, 8, dst); } else if (srcSize == 8 and dstSize == 8) { - Assembler::Register dstHigh(dst->high); + lir::Register dstHigh(dst->high); load(c, 4, base, 0, normalized, 1, 4, &dstHigh, preserveIndex, false); load(c, 4, base, 4, normalized, 1, 4, dst, preserveIndex, false); } else { @@ -1304,9 +1299,9 @@ load(Context* c, unsigned srcSize, int base, int offset, int index, case 8: { if (dstSize == 8) { - Assembler::Register dstHigh(dst->high); - load(c, 4, base, offset, NoRegister, 1, 4, &dstHigh, false, false); - load(c, 4, base, offset + 4, NoRegister, 1, 4, dst, false, false); + lir::Register dstHigh(dst->high); + load(c, 4, base, offset, lir::NoRegister, 1, 4, &dstHigh, false, false); + load(c, 4, base, offset + 4, lir::NoRegister, 1, 4, dst, false, false); } else { emit(c, lwzx(dst->low, base, offset)); } @@ -1318,29 +1313,29 @@ load(Context* c, unsigned srcSize, int base, int offset, int index, } void -moveMR(Context* c, unsigned srcSize, Assembler::Memory* src, - unsigned dstSize, Assembler::Register* dst) +moveMR(Context* c, unsigned srcSize, lir::Memory* src, + unsigned dstSize, lir::Register* dst) { load(c, srcSize, src->base, src->offset, src->index, src->scale, dstSize, dst, true, true); } void -moveZMR(Context* c, unsigned srcSize, Assembler::Memory* src, - unsigned dstSize, Assembler::Register* dst) +moveZMR(Context* c, unsigned srcSize, lir::Memory* src, + unsigned dstSize, lir::Register* dst) { load(c, srcSize, src->base, src->offset, src->index, src->scale, dstSize, dst, true, false); } void -andR(Context* c, unsigned size, Assembler::Register* a, - Assembler::Register* b, Assembler::Register* dst) +andR(Context* c, unsigned size, lir::Register* a, + lir::Register* b, lir::Register* dst) { if (size == 8) { - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); - Assembler::Register dh(dst->high); + lir::Register ah(a->high); + lir::Register bh(b->high); + lir::Register dh(dst->high); andR(c, 4, a, b, dst); andR(c, 4, &ah, &bh, &dh); @@ -1350,20 +1345,20 @@ andR(Context* c, unsigned size, Assembler::Register* a, } void -andC(Context* c, unsigned size, Assembler::Constant* a, - Assembler::Register* b, Assembler::Register* dst) +andC(Context* c, unsigned size, lir::Constant* a, + lir::Register* b, lir::Register* dst) { int64_t v = a->value->value(); if (size == 8) { ResolvedPromise high((v >> 32) & 0xFFFFFFFF); - Assembler::Constant ah(&high); + lir::Constant ah(&high); ResolvedPromise low(v & 0xFFFFFFFF); - Assembler::Constant al(&low); + lir::Constant al(&low); - Assembler::Register bh(b->high); - Assembler::Register dh(dst->high); + lir::Register bh(b->high); + lir::Register dh(dst->high); andC(c, 4, &al, b, dst); andC(c, 4, &ah, &bh, &dh); @@ -1403,7 +1398,7 @@ andC(Context* c, unsigned size, Assembler::Constant* a, emit(c, andis(dst->low, b->low, v32 >> 16)); } else { bool useTemporary = b->low == dst->low; - Assembler::Register tmp(dst->low); + lir::Register tmp(dst->low); if (useTemporary) { tmp.low = c->client->acquireTemporary(); } @@ -1434,13 +1429,13 @@ andC(Context* c, unsigned size, Assembler::Constant* a, } void -orR(Context* c, unsigned size, Assembler::Register* a, - Assembler::Register* b, Assembler::Register* dst) +orR(Context* c, unsigned size, lir::Register* a, + lir::Register* b, lir::Register* dst) { if (size == 8) { - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); - Assembler::Register dh(dst->high); + lir::Register ah(a->high); + lir::Register bh(b->high); + lir::Register dh(dst->high); orR(c, 4, a, b, dst); orR(c, 4, &ah, &bh, &dh); @@ -1450,20 +1445,20 @@ orR(Context* c, unsigned size, Assembler::Register* a, } void -orC(Context* c, unsigned size, Assembler::Constant* a, - Assembler::Register* b, Assembler::Register* dst) +orC(Context* c, unsigned size, lir::Constant* a, + lir::Register* b, lir::Register* dst) { int64_t v = a->value->value(); if (size == 8) { ResolvedPromise high((v >> 32) & 0xFFFFFFFF); - Assembler::Constant ah(&high); + lir::Constant ah(&high); ResolvedPromise low(v & 0xFFFFFFFF); - Assembler::Constant al(&low); + lir::Constant al(&low); - Assembler::Register bh(b->high); - Assembler::Register dh(dst->high); + lir::Register bh(b->high); + lir::Register dh(dst->high); orC(c, 4, &al, b, dst); orC(c, 4, &ah, &bh, &dh); @@ -1476,13 +1471,13 @@ orC(Context* c, unsigned size, Assembler::Constant* a, } void -xorR(Context* c, unsigned size, Assembler::Register* a, - Assembler::Register* b, Assembler::Register* dst) +xorR(Context* c, unsigned size, lir::Register* a, + lir::Register* b, lir::Register* dst) { if (size == 8) { - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); - Assembler::Register dh(dst->high); + lir::Register ah(a->high); + lir::Register bh(b->high); + lir::Register dh(dst->high); xorR(c, 4, a, b, dst); xorR(c, 4, &ah, &bh, &dh); @@ -1492,20 +1487,20 @@ xorR(Context* c, unsigned size, Assembler::Register* a, } void -xorC(Context* c, unsigned size, Assembler::Constant* a, - Assembler::Register* b, Assembler::Register* dst) +xorC(Context* c, unsigned size, lir::Constant* a, + lir::Register* b, lir::Register* dst) { uint64_t v = a->value->value(); if (size == 8) { ResolvedPromise high((v >> 32) & 0xFFFFFFFF); - Assembler::Constant ah(&high); + lir::Constant ah(&high); ResolvedPromise low(v & 0xFFFFFFFF); - Assembler::Constant al(&low); + lir::Constant al(&low); - Assembler::Register bh(b->high); - Assembler::Register dh(dst->high); + lir::Register bh(b->high); + lir::Register dh(dst->high); xorC(c, 4, &al, b, dst); xorC(c, 4, &ah, &bh, &dh); @@ -1520,12 +1515,12 @@ xorC(Context* c, unsigned size, Assembler::Constant* a, } void -moveAR2(Context* c, unsigned srcSize UNUSED, Assembler::Address* src, - unsigned dstSize, Assembler::Register* dst, unsigned promiseOffset) +moveAR2(Context* c, unsigned srcSize UNUSED, lir::Address* src, + unsigned dstSize, lir::Register* dst, unsigned promiseOffset) { assert(c, srcSize == 4 and dstSize == 4); - Assembler::Memory memory(dst->low, 0, -1, 0); + lir::Memory memory(dst->low, 0, -1, 0); appendImmediateTask (c, src->address, offset(c), TargetBytesPerWord, promiseOffset, true); @@ -1535,15 +1530,15 @@ moveAR2(Context* c, unsigned srcSize UNUSED, Assembler::Address* src, } void -moveAR(Context* c, unsigned srcSize, Assembler::Address* src, - unsigned dstSize, Assembler::Register* dst) +moveAR(Context* c, unsigned srcSize, lir::Address* src, + unsigned dstSize, lir::Register* dst) { moveAR2(c, srcSize, src, dstSize, dst, 0); } void -compareRR(Context* c, unsigned aSize UNUSED, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +compareRR(Context* c, unsigned aSize UNUSED, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize == 4 and bSize == 4); @@ -1551,15 +1546,15 @@ compareRR(Context* c, unsigned aSize UNUSED, Assembler::Register* a, } void -compareCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +compareCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { assert(c, aSize == 4 and bSize == 4); if (a->value->resolved() and isInt16(a->value->value())) { emit(c, cmpwi(b->low, a->value->value())); } else { - Assembler::Register tmp(c->client->acquireTemporary()); + lir::Register tmp(c->client->acquireTemporary()); moveCR(c, aSize, a, bSize, &tmp); compareRR(c, bSize, &tmp, bSize, b); c->client->releaseTemporary(tmp.low); @@ -1567,32 +1562,32 @@ compareCR(Context* c, unsigned aSize, Assembler::Constant* a, } void -compareCM(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Memory* b) +compareCM(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Memory* b) { assert(c, aSize == 4 and bSize == 4); - Assembler::Register tmp(c->client->acquireTemporary()); + lir::Register tmp(c->client->acquireTemporary()); moveMR(c, bSize, b, bSize, &tmp); compareCR(c, aSize, a, bSize, &tmp); c->client->releaseTemporary(tmp.low); } void -compareRM(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize, Assembler::Memory* b) +compareRM(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize, lir::Memory* b) { assert(c, aSize == 4 and bSize == 4); - Assembler::Register tmp(c->client->acquireTemporary()); + lir::Register tmp(c->client->acquireTemporary()); moveMR(c, bSize, b, bSize, &tmp); compareRR(c, aSize, a, bSize, &tmp); c->client->releaseTemporary(tmp.low); } void -compareUnsignedRR(Context* c, unsigned aSize UNUSED, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +compareUnsignedRR(Context* c, unsigned aSize UNUSED, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize == 4 and bSize == 4); @@ -1600,15 +1595,15 @@ compareUnsignedRR(Context* c, unsigned aSize UNUSED, Assembler::Register* a, } void -compareUnsignedCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +compareUnsignedCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { assert(c, aSize == 4 and bSize == 4); if (a->value->resolved() and (a->value->value() >> 16) == 0) { emit(c, cmplwi(b->low, a->value->value())); } else { - Assembler::Register tmp(c->client->acquireTemporary()); + lir::Register tmp(c->client->acquireTemporary()); moveCR(c, aSize, a, bSize, &tmp); compareUnsignedRR(c, bSize, &tmp, bSize, b); c->client->releaseTemporary(tmp.low); @@ -1616,25 +1611,25 @@ compareUnsignedCR(Context* c, unsigned aSize, Assembler::Constant* a, } int32_t -branch(Context* c, TernaryOperation op) +branch(Context* c, lir::TernaryOperation op) { switch (op) { - case JumpIfEqual: + case lir::JumpIfEqual: return beq(0); - case JumpIfNotEqual: + case lir::JumpIfNotEqual: return bne(0); - case JumpIfLess: + case lir::JumpIfLess: return blt(0); - case JumpIfGreater: + case lir::JumpIfGreater: return bgt(0); - case JumpIfLessOrEqual: + case lir::JumpIfLessOrEqual: return ble(0); - case JumpIfGreaterOrEqual: + case lir::JumpIfGreaterOrEqual: return bge(0); default: @@ -1643,22 +1638,22 @@ branch(Context* c, TernaryOperation op) } void -conditional(Context* c, int32_t branch, Assembler::Constant* target) +conditional(Context* c, int32_t branch, lir::Constant* target) { appendOffsetTask(c, target->value, offset(c), true); emit(c, branch); } void -branch(Context* c, TernaryOperation op, Assembler::Constant* target) +branch(Context* c, lir::TernaryOperation op, lir::Constant* target) { conditional(c, branch(c, op), target); } void -branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, - Assembler::Operand* ah, Assembler::Operand* bl, - Assembler::Operand* bh, Assembler::Constant* target, +branchLong(Context* c, lir::TernaryOperation op, lir::Operand* al, + lir::Operand* ah, lir::Operand* bl, + lir::Operand* bh, lir::Constant* target, BinaryOperationType compareSigned, BinaryOperationType compareUnsigned) { @@ -1667,7 +1662,7 @@ branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, unsigned next = 0; switch (op) { - case JumpIfEqual: + case lir::JumpIfEqual: next = c->code.length(); emit(c, bne(0)); @@ -1675,14 +1670,14 @@ branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, conditional(c, beq(0), target); break; - case JumpIfNotEqual: + case lir::JumpIfNotEqual: conditional(c, bne(0), target); compareSigned(c, 4, al, 4, bl); conditional(c, bne(0), target); break; - case JumpIfLess: + case lir::JumpIfLess: conditional(c, blt(0), target); next = c->code.length(); @@ -1692,7 +1687,7 @@ branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, conditional(c, blt(0), target); break; - case JumpIfGreater: + case lir::JumpIfGreater: conditional(c, bgt(0), target); next = c->code.length(); @@ -1702,7 +1697,7 @@ branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, conditional(c, bgt(0), target); break; - case JumpIfLessOrEqual: + case lir::JumpIfLessOrEqual: conditional(c, blt(0), target); next = c->code.length(); @@ -1712,7 +1707,7 @@ branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, conditional(c, ble(0), target); break; - case JumpIfGreaterOrEqual: + case lir::JumpIfGreaterOrEqual: conditional(c, bgt(0), target); next = c->code.length(); @@ -1734,13 +1729,13 @@ branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, } void -branchRR(Context* c, TernaryOperation op, unsigned size, - Assembler::Register* a, Assembler::Register* b, - Assembler::Constant* target) +branchRR(Context* c, lir::TernaryOperation op, unsigned size, + lir::Register* a, lir::Register* b, + lir::Constant* target) { if (size > TargetBytesPerWord) { - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); + lir::Register ah(a->high); + lir::Register bh(b->high); branchLong(c, op, a, &ah, b, &bh, target, CAST2(compareRR), CAST2(compareUnsignedRR)); @@ -1751,20 +1746,20 @@ branchRR(Context* c, TernaryOperation op, unsigned size, } void -branchCR(Context* c, TernaryOperation op, unsigned size, - Assembler::Constant* a, Assembler::Register* b, - Assembler::Constant* target) +branchCR(Context* c, lir::TernaryOperation op, unsigned size, + lir::Constant* a, lir::Register* b, + lir::Constant* target) { if (size > TargetBytesPerWord) { int64_t v = a->value->value(); ResolvedPromise low(v & ~static_cast(0)); - Assembler::Constant al(&low); + lir::Constant al(&low); ResolvedPromise high((v >> 32) & ~static_cast(0)); - Assembler::Constant ah(&high); + lir::Constant ah(&high); - Assembler::Register bh(b->high); + lir::Register bh(b->high); branchLong(c, op, &al, &ah, b, &bh, target, CAST2(compareCR), CAST2(compareUnsignedCR)); @@ -1775,9 +1770,9 @@ branchCR(Context* c, TernaryOperation op, unsigned size, } void -branchRM(Context* c, TernaryOperation op, unsigned size, - Assembler::Register* a, Assembler::Memory* b, - Assembler::Constant* target) +branchRM(Context* c, lir::TernaryOperation op, unsigned size, + lir::Register* a, lir::Memory* b, + lir::Constant* target) { assert(c, size <= TargetBytesPerWord); @@ -1786,9 +1781,9 @@ branchRM(Context* c, TernaryOperation op, unsigned size, } void -branchCM(Context* c, TernaryOperation op, unsigned size, - Assembler::Constant* a, Assembler::Memory* b, - Assembler::Constant* target) +branchCM(Context* c, lir::TernaryOperation op, unsigned size, + lir::Constant* a, lir::Memory* b, + lir::Constant* target) { assert(c, size <= TargetBytesPerWord); @@ -1803,17 +1798,17 @@ shiftMaskPromise(Context* c, Promise* base, unsigned shift, int64_t mask) } void -moveCM(Context* c, unsigned srcSize, Assembler::Constant* src, - unsigned dstSize, Assembler::Memory* dst) +moveCM(Context* c, unsigned srcSize, lir::Constant* src, + unsigned dstSize, lir::Memory* dst) { switch (dstSize) { case 8: { - Assembler::Constant srcHigh + lir::Constant srcHigh (shiftMaskPromise(c, src->value, 32, 0xFFFFFFFF)); - Assembler::Constant srcLow + lir::Constant srcLow (shiftMaskPromise(c, src->value, 0, 0xFFFFFFFF)); - Assembler::Memory dstLow + lir::Memory dstLow (dst->base, dst->offset + 4, dst->index, dst->scale); moveCM(c, 4, &srcLow, 4, &dstLow); @@ -1821,7 +1816,7 @@ moveCM(Context* c, unsigned srcSize, Assembler::Constant* src, } break; default: - Assembler::Register tmp(c->client->acquireTemporary()); + lir::Register tmp(c->client->acquireTemporary()); moveCR(c, srcSize, src, dstSize, &tmp); moveRM(c, dstSize, &tmp, dstSize, dst); c->client->releaseTemporary(tmp.low); @@ -1829,13 +1824,13 @@ moveCM(Context* c, unsigned srcSize, Assembler::Constant* src, } void -negateRR(Context* c, unsigned srcSize, Assembler::Register* src, - unsigned dstSize UNUSED, Assembler::Register* dst) +negateRR(Context* c, unsigned srcSize, lir::Register* src, + unsigned dstSize UNUSED, lir::Register* dst) { assert(c, srcSize == dstSize); if (srcSize == 8) { - Assembler::Register dstHigh(dst->high); + lir::Register dstHigh(dst->high); emit(c, subfic(dst->low, src->low, 0)); emit(c, subfze(dst->high, src->high)); @@ -1845,7 +1840,7 @@ negateRR(Context* c, unsigned srcSize, Assembler::Register* src, } void -callR(Context* c, unsigned size UNUSED, Assembler::Register* target) +callR(Context* c, unsigned size UNUSED, lir::Register* target) { assert(c, size == TargetBytesPerWord); @@ -1854,7 +1849,7 @@ callR(Context* c, unsigned size UNUSED, Assembler::Register* target) } void -callC(Context* c, unsigned size UNUSED, Assembler::Constant* target) +callC(Context* c, unsigned size UNUSED, lir::Constant* target) { assert(c, size == TargetBytesPerWord); @@ -1863,51 +1858,51 @@ callC(Context* c, unsigned size UNUSED, Assembler::Constant* target) } void -longCallC(Context* c, unsigned size UNUSED, Assembler::Constant* target) +longCallC(Context* c, unsigned size UNUSED, lir::Constant* target) { assert(c, size == TargetBytesPerWord); - Assembler::Register tmp(0); + lir::Register tmp(0); moveCR2(c, TargetBytesPerWord, target, TargetBytesPerWord, &tmp, 12); callR(c, TargetBytesPerWord, &tmp); } void -alignedLongCallC(Context* c, unsigned size UNUSED, Assembler::Constant* target) +alignedLongCallC(Context* c, unsigned size UNUSED, lir::Constant* target) { assert(c, size == TargetBytesPerWord); - Assembler::Register tmp(c->client->acquireTemporary()); - Assembler::Address address(appendConstantPoolEntry(c, target->value)); + lir::Register tmp(c->client->acquireTemporary()); + lir::Address address(appendConstantPoolEntry(c, target->value)); moveAR2(c, TargetBytesPerWord, &address, TargetBytesPerWord, &tmp, 12); callR(c, TargetBytesPerWord, &tmp); c->client->releaseTemporary(tmp.low); } void -longJumpC(Context* c, unsigned size UNUSED, Assembler::Constant* target) +longJumpC(Context* c, unsigned size UNUSED, lir::Constant* target) { assert(c, size == TargetBytesPerWord); - Assembler::Register tmp(0); + lir::Register tmp(0); moveCR2(c, TargetBytesPerWord, target, TargetBytesPerWord, &tmp, 12); jumpR(c, TargetBytesPerWord, &tmp); } void -alignedLongJumpC(Context* c, unsigned size UNUSED, Assembler::Constant* target) +alignedLongJumpC(Context* c, unsigned size UNUSED, lir::Constant* target) { assert(c, size == TargetBytesPerWord); - Assembler::Register tmp(c->client->acquireTemporary()); - Assembler::Address address(appendConstantPoolEntry(c, target->value)); + lir::Register tmp(c->client->acquireTemporary()); + lir::Address address(appendConstantPoolEntry(c, target->value)); moveAR2(c, TargetBytesPerWord, &address, TargetBytesPerWord, &tmp, 12); jumpR(c, TargetBytesPerWord, &tmp); c->client->releaseTemporary(tmp.low); } void -jumpC(Context* c, unsigned size UNUSED, Assembler::Constant* target) +jumpC(Context* c, unsigned size UNUSED, lir::Constant* target) { assert(c, size == TargetBytesPerWord); @@ -1993,10 +1988,10 @@ nextFrame(ArchitectureContext* c UNUSED, int32_t* start, unsigned size, void populateTables(ArchitectureContext* c) { - const OperandType C = ConstantOperand; - const OperandType A = AddressOperand; - const OperandType R = RegisterOperand; - const OperandType M = MemoryOperand; + const lir::OperandType C = lir::ConstantOperand; + const lir::OperandType A = lir::AddressOperand; + const lir::OperandType R = lir::RegisterOperand; + const lir::OperandType M = lir::MemoryOperand; OperationType* zo = c->operations; UnaryOperationType* uo = c->unaryOperations; @@ -2004,74 +1999,74 @@ populateTables(ArchitectureContext* c) TernaryOperationType* to = c->ternaryOperations; BranchOperationType* bro = c->branchOperations; - zo[Return] = return_; - zo[LoadBarrier] = memoryBarrier; - zo[StoreStoreBarrier] = memoryBarrier; - zo[StoreLoadBarrier] = memoryBarrier; - zo[Trap] = trap; + zo[lir::Return] = return_; + zo[lir::LoadBarrier] = memoryBarrier; + zo[lir::StoreStoreBarrier] = memoryBarrier; + zo[lir::StoreLoadBarrier] = memoryBarrier; + zo[lir::Trap] = trap; - uo[index(c, LongCall, C)] = CAST1(longCallC); + uo[index(c, lir::LongCall, C)] = CAST1(longCallC); - uo[index(c, AlignedLongCall, C)] = CAST1(alignedLongCallC); + uo[index(c, lir::AlignedLongCall, C)] = CAST1(alignedLongCallC); - uo[index(c, LongJump, C)] = CAST1(longJumpC); + uo[index(c, lir::LongJump, C)] = CAST1(longJumpC); - uo[index(c, AlignedLongJump, C)] = CAST1(alignedLongJumpC); + uo[index(c, lir::AlignedLongJump, C)] = CAST1(alignedLongJumpC); - uo[index(c, Jump, R)] = CAST1(jumpR); - uo[index(c, Jump, C)] = CAST1(jumpC); + uo[index(c, lir::Jump, R)] = CAST1(jumpR); + uo[index(c, lir::Jump, C)] = CAST1(jumpC); - uo[index(c, AlignedJump, R)] = CAST1(jumpR); - uo[index(c, AlignedJump, C)] = CAST1(jumpC); + uo[index(c, lir::AlignedJump, R)] = CAST1(jumpR); + uo[index(c, lir::AlignedJump, C)] = CAST1(jumpC); - uo[index(c, Call, C)] = CAST1(callC); - uo[index(c, Call, R)] = CAST1(callR); + uo[index(c, lir::Call, C)] = CAST1(callC); + uo[index(c, lir::Call, R)] = CAST1(callR); - uo[index(c, AlignedCall, C)] = CAST1(callC); - uo[index(c, AlignedCall, R)] = CAST1(callR); + uo[index(c, lir::AlignedCall, C)] = CAST1(callC); + uo[index(c, lir::AlignedCall, R)] = CAST1(callR); - bo[index(c, Move, R, R)] = CAST2(moveRR); - bo[index(c, Move, C, R)] = CAST2(moveCR); - bo[index(c, Move, C, M)] = CAST2(moveCM); - bo[index(c, Move, M, R)] = CAST2(moveMR); - bo[index(c, Move, R, M)] = CAST2(moveRM); - bo[index(c, Move, A, R)] = CAST2(moveAR); + bo[index(c, lir::Move, R, R)] = CAST2(moveRR); + bo[index(c, lir::Move, C, R)] = CAST2(moveCR); + bo[index(c, lir::Move, C, M)] = CAST2(moveCM); + bo[index(c, lir::Move, M, R)] = CAST2(moveMR); + bo[index(c, lir::Move, R, M)] = CAST2(moveRM); + bo[index(c, lir::Move, A, R)] = CAST2(moveAR); - bo[index(c, MoveZ, R, R)] = CAST2(moveZRR); - bo[index(c, MoveZ, M, R)] = CAST2(moveZMR); - bo[index(c, MoveZ, C, R)] = CAST2(moveCR); + bo[index(c, lir::MoveZ, R, R)] = CAST2(moveZRR); + bo[index(c, lir::MoveZ, M, R)] = CAST2(moveZMR); + bo[index(c, lir::MoveZ, C, R)] = CAST2(moveCR); - bo[index(c, Negate, R, R)] = CAST2(negateRR); + bo[index(c, lir::Negate, R, R)] = CAST2(negateRR); - to[index(c, Add, R)] = CAST3(addR); - to[index(c, Add, C)] = CAST3(addC); + to[index(c, lir::Add, R)] = CAST3(addR); + to[index(c, lir::Add, C)] = CAST3(addC); - to[index(c, Subtract, R)] = CAST3(subR); - to[index(c, Subtract, C)] = CAST3(subC); + to[index(c, lir::Subtract, R)] = CAST3(subR); + to[index(c, lir::Subtract, C)] = CAST3(subC); - to[index(c, Multiply, R)] = CAST3(multiplyR); + to[index(c, lir::Multiply, R)] = CAST3(multiplyR); - to[index(c, Divide, R)] = CAST3(divideR); + to[index(c, lir::Divide, R)] = CAST3(divideR); - to[index(c, Remainder, R)] = CAST3(remainderR); + to[index(c, lir::Remainder, R)] = CAST3(remainderR); - to[index(c, ShiftLeft, R)] = CAST3(shiftLeftR); - to[index(c, ShiftLeft, C)] = CAST3(shiftLeftC); + to[index(c, lir::ShiftLeft, R)] = CAST3(shiftLeftR); + to[index(c, lir::ShiftLeft, C)] = CAST3(shiftLeftC); - to[index(c, ShiftRight, R)] = CAST3(shiftRightR); - to[index(c, ShiftRight, C)] = CAST3(shiftRightC); + to[index(c, lir::ShiftRight, R)] = CAST3(shiftRightR); + to[index(c, lir::ShiftRight, C)] = CAST3(shiftRightC); - to[index(c, UnsignedShiftRight, R)] = CAST3(unsignedShiftRightR); - to[index(c, UnsignedShiftRight, C)] = CAST3(unsignedShiftRightC); + to[index(c, lir::UnsignedShiftRight, R)] = CAST3(unsignedShiftRightR); + to[index(c, lir::UnsignedShiftRight, C)] = CAST3(unsignedShiftRightC); - to[index(c, And, C)] = CAST3(andC); - to[index(c, And, R)] = CAST3(andR); + to[index(c, lir::And, C)] = CAST3(andC); + to[index(c, lir::And, R)] = CAST3(andR); - to[index(c, Or, C)] = CAST3(orC); - to[index(c, Or, R)] = CAST3(orR); + to[index(c, lir::Or, C)] = CAST3(orC); + to[index(c, lir::Or, R)] = CAST3(orR); - to[index(c, Xor, C)] = CAST3(xorC); - to[index(c, Xor, R)] = CAST3(xorR); + to[index(c, lir::Xor, C)] = CAST3(xorC); + to[index(c, lir::Xor, R)] = CAST3(xorR); bro[branchIndex(c, R, R)] = CAST_BRANCH(branchRR); bro[branchIndex(c, C, R)] = CAST_BRANCH(branchCR); @@ -2114,7 +2109,7 @@ class MyArchitecture: public Assembler::Architecture { } virtual int returnHigh() { - return (TargetBytesPerWord == 4 ? 3 : NoRegister); + return (TargetBytesPerWord == 4 ? 3 : lir::NoRegister); } virtual int virtualCallTarget() { @@ -2191,28 +2186,28 @@ class MyArchitecture: public Assembler::Architecture { - reinterpret_cast(instruction))); } - virtual void updateCall(UnaryOperation op UNUSED, + virtual void updateCall(lir::UnaryOperation op UNUSED, void* returnAddress, void* newTarget) { switch (op) { - case Call: - case Jump: - case AlignedCall: - case AlignedJump: { + case lir::Call: + case lir::Jump: + case lir::AlignedCall: + case lir::AlignedJump: { updateOffset(c.s, static_cast(returnAddress) - 4, false, reinterpret_cast(newTarget), 0); } break; - case LongCall: - case LongJump: { + case lir::LongCall: + case lir::LongJump: { updateImmediate (c.s, static_cast(returnAddress) - 12, reinterpret_cast(newTarget), TargetBytesPerWord, false); } break; - case AlignedLongCall: - case AlignedLongJump: { + case lir::AlignedLongCall: + case lir::AlignedLongJump: { uint32_t* p = static_cast(returnAddress) - 4; *reinterpret_cast(unha16(p[0] & 0xFFFF, p[1] & 0xFFFF)) = newTarget; @@ -2268,34 +2263,34 @@ class MyArchitecture: public Assembler::Architecture { return 0; } - virtual BinaryOperation hasBinaryIntrinsic(Thread*, object) { - return NoBinaryOperation; + virtual lir::BinaryOperation hasBinaryIntrinsic(Thread*, object) { + return lir::NoBinaryOperation; } - virtual TernaryOperation hasTernaryIntrinsic(Thread*, object) { - return NoTernaryOperation; + virtual lir::TernaryOperation hasTernaryIntrinsic(Thread*, object) { + return lir::NoTernaryOperation; } - virtual bool alwaysCondensed(BinaryOperation) { + virtual bool alwaysCondensed(lir::BinaryOperation) { return false; } - virtual bool alwaysCondensed(TernaryOperation) { + virtual bool alwaysCondensed(lir::TernaryOperation) { return false; } virtual void plan - (UnaryOperation, + (lir::UnaryOperation, unsigned, uint8_t* aTypeMask, uint64_t* aRegisterMask, bool* thunk) { - *aTypeMask = (1 << RegisterOperand) | (1 << ConstantOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::ConstantOperand); *aRegisterMask = ~static_cast(0); *thunk = false; } virtual void planSource - (BinaryOperation op, + (lir::BinaryOperation op, unsigned, uint8_t* aTypeMask, uint64_t* aRegisterMask, unsigned, bool* thunk) { @@ -2305,17 +2300,17 @@ class MyArchitecture: public Assembler::Architecture { *thunk = false; switch (op) { - case Negate: - *aTypeMask = (1 << RegisterOperand); + case lir::Negate: + *aTypeMask = (1 << lir::RegisterOperand); break; - case Absolute: - case FloatAbsolute: - case FloatSquareRoot: - case FloatNegate: - case Float2Float: - case Float2Int: - case Int2Float: + case lir::Absolute: + case lir::FloatAbsolute: + case lir::FloatSquareRoot: + case lir::FloatNegate: + case lir::Float2Float: + case lir::Float2Int: + case lir::Int2Float: *thunk = true; break; @@ -2325,16 +2320,16 @@ class MyArchitecture: public Assembler::Architecture { } virtual void planDestination - (BinaryOperation op, + (lir::BinaryOperation op, unsigned, uint8_t, uint64_t, unsigned, uint8_t* bTypeMask, uint64_t* bRegisterMask) { - *bTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); + *bTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand); *bRegisterMask = ~static_cast(0); switch (op) { - case Negate: - *bTypeMask = (1 << RegisterOperand); + case lir::Negate: + *bTypeMask = (1 << lir::RegisterOperand); break; default: @@ -2353,42 +2348,42 @@ class MyArchitecture: public Assembler::Architecture { *tmpTypeMask = 0; *tmpRegisterMask = 0; - if (dstTypeMask & (1 << MemoryOperand)) { + if (dstTypeMask & (1 << lir::MemoryOperand)) { // can't move directly from memory or constant to memory - *srcTypeMask = 1 << RegisterOperand; - *tmpTypeMask = 1 << RegisterOperand; + *srcTypeMask = 1 << lir::RegisterOperand; + *tmpTypeMask = 1 << lir::RegisterOperand; *tmpRegisterMask = ~static_cast(0); } } virtual void planSource - (TernaryOperation op, + (lir::TernaryOperation op, unsigned aSize, uint8_t* aTypeMask, uint64_t* aRegisterMask, unsigned, uint8_t* bTypeMask, uint64_t* bRegisterMask, unsigned, bool* thunk) { - *aTypeMask = (1 << RegisterOperand) | (1 << ConstantOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::ConstantOperand); *aRegisterMask = ~static_cast(0); - *bTypeMask = (1 << RegisterOperand); + *bTypeMask = (1 << lir::RegisterOperand); *bRegisterMask = ~static_cast(0); *thunk = false; switch (op) { - case Add: - case Subtract: + case lir::Add: + case lir::Subtract: if (aSize == 8) { - *aTypeMask = *bTypeMask = (1 << RegisterOperand); + *aTypeMask = *bTypeMask = (1 << lir::RegisterOperand); } break; - case Multiply: - *aTypeMask = *bTypeMask = (1 << RegisterOperand); + case lir::Multiply: + *aTypeMask = *bTypeMask = (1 << lir::RegisterOperand); break; - case Divide: - case Remainder: + case lir::Divide: + case lir::Remainder: // todo: we shouldn't need to defer to thunks for integers which // are smaller than or equal to tne native word size, but // PowerPC doesn't generate traps for divide by zero, so we'd @@ -2398,25 +2393,25 @@ class MyArchitecture: public Assembler::Architecture { if (true) {//if (TargetBytesPerWord == 4 and aSize == 8) { *thunk = true; } else { - *aTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << lir::RegisterOperand); } break; - case FloatAdd: - case FloatSubtract: - case FloatMultiply: - case FloatDivide: - case FloatRemainder: - case JumpIfFloatEqual: - case JumpIfFloatNotEqual: - case JumpIfFloatLess: - case JumpIfFloatGreater: - case JumpIfFloatLessOrEqual: - case JumpIfFloatGreaterOrEqual: - case JumpIfFloatLessOrUnordered: - case JumpIfFloatGreaterOrUnordered: - case JumpIfFloatLessOrEqualOrUnordered: - case JumpIfFloatGreaterOrEqualOrUnordered: + case lir::FloatAdd: + case lir::FloatSubtract: + case lir::FloatMultiply: + case lir::FloatDivide: + case lir::FloatRemainder: + case lir::JumpIfFloatEqual: + case lir::JumpIfFloatNotEqual: + case lir::JumpIfFloatLess: + case lir::JumpIfFloatGreater: + case lir::JumpIfFloatLessOrEqual: + case lir::JumpIfFloatGreaterOrEqual: + case lir::JumpIfFloatLessOrUnordered: + case lir::JumpIfFloatGreaterOrUnordered: + case lir::JumpIfFloatLessOrEqualOrUnordered: + case lir::JumpIfFloatGreaterOrEqualOrUnordered: *thunk = true; break; @@ -2426,16 +2421,16 @@ class MyArchitecture: public Assembler::Architecture { } virtual void planDestination - (TernaryOperation op, + (lir::TernaryOperation op, unsigned, uint8_t, uint64_t, unsigned, uint8_t, const uint64_t, unsigned, uint8_t* cTypeMask, uint64_t* cRegisterMask) { if (isBranch(op)) { - *cTypeMask = (1 << ConstantOperand); + *cTypeMask = (1 << lir::ConstantOperand); *cRegisterMask = 0; } else { - *cTypeMask = (1 << RegisterOperand); + *cTypeMask = (1 << lir::RegisterOperand); *cRegisterMask = ~static_cast(0); } } @@ -2474,41 +2469,41 @@ class MyAssembler: public Assembler { virtual void checkStackOverflow(uintptr_t handler, unsigned stackLimitOffsetFromThread) { - Register stack(StackRegister); - Memory stackLimit(ThreadRegister, stackLimitOffsetFromThread); - Constant handlerConstant + lir::Register stack(StackRegister); + lir::Memory stackLimit(ThreadRegister, stackLimitOffsetFromThread); + lir::Constant handlerConstant (new(c.zone) ResolvedPromise(handler)); - branchRM(&c, JumpIfGreaterOrEqual, TargetBytesPerWord, &stack, &stackLimit, + branchRM(&c, lir::JumpIfGreaterOrEqual, TargetBytesPerWord, &stack, &stackLimit, &handlerConstant); } virtual void saveFrame(unsigned stackOffset, unsigned) { - Register returnAddress(0); + lir::Register returnAddress(0); emit(&c, mflr(returnAddress.low)); - Memory returnAddressDst + lir::Memory returnAddressDst (StackRegister, ReturnAddressOffset * TargetBytesPerWord); moveRM(&c, TargetBytesPerWord, &returnAddress, TargetBytesPerWord, &returnAddressDst); - Register stack(StackRegister); - Memory stackDst(ThreadRegister, stackOffset); + lir::Register stack(StackRegister); + lir::Memory stackDst(ThreadRegister, stackOffset); moveRM(&c, TargetBytesPerWord, &stack, TargetBytesPerWord, &stackDst); } virtual void pushFrame(unsigned argumentCount, ...) { struct { unsigned size; - OperandType type; - Operand* operand; + lir::OperandType type; + lir::Operand* operand; } arguments[argumentCount]; va_list a; va_start(a, argumentCount); unsigned footprint = 0; for (unsigned i = 0; i < argumentCount; ++i) { arguments[i].size = va_arg(a, unsigned); - arguments[i].type = static_cast(va_arg(a, int)); - arguments[i].operand = va_arg(a, Operand*); + arguments[i].type = static_cast(va_arg(a, int)); + arguments[i].operand = va_arg(a, lir::Operand*); footprint += ceilingDivide(arguments[i].size, TargetBytesPerWord); } va_end(a); @@ -2518,21 +2513,21 @@ class MyAssembler: public Assembler { unsigned offset = 0; for (unsigned i = 0; i < argumentCount; ++i) { if (i < arch_->argumentRegisterCount()) { - Register dst(arch_->argumentRegister(i)); + lir::Register dst(arch_->argumentRegister(i)); - apply(Move, - arguments[i].size, arguments[i].type, arguments[i].operand, - pad(arguments[i].size, TargetBytesPerWord), RegisterOperand, - &dst); + apply(lir::Move, + OperandInfo(arguments[i].size, arguments[i].type, arguments[i].operand), + OperandInfo(pad(arguments[i].size, TargetBytesPerWord), lir::RegisterOperand, + &dst)); offset += ceilingDivide(arguments[i].size, TargetBytesPerWord); } else { - Memory dst + lir::Memory dst (ThreadRegister, (offset + FrameFooterSize) * TargetBytesPerWord); - apply(Move, - arguments[i].size, arguments[i].type, arguments[i].operand, - pad(arguments[i].size, TargetBytesPerWord), MemoryOperand, &dst); + apply(lir::Move, + OperandInfo(arguments[i].size, arguments[i].type, arguments[i].operand), + OperandInfo(pad(arguments[i].size, TargetBytesPerWord), lir::MemoryOperand, &dst)); offset += ceilingDivide(arguments[i].size, TargetBytesPerWord); } @@ -2540,37 +2535,37 @@ class MyAssembler: public Assembler { } virtual void allocateFrame(unsigned footprint) { - Register returnAddress(0); + lir::Register returnAddress(0); emit(&c, mflr(returnAddress.low)); - Memory returnAddressDst + lir::Memory returnAddressDst (StackRegister, ReturnAddressOffset * TargetBytesPerWord); moveRM(&c, TargetBytesPerWord, &returnAddress, TargetBytesPerWord, &returnAddressDst); - Register stack(StackRegister); - Memory stackDst(StackRegister, -footprint * TargetBytesPerWord); + lir::Register stack(StackRegister); + lir::Memory stackDst(StackRegister, -footprint * TargetBytesPerWord); moveAndUpdateRM (&c, TargetBytesPerWord, &stack, TargetBytesPerWord, &stackDst); } virtual void adjustFrame(unsigned difference) { - Register nextStack(0); - Memory stackSrc(StackRegister, 0); + lir::Register nextStack(0); + lir::Memory stackSrc(StackRegister, 0); moveMR(&c, TargetBytesPerWord, &stackSrc, TargetBytesPerWord, &nextStack); - Memory stackDst(StackRegister, -difference * TargetBytesPerWord); + lir::Memory stackDst(StackRegister, -difference * TargetBytesPerWord); moveAndUpdateRM (&c, TargetBytesPerWord, &nextStack, TargetBytesPerWord, &stackDst); } virtual void popFrame(unsigned) { - Register stack(StackRegister); - Memory stackSrc(StackRegister, 0); + lir::Register stack(StackRegister); + lir::Memory stackSrc(StackRegister, 0); moveMR(&c, TargetBytesPerWord, &stackSrc, TargetBytesPerWord, &stack); - Register returnAddress(0); - Memory returnAddressSrc + lir::Register returnAddress(0); + lir::Memory returnAddressSrc (StackRegister, ReturnAddressOffset * TargetBytesPerWord); moveMR(&c, TargetBytesPerWord, &returnAddressSrc, TargetBytesPerWord, &returnAddress); @@ -2585,8 +2580,8 @@ class MyAssembler: public Assembler { { if (TailCalls) { if (offset) { - Register tmp(0); - Memory returnAddressSrc + lir::Register tmp(0); + lir::Memory returnAddressSrc (StackRegister, (ReturnAddressOffset + footprint) * TargetBytesPerWord); moveMR(&c, TargetBytesPerWord, &returnAddressSrc, TargetBytesPerWord, @@ -2594,29 +2589,29 @@ class MyAssembler: public Assembler { emit(&c, mtlr(tmp.low)); - Memory stackSrc(StackRegister, footprint * TargetBytesPerWord); + lir::Memory stackSrc(StackRegister, footprint * TargetBytesPerWord); moveMR(&c, TargetBytesPerWord, &stackSrc, TargetBytesPerWord, &tmp); - Memory stackDst + lir::Memory stackDst (StackRegister, (footprint - offset) * TargetBytesPerWord); moveAndUpdateRM (&c, TargetBytesPerWord, &tmp, TargetBytesPerWord, &stackDst); - if (returnAddressSurrogate != NoRegister) { + if (returnAddressSurrogate != lir::NoRegister) { assert(&c, offset > 0); - Register ras(returnAddressSurrogate); - Memory dst + lir::Register ras(returnAddressSurrogate); + lir::Memory dst (StackRegister, (ReturnAddressOffset + offset) * TargetBytesPerWord); moveRM(&c, TargetBytesPerWord, &ras, TargetBytesPerWord, &dst); } - if (framePointerSurrogate != NoRegister) { + if (framePointerSurrogate != lir::NoRegister) { assert(&c, offset > 0); - Register fps(framePointerSurrogate); - Memory dst(StackRegister, offset * TargetBytesPerWord); + lir::Register fps(framePointerSurrogate); + lir::Memory dst(StackRegister, offset * TargetBytesPerWord); moveRM(&c, TargetBytesPerWord, &fps, TargetBytesPerWord, &dst); } } else { @@ -2636,11 +2631,11 @@ class MyAssembler: public Assembler { assert(&c, (argumentFootprint % StackAlignmentInWords) == 0); if (TailCalls and argumentFootprint > StackAlignmentInWords) { - Register tmp(0); - Memory stackSrc(StackRegister, 0); + lir::Register tmp(0); + lir::Memory stackSrc(StackRegister, 0); moveMR(&c, TargetBytesPerWord, &stackSrc, TargetBytesPerWord, &tmp); - Memory stackDst(StackRegister, + lir::Memory stackDst(StackRegister, (argumentFootprint - StackAlignmentInWords) * TargetBytesPerWord); moveAndUpdateRM @@ -2655,64 +2650,56 @@ class MyAssembler: public Assembler { { popFrame(frameFootprint); - Register tmp1(0); - Memory stackSrc(StackRegister, 0); + lir::Register tmp1(0); + lir::Memory stackSrc(StackRegister, 0); moveMR(&c, TargetBytesPerWord, &stackSrc, TargetBytesPerWord, &tmp1); - Register tmp2(5); - Memory newStackSrc(ThreadRegister, stackOffsetFromThread); + lir::Register tmp2(5); + lir::Memory newStackSrc(ThreadRegister, stackOffsetFromThread); moveMR(&c, TargetBytesPerWord, &newStackSrc, TargetBytesPerWord, &tmp2); - Register stack(StackRegister); + lir::Register stack(StackRegister); subR(&c, TargetBytesPerWord, &stack, &tmp2, &tmp2); - Memory stackDst(StackRegister, 0, tmp2.low); + lir::Memory stackDst(StackRegister, 0, tmp2.low); moveAndUpdateRM (&c, TargetBytesPerWord, &tmp1, TargetBytesPerWord, &stackDst); return_(&c); } - virtual void apply(Operation op) { + virtual void apply(lir::Operation op) { arch_->c.operations[op](&c); } - virtual void apply(UnaryOperation op, - unsigned aSize, OperandType aType, Operand* aOperand) + virtual void apply(lir::UnaryOperation op, OperandInfo a) { - arch_->c.unaryOperations[index(&(arch_->c), op, aType)] - (&c, aSize, aOperand); + arch_->c.unaryOperations[index(&(arch_->c), op, a.type)] + (&c, a.size, a.operand); } - virtual void apply(BinaryOperation op, - unsigned aSize, OperandType aType, Operand* aOperand, - unsigned bSize, OperandType bType, Operand* bOperand) + virtual void apply(lir::BinaryOperation op, OperandInfo a, OperandInfo b) { - arch_->c.binaryOperations[index(&(arch_->c), op, aType, bType)] - (&c, aSize, aOperand, bSize, bOperand); + arch_->c.binaryOperations[index(&(arch_->c), op, a.type, b.type)] + (&c, a.size, a.operand, b.size, b.operand); } - virtual void apply(TernaryOperation op, - unsigned aSize, OperandType aType, Operand* aOperand, - unsigned bSize, OperandType bType UNUSED, - Operand* bOperand, - unsigned cSize UNUSED, OperandType cType UNUSED, - Operand* cOperand) + virtual void apply(lir::TernaryOperation op, OperandInfo a, OperandInfo b, OperandInfo c) { if (isBranch(op)) { - assert(&c, aSize == bSize); - assert(&c, cSize == TargetBytesPerWord); - assert(&c, cType == ConstantOperand); + assert(&this->c, a.size == b.size); + assert(&this->c, c.size == TargetBytesPerWord); + assert(&this->c, c.type == lir::ConstantOperand); - arch_->c.branchOperations[branchIndex(&(arch_->c), aType, bType)] - (&c, op, aSize, aOperand, bOperand, cOperand); + arch_->c.branchOperations[branchIndex(&(arch_->c), a.type, b.type)] + (&this->c, op, a.size, a.operand, b.operand, c.operand); } else { - assert(&c, bSize == cSize); - assert(&c, bType == RegisterOperand); - assert(&c, cType == RegisterOperand); + assert(&this->c, b.size == c.size); + assert(&this->c, b.type == lir::RegisterOperand); + assert(&this->c, c.type == lir::RegisterOperand); - arch_->c.ternaryOperations[index(&(arch_->c), op, aType)] - (&c, bSize, aOperand, bOperand, cOperand); + arch_->c.ternaryOperations[index(&(arch_->c), op, a.type)] + (&this->c, b.size, a.operand, b.operand, c.operand); } } diff --git a/src/codegen/promise.h b/src/codegen/promise.h new file mode 100644 index 0000000000..1e21943999 --- /dev/null +++ b/src/codegen/promise.h @@ -0,0 +1,159 @@ +/* Copyright (c) 2008-2012, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#ifndef AVIAN_CODEGEN_PROMISE_H +#define AVIAN_CODEGEN_PROMISE_H + +#include "allocator.h" + +namespace avian { +namespace codegen { + +class Promise { + public: + class Listener { + public: + virtual bool resolve(int64_t value, void** location) = 0; + + Listener* next; + }; + + virtual int64_t value() = 0; + virtual bool resolved() = 0; + virtual Listener* listen(unsigned) { return 0; } +}; + +class ResolvedPromise: public Promise { + public: + ResolvedPromise(int64_t value): value_(value) { } + + virtual int64_t value() { + return value_; + } + + virtual bool resolved() { + return true; + } + + int64_t value_; +}; + +class ShiftMaskPromise: public Promise { + public: + ShiftMaskPromise(Promise* base, unsigned shift, int64_t mask): + base(base), shift(shift), mask(mask) + { } + + virtual int64_t value() { + return (base->value() >> shift) & mask; + } + + virtual bool resolved() { + return base->resolved(); + } + + Promise* base; + unsigned shift; + int64_t mask; +}; + +class CombinedPromise: public Promise { + public: + CombinedPromise(Promise* low, Promise* high): + low(low), high(high) + { } + + virtual int64_t value() { + return low->value() | (high->value() << 32); + } + + virtual bool resolved() { + return low->resolved() and high->resolved(); + } + + Promise* low; + Promise* high; +}; + +class OffsetPromise: public Promise { + public: + OffsetPromise(Promise* base, int64_t offset): + base(base), offset(offset) + { } + + virtual int64_t value() { + return base->value() + offset; + } + + virtual bool resolved() { + return base->resolved(); + } + + Promise* base; + int64_t offset; +}; + +class ListenPromise: public Promise { + public: + ListenPromise(vm::System* s, vm::Allocator* allocator): + s(s), allocator(allocator), listener(0) + { } + + virtual int64_t value() { + abort(s); + } + + virtual bool resolved() { + return false; + } + + virtual Listener* listen(unsigned sizeInBytes) { + Listener* l = static_cast(allocator->allocate(sizeInBytes)); + l->next = listener; + listener = l; + return l; + } + + vm::System* s; + vm::Allocator* allocator; + Listener* listener; + Promise* promise; +}; + +class DelayedPromise: public ListenPromise { + public: + DelayedPromise(vm::System* s, vm::Allocator* allocator, Promise* basis, + DelayedPromise* next): + ListenPromise(s, allocator), basis(basis), next(next) + { } + + virtual int64_t value() { + abort(s); + } + + virtual bool resolved() { + return false; + } + + virtual Listener* listen(unsigned sizeInBytes) { + Listener* l = static_cast(allocator->allocate(sizeInBytes)); + l->next = listener; + listener = l; + return l; + } + + Promise* basis; + DelayedPromise* next; +}; + +} // namespace codegen +} // namespace avian + +#endif // AVIAN_CODEGEN_PROMISE_H \ No newline at end of file diff --git a/src/codegen/targets.cpp b/src/codegen/targets.cpp index 64b5a0f630..2df6636120 100644 --- a/src/codegen/targets.cpp +++ b/src/codegen/targets.cpp @@ -14,7 +14,7 @@ namespace avian { namespace codegen { -vm::Assembler::Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures UNUSED) { +Assembler::Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures UNUSED) { #ifndef AVIAN_TARGET_ARCH #error "Must specify native target!" #endif diff --git a/src/codegen/targets.h b/src/codegen/targets.h index c4070b4641..1d146e4b4d 100644 --- a/src/codegen/targets.h +++ b/src/codegen/targets.h @@ -16,11 +16,11 @@ namespace avian { namespace codegen { -vm::Assembler::Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures); +Assembler::Architecture* makeArchitectureNative(vm::System* system, bool useNativeFeatures); -vm::Assembler::Architecture* makeArchitectureX86(vm::System* system, bool useNativeFeatures); -vm::Assembler::Architecture* makeArchitectureArm(vm::System* system, bool useNativeFeatures); -vm::Assembler::Architecture* makeArchitecturePowerpc(vm::System* system, bool useNativeFeatures); +Assembler::Architecture* makeArchitectureX86(vm::System* system, bool useNativeFeatures); +Assembler::Architecture* makeArchitectureArm(vm::System* system, bool useNativeFeatures); +Assembler::Architecture* makeArchitecturePowerpc(vm::System* system, bool useNativeFeatures); } // namespace codegen } // namespace avian diff --git a/src/codegen/x86/assembler.cpp b/src/codegen/x86/assembler.cpp index e1f107dc32..02836f40a3 100644 --- a/src/codegen/x86/assembler.cpp +++ b/src/codegen/x86/assembler.cpp @@ -21,6 +21,7 @@ #define CAST_BRANCH(x) reinterpret_cast(x) using namespace vm; +using namespace avian::codegen; namespace { @@ -126,14 +127,14 @@ class MyBlock: public Assembler::Block { typedef void (*OperationType)(Context*); -typedef void (*UnaryOperationType)(Context*, unsigned, Assembler::Operand*); +typedef void (*UnaryOperationType)(Context*, unsigned, lir::Operand*); typedef void (*BinaryOperationType) -(Context*, unsigned, Assembler::Operand*, unsigned, Assembler::Operand*); +(Context*, unsigned, lir::Operand*, unsigned, lir::Operand*); typedef void (*BranchOperationType) -(Context*, TernaryOperation, unsigned, Assembler::Operand*, - Assembler::Operand*, Assembler::Operand*); +(Context*, lir::TernaryOperation, unsigned, lir::Operand*, + lir::Operand*, lir::Operand*); class ArchitectureContext { public: @@ -143,17 +144,17 @@ class ArchitectureContext { System* s; bool useNativeFeatures; - OperationType operations[OperationCount]; - UnaryOperationType unaryOperations[UnaryOperationCount - * OperandTypeCount]; + OperationType operations[lir::OperationCount]; + UnaryOperationType unaryOperations[lir::UnaryOperationCount + * lir::OperandTypeCount]; BinaryOperationType binaryOperations - [(BinaryOperationCount + NonBranchTernaryOperationCount) - * OperandTypeCount - * OperandTypeCount]; + [(lir::BinaryOperationCount + lir::NonBranchTernaryOperationCount) + * lir::OperandTypeCount + * lir::OperandTypeCount]; BranchOperationType branchOperations - [(BranchOperationCount) - * OperandTypeCount - * OperandTypeCount]; + [lir::BranchOperationCount + * lir::OperandTypeCount + * lir::OperandTypeCount]; }; class Context { @@ -482,44 +483,44 @@ void maybeRex(Context* c, unsigned size, int a, int index, int base, } else { byte = REX_NONE; } - if (a != NoRegister and (a & 8)) byte |= REX_R; - if (index != NoRegister and (index & 8)) byte |= REX_X; - if (base != NoRegister and (base & 8)) byte |= REX_B; + if (a != lir::NoRegister and (a & 8)) byte |= REX_R; + if (index != lir::NoRegister and (index & 8)) byte |= REX_X; + if (base != lir::NoRegister and (base & 8)) byte |= REX_B; if (always or byte != REX_NONE) c->code.append(byte); } } void -maybeRex(Context* c, unsigned size, Assembler::Register* a, - Assembler::Register* b) +maybeRex(Context* c, unsigned size, lir::Register* a, + lir::Register* b) { - maybeRex(c, size, a->low, NoRegister, b->low, false); + maybeRex(c, size, a->low, lir::NoRegister, b->low, false); } void -alwaysRex(Context* c, unsigned size, Assembler::Register* a, - Assembler::Register* b) +alwaysRex(Context* c, unsigned size, lir::Register* a, + lir::Register* b) { - maybeRex(c, size, a->low, NoRegister, b->low, true); + maybeRex(c, size, a->low, lir::NoRegister, b->low, true); } void -maybeRex(Context* c, unsigned size, Assembler::Register* a) +maybeRex(Context* c, unsigned size, lir::Register* a) { - maybeRex(c, size, NoRegister, NoRegister, a->low, false); + maybeRex(c, size, lir::NoRegister, lir::NoRegister, a->low, false); } void -maybeRex(Context* c, unsigned size, Assembler::Register* a, - Assembler::Memory* b) +maybeRex(Context* c, unsigned size, lir::Register* a, + lir::Memory* b) { maybeRex(c, size, a->low, b->index, b->base, size == 1 and (a->low & 4)); } void -maybeRex(Context* c, unsigned size, Assembler::Memory* a) +maybeRex(Context* c, unsigned size, lir::Memory* a) { - maybeRex(c, size, NoRegister, a->index, a->base, false); + maybeRex(c, size, lir::NoRegister, a->index, a->base, false); } int @@ -529,7 +530,7 @@ regCode(int a) } int -regCode(Assembler::Register* a) +regCode(lir::Register* a) { return regCode(a->low); } @@ -541,7 +542,7 @@ modrm(Context* c, uint8_t mod, int a, int b) } void -modrm(Context* c, uint8_t mod, Assembler::Register* a, Assembler::Register* b) +modrm(Context* c, uint8_t mod, lir::Register* a, lir::Register* b) { modrm(c, mod, a->low, b->low); } @@ -555,7 +556,7 @@ sib(Context* c, unsigned scale, int index, int base) void modrmSib(Context* c, int width, int a, int scale, int index, int base) { - if (index == NoRegister) { + if (index == lir::NoRegister) { modrm(c, width, base, a); if (regCode(base) == rsp) { sib(c, 0x00, rsp, rsp); @@ -582,7 +583,7 @@ modrmSibImm(Context* c, int a, int scale, int index, int base, int offset) void -modrmSibImm(Context* c, Assembler::Register* a, Assembler::Memory* b) +modrmSibImm(Context* c, lir::Register* a, lir::Memory* b) { modrmSibImm(c, a->low, b->scale, b->index, b->base, b->offset); } @@ -638,7 +639,7 @@ storeLoadBarrier(Context* c) } void -unconditional(Context* c, unsigned jump, Assembler::Constant* a) +unconditional(Context* c, unsigned jump, lir::Constant* a) { appendOffsetTask(c, a->value, offset(c), 5); @@ -647,7 +648,7 @@ unconditional(Context* c, unsigned jump, Assembler::Constant* a) } void -conditional(Context* c, unsigned condition, Assembler::Constant* a) +conditional(Context* c, unsigned condition, lir::Constant* a) { appendOffsetTask(c, a->value, offset(c), 6); @@ -656,66 +657,54 @@ conditional(Context* c, unsigned condition, Assembler::Constant* a) } unsigned -index(ArchitectureContext*, UnaryOperation operation, OperandType operand) +index(ArchitectureContext*, lir::UnaryOperation operation, lir::OperandType operand) { - return operation + (UnaryOperationCount * operand); + return operation + (lir::UnaryOperationCount * operand); } unsigned -index(ArchitectureContext*, BinaryOperation operation, - OperandType operand1, - OperandType operand2) +index(ArchitectureContext*, lir::BinaryOperation operation, + lir::OperandType operand1, + lir::OperandType operand2) { return operation - + ((BinaryOperationCount + NonBranchTernaryOperationCount) * operand1) - + ((BinaryOperationCount + NonBranchTernaryOperationCount) - * OperandTypeCount * operand2); -} - -bool -isBranch(TernaryOperation op) -{ - return op > FloatMin; -} - -bool -isFloatBranch(TernaryOperation op) -{ - return op > JumpIfNotEqual; + + ((lir::BinaryOperationCount + lir::NonBranchTernaryOperationCount) * operand1) + + ((lir::BinaryOperationCount + lir::NonBranchTernaryOperationCount) + * lir::OperandTypeCount * operand2); } unsigned -index(ArchitectureContext* c UNUSED, TernaryOperation operation, - OperandType operand1, OperandType operand2) +index(ArchitectureContext* c UNUSED, lir::TernaryOperation operation, + lir::OperandType operand1, lir::OperandType operand2) { assert(c, not isBranch(operation)); - return BinaryOperationCount + operation - + ((BinaryOperationCount + NonBranchTernaryOperationCount) * operand1) - + ((BinaryOperationCount + NonBranchTernaryOperationCount) - * OperandTypeCount * operand2); + return lir::BinaryOperationCount + operation + + ((lir::BinaryOperationCount + lir::NonBranchTernaryOperationCount) * operand1) + + ((lir::BinaryOperationCount + lir::NonBranchTernaryOperationCount) + * lir::OperandTypeCount * operand2); } unsigned -branchIndex(ArchitectureContext* c UNUSED, OperandType operand1, - OperandType operand2) +branchIndex(ArchitectureContext* c UNUSED, lir::OperandType operand1, + lir::OperandType operand2) { - return operand1 + (OperandTypeCount * operand2); + return operand1 + (lir::OperandTypeCount * operand2); } void -moveCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b); +moveCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b); void -moveCR2(Context*, unsigned, Assembler::Constant*, unsigned, - Assembler::Register*, unsigned); +moveCR2(Context*, unsigned, lir::Constant*, unsigned, + lir::Register*, unsigned); void -callR(Context*, unsigned, Assembler::Register*); +callR(Context*, unsigned, lir::Register*); void -callC(Context* c, unsigned size UNUSED, Assembler::Constant* a) +callC(Context* c, unsigned size UNUSED, lir::Constant* a) { assert(c, size == TargetBytesPerWord); @@ -723,12 +712,12 @@ callC(Context* c, unsigned size UNUSED, Assembler::Constant* a) } void -longCallC(Context* c, unsigned size, Assembler::Constant* a) +longCallC(Context* c, unsigned size, lir::Constant* a) { assert(c, size == TargetBytesPerWord); if (TargetBytesPerWord == 8) { - Assembler::Register r(LongJumpRegister); + lir::Register r(LongJumpRegister); moveCR2(c, size, a, size, &r, 11); callR(c, size, &r); } else { @@ -737,7 +726,7 @@ longCallC(Context* c, unsigned size, Assembler::Constant* a) } void -jumpR(Context* c, unsigned size UNUSED, Assembler::Register* a) +jumpR(Context* c, unsigned size UNUSED, lir::Register* a) { assert(c, size == TargetBytesPerWord); @@ -746,7 +735,7 @@ jumpR(Context* c, unsigned size UNUSED, Assembler::Register* a) } void -jumpC(Context* c, unsigned size UNUSED, Assembler::Constant* a) +jumpC(Context* c, unsigned size UNUSED, lir::Constant* a) { assert(c, size == TargetBytesPerWord); @@ -754,7 +743,7 @@ jumpC(Context* c, unsigned size UNUSED, Assembler::Constant* a) } void -jumpM(Context* c, unsigned size UNUSED, Assembler::Memory* a) +jumpM(Context* c, unsigned size UNUSED, lir::Memory* a) { assert(c, size == TargetBytesPerWord); @@ -764,12 +753,12 @@ jumpM(Context* c, unsigned size UNUSED, Assembler::Memory* a) } void -longJumpC(Context* c, unsigned size, Assembler::Constant* a) +longJumpC(Context* c, unsigned size, lir::Constant* a) { assert(c, size == TargetBytesPerWord); if (TargetBytesPerWord == 8) { - Assembler::Register r(LongJumpRegister); + lir::Register r(LongJumpRegister); moveCR2(c, size, a, size, &r, 11); jumpR(c, size, &r); } else { @@ -778,7 +767,7 @@ longJumpC(Context* c, unsigned size, Assembler::Constant* a) } void -callR(Context* c, unsigned size UNUSED, Assembler::Register* a) +callR(Context* c, unsigned size UNUSED, lir::Register* a) { assert(c, size == TargetBytesPerWord); @@ -788,7 +777,7 @@ callR(Context* c, unsigned size UNUSED, Assembler::Register* a) } void -callM(Context* c, unsigned size UNUSED, Assembler::Memory* a) +callM(Context* c, unsigned size UNUSED, lir::Memory* a) { assert(c, size == TargetBytesPerWord); @@ -798,14 +787,14 @@ callM(Context* c, unsigned size UNUSED, Assembler::Memory* a) } void -alignedCallC(Context* c, unsigned size, Assembler::Constant* a) +alignedCallC(Context* c, unsigned size, lir::Constant* a) { new(c->zone) AlignmentPadding(c, 1, 4); callC(c, size, a); } void -alignedLongCallC(Context* c, unsigned size, Assembler::Constant* a) +alignedLongCallC(Context* c, unsigned size, lir::Constant* a) { assert(c, size == TargetBytesPerWord); @@ -818,14 +807,14 @@ alignedLongCallC(Context* c, unsigned size, Assembler::Constant* a) } void -alignedJumpC(Context* c, unsigned size, Assembler::Constant* a) +alignedJumpC(Context* c, unsigned size, lir::Constant* a) { new (c->zone) AlignmentPadding(c, 1, 4); jumpC(c, size, a); } void -alignedLongJumpC(Context* c, unsigned size, Assembler::Constant* a) +alignedLongJumpC(Context* c, unsigned size, lir::Constant* a) { assert(c, size == TargetBytesPerWord); @@ -838,10 +827,10 @@ alignedLongJumpC(Context* c, unsigned size, Assembler::Constant* a) } void -pushR(Context* c, unsigned size, Assembler::Register* a) +pushR(Context* c, unsigned size, lir::Register* a) { if (TargetBytesPerWord == 4 and size == 8) { - Assembler::Register ah(a->high); + lir::Register ah(a->high); pushR(c, 4, &ah); pushR(c, 4, a); @@ -852,14 +841,14 @@ pushR(Context* c, unsigned size, Assembler::Register* a) } void -moveRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize, Assembler::Register* b); +moveRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize, lir::Register* b); void -popR(Context* c, unsigned size, Assembler::Register* a) +popR(Context* c, unsigned size, lir::Register* a) { if (TargetBytesPerWord == 4 and size == 8) { - Assembler::Register ah(a->high); + lir::Register ah(a->high); popR(c, 4, a); popR(c, 4, &ah); @@ -873,19 +862,19 @@ popR(Context* c, unsigned size, Assembler::Register* a) } void -addCarryCR(Context* c, unsigned size, Assembler::Constant* a, - Assembler::Register* b); +addCarryCR(Context* c, unsigned size, lir::Constant* a, + lir::Register* b); void -negateR(Context* c, unsigned size, Assembler::Register* a) +negateR(Context* c, unsigned size, lir::Register* a) { if (TargetBytesPerWord == 4 and size == 8) { assert(c, a->low == rax and a->high == rdx); ResolvedPromise zeroPromise(0); - Assembler::Constant zero(&zeroPromise); + lir::Constant zero(&zeroPromise); - Assembler::Register ah(a->high); + lir::Register ah(a->high); negateR(c, 4, a); addCarryCR(c, 4, &zero, &ah); @@ -897,8 +886,8 @@ negateR(Context* c, unsigned size, Assembler::Register* a) } void -negateRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b UNUSED) +negateRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b UNUSED) { assert(c, aSize == bSize); @@ -906,19 +895,19 @@ negateRR(Context* c, unsigned aSize, Assembler::Register* a, } void -moveCR2(Context* c, UNUSED unsigned aSize, Assembler::Constant* a, - UNUSED unsigned bSize, Assembler::Register* b, unsigned promiseOffset) +moveCR2(Context* c, UNUSED unsigned aSize, lir::Constant* a, + UNUSED unsigned bSize, lir::Register* b, unsigned promiseOffset) { if (TargetBytesPerWord == 4 and bSize == 8) { int64_t v = a->value->value(); ResolvedPromise high((v >> 32) & 0xFFFFFFFF); - Assembler::Constant ah(&high); + lir::Constant ah(&high); ResolvedPromise low(v & 0xFFFFFFFF); - Assembler::Constant al(&low); + lir::Constant al(&low); - Assembler::Register bh(b->high); + lir::Register bh(b->high); moveCR(c, 4, &al, 4, b); moveCR(c, 4, &ah, 4, &bh); @@ -936,14 +925,14 @@ moveCR2(Context* c, UNUSED unsigned aSize, Assembler::Constant* a, } bool -floatReg(Assembler::Register* a) +floatReg(lir::Register* a) { return a->low >= xmm0; } void -sseMoveRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +sseMoveRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize >= 4); assert(c, aSize == bSize); @@ -974,19 +963,19 @@ sseMoveRR(Context* c, unsigned aSize, Assembler::Register* a, } void -sseMoveCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +sseMoveCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { assert(c, aSize <= TargetBytesPerWord); - Assembler::Register tmp(c->client->acquireTemporary(GeneralRegisterMask)); + lir::Register tmp(c->client->acquireTemporary(GeneralRegisterMask)); moveCR2(c, aSize, a, aSize, &tmp, 0); sseMoveRR(c, aSize, &tmp, bSize, b); c->client->releaseTemporary(tmp.low); } void -moveCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +moveCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { if (floatReg(b)) { sseMoveCR(c, aSize, a, bSize, b); @@ -996,8 +985,8 @@ moveCR(Context* c, unsigned aSize, Assembler::Constant* a, } void -swapRR(Context* c, unsigned aSize UNUSED, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +swapRR(Context* c, unsigned aSize UNUSED, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize == bSize); assert(c, aSize == TargetBytesPerWord); @@ -1008,8 +997,8 @@ swapRR(Context* c, unsigned aSize UNUSED, Assembler::Register* a, } void -moveRR(Context* c, unsigned aSize, Assembler::Register* a, - UNUSED unsigned bSize, Assembler::Register* b) +moveRR(Context* c, unsigned aSize, lir::Register* a, + UNUSED unsigned bSize, lir::Register* b) { if (floatReg(a) or floatReg(b)) { sseMoveRR(c, aSize, a, bSize, b); @@ -1017,8 +1006,8 @@ moveRR(Context* c, unsigned aSize, Assembler::Register* a, } if (TargetBytesPerWord == 4 and aSize == 8 and bSize == 8) { - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); + lir::Register ah(a->high); + lir::Register bh(b->high); if (a->high == b->low) { if (a->low == b->high) { @@ -1089,8 +1078,8 @@ moveRR(Context* c, unsigned aSize, Assembler::Register* a, } void -sseMoveMR(Context* c, unsigned aSize, Assembler::Memory* a, - unsigned bSize UNUSED, Assembler::Register* b) +sseMoveMR(Context* c, unsigned aSize, lir::Memory* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize >= 4); @@ -1107,8 +1096,8 @@ sseMoveMR(Context* c, unsigned aSize, Assembler::Memory* a, } void -moveMR(Context* c, unsigned aSize, Assembler::Memory* a, - unsigned bSize, Assembler::Register* b) +moveMR(Context* c, unsigned aSize, lir::Memory* a, + unsigned bSize, lir::Register* b) { if (floatReg(b)) { sseMoveMR(c, aSize, a, bSize, b); @@ -1149,8 +1138,8 @@ moveMR(Context* c, unsigned aSize, Assembler::Memory* a, case 8: if (TargetBytesPerWord == 4 and bSize == 8) { - Assembler::Memory ah(a->base, a->offset + 4, a->index, a->scale); - Assembler::Register bh(b->high); + lir::Memory ah(a->base, a->offset + 4, a->index, a->scale); + lir::Register bh(b->high); moveMR(c, 4, a, 4, b); moveMR(c, 4, &ah, 4, &bh); @@ -1166,8 +1155,8 @@ moveMR(Context* c, unsigned aSize, Assembler::Memory* a, } void -sseMoveRM(Context* c, unsigned aSize, Assembler::Register* a, - UNUSED unsigned bSize, Assembler::Memory* b) +sseMoveRM(Context* c, unsigned aSize, lir::Register* a, + UNUSED unsigned bSize, lir::Memory* b) { assert(c, aSize >= 4); assert(c, aSize == bSize); @@ -1185,8 +1174,8 @@ sseMoveRM(Context* c, unsigned aSize, Assembler::Register* a, } void -moveRM(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Memory* b) +moveRM(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Memory* b) { assert(c, aSize == bSize); @@ -1227,8 +1216,8 @@ moveRM(Context* c, unsigned aSize, Assembler::Register* a, opcode(c, 0x89); modrmSibImm(c, a, b); } else { - Assembler::Register ah(a->high); - Assembler::Memory bh(b->base, b->offset + 4, b->index, b->scale); + lir::Register ah(a->high); + lir::Memory bh(b->base, b->offset + 4, b->index, b->scale); moveRM(c, 4, a, 4, b); moveRM(c, 4, &ah, 4, &bh); @@ -1240,13 +1229,13 @@ moveRM(Context* c, unsigned aSize, Assembler::Register* a, } void -moveAR(Context* c, unsigned aSize, Assembler::Address* a, - unsigned bSize, Assembler::Register* b) +moveAR(Context* c, unsigned aSize, lir::Address* a, + unsigned bSize, lir::Register* b) { assert(c, TargetBytesPerWord == 8 or (aSize == 4 and bSize == 4)); - Assembler::Constant constant(a->address); - Assembler::Memory memory(b->low, 0, -1, 0); + lir::Constant constant(a->address); + lir::Memory memory(b->low, 0, -1, 0); moveCR(c, aSize, &constant, bSize, b); moveMR(c, bSize, &memory, bSize, b); @@ -1259,8 +1248,8 @@ shiftMaskPromise(Context* c, Promise* base, unsigned shift, int64_t mask) } void -moveCM(Context* c, unsigned aSize UNUSED, Assembler::Constant* a, - unsigned bSize, Assembler::Memory* b) +moveCM(Context* c, unsigned aSize UNUSED, lir::Constant* a, + unsigned bSize, lir::Memory* b) { switch (bSize) { case 1: @@ -1298,17 +1287,17 @@ moveCM(Context* c, unsigned aSize UNUSED, Assembler::Constant* a, modrmSibImm(c, 0, b->scale, b->index, b->base, b->offset); c->code.append4(a->value->value()); } else { - Assembler::Register tmp + lir::Register tmp (c->client->acquireTemporary(GeneralRegisterMask)); moveCR(c, 8, a, 8, &tmp); moveRM(c, 8, &tmp, 8, b); c->client->releaseTemporary(tmp.low); } } else { - Assembler::Constant ah(shiftMaskPromise(c, a->value, 32, 0xFFFFFFFF)); - Assembler::Constant al(shiftMaskPromise(c, a->value, 0, 0xFFFFFFFF)); + lir::Constant ah(shiftMaskPromise(c, a->value, 32, 0xFFFFFFFF)); + lir::Constant al(shiftMaskPromise(c, a->value, 0, 0xFFFFFFFF)); - Assembler::Memory bh(b->base, b->offset + 4, b->index, b->scale); + lir::Memory bh(b->base, b->offset + 4, b->index, b->scale); moveCM(c, 4, &al, 4, b); moveCM(c, 4, &ah, 4, &bh); @@ -1320,8 +1309,8 @@ moveCM(Context* c, unsigned aSize UNUSED, Assembler::Constant* a, } void -moveZRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +moveZRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { switch (aSize) { case 2: @@ -1335,8 +1324,8 @@ moveZRR(Context* c, unsigned aSize, Assembler::Register* a, } void -moveZMR(Context* c, unsigned aSize UNUSED, Assembler::Memory* a, - unsigned bSize UNUSED, Assembler::Register* b) +moveZMR(Context* c, unsigned aSize UNUSED, lir::Memory* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, bSize == TargetBytesPerWord); assert(c, aSize == 2); @@ -1347,8 +1336,8 @@ moveZMR(Context* c, unsigned aSize UNUSED, Assembler::Memory* a, } void -addCarryRR(Context* c, unsigned size, Assembler::Register* a, - Assembler::Register* b) +addCarryRR(Context* c, unsigned size, lir::Register* a, + lir::Register* b) { assert(c, TargetBytesPerWord == 8 or size == 4); @@ -1358,14 +1347,14 @@ addCarryRR(Context* c, unsigned size, Assembler::Register* a, } void -addRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +addRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize == bSize); if (TargetBytesPerWord == 4 and aSize == 8) { - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); + lir::Register ah(a->high); + lir::Register bh(b->high); addRR(c, 4, a, 4, b); addCarryRR(c, 4, &ah, &bh); @@ -1377,8 +1366,8 @@ addRR(Context* c, unsigned aSize, Assembler::Register* a, } void -addCarryCR(Context* c, unsigned size, Assembler::Constant* a, - Assembler::Register* b) +addCarryCR(Context* c, unsigned size, lir::Constant* a, + lir::Register* b) { int64_t v = a->value->value(); @@ -1393,8 +1382,8 @@ addCarryCR(Context* c, unsigned size, Assembler::Constant* a, } void -addCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +addCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { assert(c, aSize == bSize); @@ -1402,12 +1391,12 @@ addCR(Context* c, unsigned aSize, Assembler::Constant* a, if (v) { if (TargetBytesPerWord == 4 and bSize == 8) { ResolvedPromise high((v >> 32) & 0xFFFFFFFF); - Assembler::Constant ah(&high); + lir::Constant ah(&high); ResolvedPromise low(v & 0xFFFFFFFF); - Assembler::Constant al(&low); + lir::Constant al(&low); - Assembler::Register bh(b->high); + lir::Register bh(b->high); addCR(c, 4, &al, 4, b); addCarryCR(c, 4, &ah, &bh); @@ -1422,7 +1411,7 @@ addCR(Context* c, unsigned aSize, Assembler::Constant* a, c->code.append4(v); } } else { - Assembler::Register tmp + lir::Register tmp (c->client->acquireTemporary(GeneralRegisterMask)); moveCR(c, aSize, a, aSize, &tmp); addRR(c, aSize, &tmp, bSize, b); @@ -1433,8 +1422,8 @@ addCR(Context* c, unsigned aSize, Assembler::Constant* a, } void -subtractBorrowCR(Context* c, unsigned size UNUSED, Assembler::Constant* a, - Assembler::Register* b) +subtractBorrowCR(Context* c, unsigned size UNUSED, lir::Constant* a, + lir::Register* b) { assert(c, TargetBytesPerWord == 8 or size == 4); @@ -1449,12 +1438,12 @@ subtractBorrowCR(Context* c, unsigned size UNUSED, Assembler::Constant* a, } void -subtractRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize, Assembler::Register* b); +subtractRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize, lir::Register* b); void -subtractCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +subtractCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { assert(c, aSize == bSize); @@ -1462,12 +1451,12 @@ subtractCR(Context* c, unsigned aSize, Assembler::Constant* a, if (v) { if (TargetBytesPerWord == 4 and bSize == 8) { ResolvedPromise high((v >> 32) & 0xFFFFFFFF); - Assembler::Constant ah(&high); + lir::Constant ah(&high); ResolvedPromise low(v & 0xFFFFFFFF); - Assembler::Constant al(&low); + lir::Constant al(&low); - Assembler::Register bh(b->high); + lir::Register bh(b->high); subtractCR(c, 4, &al, 4, b); subtractBorrowCR(c, 4, &ah, &bh); @@ -1482,7 +1471,7 @@ subtractCR(Context* c, unsigned aSize, Assembler::Constant* a, c->code.append4(v); } } else { - Assembler::Register tmp + lir::Register tmp (c->client->acquireTemporary(GeneralRegisterMask)); moveCR(c, aSize, a, aSize, &tmp); subtractRR(c, aSize, &tmp, bSize, b); @@ -1493,8 +1482,8 @@ subtractCR(Context* c, unsigned aSize, Assembler::Constant* a, } void -subtractBorrowRR(Context* c, unsigned size, Assembler::Register* a, - Assembler::Register* b) +subtractBorrowRR(Context* c, unsigned size, lir::Register* a, + lir::Register* b) { assert(c, TargetBytesPerWord == 8 or size == 4); @@ -1504,14 +1493,14 @@ subtractBorrowRR(Context* c, unsigned size, Assembler::Register* a, } void -subtractRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +subtractRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize == bSize); if (TargetBytesPerWord == 4 and aSize == 8) { - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); + lir::Register ah(a->high); + lir::Register bh(b->high); subtractRR(c, 4, a, 4, b); subtractBorrowRR(c, 4, &ah, &bh); @@ -1523,15 +1512,15 @@ subtractRR(Context* c, unsigned aSize, Assembler::Register* a, } void -andRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +andRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize == bSize); if (TargetBytesPerWord == 4 and aSize == 8) { - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); + lir::Register ah(a->high); + lir::Register bh(b->high); andRR(c, 4, a, 4, b); andRR(c, 4, &ah, 4, &bh); @@ -1543,8 +1532,8 @@ andRR(Context* c, unsigned aSize, Assembler::Register* a, } void -andCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +andCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { assert(c, aSize == bSize); @@ -1552,12 +1541,12 @@ andCR(Context* c, unsigned aSize, Assembler::Constant* a, if (TargetBytesPerWord == 4 and bSize == 8) { ResolvedPromise high((v >> 32) & 0xFFFFFFFF); - Assembler::Constant ah(&high); + lir::Constant ah(&high); ResolvedPromise low(v & 0xFFFFFFFF); - Assembler::Constant al(&low); + lir::Constant al(&low); - Assembler::Register bh(b->high); + lir::Register bh(b->high); andCR(c, 4, &al, 4, b); andCR(c, 4, &ah, 4, &bh); @@ -1572,7 +1561,7 @@ andCR(Context* c, unsigned aSize, Assembler::Constant* a, c->code.append4(v); } } else { - Assembler::Register tmp + lir::Register tmp (c->client->acquireTemporary(GeneralRegisterMask)); moveCR(c, aSize, a, aSize, &tmp); andRR(c, aSize, &tmp, bSize, b); @@ -1582,14 +1571,14 @@ andCR(Context* c, unsigned aSize, Assembler::Constant* a, } void -orRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +orRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize == bSize); if (TargetBytesPerWord == 4 and aSize == 8) { - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); + lir::Register ah(a->high); + lir::Register bh(b->high); orRR(c, 4, a, 4, b); orRR(c, 4, &ah, 4, &bh); @@ -1601,8 +1590,8 @@ orRR(Context* c, unsigned aSize, Assembler::Register* a, } void -orCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +orCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { assert(c, aSize == bSize); @@ -1610,12 +1599,12 @@ orCR(Context* c, unsigned aSize, Assembler::Constant* a, if (v) { if (TargetBytesPerWord == 4 and bSize == 8) { ResolvedPromise high((v >> 32) & 0xFFFFFFFF); - Assembler::Constant ah(&high); + lir::Constant ah(&high); ResolvedPromise low(v & 0xFFFFFFFF); - Assembler::Constant al(&low); + lir::Constant al(&low); - Assembler::Register bh(b->high); + lir::Register bh(b->high); orCR(c, 4, &al, 4, b); orCR(c, 4, &ah, 4, &bh); @@ -1630,7 +1619,7 @@ orCR(Context* c, unsigned aSize, Assembler::Constant* a, c->code.append4(v); } } else { - Assembler::Register tmp + lir::Register tmp (c->client->acquireTemporary(GeneralRegisterMask)); moveCR(c, aSize, a, aSize, &tmp); orRR(c, aSize, &tmp, bSize, b); @@ -1641,12 +1630,12 @@ orCR(Context* c, unsigned aSize, Assembler::Constant* a, } void -xorRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +xorRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { if (TargetBytesPerWord == 4 and aSize == 8) { - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); + lir::Register ah(a->high); + lir::Register bh(b->high); xorRR(c, 4, a, 4, b); xorRR(c, 4, &ah, 4, &bh); @@ -1658,8 +1647,8 @@ xorRR(Context* c, unsigned aSize, Assembler::Register* a, } void -xorCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +xorCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { assert(c, aSize == bSize); @@ -1667,12 +1656,12 @@ xorCR(Context* c, unsigned aSize, Assembler::Constant* a, if (v) { if (TargetBytesPerWord == 4 and bSize == 8) { ResolvedPromise high((v >> 32) & 0xFFFFFFFF); - Assembler::Constant ah(&high); + lir::Constant ah(&high); ResolvedPromise low(v & 0xFFFFFFFF); - Assembler::Constant al(&low); + lir::Constant al(&low); - Assembler::Register bh(b->high); + lir::Register bh(b->high); xorCR(c, 4, &al, 4, b); xorCR(c, 4, &ah, 4, &bh); @@ -1687,7 +1676,7 @@ xorCR(Context* c, unsigned aSize, Assembler::Constant* a, c->code.append4(v); } } else { - Assembler::Register tmp + lir::Register tmp (c->client->acquireTemporary(GeneralRegisterMask)); moveCR(c, aSize, a, aSize, &tmp); xorRR(c, aSize, &tmp, bSize, b); @@ -1698,8 +1687,8 @@ xorCR(Context* c, unsigned aSize, Assembler::Constant* a, } void -multiplyRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +multiplyRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize == bSize); @@ -1712,12 +1701,12 @@ multiplyRR(Context* c, unsigned aSize, Assembler::Register* a, c->client->save(rax); - Assembler::Register axdx(rax, rdx); - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); + lir::Register axdx(rax, rdx); + lir::Register ah(a->high); + lir::Register bh(b->high); - Assembler::Register tmp(-1); - Assembler::Register* scratch; + lir::Register tmp(-1); + lir::Register* scratch; if (a->low == b->low) { tmp.low = c->client->acquireTemporary (GeneralRegisterMask & ~(1 << rax)); @@ -1749,30 +1738,30 @@ multiplyRR(Context* c, unsigned aSize, Assembler::Register* a, } void -branch(Context* c, TernaryOperation op, Assembler::Constant* target) +branch(Context* c, lir::TernaryOperation op, lir::Constant* target) { switch (op) { - case JumpIfEqual: + case lir::JumpIfEqual: conditional(c, 0x84, target); break; - case JumpIfNotEqual: + case lir::JumpIfNotEqual: conditional(c, 0x85, target); break; - case JumpIfLess: + case lir::JumpIfLess: conditional(c, 0x8c, target); break; - case JumpIfGreater: + case lir::JumpIfGreater: conditional(c, 0x8f, target); break; - case JumpIfLessOrEqual: + case lir::JumpIfLessOrEqual: conditional(c, 0x8e, target); break; - case JumpIfGreaterOrEqual: + case lir::JumpIfGreaterOrEqual: conditional(c, 0x8d, target); break; @@ -1782,49 +1771,49 @@ branch(Context* c, TernaryOperation op, Assembler::Constant* target) } void -branchFloat(Context* c, TernaryOperation op, Assembler::Constant* target) +branchFloat(Context* c, lir::TernaryOperation op, lir::Constant* target) { switch (op) { - case JumpIfFloatEqual: + case lir::JumpIfFloatEqual: conditional(c, 0x84, target); break; - case JumpIfFloatNotEqual: + case lir::JumpIfFloatNotEqual: conditional(c, 0x85, target); break; - case JumpIfFloatLess: + case lir::JumpIfFloatLess: conditional(c, 0x82, target); break; - case JumpIfFloatGreater: + case lir::JumpIfFloatGreater: conditional(c, 0x87, target); break; - case JumpIfFloatLessOrEqual: + case lir::JumpIfFloatLessOrEqual: conditional(c, 0x86, target); break; - case JumpIfFloatGreaterOrEqual: + case lir::JumpIfFloatGreaterOrEqual: conditional(c, 0x83, target); break; - case JumpIfFloatLessOrUnordered: + case lir::JumpIfFloatLessOrUnordered: conditional(c, 0x82, target); conditional(c, 0x8a, target); break; - case JumpIfFloatGreaterOrUnordered: + case lir::JumpIfFloatGreaterOrUnordered: conditional(c, 0x87, target); conditional(c, 0x8a, target); break; - case JumpIfFloatLessOrEqualOrUnordered: + case lir::JumpIfFloatLessOrEqualOrUnordered: conditional(c, 0x86, target); conditional(c, 0x8a, target); break; - case JumpIfFloatGreaterOrEqualOrUnordered: + case lir::JumpIfFloatGreaterOrEqualOrUnordered: conditional(c, 0x83, target); conditional(c, 0x8a, target); break; @@ -1835,8 +1824,8 @@ branchFloat(Context* c, TernaryOperation op, Assembler::Constant* target) } void -compareRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +compareRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize == bSize); assert(c, aSize <= TargetBytesPerWord); @@ -1847,8 +1836,8 @@ compareRR(Context* c, unsigned aSize, Assembler::Register* a, } void -compareCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +compareCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { assert(c, aSize == bSize); assert(c, TargetBytesPerWord == 8 or aSize == 4); @@ -1864,7 +1853,7 @@ compareCR(Context* c, unsigned aSize, Assembler::Constant* a, c->code.append4(v); } } else { - Assembler::Register tmp(c->client->acquireTemporary(GeneralRegisterMask)); + lir::Register tmp(c->client->acquireTemporary(GeneralRegisterMask)); moveCR(c, aSize, a, aSize, &tmp); compareRR(c, aSize, &tmp, bSize, b); c->client->releaseTemporary(tmp.low); @@ -1872,8 +1861,8 @@ compareCR(Context* c, unsigned aSize, Assembler::Constant* a, } void -compareRM(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Memory* b) +compareRM(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Memory* b) { assert(c, aSize == bSize); assert(c, TargetBytesPerWord == 8 or aSize == 4); @@ -1887,8 +1876,8 @@ compareRM(Context* c, unsigned aSize, Assembler::Register* a, } void -compareCM(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Memory* b) +compareCM(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Memory* b) { assert(c, aSize == bSize); assert(c, TargetBytesPerWord == 8 or aSize == 4); @@ -1907,7 +1896,7 @@ compareCM(Context* c, unsigned aSize, Assembler::Constant* a, abort(c); } } else { - Assembler::Register tmp(c->client->acquireTemporary(GeneralRegisterMask)); + lir::Register tmp(c->client->acquireTemporary(GeneralRegisterMask)); moveCR(c, aSize, a, bSize, &tmp); compareRM(c, bSize, &tmp, bSize, b); c->client->releaseTemporary(tmp.low); @@ -1915,8 +1904,8 @@ compareCM(Context* c, unsigned aSize, Assembler::Constant* a, } void -compareFloatRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +compareFloatRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize == bSize); @@ -1929,9 +1918,9 @@ compareFloatRR(Context* c, unsigned aSize, Assembler::Register* a, } void -branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, - Assembler::Operand* ah, Assembler::Operand* bl, - Assembler::Operand* bh, Assembler::Constant* target, +branchLong(Context* c, lir::TernaryOperation op, lir::Operand* al, + lir::Operand* ah, lir::Operand* bl, + lir::Operand* bh, lir::Constant* target, BinaryOperationType compare) { compare(c, 4, ah, 4, bh); @@ -1939,7 +1928,7 @@ branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, unsigned next = 0; switch (op) { - case JumpIfEqual: + case lir::JumpIfEqual: opcode(c, 0x75); // jne next = c->code.length(); c->code.append(0); @@ -1948,14 +1937,14 @@ branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, conditional(c, 0x84, target); // je break; - case JumpIfNotEqual: + case lir::JumpIfNotEqual: conditional(c, 0x85, target); // jne compare(c, 4, al, 4, bl); conditional(c, 0x85, target); // jne break; - case JumpIfLess: + case lir::JumpIfLess: conditional(c, 0x8c, target); // jl opcode(c, 0x7f); // jg @@ -1966,7 +1955,7 @@ branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, conditional(c, 0x82, target); // jb break; - case JumpIfGreater: + case lir::JumpIfGreater: conditional(c, 0x8f, target); // jg opcode(c, 0x7c); // jl @@ -1977,7 +1966,7 @@ branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, conditional(c, 0x87, target); // ja break; - case JumpIfLessOrEqual: + case lir::JumpIfLessOrEqual: conditional(c, 0x8c, target); // jl opcode(c, 0x7f); // jg @@ -1988,7 +1977,7 @@ branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, conditional(c, 0x86, target); // jbe break; - case JumpIfGreaterOrEqual: + case lir::JumpIfGreaterOrEqual: conditional(c, 0x8f, target); // jg opcode(c, 0x7c); // jl @@ -2010,16 +1999,16 @@ branchLong(Context* c, TernaryOperation op, Assembler::Operand* al, } void -branchRR(Context* c, TernaryOperation op, unsigned size, - Assembler::Register* a, Assembler::Register* b, - Assembler::Constant* target) +branchRR(Context* c, lir::TernaryOperation op, unsigned size, + lir::Register* a, lir::Register* b, + lir::Constant* target) { if (isFloatBranch(op)) { compareFloatRR(c, size, a, size, b); branchFloat(c, op, target); } else if (size > TargetBytesPerWord) { - Assembler::Register ah(a->high); - Assembler::Register bh(b->high); + lir::Register ah(a->high); + lir::Register bh(b->high); branchLong(c, op, a, &ah, b, &bh, target, CAST2(compareRR)); } else { @@ -2029,9 +2018,9 @@ branchRR(Context* c, TernaryOperation op, unsigned size, } void -branchCR(Context* c, TernaryOperation op, unsigned size, - Assembler::Constant* a, Assembler::Register* b, - Assembler::Constant* target) +branchCR(Context* c, lir::TernaryOperation op, unsigned size, + lir::Constant* a, lir::Register* b, + lir::Constant* target) { assert(c, not isFloatBranch(op)); @@ -2039,12 +2028,12 @@ branchCR(Context* c, TernaryOperation op, unsigned size, int64_t v = a->value->value(); ResolvedPromise low(v & ~static_cast(0)); - Assembler::Constant al(&low); + lir::Constant al(&low); ResolvedPromise high((v >> 32) & ~static_cast(0)); - Assembler::Constant ah(&high); + lir::Constant ah(&high); - Assembler::Register bh(b->high); + lir::Register bh(b->high); branchLong(c, op, &al, &ah, b, &bh, target, CAST2(compareCR)); } else { @@ -2054,9 +2043,9 @@ branchCR(Context* c, TernaryOperation op, unsigned size, } void -branchRM(Context* c, TernaryOperation op, unsigned size, - Assembler::Register* a, Assembler::Memory* b, - Assembler::Constant* target) +branchRM(Context* c, lir::TernaryOperation op, unsigned size, + lir::Register* a, lir::Memory* b, + lir::Constant* target) { assert(c, not isFloatBranch(op)); assert(c, size <= TargetBytesPerWord); @@ -2066,9 +2055,9 @@ branchRM(Context* c, TernaryOperation op, unsigned size, } void -branchCM(Context* c, TernaryOperation op, unsigned size, - Assembler::Constant* a, Assembler::Memory* b, - Assembler::Constant* target) +branchCM(Context* c, lir::TernaryOperation op, unsigned size, + lir::Constant* a, lir::Memory* b, + lir::Constant* target) { assert(c, not isFloatBranch(op)); assert(c, size <= TargetBytesPerWord); @@ -2078,14 +2067,14 @@ branchCM(Context* c, TernaryOperation op, unsigned size, } void -multiplyCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +multiplyCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { assert(c, aSize == bSize); if (TargetBytesPerWord == 4 and aSize == 8) { const uint32_t mask = GeneralRegisterMask & ~((1 << rax) | (1 << rdx)); - Assembler::Register tmp(c->client->acquireTemporary(mask), + lir::Register tmp(c->client->acquireTemporary(mask), c->client->acquireTemporary(mask)); moveCR(c, aSize, a, aSize, &tmp); @@ -2107,7 +2096,7 @@ multiplyCR(Context* c, unsigned aSize, Assembler::Constant* a, c->code.append4(v); } } else { - Assembler::Register tmp + lir::Register tmp (c->client->acquireTemporary(GeneralRegisterMask)); moveCR(c, aSize, a, aSize, &tmp); multiplyRR(c, aSize, &tmp, bSize, b); @@ -2118,8 +2107,8 @@ multiplyCR(Context* c, unsigned aSize, Assembler::Constant* a, } void -divideRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b UNUSED) +divideRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b UNUSED) { assert(c, aSize == bSize); @@ -2135,8 +2124,8 @@ divideRR(Context* c, unsigned aSize, Assembler::Register* a, } void -remainderRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +remainderRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, aSize == bSize); @@ -2150,25 +2139,25 @@ remainderRR(Context* c, unsigned aSize, Assembler::Register* a, maybeRex(c, aSize, b, a); opcode(c, 0xf7, 0xf8 + regCode(a)); - Assembler::Register dx(rdx); + lir::Register dx(rdx); moveRR(c, TargetBytesPerWord, &dx, TargetBytesPerWord, b); } void doShift(Context* c, UNUSED void (*shift) - (Context*, unsigned, Assembler::Register*, unsigned, - Assembler::Register*), - int type, UNUSED unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) + (Context*, unsigned, lir::Register*, unsigned, + lir::Register*), + int type, UNUSED unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { int64_t v = a->value->value(); if (TargetBytesPerWord == 4 and bSize == 8) { c->client->save(rcx); - Assembler::Register cx(rcx); + lir::Register cx(rcx); ResolvedPromise promise(v & 0x3F); - Assembler::Constant masked(&promise); + lir::Constant masked(&promise); moveCR(c, 4, &masked, 4, &cx); shift(c, aSize, &cx, bSize, b); } else { @@ -2185,15 +2174,15 @@ doShift(Context* c, UNUSED void (*shift) } void -shiftLeftRR(Context* c, UNUSED unsigned aSize, Assembler::Register* a, - unsigned bSize, Assembler::Register* b) +shiftLeftRR(Context* c, UNUSED unsigned aSize, lir::Register* a, + unsigned bSize, lir::Register* b) { if (TargetBytesPerWord == 4 and bSize == 8) { - Assembler::Register cx(rcx); + lir::Register cx(rcx); if (a->low != rcx) { c->client->save(rcx); ResolvedPromise promise(0x3F); - Assembler::Constant mask(&promise); + lir::Constant mask(&promise); moveRR(c, 4, a, 4, &cx); andCR(c, 4, &mask, 4, &cx); } @@ -2206,13 +2195,13 @@ shiftLeftRR(Context* c, UNUSED unsigned aSize, Assembler::Register* a, opcode(c, 0xd3, 0xe0 + b->low); ResolvedPromise promise(32); - Assembler::Constant constant(&promise); + lir::Constant constant(&promise); compareCR(c, aSize, &constant, aSize, &cx); opcode(c, 0x7c); //jl c->code.append(2 + 2); - Assembler::Register bh(b->high); + lir::Register bh(b->high); moveRR(c, 4, b, 4, &bh); // 2 bytes xorRR(c, 4, b, 4, b); // 2 bytes } else { @@ -2224,22 +2213,22 @@ shiftLeftRR(Context* c, UNUSED unsigned aSize, Assembler::Register* a, } void -shiftLeftCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +shiftLeftCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { doShift(c, shiftLeftRR, 0xe0, aSize, a, bSize, b); } void -shiftRightRR(Context* c, UNUSED unsigned aSize, Assembler::Register* a, - unsigned bSize, Assembler::Register* b) +shiftRightRR(Context* c, UNUSED unsigned aSize, lir::Register* a, + unsigned bSize, lir::Register* b) { if (TargetBytesPerWord == 4 and bSize == 8) { - Assembler::Register cx(rcx); + lir::Register cx(rcx); if (a->low != rcx) { c->client->save(rcx); ResolvedPromise promise(0x3F); - Assembler::Constant mask(&promise); + lir::Constant mask(&promise); moveRR(c, 4, a, 4, &cx); andCR(c, 4, &mask, 4, &cx); } @@ -2252,13 +2241,13 @@ shiftRightRR(Context* c, UNUSED unsigned aSize, Assembler::Register* a, opcode(c, 0xd3, 0xf8 + b->high); ResolvedPromise promise(32); - Assembler::Constant constant(&promise); + lir::Constant constant(&promise); compareCR(c, aSize, &constant, aSize, &cx); opcode(c, 0x7c); //jl c->code.append(2 + 3); - Assembler::Register bh(b->high); + lir::Register bh(b->high); moveRR(c, 4, &bh, 4, b); // 2 bytes // sar 31,high @@ -2273,22 +2262,22 @@ shiftRightRR(Context* c, UNUSED unsigned aSize, Assembler::Register* a, } void -shiftRightCR(Context* c, unsigned aSize, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +shiftRightCR(Context* c, unsigned aSize, lir::Constant* a, + unsigned bSize, lir::Register* b) { doShift(c, shiftRightRR, 0xf8, aSize, a, bSize, b); } void -unsignedShiftRightRR(Context* c, UNUSED unsigned aSize, Assembler::Register* a, - unsigned bSize, Assembler::Register* b) +unsignedShiftRightRR(Context* c, UNUSED unsigned aSize, lir::Register* a, + unsigned bSize, lir::Register* b) { if (TargetBytesPerWord == 4 and bSize == 8) { - Assembler::Register cx(rcx); + lir::Register cx(rcx); if (a->low != rcx) { c->client->save(rcx); ResolvedPromise promise(0x3F); - Assembler::Constant mask(&promise); + lir::Constant mask(&promise); moveRR(c, 4, a, 4, &cx); andCR(c, 4, &mask, 4, &cx); } @@ -2301,13 +2290,13 @@ unsignedShiftRightRR(Context* c, UNUSED unsigned aSize, Assembler::Register* a, opcode(c, 0xd3, 0xe8 + b->high); ResolvedPromise promise(32); - Assembler::Constant constant(&promise); + lir::Constant constant(&promise); compareCR(c, aSize, &constant, aSize, &cx); opcode(c, 0x7c); //jl c->code.append(2 + 2); - Assembler::Register bh(b->high); + lir::Register bh(b->high); moveRR(c, 4, &bh, 4, b); // 2 bytes xorRR(c, 4, &bh, 4, &bh); // 2 bytes } else { @@ -2319,15 +2308,15 @@ unsignedShiftRightRR(Context* c, UNUSED unsigned aSize, Assembler::Register* a, } void -unsignedShiftRightCR(Context* c, unsigned aSize UNUSED, Assembler::Constant* a, - unsigned bSize, Assembler::Register* b) +unsignedShiftRightCR(Context* c, unsigned aSize UNUSED, lir::Constant* a, + unsigned bSize, lir::Register* b) { doShift(c, unsignedShiftRightRR, 0xe8, aSize, a, bSize, b); } void -floatRegOp(Context* c, unsigned aSize, Assembler::Register* a, unsigned bSize, - Assembler::Register* b, uint8_t op, uint8_t mod = 0xc0) +floatRegOp(Context* c, unsigned aSize, lir::Register* a, unsigned bSize, + lir::Register* b, uint8_t op, uint8_t mod = 0xc0) { if (aSize == 4) { opcode(c, 0xf3); @@ -2340,8 +2329,8 @@ floatRegOp(Context* c, unsigned aSize, Assembler::Register* a, unsigned bSize, } void -floatMemOp(Context* c, unsigned aSize, Assembler::Memory* a, unsigned bSize, - Assembler::Register* b, uint8_t op) +floatMemOp(Context* c, unsigned aSize, lir::Memory* a, unsigned bSize, + lir::Register* b, uint8_t op) { if (aSize == 4) { opcode(c, 0xf3); @@ -2354,130 +2343,130 @@ floatMemOp(Context* c, unsigned aSize, Assembler::Memory* a, unsigned bSize, } void -floatSqrtRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +floatSqrtRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { floatRegOp(c, aSize, a, 4, b, 0x51); } void -floatSqrtMR(Context* c, unsigned aSize, Assembler::Memory* a, - unsigned bSize UNUSED, Assembler::Register* b) +floatSqrtMR(Context* c, unsigned aSize, lir::Memory* a, + unsigned bSize UNUSED, lir::Register* b) { floatMemOp(c, aSize, a, 4, b, 0x51); } void -floatAddRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +floatAddRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { floatRegOp(c, aSize, a, 4, b, 0x58); } void -floatAddMR(Context* c, unsigned aSize, Assembler::Memory* a, - unsigned bSize UNUSED, Assembler::Register* b) +floatAddMR(Context* c, unsigned aSize, lir::Memory* a, + unsigned bSize UNUSED, lir::Register* b) { floatMemOp(c, aSize, a, 4, b, 0x58); } void -floatSubtractRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +floatSubtractRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { floatRegOp(c, aSize, a, 4, b, 0x5c); } void -floatSubtractMR(Context* c, unsigned aSize, Assembler::Memory* a, - unsigned bSize UNUSED, Assembler::Register* b) +floatSubtractMR(Context* c, unsigned aSize, lir::Memory* a, + unsigned bSize UNUSED, lir::Register* b) { floatMemOp(c, aSize, a, 4, b, 0x5c); } void -floatMultiplyRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +floatMultiplyRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { floatRegOp(c, aSize, a, 4, b, 0x59); } void -floatMultiplyMR(Context* c, unsigned aSize, Assembler::Memory* a, - unsigned bSize UNUSED, Assembler::Register* b) +floatMultiplyMR(Context* c, unsigned aSize, lir::Memory* a, + unsigned bSize UNUSED, lir::Register* b) { floatMemOp(c, aSize, a, 4, b, 0x59); } void -floatDivideRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +floatDivideRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { floatRegOp(c, aSize, a, 4, b, 0x5e); } void -floatDivideMR(Context* c, unsigned aSize, Assembler::Memory* a, - unsigned bSize UNUSED, Assembler::Register* b) +floatDivideMR(Context* c, unsigned aSize, lir::Memory* a, + unsigned bSize UNUSED, lir::Register* b) { floatMemOp(c, aSize, a, 4, b, 0x5e); } void -float2FloatRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +float2FloatRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { floatRegOp(c, aSize, a, 4, b, 0x5a); } void -float2FloatMR(Context* c, unsigned aSize, Assembler::Memory* a, - unsigned bSize UNUSED, Assembler::Register* b) +float2FloatMR(Context* c, unsigned aSize, lir::Memory* a, + unsigned bSize UNUSED, lir::Register* b) { floatMemOp(c, aSize, a, 4, b, 0x5a); } void -float2IntRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize, Assembler::Register* b) +float2IntRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize, lir::Register* b) { assert(c, not floatReg(b)); floatRegOp(c, aSize, a, bSize, b, 0x2c); } void -float2IntMR(Context* c, unsigned aSize, Assembler::Memory* a, - unsigned bSize, Assembler::Register* b) +float2IntMR(Context* c, unsigned aSize, lir::Memory* a, + unsigned bSize, lir::Register* b) { floatMemOp(c, aSize, a, bSize, b, 0x2c); } void -int2FloatRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize, Assembler::Register* b) +int2FloatRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize, lir::Register* b) { floatRegOp(c, bSize, a, aSize, b, 0x2a); } void -int2FloatMR(Context* c, unsigned aSize, Assembler::Memory* a, - unsigned bSize, Assembler::Register* b) +int2FloatMR(Context* c, unsigned aSize, lir::Memory* a, + unsigned bSize, lir::Register* b) { floatMemOp(c, bSize, a, aSize, b, 0x2a); } void -floatNegateRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +floatNegateRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, floatReg(a) and floatReg(b)); // unlike most of the other floating point code, this does NOT // support doubles: assert(c, aSize == 4); ResolvedPromise pcon(0x80000000); - Assembler::Constant con(&pcon); + lir::Constant con(&pcon); if (a->low == b->low) { - Assembler::Register tmp(c->client->acquireTemporary(FloatRegisterMask)); + lir::Register tmp(c->client->acquireTemporary(FloatRegisterMask)); moveCR(c, 4, &con, 4, &tmp); maybeRex(c, 4, a, &tmp); opcode(c, 0x0f, 0x57); @@ -2493,17 +2482,17 @@ floatNegateRR(Context* c, unsigned aSize, Assembler::Register* a, } void -floatAbsoluteRR(Context* c, unsigned aSize UNUSED, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b) +floatAbsoluteRR(Context* c, unsigned aSize UNUSED, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b) { assert(c, floatReg(a) and floatReg(b)); // unlike most of the other floating point code, this does NOT // support doubles: assert(c, aSize == 4); ResolvedPromise pcon(0x7fffffff); - Assembler::Constant con(&pcon); + lir::Constant con(&pcon); if (a->low == b->low) { - Assembler::Register tmp(c->client->acquireTemporary(FloatRegisterMask)); + lir::Register tmp(c->client->acquireTemporary(FloatRegisterMask)); moveCR(c, 4, &con, 4, &tmp); maybeRex(c, 4, a, &tmp); opcode(c, 0x0f, 0x54); @@ -2518,11 +2507,11 @@ floatAbsoluteRR(Context* c, unsigned aSize UNUSED, Assembler::Register* a, } void -absoluteRR(Context* c, unsigned aSize, Assembler::Register* a, - unsigned bSize UNUSED, Assembler::Register* b UNUSED) +absoluteRR(Context* c, unsigned aSize, lir::Register* a, + unsigned bSize UNUSED, lir::Register* b UNUSED) { assert(c, aSize == bSize and a->low == rax and b->low == rax); - Assembler::Register d + lir::Register d (c->client->acquireTemporary(static_cast(1) << rdx)); maybeRex(c, aSize, a, b); opcode(c, 0x99); @@ -2624,114 +2613,114 @@ nextFrame(ArchitectureContext* c UNUSED, uint8_t* start, unsigned size UNUSED, void populateTables(ArchitectureContext* c) { - const OperandType C = ConstantOperand; - const OperandType A = AddressOperand; - const OperandType R = RegisterOperand; - const OperandType M = MemoryOperand; + const lir::OperandType C = lir::ConstantOperand; + const lir::OperandType A = lir::AddressOperand; + const lir::OperandType R = lir::RegisterOperand; + const lir::OperandType M = lir::MemoryOperand; OperationType* zo = c->operations; UnaryOperationType* uo = c->unaryOperations; BinaryOperationType* bo = c->binaryOperations; BranchOperationType* bro = c->branchOperations; - zo[Return] = return_; - zo[LoadBarrier] = ignore; - zo[StoreStoreBarrier] = ignore; - zo[StoreLoadBarrier] = storeLoadBarrier; - zo[Trap] = trap; + zo[lir::Return] = return_; + zo[lir::LoadBarrier] = ignore; + zo[lir::StoreStoreBarrier] = ignore; + zo[lir::StoreLoadBarrier] = storeLoadBarrier; + zo[lir::Trap] = trap; - uo[index(c, Call, C)] = CAST1(callC); - uo[index(c, Call, R)] = CAST1(callR); - uo[index(c, Call, M)] = CAST1(callM); + uo[index(c, lir::Call, C)] = CAST1(callC); + uo[index(c, lir::Call, R)] = CAST1(callR); + uo[index(c, lir::Call, M)] = CAST1(callM); - uo[index(c, AlignedCall, C)] = CAST1(alignedCallC); + uo[index(c, lir::AlignedCall, C)] = CAST1(alignedCallC); - uo[index(c, LongCall, C)] = CAST1(longCallC); + uo[index(c, lir::LongCall, C)] = CAST1(longCallC); - uo[index(c, AlignedLongCall, C)] = CAST1(alignedLongCallC); + uo[index(c, lir::AlignedLongCall, C)] = CAST1(alignedLongCallC); - uo[index(c, Jump, R)] = CAST1(jumpR); - uo[index(c, Jump, C)] = CAST1(jumpC); - uo[index(c, Jump, M)] = CAST1(jumpM); + uo[index(c, lir::Jump, R)] = CAST1(jumpR); + uo[index(c, lir::Jump, C)] = CAST1(jumpC); + uo[index(c, lir::Jump, M)] = CAST1(jumpM); - uo[index(c, AlignedJump, C)] = CAST1(alignedJumpC); + uo[index(c, lir::AlignedJump, C)] = CAST1(alignedJumpC); - uo[index(c, LongJump, C)] = CAST1(longJumpC); + uo[index(c, lir::LongJump, C)] = CAST1(longJumpC); - uo[index(c, AlignedLongJump, C)] = CAST1(alignedLongJumpC); + uo[index(c, lir::AlignedLongJump, C)] = CAST1(alignedLongJumpC); - bo[index(c, Negate, R, R)] = CAST2(negateRR); + bo[index(c, lir::Negate, R, R)] = CAST2(negateRR); - bo[index(c, FloatNegate, R, R)] = CAST2(floatNegateRR); + bo[index(c, lir::FloatNegate, R, R)] = CAST2(floatNegateRR); - bo[index(c, Move, R, R)] = CAST2(moveRR); - bo[index(c, Move, C, R)] = CAST2(moveCR); - bo[index(c, Move, M, R)] = CAST2(moveMR); - bo[index(c, Move, R, M)] = CAST2(moveRM); - bo[index(c, Move, C, M)] = CAST2(moveCM); - bo[index(c, Move, A, R)] = CAST2(moveAR); + bo[index(c, lir::Move, R, R)] = CAST2(moveRR); + bo[index(c, lir::Move, C, R)] = CAST2(moveCR); + bo[index(c, lir::Move, M, R)] = CAST2(moveMR); + bo[index(c, lir::Move, R, M)] = CAST2(moveRM); + bo[index(c, lir::Move, C, M)] = CAST2(moveCM); + bo[index(c, lir::Move, A, R)] = CAST2(moveAR); - bo[index(c, FloatSquareRoot, R, R)] = CAST2(floatSqrtRR); - bo[index(c, FloatSquareRoot, M, R)] = CAST2(floatSqrtMR); + bo[index(c, lir::FloatSquareRoot, R, R)] = CAST2(floatSqrtRR); + bo[index(c, lir::FloatSquareRoot, M, R)] = CAST2(floatSqrtMR); - bo[index(c, MoveZ, R, R)] = CAST2(moveZRR); - bo[index(c, MoveZ, M, R)] = CAST2(moveZMR); - bo[index(c, MoveZ, C, R)] = CAST2(moveCR); + bo[index(c, lir::MoveZ, R, R)] = CAST2(moveZRR); + bo[index(c, lir::MoveZ, M, R)] = CAST2(moveZMR); + bo[index(c, lir::MoveZ, C, R)] = CAST2(moveCR); - bo[index(c, Add, R, R)] = CAST2(addRR); - bo[index(c, Add, C, R)] = CAST2(addCR); + bo[index(c, lir::Add, R, R)] = CAST2(addRR); + bo[index(c, lir::Add, C, R)] = CAST2(addCR); - bo[index(c, Subtract, C, R)] = CAST2(subtractCR); - bo[index(c, Subtract, R, R)] = CAST2(subtractRR); + bo[index(c, lir::Subtract, C, R)] = CAST2(subtractCR); + bo[index(c, lir::Subtract, R, R)] = CAST2(subtractRR); - bo[index(c, FloatAdd, R, R)] = CAST2(floatAddRR); - bo[index(c, FloatAdd, M, R)] = CAST2(floatAddMR); + bo[index(c, lir::FloatAdd, R, R)] = CAST2(floatAddRR); + bo[index(c, lir::FloatAdd, M, R)] = CAST2(floatAddMR); - bo[index(c, FloatSubtract, R, R)] = CAST2(floatSubtractRR); - bo[index(c, FloatSubtract, M, R)] = CAST2(floatSubtractMR); + bo[index(c, lir::FloatSubtract, R, R)] = CAST2(floatSubtractRR); + bo[index(c, lir::FloatSubtract, M, R)] = CAST2(floatSubtractMR); - bo[index(c, And, R, R)] = CAST2(andRR); - bo[index(c, And, C, R)] = CAST2(andCR); + bo[index(c, lir::And, R, R)] = CAST2(andRR); + bo[index(c, lir::And, C, R)] = CAST2(andCR); - bo[index(c, Or, R, R)] = CAST2(orRR); - bo[index(c, Or, C, R)] = CAST2(orCR); + bo[index(c, lir::Or, R, R)] = CAST2(orRR); + bo[index(c, lir::Or, C, R)] = CAST2(orCR); - bo[index(c, Xor, R, R)] = CAST2(xorRR); - bo[index(c, Xor, C, R)] = CAST2(xorCR); + bo[index(c, lir::Xor, R, R)] = CAST2(xorRR); + bo[index(c, lir::Xor, C, R)] = CAST2(xorCR); - bo[index(c, Multiply, R, R)] = CAST2(multiplyRR); - bo[index(c, Multiply, C, R)] = CAST2(multiplyCR); + bo[index(c, lir::Multiply, R, R)] = CAST2(multiplyRR); + bo[index(c, lir::Multiply, C, R)] = CAST2(multiplyCR); - bo[index(c, Divide, R, R)] = CAST2(divideRR); + bo[index(c, lir::Divide, R, R)] = CAST2(divideRR); - bo[index(c, FloatMultiply, R, R)] = CAST2(floatMultiplyRR); - bo[index(c, FloatMultiply, M, R)] = CAST2(floatMultiplyMR); + bo[index(c, lir::FloatMultiply, R, R)] = CAST2(floatMultiplyRR); + bo[index(c, lir::FloatMultiply, M, R)] = CAST2(floatMultiplyMR); - bo[index(c, FloatDivide, R, R)] = CAST2(floatDivideRR); - bo[index(c, FloatDivide, M, R)] = CAST2(floatDivideMR); + bo[index(c, lir::FloatDivide, R, R)] = CAST2(floatDivideRR); + bo[index(c, lir::FloatDivide, M, R)] = CAST2(floatDivideMR); - bo[index(c, Remainder, R, R)] = CAST2(remainderRR); + bo[index(c, lir::Remainder, R, R)] = CAST2(remainderRR); - bo[index(c, ShiftLeft, R, R)] = CAST2(shiftLeftRR); - bo[index(c, ShiftLeft, C, R)] = CAST2(shiftLeftCR); + bo[index(c, lir::ShiftLeft, R, R)] = CAST2(shiftLeftRR); + bo[index(c, lir::ShiftLeft, C, R)] = CAST2(shiftLeftCR); - bo[index(c, ShiftRight, R, R)] = CAST2(shiftRightRR); - bo[index(c, ShiftRight, C, R)] = CAST2(shiftRightCR); + bo[index(c, lir::ShiftRight, R, R)] = CAST2(shiftRightRR); + bo[index(c, lir::ShiftRight, C, R)] = CAST2(shiftRightCR); - bo[index(c, UnsignedShiftRight, R, R)] = CAST2(unsignedShiftRightRR); - bo[index(c, UnsignedShiftRight, C, R)] = CAST2(unsignedShiftRightCR); + bo[index(c, lir::UnsignedShiftRight, R, R)] = CAST2(unsignedShiftRightRR); + bo[index(c, lir::UnsignedShiftRight, C, R)] = CAST2(unsignedShiftRightCR); - bo[index(c, Float2Float, R, R)] = CAST2(float2FloatRR); - bo[index(c, Float2Float, M, R)] = CAST2(float2FloatMR); + bo[index(c, lir::Float2Float, R, R)] = CAST2(float2FloatRR); + bo[index(c, lir::Float2Float, M, R)] = CAST2(float2FloatMR); - bo[index(c, Float2Int, R, R)] = CAST2(float2IntRR); - bo[index(c, Float2Int, M, R)] = CAST2(float2IntMR); + bo[index(c, lir::Float2Int, R, R)] = CAST2(float2IntRR); + bo[index(c, lir::Float2Int, M, R)] = CAST2(float2IntMR); - bo[index(c, Int2Float, R, R)] = CAST2(int2FloatRR); - bo[index(c, Int2Float, M, R)] = CAST2(int2FloatMR); + bo[index(c, lir::Int2Float, R, R)] = CAST2(int2FloatRR); + bo[index(c, lir::Int2Float, M, R)] = CAST2(int2FloatMR); - bo[index(c, Absolute, R, R)] = CAST2(absoluteRR); - bo[index(c, FloatAbsolute, R, R)] = CAST2(floatAbsoluteRR); + bo[index(c, lir::Absolute, R, R)] = CAST2(absoluteRR); + bo[index(c, lir::FloatAbsolute, R, R)] = CAST2(floatAbsoluteRR); bro[branchIndex(c, R, R)] = CAST_BRANCH(branchRR); bro[branchIndex(c, C, R)] = CAST_BRANCH(branchCR); @@ -2780,7 +2769,7 @@ class MyArchitecture: public Assembler::Architecture { } virtual int returnHigh() { - return (TargetBytesPerWord == 4 ? rdx : NoRegister); + return (TargetBytesPerWord == 4 ? rdx : lir::NoRegister); } virtual int virtualCallTarget() { @@ -2891,28 +2880,28 @@ class MyArchitecture: public Assembler::Architecture { return *instruction == 0xE8 and actualTarget == target; } - virtual void updateCall(UnaryOperation op, void* returnAddress, + virtual void updateCall(lir::UnaryOperation op, void* returnAddress, void* newTarget) { bool assertAlignment UNUSED; switch (op) { - case AlignedCall: - op = Call; + case lir::AlignedCall: + op = lir::Call; assertAlignment = true; break; - case AlignedJump: - op = Jump; + case lir::AlignedJump: + op = lir::Jump; assertAlignment = true; break; - case AlignedLongCall: - op = LongCall; + case lir::AlignedLongCall: + op = lir::LongCall; assertAlignment = true; break; - case AlignedLongJump: - op = LongJump; + case lir::AlignedLongJump: + op = lir::LongJump; assertAlignment = true; break; @@ -2920,11 +2909,11 @@ class MyArchitecture: public Assembler::Architecture { assertAlignment = false; } - if (TargetBytesPerWord == 4 or op == Call or op == Jump) { + if (TargetBytesPerWord == 4 or op == lir::Call or op == lir::Jump) { uint8_t* instruction = static_cast(returnAddress) - 5; - assert(&c, ((op == Call or op == LongCall) and *instruction == 0xE8) - or ((op == Jump or op == LongJump) and *instruction == 0xE9)); + assert(&c, ((op == lir::Call or op == lir::LongCall) and *instruction == 0xE8) + or ((op == lir::Jump or op == lir::LongJump) and *instruction == 0xE9)); assert(&c, (not assertAlignment) or reinterpret_cast(instruction + 1) % 4 == 0); @@ -2942,8 +2931,8 @@ class MyArchitecture: public Assembler::Architecture { assert(&c, instruction[0] == 0x49 and instruction[1] == 0xBA); assert(&c, instruction[10] == 0x41 and instruction[11] == 0xFF); - assert(&c, (op == LongCall and instruction[12] == 0xD2) - or (op == LongJump and instruction[12] == 0xE2)); + assert(&c, (op == lir::LongCall and instruction[12] == 0xD2) + or (op == lir::LongJump and instruction[12] == 0xE2)); assert(&c, (not assertAlignment) or reinterpret_cast(instruction + 2) % 8 == 0); @@ -2987,18 +2976,18 @@ class MyArchitecture: public Assembler::Architecture { return 0; } - virtual bool alwaysCondensed(BinaryOperation op) { + virtual bool alwaysCondensed(lir::BinaryOperation op) { switch(op) { - case Float2Float: - case Float2Int: - case Int2Float: - case FloatAbsolute: - case FloatNegate: - case FloatSquareRoot: + case lir::Float2Float: + case lir::Float2Int: + case lir::Int2Float: + case lir::FloatAbsolute: + case lir::FloatNegate: + case lir::FloatSquareRoot: return false; - case Negate: - case Absolute: + case lir::Negate: + case lir::Absolute: return true; default: @@ -3006,7 +2995,7 @@ class MyArchitecture: public Assembler::Architecture { } } - virtual bool alwaysCondensed(TernaryOperation) { + virtual bool alwaysCondensed(lir::TernaryOperation) { return true; } @@ -3019,18 +3008,18 @@ class MyArchitecture: public Assembler::Architecture { } virtual void plan - (UnaryOperation, + (lir::UnaryOperation, unsigned, uint8_t* aTypeMask, uint64_t* aRegisterMask, bool* thunk) { - *aTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand) - | (1 << ConstantOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand) + | (1 << lir::ConstantOperand); *aRegisterMask = ~static_cast(0); *thunk = false; } virtual void planSource - (BinaryOperation op, + (lir::BinaryOperation op, unsigned aSize, uint8_t* aTypeMask, uint64_t* aRegisterMask, unsigned bSize, bool* thunk) { @@ -3041,24 +3030,24 @@ class MyArchitecture: public Assembler::Architecture { *thunk = false; switch (op) { - case Negate: - *aTypeMask = (1 << RegisterOperand); + case lir::Negate: + *aTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = (static_cast(1) << (rdx + 32)) | (static_cast(1) << rax); break; - case Absolute: + case lir::Absolute: if (aSize <= TargetBytesPerWord) { - *aTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = (static_cast(1) << rax); } else { *thunk = true; } break; - case FloatAbsolute: + case lir::FloatAbsolute: if (useSSE(&c)) { - *aTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = (static_cast(FloatRegisterMask) << 32) | FloatRegisterMask; } else { @@ -3066,19 +3055,19 @@ class MyArchitecture: public Assembler::Architecture { } break; - case FloatNegate: + case lir::FloatNegate: // floatNegateRR does not support doubles if (useSSE(&c) and aSize == 4 and bSize == 4) { - *aTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = FloatRegisterMask; } else { *thunk = true; } break; - case FloatSquareRoot: + case lir::FloatSquareRoot: if (useSSE(&c)) { - *aTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand); *aRegisterMask = (static_cast(FloatRegisterMask) << 32) | FloatRegisterMask; } else { @@ -3086,9 +3075,9 @@ class MyArchitecture: public Assembler::Architecture { } break; - case Float2Float: + case lir::Float2Float: if (useSSE(&c)) { - *aTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand); *aRegisterMask = (static_cast(FloatRegisterMask) << 32) | FloatRegisterMask; } else { @@ -3096,13 +3085,13 @@ class MyArchitecture: public Assembler::Architecture { } break; - case Float2Int: + case lir::Float2Int: // todo: Java requires different semantics than SSE for // converting floats to integers, we we need to either use // thunks or produce inline machine code which handles edge // cases properly. if (false and useSSE(&c) and bSize <= TargetBytesPerWord) { - *aTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand); *aRegisterMask = (static_cast(FloatRegisterMask) << 32) | FloatRegisterMask; } else { @@ -3110,9 +3099,9 @@ class MyArchitecture: public Assembler::Architecture { } break; - case Int2Float: + case lir::Int2Float: if (useSSE(&c) and aSize <= TargetBytesPerWord) { - *aTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand); *aRegisterMask = GeneralRegisterMask | (static_cast(GeneralRegisterMask) << 32); } else { @@ -3120,18 +3109,18 @@ class MyArchitecture: public Assembler::Architecture { } break; - case Move: + case lir::Move: *aTypeMask = ~0; *aRegisterMask = ~static_cast(0); if (TargetBytesPerWord == 4) { if (aSize == 4 and bSize == 8) { - *aTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand); const uint32_t mask = GeneralRegisterMask & ~((1 << rax) | (1 << rdx)); *aRegisterMask = (static_cast(mask) << 32) | mask; } else if (aSize == 1 or bSize == 1) { - *aTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand); const uint32_t mask = (1 << rax) | (1 << rcx) | (1 << rdx) | (1 << rbx); *aRegisterMask = (static_cast(mask) << 32) | mask; @@ -3145,7 +3134,7 @@ class MyArchitecture: public Assembler::Architecture { } virtual void planDestination - (BinaryOperation op, unsigned aSize, uint8_t aTypeMask, + (lir::BinaryOperation op, unsigned aSize, uint8_t aTypeMask, uint64_t aRegisterMask, unsigned bSize, uint8_t* bTypeMask, uint64_t* bRegisterMask) { @@ -3154,42 +3143,42 @@ class MyArchitecture: public Assembler::Architecture { | (static_cast(GeneralRegisterMask) << 32); switch (op) { - case Absolute: - *bTypeMask = (1 << RegisterOperand); + case lir::Absolute: + *bTypeMask = (1 << lir::RegisterOperand); *bRegisterMask = (static_cast(1) << rax); break; - case FloatAbsolute: - *bTypeMask = (1 << RegisterOperand); + case lir::FloatAbsolute: + *bTypeMask = (1 << lir::RegisterOperand); *bRegisterMask = aRegisterMask; break; - case Negate: - *bTypeMask = (1 << RegisterOperand); + case lir::Negate: + *bTypeMask = (1 << lir::RegisterOperand); *bRegisterMask = aRegisterMask; break; - case FloatNegate: - case FloatSquareRoot: - case Float2Float: - case Int2Float: - *bTypeMask = (1 << RegisterOperand); + case lir::FloatNegate: + case lir::FloatSquareRoot: + case lir::Float2Float: + case lir::Int2Float: + *bTypeMask = (1 << lir::RegisterOperand); *bRegisterMask = (static_cast(FloatRegisterMask) << 32) | FloatRegisterMask; break; - case Float2Int: - *bTypeMask = (1 << RegisterOperand); + case lir::Float2Int: + *bTypeMask = (1 << lir::RegisterOperand); break; - case Move: - if (aTypeMask & ((1 << MemoryOperand) | 1 << AddressOperand)) { - *bTypeMask = (1 << RegisterOperand); + case lir::Move: + if (aTypeMask & ((1 << lir::MemoryOperand) | 1 << lir::AddressOperand)) { + *bTypeMask = (1 << lir::RegisterOperand); *bRegisterMask = GeneralRegisterMask | (static_cast(GeneralRegisterMask) << 32) | FloatRegisterMask; - } else if (aTypeMask & (1 << RegisterOperand)) { - *bTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); + } else if (aTypeMask & (1 << lir::RegisterOperand)) { + *bTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand); if (aRegisterMask & FloatRegisterMask) { *bRegisterMask = FloatRegisterMask; } else { @@ -3197,7 +3186,7 @@ class MyArchitecture: public Assembler::Architecture { | (static_cast(GeneralRegisterMask) << 32); } } else { - *bTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); + *bTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand); } if (TargetBytesPerWord == 4) { @@ -3228,33 +3217,33 @@ class MyArchitecture: public Assembler::Architecture { *tmpTypeMask = 0; *tmpRegisterMask = 0; - if (dstTypeMask & (1 << MemoryOperand)) { + if (dstTypeMask & (1 << lir::MemoryOperand)) { // can't move directly from memory to memory - *srcTypeMask = (1 << RegisterOperand) | (1 << ConstantOperand); - *tmpTypeMask = 1 << RegisterOperand; + *srcTypeMask = (1 << lir::RegisterOperand) | (1 << lir::ConstantOperand); + *tmpTypeMask = 1 << lir::RegisterOperand; *tmpRegisterMask = GeneralRegisterMask | (static_cast(GeneralRegisterMask) << 32); - } else if (dstTypeMask & (1 << RegisterOperand)) { + } else if (dstTypeMask & (1 << lir::RegisterOperand)) { if (size > TargetBytesPerWord) { // can't move directly from FPR to GPR or vice-versa for // values larger than the GPR size if (dstRegisterMask & FloatRegisterMask) { *srcRegisterMask = FloatRegisterMask | (static_cast(FloatRegisterMask) << 32); - *tmpTypeMask = 1 << MemoryOperand; + *tmpTypeMask = 1 << lir::MemoryOperand; } else if (dstRegisterMask & GeneralRegisterMask) { *srcRegisterMask = GeneralRegisterMask | (static_cast(GeneralRegisterMask) << 32); - *tmpTypeMask = 1 << MemoryOperand; + *tmpTypeMask = 1 << lir::MemoryOperand; } } if (dstRegisterMask & FloatRegisterMask) { // can't move directly from constant to FPR - *srcTypeMask &= ~(1 << ConstantOperand); + *srcTypeMask &= ~(1 << lir::ConstantOperand); if (size > TargetBytesPerWord) { - *tmpTypeMask = 1 << MemoryOperand; + *tmpTypeMask = 1 << lir::MemoryOperand; } else { - *tmpTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); + *tmpTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand); *tmpRegisterMask = GeneralRegisterMask | (static_cast(GeneralRegisterMask) << 32); } @@ -3263,29 +3252,29 @@ class MyArchitecture: public Assembler::Architecture { } virtual void planSource - (TernaryOperation op, + (lir::TernaryOperation op, unsigned aSize, uint8_t *aTypeMask, uint64_t *aRegisterMask, unsigned bSize, uint8_t* bTypeMask, uint64_t* bRegisterMask, unsigned, bool* thunk) { - *aTypeMask = (1 << RegisterOperand) | (1 << ConstantOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::ConstantOperand); *aRegisterMask = GeneralRegisterMask | (static_cast(GeneralRegisterMask) << 32); - *bTypeMask = (1 << RegisterOperand); + *bTypeMask = (1 << lir::RegisterOperand); *bRegisterMask = GeneralRegisterMask | (static_cast(GeneralRegisterMask) << 32); *thunk = false; switch (op) { - case FloatAdd: - case FloatSubtract: - case FloatMultiply: - case FloatDivide: + case lir::FloatAdd: + case lir::FloatSubtract: + case lir::FloatMultiply: + case lir::FloatDivide: if (useSSE(&c)) { - *aTypeMask = (1 << RegisterOperand) | (1 << MemoryOperand); - *bTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << lir::RegisterOperand) | (1 << lir::MemoryOperand); + *bTypeMask = (1 << lir::RegisterOperand); const uint64_t mask = (static_cast(FloatRegisterMask) << 32) @@ -3297,11 +3286,11 @@ class MyArchitecture: public Assembler::Architecture { } break; - case FloatRemainder: + case lir::FloatRemainder: *thunk = true; break; - case Multiply: + case lir::Multiply: if (TargetBytesPerWord == 4 and aSize == 8) { const uint32_t mask = GeneralRegisterMask & ~((1 << rax) | (1 << rdx)); *aRegisterMask = (static_cast(mask) << 32) | mask; @@ -3312,29 +3301,29 @@ class MyArchitecture: public Assembler::Architecture { } break; - case Divide: + case lir::Divide: if (TargetBytesPerWord == 4 and aSize == 8) { *thunk = true; } else { - *aTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = GeneralRegisterMask & ~((1 << rax) | (1 << rdx)); *bRegisterMask = 1 << rax; } break; - case Remainder: + case lir::Remainder: if (TargetBytesPerWord == 4 and aSize == 8) { *thunk = true; } else { - *aTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = GeneralRegisterMask & ~((1 << rax) | (1 << rdx)); *bRegisterMask = 1 << rax; } break; - case ShiftLeft: - case ShiftRight: - case UnsignedShiftRight: { + case lir::ShiftLeft: + case lir::ShiftRight: + case lir::UnsignedShiftRight: { if (TargetBytesPerWord == 4 and bSize == 8) { const uint32_t mask = GeneralRegisterMask & ~(1 << rcx); *aRegisterMask = (static_cast(mask) << 32) | mask; @@ -3347,18 +3336,18 @@ class MyArchitecture: public Assembler::Architecture { } } break; - case JumpIfFloatEqual: - case JumpIfFloatNotEqual: - case JumpIfFloatLess: - case JumpIfFloatGreater: - case JumpIfFloatLessOrEqual: - case JumpIfFloatGreaterOrEqual: - case JumpIfFloatLessOrUnordered: - case JumpIfFloatGreaterOrUnordered: - case JumpIfFloatLessOrEqualOrUnordered: - case JumpIfFloatGreaterOrEqualOrUnordered: + case lir::JumpIfFloatEqual: + case lir::JumpIfFloatNotEqual: + case lir::JumpIfFloatLess: + case lir::JumpIfFloatGreater: + case lir::JumpIfFloatLessOrEqual: + case lir::JumpIfFloatGreaterOrEqual: + case lir::JumpIfFloatLessOrUnordered: + case lir::JumpIfFloatGreaterOrUnordered: + case lir::JumpIfFloatLessOrEqualOrUnordered: + case lir::JumpIfFloatGreaterOrEqualOrUnordered: if (useSSE(&c)) { - *aTypeMask = (1 << RegisterOperand); + *aTypeMask = (1 << lir::RegisterOperand); *aRegisterMask = (static_cast(FloatRegisterMask) << 32) | FloatRegisterMask; *bTypeMask = *aTypeMask; @@ -3374,15 +3363,15 @@ class MyArchitecture: public Assembler::Architecture { } virtual void planDestination - (TernaryOperation op, unsigned, uint8_t, uint64_t, unsigned, uint8_t, + (lir::TernaryOperation op, unsigned, uint8_t, uint64_t, unsigned, uint8_t, uint64_t bRegisterMask, unsigned, uint8_t* cTypeMask, uint64_t* cRegisterMask) { if (isBranch(op)) { - *cTypeMask = (1 << ConstantOperand); + *cTypeMask = (1 << lir::ConstantOperand); *cRegisterMask = 0; } else { - *cTypeMask = (1 << RegisterOperand); + *cTypeMask = (1 << lir::RegisterOperand); *cRegisterMask = bRegisterMask; } } @@ -3421,25 +3410,27 @@ class MyAssembler: public Assembler { virtual void checkStackOverflow(uintptr_t handler, unsigned stackLimitOffsetFromThread) { - Register stack(rsp); - Memory stackLimit(rbx, stackLimitOffsetFromThread); - Constant handlerConstant(resolved(&c, handler)); - branchRM(&c, JumpIfGreaterOrEqual, TargetBytesPerWord, &stack, &stackLimit, + lir::Register stack(rsp); + lir::Memory stackLimit(rbx, stackLimitOffsetFromThread); + lir::Constant handlerConstant(resolved(&c, handler)); + branchRM(&c, lir::JumpIfGreaterOrEqual, TargetBytesPerWord, &stack, &stackLimit, &handlerConstant); } virtual void saveFrame(unsigned stackOffset, unsigned) { - Register stack(rsp); - Memory stackDst(rbx, stackOffset); - apply(Move, TargetBytesPerWord, RegisterOperand, &stack, - TargetBytesPerWord, MemoryOperand, &stackDst); + lir::Register stack(rsp); + lir::Memory stackDst(rbx, stackOffset); + apply(lir::Move, + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &stack), + OperandInfo(TargetBytesPerWord, lir::MemoryOperand, &stackDst)); } virtual void pushFrame(unsigned argumentCount, ...) { + // TODO: Argument should be replaced by OperandInfo... struct Argument { unsigned size; - OperandType type; - Operand* operand; + lir::OperandType type; + lir::Operand* operand; }; RUNTIME_ARRAY(Argument, arguments, argumentCount); va_list a; va_start(a, argumentCount); @@ -3447,8 +3438,8 @@ class MyAssembler: public Assembler { for (unsigned i = 0; i < argumentCount; ++i) { RUNTIME_ARRAY_BODY(arguments)[i].size = va_arg(a, unsigned); RUNTIME_ARRAY_BODY(arguments)[i].type - = static_cast(va_arg(a, int)); - RUNTIME_ARRAY_BODY(arguments)[i].operand = va_arg(a, Operand*); + = static_cast(va_arg(a, int)); + RUNTIME_ARRAY_BODY(arguments)[i].operand = va_arg(a, lir::Operand*); footprint += ceilingDivide (RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord); } @@ -3459,23 +3450,27 @@ class MyAssembler: public Assembler { unsigned offset = 0; for (unsigned i = 0; i < argumentCount; ++i) { if (i < arch_->argumentRegisterCount()) { - Register dst(arch_->argumentRegister(i)); - apply(Move, - RUNTIME_ARRAY_BODY(arguments)[i].size, - RUNTIME_ARRAY_BODY(arguments)[i].type, - RUNTIME_ARRAY_BODY(arguments)[i].operand, - pad(RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord), - RegisterOperand, - &dst); + lir::Register dst(arch_->argumentRegister(i)); + apply(lir::Move, + OperandInfo( + RUNTIME_ARRAY_BODY(arguments)[i].size, + RUNTIME_ARRAY_BODY(arguments)[i].type, + RUNTIME_ARRAY_BODY(arguments)[i].operand), + OperandInfo( + pad(RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord), + lir::RegisterOperand, + &dst)); } else { - Memory dst(rsp, offset * TargetBytesPerWord); - apply(Move, - RUNTIME_ARRAY_BODY(arguments)[i].size, - RUNTIME_ARRAY_BODY(arguments)[i].type, - RUNTIME_ARRAY_BODY(arguments)[i].operand, - pad(RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord), - MemoryOperand, - &dst); + lir::Memory dst(rsp, offset * TargetBytesPerWord); + apply(lir::Move, + OperandInfo( + RUNTIME_ARRAY_BODY(arguments)[i].size, + RUNTIME_ARRAY_BODY(arguments)[i].type, + RUNTIME_ARRAY_BODY(arguments)[i].operand), + OperandInfo( + pad(RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord), + lir::MemoryOperand, + &dst)); offset += ceilingDivide (RUNTIME_ARRAY_BODY(arguments)[i].size, TargetBytesPerWord); } @@ -3483,44 +3478,49 @@ class MyAssembler: public Assembler { } virtual void allocateFrame(unsigned footprint) { - Register stack(rsp); + lir::Register stack(rsp); if (UseFramePointer) { - Register base(rbp); + lir::Register base(rbp); pushR(&c, TargetBytesPerWord, &base); - apply(Move, TargetBytesPerWord, RegisterOperand, &stack, - TargetBytesPerWord, RegisterOperand, &base); + apply(lir::Move, + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &stack), + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &base)); } - Constant footprintConstant(resolved(&c, footprint * TargetBytesPerWord)); - apply(Subtract, TargetBytesPerWord, ConstantOperand, &footprintConstant, - TargetBytesPerWord, RegisterOperand, &stack, - TargetBytesPerWord, RegisterOperand, &stack); + lir::Constant footprintConstant(resolved(&c, footprint * TargetBytesPerWord)); + apply(lir::Subtract, + OperandInfo(TargetBytesPerWord, lir::ConstantOperand, &footprintConstant), + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &stack), + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &stack)); } virtual void adjustFrame(unsigned difference) { - Register stack(rsp); - Constant differenceConstant(resolved(&c, difference * TargetBytesPerWord)); - apply(Subtract, TargetBytesPerWord, ConstantOperand, &differenceConstant, - TargetBytesPerWord, RegisterOperand, &stack, - TargetBytesPerWord, RegisterOperand, &stack); + lir::Register stack(rsp); + lir::Constant differenceConstant(resolved(&c, difference * TargetBytesPerWord)); + apply(lir::Subtract, + OperandInfo(TargetBytesPerWord, lir::ConstantOperand, &differenceConstant), + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &stack), + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &stack)); } virtual void popFrame(unsigned frameFootprint) { if (UseFramePointer) { - Register base(rbp); - Register stack(rsp); - apply(Move, TargetBytesPerWord, RegisterOperand, &base, - TargetBytesPerWord, RegisterOperand, &stack); + lir::Register base(rbp); + lir::Register stack(rsp); + apply(lir::Move, + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &base), + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &stack)); popR(&c, TargetBytesPerWord, &base); } else { - Register stack(rsp); - Constant footprint(resolved(&c, frameFootprint * TargetBytesPerWord)); - apply(Add, TargetBytesPerWord, ConstantOperand, &footprint, - TargetBytesPerWord, RegisterOperand, &stack, - TargetBytesPerWord, RegisterOperand, &stack); + lir::Register stack(rsp); + lir::Constant footprint(resolved(&c, frameFootprint * TargetBytesPerWord)); + apply(lir::Add, + OperandInfo(TargetBytesPerWord, lir::ConstantOperand, &footprint), + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &stack), + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &stack)); } } @@ -3531,16 +3531,16 @@ class MyAssembler: public Assembler { { if (TailCalls) { if (offset) { - Register tmp(c.client->acquireTemporary()); + lir::Register tmp(c.client->acquireTemporary()); unsigned baseSize = UseFramePointer ? 1 : 0; - Memory returnAddressSrc + lir::Memory returnAddressSrc (rsp, (frameFootprint + baseSize) * TargetBytesPerWord); moveMR(&c, TargetBytesPerWord, &returnAddressSrc, TargetBytesPerWord, &tmp); - Memory returnAddressDst + lir::Memory returnAddressDst (rsp, (frameFootprint - offset + baseSize) * TargetBytesPerWord); moveRM(&c, TargetBytesPerWord, &tmp, TargetBytesPerWord, &returnAddressDst); @@ -3548,31 +3548,31 @@ class MyAssembler: public Assembler { c.client->releaseTemporary(tmp.low); if (UseFramePointer) { - Memory baseSrc(rsp, frameFootprint * TargetBytesPerWord); - Register base(rbp); + lir::Memory baseSrc(rsp, frameFootprint * TargetBytesPerWord); + lir::Register base(rbp); moveMR(&c, TargetBytesPerWord, &baseSrc, TargetBytesPerWord, &base); } - Register stack(rsp); - Constant footprint + lir::Register stack(rsp); + lir::Constant footprint (resolved (&c, (frameFootprint - offset + baseSize) * TargetBytesPerWord)); addCR(&c, TargetBytesPerWord, &footprint, TargetBytesPerWord, &stack); - if (returnAddressSurrogate != NoRegister) { + if (returnAddressSurrogate != lir::NoRegister) { assert(&c, offset > 0); - Register ras(returnAddressSurrogate); - Memory dst(rsp, offset * TargetBytesPerWord); + lir::Register ras(returnAddressSurrogate); + lir::Memory dst(rsp, offset * TargetBytesPerWord); moveRM(&c, TargetBytesPerWord, &ras, TargetBytesPerWord, &dst); } - if (framePointerSurrogate != NoRegister) { + if (framePointerSurrogate != lir::NoRegister) { assert(&c, offset > 0); - Register fps(framePointerSurrogate); - Memory dst(rsp, (offset - 1) * TargetBytesPerWord); + lir::Register fps(framePointerSurrogate); + lir::Memory dst(rsp, (offset - 1) * TargetBytesPerWord); moveRM(&c, TargetBytesPerWord, &fps, TargetBytesPerWord, &dst); } } else { @@ -3592,11 +3592,11 @@ class MyAssembler: public Assembler { assert(&c, (argumentFootprint % StackAlignmentInWords) == 0); if (TailCalls and argumentFootprint > StackAlignmentInWords) { - Register returnAddress(rcx); + lir::Register returnAddress(rcx); popR(&c, TargetBytesPerWord, &returnAddress); - Register stack(rsp); - Constant adjustment + lir::Register stack(rsp); + lir::Constant adjustment (resolved(&c, (argumentFootprint - StackAlignmentInWords) * TargetBytesPerWord)); addCR(&c, TargetBytesPerWord, &adjustment, TargetBytesPerWord, &stack); @@ -3612,54 +3612,47 @@ class MyAssembler: public Assembler { { popFrame(frameFootprint); - Register returnAddress(rcx); + lir::Register returnAddress(rcx); popR(&c, TargetBytesPerWord, &returnAddress); - Register stack(rsp); - Memory stackSrc(rbx, stackOffsetFromThread); + lir::Register stack(rsp); + lir::Memory stackSrc(rbx, stackOffsetFromThread); moveMR(&c, TargetBytesPerWord, &stackSrc, TargetBytesPerWord, &stack); jumpR(&c, TargetBytesPerWord, &returnAddress); } - virtual void apply(Operation op) { + virtual void apply(lir::Operation op) { arch_->c.operations[op](&c); } - virtual void apply(UnaryOperation op, - unsigned aSize, OperandType aType, Operand* aOperand) + virtual void apply(lir::UnaryOperation op, OperandInfo a) { - arch_->c.unaryOperations[index(&(arch_->c), op, aType)] - (&c, aSize, aOperand); + arch_->c.unaryOperations[index(&(arch_->c), op, a.type)] + (&c, a.size, a.operand); } - virtual void apply(BinaryOperation op, - unsigned aSize, OperandType aType, Operand* aOperand, - unsigned bSize, OperandType bType, Operand* bOperand) + virtual void apply(lir::BinaryOperation op, OperandInfo a, OperandInfo b) { - arch_->c.binaryOperations[index(&(arch_->c), op, aType, bType)] - (&c, aSize, aOperand, bSize, bOperand); + arch_->c.binaryOperations[index(&(arch_->c), op, a.type, b.type)] + (&c, a.size, a.operand, b.size, b.operand); } - virtual void apply(TernaryOperation op, - unsigned aSize, OperandType aType, Operand* aOperand, - unsigned bSize, OperandType bType, Operand* bOperand, - unsigned cSize UNUSED, OperandType cType UNUSED, - Operand* cOperand) + virtual void apply(lir::TernaryOperation op, OperandInfo a, OperandInfo b, OperandInfo c) { if (isBranch(op)) { - assert(&c, aSize == bSize); - assert(&c, cSize == TargetBytesPerWord); - assert(&c, cType == ConstantOperand); + assert(&this->c, a.size == b.size); + assert(&this->c, c.size == TargetBytesPerWord); + assert(&this->c, c.type == lir::ConstantOperand); - arch_->c.branchOperations[branchIndex(&(arch_->c), aType, bType)] - (&c, op, aSize, aOperand, bOperand, cOperand); + arch_->c.branchOperations[branchIndex(&(arch_->c), a.type, b.type)] + (&this->c, op, a.size, a.operand, b.operand, c.operand); } else { - assert(&c, bSize == cSize); - assert(&c, bType == cType); + assert(&this->c, b.size == c.size); + assert(&this->c, b.type == c.type); - arch_->c.binaryOperations[index(&(arch_->c), op, aType, bType)] - (&c, aSize, aOperand, bSize, bOperand); + arch_->c.binaryOperations[index(&(arch_->c), op, a.type, b.type)] + (&this->c, a.size, a.operand, b.size, b.operand); } } diff --git a/src/compile.cpp b/src/compile.cpp index b01e56bee6..5b9245df15 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -37,6 +37,8 @@ vmJumpAndInvoke(void* thread, void* function, void* stack, unsigned argumentFootprint, uintptr_t* arguments, unsigned frameSize); +using avian::codegen::Compiler; + namespace { namespace local { @@ -291,7 +293,7 @@ class MyThread: public Thread { void** thunkTable; CallTrace* trace; Reference* reference; - Assembler::Architecture* arch; + avian::codegen::Assembler::Architecture* arch; Context* transition; TraceContext* traceContext; uintptr_t stackLimit; @@ -737,7 +739,7 @@ stackForFrame(MyThread* t, void* frame, object method) return static_cast(frame) - stackOffsetFromFrame(t, method); } -class PoolElement: public Promise { +class PoolElement: public avian::codegen::Promise { public: PoolElement(Thread* t, object target, PoolElement* next): t(t), target(target), address(0), next(next) @@ -793,7 +795,7 @@ class SubroutinePath; class SubroutineCall { public: - SubroutineCall(Subroutine* subroutine, Promise* returnAddress): + SubroutineCall(Subroutine* subroutine, avian::codegen::Promise* returnAddress): subroutine(subroutine), returnAddress(returnAddress), paths(0), @@ -804,7 +806,7 @@ class SubroutineCall { } Subroutine* subroutine; - Promise* returnAddress; + avian::codegen::Promise* returnAddress; SubroutinePath* paths; SubroutineCall* next; }; @@ -863,7 +865,7 @@ class SubroutineTrace { uintptr_t map[0]; }; -class TraceElement: public TraceHandler { +class TraceElement: public avian::codegen::TraceHandler { public: static const unsigned VirtualCall = 1 << 0; static const unsigned TailCall = 1 << 1; @@ -885,7 +887,7 @@ class TraceElement: public TraceHandler { memset(map, 0xFF, mapSize * BytesPerWord); } - virtual void handleTrace(Promise* address, unsigned argumentIndex) { + virtual void handleTrace(avian::codegen::Promise* address, unsigned argumentIndex) { if (this->address == 0) { this->address = address; this->argumentIndex = argumentIndex; @@ -893,7 +895,7 @@ class TraceElement: public TraceHandler { } Context* context; - Promise* address; + avian::codegen::Promise* address; TraceElement* next; SubroutineTrace* subroutineTrace; object target; @@ -905,7 +907,7 @@ class TraceElement: public TraceHandler { uintptr_t map[0]; }; -class TraceElementPromise: public Promise { +class TraceElementPromise: public avian::codegen::Promise { public: TraceElementPromise(System* s, TraceElement* trace): s(s), trace(trace) { } @@ -994,7 +996,7 @@ class BootContext { }; BootContext(Thread* t, object constants, object calls, - DelayedPromise* addresses, Zone* zone, OffsetResolver* resolver): + avian::codegen::DelayedPromise* addresses, Zone* zone, OffsetResolver* resolver): protector(t, this), constants(constants), calls(calls), addresses(addresses), addressSentinal(addresses), zone(zone), resolver(resolver) @@ -1003,8 +1005,8 @@ class BootContext { MyProtector protector; object constants; object calls; - DelayedPromise* addresses; - DelayedPromise* addressSentinal; + avian::codegen::DelayedPromise* addresses; + avian::codegen::DelayedPromise* addressSentinal; Zone* zone; OffsetResolver* resolver; }; @@ -1045,32 +1047,32 @@ class Context { public: MyClient(MyThread* t): t(t) { } - virtual intptr_t getThunk(UnaryOperation, unsigned) { + virtual intptr_t getThunk(avian::codegen::lir::UnaryOperation, unsigned) { abort(t); } - virtual intptr_t getThunk(BinaryOperation op, unsigned size, + virtual intptr_t getThunk(avian::codegen::lir::BinaryOperation op, unsigned size, unsigned resultSize) { if (size == 8) { switch(op) { - case Absolute: + case avian::codegen::lir::Absolute: assert(t, resultSize == 8); return local::getThunk(t, absoluteLongThunk); - case FloatNegate: + case avian::codegen::lir::FloatNegate: assert(t, resultSize == 8); return local::getThunk(t, negateDoubleThunk); - case FloatSquareRoot: + case avian::codegen::lir::FloatSquareRoot: assert(t, resultSize == 8); return local::getThunk(t, squareRootDoubleThunk); - case Float2Float: + case avian::codegen::lir::Float2Float: assert(t, resultSize == 4); return local::getThunk(t, doubleToFloatThunk); - case Float2Int: + case avian::codegen::lir::Float2Int: if (resultSize == 8) { return local::getThunk(t, doubleToLongThunk); } else { @@ -1078,7 +1080,7 @@ class Context { return local::getThunk(t, doubleToIntThunk); } - case Int2Float: + case avian::codegen::lir::Int2Float: if (resultSize == 8) { return local::getThunk(t, longToDoubleThunk); } else { @@ -1092,23 +1094,23 @@ class Context { assert(t, size == 4); switch(op) { - case Absolute: + case avian::codegen::lir::Absolute: assert(t, resultSize == 4); return local::getThunk(t, absoluteIntThunk); - case FloatNegate: + case avian::codegen::lir::FloatNegate: assert(t, resultSize == 4); return local::getThunk(t, negateFloatThunk); - case FloatAbsolute: + case avian::codegen::lir::FloatAbsolute: assert(t, resultSize == 4); return local::getThunk(t, absoluteFloatThunk); - case Float2Float: + case avian::codegen::lir::Float2Float: assert(t, resultSize == 8); return local::getThunk(t, floatToDoubleThunk); - case Float2Int: + case avian::codegen::lir::Float2Int: if (resultSize == 4) { return local::getThunk(t, floatToIntThunk); } else { @@ -1116,7 +1118,7 @@ class Context { return local::getThunk(t, floatToLongThunk); } - case Int2Float: + case avian::codegen::lir::Int2Float: if (resultSize == 4) { return local::getThunk(t, intToFloatThunk); } else { @@ -1129,48 +1131,48 @@ class Context { } } - virtual intptr_t getThunk(TernaryOperation op, unsigned size, unsigned, + virtual intptr_t getThunk(avian::codegen::lir::TernaryOperation op, unsigned size, unsigned, bool* threadParameter) { *threadParameter = false; if (size == 8) { switch (op) { - case Divide: + case avian::codegen::lir::Divide: *threadParameter = true; return local::getThunk(t, divideLongThunk); - case Remainder: + case avian::codegen::lir::Remainder: *threadParameter = true; return local::getThunk(t, moduloLongThunk); - case FloatAdd: + case avian::codegen::lir::FloatAdd: return local::getThunk(t, addDoubleThunk); - case FloatSubtract: + case avian::codegen::lir::FloatSubtract: return local::getThunk(t, subtractDoubleThunk); - case FloatMultiply: + case avian::codegen::lir::FloatMultiply: return local::getThunk(t, multiplyDoubleThunk); - case FloatDivide: + case avian::codegen::lir::FloatDivide: return local::getThunk(t, divideDoubleThunk); - case FloatRemainder: + case avian::codegen::lir::FloatRemainder: return local::getThunk(t, moduloDoubleThunk); - case JumpIfFloatEqual: - case JumpIfFloatNotEqual: - case JumpIfFloatLess: - case JumpIfFloatGreater: - case JumpIfFloatLessOrEqual: - case JumpIfFloatGreaterOrUnordered: - case JumpIfFloatGreaterOrEqualOrUnordered: + case avian::codegen::lir::JumpIfFloatEqual: + case avian::codegen::lir::JumpIfFloatNotEqual: + case avian::codegen::lir::JumpIfFloatLess: + case avian::codegen::lir::JumpIfFloatGreater: + case avian::codegen::lir::JumpIfFloatLessOrEqual: + case avian::codegen::lir::JumpIfFloatGreaterOrUnordered: + case avian::codegen::lir::JumpIfFloatGreaterOrEqualOrUnordered: return local::getThunk(t, compareDoublesGThunk); - case JumpIfFloatGreaterOrEqual: - case JumpIfFloatLessOrUnordered: - case JumpIfFloatLessOrEqualOrUnordered: + case avian::codegen::lir::JumpIfFloatGreaterOrEqual: + case avian::codegen::lir::JumpIfFloatLessOrUnordered: + case avian::codegen::lir::JumpIfFloatLessOrEqualOrUnordered: return local::getThunk(t, compareDoublesLThunk); default: abort(t); @@ -1178,41 +1180,41 @@ class Context { } else { assert(t, size == 4); switch (op) { - case Divide: + case avian::codegen::lir::Divide: *threadParameter = true; return local::getThunk(t, divideIntThunk); - case Remainder: + case avian::codegen::lir::Remainder: *threadParameter = true; return local::getThunk(t, moduloIntThunk); - case FloatAdd: + case avian::codegen::lir::FloatAdd: return local::getThunk(t, addFloatThunk); - case FloatSubtract: + case avian::codegen::lir::FloatSubtract: return local::getThunk(t, subtractFloatThunk); - case FloatMultiply: + case avian::codegen::lir::FloatMultiply: return local::getThunk(t, multiplyFloatThunk); - case FloatDivide: + case avian::codegen::lir::FloatDivide: return local::getThunk(t, divideFloatThunk); - case FloatRemainder: + case avian::codegen::lir::FloatRemainder: return local::getThunk(t, moduloFloatThunk); - case JumpIfFloatEqual: - case JumpIfFloatNotEqual: - case JumpIfFloatLess: - case JumpIfFloatGreater: - case JumpIfFloatLessOrEqual: - case JumpIfFloatGreaterOrUnordered: - case JumpIfFloatGreaterOrEqualOrUnordered: + case avian::codegen::lir::JumpIfFloatEqual: + case avian::codegen::lir::JumpIfFloatNotEqual: + case avian::codegen::lir::JumpIfFloatLess: + case avian::codegen::lir::JumpIfFloatGreater: + case avian::codegen::lir::JumpIfFloatLessOrEqual: + case avian::codegen::lir::JumpIfFloatGreaterOrUnordered: + case avian::codegen::lir::JumpIfFloatGreaterOrEqualOrUnordered: return local::getThunk(t, compareFloatsGThunk); - case JumpIfFloatGreaterOrEqual: - case JumpIfFloatLessOrUnordered: - case JumpIfFloatLessOrEqualOrUnordered: + case avian::codegen::lir::JumpIfFloatGreaterOrEqual: + case avian::codegen::lir::JumpIfFloatLessOrUnordered: + case avian::codegen::lir::JumpIfFloatLessOrEqualOrUnordered: return local::getThunk(t, compareFloatsLThunk); default: abort(t); @@ -1297,9 +1299,9 @@ class Context { MyThread* thread; Zone zone; - Assembler* assembler; + avian::codegen::Assembler* assembler; MyClient client; - Compiler* compiler; + avian::codegen::Compiler* compiler; object method; BootContext* bootContext; PoolElement* objectPool; @@ -1359,6 +1361,8 @@ class Frame { Object }; + typedef Compiler::Operand* Value; + Frame(Context* context, uint8_t* stackMap): context(context), t(context->thread), @@ -1400,10 +1404,10 @@ class Frame { } } - Compiler::Operand* append(object o) { + Value append(object o) { BootContext* bc = context->bootContext; if (bc) { - Promise* p = new (bc->zone) ListenPromise(t->m->system, bc->zone); + avian::codegen::Promise* p = new (bc->zone) avian::codegen::ListenPromise(t->m->system, bc->zone); PROTECT(t, o); object pointer = makePointer(t, p); @@ -1623,34 +1627,34 @@ class Frame { set(sp - 2, saved); } - Promise* addressPromise(Promise* p) { + avian::codegen::Promise* addressPromise(avian::codegen::Promise* p) { BootContext* bc = context->bootContext; if (bc) { - bc->addresses = new(bc->zone) DelayedPromise(t->m->system, bc->zone, p, bc->addresses); + bc->addresses = new(bc->zone) avian::codegen::DelayedPromise(t->m->system, bc->zone, p, bc->addresses); return bc->addresses; } else { return p; } } - Compiler::Operand* addressOperand(Promise* p) { + Value addressOperand(avian::codegen::Promise* p) { return c->promiseConstant(p, Compiler::AddressType); } - Compiler::Operand* absoluteAddressOperand(Promise* p) { + Value absoluteAddressOperand(avian::codegen::Promise* p) { return context->bootContext ? c->add (TargetBytesPerWord, c->memory (c->register_(t->arch->thread()), Compiler::AddressType, TARGET_THREAD_CODEIMAGE), c->promiseConstant (new(&context->zone) - OffsetPromise + avian::codegen::OffsetPromise (p, - reinterpret_cast(codeAllocator(t)->base)), Compiler::AddressType)) : addressOperand(p); } - Compiler::Operand* machineIp(unsigned logicalIp) { + Value machineIp(unsigned logicalIp) { return c->promiseConstant(c->machineIp(logicalIp), Compiler::AddressType); } @@ -1674,35 +1678,33 @@ class Frame { this->ip = ip; } - void pushQuiet(unsigned footprint, Compiler::Operand* o) { + void pushQuiet(unsigned footprint, Value o) { c->push(footprint, o); } - void pushLongQuiet(Compiler::Operand* o) { + void pushLongQuiet(Value o) { pushQuiet(2, o); } - Compiler::Operand* popQuiet(unsigned footprint) { + Value popQuiet(unsigned footprint) { return c->pop(footprint); } - Compiler::Operand* popLongQuiet() { - Compiler::Operand* r = popQuiet(2); - - return r; + Value popLongQuiet() { + return popQuiet(2); } - void pushInt(Compiler::Operand* o) { + void pushInt(Value o) { pushQuiet(1, o); pushedInt(); } - void pushAddress(Compiler::Operand* o) { + void pushAddress(Value o) { pushQuiet(1, o); pushedInt(); } - void pushObject(Compiler::Operand* o) { + void pushObject(Value o) { pushQuiet(1, o); pushedObject(); } @@ -1713,7 +1715,7 @@ class Frame { pushedObject(); } - void pushLong(Compiler::Operand* o) { + void pushLong(Value o) { pushLongQuiet(o); pushedLong(); } @@ -1723,17 +1725,17 @@ class Frame { c->popped(count); } - Compiler::Operand* popInt() { + Value popInt() { poppedInt(); return popQuiet(1); } - Compiler::Operand* popLong() { + Value popLong() { poppedLong(); return popLongQuiet(); } - Compiler::Operand* popObject() { + Value popObject() { poppedObject(); return popQuiet(1); } @@ -1789,8 +1791,8 @@ class Frame { } void dupX1() { - Compiler::Operand* s0 = popQuiet(1); - Compiler::Operand* s1 = popQuiet(1); + Value s0 = popQuiet(1); + Value s1 = popQuiet(1); pushQuiet(1, s0); pushQuiet(1, s1); @@ -1800,17 +1802,17 @@ class Frame { } void dupX2() { - Compiler::Operand* s0 = popQuiet(1); + Value s0 = popQuiet(1); if (get(sp - 2) == Long) { - Compiler::Operand* s1 = popLongQuiet(); + Value s1 = popLongQuiet(); pushQuiet(1, s0); pushLongQuiet(s1); pushQuiet(1, s0); } else { - Compiler::Operand* s1 = popQuiet(1); - Compiler::Operand* s2 = popQuiet(1); + Value s1 = popQuiet(1); + Value s2 = popQuiet(1); pushQuiet(1, s0); pushQuiet(1, s2); @@ -1825,8 +1827,8 @@ class Frame { if (get(sp - 1) == Long) { pushLongQuiet(c->peek(2, 0)); } else { - Compiler::Operand* s0 = popQuiet(1); - Compiler::Operand* s1 = popQuiet(1); + Value s0 = popQuiet(1); + Value s1 = popQuiet(1); pushQuiet(1, s1); pushQuiet(1, s0); @@ -1839,16 +1841,16 @@ class Frame { void dup2X1() { if (get(sp - 1) == Long) { - Compiler::Operand* s0 = popLongQuiet(); - Compiler::Operand* s1 = popQuiet(1); + Value s0 = popLongQuiet(); + Value s1 = popQuiet(1); pushLongQuiet(s0); pushQuiet(1, s1); pushLongQuiet(s0); } else { - Compiler::Operand* s0 = popQuiet(1); - Compiler::Operand* s1 = popQuiet(1); - Compiler::Operand* s2 = popQuiet(1); + Value s0 = popQuiet(1); + Value s1 = popQuiet(1); + Value s2 = popQuiet(1); pushQuiet(1, s1); pushQuiet(1, s0); @@ -1862,17 +1864,17 @@ class Frame { void dup2X2() { if (get(sp - 1) == Long) { - Compiler::Operand* s0 = popLongQuiet(); + Value s0 = popLongQuiet(); if (get(sp - 3) == Long) { - Compiler::Operand* s1 = popLongQuiet(); + Value s1 = popLongQuiet(); pushLongQuiet(s0); pushLongQuiet(s1); pushLongQuiet(s0); } else { - Compiler::Operand* s1 = popQuiet(1); - Compiler::Operand* s2 = popQuiet(1); + Value s1 = popQuiet(1); + Value s2 = popQuiet(1); pushLongQuiet(s0); pushQuiet(1, s2); @@ -1880,10 +1882,10 @@ class Frame { pushLongQuiet(s0); } } else { - Compiler::Operand* s0 = popQuiet(1); - Compiler::Operand* s1 = popQuiet(1); - Compiler::Operand* s2 = popQuiet(1); - Compiler::Operand* s3 = popQuiet(1); + Value s0 = popQuiet(1); + Value s1 = popQuiet(1); + Value s2 = popQuiet(1); + Value s3 = popQuiet(1); pushQuiet(1, s1); pushQuiet(1, s0); @@ -1897,8 +1899,8 @@ class Frame { } void swap() { - Compiler::Operand* s0 = popQuiet(1); - Compiler::Operand* s1 = popQuiet(1); + Value s0 = popQuiet(1); + Value s1 = popQuiet(1); pushQuiet(1, s0); pushQuiet(1, s1); @@ -1921,7 +1923,7 @@ class Frame { return e; } - unsigned startSubroutine(unsigned ip, Promise* returnAddress) { + unsigned startSubroutine(unsigned ip, avian::codegen::Promise* returnAddress) { pushAddress(absoluteAddressOperand(returnAddress)); Subroutine* subroutine = 0; @@ -1989,7 +1991,7 @@ class Frame { Context* context; MyThread* t; - Compiler* c; + avian::codegen::Compiler* c; Subroutine* subroutine; uint8_t* stackMap; unsigned ip; @@ -2194,7 +2196,7 @@ makeCurrentContinuation(MyThread* t, void** targetIp, void** targetStack) unsigned argumentFootprint = t->arch->argumentFootprint(methodParameterFootprint(t, target)); unsigned alignment = t->arch->stackAlignmentInWords(); - if (TailCalls and argumentFootprint > alignment) { + if (avian::codegen::TailCalls and argumentFootprint > alignment) { top += argumentFootprint - alignment; } @@ -3379,11 +3381,11 @@ useLongJump(MyThread* t, uintptr_t target) Compiler::Operand* compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall, - bool useThunk, unsigned rSize, Promise* addressPromise) + bool useThunk, unsigned rSize, avian::codegen::Promise* addressPromise) { - Compiler* c = frame->c; + avian::codegen::Compiler* c = frame->c; - unsigned flags = (TailCalls and tailCall ? Compiler::TailJump : 0); + unsigned flags = (avian::codegen::TailCalls and tailCall ? Compiler::TailJump : 0); unsigned traceFlags; if (addressPromise == 0 and useLongJump(t, methodAddress(t, target))) { @@ -3394,18 +3396,18 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall, } if (useThunk - or (TailCalls and tailCall and (methodFlags(t, target) & ACC_NATIVE))) + or (avian::codegen::TailCalls and tailCall and (methodFlags(t, target) & ACC_NATIVE))) { if (frame->context->bootContext == 0) { flags |= Compiler::Aligned; } - if (TailCalls and tailCall) { + if (avian::codegen::TailCalls and tailCall) { traceFlags |= TraceElement::TailCall; TraceElement* trace = frame->trace(target, traceFlags); - Promise* returnAddressPromise = new + avian::codegen::Promise* returnAddressPromise = new (frame->context->zone.allocate(sizeof(TraceElementPromise))) TraceElementPromise(t->m->system, trace); @@ -3471,10 +3473,10 @@ compileDirectInvoke(MyThread* t, Frame* frame, object target, bool tailCall) if (bc) { if ((methodClass(t, target) == methodClass(t, frame->context->method) or (not classNeedsInit(t, methodClass(t, target)))) - and (not (TailCalls and tailCall + and (not (avian::codegen::TailCalls and tailCall and (methodFlags(t, target) & ACC_NATIVE)))) { - Promise* p = new(bc->zone) ListenPromise(t->m->system, bc->zone); + avian::codegen::Promise* p = new(bc->zone) avian::codegen::ListenPromise(t->m->system, bc->zone); PROTECT(t, target); object pointer = makePointer(t, p); @@ -3557,7 +3559,7 @@ void compileDirectReferenceInvoke(MyThread* t, Frame* frame, Thunk thunk, object reference, bool isStatic, bool tailCall) { - Compiler* c = frame->c; + avian::codegen::Compiler* c = frame->c; PROTECT(t, reference); @@ -3603,7 +3605,7 @@ void compileDirectAbstractInvoke(MyThread* t, Frame* frame, Thunk thunk, object target, bool tailCall) { - Compiler* c = frame->c; + avian::codegen::Compiler* c = frame->c; compileAbstractInvoke (t, frame, c->call @@ -3619,7 +3621,7 @@ compileDirectAbstractInvoke(MyThread* t, Frame* frame, Thunk thunk, void handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function) { - Compiler* c = frame->c; + avian::codegen::Compiler* c = frame->c; object method = frame->context->method; if (methodFlags(t, method) & ACC_SYNCHRONIZED) { @@ -3728,7 +3730,7 @@ bool isTailCall(MyThread* t, object code, unsigned ip, object caller, int calleeReturnCode) { - return TailCalls + return avian::codegen::TailCalls and ((methodFlags(t, caller) & ACC_SYNCHRONIZED) == 0) and (not inTryBlock(t, code, ip - 1)) and (not needsReturnBarrier(t, caller)) @@ -3760,7 +3762,7 @@ integerBranch(MyThread* t, Frame* frame, object code, unsigned& ip, return false; } - Compiler* c = frame->c; + avian::codegen::Compiler* c = frame->c; unsigned instruction = codeBody(t, code, ip++); uint32_t offset = codeReadInt16(t, code, ip); uint32_t newIp = (ip - 3) + offset; @@ -3811,7 +3813,7 @@ floatBranch(MyThread* t, Frame* frame, object code, unsigned& ip, return false; } - Compiler* c = frame->c; + avian::codegen::Compiler* c = frame->c; unsigned instruction = codeBody(t, code, ip++); uint32_t offset = codeReadInt16(t, code, ip); uint32_t newIp = (ip - 3) + offset; @@ -3886,7 +3888,7 @@ intrinsic(MyThread* t, Frame* frame, object target) object className = vm::className(t, methodClass(t, target)); if (UNLIKELY(MATCH(className, "java/lang/Math"))) { - Compiler* c = frame->c; + avian::codegen::Compiler* c = frame->c; if (MATCH(methodName(t, target), "sqrt") and MATCH(methodSpec(t, target), "(D)D")) { @@ -3905,7 +3907,7 @@ intrinsic(MyThread* t, Frame* frame, object target) } } } else if (UNLIKELY(MATCH(className, "sun/misc/Unsafe"))) { - Compiler* c = frame->c; + avian::codegen::Compiler* c = frame->c; if (MATCH(methodName(t, target), "getByte") and MATCH(methodSpec(t, target), "(J)B")) { @@ -4099,7 +4101,7 @@ class SwitchState { unsigned count, unsigned defaultIp, Compiler::Operand* key, - Promise* start, + avian::codegen::Promise* start, int bottom, int top): state(state), @@ -4126,7 +4128,7 @@ class SwitchState { unsigned count; unsigned defaultIp; Compiler::Operand* key; - Promise* start; + avian::codegen::Promise* start; int bottom; int top; unsigned index; @@ -4146,7 +4148,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, }; Frame* frame = initialFrame; - Compiler* c = frame->c; + avian::codegen::Compiler* c = frame->c; Context* context = frame->context; unsigned stackSize = codeMaxStack(t, methodCode(t, context->method)); Stack stack(t); @@ -5673,7 +5675,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, Compiler::Operand* default_ = frame->addressOperand (frame->addressPromise(c->machineIp(defaultIp))); - Promise* start = 0; + avian::codegen::Promise* start = 0; uint32_t* ipTable = static_cast (stack.push(sizeof(uint32_t) * pairCount)); for (int32_t i = 0; i < pairCount; ++i) { @@ -5684,7 +5686,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ipTable[i] = newIp; - Promise* p = c->poolAppend(key); + avian::codegen::Promise* p = c->poolAppend(key); if (i == 0) { start = p; } @@ -6199,7 +6201,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, int32_t bottom = codeReadInt32(t, code, ip); int32_t top = codeReadInt32(t, code, ip); - Promise* start = 0; + avian::codegen::Promise* start = 0; unsigned count = top - bottom + 1; uint32_t* ipTable = static_cast (stack.push(sizeof(uint32_t) * count)); @@ -6210,7 +6212,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp, ipTable[i] = newIp; - Promise* p = c->poolAppendPromise + avian::codegen::Promise* p = c->poolAppendPromise (frame->addressPromise(c->machineIp(newIp))); if (i == 0) { start = p; @@ -6489,7 +6491,7 @@ truncateLineNumberTable(Thread* t, object table, unsigned length) object translateExceptionHandlerTable(MyThread* t, Context* context, intptr_t start) { - Compiler* c = context->compiler; + avian::codegen::Compiler* c = context->compiler; object oldTable = codeExceptionHandlerTable (t, methodCode(t, context->method)); @@ -6935,7 +6937,7 @@ simpleFrameMapTableSize(MyThread* t, object method, object map) } uint8_t* -finish(MyThread* t, FixedAllocator* allocator, Assembler* a, const char* name, +finish(MyThread* t, FixedAllocator* allocator, avian::codegen::Assembler* a, const char* name, unsigned length) { uint8_t* start = static_cast @@ -7214,7 +7216,7 @@ makeSimpleFrameMapTable(MyThread* t, Context* context, uint8_t* start, void finish(MyThread* t, FixedAllocator* allocator, Context* context) { - Compiler* c = context->compiler; + avian::codegen::Compiler* c = context->compiler; if (false) { logCompile @@ -7291,11 +7293,11 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) BootContext* bc = context->bootContext; if (bc) { - for (DelayedPromise* p = bc->addresses; + for (avian::codegen::DelayedPromise* p = bc->addresses; p != bc->addressSentinal; p = p->next) { - p->basis = new(bc->zone) ResolvedPromise(p->basis->value()); + p->basis = new(bc->zone) avian::codegen::ResolvedPromise(p->basis->value()); } } @@ -7400,7 +7402,7 @@ finish(MyThread* t, FixedAllocator* allocator, Context* context) void compile(MyThread* t, Context* context) { - Compiler* c = context->compiler; + avian::codegen::Compiler* c = context->compiler; // fprintf(stderr, "compiling %s.%s%s\n", // &byteArrayBody(t, className(t, methodClass(t, context->method)), 0), @@ -7534,7 +7536,7 @@ compile(MyThread* t, Context* context) } void -updateCall(MyThread* t, UnaryOperation op, void* returnAddress, void* target) +updateCall(MyThread* t, avian::codegen::lir::UnaryOperation op, void* returnAddress, void* target) { t->arch->updateCall(op, returnAddress, target); } @@ -7827,7 +7829,7 @@ invokeNative(MyThread* t) uintptr_t* stack = static_cast(t->stack); - if (TailCalls + if (avian::codegen::TailCalls and t->arch->argumentFootprint(parameterFootprint) > t->arch->stackAlignmentInWords()) { @@ -9264,7 +9266,7 @@ class MyProcessor: public Processor { } virtual void compileMethod(Thread* vmt, Zone* zone, object* constants, - object* calls, DelayedPromise** addresses, + object* calls, avian::codegen::DelayedPromise** addresses, object method, OffsetResolver* resolver) { MyThread* t = static_cast(vmt); @@ -9505,17 +9507,17 @@ compileMethod2(MyThread* t, void* ip) } if (updateCaller) { - UnaryOperation op; + avian::codegen::lir::UnaryOperation op; if (callNodeFlags(t, node) & TraceElement::LongCall) { if (callNodeFlags(t, node) & TraceElement::TailCall) { - op = AlignedLongJump; + op = avian::codegen::lir::AlignedLongJump; } else { - op = AlignedLongCall; + op = avian::codegen::lir::AlignedLongCall; } } else if (callNodeFlags(t, node) & TraceElement::TailCall) { - op = AlignedJump; + op = avian::codegen::lir::AlignedJump; } else { - op = AlignedCall; + op = avian::codegen::lir::AlignedCall; } updateCall(t, op, updateIp, reinterpret_cast(address)); @@ -10045,27 +10047,34 @@ thunkToThunk(const MyProcessor::Thunk& thunk, uint8_t* base) (thunk.start - base, thunk.frameSavedOffset, thunk.length); } +using avian::codegen::OperandInfo; +namespace lir = avian::codegen::lir; + void compileCall(MyThread* t, Context* c, ThunkIndex index, bool call = true) { - Assembler* a = c->assembler; + avian::codegen::Assembler* a = c->assembler; if (processor(t)->bootImage) { - Assembler::Memory table(t->arch->thread(), TARGET_THREAD_THUNKTABLE); - Assembler::Register scratch(t->arch->scratch()); - a->apply(Move, TargetBytesPerWord, MemoryOperand, &table, - TargetBytesPerWord, RegisterOperand, &scratch); - Assembler::Memory proc(scratch.low, index * TargetBytesPerWord); - a->apply(Move, TargetBytesPerWord, MemoryOperand, &proc, - TargetBytesPerWord, RegisterOperand, &scratch); + lir::Memory table(t->arch->thread(), TARGET_THREAD_THUNKTABLE); + lir::Register scratch(t->arch->scratch()); + a->apply(lir::Move, + OperandInfo(TargetBytesPerWord, lir::MemoryOperand, &table), + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &scratch)); + lir::Memory proc(scratch.low, index * TargetBytesPerWord); + a->apply(lir::Move, + OperandInfo(TargetBytesPerWord, lir::MemoryOperand, &proc), + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &scratch)); a->apply - (call ? Call : Jump, TargetBytesPerWord, RegisterOperand, &scratch); + (call ? lir::Call : lir::Jump, + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &scratch)); } else { - Assembler::Constant proc - (new(&c->zone) ResolvedPromise(reinterpret_cast(t->thunkTable[index]))); + lir::Constant proc + (new(&c->zone) avian::codegen::ResolvedPromise(reinterpret_cast(t->thunkTable[index]))); a->apply - (call ? LongCall : LongJump, TargetBytesPerWord, ConstantOperand, &proc); + (call ? lir::LongCall : lir::LongJump, + OperandInfo(TargetBytesPerWord, lir::ConstantOperand, &proc)); } } @@ -10075,21 +10084,22 @@ compileThunks(MyThread* t, FixedAllocator* allocator) MyProcessor* p = processor(t); { Context context(t); - Assembler* a = context.assembler; + avian::codegen::Assembler* a = context.assembler; a->saveFrame(TARGET_THREAD_STACK, TARGET_THREAD_IP); p->thunks.default_.frameSavedOffset = a->length(); - Assembler::Register thread(t->arch->thread()); - a->pushFrame(1, TargetBytesPerWord, RegisterOperand, &thread); + lir::Register thread(t->arch->thread()); + a->pushFrame(1, TargetBytesPerWord, lir::RegisterOperand, &thread); compileCall(t, &context, compileMethodIndex); a->popFrame(t->arch->alignFrameSize(1)); - Assembler::Register result(t->arch->returnLow()); - a->apply(Jump, TargetBytesPerWord, RegisterOperand, &result); + lir::Register result(t->arch->returnLow()); + a->apply(lir::Jump, + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &result)); p->thunks.default_.length = a->endBlock(false)->resolve(0, 0); @@ -10098,43 +10108,47 @@ compileThunks(MyThread* t, FixedAllocator* allocator) } { Context context(t); - Assembler* a = context.assembler; + avian::codegen::Assembler* a = context.assembler; - Assembler::Register class_(t->arch->virtualCallTarget()); - Assembler::Memory virtualCallTargetSrc + lir::Register class_(t->arch->virtualCallTarget()); + lir::Memory virtualCallTargetSrc (t->arch->stack(), (t->arch->frameFooterSize() + t->arch->frameReturnAddressSize()) * TargetBytesPerWord); - a->apply(Move, TargetBytesPerWord, MemoryOperand, &virtualCallTargetSrc, - TargetBytesPerWord, RegisterOperand, &class_); + a->apply(lir::Move, + OperandInfo(TargetBytesPerWord, lir::MemoryOperand, &virtualCallTargetSrc), + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &class_)); - Assembler::Memory virtualCallTargetDst + lir::Memory virtualCallTargetDst (t->arch->thread(), TARGET_THREAD_VIRTUALCALLTARGET); - a->apply(Move, TargetBytesPerWord, RegisterOperand, &class_, - TargetBytesPerWord, MemoryOperand, &virtualCallTargetDst); + a->apply(lir::Move, + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &class_), + OperandInfo(TargetBytesPerWord, lir::MemoryOperand, &virtualCallTargetDst)); - Assembler::Register index(t->arch->virtualCallIndex()); - Assembler::Memory virtualCallIndex + lir::Register index(t->arch->virtualCallIndex()); + lir::Memory virtualCallIndex (t->arch->thread(), TARGET_THREAD_VIRTUALCALLINDEX); - a->apply(Move, TargetBytesPerWord, RegisterOperand, &index, - TargetBytesPerWord, MemoryOperand, &virtualCallIndex); + a->apply(lir::Move, + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &index), + OperandInfo(TargetBytesPerWord, lir::MemoryOperand, &virtualCallIndex)); a->saveFrame(TARGET_THREAD_STACK, TARGET_THREAD_IP); p->thunks.defaultVirtual.frameSavedOffset = a->length(); - Assembler::Register thread(t->arch->thread()); - a->pushFrame(1, TargetBytesPerWord, RegisterOperand, &thread); + lir::Register thread(t->arch->thread()); + a->pushFrame(1, TargetBytesPerWord, lir::RegisterOperand, &thread); compileCall(t, &context, compileVirtualMethodIndex); a->popFrame(t->arch->alignFrameSize(1)); - Assembler::Register result(t->arch->returnLow()); - a->apply(Jump, TargetBytesPerWord, RegisterOperand, &result); + lir::Register result(t->arch->returnLow()); + a->apply(lir::Jump, + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &result)); p->thunks.defaultVirtual.length = a->endBlock(false)->resolve(0, 0); @@ -10143,14 +10157,14 @@ compileThunks(MyThread* t, FixedAllocator* allocator) } { Context context(t); - Assembler* a = context.assembler; + avian::codegen::Assembler* a = context.assembler; a->saveFrame(TARGET_THREAD_STACK, TARGET_THREAD_IP); p->thunks.native.frameSavedOffset = a->length(); - Assembler::Register thread(t->arch->thread()); - a->pushFrame(1, TargetBytesPerWord, RegisterOperand, &thread); + lir::Register thread(t->arch->thread()); + a->pushFrame(1, TargetBytesPerWord, lir::RegisterOperand, &thread); compileCall(t, &context, invokeNativeIndex); @@ -10164,14 +10178,14 @@ compileThunks(MyThread* t, FixedAllocator* allocator) } { Context context(t); - Assembler* a = context.assembler; + avian::codegen::Assembler* a = context.assembler; a->saveFrame(TARGET_THREAD_STACK, TARGET_THREAD_IP); p->thunks.aioob.frameSavedOffset = a->length(); - Assembler::Register thread(t->arch->thread()); - a->pushFrame(1, TargetBytesPerWord, RegisterOperand, &thread); + lir::Register thread(t->arch->thread()); + a->pushFrame(1, TargetBytesPerWord, lir::RegisterOperand, &thread); compileCall(t, &context, throwArrayIndexOutOfBoundsIndex); @@ -10182,14 +10196,14 @@ compileThunks(MyThread* t, FixedAllocator* allocator) } { Context context(t); - Assembler* a = context.assembler; + avian::codegen::Assembler* a = context.assembler; a->saveFrame(TARGET_THREAD_STACK, TARGET_THREAD_IP); p->thunks.stackOverflow.frameSavedOffset = a->length(); - Assembler::Register thread(t->arch->thread()); - a->pushFrame(1, TargetBytesPerWord, RegisterOperand, &thread); + lir::Register thread(t->arch->thread()); + a->pushFrame(1, TargetBytesPerWord, lir::RegisterOperand, &thread); compileCall(t, &context, throwStackOverflowIndex); @@ -10200,7 +10214,7 @@ compileThunks(MyThread* t, FixedAllocator* allocator) } { { Context context(t); - Assembler* a = context.assembler; + avian::codegen::Assembler* a = context.assembler; a->saveFrame(TARGET_THREAD_STACK, TARGET_THREAD_IP); @@ -10219,7 +10233,7 @@ compileThunks(MyThread* t, FixedAllocator* allocator) #define THUNK(s) { \ Context context(t); \ - Assembler* a = context.assembler; \ + avian::codegen::Assembler* a = context.assembler; \ \ a->saveFrame(TARGET_THREAD_STACK, TARGET_THREAD_IP); \ \ @@ -10317,17 +10331,19 @@ uintptr_t compileVirtualThunk(MyThread* t, unsigned index, unsigned* size) { Context context(t); - Assembler* a = context.assembler; + avian::codegen::Assembler* a = context.assembler; - ResolvedPromise indexPromise(index); - Assembler::Constant indexConstant(&indexPromise); - Assembler::Register indexRegister(t->arch->virtualCallIndex()); - a->apply(Move, TargetBytesPerWord, ConstantOperand, &indexConstant, - TargetBytesPerWord, RegisterOperand, &indexRegister); + avian::codegen::ResolvedPromise indexPromise(index); + lir::Constant indexConstant(&indexPromise); + lir::Register indexRegister(t->arch->virtualCallIndex()); + a->apply(lir::Move, + OperandInfo(TargetBytesPerWord, lir::ConstantOperand, &indexConstant), + OperandInfo(TargetBytesPerWord, lir::RegisterOperand, &indexRegister)); - ResolvedPromise defaultVirtualThunkPromise(defaultVirtualThunk(t)); - Assembler::Constant thunk(&defaultVirtualThunkPromise); - a->apply(Jump, TargetBytesPerWord, ConstantOperand, &thunk); + avian::codegen::ResolvedPromise defaultVirtualThunkPromise(defaultVirtualThunk(t)); + lir::Constant thunk(&defaultVirtualThunkPromise); + a->apply(lir::Jump, + OperandInfo(TargetBytesPerWord, lir::ConstantOperand, &thunk)); *size = a->endBlock(false)->resolve(0, 0); diff --git a/src/processor.h b/src/processor.h index ab9d68e1aa..1c1de3e577 100644 --- a/src/processor.h +++ b/src/processor.h @@ -18,9 +18,13 @@ #include "heapwalk.h" #include "zone.h" -namespace vm { - +namespace avian { +namespace codegen { class DelayedPromise; +} +} + +namespace vm { class Processor { public: @@ -143,7 +147,7 @@ class Processor { virtual void compileMethod(Thread* t, Zone* zone, object* constants, object* calls, - DelayedPromise** addresses, object method, + avian::codegen::DelayedPromise** addresses, object method, OffsetResolver* resolver) = 0; virtual void