| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "test/unittests/compiler/interpreter-assembler-unittest.h" | 5 #include "test/unittests/compiler/interpreter-assembler-unittest.h" |
| 6 | 6 |
| 7 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
| 8 #include "src/compiler/node.h" | 8 #include "src/compiler/node.h" |
| 9 #include "test/unittests/compiler/compiler-test-utils.h" | 9 #include "test/unittests/compiler/compiler-test-utils.h" |
| 10 #include "test/unittests/compiler/node-test-utils.h" | 10 #include "test/unittests/compiler/node-test-utils.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 | 47 |
| 48 Matcher<Node*> IsIntPtrAdd(const Matcher<Node*>& lhs_matcher, | 48 Matcher<Node*> IsIntPtrAdd(const Matcher<Node*>& lhs_matcher, |
| 49 const Matcher<Node*>& rhs_matcher) { | 49 const Matcher<Node*>& rhs_matcher) { |
| 50 return kPointerSize == 8 ? IsInt64Add(lhs_matcher, rhs_matcher) | 50 return kPointerSize == 8 ? IsInt64Add(lhs_matcher, rhs_matcher) |
| 51 : IsInt32Add(lhs_matcher, rhs_matcher); | 51 : IsInt32Add(lhs_matcher, rhs_matcher); |
| 52 } | 52 } |
| 53 | 53 |
| 54 | 54 |
| 55 Matcher<Node*> IsIntPtrConstant(intptr_t value) { | |
| 56 #ifdef V8_TARGET_ARCH_64_BIT | |
| 57 return IsInt64Constant(value); | |
| 58 #else | |
| 59 return IsInt32Constant(value); | |
| 60 #endif | |
| 61 } | |
| 62 | |
| 63 | |
| 64 TARGET_TEST_F(InterpreterAssemblerTest, Dispatch) { | 55 TARGET_TEST_F(InterpreterAssemblerTest, Dispatch) { |
| 65 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { | 56 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { |
| 66 InterpreterAssemblerForTest m(this, bytecode); | 57 InterpreterAssemblerForTest m(this, bytecode); |
| 67 m.Dispatch(); | 58 m.Dispatch(); |
| 68 Graph* graph = m.GetCompletedGraph(); | 59 Graph* graph = m.GetCompletedGraph(); |
| 69 | 60 |
| 70 Node* end = graph->end(); | 61 Node* end = graph->end(); |
| 71 EXPECT_EQ(1, end->InputCount()); | 62 EXPECT_EQ(1, end->InputCount()); |
| 72 Node* tail_call_node = end->InputAt(0); | 63 Node* tail_call_node = end->InputAt(0); |
| 73 | 64 |
| 74 Matcher<Node*> next_bytecode_matcher = | 65 Matcher<Node*> next_bytecode_offset_matcher = |
| 75 IsIntPtrAdd(IsParameter(Linkage::kInterpreterBytecodeParameter), | 66 IsIntPtrAdd(IsParameter(Linkage::kInterpreterBytecodeOffsetParameter), |
| 76 IsInt32Constant(interpreter::Bytecodes::Size(bytecode))); | 67 IsInt32Constant(interpreter::Bytecodes::Size(bytecode))); |
| 77 Matcher<Node*> target_bytecode_matcher = | 68 Matcher<Node*> target_bytecode_matcher = m.IsLoad( |
| 78 m.IsLoad(kMachUint8, next_bytecode_matcher, IsIntPtrConstant(0)); | 69 kMachUint8, IsParameter(Linkage::kInterpreterBytecodeArrayParameter), |
| 70 next_bytecode_offset_matcher); |
| 79 Matcher<Node*> code_target_matcher = m.IsLoad( | 71 Matcher<Node*> code_target_matcher = m.IsLoad( |
| 80 kMachPtr, IsParameter(Linkage::kInterpreterDispatchTableParameter), | 72 kMachPtr, IsParameter(Linkage::kInterpreterDispatchTableParameter), |
| 81 IsWord32Shl(target_bytecode_matcher, | 73 IsWord32Shl(target_bytecode_matcher, |
| 82 IsInt32Constant(kPointerSizeLog2))); | 74 IsInt32Constant(kPointerSizeLog2))); |
| 83 | 75 |
| 84 EXPECT_EQ(CallDescriptor::kInterpreterDispatch, | 76 EXPECT_EQ(CallDescriptor::kInterpreterDispatch, |
| 85 m.call_descriptor()->kind()); | 77 m.call_descriptor()->kind()); |
| 86 EXPECT_THAT( | 78 EXPECT_THAT( |
| 87 tail_call_node, | 79 tail_call_node, |
| 88 IsTailCall(m.call_descriptor(), code_target_matcher, | 80 IsTailCall(m.call_descriptor(), code_target_matcher, |
| 89 next_bytecode_matcher, | 81 next_bytecode_offset_matcher, |
| 82 IsParameter(Linkage::kInterpreterBytecodeArrayParameter), |
| 90 IsParameter(Linkage::kInterpreterDispatchTableParameter), | 83 IsParameter(Linkage::kInterpreterDispatchTableParameter), |
| 91 graph->start(), graph->start())); | 84 graph->start(), graph->start())); |
| 92 } | 85 } |
| 93 } | 86 } |
| 94 | 87 |
| 95 | 88 |
| 96 TARGET_TEST_F(InterpreterAssemblerTest, BytecodeArg) { | 89 TARGET_TEST_F(InterpreterAssemblerTest, BytecodeArg) { |
| 97 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { | 90 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { |
| 98 InterpreterAssemblerForTest m(this, bytecode); | 91 InterpreterAssemblerForTest m(this, bytecode); |
| 99 int number_of_args = interpreter::Bytecodes::NumberOfArguments(bytecode); | 92 int number_of_args = interpreter::Bytecodes::NumberOfArguments(bytecode); |
| 100 for (int i = 0; i < number_of_args; i++) { | 93 for (int i = 0; i < number_of_args; i++) { |
| 101 Node* load_arg_node = m.BytecodeArg(i); | 94 Node* load_arg_node = m.BytecodeArg(i); |
| 102 EXPECT_THAT(load_arg_node, | 95 EXPECT_THAT( |
| 103 m.IsLoad(kMachUint8, | 96 load_arg_node, |
| 104 IsParameter(Linkage::kInterpreterBytecodeParameter), | 97 m.IsLoad( |
| 105 IsInt32Constant(1 + i))); | 98 kMachUint8, |
| 99 IsParameter(Linkage::kInterpreterBytecodeArrayParameter), |
| 100 IsIntPtrAdd( |
| 101 IsParameter(Linkage::kInterpreterBytecodeOffsetParameter), |
| 102 IsInt32Constant(1 + i)))); |
| 106 } | 103 } |
| 107 } | 104 } |
| 108 } | 105 } |
| 109 | 106 |
| 110 | 107 |
| 111 TARGET_TEST_F(InterpreterAssemblerTest, LoadRegisterFixed) { | 108 TARGET_TEST_F(InterpreterAssemblerTest, LoadRegisterFixed) { |
| 112 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { | 109 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { |
| 113 InterpreterAssemblerForTest m(this, bytecode); | 110 InterpreterAssemblerForTest m(this, bytecode); |
| 114 for (int i = 0; i < m.kMaxRegisterIndex; i++) { | 111 for (int i = 0; i < m.kMaxRegisterIndex; i++) { |
| 115 Node* load_reg_node = m.LoadRegister(i); | 112 Node* load_reg_node = m.LoadRegister(i); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 IsInt32Sub(IsInt32Constant(m.kFirstRegisterOffsetFromFp), | 164 IsInt32Sub(IsInt32Constant(m.kFirstRegisterOffsetFromFp), |
| 168 IsWord32Shl(reg_index_node, | 165 IsWord32Shl(reg_index_node, |
| 169 IsInt32Constant(kPointerSizeLog2))), | 166 IsInt32Constant(kPointerSizeLog2))), |
| 170 store_value)); | 167 store_value)); |
| 171 } | 168 } |
| 172 } | 169 } |
| 173 | 170 |
| 174 } // namespace compiler | 171 } // namespace compiler |
| 175 } // namespace internal | 172 } // namespace internal |
| 176 } // namespace v8 | 173 } // namespace v8 |
| OLD | NEW |