OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/ast-graph-builder.h" | 5 #include "src/compiler/ast-graph-builder.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/compiler/ast-loop-assignment-analyzer.h" | 8 #include "src/compiler/ast-loop-assignment-analyzer.h" |
9 #include "src/compiler/control-builders.h" | 9 #include "src/compiler/control-builders.h" |
10 #include "src/compiler/linkage.h" | 10 #include "src/compiler/linkage.h" |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 423 |
424 | 424 |
425 Node* AstGraphBuilder::NewCurrentContextOsrValue() { | 425 Node* AstGraphBuilder::NewCurrentContextOsrValue() { |
426 // TODO(titzer): use a real OSR value here; a parameter works by accident. | 426 // TODO(titzer): use a real OSR value here; a parameter works by accident. |
427 // Parameter (arity + 1) is special for the outer context of the function | 427 // Parameter (arity + 1) is special for the outer context of the function |
428 const Operator* op = common()->Parameter(info()->num_parameters() + 1); | 428 const Operator* op = common()->Parameter(info()->num_parameters() + 1); |
429 return NewNode(op, graph()->start()); | 429 return NewNode(op, graph()->start()); |
430 } | 430 } |
431 | 431 |
432 | 432 |
433 bool AstGraphBuilder::CreateGraph(bool constant_context) { | 433 bool AstGraphBuilder::CreateGraph(bool constant_context, bool stack_check) { |
434 Scope* scope = info()->scope(); | 434 Scope* scope = info()->scope(); |
435 DCHECK(graph() != NULL); | 435 DCHECK(graph() != NULL); |
436 | 436 |
437 // Set up the basic structure of the graph. | 437 // Set up the basic structure of the graph. |
438 int parameter_count = info()->num_parameters(); | 438 int parameter_count = info()->num_parameters(); |
439 graph()->SetStart(graph()->NewNode(common()->Start(parameter_count))); | 439 graph()->SetStart(graph()->NewNode(common()->Start(parameter_count))); |
440 | 440 |
441 // Initialize the top-level environment. | 441 // Initialize the top-level environment. |
442 Environment env(this, scope, graph()->start()); | 442 Environment env(this, scope, graph()->start()); |
443 set_environment(&env); | 443 set_environment(&env); |
(...skipping 18 matching lines...) Expand all Loading... |
462 env.Bind(scope->receiver(), patched_receiver); | 462 env.Bind(scope->receiver(), patched_receiver); |
463 | 463 |
464 // Build function context only if there are context allocated variables. | 464 // Build function context only if there are context allocated variables. |
465 int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | 465 int heap_slots = info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
466 if (heap_slots > 0) { | 466 if (heap_slots > 0) { |
467 // Push a new inner context scope for the function. | 467 // Push a new inner context scope for the function. |
468 Node* closure = GetFunctionClosure(); | 468 Node* closure = GetFunctionClosure(); |
469 Node* inner_context = | 469 Node* inner_context = |
470 BuildLocalFunctionContext(function_context_.get(), closure); | 470 BuildLocalFunctionContext(function_context_.get(), closure); |
471 ContextScope top_context(this, scope, inner_context); | 471 ContextScope top_context(this, scope, inner_context); |
472 CreateGraphBody(); | 472 CreateGraphBody(stack_check); |
473 } else { | 473 } else { |
474 // Simply use the outer function context in building the graph. | 474 // Simply use the outer function context in building the graph. |
475 CreateGraphBody(); | 475 CreateGraphBody(stack_check); |
476 } | 476 } |
477 | 477 |
478 // Finish the basic structure of the graph. | 478 // Finish the basic structure of the graph. |
479 graph()->SetEnd(graph()->NewNode(common()->End(), exit_control())); | 479 graph()->SetEnd(graph()->NewNode(common()->End(), exit_control())); |
480 | 480 |
481 // Failures indicated by stack overflow. | 481 // Failures indicated by stack overflow. |
482 return !HasStackOverflow(); | 482 return !HasStackOverflow(); |
483 } | 483 } |
484 | 484 |
485 | 485 |
486 void AstGraphBuilder::CreateGraphBody() { | 486 void AstGraphBuilder::CreateGraphBody(bool stack_check) { |
487 Scope* scope = info()->scope(); | 487 Scope* scope = info()->scope(); |
488 | 488 |
489 // Build the arguments object if it is used. | 489 // Build the arguments object if it is used. |
490 BuildArgumentsObject(scope->arguments()); | 490 BuildArgumentsObject(scope->arguments()); |
491 | 491 |
492 // Build rest arguments array if it is used. | 492 // Build rest arguments array if it is used. |
493 int rest_index; | 493 int rest_index; |
494 Variable* rest_parameter = scope->rest_parameter(&rest_index); | 494 Variable* rest_parameter = scope->rest_parameter(&rest_index); |
495 BuildRestArgumentsArray(rest_parameter, rest_index); | 495 BuildRestArgumentsArray(rest_parameter, rest_index); |
496 | 496 |
497 // Emit tracing call if requested to do so. | 497 // Emit tracing call if requested to do so. |
498 if (FLAG_trace) { | 498 if (FLAG_trace) { |
499 NewNode(javascript()->CallRuntime(Runtime::kTraceEnter, 0)); | 499 NewNode(javascript()->CallRuntime(Runtime::kTraceEnter, 0)); |
500 } | 500 } |
501 | 501 |
502 // Visit implicit declaration of the function name. | 502 // Visit implicit declaration of the function name. |
503 if (scope->is_function_scope() && scope->function() != NULL) { | 503 if (scope->is_function_scope() && scope->function() != NULL) { |
504 VisitVariableDeclaration(scope->function()); | 504 VisitVariableDeclaration(scope->function()); |
505 } | 505 } |
506 | 506 |
507 // Visit declarations within the function scope. | 507 // Visit declarations within the function scope. |
508 VisitDeclarations(scope->declarations()); | 508 VisitDeclarations(scope->declarations()); |
509 | 509 |
510 // Build a stack-check before the body. | 510 // Build a stack-check before the body. |
511 Node* node = NewNode(javascript()->StackCheck()); | 511 if (stack_check) { |
512 PrepareFrameState(node, BailoutId::FunctionEntry()); | 512 Node* node = NewNode(javascript()->StackCheck()); |
| 513 PrepareFrameState(node, BailoutId::FunctionEntry()); |
| 514 } |
513 | 515 |
514 // Visit statements in the function body. | 516 // Visit statements in the function body. |
515 VisitStatements(info()->function()->body()); | 517 VisitStatements(info()->function()->body()); |
516 | 518 |
517 // Emit tracing call if requested to do so. | 519 // Emit tracing call if requested to do so. |
518 if (FLAG_trace) { | 520 if (FLAG_trace) { |
519 // TODO(mstarzinger): Only traces implicit return. | 521 // TODO(mstarzinger): Only traces implicit return. |
520 Node* return_value = jsgraph()->UndefinedConstant(); | 522 Node* return_value = jsgraph()->UndefinedConstant(); |
521 NewNode(javascript()->CallRuntime(Runtime::kTraceExit, 1), return_value); | 523 NewNode(javascript()->CallRuntime(Runtime::kTraceExit, 1), return_value); |
522 } | 524 } |
(...skipping 2744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3267 // Phi does not exist yet, introduce one. | 3269 // Phi does not exist yet, introduce one. |
3268 value = NewPhi(inputs, value, control); | 3270 value = NewPhi(inputs, value, control); |
3269 value->ReplaceInput(inputs - 1, other); | 3271 value->ReplaceInput(inputs - 1, other); |
3270 } | 3272 } |
3271 return value; | 3273 return value; |
3272 } | 3274 } |
3273 | 3275 |
3274 } // namespace compiler | 3276 } // namespace compiler |
3275 } // namespace internal | 3277 } // namespace internal |
3276 } // namespace v8 | 3278 } // namespace v8 |
OLD | NEW |