| 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 "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 Loading... |
| 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 explicit FrameStateBeforeAndAfter(BytecodeGraphBuilder* builder) |
| 104 : builder_(builder) { |
| 105 // TODO(mythria): Replace with the actual frame state. Current |
| 106 // implementation introduces empty frame state. |
| 107 frame_state_before_ = builder_->jsgraph()->EmptyFrameState(); |
| 108 } |
| 109 |
| 110 void AddToNode(Node* node) { |
| 111 int count = OperatorProperties::GetFrameStateInputCount(node->op()); |
| 112 DCHECK_LE(count, 2); |
| 113 if (count >= 1) { |
| 114 // Add the frame state for after the operation. |
| 115 DCHECK_EQ(IrOpcode::kDead, |
| 116 NodeProperties::GetFrameStateInput(node, 0)->opcode()); |
| 117 |
| 118 // TODO(mythria): Replace with the actual frame state. Current |
| 119 // implementation introduces empty frame state. |
| 120 NodeProperties::ReplaceFrameStateInput( |
| 121 node, 0, builder_->jsgraph()->EmptyFrameState()); |
| 122 } |
| 123 if (count >= 2) { |
| 124 // Add the frame state for before the operation. |
| 125 DCHECK_EQ(IrOpcode::kDead, |
| 126 NodeProperties::GetFrameStateInput(node, 1)->opcode()); |
| 127 NodeProperties::ReplaceFrameStateInput(node, 1, frame_state_before_); |
| 128 } |
| 129 } |
| 130 |
| 131 private: |
| 132 BytecodeGraphBuilder* builder_; |
| 133 Node* frame_state_before_; |
| 134 }; |
| 135 |
| 136 |
| 101 BytecodeGraphBuilder::BytecodeGraphBuilder(Zone* local_zone, | 137 BytecodeGraphBuilder::BytecodeGraphBuilder(Zone* local_zone, |
| 102 CompilationInfo* compilation_info, | 138 CompilationInfo* compilation_info, |
| 103 JSGraph* jsgraph) | 139 JSGraph* jsgraph) |
| 104 : local_zone_(local_zone), | 140 : local_zone_(local_zone), |
| 105 info_(compilation_info), | 141 info_(compilation_info), |
| 106 jsgraph_(jsgraph), | 142 jsgraph_(jsgraph), |
| 107 input_buffer_size_(0), | 143 input_buffer_size_(0), |
| 108 input_buffer_(nullptr), | 144 input_buffer_(nullptr), |
| 109 exit_controls_(local_zone) { | 145 exit_controls_(local_zone) { |
| 110 bytecode_array_ = handle(info()->shared_info()->bytecode_array()); | 146 bytecode_array_ = handle(info()->shared_info()->bytecode_array()); |
| 111 } | 147 } |
| 112 | 148 |
| 113 | 149 |
| 114 Node* BytecodeGraphBuilder::GetFunctionContext() { | 150 Node* BytecodeGraphBuilder::GetFunctionContext() { |
| 115 if (!function_context_.is_set()) { | 151 if (!function_context_.is_set()) { |
| 116 // Parameter (arity + 1) is special for the outer context of the function | 152 // Parameter (arity + 1) is special for the outer context of the function |
| 117 const Operator* op = | 153 const Operator* op = |
| 118 common()->Parameter(bytecode_array()->parameter_count(), "%context"); | 154 common()->Parameter(bytecode_array()->parameter_count(), "%context"); |
| 119 Node* node = NewNode(op, graph()->start()); | 155 Node* node = NewNode(op, graph()->start()); |
| 120 function_context_.set(node); | 156 function_context_.set(node); |
| 121 } | 157 } |
| 122 return function_context_.get(); | 158 return function_context_.get(); |
| 123 } | 159 } |
| 124 | 160 |
| 125 | 161 |
| 162 Node* BytecodeGraphBuilder::GetFunctionClosure() { |
| 163 if (!function_closure_.is_set()) { |
| 164 const Operator* op = common()->Parameter( |
| 165 Linkage::kJSFunctionCallClosureParamIndex, "%closure"); |
| 166 Node* node = NewNode(op, graph()->start()); |
| 167 function_closure_.set(node); |
| 168 } |
| 169 return function_closure_.get(); |
| 170 } |
| 171 |
| 172 |
| 173 Node* BytecodeGraphBuilder::BuildLoadImmutableObjectField(Node* object, |
| 174 int offset) { |
| 175 return graph()->NewNode(jsgraph()->machine()->Load(kMachAnyTagged), object, |
| 176 jsgraph()->IntPtrConstant(offset - kHeapObjectTag), |
| 177 graph()->start(), graph()->start()); |
| 178 } |
| 179 |
| 180 |
| 181 Node* BytecodeGraphBuilder::BuildLoadFeedbackVector() { |
| 182 if (!feedback_vector_.is_set()) { |
| 183 Node* closure = GetFunctionClosure(); |
| 184 Node* shared = BuildLoadImmutableObjectField( |
| 185 closure, JSFunction::kSharedFunctionInfoOffset); |
| 186 Node* vector = BuildLoadImmutableObjectField( |
| 187 shared, SharedFunctionInfo::kFeedbackVectorOffset); |
| 188 feedback_vector_.set(vector); |
| 189 } |
| 190 return feedback_vector_.get(); |
| 191 } |
| 192 |
| 193 |
| 194 VectorSlotPair BytecodeGraphBuilder::CreateVectorSlotPair(int slot_id) { |
| 195 Handle<TypeFeedbackVector> feedback_vector = info()->feedback_vector(); |
| 196 FeedbackVectorSlot slot = feedback_vector->ToSlot(slot_id); |
| 197 return VectorSlotPair(feedback_vector, slot); |
| 198 } |
| 199 |
| 200 |
| 126 bool BytecodeGraphBuilder::CreateGraph(bool stack_check) { | 201 bool BytecodeGraphBuilder::CreateGraph(bool stack_check) { |
| 127 // Set up the basic structure of the graph. Outputs for {Start} are | 202 // Set up the basic structure of the graph. Outputs for {Start} are |
| 128 // the formal parameters (including the receiver) plus context and | 203 // the formal parameters (including the receiver) plus context and |
| 129 // closure. | 204 // closure. |
| 130 | 205 |
| 131 // The additional count items are for the context and closure. | 206 // The additional count items are for the context and closure. |
| 132 int actual_parameter_count = bytecode_array()->parameter_count() + 2; | 207 int actual_parameter_count = bytecode_array()->parameter_count() + 2; |
| 133 graph()->SetStart(graph()->NewNode(common()->Start(actual_parameter_count))); | 208 graph()->SetStart(graph()->NewNode(common()->Start(actual_parameter_count))); |
| 134 | 209 |
| 135 Environment env(this, bytecode_array()->register_count(), | 210 Environment env(this, bytecode_array()->register_count(), |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 UNIMPLEMENTED(); | 383 UNIMPLEMENTED(); |
| 309 } | 384 } |
| 310 | 385 |
| 311 | 386 |
| 312 void BytecodeGraphBuilder::VisitStaContextSlot( | 387 void BytecodeGraphBuilder::VisitStaContextSlot( |
| 313 const interpreter::BytecodeArrayIterator& iterator) { | 388 const interpreter::BytecodeArrayIterator& iterator) { |
| 314 UNIMPLEMENTED(); | 389 UNIMPLEMENTED(); |
| 315 } | 390 } |
| 316 | 391 |
| 317 | 392 |
| 393 void BytecodeGraphBuilder::BuildNamedLoad( |
| 394 const interpreter::BytecodeArrayIterator& iterator) { |
| 395 FrameStateBeforeAndAfter states(this); |
| 396 Node* object = environment()->LookupRegister(iterator.GetRegisterOperand(0)); |
| 397 Handle<Name> name = |
| 398 Handle<Name>::cast(iterator.GetConstantForIndexOperand(1)); |
| 399 VectorSlotPair feedback = CreateVectorSlotPair(iterator.GetIndexOperand(2)); |
| 400 |
| 401 const Operator* op = javascript()->LoadNamed(language_mode(), name, feedback); |
| 402 Node* node = NewNode(op, object, BuildLoadFeedbackVector()); |
| 403 states.AddToNode(node); |
| 404 environment()->BindAccumulator(node); |
| 405 } |
| 406 |
| 407 |
| 318 void BytecodeGraphBuilder::VisitLoadICSloppy( | 408 void BytecodeGraphBuilder::VisitLoadICSloppy( |
| 319 const interpreter::BytecodeArrayIterator& iterator) { | 409 const interpreter::BytecodeArrayIterator& iterator) { |
| 320 UNIMPLEMENTED(); | 410 DCHECK(is_sloppy(language_mode())); |
| 411 BuildNamedLoad(iterator); |
| 321 } | 412 } |
| 322 | 413 |
| 323 | 414 |
| 324 void BytecodeGraphBuilder::VisitLoadICStrict( | 415 void BytecodeGraphBuilder::VisitLoadICStrict( |
| 325 const interpreter::BytecodeArrayIterator& iterator) { | 416 const interpreter::BytecodeArrayIterator& iterator) { |
| 326 UNIMPLEMENTED(); | 417 DCHECK(is_strict(language_mode())); |
| 418 BuildNamedLoad(iterator); |
| 327 } | 419 } |
| 328 | 420 |
| 329 | 421 |
| 330 void BytecodeGraphBuilder::VisitKeyedLoadICSloppy( | 422 void BytecodeGraphBuilder::VisitKeyedLoadICSloppy( |
| 331 const interpreter::BytecodeArrayIterator& iterator) { | 423 const interpreter::BytecodeArrayIterator& iterator) { |
| 332 UNIMPLEMENTED(); | 424 UNIMPLEMENTED(); |
| 333 } | 425 } |
| 334 | 426 |
| 335 | 427 |
| 336 void BytecodeGraphBuilder::VisitKeyedLoadICStrict( | 428 void BytecodeGraphBuilder::VisitKeyedLoadICStrict( |
| 337 const interpreter::BytecodeArrayIterator& iterator) { | 429 const interpreter::BytecodeArrayIterator& iterator) { |
| 338 UNIMPLEMENTED(); | 430 UNIMPLEMENTED(); |
| 339 } | 431 } |
| 340 | 432 |
| 341 | 433 |
| 342 void BytecodeGraphBuilder::VisitLoadICSloppyWide( | 434 void BytecodeGraphBuilder::VisitLoadICSloppyWide( |
| 343 const interpreter::BytecodeArrayIterator& iterator) { | 435 const interpreter::BytecodeArrayIterator& iterator) { |
| 344 UNIMPLEMENTED(); | 436 DCHECK(is_sloppy(language_mode())); |
| 437 BuildNamedLoad(iterator); |
| 345 } | 438 } |
| 346 | 439 |
| 347 | 440 |
| 348 void BytecodeGraphBuilder::VisitLoadICStrictWide( | 441 void BytecodeGraphBuilder::VisitLoadICStrictWide( |
| 349 const interpreter::BytecodeArrayIterator& iterator) { | 442 const interpreter::BytecodeArrayIterator& iterator) { |
| 350 UNIMPLEMENTED(); | 443 DCHECK(is_strict(language_mode())); |
| 444 BuildNamedLoad(iterator); |
| 351 } | 445 } |
| 352 | 446 |
| 353 | 447 |
| 354 void BytecodeGraphBuilder::VisitKeyedLoadICSloppyWide( | 448 void BytecodeGraphBuilder::VisitKeyedLoadICSloppyWide( |
| 355 const interpreter::BytecodeArrayIterator& iterator) { | 449 const interpreter::BytecodeArrayIterator& iterator) { |
| 356 UNIMPLEMENTED(); | 450 UNIMPLEMENTED(); |
| 357 } | 451 } |
| 358 | 452 |
| 359 | 453 |
| 360 void BytecodeGraphBuilder::VisitKeyedLoadICStrictWide( | 454 void BytecodeGraphBuilder::VisitKeyedLoadICStrictWide( |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 | 986 |
| 893 void BytecodeGraphBuilder::UpdateControlDependencyToLeaveFunction(Node* exit) { | 987 void BytecodeGraphBuilder::UpdateControlDependencyToLeaveFunction(Node* exit) { |
| 894 if (environment()->IsMarkedAsUnreachable()) return; | 988 if (environment()->IsMarkedAsUnreachable()) return; |
| 895 environment()->MarkAsUnreachable(); | 989 environment()->MarkAsUnreachable(); |
| 896 exit_controls_.push_back(exit); | 990 exit_controls_.push_back(exit); |
| 897 } | 991 } |
| 898 | 992 |
| 899 } // namespace compiler | 993 } // namespace compiler |
| 900 } // namespace internal | 994 } // namespace internal |
| 901 } // namespace v8 | 995 } // namespace v8 |
| OLD | NEW |