OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/instruction-selector-unittest.h" | 5 #include "test/unittests/compiler/instruction-selector-unittest.h" |
6 | 6 |
| 7 #include "src/compiler/graph-inl.h" |
7 #include "src/flags.h" | 8 #include "src/flags.h" |
8 #include "test/unittests/compiler/compiler-test-utils.h" | 9 #include "test/unittests/compiler/compiler-test-utils.h" |
9 | 10 |
10 namespace v8 { | 11 namespace v8 { |
11 namespace internal { | 12 namespace internal { |
12 namespace compiler { | 13 namespace compiler { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 typedef RawMachineAssembler::Label MLabel; | 17 typedef RawMachineAssembler::Label MLabel; |
(...skipping 10 matching lines...) Expand all Loading... |
27 InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build( | 28 InstructionSelectorTest::Stream InstructionSelectorTest::StreamBuilder::Build( |
28 InstructionSelector::Features features, | 29 InstructionSelector::Features features, |
29 InstructionSelectorTest::StreamBuilderMode mode) { | 30 InstructionSelectorTest::StreamBuilderMode mode) { |
30 Schedule* schedule = Export(); | 31 Schedule* schedule = Export(); |
31 if (FLAG_trace_turbo) { | 32 if (FLAG_trace_turbo) { |
32 OFStream out(stdout); | 33 OFStream out(stdout); |
33 out << "=== Schedule before instruction selection ===" << std::endl | 34 out << "=== Schedule before instruction selection ===" << std::endl |
34 << *schedule; | 35 << *schedule; |
35 } | 36 } |
36 EXPECT_NE(0, graph()->NodeCount()); | 37 EXPECT_NE(0, graph()->NodeCount()); |
| 38 int initial_node_count = graph()->NodeCount(); |
37 CompilationInfo info(test_->isolate(), test_->zone()); | 39 CompilationInfo info(test_->isolate(), test_->zone()); |
38 Linkage linkage(&info, call_descriptor()); | 40 Linkage linkage(&info, call_descriptor()); |
39 InstructionSequence sequence(&linkage, graph(), schedule); | 41 InstructionSequence sequence(&linkage, graph(), schedule); |
40 SourcePositionTable source_position_table(graph()); | 42 SourcePositionTable source_position_table(graph()); |
41 InstructionSelector selector(&sequence, &source_position_table, features); | 43 InstructionSelector selector(&sequence, &source_position_table, features); |
42 selector.SelectInstructions(); | 44 selector.SelectInstructions(); |
43 if (FLAG_trace_turbo) { | 45 if (FLAG_trace_turbo) { |
44 OFStream out(stdout); | 46 OFStream out(stdout); |
45 out << "=== Code sequence after instruction selection ===" << std::endl | 47 out << "=== Code sequence after instruction selection ===" << std::endl |
46 << sequence; | 48 << sequence; |
47 } | 49 } |
48 Stream s; | 50 Stream s; |
| 51 // Map virtual registers. |
| 52 { |
| 53 const int* node_map = sequence.GetNodeMapForTesting(); |
| 54 for (int i = 0; i < initial_node_count; ++i) { |
| 55 if (node_map[i] >= 0) { |
| 56 s.virtual_registers_.insert(std::make_pair(i, node_map[i])); |
| 57 } |
| 58 } |
| 59 } |
49 std::set<int> virtual_registers; | 60 std::set<int> virtual_registers; |
50 for (InstructionSequence::const_iterator i = sequence.begin(); | 61 for (InstructionSequence::const_iterator i = sequence.begin(); |
51 i != sequence.end(); ++i) { | 62 i != sequence.end(); ++i) { |
52 Instruction* instr = *i; | 63 Instruction* instr = *i; |
53 if (instr->opcode() < 0) continue; | 64 if (instr->opcode() < 0) continue; |
54 if (mode == kTargetInstructions) { | 65 if (mode == kTargetInstructions) { |
55 switch (instr->arch_opcode()) { | 66 switch (instr->arch_opcode()) { |
56 #define CASE(Name) \ | 67 #define CASE(Name) \ |
57 case k##Name: \ | 68 case k##Name: \ |
58 break; | 69 break; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 114 } |
104 } | 115 } |
105 for (int i = 0; i < sequence.GetFrameStateDescriptorCount(); i++) { | 116 for (int i = 0; i < sequence.GetFrameStateDescriptorCount(); i++) { |
106 s.deoptimization_entries_.push_back(sequence.GetFrameStateDescriptor( | 117 s.deoptimization_entries_.push_back(sequence.GetFrameStateDescriptor( |
107 InstructionSequence::StateId::FromInt(i))); | 118 InstructionSequence::StateId::FromInt(i))); |
108 } | 119 } |
109 return s; | 120 return s; |
110 } | 121 } |
111 | 122 |
112 | 123 |
| 124 int InstructionSelectorTest::Stream::ToVreg(const Node* node) const { |
| 125 VirtualRegisters::const_iterator i = virtual_registers_.find(node->id()); |
| 126 CHECK(i != virtual_registers_.end()); |
| 127 return i->second; |
| 128 } |
| 129 |
| 130 |
113 // ----------------------------------------------------------------------------- | 131 // ----------------------------------------------------------------------------- |
114 // Return. | 132 // Return. |
115 | 133 |
116 | 134 |
117 TARGET_TEST_F(InstructionSelectorTest, ReturnFloat32Constant) { | 135 TARGET_TEST_F(InstructionSelectorTest, ReturnFloat32Constant) { |
118 const float kValue = 4.2f; | 136 const float kValue = 4.2f; |
119 StreamBuilder m(this, kMachFloat32); | 137 StreamBuilder m(this, kMachFloat32); |
120 m.Return(m.Float32Constant(kValue)); | 138 m.Return(m.Float32Constant(kValue)); |
121 Stream s = m.Build(kAllInstructions); | 139 Stream s = m.Build(kAllInstructions); |
122 ASSERT_EQ(2U, s.size()); | 140 ASSERT_EQ(2U, s.size()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 191 |
174 // ----------------------------------------------------------------------------- | 192 // ----------------------------------------------------------------------------- |
175 // Parameters. | 193 // Parameters. |
176 | 194 |
177 | 195 |
178 TARGET_TEST_F(InstructionSelectorTest, DoubleParameter) { | 196 TARGET_TEST_F(InstructionSelectorTest, DoubleParameter) { |
179 StreamBuilder m(this, kMachFloat64, kMachFloat64); | 197 StreamBuilder m(this, kMachFloat64, kMachFloat64); |
180 Node* param = m.Parameter(0); | 198 Node* param = m.Parameter(0); |
181 m.Return(param); | 199 m.Return(param); |
182 Stream s = m.Build(kAllInstructions); | 200 Stream s = m.Build(kAllInstructions); |
183 EXPECT_TRUE(s.IsDouble(param->id())); | 201 EXPECT_TRUE(s.IsDouble(param)); |
184 } | 202 } |
185 | 203 |
186 | 204 |
187 TARGET_TEST_F(InstructionSelectorTest, ReferenceParameter) { | 205 TARGET_TEST_F(InstructionSelectorTest, ReferenceParameter) { |
188 StreamBuilder m(this, kMachAnyTagged, kMachAnyTagged); | 206 StreamBuilder m(this, kMachAnyTagged, kMachAnyTagged); |
189 Node* param = m.Parameter(0); | 207 Node* param = m.Parameter(0); |
190 m.Return(param); | 208 m.Return(param); |
191 Stream s = m.Build(kAllInstructions); | 209 Stream s = m.Build(kAllInstructions); |
192 EXPECT_TRUE(s.IsReference(param->id())); | 210 EXPECT_TRUE(s.IsReference(param)); |
193 } | 211 } |
194 | 212 |
195 | 213 |
196 // ----------------------------------------------------------------------------- | 214 // ----------------------------------------------------------------------------- |
197 // Finish. | 215 // Finish. |
198 | 216 |
199 | 217 |
200 TARGET_TEST_F(InstructionSelectorTest, Finish) { | 218 TARGET_TEST_F(InstructionSelectorTest, Finish) { |
201 StreamBuilder m(this, kMachAnyTagged, kMachAnyTagged); | 219 StreamBuilder m(this, kMachAnyTagged, kMachAnyTagged); |
202 Node* param = m.Parameter(0); | 220 Node* param = m.Parameter(0); |
203 Node* finish = m.NewNode(m.common()->Finish(1), param, m.graph()->start()); | 221 Node* finish = m.NewNode(m.common()->Finish(1), param, m.graph()->start()); |
204 m.Return(finish); | 222 m.Return(finish); |
205 Stream s = m.Build(kAllInstructions); | 223 Stream s = m.Build(kAllInstructions); |
206 ASSERT_EQ(3U, s.size()); | 224 ASSERT_EQ(3U, s.size()); |
207 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); | 225 EXPECT_EQ(kArchNop, s[0]->arch_opcode()); |
208 ASSERT_EQ(1U, s[0]->OutputCount()); | 226 ASSERT_EQ(1U, s[0]->OutputCount()); |
209 ASSERT_TRUE(s[0]->Output()->IsUnallocated()); | 227 ASSERT_TRUE(s[0]->Output()->IsUnallocated()); |
210 EXPECT_EQ(param->id(), s.ToVreg(s[0]->Output())); | 228 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->Output())); |
211 EXPECT_EQ(kArchNop, s[1]->arch_opcode()); | 229 EXPECT_EQ(kArchNop, s[1]->arch_opcode()); |
212 ASSERT_EQ(1U, s[1]->InputCount()); | 230 ASSERT_EQ(1U, s[1]->InputCount()); |
213 ASSERT_TRUE(s[1]->InputAt(0)->IsUnallocated()); | 231 ASSERT_TRUE(s[1]->InputAt(0)->IsUnallocated()); |
214 EXPECT_EQ(param->id(), s.ToVreg(s[1]->InputAt(0))); | 232 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[1]->InputAt(0))); |
215 ASSERT_EQ(1U, s[1]->OutputCount()); | 233 ASSERT_EQ(1U, s[1]->OutputCount()); |
216 ASSERT_TRUE(s[1]->Output()->IsUnallocated()); | 234 ASSERT_TRUE(s[1]->Output()->IsUnallocated()); |
217 EXPECT_TRUE(UnallocatedOperand::cast(s[1]->Output())->HasSameAsInputPolicy()); | 235 EXPECT_TRUE(UnallocatedOperand::cast(s[1]->Output())->HasSameAsInputPolicy()); |
218 EXPECT_EQ(finish->id(), s.ToVreg(s[1]->Output())); | 236 EXPECT_EQ(s.ToVreg(finish), s.ToVreg(s[1]->Output())); |
219 EXPECT_TRUE(s.IsReference(finish->id())); | 237 EXPECT_TRUE(s.IsReference(finish)); |
220 } | 238 } |
221 | 239 |
222 | 240 |
223 // ----------------------------------------------------------------------------- | 241 // ----------------------------------------------------------------------------- |
224 // Phi. | 242 // Phi. |
225 | 243 |
226 | 244 |
227 typedef InstructionSelectorTestWithParam<MachineType> | 245 typedef InstructionSelectorTestWithParam<MachineType> |
228 InstructionSelectorPhiTest; | 246 InstructionSelectorPhiTest; |
229 | 247 |
230 | 248 |
231 TARGET_TEST_P(InstructionSelectorPhiTest, Doubleness) { | 249 TARGET_TEST_P(InstructionSelectorPhiTest, Doubleness) { |
232 const MachineType type = GetParam(); | 250 const MachineType type = GetParam(); |
233 StreamBuilder m(this, type, type, type); | 251 StreamBuilder m(this, type, type, type); |
234 Node* param0 = m.Parameter(0); | 252 Node* param0 = m.Parameter(0); |
235 Node* param1 = m.Parameter(1); | 253 Node* param1 = m.Parameter(1); |
236 MLabel a, b, c; | 254 MLabel a, b, c; |
237 m.Branch(m.Int32Constant(0), &a, &b); | 255 m.Branch(m.Int32Constant(0), &a, &b); |
238 m.Bind(&a); | 256 m.Bind(&a); |
239 m.Goto(&c); | 257 m.Goto(&c); |
240 m.Bind(&b); | 258 m.Bind(&b); |
241 m.Goto(&c); | 259 m.Goto(&c); |
242 m.Bind(&c); | 260 m.Bind(&c); |
243 Node* phi = m.Phi(type, param0, param1); | 261 Node* phi = m.Phi(type, param0, param1); |
244 m.Return(phi); | 262 m.Return(phi); |
245 Stream s = m.Build(kAllInstructions); | 263 Stream s = m.Build(kAllInstructions); |
246 EXPECT_EQ(s.IsDouble(phi->id()), s.IsDouble(param0->id())); | 264 EXPECT_EQ(s.IsDouble(phi), s.IsDouble(param0)); |
247 EXPECT_EQ(s.IsDouble(phi->id()), s.IsDouble(param1->id())); | 265 EXPECT_EQ(s.IsDouble(phi), s.IsDouble(param1)); |
248 } | 266 } |
249 | 267 |
250 | 268 |
251 TARGET_TEST_P(InstructionSelectorPhiTest, Referenceness) { | 269 TARGET_TEST_P(InstructionSelectorPhiTest, Referenceness) { |
252 const MachineType type = GetParam(); | 270 const MachineType type = GetParam(); |
253 StreamBuilder m(this, type, type, type); | 271 StreamBuilder m(this, type, type, type); |
254 Node* param0 = m.Parameter(0); | 272 Node* param0 = m.Parameter(0); |
255 Node* param1 = m.Parameter(1); | 273 Node* param1 = m.Parameter(1); |
256 MLabel a, b, c; | 274 MLabel a, b, c; |
257 m.Branch(m.Int32Constant(1), &a, &b); | 275 m.Branch(m.Int32Constant(1), &a, &b); |
258 m.Bind(&a); | 276 m.Bind(&a); |
259 m.Goto(&c); | 277 m.Goto(&c); |
260 m.Bind(&b); | 278 m.Bind(&b); |
261 m.Goto(&c); | 279 m.Goto(&c); |
262 m.Bind(&c); | 280 m.Bind(&c); |
263 Node* phi = m.Phi(type, param0, param1); | 281 Node* phi = m.Phi(type, param0, param1); |
264 m.Return(phi); | 282 m.Return(phi); |
265 Stream s = m.Build(kAllInstructions); | 283 Stream s = m.Build(kAllInstructions); |
266 EXPECT_EQ(s.IsReference(phi->id()), s.IsReference(param0->id())); | 284 EXPECT_EQ(s.IsReference(phi), s.IsReference(param0)); |
267 EXPECT_EQ(s.IsReference(phi->id()), s.IsReference(param1->id())); | 285 EXPECT_EQ(s.IsReference(phi), s.IsReference(param1)); |
268 } | 286 } |
269 | 287 |
270 | 288 |
271 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorPhiTest, | 289 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorPhiTest, |
272 ::testing::Values(kMachFloat64, kMachInt8, kMachUint8, | 290 ::testing::Values(kMachFloat64, kMachInt8, kMachUint8, |
273 kMachInt16, kMachUint16, kMachInt32, | 291 kMachInt16, kMachUint16, kMachInt32, |
274 kMachUint32, kMachInt64, kMachUint64, | 292 kMachUint32, kMachInt64, kMachUint64, |
275 kMachPtr, kMachAnyTagged)); | 293 kMachPtr, kMachAnyTagged)); |
276 | 294 |
277 | 295 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 desc_before->state_combine().kind()); | 423 desc_before->state_combine().kind()); |
406 EXPECT_EQ(1u, desc_before->parameters_count()); | 424 EXPECT_EQ(1u, desc_before->parameters_count()); |
407 EXPECT_EQ(1u, desc_before->locals_count()); | 425 EXPECT_EQ(1u, desc_before->locals_count()); |
408 EXPECT_EQ(1u, desc_before->stack_count()); | 426 EXPECT_EQ(1u, desc_before->stack_count()); |
409 EXPECT_EQ(43, s.ToInt32(call_instr->InputAt(2))); | 427 EXPECT_EQ(43, s.ToInt32(call_instr->InputAt(2))); |
410 EXPECT_EQ(0, s.ToInt32(call_instr->InputAt(3))); | 428 EXPECT_EQ(0, s.ToInt32(call_instr->InputAt(3))); |
411 EXPECT_EQ(44, s.ToInt32(call_instr->InputAt(4))); | 429 EXPECT_EQ(44, s.ToInt32(call_instr->InputAt(4))); |
412 EXPECT_EQ(45, s.ToInt32(call_instr->InputAt(5))); | 430 EXPECT_EQ(45, s.ToInt32(call_instr->InputAt(5))); |
413 | 431 |
414 // Function. | 432 // Function. |
415 EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(6))); | 433 EXPECT_EQ(s.ToVreg(function_node), s.ToVreg(call_instr->InputAt(6))); |
416 // Context. | 434 // Context. |
417 EXPECT_EQ(context->id(), s.ToVreg(call_instr->InputAt(7))); | 435 EXPECT_EQ(s.ToVreg(context), s.ToVreg(call_instr->InputAt(7))); |
418 | 436 |
419 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); | 437 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); |
420 | 438 |
421 EXPECT_EQ(index, s.size()); | 439 EXPECT_EQ(index, s.size()); |
422 } | 440 } |
423 | 441 |
424 | 442 |
425 TARGET_TEST_F(InstructionSelectorTest, | 443 TARGET_TEST_F(InstructionSelectorTest, |
426 CallFunctionStubDeoptRecursiveFrameState) { | 444 CallFunctionStubDeoptRecursiveFrameState) { |
427 StreamBuilder m(this, kMachAnyTagged, kMachAnyTagged, kMachAnyTagged, | 445 StreamBuilder m(this, kMachAnyTagged, kMachAnyTagged, kMachAnyTagged, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 EXPECT_EQ(66, s.ToInt32(call_instr->InputAt(3))); | 515 EXPECT_EQ(66, s.ToInt32(call_instr->InputAt(3))); |
498 EXPECT_EQ(64, s.ToInt32(call_instr->InputAt(4))); | 516 EXPECT_EQ(64, s.ToInt32(call_instr->InputAt(4))); |
499 EXPECT_EQ(65, s.ToInt32(call_instr->InputAt(5))); | 517 EXPECT_EQ(65, s.ToInt32(call_instr->InputAt(5))); |
500 // Values from parent environment should follow. | 518 // Values from parent environment should follow. |
501 EXPECT_EQ(43, s.ToInt32(call_instr->InputAt(6))); | 519 EXPECT_EQ(43, s.ToInt32(call_instr->InputAt(6))); |
502 EXPECT_EQ(46, s.ToInt32(call_instr->InputAt(7))); | 520 EXPECT_EQ(46, s.ToInt32(call_instr->InputAt(7))); |
503 EXPECT_EQ(44, s.ToInt32(call_instr->InputAt(8))); | 521 EXPECT_EQ(44, s.ToInt32(call_instr->InputAt(8))); |
504 EXPECT_EQ(45, s.ToInt32(call_instr->InputAt(9))); | 522 EXPECT_EQ(45, s.ToInt32(call_instr->InputAt(9))); |
505 | 523 |
506 // Function. | 524 // Function. |
507 EXPECT_EQ(function_node->id(), s.ToVreg(call_instr->InputAt(10))); | 525 EXPECT_EQ(s.ToVreg(function_node), s.ToVreg(call_instr->InputAt(10))); |
508 // Context. | 526 // Context. |
509 EXPECT_EQ(context2->id(), s.ToVreg(call_instr->InputAt(11))); | 527 EXPECT_EQ(s.ToVreg(context2), s.ToVreg(call_instr->InputAt(11))); |
510 // Continuation. | 528 // Continuation. |
511 | 529 |
512 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); | 530 EXPECT_EQ(kArchRet, s[index++]->arch_opcode()); |
513 EXPECT_EQ(index, s.size()); | 531 EXPECT_EQ(index, s.size()); |
514 } | 532 } |
515 | 533 |
516 } // namespace compiler | 534 } // namespace compiler |
517 } // namespace internal | 535 } // namespace internal |
518 } // namespace v8 | 536 } // namespace v8 |
OLD | NEW |