Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: test/unittests/compiler/interpreter-assembler-unittest.cc

Issue 1239793002: [interpreter] Add basic framework for bytecode handler code generation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix GN for realz Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "test/unittests/compiler/interpreter-assembler-unittest.h"
6
7 #include "src/compiler/graph.h"
8 #include "src/compiler/node.h"
9 #include "test/unittests/compiler/compiler-test-utils.h"
10 #include "test/unittests/compiler/node-test-utils.h"
11
12 namespace v8 {
13 namespace internal {
14 namespace compiler {
15
16 const interpreter::Bytecode kBytecodes[] = {
17 #define DEFINE_BYTECODE(Name, _) interpreter::Bytecode::k##Name,
18 BYTECODE_LIST(DEFINE_BYTECODE)
19 #undef DEFINE_BYTECODE
20 };
21
22
23 Graph*
24 InterpreterAssemblerTest::InterpreterAssemblerForTest::GetCompletedGraph() {
25 End();
26 return graph();
27 }
28
29
30 Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoad(
31 const Matcher<LoadRepresentation>& rep_matcher,
32 const Matcher<Node*>& base_matcher, const Matcher<Node*>& index_matcher) {
33 return ::i::compiler::IsLoad(rep_matcher, base_matcher, index_matcher,
34 graph()->start(), graph()->start());
35 }
36
37
38 Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsStore(
39 const Matcher<StoreRepresentation>& rep_matcher,
40 const Matcher<Node*>& base_matcher, const Matcher<Node*>& index_matcher,
41 const Matcher<Node*>& value_matcher) {
42 return ::i::compiler::IsStore(rep_matcher, base_matcher, index_matcher,
43 value_matcher, graph()->start(),
44 graph()->start());
45 }
46
47
48 Matcher<Node*> IsIntPtrAdd(const Matcher<Node*>& lhs_matcher,
49 const Matcher<Node*>& rhs_matcher) {
50 return kPointerSize == 8 ? IsInt64Add(lhs_matcher, rhs_matcher)
51 : IsInt32Add(lhs_matcher, rhs_matcher);
52 }
53
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) {
65 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
66 InterpreterAssemblerForTest m(this, bytecode);
67 m.Dispatch();
68 Graph* graph = m.GetCompletedGraph();
69
70 Node* end = graph->end();
71 EXPECT_EQ(1, end->InputCount());
72 Node* tail_call_node = end->InputAt(0);
73
74 Matcher<Node*> next_bytecode_matcher =
75 IsIntPtrAdd(IsParameter(Linkage::kInterpreterBytecodeParameter),
76 IsInt32Constant(interpreter::Bytecodes::Size(bytecode)));
77 Matcher<Node*> target_bytecode_matcher =
78 m.IsLoad(kMachUint8, next_bytecode_matcher, IsIntPtrConstant(0));
79 Matcher<Node*> code_target_matcher = m.IsLoad(
80 kMachPtr, IsParameter(Linkage::kInterpreterDispatchTableParameter),
81 IsWord32Shl(target_bytecode_matcher,
82 IsInt32Constant(kPointerSizeLog2)));
83
84 EXPECT_EQ(CallDescriptor::kInterpreterDispatch,
85 m.call_descriptor()->kind());
86 EXPECT_THAT(
87 tail_call_node,
88 IsTailCall(m.call_descriptor(), code_target_matcher,
89 next_bytecode_matcher,
90 IsParameter(Linkage::kInterpreterDispatchTableParameter),
91 graph->start(), graph->start()));
92 }
93 }
94
95
96 TARGET_TEST_F(InterpreterAssemblerTest, BytecodeArg) {
97 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
98 InterpreterAssemblerForTest m(this, bytecode);
99 int number_of_args = interpreter::Bytecodes::NumberOfArguments(bytecode);
100 for (int i = 0; i < number_of_args; i++) {
101 Node* load_arg_node = m.BytecodeArg(i);
102 EXPECT_THAT(load_arg_node,
103 m.IsLoad(kMachUint8,
104 IsParameter(Linkage::kInterpreterBytecodeParameter),
105 IsInt32Constant(1 + i)));
106 }
107 }
108 }
109
110
111 TARGET_TEST_F(InterpreterAssemblerTest, LoadRegisterFixed) {
112 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
113 InterpreterAssemblerForTest m(this, bytecode);
114 for (int i = 0; i < m.kMaxRegisterIndex; i++) {
115 Node* load_reg_node = m.LoadRegister(i);
116 EXPECT_THAT(load_reg_node,
117 m.IsLoad(kMachPtr, IsLoadFramePointer(),
118 IsInt32Constant(m.kFirstRegisterOffsetFromFp -
119 (i << kPointerSizeLog2))));
120 }
121 }
122 }
123
124
125 TARGET_TEST_F(InterpreterAssemblerTest, LoadRegister) {
126 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
127 InterpreterAssemblerForTest m(this, bytecode);
128 Node* reg_index_node = m.Int32Constant(44);
129 Node* load_reg_node = m.LoadRegister(reg_index_node);
130 EXPECT_THAT(
131 load_reg_node,
132 m.IsLoad(kMachPtr, IsLoadFramePointer(),
133 IsInt32Sub(IsInt32Constant(m.kFirstRegisterOffsetFromFp),
134 IsWord32Shl(reg_index_node,
135 IsInt32Constant(kPointerSizeLog2)))));
136 }
137 }
138
139
140 TARGET_TEST_F(InterpreterAssemblerTest, StoreRegisterFixed) {
141 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
142 InterpreterAssemblerForTest m(this, bytecode);
143 Node* store_value = m.Int32Constant(0xdeadbeef);
144 for (int i = 0; i < m.kMaxRegisterIndex; i++) {
145 Node* store_reg_node = m.StoreRegister(store_value, i);
146 EXPECT_THAT(store_reg_node,
147 m.IsStore(StoreRepresentation(kMachPtr, kNoWriteBarrier),
148 IsLoadFramePointer(),
149 IsInt32Constant(m.kFirstRegisterOffsetFromFp -
150 (i << kPointerSizeLog2)),
151 store_value));
152 }
153 }
154 }
155
156
157 TARGET_TEST_F(InterpreterAssemblerTest, StoreRegister) {
158 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
159 InterpreterAssemblerForTest m(this, bytecode);
160 Node* store_value = m.Int32Constant(0xdeadbeef);
161 Node* reg_index_node = m.Int32Constant(44);
162 Node* store_reg_node = m.StoreRegister(store_value, reg_index_node);
163 EXPECT_THAT(
164 store_reg_node,
165 m.IsStore(StoreRepresentation(kMachPtr, kNoWriteBarrier),
166 IsLoadFramePointer(),
167 IsInt32Sub(IsInt32Constant(m.kFirstRegisterOffsetFromFp),
168 IsWord32Shl(reg_index_node,
169 IsInt32Constant(kPointerSizeLog2))),
170 store_value));
171 }
172 }
173
174 } // namespace compiler
175 } // namespace internal
176 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler/interpreter-assembler-unittest.h ('k') | test/unittests/compiler/node-test-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698