[vm/bytecode] Change encoding of MoveSpecial bytecode instruction

Previously MoveSpecial bytecode instruction used unsigned 8-bit A field
to encode target local variable index. This is too restrictive as we allow
signed 16-bit local variable indices.

After this change MoveSpecial has A_X encoding, with A field used for
special index (0 or 1), and signed 16-bit X field used for target local.

Change-Id: Ib87992e192b2923a39a9968913c39476947d3ea5
Reviewed-on: https://dart-review.googlesource.com/c/81440
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Alexander Markov
2018-10-25 19:07:19 +00:00
committed by commit-bot@chromium.org
parent 843142bb79
commit 59e626e5c9
15 changed files with 99 additions and 105 deletions
+4 -7
View File
@@ -121,11 +121,8 @@ class BytecodeAssembler {
int _encodeAD(Opcode opcode, int ra, int rd) =>
_uint8(opcode.index) | (_uint8(ra) << 8) | (_uint16(rd) << 16);
// TODO(alexmarkov) This format is currently unused. Restore it if needed, or
// remove it once bytecode instruction set is finalized.
//
// int _encodeAX(Opcode opcode, int ra, int rx) =>
// _uint8(opcode.index) | (_uint8(ra) << 8) | (_int16(rx) << 16);
int _encodeAX(Opcode opcode, int ra, int rx) =>
_uint8(opcode.index) | (_uint8(ra) << 8) | (_int16(rx) << 16);
int _encodeD(Opcode opcode, int rd) =>
_uint8(opcode.index) | (_uint16(rd) << 16);
@@ -350,8 +347,8 @@ class BytecodeAssembler {
emitWord(_encode0(Opcode.kCloneContext));
}
void emitMoveSpecial(int ra, SpecialIndex rd) {
emitWord(_encodeAD(Opcode.kMoveSpecial, ra, rd.index));
void emitMoveSpecial(SpecialIndex ra, int rx) {
emitWord(_encodeAX(Opcode.kMoveSpecial, ra.index, rx));
}
void emitInstantiateType(int rd) {
+2 -2
View File
@@ -163,7 +163,7 @@ const Map<Opcode, Format> BytecodeFormats = const {
Opcode.kFrame: const Format(
Encoding.kD, const [Operand.imm, Operand.none, Operand.none]),
Opcode.kCheckFunctionTypeArgs: const Format(
Encoding.kAD, const [Operand.imm, Operand.imm, Operand.none]),
Encoding.kAD, const [Operand.imm, Operand.reg, Operand.none]),
Opcode.kCheckStack: const Format(
Encoding.k0, const [Operand.none, Operand.none, Operand.none]),
Opcode.kAllocate: const Format(
@@ -253,7 +253,7 @@ const Map<Opcode, Format> BytecodeFormats = const {
Opcode.kThrow: const Format(
Encoding.kA, const [Operand.imm, Operand.none, Operand.none]),
Opcode.kMoveSpecial: const Format(
Encoding.kAD, const [Operand.reg, Operand.spe, Operand.none]),
Encoding.kAX, const [Operand.spe, Operand.xeg, Operand.none]),
Opcode.kSetFrame: const Format(
Encoding.kA, const [Operand.imm, Operand.none, Operand.none]),
Opcode.kBooleanNegateTOS: const Format(
+2 -2
View File
@@ -2617,8 +2617,8 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
_restoreContextForTryBlock(node);
asm.emitMoveSpecial(_exceptionVar(node), SpecialIndex.exception);
asm.emitMoveSpecial(_stackTraceVar(node), SpecialIndex.stackTrace);
asm.emitMoveSpecial(SpecialIndex.exception, _exceptionVar(node));
asm.emitMoveSpecial(SpecialIndex.stackTrace, _stackTraceVar(node));
final capturedExceptionVar = locals.capturedExceptionVar(node);
if (capturedExceptionVar != null) {
+20 -20
View File
@@ -129,8 +129,8 @@ Try #0 handler:
Push r4
LoadContextVar 7
PopLocal r4
MoveSpecial r6, exception
MoveSpecial r7, stackTrace
MoveSpecial exception, r6
MoveSpecial stackTrace, r7
Push r6
PopLocal r8
Push r7
@@ -406,8 +406,8 @@ Try #0 handler:
SetFrame 10
Push r6
PopLocal r4
MoveSpecial r6, exception
MoveSpecial r7, stackTrace
MoveSpecial exception, r6
MoveSpecial stackTrace, r7
Push r6
PopLocal r8
Push r7
@@ -675,8 +675,8 @@ Try #0 handler:
Push r4
LoadContextVar 8
PopLocal r4
MoveSpecial r6, exception
MoveSpecial r7, stackTrace
MoveSpecial exception, r6
MoveSpecial stackTrace, r7
Push r6
PopLocal r8
Push r7
@@ -1081,8 +1081,8 @@ Try #0 handler:
Push r4
LoadContextVar 7
PopLocal r4
MoveSpecial r6, exception
MoveSpecial r7, stackTrace
MoveSpecial exception, r6
MoveSpecial stackTrace, r7
Push r6
PopLocal r8
Push r7
@@ -1388,8 +1388,8 @@ Try #2 handler:
Push r4
LoadContextVar 11
PopLocal r4
MoveSpecial r10, exception
MoveSpecial r11, stackTrace
MoveSpecial exception, r10
MoveSpecial stackTrace, r11
Push r4
LoadContextParent
Push r10
@@ -1475,8 +1475,8 @@ Try #1 handler:
Push r4
LoadContextVar 10
PopLocal r4
MoveSpecial r8, exception
MoveSpecial r9, stackTrace
MoveSpecial exception, r8
MoveSpecial stackTrace, r9
Push r4
LoadContextParent
Push r8
@@ -1689,8 +1689,8 @@ Try #0 handler:
Push r4
LoadContextVar 9
PopLocal r4
MoveSpecial r6, exception
MoveSpecial r7, stackTrace
MoveSpecial exception, r6
MoveSpecial stackTrace, r7
Push r6
PopLocal r8
Push r7
@@ -1945,8 +1945,8 @@ Try #1 handler:
Push r4
LoadContextVar 7
PopLocal r4
MoveSpecial r8, exception
MoveSpecial r9, stackTrace
MoveSpecial exception, r8
MoveSpecial stackTrace, r9
PushConstant CP#11
PushConstant CP#12
IndirectStaticCall 1, CP#4
@@ -1988,8 +1988,8 @@ Try #0 handler:
Push r4
LoadContextVar 6
PopLocal r4
MoveSpecial r6, exception
MoveSpecial r7, stackTrace
MoveSpecial exception, r6
MoveSpecial stackTrace, r7
Push r6
PopLocal r8
Push r7
@@ -2340,8 +2340,8 @@ Try #0 handler:
Push r4
LoadContextVar 7
PopLocal r4
MoveSpecial r6, exception
MoveSpecial r7, stackTrace
MoveSpecial exception, r6
MoveSpecial stackTrace, r7
Push r6
PopLocal r8
Push r7
@@ -186,7 +186,7 @@ ConstantPool {
Bytecode (version: stable) {
Entry 5
CheckStack
CheckFunctionTypeArgs 2, 0
CheckFunctionTypeArgs 2, r0
AllocateContext 1
PopLocal r1
Push r1
@@ -368,10 +368,10 @@ Closure CP#10 {
StoreLocal r0
PushConstant CP#5
JumpIfEqStrict L1
CheckFunctionTypeArgs 0, 2
CheckFunctionTypeArgs 0, r2
Jump L2
L1:
CheckFunctionTypeArgs 2, 0
CheckFunctionTypeArgs 2, r0
L2:
Push r0
Push FP[-5]
@@ -420,10 +420,10 @@ Closure CP#0 {
StoreLocal r0
PushConstant CP#5
JumpIfEqStrict L1
CheckFunctionTypeArgs 0, 2
CheckFunctionTypeArgs 0, r2
Jump L2
L1:
CheckFunctionTypeArgs 2, 0
CheckFunctionTypeArgs 2, r0
L2:
Push r0
Push FP[-5]
@@ -1256,7 +1256,7 @@ Closure CP#0 {
Bytecode (version: stable) {
Entry 2
CheckStack
CheckFunctionTypeArgs 8, 0
CheckFunctionTypeArgs 8, r0
PushConstant CP#0
StoreLocal r1
Push r1
@@ -1486,10 +1486,10 @@ Closure CP#0 {
StoreLocal r0
PushConstant CP#5
JumpIfEqStrict L1
CheckFunctionTypeArgs 0, 2
CheckFunctionTypeArgs 0, r2
Jump L2
L1:
CheckFunctionTypeArgs 1, 0
CheckFunctionTypeArgs 1, r0
L2:
Push r0
Push FP[-6]
@@ -479,7 +479,7 @@ ConstantPool {
Bytecode (version: stable) {
Entry 2
CheckStack
CheckFunctionTypeArgs 1, 0
CheckFunctionTypeArgs 1, r0
PushNull
Push r0
InstantiateTypeArgumentsTOS 0, CP#1
@@ -518,7 +518,7 @@ ConstantPool {
Bytecode (version: stable) {
Entry 2
CheckStack
CheckFunctionTypeArgs 1, 0
CheckFunctionTypeArgs 1, r0
PushConstant CP#0
PushConstant CP#1
PushInt 4
@@ -660,7 +660,7 @@ ConstantPool {
Bytecode (version: stable) {
Entry 1
CheckStack
CheckFunctionTypeArgs 1, 0
CheckFunctionTypeArgs 1, r0
PushConstant CP#0
PushConstant CP#2
IndirectStaticCall 1, CP#1
@@ -222,7 +222,7 @@ Bytecode (version: stable) {
LoadConstant r3, CP#3
Frame 1
CheckStack
CheckFunctionTypeArgs 2, 4
CheckFunctionTypeArgs 2, r4
PushNull
Push r4
InstantiateType CP#4
@@ -25,7 +25,7 @@ ConstantPool {
Bytecode (version: stable) {
Entry 1
CheckStack
CheckFunctionTypeArgs 1, 0
CheckFunctionTypeArgs 1, r0
PushNull
ReturnTOS
}
@@ -15,8 +15,8 @@ Try #0 start:
Try #0 end:
Try #0 handler:
SetFrame 4
MoveSpecial r0, exception
MoveSpecial r1, stackTrace
MoveSpecial exception, r0
MoveSpecial stackTrace, r1
Push r0
PopLocal r2
PushNull
@@ -74,8 +74,8 @@ Try #0 start:
Try #0 end:
Try #0 handler:
SetFrame 5
MoveSpecial r0, exception
MoveSpecial r1, stackTrace
MoveSpecial exception, r0
MoveSpecial stackTrace, r1
Push r0
PushConstant CP#3
InstanceCall 2, CP#5
@@ -272,8 +272,8 @@ Try #0 handler:
SetFrame 7
Push r2
PopLocal r0
MoveSpecial r2, exception
MoveSpecial r3, stackTrace
MoveSpecial exception, r2
MoveSpecial stackTrace, r3
Push r2
PopLocal r4
Push r0
@@ -392,8 +392,8 @@ Try #0 handler:
SetFrame 6
Push r2
PopLocal r0
MoveSpecial r2, exception
MoveSpecial r3, stackTrace
MoveSpecial exception, r2
MoveSpecial stackTrace, r3
Push r2
PopLocal r4
Push r0
@@ -430,8 +430,8 @@ Try #0 handler:
SetFrame 6
Push r2
PopLocal r0
MoveSpecial r2, exception
MoveSpecial r3, stackTrace
MoveSpecial exception, r2
MoveSpecial stackTrace, r3
Push r2
PushConstant CP#28
InstanceCall 2, CP#30
@@ -517,8 +517,8 @@ Try #1 start:
Try #1 end:
Try #1 handler:
SetFrame 8
MoveSpecial r2, exception
MoveSpecial r3, stackTrace
MoveSpecial exception, r2
MoveSpecial stackTrace, r3
Push r2
PopLocal r4
Try #2 start:
@@ -537,8 +537,8 @@ L2:
Try #2 end:
Try #2 handler:
SetFrame 8
MoveSpecial r5, exception
MoveSpecial r6, stackTrace
MoveSpecial exception, r5
MoveSpecial stackTrace, r6
Push r5
PopLocal r7
PushConstant CP#6
@@ -553,8 +553,8 @@ L1:
Try #0 end:
Try #0 handler:
SetFrame 8
MoveSpecial r0, exception
MoveSpecial r1, stackTrace
MoveSpecial exception, r0
MoveSpecial stackTrace, r1
Push r0
PopLocal r2
Push r1
@@ -637,8 +637,8 @@ L2:
Try #0 end:
Try #0 handler:
SetFrame 3
MoveSpecial r1, exception
MoveSpecial r2, stackTrace
MoveSpecial exception, r1
MoveSpecial stackTrace, r2
Push r0
PushConstant CP#2
IndirectStaticCall 1, CP#1
@@ -756,8 +756,8 @@ Try #1 handler:
SetFrame 9
Push r5
PopLocal r0
MoveSpecial r5, exception
MoveSpecial r6, stackTrace
MoveSpecial exception, r5
MoveSpecial stackTrace, r6
PushConstant CP#26
PushConstant CP#27
IndirectStaticCall 1, CP#4
@@ -778,8 +778,8 @@ Try #0 handler:
SetFrame 9
Push r3
PopLocal r0
MoveSpecial r3, exception
MoveSpecial r4, stackTrace
MoveSpecial exception, r3
MoveSpecial stackTrace, r4
PushConstant CP#31
PushConstant CP#32
IndirectStaticCall 1, CP#4
@@ -941,8 +941,8 @@ Try #0 handler:
SetFrame 6
Push r3
PopLocal r0
MoveSpecial r3, exception
MoveSpecial r4, stackTrace
MoveSpecial exception, r3
MoveSpecial stackTrace, r4
Push r0
LoadContextVar 0
PushConstant CP#26
@@ -1030,8 +1030,8 @@ Try #0 handler:
SetFrame 6
Push r2
PopLocal r0
MoveSpecial r2, exception
MoveSpecial r3, stackTrace
MoveSpecial exception, r2
MoveSpecial stackTrace, r3
Push r0
PopLocal r4
Try #1 start:
@@ -1045,8 +1045,8 @@ Try #1 handler:
SetFrame 6
Push r4
PopLocal r0
MoveSpecial r4, exception
MoveSpecial r5, stackTrace
MoveSpecial exception, r4
MoveSpecial stackTrace, r5
Push r0
LoadContextVar 0
PushConstant CP#10
@@ -1081,8 +1081,8 @@ Try #2 handler:
SetFrame 6
Push r4
PopLocal r0
MoveSpecial r4, exception
MoveSpecial r5, stackTrace
MoveSpecial exception, r4
MoveSpecial stackTrace, r5
Push r0
LoadContextVar 0
PushConstant CP#13
@@ -1143,8 +1143,8 @@ Try #1 start:
Try #1 end:
Try #1 handler:
SetFrame 5
MoveSpecial r2, exception
MoveSpecial r3, stackTrace
MoveSpecial exception, r2
MoveSpecial stackTrace, r3
Push r2
PopLocal r4
PushConstant CP#4
@@ -1157,8 +1157,8 @@ L1:
Try #0 end:
Try #0 handler:
SetFrame 5
MoveSpecial r0, exception
MoveSpecial r1, stackTrace
MoveSpecial exception, r0
MoveSpecial stackTrace, r1
PushConstant CP#6
PushConstant CP#7
IndirectStaticCall 1, CP#1
@@ -171,7 +171,7 @@ ConstantPool {
Bytecode (version: stable) {
Entry 1
CheckStack
CheckFunctionTypeArgs 2, 0
CheckFunctionTypeArgs 2, r0
Push FP[-5]
PushNull
Push r0
@@ -299,7 +299,7 @@ ConstantPool {
Bytecode (version: stable) {
Entry 1
CheckStack
CheckFunctionTypeArgs 2, 0
CheckFunctionTypeArgs 2, r0
JumpIfNotZeroTypeArgs L1
Push FP[-6]
LoadTypeArgumentsField CP#0
@@ -128,21 +128,18 @@ static void FormatA_D(char* buf,
Apply(&buf, &size, pc, op2, bc, "");
}
// TODO(alexmarkov) This format is currently unused. Restore it if needed, or
// remove it once bytecode instruction set is finalized.
//
// static void FormatA_X(char* buf,
// intptr_t size,
// uword pc,
// uint32_t op,
// Fmt op1,
// Fmt op2,
// Fmt op3) {
// const int32_t a = (op & 0xFF00) >> 8;
// const int32_t bc = static_cast<int32_t>(op) >> 16;
// Apply(&buf, &size, pc, op1, a, ", ");
// Apply(&buf, &size, pc, op2, bc, "");
// }
static void FormatA_X(char* buf,
intptr_t size,
uword pc,
uint32_t op,
Fmt op1,
Fmt op2,
Fmt op3) {
const int32_t a = (op & 0xFF00) >> 8;
const int32_t bc = static_cast<int32_t>(op) >> 16;
Apply(&buf, &size, pc, op1, a, ", ");
Apply(&buf, &size, pc, op2, bc, "");
}
static void FormatX(char* buf,
intptr_t size,
@@ -1156,8 +1156,7 @@ void BytecodeFlowGraphBuilder::BuildMoveSpecial() {
}
LocalVariable* special_var = nullptr;
switch (DecodeOperandD().value()) {
// TODO(alexmarkov): Move these constants to constants_kbc.h
switch (DecodeOperandA().value()) {
case KernelBytecode::kExceptionSpecialIndex:
ASSERT(exception_var_ != nullptr);
special_var = exception_var_;
@@ -1171,7 +1170,7 @@ void BytecodeFlowGraphBuilder::BuildMoveSpecial() {
}
code_ += B->LoadLocal(special_var);
StoreLocal(DecodeOperandA());
StoreLocal(DecodeOperandX());
code_ += B->Drop();
}
+5 -5
View File
@@ -329,10 +329,10 @@ namespace dart {
// Throw (Rethrow if A != 0) exception. Exception object and stack object
// are taken from TOS.
//
// - MoveSpecial rA, D
// - MoveSpecial A, rX
//
// Copy special values from inside interpreter to FP[rA]. Currently only
// used to pass exception object (D = 0) and stack trace object (D = 1) to
// Copy value from special variable to FP[rX]. Currently only
// used to pass exception object (A = 0) and stack trace object (A = 1) to
// catch handler.
//
// - SetFrame A
@@ -396,7 +396,7 @@ namespace dart {
V(EntryOptional, A_B_C, num, num, num) \
V(LoadConstant, A_D, reg, lit, ___) \
V(Frame, D, num, ___, ___) \
V(CheckFunctionTypeArgs, A_D, num, num, ___) \
V(CheckFunctionTypeArgs, A_D, num, reg, ___) \
V(CheckStack, 0, ___, ___, ___) \
V(Allocate, D, lit, ___, ___) \
V(AllocateT, 0, ___, ___, ___) \
@@ -441,7 +441,7 @@ namespace dart {
V(InstantiateType, D, lit, ___, ___) \
V(InstantiateTypeArgumentsTOS, A_D, num, lit, ___) \
V(Throw, A, num, ___, ___) \
V(MoveSpecial, A_D, reg, num, ___) \
V(MoveSpecial, A_X, num, xeg, ___) \
V(SetFrame, A, num, ___, num) \
V(BooleanNegateTOS, 0, ___, ___, ___) \
V(EqualsNull, 0, ___, ___, ___) \
+3 -2
View File
@@ -2061,8 +2061,9 @@ RawObject* Interpreter::Call(RawFunction* function,
}
{
BYTECODE(MoveSpecial, A_D);
FP[rA] = special_[rD];
BYTECODE(MoveSpecial, A_X);
ASSERT(rA < KernelBytecode::kSpecialIndexCount);
FP[rD] = special_[rA];
DISPATCH();
}