diff --git a/pkg/vm/lib/bytecode/assembler.dart b/pkg/vm/lib/bytecode/assembler.dart index b45b4c15011..efaae5fbd46 100644 --- a/pkg/vm/lib/bytecode/assembler.dart +++ b/pkg/vm/lib/bytecode/assembler.dart @@ -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) { diff --git a/pkg/vm/lib/bytecode/dbc.dart b/pkg/vm/lib/bytecode/dbc.dart index 2a8bbefe816..3a45d1394f5 100644 --- a/pkg/vm/lib/bytecode/dbc.dart +++ b/pkg/vm/lib/bytecode/dbc.dart @@ -163,7 +163,7 @@ const Map 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 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( diff --git a/pkg/vm/lib/bytecode/gen_bytecode.dart b/pkg/vm/lib/bytecode/gen_bytecode.dart index 06c8592b9e8..a3b31927522 100644 --- a/pkg/vm/lib/bytecode/gen_bytecode.dart +++ b/pkg/vm/lib/bytecode/gen_bytecode.dart @@ -2617,8 +2617,8 @@ class BytecodeGenerator extends RecursiveVisitor { _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) { diff --git a/pkg/vm/testcases/bytecode/async.dart.expect b/pkg/vm/testcases/bytecode/async.dart.expect index 7b37aaa16a5..a30628251c2 100644 --- a/pkg/vm/testcases/bytecode/async.dart.expect +++ b/pkg/vm/testcases/bytecode/async.dart.expect @@ -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 diff --git a/pkg/vm/testcases/bytecode/closures.dart.expect b/pkg/vm/testcases/bytecode/closures.dart.expect index d73647e8967..c468b72b41f 100644 --- a/pkg/vm/testcases/bytecode/closures.dart.expect +++ b/pkg/vm/testcases/bytecode/closures.dart.expect @@ -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] diff --git a/pkg/vm/testcases/bytecode/instance_creation.dart.expect b/pkg/vm/testcases/bytecode/instance_creation.dart.expect index 1cd0231ab64..db64c595fbe 100644 --- a/pkg/vm/testcases/bytecode/instance_creation.dart.expect +++ b/pkg/vm/testcases/bytecode/instance_creation.dart.expect @@ -479,7 +479,7 @@ ConstantPool { Bytecode (version: stable) { Entry 2 CheckStack - CheckFunctionTypeArgs 1, 0 + CheckFunctionTypeArgs 1, r0 PushNull Push r0 InstantiateTypeArgumentsTOS 0, CP#1 diff --git a/pkg/vm/testcases/bytecode/literals.dart.expect b/pkg/vm/testcases/bytecode/literals.dart.expect index e5ace827d47..a8181567f3b 100644 --- a/pkg/vm/testcases/bytecode/literals.dart.expect +++ b/pkg/vm/testcases/bytecode/literals.dart.expect @@ -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 diff --git a/pkg/vm/testcases/bytecode/optional_params.dart.expect b/pkg/vm/testcases/bytecode/optional_params.dart.expect index bd33fe5b262..e599a144b38 100644 --- a/pkg/vm/testcases/bytecode/optional_params.dart.expect +++ b/pkg/vm/testcases/bytecode/optional_params.dart.expect @@ -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 diff --git a/pkg/vm/testcases/bytecode/super_calls.dart.expect b/pkg/vm/testcases/bytecode/super_calls.dart.expect index f466a6d0817..cc3d474a9d2 100644 --- a/pkg/vm/testcases/bytecode/super_calls.dart.expect +++ b/pkg/vm/testcases/bytecode/super_calls.dart.expect @@ -25,7 +25,7 @@ ConstantPool { Bytecode (version: stable) { Entry 1 CheckStack - CheckFunctionTypeArgs 1, 0 + CheckFunctionTypeArgs 1, r0 PushNull ReturnTOS } diff --git a/pkg/vm/testcases/bytecode/try_blocks.dart.expect b/pkg/vm/testcases/bytecode/try_blocks.dart.expect index e513f1e4ce3..ed1405465c4 100644 --- a/pkg/vm/testcases/bytecode/try_blocks.dart.expect +++ b/pkg/vm/testcases/bytecode/try_blocks.dart.expect @@ -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 diff --git a/pkg/vm/testcases/bytecode/type_ops.dart.expect b/pkg/vm/testcases/bytecode/type_ops.dart.expect index ef137094fb0..66d2906a956 100644 --- a/pkg/vm/testcases/bytecode/type_ops.dart.expect +++ b/pkg/vm/testcases/bytecode/type_ops.dart.expect @@ -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 diff --git a/runtime/vm/compiler/assembler/disassembler_kbc.cc b/runtime/vm/compiler/assembler/disassembler_kbc.cc index a51753bba96..00f892d7b64 100644 --- a/runtime/vm/compiler/assembler/disassembler_kbc.cc +++ b/runtime/vm/compiler/assembler/disassembler_kbc.cc @@ -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(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(op) >> 16; + Apply(&buf, &size, pc, op1, a, ", "); + Apply(&buf, &size, pc, op2, bc, ""); +} static void FormatX(char* buf, intptr_t size, diff --git a/runtime/vm/compiler/frontend/bytecode_flow_graph_builder.cc b/runtime/vm/compiler/frontend/bytecode_flow_graph_builder.cc index 6d48c901aba..af0e35ee12a 100644 --- a/runtime/vm/compiler/frontend/bytecode_flow_graph_builder.cc +++ b/runtime/vm/compiler/frontend/bytecode_flow_graph_builder.cc @@ -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(); } diff --git a/runtime/vm/constants_kbc.h b/runtime/vm/constants_kbc.h index d61ac75825c..00c39f9b24c 100644 --- a/runtime/vm/constants_kbc.h +++ b/runtime/vm/constants_kbc.h @@ -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, ___, ___, ___) \ diff --git a/runtime/vm/interpreter.cc b/runtime/vm/interpreter.cc index 3185b938b1a..30662fb5012 100644 --- a/runtime/vm/interpreter.cc +++ b/runtime/vm/interpreter.cc @@ -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(); }