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