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

Side by Side Diff: src/compiler/bytecode-graph-builder.cc

Issue 1419373007: [Interpreter] Adds implementation of bytecode graph builder for LoadICSloppy/Strict (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 "src/compiler/bytecode-graph-builder.h" 5 #include "src/compiler/bytecode-graph-builder.h"
6 6
7 #include "src/compiler/linkage.h" 7 #include "src/compiler/linkage.h"
8 #include "src/compiler/operator-properties.h" 8 #include "src/compiler/operator-properties.h"
9 #include "src/interpreter/bytecode-array-iterator.h" 9 #include "src/interpreter/bytecode-array-iterator.h"
10 10
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 bool BytecodeGraphBuilder::Environment::IsMarkedAsUnreachable() const { 91 bool BytecodeGraphBuilder::Environment::IsMarkedAsUnreachable() const {
92 return GetControlDependency()->opcode() == IrOpcode::kDead; 92 return GetControlDependency()->opcode() == IrOpcode::kDead;
93 } 93 }
94 94
95 95
96 void BytecodeGraphBuilder::Environment::MarkAsUnreachable() { 96 void BytecodeGraphBuilder::Environment::MarkAsUnreachable() {
97 UpdateControlDependency(builder()->jsgraph()->Dead()); 97 UpdateControlDependency(builder()->jsgraph()->Dead());
98 } 98 }
99 99
100 100
101 class BytecodeGraphBuilder::FrameStateBeforeAndAfter {
102 public:
103 // TODO(mythria) remove explicit when there are more parameters for
104 // constructor.
rmcilroy 2015/11/04 14:27:37 no need for this comment
mythria 2015/11/09 12:08:37 Done.
105 explicit FrameStateBeforeAndAfter(BytecodeGraphBuilder* builder)
106 : builder_(builder) {
107 // TODO(mythria) Replace with the actual frame state. Current
rmcilroy 2015/11/04 14:27:37 /s/TODO(mythria)/TODO(mythria):/ (add the colon af
mythria 2015/11/09 12:08:37 Done.
108 // implementation introduces empty frame state.
109 frame_state_before_ = builder_->jsgraph()->EmptyFrameState();
110 }
111
rmcilroy 2015/11/04 14:27:37 nit - remove extra newline (only a single line bet
mythria 2015/11/09 12:08:37 Done.
112
113 void AddToNode(Node* node) {
mythria 2015/11/04 12:19:14 In the AstGraphBuilder, this function expects two
114 int count = OperatorProperties::GetFrameStateInputCount(node->op());
115 DCHECK_LE(count, 2);
116 if (count >= 1) {
117 // Add the frame state for after the operation.
118 DCHECK_EQ(IrOpcode::kDead,
119 NodeProperties::GetFrameStateInput(node, 0)->opcode());
120 // TODO(mythria) Replace with the actual frame state. Current
rmcilroy 2015/11/04 14:27:36 nit - newline above
mythria 2015/11/09 12:08:37 Done.
121 // implementation introduces empty frame state.
122 NodeProperties::ReplaceFrameStateInput(
123 node, 0, builder_->jsgraph()->EmptyFrameState());
124 }
125 if (count >= 2) {
126 // Add the frame state for before the operation.
127 DCHECK_EQ(IrOpcode::kDead,
128 NodeProperties::GetFrameStateInput(node, 1)->opcode());
129 NodeProperties::ReplaceFrameStateInput(node, 1, frame_state_before_);
130 }
131 }
132
133 private:
134 BytecodeGraphBuilder* builder_;
135 Node* frame_state_before_;
136 };
137
138
101 BytecodeGraphBuilder::BytecodeGraphBuilder(Zone* local_zone, 139 BytecodeGraphBuilder::BytecodeGraphBuilder(Zone* local_zone,
102 CompilationInfo* compilation_info, 140 CompilationInfo* compilation_info,
103 JSGraph* jsgraph) 141 JSGraph* jsgraph)
104 : local_zone_(local_zone), 142 : local_zone_(local_zone),
105 info_(compilation_info), 143 info_(compilation_info),
106 jsgraph_(jsgraph), 144 jsgraph_(jsgraph),
107 input_buffer_size_(0), 145 input_buffer_size_(0),
108 input_buffer_(nullptr), 146 input_buffer_(nullptr),
109 exit_controls_(local_zone) { 147 exit_controls_(local_zone) {
110 bytecode_array_ = handle(info()->shared_info()->bytecode_array()); 148 bytecode_array_ = handle(info()->shared_info()->bytecode_array());
111 } 149 }
112 150
113 151
114 Node* BytecodeGraphBuilder::GetFunctionContext() { 152 Node* BytecodeGraphBuilder::GetFunctionContext() {
115 if (!function_context_.is_set()) { 153 if (!function_context_.is_set()) {
116 // Parameter (arity + 1) is special for the outer context of the function 154 // Parameter (arity + 1) is special for the outer context of the function
117 const Operator* op = 155 const Operator* op =
118 common()->Parameter(bytecode_array()->parameter_count(), "%context"); 156 common()->Parameter(bytecode_array()->parameter_count(), "%context");
119 Node* node = NewNode(op, graph()->start()); 157 Node* node = NewNode(op, graph()->start());
120 function_context_.set(node); 158 function_context_.set(node);
121 } 159 }
122 return function_context_.get(); 160 return function_context_.get();
123 } 161 }
124 162
125 163
164 Node* BytecodeGraphBuilder::GetFunctionClosure() {
165 if (!function_closure_.is_set()) {
166 const Operator* op = common()->Parameter(
167 Linkage::kJSFunctionCallClosureParamIndex, "%closure");
168 Node* node = NewNode(op, graph()->start());
169 function_closure_.set(node);
170 }
171 return function_closure_.get();
172 }
173
174
175 Node* BytecodeGraphBuilder::BuildLoadObjectField(Node* object, int offset) {
176 return NewNode(jsgraph()->machine()->Load(kMachAnyTagged), object,
177 jsgraph()->IntPtrConstant(offset - kHeapObjectTag));
178 }
179
180
181 Node* BytecodeGraphBuilder::BuildLoadImmutableObjectField(Node* object,
182 int offset) {
183 return graph()->NewNode(jsgraph()->machine()->Load(kMachAnyTagged), object,
184 jsgraph()->IntPtrConstant(offset - kHeapObjectTag),
185 graph()->start(), graph()->start());
186 }
187
188
189 Node* BytecodeGraphBuilder::BuildLoadFeedbackVector() {
190 if (!feedback_vector_.is_set()) {
191 Node* closure = GetFunctionClosure();
192 Node* shared = BuildLoadImmutableObjectField(
193 closure, JSFunction::kSharedFunctionInfoOffset);
194 Node* vector = BuildLoadImmutableObjectField(
195 shared, SharedFunctionInfo::kFeedbackVectorOffset);
196 feedback_vector_.set(vector);
197 }
198 return feedback_vector_.get();
199 }
200
201
202 VectorSlotPair BytecodeGraphBuilder::CreateVectorSlotPair(
203 FeedbackVectorSlot slot) {
204 return VectorSlotPair(handle(info()->shared_info()->feedback_vector()), slot);
205 }
206
207
208 // TODO(mythria) This implementation introduces empty frame state. Replace with
209 // the correct frame state.
210 void BytecodeGraphBuilder::PrepareFrameState(Node* node) {
mythria 2015/11/04 12:19:14 In the AstGraphBuilder, this function expects two
211 int count = OperatorProperties::GetFrameStateInputCount(node->op());
212 if (count > 0) {
213 DCHECK_EQ(1, count);
214 DCHECK_EQ(IrOpcode::kDead,
215 NodeProperties::GetFrameStateInput(node, 0)->opcode());
216 NodeProperties::ReplaceFrameStateInput(node, 0,
217 jsgraph()->EmptyFrameState());
218 }
219 }
220
221
126 bool BytecodeGraphBuilder::CreateGraph(bool stack_check) { 222 bool BytecodeGraphBuilder::CreateGraph(bool stack_check) {
127 // Set up the basic structure of the graph. Outputs for {Start} are 223 // Set up the basic structure of the graph. Outputs for {Start} are
128 // the formal parameters (including the receiver) plus context and 224 // the formal parameters (including the receiver) plus context and
129 // closure. 225 // closure.
130 226
131 // The additional count items are for the context and closure. 227 // The additional count items are for the context and closure.
132 int actual_parameter_count = bytecode_array()->parameter_count() + 2; 228 int actual_parameter_count = bytecode_array()->parameter_count() + 2;
133 graph()->SetStart(graph()->NewNode(common()->Start(actual_parameter_count))); 229 graph()->SetStart(graph()->NewNode(common()->Start(actual_parameter_count)));
134 230
135 Environment env(this, bytecode_array()->register_count(), 231 Environment env(this, bytecode_array()->register_count(),
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 406
311 407
312 void BytecodeGraphBuilder::VisitStaContextSlot( 408 void BytecodeGraphBuilder::VisitStaContextSlot(
313 const interpreter::BytecodeArrayIterator& iterator) { 409 const interpreter::BytecodeArrayIterator& iterator) {
314 UNIMPLEMENTED(); 410 UNIMPLEMENTED();
315 } 411 }
316 412
317 413
318 void BytecodeGraphBuilder::VisitLoadICSloppy( 414 void BytecodeGraphBuilder::VisitLoadICSloppy(
319 const interpreter::BytecodeArrayIterator& iterator) { 415 const interpreter::BytecodeArrayIterator& iterator) {
320 UNIMPLEMENTED(); 416 FrameStateBeforeAndAfter states(this);
rmcilroy 2015/11/04 14:27:37 Add a DCHECK(is_sloppy(language_mode()) (and simil
mythria 2015/11/09 12:08:37 Done.
417 Node* object = environment()->LookupRegister(iterator.GetRegisterOperand(0));
418 Handle<Name> name =
419 Handle<Name>::cast(iterator.GetConstantForIndexOperand(1));
420 FeedbackVectorSlot slot =
421 info()->feedback_vector()->ToSlot(iterator.GetIndexOperand(2));
422 VectorSlotPair feedback = CreateVectorSlotPair(slot);
rmcilroy 2015/11/04 14:27:37 Could you create a helper for the FeedbackVecto
mythria 2015/11/09 12:08:37 Done.
423 const Operator* op = javascript()->LoadNamed(language_mode(), name, feedback);
rmcilroy 2015/11/04 14:27:37 nit - newline above
424 Node* node = NewNode(op, object, BuildLoadFeedbackVector());
425 states.AddToNode(node);
426 environment()->BindAccumulator(node);
rmcilroy 2015/11/04 14:27:37 Could you pull this out into a BuildNamedLoad help
mythria 2015/11/09 12:08:37 Done.
321 } 427 }
322 428
323 429
324 void BytecodeGraphBuilder::VisitLoadICStrict( 430 void BytecodeGraphBuilder::VisitLoadICStrict(
325 const interpreter::BytecodeArrayIterator& iterator) { 431 const interpreter::BytecodeArrayIterator& iterator) {
326 UNIMPLEMENTED(); 432 UNIMPLEMENTED();
327 } 433 }
328 434
329 435
330 void BytecodeGraphBuilder::VisitKeyedLoadICSloppy( 436 void BytecodeGraphBuilder::VisitKeyedLoadICSloppy(
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 554
449 555
450 void BytecodeGraphBuilder::VisitCreateArrayLiteral( 556 void BytecodeGraphBuilder::VisitCreateArrayLiteral(
451 const interpreter::BytecodeArrayIterator& iterator) { 557 const interpreter::BytecodeArrayIterator& iterator) {
452 UNIMPLEMENTED(); 558 UNIMPLEMENTED();
453 } 559 }
454 560
455 561
456 void BytecodeGraphBuilder::VisitCreateObjectLiteral( 562 void BytecodeGraphBuilder::VisitCreateObjectLiteral(
457 const interpreter::BytecodeArrayIterator& iterator) { 563 const interpreter::BytecodeArrayIterator& iterator) {
458 UNIMPLEMENTED(); 564 Node* closure = GetFunctionClosure();
565 Node* literals_array =
566 BuildLoadObjectField(closure, JSFunction::kLiteralsOffset);
567 Node* literal_index = jsgraph()->Constant(iterator.GetIndexOperand(0));
568 Node* constants = environment()->LookupAccumulator();
569 const Operator* op =
570 javascript()->CreateLiteralObject(iterator.GetImmediateOperand(1));
571 Node* literal = NewNode(op, literals_array, literal_index, constants);
572 PrepareFrameState(literal);
573 environment()->BindAccumulator(literal);
rmcilroy 2015/11/04 14:27:37 Could you remove this and do it in a separate CL p
mythria 2015/11/09 12:08:37 Done.
459 } 574 }
460 575
461 576
462 void BytecodeGraphBuilder::VisitCall( 577 void BytecodeGraphBuilder::VisitCall(
463 const interpreter::BytecodeArrayIterator& iterator) { 578 const interpreter::BytecodeArrayIterator& iterator) {
464 UNIMPLEMENTED(); 579 UNIMPLEMENTED();
465 } 580 }
466 581
467 582
468 void BytecodeGraphBuilder::VisitCallRuntime( 583 void BytecodeGraphBuilder::VisitCallRuntime(
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 1007
893 void BytecodeGraphBuilder::UpdateControlDependencyToLeaveFunction(Node* exit) { 1008 void BytecodeGraphBuilder::UpdateControlDependencyToLeaveFunction(Node* exit) {
894 if (environment()->IsMarkedAsUnreachable()) return; 1009 if (environment()->IsMarkedAsUnreachable()) return;
895 environment()->MarkAsUnreachable(); 1010 environment()->MarkAsUnreachable();
896 exit_controls_.push_back(exit); 1011 exit_controls_.push_back(exit);
897 } 1012 }
898 1013
899 } // namespace compiler 1014 } // namespace compiler
900 } // namespace internal 1015 } // namespace internal
901 } // namespace v8 1016 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698