diff options
Diffstat (limited to 'deps/v8/test/unittests/interpreter/interpreter-assembler-unittest.cc')
-rw-r--r-- | deps/v8/test/unittests/interpreter/interpreter-assembler-unittest.cc | 189 |
1 files changed, 114 insertions, 75 deletions
diff --git a/deps/v8/test/unittests/interpreter/interpreter-assembler-unittest.cc b/deps/v8/test/unittests/interpreter/interpreter-assembler-unittest.cc index b8eb64c884..f80e8a3f80 100644 --- a/deps/v8/test/unittests/interpreter/interpreter-assembler-unittest.cc +++ b/deps/v8/test/unittests/interpreter/interpreter-assembler-unittest.cc @@ -5,7 +5,6 @@ #include "test/unittests/interpreter/interpreter-assembler-unittest.h" #include "src/code-factory.h" -#include "src/compiler/graph.h" #include "src/compiler/node.h" #include "src/interface-descriptors.h" #include "src/isolate.h" @@ -21,6 +20,14 @@ using namespace compiler; namespace interpreter { +InterpreterAssemblerTestState::InterpreterAssemblerTestState( + InterpreterAssemblerTest* test, Bytecode bytecode) + : compiler::CodeAssemblerState( + test->isolate(), test->zone(), + InterpreterDispatchDescriptor(test->isolate()), + Code::ComputeFlags(Code::BYTECODE_HANDLER), + Bytecodes::ToString(bytecode), Bytecodes::ReturnCount(bytecode)) {} + const interpreter::Bytecode kBytecodes[] = { #define DEFINE_BYTECODE(Name, ...) interpreter::Bytecode::k##Name, BYTECODE_LIST(DEFINE_BYTECODE) @@ -44,6 +51,12 @@ Matcher<Node*> IsIntPtrSub(const Matcher<Node*>& lhs_matcher, : IsInt32Sub(lhs_matcher, rhs_matcher); } +Matcher<Node*> IsIntPtrMul(const Matcher<Node*>& lhs_matcher, + const Matcher<Node*>& rhs_matcher) { + return kPointerSize == 8 ? IsInt64Mul(lhs_matcher, rhs_matcher) + : IsInt32Mul(lhs_matcher, rhs_matcher); +} + Matcher<Node*> IsWordShl(const Matcher<Node*>& lhs_matcher, const Matcher<Node*>& rhs_matcher) { return kPointerSize == 8 ? IsWord64Shl(lhs_matcher, rhs_matcher) @@ -62,6 +75,18 @@ Matcher<Node*> IsWordOr(const Matcher<Node*>& lhs_matcher, : IsWord32Or(lhs_matcher, rhs_matcher); } +Matcher<Node*> IsChangeInt32ToIntPtr(const Matcher<Node*>& matcher) { + return kPointerSize == 8 ? IsChangeInt32ToInt64(matcher) : matcher; +} + +Matcher<Node*> IsChangeUint32ToWord(const Matcher<Node*>& matcher) { + return kPointerSize == 8 ? IsChangeUint32ToUint64(matcher) : matcher; +} + +Matcher<Node*> IsTruncateWordToWord32(const Matcher<Node*>& matcher) { + return kPointerSize == 8 ? IsTruncateInt64ToInt32(matcher) : matcher; +} + InterpreterAssemblerTest::InterpreterAssemblerForTest:: ~InterpreterAssemblerForTest() { // Tests don't necessarily read and write accumulator but @@ -101,15 +126,11 @@ InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedByteOperand( Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedByteOperand( int offset) { - Matcher<Node*> load_matcher = IsLoad( + return IsLoad( MachineType::Int8(), IsParameter(InterpreterDispatchDescriptor::kBytecodeArray), IsIntPtrAdd(IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset), IsIntPtrConstant(offset))); - if (kPointerSize == 8) { - load_matcher = IsChangeInt32ToInt64(load_matcher); - } - return load_matcher; } Matcher<Node*> @@ -148,9 +169,8 @@ InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedShortOperand( Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedShortOperand( int offset) { - Matcher<Node*> load_matcher; if (TargetSupportsUnalignedAccess()) { - load_matcher = IsLoad( + return IsLoad( MachineType::Int16(), IsParameter(InterpreterDispatchDescriptor::kBytecodeArray), IsIntPtrAdd(IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset), @@ -174,14 +194,9 @@ InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedShortOperand( IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset), IsIntPtrConstant(offset + kMsbOffset + kStep * i))); } - load_matcher = IsWord32Or( - IsWord32Shl(bytes[0], IsInt32Constant(kBitsPerByte)), bytes[1]); - } - - if (kPointerSize == 8) { - load_matcher = IsChangeInt32ToInt64(load_matcher); + return IsWord32Or(IsWord32Shl(bytes[0], IsInt32Constant(kBitsPerByte)), + bytes[1]); } - return load_matcher; } Matcher<Node*> @@ -224,9 +239,8 @@ InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedQuadOperand( Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedQuadOperand( int offset) { - Matcher<Node*> load_matcher; if (TargetSupportsUnalignedAccess()) { - load_matcher = IsLoad( + return IsLoad( MachineType::Int32(), IsParameter(InterpreterDispatchDescriptor::kBytecodeArray), IsIntPtrAdd(IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset), @@ -250,18 +264,13 @@ InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedQuadOperand( IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset), IsIntPtrConstant(offset + kMsbOffset + kStep * i))); } - load_matcher = IsWord32Or( + return IsWord32Or( IsWord32Shl(bytes[0], IsInt32Constant(3 * kBitsPerByte)), IsWord32Or( IsWord32Shl(bytes[1], IsInt32Constant(2 * kBitsPerByte)), IsWord32Or(IsWord32Shl(bytes[2], IsInt32Constant(1 * kBitsPerByte)), bytes[3]))); } - - if (kPointerSize == 8) { - load_matcher = IsChangeInt32ToInt64(load_matcher); - } - return load_matcher; } Matcher<Node*> @@ -298,7 +307,8 @@ InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedOperand( TARGET_TEST_F(InterpreterAssemblerTest, Dispatch) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); Node* tail_call_node = m.Dispatch(); OperandScale operand_scale = OperandScale::kSingle; @@ -310,9 +320,7 @@ TARGET_TEST_F(InterpreterAssemblerTest, Dispatch) { m.IsLoad(MachineType::Uint8(), IsParameter(InterpreterDispatchDescriptor::kBytecodeArray), next_bytecode_offset_matcher); - if (kPointerSize == 8) { - target_bytecode_matcher = IsChangeUint32ToUint64(target_bytecode_matcher); - } + target_bytecode_matcher = IsChangeUint32ToWord(target_bytecode_matcher); Matcher<Node*> code_target_matcher = m.IsLoad( MachineType::Pointer(), IsParameter(InterpreterDispatchDescriptor::kDispatchTable), @@ -330,10 +338,7 @@ TARGET_TEST_F(InterpreterAssemblerTest, Dispatch) { m.IsLoad(MachineType::Uint8(), IsParameter(InterpreterDispatchDescriptor::kBytecodeArray), after_lookahead_offset); - if (kPointerSize == 8) { - after_lookahead_bytecode = - IsChangeUint32ToUint64(after_lookahead_bytecode); - } + after_lookahead_bytecode = IsChangeUint32ToWord(after_lookahead_bytecode); target_bytecode_matcher = IsPhi(MachineType::PointerRepresentation(), target_bytecode_matcher, after_lookahead_bytecode, _); @@ -364,7 +369,8 @@ TARGET_TEST_F(InterpreterAssemblerTest, Jump) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { if (!interpreter::Bytecodes::IsJump(bytecode)) return; - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); Node* tail_call_node = m.Jump(m.IntPtrConstant(jump_offset)); Matcher<Node*> next_bytecode_offset_matcher = IsIntPtrAdd( @@ -372,10 +378,7 @@ TARGET_TEST_F(InterpreterAssemblerTest, Jump) { IsIntPtrConstant(jump_offset)); Matcher<Node*> target_bytecode_matcher = m.IsLoad(MachineType::Uint8(), _, next_bytecode_offset_matcher); - if (kPointerSize == 8) { - target_bytecode_matcher = - IsChangeUint32ToUint64(target_bytecode_matcher); - } + target_bytecode_matcher = IsChangeUint32ToWord(target_bytecode_matcher); Matcher<Node*> code_target_matcher = m.IsLoad(MachineType::Pointer(), IsParameter(InterpreterDispatchDescriptor::kDispatchTable), @@ -398,7 +401,8 @@ TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) { OperandScale::kSingle, OperandScale::kDouble, OperandScale::kQuadruple}; TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { TRACED_FOREACH(interpreter::OperandScale, operand_scale, kOperandScales) { - InterpreterAssemblerForTest m(this, bytecode, operand_scale); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode, operand_scale); int number_of_operands = interpreter::Bytecodes::NumberOfOperands(bytecode); for (int i = 0; i < number_of_operands; i++) { @@ -419,7 +423,8 @@ TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) { break; case interpreter::OperandType::kIdx: EXPECT_THAT(m.BytecodeOperandIdx(i), - m.IsUnsignedOperand(offset, operand_size)); + IsChangeUint32ToWord( + m.IsUnsignedOperand(offset, operand_size))); break; case interpreter::OperandType::kUImm: EXPECT_THAT(m.BytecodeOperandUImm(i), @@ -436,8 +441,9 @@ TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) { case interpreter::OperandType::kRegOutPair: case interpreter::OperandType::kRegOutTriple: case interpreter::OperandType::kRegPair: - EXPECT_THAT(m.BytecodeOperandReg(i), - m.IsSignedOperand(offset, operand_size)); + EXPECT_THAT( + m.BytecodeOperandReg(i), + IsChangeInt32ToIntPtr(m.IsSignedOperand(offset, operand_size))); break; case interpreter::OperandType::kRuntimeId: EXPECT_THAT(m.BytecodeOperandRuntimeId(i), @@ -463,7 +469,8 @@ TARGET_TEST_F(InterpreterAssemblerTest, GetSetAccumulator) { continue; } - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); // Should be incoming accumulator if not set. EXPECT_THAT(m.GetAccumulator(), IsParameter(InterpreterDispatchDescriptor::kAccumulator)); @@ -485,7 +492,8 @@ TARGET_TEST_F(InterpreterAssemblerTest, GetSetAccumulator) { TARGET_TEST_F(InterpreterAssemblerTest, GetContext) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); EXPECT_THAT( m.GetContext(), m.IsLoad(MachineType::AnyTagged(), IsLoadParentFramePointer(), @@ -496,7 +504,8 @@ TARGET_TEST_F(InterpreterAssemblerTest, GetContext) { TARGET_TEST_F(InterpreterAssemblerTest, RegisterLocation) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); Node* reg_index_node = m.IntPtrConstant(44); Node* reg_location_node = m.RegisterLocation(reg_index_node); EXPECT_THAT(reg_location_node, @@ -508,7 +517,8 @@ TARGET_TEST_F(InterpreterAssemblerTest, RegisterLocation) { TARGET_TEST_F(InterpreterAssemblerTest, LoadRegister) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); Node* reg_index_node = m.IntPtrConstant(44); Node* load_reg_node = m.LoadRegister(reg_index_node); EXPECT_THAT(load_reg_node, @@ -520,7 +530,8 @@ TARGET_TEST_F(InterpreterAssemblerTest, LoadRegister) { TARGET_TEST_F(InterpreterAssemblerTest, StoreRegister) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); Node* store_value = m.Int32Constant(0xdeadbeef); Node* reg_index_node = m.IntPtrConstant(44); Node* store_reg_node = m.StoreRegister(store_value, reg_index_node); @@ -536,7 +547,8 @@ TARGET_TEST_F(InterpreterAssemblerTest, StoreRegister) { TARGET_TEST_F(InterpreterAssemblerTest, SmiTag) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); Node* value = m.Int32Constant(44); EXPECT_THAT(m.SmiTag(value), IsBitcastWordToTaggedSigned(IsIntPtrConstant( static_cast<intptr_t>(44) @@ -549,8 +561,9 @@ TARGET_TEST_F(InterpreterAssemblerTest, SmiTag) { TARGET_TEST_F(InterpreterAssemblerTest, IntPtrAdd) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); - Node* a = m.Int32Constant(0); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); + Node* a = m.Parameter(0); Node* b = m.Int32Constant(1); Node* add = m.IntPtrAdd(a, b); EXPECT_THAT(add, IsIntPtrAdd(a, b)); @@ -559,8 +572,9 @@ TARGET_TEST_F(InterpreterAssemblerTest, IntPtrAdd) { TARGET_TEST_F(InterpreterAssemblerTest, IntPtrSub) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); - Node* a = m.Int32Constant(0); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); + Node* a = m.Parameter(0); Node* b = m.Int32Constant(1); Node* add = m.IntPtrSub(a, b); EXPECT_THAT(add, IsIntPtrSub(a, b)); @@ -569,7 +583,8 @@ TARGET_TEST_F(InterpreterAssemblerTest, IntPtrSub) { TARGET_TEST_F(InterpreterAssemblerTest, WordShl) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); Node* a = m.IntPtrConstant(0); Node* add = m.WordShl(a, 10); EXPECT_THAT(add, IsWordShl(a, IsIntPtrConstant(10))); @@ -578,25 +593,44 @@ TARGET_TEST_F(InterpreterAssemblerTest, WordShl) { TARGET_TEST_F(InterpreterAssemblerTest, LoadConstantPoolEntry) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); - Node* index = m.IntPtrConstant(2); - Node* load_constant = m.LoadConstantPoolEntry(index); - Matcher<Node*> constant_pool_matcher = m.IsLoad( - MachineType::AnyTagged(), - IsParameter(InterpreterDispatchDescriptor::kBytecodeArray), - IsIntPtrConstant(BytecodeArray::kConstantPoolOffset - kHeapObjectTag)); - EXPECT_THAT( - load_constant, - m.IsLoad(MachineType::AnyTagged(), constant_pool_matcher, - IsIntPtrAdd( - IsIntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag), - IsWordShl(index, IsIntPtrConstant(kPointerSizeLog2))))); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); + { + Node* index = m.IntPtrConstant(2); + Node* load_constant = m.LoadConstantPoolEntry(index); + Matcher<Node*> constant_pool_matcher = + m.IsLoad(MachineType::AnyTagged(), + IsParameter(InterpreterDispatchDescriptor::kBytecodeArray), + IsIntPtrConstant(BytecodeArray::kConstantPoolOffset - + kHeapObjectTag)); + EXPECT_THAT(load_constant, + m.IsLoad(MachineType::AnyTagged(), constant_pool_matcher, + IsIntPtrConstant(FixedArray::OffsetOfElementAt(2) - + kHeapObjectTag))); + } + { + Node* index = m.Parameter(2); + Node* load_constant = m.LoadConstantPoolEntry(index); + Matcher<Node*> constant_pool_matcher = + m.IsLoad(MachineType::AnyTagged(), + IsParameter(InterpreterDispatchDescriptor::kBytecodeArray), + IsIntPtrConstant(BytecodeArray::kConstantPoolOffset - + kHeapObjectTag)); + EXPECT_THAT( + load_constant, + m.IsLoad( + MachineType::AnyTagged(), constant_pool_matcher, + IsIntPtrAdd( + IsIntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag), + IsWordShl(index, IsIntPtrConstant(kPointerSizeLog2))))); + } } } TARGET_TEST_F(InterpreterAssemblerTest, LoadObjectField) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); Node* object = m.IntPtrConstant(0xdeadbeef); int offset = 16; Node* load_field = m.LoadObjectField(object, offset); @@ -608,7 +642,8 @@ TARGET_TEST_F(InterpreterAssemblerTest, LoadObjectField) { TARGET_TEST_F(InterpreterAssemblerTest, CallRuntime2) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); Node* arg1 = m.Int32Constant(2); Node* arg2 = m.Int32Constant(3); Node* context = m.Int32Constant(4); @@ -622,19 +657,21 @@ TARGET_TEST_F(InterpreterAssemblerTest, CallRuntime) { const int kResultSizes[] = {1, 2}; TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { TRACED_FOREACH(int, result_size, kResultSizes) { - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); Callable builtin = CodeFactory::InterpreterCEntry(isolate(), result_size); Node* function_id = m.Int32Constant(0); - Node* first_arg = m.Int32Constant(1); + Node* first_arg = m.IntPtrConstant(1); Node* arg_count = m.Int32Constant(2); - Node* context = m.Int32Constant(4); + Node* context = m.IntPtrConstant(4); Matcher<Node*> function_table = IsExternalConstant( ExternalReference::runtime_function_table_address(isolate())); Matcher<Node*> function = IsIntPtrAdd( function_table, - IsInt32Mul(function_id, IsInt32Constant(sizeof(Runtime::Function)))); + IsChangeUint32ToWord(IsInt32Mul( + function_id, IsInt32Constant(sizeof(Runtime::Function))))); Matcher<Node*> function_entry = m.IsLoad(MachineType::Pointer(), function, IsIntPtrConstant(offsetof(Runtime::Function, entry))); @@ -653,13 +690,14 @@ TARGET_TEST_F(InterpreterAssemblerTest, CallJS) { TailCallMode::kAllow}; TRACED_FOREACH(TailCallMode, tail_call_mode, tail_call_modes) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); Callable builtin = CodeFactory::InterpreterPushArgsAndCall(isolate(), tail_call_mode); - Node* function = m.Int32Constant(0); - Node* first_arg = m.Int32Constant(1); + Node* function = m.IntPtrConstant(0); + Node* first_arg = m.IntPtrConstant(1); Node* arg_count = m.Int32Constant(2); - Node* context = m.Int32Constant(3); + Node* context = m.IntPtrConstant(3); Node* call_js = m.CallJS(function, context, first_arg, arg_count, tail_call_mode); EXPECT_THAT(call_js, IsCall(_, IsHeapConstant(builtin.code()), arg_count, @@ -670,7 +708,8 @@ TARGET_TEST_F(InterpreterAssemblerTest, CallJS) { TARGET_TEST_F(InterpreterAssemblerTest, LoadTypeFeedbackVector) { TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { - InterpreterAssemblerForTest m(this, bytecode); + InterpreterAssemblerTestState state(this, bytecode); + InterpreterAssemblerForTest m(&state, bytecode); Node* feedback_vector = m.LoadTypeFeedbackVector(); Matcher<Node*> load_function_matcher = |