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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 input_buffer_size_(0), | 107 input_buffer_size_(0), |
108 input_buffer_(nullptr), | 108 input_buffer_(nullptr), |
109 exit_controls_(local_zone) { | 109 exit_controls_(local_zone) { |
110 bytecode_array_ = handle(info()->shared_info()->bytecode_array()); | 110 bytecode_array_ = handle(info()->shared_info()->bytecode_array()); |
111 } | 111 } |
112 | 112 |
113 | 113 |
114 Node* BytecodeGraphBuilder::GetFunctionContext() { | 114 Node* BytecodeGraphBuilder::GetFunctionContext() { |
115 if (!function_context_.is_set()) { | 115 if (!function_context_.is_set()) { |
116 // Parameter (arity + 1) is special for the outer context of the function | 116 // Parameter (arity + 1) is special for the outer context of the function |
117 const Operator* op = | 117 const Operator* op = common()->Parameter( |
118 common()->Parameter(bytecode_array()->parameter_count(), "%context"); | 118 bytecode_array()->parameter_count() + 1, "%context"); |
119 Node* node = NewNode(op, graph()->start()); | 119 Node* node = NewNode(op, graph()->start()); |
120 function_context_.set(node); | 120 function_context_.set(node); |
121 } | 121 } |
122 return function_context_.get(); | 122 return function_context_.get(); |
123 } | 123 } |
124 | 124 |
125 | 125 |
126 Node* BytecodeGraphBuilder::GetFunctionClosure() { | 126 Node* BytecodeGraphBuilder::GetFunctionClosure() { |
127 if (!function_closure_.is_set()) { | 127 if (!function_closure_.is_set()) { |
128 const Operator* op = common()->Parameter( | 128 const Operator* op = common()->Parameter( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 jsgraph()->EmptyFrameState()); | 170 jsgraph()->EmptyFrameState()); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 | 174 |
175 bool BytecodeGraphBuilder::CreateGraph(bool stack_check) { | 175 bool BytecodeGraphBuilder::CreateGraph(bool stack_check) { |
176 // Set up the basic structure of the graph. Outputs for {Start} are | 176 // Set up the basic structure of the graph. Outputs for {Start} are |
177 // the formal parameters (including the receiver) plus context and | 177 // the formal parameters (including the receiver) plus context and |
178 // closure. | 178 // closure. |
179 | 179 |
180 // The additional count items are for the context and closure. | 180 // Set up the basic structure of the graph. Outputs for {Start} are the formal |
181 int actual_parameter_count = bytecode_array()->parameter_count() + 2; | 181 // parameters (including the receiver) plus number of arguments, context and |
| 182 // closure. |
| 183 int actual_parameter_count = bytecode_array()->parameter_count() + 3; |
182 graph()->SetStart(graph()->NewNode(common()->Start(actual_parameter_count))); | 184 graph()->SetStart(graph()->NewNode(common()->Start(actual_parameter_count))); |
183 | 185 |
184 Environment env(this, bytecode_array()->register_count(), | 186 Environment env(this, bytecode_array()->register_count(), |
185 bytecode_array()->parameter_count(), graph()->start(), | 187 bytecode_array()->parameter_count(), graph()->start(), |
186 GetFunctionContext()); | 188 GetFunctionContext()); |
187 set_environment(&env); | 189 set_environment(&env); |
188 | 190 |
189 // Build function context only if there are context allocated variables. | 191 // Build function context only if there are context allocated variables. |
190 if (info()->num_heap_slots() > 0) { | 192 if (info()->num_heap_slots() > 0) { |
191 UNIMPLEMENTED(); // TODO(oth): Write ast-graph-builder equivalent. | 193 UNIMPLEMENTED(); // TODO(oth): Write ast-graph-builder equivalent. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 300 } |
299 | 301 |
300 | 302 |
301 void BytecodeGraphBuilder::VisitStar( | 303 void BytecodeGraphBuilder::VisitStar( |
302 const interpreter::BytecodeArrayIterator& iterator) { | 304 const interpreter::BytecodeArrayIterator& iterator) { |
303 Node* value = environment()->LookupAccumulator(); | 305 Node* value = environment()->LookupAccumulator(); |
304 environment()->BindRegister(iterator.GetRegisterOperand(0), value); | 306 environment()->BindRegister(iterator.GetRegisterOperand(0), value); |
305 } | 307 } |
306 | 308 |
307 | 309 |
| 310 void BytecodeGraphBuilder::BuildLoadGlobal( |
| 311 const interpreter::BytecodeArrayIterator& iterator, |
| 312 TypeofMode typeof_mode) { |
| 313 Handle<Name> name = |
| 314 Handle<Name>::cast(iterator.GetConstantForIndexOperand(0)); |
| 315 VectorSlotPair feedback = CreateVectorSlotPair(iterator.GetIndexOperand(1)); |
| 316 |
| 317 const Operator* op = javascript()->LoadGlobal(name, feedback, typeof_mode); |
| 318 Node* node = NewNode(op, BuildLoadFeedbackVector()); |
| 319 AddEmptyFrameStateInputs(node); |
| 320 environment()->BindAccumulator(node); |
| 321 } |
| 322 |
| 323 |
308 void BytecodeGraphBuilder::VisitLdaGlobalSloppy( | 324 void BytecodeGraphBuilder::VisitLdaGlobalSloppy( |
309 const interpreter::BytecodeArrayIterator& iterator) { | 325 const interpreter::BytecodeArrayIterator& iterator) { |
310 UNIMPLEMENTED(); | 326 DCHECK(is_sloppy(language_mode())); |
| 327 BuildLoadGlobal(iterator, TypeofMode::NOT_INSIDE_TYPEOF); |
311 } | 328 } |
312 | 329 |
313 | 330 |
314 void BytecodeGraphBuilder::VisitLdaGlobalStrict( | 331 void BytecodeGraphBuilder::VisitLdaGlobalStrict( |
315 const interpreter::BytecodeArrayIterator& iterator) { | 332 const interpreter::BytecodeArrayIterator& iterator) { |
316 UNIMPLEMENTED(); | 333 DCHECK(is_strict(language_mode())); |
| 334 BuildLoadGlobal(iterator, TypeofMode::NOT_INSIDE_TYPEOF); |
317 } | 335 } |
318 | 336 |
319 | 337 |
320 void BytecodeGraphBuilder::VisitLdaGlobalInsideTypeofSloppy( | 338 void BytecodeGraphBuilder::VisitLdaGlobalInsideTypeofSloppy( |
321 const interpreter::BytecodeArrayIterator& iterator) { | 339 const interpreter::BytecodeArrayIterator& iterator) { |
322 UNIMPLEMENTED(); | 340 DCHECK(is_sloppy(language_mode())); |
| 341 BuildLoadGlobal(iterator, TypeofMode::INSIDE_TYPEOF); |
323 } | 342 } |
324 | 343 |
325 | 344 |
326 void BytecodeGraphBuilder::VisitLdaGlobalInsideTypeofStrict( | 345 void BytecodeGraphBuilder::VisitLdaGlobalInsideTypeofStrict( |
327 const interpreter::BytecodeArrayIterator& iterator) { | 346 const interpreter::BytecodeArrayIterator& iterator) { |
328 UNIMPLEMENTED(); | 347 DCHECK(is_strict(language_mode())); |
| 348 BuildLoadGlobal(iterator, TypeofMode::INSIDE_TYPEOF); |
329 } | 349 } |
330 | 350 |
331 | 351 |
332 void BytecodeGraphBuilder::VisitLdaGlobalSloppyWide( | 352 void BytecodeGraphBuilder::VisitLdaGlobalSloppyWide( |
333 const interpreter::BytecodeArrayIterator& iterator) { | 353 const interpreter::BytecodeArrayIterator& iterator) { |
334 UNIMPLEMENTED(); | 354 DCHECK(is_sloppy(language_mode())); |
| 355 BuildLoadGlobal(iterator, TypeofMode::NOT_INSIDE_TYPEOF); |
335 } | 356 } |
336 | 357 |
337 | 358 |
338 void BytecodeGraphBuilder::VisitLdaGlobalStrictWide( | 359 void BytecodeGraphBuilder::VisitLdaGlobalStrictWide( |
339 const interpreter::BytecodeArrayIterator& iterator) { | 360 const interpreter::BytecodeArrayIterator& iterator) { |
340 UNIMPLEMENTED(); | 361 DCHECK(is_strict(language_mode())); |
| 362 BuildLoadGlobal(iterator, TypeofMode::NOT_INSIDE_TYPEOF); |
341 } | 363 } |
342 | 364 |
343 | 365 |
344 void BytecodeGraphBuilder::VisitLdaGlobalInsideTypeofSloppyWide( | 366 void BytecodeGraphBuilder::VisitLdaGlobalInsideTypeofSloppyWide( |
345 const interpreter::BytecodeArrayIterator& iterator) { | 367 const interpreter::BytecodeArrayIterator& iterator) { |
346 UNIMPLEMENTED(); | 368 DCHECK(is_sloppy(language_mode())); |
| 369 BuildLoadGlobal(iterator, TypeofMode::INSIDE_TYPEOF); |
347 } | 370 } |
348 | 371 |
349 | 372 |
350 void BytecodeGraphBuilder::VisitLdaGlobalInsideTypeofStrictWide( | 373 void BytecodeGraphBuilder::VisitLdaGlobalInsideTypeofStrictWide( |
351 const interpreter::BytecodeArrayIterator& iterator) { | 374 const interpreter::BytecodeArrayIterator& iterator) { |
352 UNIMPLEMENTED(); | 375 DCHECK(is_strict(language_mode())); |
| 376 BuildLoadGlobal(iterator, TypeofMode::INSIDE_TYPEOF); |
| 377 } |
| 378 |
| 379 |
| 380 void BytecodeGraphBuilder::BuildStoreGlobal( |
| 381 const interpreter::BytecodeArrayIterator& iterator) { |
| 382 Handle<Name> name = |
| 383 Handle<Name>::cast(iterator.GetConstantForIndexOperand(0)); |
| 384 VectorSlotPair feedback = CreateVectorSlotPair(iterator.GetIndexOperand(1)); |
| 385 Node* value = environment()->LookupAccumulator(); |
| 386 |
| 387 const Operator* op = |
| 388 javascript()->StoreGlobal(language_mode(), name, feedback); |
| 389 Node* node = NewNode(op, value, BuildLoadFeedbackVector()); |
| 390 AddEmptyFrameStateInputs(node); |
353 } | 391 } |
354 | 392 |
355 | 393 |
356 void BytecodeGraphBuilder::VisitStaGlobalSloppy( | 394 void BytecodeGraphBuilder::VisitStaGlobalSloppy( |
357 const interpreter::BytecodeArrayIterator& iterator) { | 395 const interpreter::BytecodeArrayIterator& iterator) { |
358 UNIMPLEMENTED(); | 396 DCHECK(is_sloppy(language_mode())); |
| 397 BuildStoreGlobal(iterator); |
359 } | 398 } |
360 | 399 |
361 | 400 |
362 void BytecodeGraphBuilder::VisitStaGlobalStrict( | 401 void BytecodeGraphBuilder::VisitStaGlobalStrict( |
363 const interpreter::BytecodeArrayIterator& iterator) { | 402 const interpreter::BytecodeArrayIterator& iterator) { |
364 UNIMPLEMENTED(); | 403 DCHECK(is_strict(language_mode())); |
| 404 BuildStoreGlobal(iterator); |
365 } | 405 } |
366 | 406 |
367 void BytecodeGraphBuilder::VisitStaGlobalSloppyWide( | 407 void BytecodeGraphBuilder::VisitStaGlobalSloppyWide( |
368 const interpreter::BytecodeArrayIterator& iterator) { | 408 const interpreter::BytecodeArrayIterator& iterator) { |
369 UNIMPLEMENTED(); | 409 DCHECK(is_sloppy(language_mode())); |
| 410 BuildStoreGlobal(iterator); |
370 } | 411 } |
371 | 412 |
372 | 413 |
373 void BytecodeGraphBuilder::VisitStaGlobalStrictWide( | 414 void BytecodeGraphBuilder::VisitStaGlobalStrictWide( |
374 const interpreter::BytecodeArrayIterator& iterator) { | 415 const interpreter::BytecodeArrayIterator& iterator) { |
375 UNIMPLEMENTED(); | 416 DCHECK(is_strict(language_mode())); |
| 417 BuildStoreGlobal(iterator); |
376 } | 418 } |
377 | 419 |
378 | 420 |
379 void BytecodeGraphBuilder::VisitLdaContextSlot( | 421 void BytecodeGraphBuilder::VisitLdaContextSlot( |
380 const interpreter::BytecodeArrayIterator& iterator) { | 422 const interpreter::BytecodeArrayIterator& iterator) { |
381 UNIMPLEMENTED(); | 423 UNIMPLEMENTED(); |
382 } | 424 } |
383 | 425 |
384 | 426 |
385 void BytecodeGraphBuilder::VisitStaContextSlot( | 427 void BytecodeGraphBuilder::VisitStaContextSlot( |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 | 1070 |
1029 void BytecodeGraphBuilder::UpdateControlDependencyToLeaveFunction(Node* exit) { | 1071 void BytecodeGraphBuilder::UpdateControlDependencyToLeaveFunction(Node* exit) { |
1030 if (environment()->IsMarkedAsUnreachable()) return; | 1072 if (environment()->IsMarkedAsUnreachable()) return; |
1031 environment()->MarkAsUnreachable(); | 1073 environment()->MarkAsUnreachable(); |
1032 exit_controls_.push_back(exit); | 1074 exit_controls_.push_back(exit); |
1033 } | 1075 } |
1034 | 1076 |
1035 } // namespace compiler | 1077 } // namespace compiler |
1036 } // namespace internal | 1078 } // namespace internal |
1037 } // namespace v8 | 1079 } // namespace v8 |
OLD | NEW |