| 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 <iostream> | 5 #include <iostream> |
| 6 | 6 |
| 7 #include "src/compiler/bytecode-graph-builder.h" | 7 #include "src/compiler/bytecode-graph-builder.h" |
| 8 #include "src/compiler/common-operator.h" | 8 #include "src/compiler/common-operator.h" |
| 9 #include "src/compiler/graph-visualizer.h" | 9 #include "src/compiler/graph-visualizer.h" |
| 10 #include "src/compiler/instruction.h" | 10 #include "src/compiler/instruction.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 SEP() \ | 49 SEP() \ |
| 50 REPEAT_32(SEP, __VA_ARGS__) \ | 50 REPEAT_32(SEP, __VA_ARGS__) \ |
| 51 SEP() \ | 51 SEP() \ |
| 52 REPEAT_16(SEP, __VA_ARGS__) \ | 52 REPEAT_16(SEP, __VA_ARGS__) \ |
| 53 SEP() \ | 53 SEP() \ |
| 54 REPEAT_8(SEP, __VA_ARGS__) \ | 54 REPEAT_8(SEP, __VA_ARGS__) \ |
| 55 SEP() \ | 55 SEP() \ |
| 56 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() __VA_ARGS__ | 56 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() __VA_ARGS__ |
| 57 | 57 |
| 58 | 58 |
| 59 Handle<TypeFeedbackVector> NewTypeFeedbackVector( |
| 60 Isolate* isolate, FeedbackVectorSpec* spec) { |
| 61 Handle<TypeFeedbackMetadata> vector_metadata = |
| 62 TypeFeedbackMetadata::New(isolate, spec); |
| 63 return TypeFeedbackVector::New(isolate, vector_metadata); |
| 64 } |
| 65 |
| 66 |
| 59 class BytecodeGraphBuilderTest : public TestWithIsolateAndZone { | 67 class BytecodeGraphBuilderTest : public TestWithIsolateAndZone { |
| 60 public: | 68 public: |
| 61 BytecodeGraphBuilderTest() {} | 69 BytecodeGraphBuilderTest() {} |
| 62 | 70 |
| 63 Graph* GetCompletedGraph(Handle<BytecodeArray> bytecode_array); | 71 Graph* GetCompletedGraph(Handle<BytecodeArray> bytecode_array, |
| 72 MaybeHandle<TypeFeedbackVector> feedback_vector = |
| 73 MaybeHandle<TypeFeedbackVector>()); |
| 64 | 74 |
| 65 Matcher<Node*> IsUndefinedConstant(); | 75 Matcher<Node*> IsUndefinedConstant(); |
| 66 Matcher<Node*> IsNullConstant(); | 76 Matcher<Node*> IsNullConstant(); |
| 67 Matcher<Node*> IsTheHoleConstant(); | 77 Matcher<Node*> IsTheHoleConstant(); |
| 68 Matcher<Node*> IsFalseConstant(); | 78 Matcher<Node*> IsFalseConstant(); |
| 69 Matcher<Node*> IsTrueConstant(); | 79 Matcher<Node*> IsTrueConstant(); |
| 70 Matcher<Node*> IsIntPtrConstant(int value); | 80 Matcher<Node*> IsIntPtrConstant(int value); |
| 71 Matcher<Node*> IsFeedbackVector(Node* effect, Node* control); | 81 Matcher<Node*> IsFeedbackVector(Node* effect, Node* control); |
| 72 | 82 |
| 73 static Handle<String> GetName(Isolate* isolate, const char* name) { | 83 static Handle<String> GetName(Isolate* isolate, const char* name) { |
| 74 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name); | 84 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name); |
| 75 return isolate->factory()->string_table()->LookupString(isolate, result); | 85 return isolate->factory()->string_table()->LookupString(isolate, result); |
| 76 } | 86 } |
| 77 | 87 |
| 78 private: | 88 private: |
| 79 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilderTest); | 89 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilderTest); |
| 80 }; | 90 }; |
| 81 | 91 |
| 82 | 92 |
| 83 Graph* BytecodeGraphBuilderTest::GetCompletedGraph( | 93 Graph* BytecodeGraphBuilderTest::GetCompletedGraph( |
| 84 Handle<BytecodeArray> bytecode_array) { | 94 Handle<BytecodeArray> bytecode_array, |
| 95 MaybeHandle<TypeFeedbackVector> feedback_vector) { |
| 85 MachineOperatorBuilder* machine = new (zone()) MachineOperatorBuilder( | 96 MachineOperatorBuilder* machine = new (zone()) MachineOperatorBuilder( |
| 86 zone(), kMachPtr, InstructionSelector::SupportedMachineOperatorFlags()); | 97 zone(), kMachPtr, InstructionSelector::SupportedMachineOperatorFlags()); |
| 87 CommonOperatorBuilder* common = new (zone()) CommonOperatorBuilder(zone()); | 98 CommonOperatorBuilder* common = new (zone()) CommonOperatorBuilder(zone()); |
| 88 JSOperatorBuilder* javascript = new (zone()) JSOperatorBuilder(zone()); | 99 JSOperatorBuilder* javascript = new (zone()) JSOperatorBuilder(zone()); |
| 89 Graph* graph = new (zone()) Graph(zone()); | 100 Graph* graph = new (zone()) Graph(zone()); |
| 90 JSGraph* jsgraph = new (zone()) | 101 JSGraph* jsgraph = new (zone()) |
| 91 JSGraph(isolate(), graph, common, javascript, nullptr, machine); | 102 JSGraph(isolate(), graph, common, javascript, nullptr, machine); |
| 92 | 103 |
| 93 Handle<String> name = factory()->NewStringFromStaticChars("test"); | 104 Handle<String> name = factory()->NewStringFromStaticChars("test"); |
| 94 Handle<String> script = factory()->NewStringFromStaticChars("test() {}"); | 105 Handle<String> script = factory()->NewStringFromStaticChars("test() {}"); |
| 95 Handle<SharedFunctionInfo> shared_info = | 106 Handle<SharedFunctionInfo> shared_info = |
| 96 factory()->NewSharedFunctionInfo(name, MaybeHandle<Code>()); | 107 factory()->NewSharedFunctionInfo(name, MaybeHandle<Code>()); |
| 97 shared_info->set_script(*factory()->NewScript(script)); | 108 shared_info->set_script(*factory()->NewScript(script)); |
| 109 if (!feedback_vector.is_null()) { |
| 110 shared_info->set_feedback_vector(*feedback_vector.ToHandleChecked()); |
| 111 } |
| 98 | 112 |
| 99 ParseInfo parse_info(zone(), shared_info); | 113 ParseInfo parse_info(zone(), shared_info); |
| 100 CompilationInfo info(&parse_info); | 114 CompilationInfo info(&parse_info); |
| 101 info.shared_info()->set_function_data(*bytecode_array); | 115 info.shared_info()->set_function_data(*bytecode_array); |
| 102 | 116 |
| 103 BytecodeGraphBuilder graph_builder(zone(), &info, jsgraph); | 117 BytecodeGraphBuilder graph_builder(zone(), &info, jsgraph); |
| 104 graph_builder.CreateGraph(); | 118 graph_builder.CreateGraph(); |
| 105 return graph; | 119 return graph; |
| 106 } | 120 } |
| 107 | 121 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 Matcher<Node*> feedback_vector_matcher = IsFeedbackVector(start, start); | 410 Matcher<Node*> feedback_vector_matcher = IsFeedbackVector(start, start); |
| 397 Matcher<Node*> preceeding_load = IsJSLoadNamed(val_prev, _, _, _, _); | 411 Matcher<Node*> preceeding_load = IsJSLoadNamed(val_prev, _, _, _, _); |
| 398 Matcher<Node*> load_named_matcher_wide = | 412 Matcher<Node*> load_named_matcher_wide = |
| 399 IsJSLoadNamed(val, IsParameter(1), feedback_vector_matcher, | 413 IsJSLoadNamed(val, IsParameter(1), feedback_vector_matcher, |
| 400 preceeding_load, IsIfSuccess(_)); | 414 preceeding_load, IsIfSuccess(_)); |
| 401 | 415 |
| 402 EXPECT_THAT(ret, IsReturn(load_named_matcher_wide, _, _)); | 416 EXPECT_THAT(ret, IsReturn(load_named_matcher_wide, _, _)); |
| 403 } | 417 } |
| 404 | 418 |
| 405 | 419 |
| 420 TEST_F(BytecodeGraphBuilderTest, CallProperty0) { |
| 421 FeedbackVectorSpec feedback_spec(zone()); |
| 422 FeedbackVectorSlot call_slot = feedback_spec.AddCallICSlot(); |
| 423 FeedbackVectorSlot load_slot = feedback_spec.AddLoadICSlot(); |
| 424 Handle<TypeFeedbackVector> vector = |
| 425 NewTypeFeedbackVector(isolate(), &feedback_spec); |
| 426 |
| 427 interpreter::BytecodeArrayBuilder array_builder(isolate(), zone()); |
| 428 array_builder.set_locals_count(1); |
| 429 array_builder.set_context_count(0); |
| 430 array_builder.set_parameter_count(2); |
| 431 |
| 432 Handle<Name> func_name = GetName(isolate(), "func"); |
| 433 size_t func_name_index = array_builder.GetConstantPoolEntry(func_name); |
| 434 |
| 435 interpreter::Register reg0 = interpreter::Register(0); |
| 436 array_builder.LoadNamedProperty( |
| 437 array_builder.Parameter(1), func_name_index, |
| 438 vector->GetIndex(load_slot), LanguageMode::SLOPPY) |
| 439 .StoreAccumulatorInRegister(reg0) |
| 440 .Call(reg0, array_builder.Parameter(1), 0, vector->GetIndex(call_slot)) |
| 441 .Return(); |
| 442 |
| 443 Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray(), vector); |
| 444 Node* ret = graph->end()->InputAt(0); |
| 445 Node* start = graph->start(); |
| 446 |
| 447 Matcher<Node*> feedback_vector_matcher = IsFeedbackVector(start, start); |
| 448 Matcher<Node*> load_named_matcher = IsJSLoadNamed( |
| 449 func_name, IsParameter(1), feedback_vector_matcher, start, start); |
| 450 std::vector<Matcher<Node*>> call_inputs; |
| 451 call_inputs.push_back(load_named_matcher); |
| 452 call_inputs.push_back(IsParameter(1)); |
| 453 Matcher<Node*> call_matcher = |
| 454 IsJSCallFunction(call_inputs, load_named_matcher, IsIfSuccess(_)); |
| 455 |
| 456 EXPECT_THAT(ret, IsReturn(call_matcher, _, _)); |
| 457 } |
| 458 |
| 459 |
| 460 TEST_F(BytecodeGraphBuilderTest, CallProperty2) { |
| 461 FeedbackVectorSpec feedback_spec(zone()); |
| 462 FeedbackVectorSlot call_slot = feedback_spec.AddCallICSlot(); |
| 463 FeedbackVectorSlot load_slot = feedback_spec.AddLoadICSlot(); |
| 464 Handle<TypeFeedbackVector> vector = |
| 465 NewTypeFeedbackVector(isolate(), &feedback_spec); |
| 466 |
| 467 interpreter::BytecodeArrayBuilder array_builder(isolate(), zone()); |
| 468 array_builder.set_locals_count(4); |
| 469 array_builder.set_context_count(0); |
| 470 array_builder.set_parameter_count(4); |
| 471 |
| 472 Handle<Name> func_name = GetName(isolate(), "func"); |
| 473 size_t func_name_index = array_builder.GetConstantPoolEntry(func_name); |
| 474 |
| 475 interpreter::Register reg0 = interpreter::Register(0); |
| 476 interpreter::Register reg1 = interpreter::Register(1); |
| 477 interpreter::Register reg2 = interpreter::Register(2); |
| 478 interpreter::Register reg3 = interpreter::Register(3); |
| 479 array_builder.LoadNamedProperty( |
| 480 array_builder.Parameter(1), func_name_index, |
| 481 vector->GetIndex(load_slot), LanguageMode::SLOPPY) |
| 482 .StoreAccumulatorInRegister(reg0) |
| 483 .LoadAccumulatorWithRegister(array_builder.Parameter(1)) |
| 484 .StoreAccumulatorInRegister(reg1) |
| 485 .LoadAccumulatorWithRegister(array_builder.Parameter(2)) |
| 486 .StoreAccumulatorInRegister(reg2) |
| 487 .LoadAccumulatorWithRegister(array_builder.Parameter(3)) |
| 488 .StoreAccumulatorInRegister(reg3) |
| 489 .Call(reg0, reg1, 2, vector->GetIndex(call_slot)) |
| 490 .Return(); |
| 491 |
| 492 Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray(), vector); |
| 493 Node* ret = graph->end()->InputAt(0); |
| 494 Node* start = graph->start(); |
| 495 |
| 496 Matcher<Node*> feedback_vector_matcher = IsFeedbackVector(start, start); |
| 497 Matcher<Node*> load_named_matcher = IsJSLoadNamed( |
| 498 func_name, IsParameter(1), feedback_vector_matcher, start, start); |
| 499 std::vector<Matcher<Node*>> call_inputs; |
| 500 call_inputs.push_back(load_named_matcher); |
| 501 call_inputs.push_back(IsParameter(1)); |
| 502 call_inputs.push_back(IsParameter(2)); |
| 503 call_inputs.push_back(IsParameter(3)); |
| 504 Matcher<Node*> call_matcher = |
| 505 IsJSCallFunction(call_inputs, load_named_matcher, IsIfSuccess(_)); |
| 506 |
| 507 EXPECT_THAT(ret, IsReturn(call_matcher, _, _)); |
| 508 } |
| 509 |
| 406 } // namespace compiler | 510 } // namespace compiler |
| 407 } // namespace internal | 511 } // namespace internal |
| 408 } // namespace v8 | 512 } // namespace v8 |
| OLD | NEW |