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

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

Issue 1294133004: [Interpreter] Pass context to interpreter bytecode handlers and add LoadConstextSlot (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 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
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 "src/unique.h" 9 #include "src/unique.h"
10 #include "test/unittests/compiler/compiler-test-utils.h" 10 #include "test/unittests/compiler/compiler-test-utils.h"
11 #include "test/unittests/compiler/node-test-utils.h" 11 #include "test/unittests/compiler/node-test-utils.h"
12 12
13 using ::testing::_; 13 using ::testing::_;
14 14
15 namespace v8 { 15 namespace v8 {
16 namespace internal { 16 namespace internal {
17 namespace compiler { 17 namespace compiler {
18 18
19 const interpreter::Bytecode kBytecodes[] = { 19 const interpreter::Bytecode kBytecodes[] = {
20 #define DEFINE_BYTECODE(Name, ...) interpreter::Bytecode::k##Name, 20 #define DEFINE_BYTECODE(Name, ...) interpreter::Bytecode::k##Name,
21 BYTECODE_LIST(DEFINE_BYTECODE) 21 BYTECODE_LIST(DEFINE_BYTECODE)
22 #undef DEFINE_BYTECODE 22 #undef DEFINE_BYTECODE
23 }; 23 };
24 24
25 25
26 Matcher<Node*> IsIntPtrConstant(const intptr_t value) {
27 return kPointerSize == 8 ? IsInt64Constant(static_cast<int64_t>(value))
28 : IsInt32Constant(static_cast<int32_t>(value));
29 }
30
31
26 Matcher<Node*> IsIntPtrAdd(const Matcher<Node*>& lhs_matcher, 32 Matcher<Node*> IsIntPtrAdd(const Matcher<Node*>& lhs_matcher,
27 const Matcher<Node*>& rhs_matcher) { 33 const Matcher<Node*>& rhs_matcher) {
28 return kPointerSize == 8 ? IsInt64Add(lhs_matcher, rhs_matcher) 34 return kPointerSize == 8 ? IsInt64Add(lhs_matcher, rhs_matcher)
29 : IsInt32Add(lhs_matcher, rhs_matcher); 35 : IsInt32Add(lhs_matcher, rhs_matcher);
30 } 36 }
31 37
32 38
33 Matcher<Node*> IsIntPtrSub(const Matcher<Node*>& lhs_matcher, 39 Matcher<Node*> IsIntPtrSub(const Matcher<Node*>& lhs_matcher,
34 const Matcher<Node*>& rhs_matcher) { 40 const Matcher<Node*>& rhs_matcher) {
35 return kPointerSize == 8 ? IsInt64Sub(lhs_matcher, rhs_matcher) 41 return kPointerSize == 8 ? IsInt64Sub(lhs_matcher, rhs_matcher)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 EXPECT_EQ(CallDescriptor::kCallCodeObject, m.call_descriptor()->kind()); 129 EXPECT_EQ(CallDescriptor::kCallCodeObject, m.call_descriptor()->kind());
124 EXPECT_TRUE(m.call_descriptor()->flags() & CallDescriptor::kCanUseRoots); 130 EXPECT_TRUE(m.call_descriptor()->flags() & CallDescriptor::kCanUseRoots);
125 EXPECT_THAT( 131 EXPECT_THAT(
126 tail_call_node, 132 tail_call_node,
127 IsTailCall(m.call_descriptor(), code_target_matcher, 133 IsTailCall(m.call_descriptor(), code_target_matcher,
128 IsParameter(Linkage::kInterpreterAccumulatorParameter), 134 IsParameter(Linkage::kInterpreterAccumulatorParameter),
129 IsParameter(Linkage::kInterpreterRegisterFileParameter), 135 IsParameter(Linkage::kInterpreterRegisterFileParameter),
130 next_bytecode_offset_matcher, 136 next_bytecode_offset_matcher,
131 IsParameter(Linkage::kInterpreterBytecodeArrayParameter), 137 IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
132 IsParameter(Linkage::kInterpreterDispatchTableParameter), 138 IsParameter(Linkage::kInterpreterDispatchTableParameter),
139 IsParameter(Linkage::kInterpreterContextParameter),
133 graph->start(), graph->start())); 140 graph->start(), graph->start()));
134 } 141 }
135 } 142 }
136 143
137 144
138 TARGET_TEST_F(InterpreterAssemblerTest, Return) { 145 TARGET_TEST_F(InterpreterAssemblerTest, Return) {
139 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { 146 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
140 InterpreterAssemblerForTest m(this, bytecode); 147 InterpreterAssemblerForTest m(this, bytecode);
141 m.Return(); 148 m.Return();
142 Graph* graph = m.GetCompletedGraph(); 149 Graph* graph = m.GetCompletedGraph();
143 150
144 Node* end = graph->end(); 151 Node* end = graph->end();
145 EXPECT_EQ(1, end->InputCount()); 152 EXPECT_EQ(1, end->InputCount());
146 Node* tail_call_node = end->InputAt(0); 153 Node* tail_call_node = end->InputAt(0);
147 154
148 EXPECT_EQ(CallDescriptor::kCallCodeObject, m.call_descriptor()->kind()); 155 EXPECT_EQ(CallDescriptor::kCallCodeObject, m.call_descriptor()->kind());
149 EXPECT_TRUE(m.call_descriptor()->flags() & CallDescriptor::kCanUseRoots); 156 EXPECT_TRUE(m.call_descriptor()->flags() & CallDescriptor::kCanUseRoots);
150 Matcher<Unique<HeapObject>> exit_trampoline( 157 Matcher<Unique<HeapObject>> exit_trampoline(
151 Unique<HeapObject>::CreateImmovable( 158 Unique<HeapObject>::CreateImmovable(
152 isolate()->builtins()->InterpreterExitTrampoline())); 159 isolate()->builtins()->InterpreterExitTrampoline()));
153 EXPECT_THAT( 160 EXPECT_THAT(
154 tail_call_node, 161 tail_call_node,
155 IsTailCall(m.call_descriptor(), IsHeapConstant(exit_trampoline), 162 IsTailCall(m.call_descriptor(), IsHeapConstant(exit_trampoline),
156 IsParameter(Linkage::kInterpreterAccumulatorParameter), 163 IsParameter(Linkage::kInterpreterAccumulatorParameter),
157 IsParameter(Linkage::kInterpreterRegisterFileParameter), 164 IsParameter(Linkage::kInterpreterRegisterFileParameter),
158 IsParameter(Linkage::kInterpreterBytecodeOffsetParameter), 165 IsParameter(Linkage::kInterpreterBytecodeOffsetParameter),
159 IsParameter(Linkage::kInterpreterBytecodeArrayParameter), 166 IsParameter(Linkage::kInterpreterBytecodeArrayParameter),
160 IsParameter(Linkage::kInterpreterDispatchTableParameter), 167 IsParameter(Linkage::kInterpreterDispatchTableParameter),
168 IsParameter(Linkage::kInterpreterContextParameter),
161 graph->start(), graph->start())); 169 graph->start(), graph->start()));
162 } 170 }
163 } 171 }
164 172
165 173
166 TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) { 174 TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
167 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { 175 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
168 InterpreterAssemblerForTest m(this, bytecode); 176 InterpreterAssemblerForTest m(this, bytecode);
169 int number_of_operands = interpreter::Bytecodes::NumberOfOperands(bytecode); 177 int number_of_operands = interpreter::Bytecodes::NumberOfOperands(bytecode);
170 for (int i = 0; i < number_of_operands; i++) { 178 for (int i = 0; i < number_of_operands; i++) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } 224 }
217 225
218 226
219 TARGET_TEST_F(InterpreterAssemblerTest, LoadRegister) { 227 TARGET_TEST_F(InterpreterAssemblerTest, LoadRegister) {
220 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { 228 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
221 InterpreterAssemblerForTest m(this, bytecode); 229 InterpreterAssemblerForTest m(this, bytecode);
222 Node* reg_index_node = m.Int32Constant(44); 230 Node* reg_index_node = m.Int32Constant(44);
223 Node* load_reg_node = m.LoadRegister(reg_index_node); 231 Node* load_reg_node = m.LoadRegister(reg_index_node);
224 EXPECT_THAT( 232 EXPECT_THAT(
225 load_reg_node, 233 load_reg_node,
226 m.IsLoad(kMachPtr, 234 m.IsLoad(kMachAnyTagged,
227 IsParameter(Linkage::kInterpreterRegisterFileParameter), 235 IsParameter(Linkage::kInterpreterRegisterFileParameter),
228 IsWordShl(reg_index_node, IsInt32Constant(kPointerSizeLog2)))); 236 IsWordShl(reg_index_node, IsInt32Constant(kPointerSizeLog2))));
229 } 237 }
230 } 238 }
231 239
232 240
233 TARGET_TEST_F(InterpreterAssemblerTest, StoreRegister) { 241 TARGET_TEST_F(InterpreterAssemblerTest, StoreRegister) {
234 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { 242 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
235 InterpreterAssemblerForTest m(this, bytecode); 243 InterpreterAssemblerForTest m(this, bytecode);
236 Node* store_value = m.Int32Constant(0xdeadbeef); 244 Node* store_value = m.Int32Constant(0xdeadbeef);
237 Node* reg_index_node = m.Int32Constant(44); 245 Node* reg_index_node = m.Int32Constant(44);
238 Node* store_reg_node = m.StoreRegister(store_value, reg_index_node); 246 Node* store_reg_node = m.StoreRegister(store_value, reg_index_node);
239 EXPECT_THAT( 247 EXPECT_THAT(
240 store_reg_node, 248 store_reg_node,
241 m.IsStore(StoreRepresentation(kMachPtr, kNoWriteBarrier), 249 m.IsStore(StoreRepresentation(kMachAnyTagged, kNoWriteBarrier),
242 IsParameter(Linkage::kInterpreterRegisterFileParameter), 250 IsParameter(Linkage::kInterpreterRegisterFileParameter),
243 IsWordShl(reg_index_node, IsInt32Constant(kPointerSizeLog2)), 251 IsWordShl(reg_index_node, IsInt32Constant(kPointerSizeLog2)),
244 store_value)); 252 store_value));
245 } 253 }
246 } 254 }
247 255
248 256
249 TARGET_TEST_F(InterpreterAssemblerTest, SmiTag) { 257 TARGET_TEST_F(InterpreterAssemblerTest, SmiTag) {
250 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) { 258 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
251 InterpreterAssemblerForTest m(this, bytecode); 259 InterpreterAssemblerForTest m(this, bytecode);
252 Node* value = m.Int32Constant(44); 260 Node* value = m.Int32Constant(44);
253 EXPECT_THAT(m.SmiTag(value), 261 EXPECT_THAT(m.SmiTag(value),
254 IsWordShl(value, IsInt32Constant(kSmiShiftSize + kSmiTagSize))); 262 IsWordShl(value, IsInt32Constant(kSmiShiftSize + kSmiTagSize)));
255 EXPECT_THAT(m.SmiUntag(value), 263 EXPECT_THAT(m.SmiUntag(value),
256 IsWordSar(value, IsInt32Constant(kSmiShiftSize + kSmiTagSize))); 264 IsWordSar(value, IsInt32Constant(kSmiShiftSize + kSmiTagSize)));
257 } 265 }
258 } 266 }
259 267
268
269 TARGET_TEST_F(InterpreterAssemblerTest, LoadContextSlot) {
270 TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
271 InterpreterAssemblerForTest m(this, bytecode);
272 Node* load_context = m.LoadContextSlot(22);
273 EXPECT_THAT(load_context,
274 m.IsLoad(kMachAnyTagged,
275 IsParameter(Linkage::kInterpreterContextParameter),
276 IsIntPtrConstant(Context::SlotOffset(22))));
277 }
278 }
279
260 } // namespace compiler 280 } // namespace compiler
261 } // namespace internal 281 } // namespace internal
262 } // namespace v8 282 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698