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

Side by Side Diff: test/unittests/compiler/bytecode-graph-builder-unittest.cc

Issue 1441643002: [Interpreter] Add support for global loads / stores / calls to BytecodeGraphBuilder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_tf_call
Patch Set: Move unittest to bytcodearraybuilder Created 5 years, 1 month 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 <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
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 LanguageMode kLanguageModes[] = {LanguageMode::SLOPPY, LanguageMode::STRICT};
60
59 Handle<TypeFeedbackVector> NewTypeFeedbackVector( 61 Handle<TypeFeedbackVector> NewTypeFeedbackVector(
60 Isolate* isolate, FeedbackVectorSpec* spec) { 62 Isolate* isolate, FeedbackVectorSpec* spec) {
61 Handle<TypeFeedbackMetadata> vector_metadata = 63 Handle<TypeFeedbackMetadata> vector_metadata =
62 TypeFeedbackMetadata::New(isolate, spec); 64 TypeFeedbackMetadata::New(isolate, spec);
63 return TypeFeedbackVector::New(isolate, vector_metadata); 65 return TypeFeedbackVector::New(isolate, vector_metadata);
64 } 66 }
65 67
66 68
67 class BytecodeGraphBuilderTest : public TestWithIsolateAndZone { 69 class BytecodeGraphBuilderTest : public TestWithIsolateAndZone {
68 public: 70 public:
69 BytecodeGraphBuilderTest() {} 71 BytecodeGraphBuilderTest() {}
70 72
71 Graph* GetCompletedGraph(Handle<BytecodeArray> bytecode_array, 73 Graph* GetCompletedGraph(Handle<BytecodeArray> bytecode_array,
72 MaybeHandle<TypeFeedbackVector> feedback_vector = 74 MaybeHandle<TypeFeedbackVector> feedback_vector =
73 MaybeHandle<TypeFeedbackVector>()); 75 MaybeHandle<TypeFeedbackVector>(),
76 LanguageMode language_mode = LanguageMode::SLOPPY);
74 77
75 Matcher<Node*> IsUndefinedConstant(); 78 Matcher<Node*> IsUndefinedConstant();
76 Matcher<Node*> IsNullConstant(); 79 Matcher<Node*> IsNullConstant();
77 Matcher<Node*> IsTheHoleConstant(); 80 Matcher<Node*> IsTheHoleConstant();
78 Matcher<Node*> IsFalseConstant(); 81 Matcher<Node*> IsFalseConstant();
79 Matcher<Node*> IsTrueConstant(); 82 Matcher<Node*> IsTrueConstant();
80 Matcher<Node*> IsIntPtrConstant(int value); 83 Matcher<Node*> IsIntPtrConstant(int value);
81 Matcher<Node*> IsFeedbackVector(Node* effect, Node* control); 84 Matcher<Node*> IsFeedbackVector(Node* effect, Node* control);
82 85
83 static Handle<String> GetName(Isolate* isolate, const char* name) { 86 static Handle<String> GetName(Isolate* isolate, const char* name) {
84 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name); 87 Handle<String> result = isolate->factory()->NewStringFromAsciiChecked(name);
85 return isolate->factory()->string_table()->LookupString(isolate, result); 88 return isolate->factory()->string_table()->LookupString(isolate, result);
86 } 89 }
87 90
88 private: 91 private:
89 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilderTest); 92 DISALLOW_COPY_AND_ASSIGN(BytecodeGraphBuilderTest);
90 }; 93 };
91 94
92 95
93 Graph* BytecodeGraphBuilderTest::GetCompletedGraph( 96 Graph* BytecodeGraphBuilderTest::GetCompletedGraph(
94 Handle<BytecodeArray> bytecode_array, 97 Handle<BytecodeArray> bytecode_array,
95 MaybeHandle<TypeFeedbackVector> feedback_vector) { 98 MaybeHandle<TypeFeedbackVector> feedback_vector,
99 LanguageMode language_mode) {
96 MachineOperatorBuilder* machine = new (zone()) MachineOperatorBuilder( 100 MachineOperatorBuilder* machine = new (zone()) MachineOperatorBuilder(
97 zone(), kMachPtr, InstructionSelector::SupportedMachineOperatorFlags()); 101 zone(), kMachPtr, InstructionSelector::SupportedMachineOperatorFlags());
98 CommonOperatorBuilder* common = new (zone()) CommonOperatorBuilder(zone()); 102 CommonOperatorBuilder* common = new (zone()) CommonOperatorBuilder(zone());
99 JSOperatorBuilder* javascript = new (zone()) JSOperatorBuilder(zone()); 103 JSOperatorBuilder* javascript = new (zone()) JSOperatorBuilder(zone());
100 Graph* graph = new (zone()) Graph(zone()); 104 Graph* graph = new (zone()) Graph(zone());
101 JSGraph* jsgraph = new (zone()) 105 JSGraph* jsgraph = new (zone())
102 JSGraph(isolate(), graph, common, javascript, nullptr, machine); 106 JSGraph(isolate(), graph, common, javascript, nullptr, machine);
103 107
104 Handle<String> name = factory()->NewStringFromStaticChars("test"); 108 Handle<String> name = factory()->NewStringFromStaticChars("test");
105 Handle<String> script = factory()->NewStringFromStaticChars("test() {}"); 109 Handle<String> script = factory()->NewStringFromStaticChars("test() {}");
106 Handle<SharedFunctionInfo> shared_info = 110 Handle<SharedFunctionInfo> shared_info =
107 factory()->NewSharedFunctionInfo(name, MaybeHandle<Code>()); 111 factory()->NewSharedFunctionInfo(name, MaybeHandle<Code>());
108 shared_info->set_script(*factory()->NewScript(script)); 112 shared_info->set_script(*factory()->NewScript(script));
109 if (!feedback_vector.is_null()) { 113 if (!feedback_vector.is_null()) {
110 shared_info->set_feedback_vector(*feedback_vector.ToHandleChecked()); 114 shared_info->set_feedback_vector(*feedback_vector.ToHandleChecked());
111 } 115 }
112 116
113 ParseInfo parse_info(zone(), shared_info); 117 ParseInfo parse_info(zone(), shared_info);
118 parse_info.set_language_mode(language_mode);
114 CompilationInfo info(&parse_info); 119 CompilationInfo info(&parse_info);
115 info.shared_info()->set_function_data(*bytecode_array); 120 info.shared_info()->set_function_data(*bytecode_array);
116 121
117 BytecodeGraphBuilder graph_builder(zone(), &info, jsgraph); 122 BytecodeGraphBuilder graph_builder(zone(), &info, jsgraph);
118 graph_builder.CreateGraph(); 123 graph_builder.CreateGraph();
119 return graph; 124 return graph;
120 } 125 }
121 126
122 127
123 Matcher<Node*> BytecodeGraphBuilderTest::IsUndefinedConstant() { 128 Matcher<Node*> BytecodeGraphBuilderTest::IsUndefinedConstant() {
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 call_inputs.push_back(load_named_matcher); 505 call_inputs.push_back(load_named_matcher);
501 call_inputs.push_back(IsParameter(1)); 506 call_inputs.push_back(IsParameter(1));
502 call_inputs.push_back(IsParameter(2)); 507 call_inputs.push_back(IsParameter(2));
503 call_inputs.push_back(IsParameter(3)); 508 call_inputs.push_back(IsParameter(3));
504 Matcher<Node*> call_matcher = 509 Matcher<Node*> call_matcher =
505 IsJSCallFunction(call_inputs, load_named_matcher, IsIfSuccess(_)); 510 IsJSCallFunction(call_inputs, load_named_matcher, IsIfSuccess(_));
506 511
507 EXPECT_THAT(ret, IsReturn(call_matcher, _, _)); 512 EXPECT_THAT(ret, IsReturn(call_matcher, _, _));
508 } 513 }
509 514
515
516 TEST_F(BytecodeGraphBuilderTest, LoadGlobal) {
517 const TypeofMode kTypeOfModes[] = {TypeofMode::NOT_INSIDE_TYPEOF,
518 TypeofMode::INSIDE_TYPEOF};
519 const bool kWideBytecode[] = {false, true};
520 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) {
521 TRACED_FOREACH(TypeofMode, typeof_mode, kTypeOfModes) {
522 TRACED_FOREACH(bool, wide_bytecode, kWideBytecode) {
523 FeedbackVectorSpec feedback_spec(zone());
524 if (wide_bytecode) {
525 for (int i = 0; i < 128; i++) {
526 feedback_spec.AddLoadICSlot();
527 }
528 }
529 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot();
530 Handle<TypeFeedbackVector> vector =
531 NewTypeFeedbackVector(isolate(), &feedback_spec);
532
533 interpreter::BytecodeArrayBuilder array_builder(isolate(), zone());
534 array_builder.set_locals_count(0);
535 array_builder.set_context_count(0);
536 array_builder.set_parameter_count(1);
537
538 Handle<Name> name = GetName(isolate(), "global");
539 size_t name_index = array_builder.GetConstantPoolEntry(name);
540
541 array_builder.LoadGlobal(name_index, vector->GetIndex(slot),
542 language_mode, typeof_mode)
543 .Return();
544 Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray(),
545 vector, language_mode);
546
547 Node* ret = graph->end()->InputAt(0);
548 Node* start = graph->start();
549
550 Matcher<Node*> feedback_vector_matcher = IsFeedbackVector(start, start);
551 Matcher<Node*> load_global_matcher = IsJSLoadGlobal(
552 name, typeof_mode, feedback_vector_matcher, start, start);
553
554 EXPECT_THAT(ret, IsReturn(load_global_matcher, _, _));
555 }
556 }
557 }
558 }
559
560
561 TEST_F(BytecodeGraphBuilderTest, StoreGlobal) {
562 const bool kWideBytecode[] = {false, true};
563 TRACED_FOREACH(LanguageMode, language_mode, kLanguageModes) {
564 TRACED_FOREACH(bool, wide_bytecode, kWideBytecode) {
565 FeedbackVectorSpec feedback_spec(zone());
566 if (wide_bytecode) {
567 for (int i = 0; i < 128; i++) {
568 feedback_spec.AddStoreICSlot();
569 }
570 }
571 FeedbackVectorSlot slot = feedback_spec.AddStoreICSlot();
572 Handle<TypeFeedbackVector> vector =
573 NewTypeFeedbackVector(isolate(), &feedback_spec);
574
575 interpreter::BytecodeArrayBuilder array_builder(isolate(), zone());
576 array_builder.set_locals_count(0);
577 array_builder.set_context_count(0);
578 array_builder.set_parameter_count(1);
579
580 Handle<Name> name = GetName(isolate(), "global");
581 size_t name_index = array_builder.GetConstantPoolEntry(name);
582
583 array_builder.LoadLiteral(Smi::FromInt(321))
584 .StoreGlobal(name_index, vector->GetIndex(slot), language_mode)
585 .Return();
586 Graph* graph = GetCompletedGraph(array_builder.ToBytecodeArray(), vector,
587 language_mode);
588
589 Node* ret = graph->end()->InputAt(0);
590 Node* start = graph->start();
591
592 Matcher<Node*> value_matcher = IsNumberConstant(321);
593 Matcher<Node*> feedback_vector_matcher = IsFeedbackVector(start, start);
594 Matcher<Node*> store_global_matcher = IsJSStoreGlobal(
595 name, value_matcher, feedback_vector_matcher, start, start);
596
597 EXPECT_THAT(ret, IsReturn(_, store_global_matcher, _));
598 }
599 }
600 }
601
510 } // namespace compiler 602 } // namespace compiler
511 } // namespace internal 603 } // namespace internal
512 } // namespace v8 604 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-run-bytecode-graph-builder.cc ('k') | test/unittests/compiler/node-test-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698