Chromium Code Reviews| 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 FeedbackVectorSlot slot = info()->feedback_vector()->ToSlot(slot_id); | |
| 196 return CreateVectorSlotPair(slot); | |
| 197 } | |
| 198 | |
| 199 | |
| 200 VectorSlotPair BytecodeGraphBuilder::CreateVectorSlotPair( | |
|
rmcilroy
2015/11/09 15:23:00
Just inline this into the function above (I don't
mythria
2015/11/10 09:55:35
Done.
| |
| 201 FeedbackVectorSlot slot) { | |
| 202 return VectorSlotPair(handle(info()->shared_info()->feedback_vector()), slot); | |
| 203 } | |
| 204 | |
| 205 | |
| 206 // TODO(mythria): This implementation introduces empty frame state. Replace with | |
|
rmcilroy
2015/11/09 15:23:00
nit - /empty frame state/an empty frame state/
mythria
2015/11/10 09:55:35
Done.
| |
| 207 // the correct frame state. | |
| 208 void BytecodeGraphBuilder::PrepareFrameState(Node* node) { | |
|
rmcilroy
2015/11/09 15:23:00
Unused? If so, please remove for now.
mythria
2015/11/10 09:55:35
Done.
| |
| 209 int count = OperatorProperties::GetFrameStateInputCount(node->op()); | |
| 210 if (count > 0) { | |
| 211 DCHECK_EQ(1, count); | |
| 212 DCHECK_EQ(IrOpcode::kDead, | |
| 213 NodeProperties::GetFrameStateInput(node, 0)->opcode()); | |
| 214 NodeProperties::ReplaceFrameStateInput(node, 0, | |
| 215 jsgraph()->EmptyFrameState()); | |
| 216 } | |
| 217 } | |
| 218 | |
| 219 | |
| 126 bool BytecodeGraphBuilder::CreateGraph(bool stack_check) { | 220 bool BytecodeGraphBuilder::CreateGraph(bool stack_check) { |
| 127 // Set up the basic structure of the graph. Outputs for {Start} are | 221 // Set up the basic structure of the graph. Outputs for {Start} are |
| 128 // the formal parameters (including the receiver) plus context and | 222 // the formal parameters (including the receiver) plus context and |
| 129 // closure. | 223 // closure. |
| 130 | 224 |
| 131 // The additional count items are for the context and closure. | 225 // The additional count items are for the context and closure. |
| 132 int actual_parameter_count = bytecode_array()->parameter_count() + 2; | 226 int actual_parameter_count = bytecode_array()->parameter_count() + 2; |
| 133 graph()->SetStart(graph()->NewNode(common()->Start(actual_parameter_count))); | 227 graph()->SetStart(graph()->NewNode(common()->Start(actual_parameter_count))); |
| 134 | 228 |
| 135 Environment env(this, bytecode_array()->register_count(), | 229 Environment env(this, bytecode_array()->register_count(), |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 UNIMPLEMENTED(); | 402 UNIMPLEMENTED(); |
| 309 } | 403 } |
| 310 | 404 |
| 311 | 405 |
| 312 void BytecodeGraphBuilder::VisitStaContextSlot( | 406 void BytecodeGraphBuilder::VisitStaContextSlot( |
| 313 const interpreter::BytecodeArrayIterator& iterator) { | 407 const interpreter::BytecodeArrayIterator& iterator) { |
| 314 UNIMPLEMENTED(); | 408 UNIMPLEMENTED(); |
| 315 } | 409 } |
| 316 | 410 |
| 317 | 411 |
| 412 void BytecodeGraphBuilder::BuildNamedLoad( | |
| 413 const interpreter::BytecodeArrayIterator& iterator) { | |
| 414 FrameStateBeforeAndAfter states(this); | |
| 415 Node* object = environment()->LookupRegister(iterator.GetRegisterOperand(0)); | |
| 416 Handle<Name> name = | |
| 417 Handle<Name>::cast(iterator.GetConstantForIndexOperand(1)); | |
| 418 VectorSlotPair feedback = CreateVectorSlotPair(iterator.GetIndexOperand(2)); | |
| 419 | |
| 420 const Operator* op = javascript()->LoadNamed(language_mode(), name, feedback); | |
| 421 Node* node = NewNode(op, object, BuildLoadFeedbackVector()); | |
| 422 states.AddToNode(node); | |
| 423 environment()->BindAccumulator(node); | |
| 424 } | |
| 425 | |
| 426 | |
| 318 void BytecodeGraphBuilder::VisitLoadICSloppy( | 427 void BytecodeGraphBuilder::VisitLoadICSloppy( |
| 319 const interpreter::BytecodeArrayIterator& iterator) { | 428 const interpreter::BytecodeArrayIterator& iterator) { |
| 320 UNIMPLEMENTED(); | 429 DCHECK(is_sloppy(language_mode())); |
| 430 BuildNamedLoad(iterator); | |
| 321 } | 431 } |
| 322 | 432 |
| 323 | 433 |
| 324 void BytecodeGraphBuilder::VisitLoadICStrict( | 434 void BytecodeGraphBuilder::VisitLoadICStrict( |
| 325 const interpreter::BytecodeArrayIterator& iterator) { | 435 const interpreter::BytecodeArrayIterator& iterator) { |
| 326 UNIMPLEMENTED(); | 436 DCHECK(is_strict(language_mode())); |
| 437 BuildNamedLoad(iterator); | |
| 327 } | 438 } |
| 328 | 439 |
| 329 | 440 |
| 330 void BytecodeGraphBuilder::VisitKeyedLoadICSloppy( | 441 void BytecodeGraphBuilder::VisitKeyedLoadICSloppy( |
| 331 const interpreter::BytecodeArrayIterator& iterator) { | 442 const interpreter::BytecodeArrayIterator& iterator) { |
| 332 UNIMPLEMENTED(); | 443 UNIMPLEMENTED(); |
| 333 } | 444 } |
| 334 | 445 |
| 335 | 446 |
| 336 void BytecodeGraphBuilder::VisitKeyedLoadICStrict( | 447 void BytecodeGraphBuilder::VisitKeyedLoadICStrict( |
| 337 const interpreter::BytecodeArrayIterator& iterator) { | 448 const interpreter::BytecodeArrayIterator& iterator) { |
| 338 UNIMPLEMENTED(); | 449 UNIMPLEMENTED(); |
| 339 } | 450 } |
| 340 | 451 |
| 341 | 452 |
| 342 void BytecodeGraphBuilder::VisitLoadICSloppyWide( | 453 void BytecodeGraphBuilder::VisitLoadICSloppyWide( |
| 343 const interpreter::BytecodeArrayIterator& iterator) { | 454 const interpreter::BytecodeArrayIterator& iterator) { |
| 344 UNIMPLEMENTED(); | 455 DCHECK(is_sloppy(language_mode())); |
| 456 BuildNamedLoad(iterator); | |
| 345 } | 457 } |
| 346 | 458 |
| 347 | 459 |
| 348 void BytecodeGraphBuilder::VisitLoadICStrictWide( | 460 void BytecodeGraphBuilder::VisitLoadICStrictWide( |
| 349 const interpreter::BytecodeArrayIterator& iterator) { | 461 const interpreter::BytecodeArrayIterator& iterator) { |
| 350 UNIMPLEMENTED(); | 462 DCHECK(is_strict(language_mode())); |
| 463 BuildNamedLoad(iterator); | |
| 351 } | 464 } |
| 352 | 465 |
| 353 | 466 |
| 354 void BytecodeGraphBuilder::VisitKeyedLoadICSloppyWide( | 467 void BytecodeGraphBuilder::VisitKeyedLoadICSloppyWide( |
| 355 const interpreter::BytecodeArrayIterator& iterator) { | 468 const interpreter::BytecodeArrayIterator& iterator) { |
| 356 UNIMPLEMENTED(); | 469 UNIMPLEMENTED(); |
| 357 } | 470 } |
| 358 | 471 |
| 359 | 472 |
| 360 void BytecodeGraphBuilder::VisitKeyedLoadICStrictWide( | 473 void BytecodeGraphBuilder::VisitKeyedLoadICStrictWide( |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 | 1005 |
| 893 void BytecodeGraphBuilder::UpdateControlDependencyToLeaveFunction(Node* exit) { | 1006 void BytecodeGraphBuilder::UpdateControlDependencyToLeaveFunction(Node* exit) { |
| 894 if (environment()->IsMarkedAsUnreachable()) return; | 1007 if (environment()->IsMarkedAsUnreachable()) return; |
| 895 environment()->MarkAsUnreachable(); | 1008 environment()->MarkAsUnreachable(); |
| 896 exit_controls_.push_back(exit); | 1009 exit_controls_.push_back(exit); |
| 897 } | 1010 } |
| 898 | 1011 |
| 899 } // namespace compiler | 1012 } // namespace compiler |
| 900 } // namespace internal | 1013 } // namespace internal |
| 901 } // namespace v8 | 1014 } // namespace v8 |
| OLD | NEW |