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/js-type-feedback.h" | 10 #include "src/compiler/js-type-feedback.h" |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 state_values_cache_(jsgraph), | 403 state_values_cache_(jsgraph), |
404 liveness_analyzer_(static_cast<size_t>(info->scope()->num_stack_slots()), | 404 liveness_analyzer_(static_cast<size_t>(info->scope()->num_stack_slots()), |
405 local_zone), | 405 local_zone), |
406 js_type_feedback_(js_type_feedback) { | 406 js_type_feedback_(js_type_feedback) { |
407 InitializeAstVisitor(info->isolate(), local_zone); | 407 InitializeAstVisitor(info->isolate(), local_zone); |
408 } | 408 } |
409 | 409 |
410 | 410 |
411 Node* AstGraphBuilder::GetFunctionClosure() { | 411 Node* AstGraphBuilder::GetFunctionClosure() { |
412 if (!function_closure_.is_set()) { | 412 if (!function_closure_.is_set()) { |
413 const Operator* op = | 413 const Operator* op = common()->Parameter( |
414 common()->Parameter(Linkage::kJSFunctionCallClosureParamIndex); | 414 Linkage::kJSFunctionCallClosureParamIndex, "%closure"); |
415 Node* node = NewNode(op, graph()->start()); | 415 Node* node = NewNode(op, graph()->start()); |
416 function_closure_.set(node); | 416 function_closure_.set(node); |
417 } | 417 } |
418 return function_closure_.get(); | 418 return function_closure_.get(); |
419 } | 419 } |
420 | 420 |
421 | 421 |
422 void AstGraphBuilder::CreateFunctionContext(bool constant_context) { | 422 void AstGraphBuilder::CreateFunctionContext(bool constant_context) { |
423 function_context_.set(constant_context | 423 function_context_.set(constant_context |
424 ? jsgraph()->HeapConstant(info()->context()) | 424 ? jsgraph()->HeapConstant(info()->context()) |
425 : NewOuterContextParam()); | 425 : NewOuterContextParam()); |
426 } | 426 } |
427 | 427 |
428 | 428 |
429 Node* AstGraphBuilder::NewOuterContextParam() { | 429 Node* AstGraphBuilder::NewOuterContextParam() { |
430 // Parameter (arity + 1) is special for the outer context of the function | 430 // Parameter (arity + 1) is special for the outer context of the function |
431 const Operator* op = common()->Parameter(info()->num_parameters() + 1); | 431 const Operator* op = |
432 common()->Parameter(info()->num_parameters() + 1, "%context"); | |
432 return NewNode(op, graph()->start()); | 433 return NewNode(op, graph()->start()); |
433 } | 434 } |
434 | 435 |
435 | 436 |
436 Node* AstGraphBuilder::NewCurrentContextOsrValue() { | 437 Node* AstGraphBuilder::NewCurrentContextOsrValue() { |
437 // TODO(titzer): use a real OSR value here; a parameter works by accident. | 438 // TODO(titzer): use a real OSR value here; a parameter works by accident. |
438 // Parameter (arity + 1) is special for the outer context of the function | 439 // Parameter (arity + 1) is special for the outer context of the function |
439 const Operator* op = common()->Parameter(info()->num_parameters() + 1); | 440 const Operator* op = |
441 common()->Parameter(info()->num_parameters() + 1, "%osr-context"); | |
440 return NewNode(op, graph()->start()); | 442 return NewNode(op, graph()->start()); |
441 } | 443 } |
442 | 444 |
443 | 445 |
444 bool AstGraphBuilder::CreateGraph(bool constant_context, bool stack_check) { | 446 bool AstGraphBuilder::CreateGraph(bool constant_context, bool stack_check) { |
445 Scope* scope = info()->scope(); | 447 Scope* scope = info()->scope(); |
446 DCHECK(graph() != NULL); | 448 DCHECK(graph() != NULL); |
447 | 449 |
448 // Set up the basic structure of the graph. | 450 // Set up the basic structure of the graph. |
449 int parameter_count = info()->num_parameters(); | 451 int parameter_count = info()->num_parameters(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 Property* property = expr->AsProperty(); | 570 Property* property = expr->AsProperty(); |
569 DCHECK(expr->IsValidReferenceExpression()); | 571 DCHECK(expr->IsValidReferenceExpression()); |
570 LhsKind lhs_kind = | 572 LhsKind lhs_kind = |
571 (property == NULL) ? VARIABLE : (property->key()->IsPropertyName()) | 573 (property == NULL) ? VARIABLE : (property->key()->IsPropertyName()) |
572 ? NAMED_PROPERTY | 574 ? NAMED_PROPERTY |
573 : KEYED_PROPERTY; | 575 : KEYED_PROPERTY; |
574 return lhs_kind; | 576 return lhs_kind; |
575 } | 577 } |
576 | 578 |
577 | 579 |
580 static const char* GetDebugParameterName(Zone* zone, Scope* scope, int index) { | |
581 #if DEBUG | |
582 const AstRawString* name = scope->parameter(index)->raw_name(); | |
583 if (name && name->length() > 0) { | |
584 char* data = zone->NewArray<char>(name->length() + 1); | |
585 data[name->length()] = 0; | |
586 memcpy(data, name->raw_data(), name->length()); | |
587 return data; | |
588 } | |
589 #endif | |
590 return nullptr; | |
591 } | |
592 | |
Benedikt Meurer
2015/04/22 09:47:12
Nit: missing new line (presubmit should have compl
titzer
2015/04/22 09:50:01
Done.
| |
578 AstGraphBuilder::Environment::Environment(AstGraphBuilder* builder, | 593 AstGraphBuilder::Environment::Environment(AstGraphBuilder* builder, |
579 Scope* scope, | 594 Scope* scope, |
580 Node* control_dependency) | 595 Node* control_dependency) |
581 : builder_(builder), | 596 : builder_(builder), |
582 parameters_count_(scope->num_parameters() + 1), | 597 parameters_count_(scope->num_parameters() + 1), |
583 locals_count_(scope->num_stack_slots()), | 598 locals_count_(scope->num_stack_slots()), |
584 liveness_block_(builder_->liveness_analyzer()->NewBlock()), | 599 liveness_block_(builder_->liveness_analyzer()->NewBlock()), |
585 values_(builder_->local_zone()), | 600 values_(builder_->local_zone()), |
586 contexts_(builder_->local_zone()), | 601 contexts_(builder_->local_zone()), |
587 control_dependency_(control_dependency), | 602 control_dependency_(control_dependency), |
588 effect_dependency_(control_dependency), | 603 effect_dependency_(control_dependency), |
589 parameters_node_(nullptr), | 604 parameters_node_(nullptr), |
590 locals_node_(nullptr), | 605 locals_node_(nullptr), |
591 stack_node_(nullptr) { | 606 stack_node_(nullptr) { |
592 DCHECK_EQ(scope->num_parameters() + 1, parameters_count()); | 607 DCHECK_EQ(scope->num_parameters() + 1, parameters_count()); |
593 | 608 |
594 // Bind the receiver variable. | 609 // Bind the receiver variable. |
595 Node* receiver = builder->graph()->NewNode(common()->Parameter(0), | 610 Node* receiver = builder->graph()->NewNode(common()->Parameter(0, "%this"), |
596 builder->graph()->start()); | 611 builder->graph()->start()); |
597 values()->push_back(receiver); | 612 values()->push_back(receiver); |
598 | 613 |
599 // Bind all parameter variables. The parameter indices are shifted by 1 | 614 // Bind all parameter variables. The parameter indices are shifted by 1 |
600 // (receiver is parameter index -1 but environment index 0). | 615 // (receiver is parameter index -1 but environment index 0). |
601 for (int i = 0; i < scope->num_parameters(); ++i) { | 616 for (int i = 0; i < scope->num_parameters(); ++i) { |
602 Node* parameter = builder->graph()->NewNode(common()->Parameter(i + 1), | 617 const char* debug_name = GetDebugParameterName(graph()->zone(), scope, i); |
603 builder->graph()->start()); | 618 Node* parameter = builder->graph()->NewNode( |
619 common()->Parameter(i + 1, debug_name), builder->graph()->start()); | |
604 values()->push_back(parameter); | 620 values()->push_back(parameter); |
605 } | 621 } |
606 | 622 |
607 // Bind all local variables to undefined. | 623 // Bind all local variables to undefined. |
608 Node* undefined_constant = builder->jsgraph()->UndefinedConstant(); | 624 Node* undefined_constant = builder->jsgraph()->UndefinedConstant(); |
609 values()->insert(values()->end(), locals_count(), undefined_constant); | 625 values()->insert(values()->end(), locals_count(), undefined_constant); |
610 } | 626 } |
611 | 627 |
612 | 628 |
613 AstGraphBuilder::Environment::Environment(AstGraphBuilder::Environment* copy) | 629 AstGraphBuilder::Environment::Environment(AstGraphBuilder::Environment* copy) |
(...skipping 2936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3550 // Phi does not exist yet, introduce one. | 3566 // Phi does not exist yet, introduce one. |
3551 value = NewPhi(inputs, value, control); | 3567 value = NewPhi(inputs, value, control); |
3552 value->ReplaceInput(inputs - 1, other); | 3568 value->ReplaceInput(inputs - 1, other); |
3553 } | 3569 } |
3554 return value; | 3570 return value; |
3555 } | 3571 } |
3556 | 3572 |
3557 } // namespace compiler | 3573 } // namespace compiler |
3558 } // namespace internal | 3574 } // namespace internal |
3559 } // namespace v8 | 3575 } // namespace v8 |
OLD | NEW |