OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 if (scope->is_function_scope() && scope->function() != NULL) { | 64 if (scope->is_function_scope() && scope->function() != NULL) { |
65 RECURSE(visitor->VisitVariableDeclaration(scope->function())); | 65 RECURSE(visitor->VisitVariableDeclaration(scope->function())); |
66 } | 66 } |
67 RECURSE(visitor->VisitDeclarations(scope->declarations())); | 67 RECURSE(visitor->VisitDeclarations(scope->declarations())); |
68 RECURSE(visitor->VisitStatements(info->function()->body())); | 68 RECURSE(visitor->VisitStatements(info->function()->body())); |
69 } | 69 } |
70 | 70 |
71 #undef RECURSE | 71 #undef RECURSE |
72 | 72 |
73 | 73 |
74 Effect AstTyper::ObservedOnStack(Object* value) { | |
75 Type* lower = Type::OfCurrently(Handle<Object>(value, isolate())); | |
76 return Effect(Bounds(lower, Type::Any(), isolate())); | |
77 } | |
78 | |
79 | |
80 #ifdef OBJECT_PRINT | 74 #ifdef OBJECT_PRINT |
81 static void PrintObserved(Variable* var, Object* value, Handle<Type> type) { | 75 static void PrintObserved(Variable* var, Object* value, Handle<Type> type) { |
82 PrintF(" observed %s ", var->IsParameter() ? "param" : "local"); | 76 PrintF(" observed %s ", var->IsParameter() ? "param" : "local"); |
83 var->name()->Print(); | 77 var->name()->Print(); |
84 PrintF(" : "); | 78 PrintF(" : "); |
85 value->ShortPrint(); | 79 value->ShortPrint(); |
86 PrintF(" -> "); | 80 PrintF(" -> "); |
87 type->TypePrint(); | 81 type->TypePrint(); |
88 } | 82 } |
89 #endif // OBJECT_PRINT | 83 #endif // OBJECT_PRINT |
90 | 84 |
91 | 85 |
| 86 Effect AstTyper::ObservedOnStack(Object* value) { |
| 87 Handle<Type> lower = Type::OfCurrently(handle(value, isolate()), isolate()); |
| 88 return Effect(Bounds(lower, Type::Any(isolate()))); |
| 89 } |
| 90 |
| 91 |
92 void AstTyper::ObserveTypesAtOsrEntry(IterationStatement* stmt) { | 92 void AstTyper::ObserveTypesAtOsrEntry(IterationStatement* stmt) { |
93 if (stmt->OsrEntryId() != info_->osr_ast_id()) return; | 93 if (stmt->OsrEntryId() != info_->osr_ast_id()) return; |
94 | 94 |
95 DisallowHeapAllocation no_gc; | 95 DisallowHeapAllocation no_gc; |
96 JavaScriptFrameIterator it(isolate()); | 96 JavaScriptFrameIterator it(isolate()); |
97 JavaScriptFrame* frame = it.frame(); | 97 JavaScriptFrame* frame = it.frame(); |
98 Scope* scope = info_->scope(); | 98 Scope* scope = info_->scope(); |
99 | 99 |
100 // Assert that the frame on the stack belongs to the function we want to OSR. | 100 // Assert that the frame on the stack belongs to the function we want to OSR. |
101 ASSERT_EQ(*info_->closure(), frame->function()); | 101 ASSERT_EQ(*info_->closure(), frame->function()); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 398 |
399 void AstTyper::VisitVariableProxy(VariableProxy* expr) { | 399 void AstTyper::VisitVariableProxy(VariableProxy* expr) { |
400 Variable* var = expr->var(); | 400 Variable* var = expr->var(); |
401 if (var->IsStackAllocated()) { | 401 if (var->IsStackAllocated()) { |
402 NarrowType(expr, store_.LookupBounds(variable_index(var))); | 402 NarrowType(expr, store_.LookupBounds(variable_index(var))); |
403 } | 403 } |
404 } | 404 } |
405 | 405 |
406 | 406 |
407 void AstTyper::VisitLiteral(Literal* expr) { | 407 void AstTyper::VisitLiteral(Literal* expr) { |
408 Type* type = Type::Constant(expr->value(), isolate_); | 408 Handle<Type> type = Type::Constant(expr->value(), isolate_); |
409 NarrowType(expr, Bounds(type, isolate_)); | 409 NarrowType(expr, Bounds(type)); |
410 } | 410 } |
411 | 411 |
412 | 412 |
413 void AstTyper::VisitRegExpLiteral(RegExpLiteral* expr) { | 413 void AstTyper::VisitRegExpLiteral(RegExpLiteral* expr) { |
414 NarrowType(expr, Bounds(Type::RegExp(), isolate_)); | 414 NarrowType(expr, Bounds(Type::RegExp(isolate_))); |
415 } | 415 } |
416 | 416 |
417 | 417 |
418 void AstTyper::VisitObjectLiteral(ObjectLiteral* expr) { | 418 void AstTyper::VisitObjectLiteral(ObjectLiteral* expr) { |
419 ZoneList<ObjectLiteral::Property*>* properties = expr->properties(); | 419 ZoneList<ObjectLiteral::Property*>* properties = expr->properties(); |
420 for (int i = 0; i < properties->length(); ++i) { | 420 for (int i = 0; i < properties->length(); ++i) { |
421 ObjectLiteral::Property* prop = properties->at(i); | 421 ObjectLiteral::Property* prop = properties->at(i); |
422 | 422 |
423 // Collect type feedback. | 423 // Collect type feedback. |
424 if ((prop->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL && | 424 if ((prop->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL && |
425 !CompileTimeValue::IsCompileTimeValue(prop->value())) || | 425 !CompileTimeValue::IsCompileTimeValue(prop->value())) || |
426 prop->kind() == ObjectLiteral::Property::COMPUTED) { | 426 prop->kind() == ObjectLiteral::Property::COMPUTED) { |
427 if (prop->key()->value()->IsInternalizedString() && prop->emit_store()) { | 427 if (prop->key()->value()->IsInternalizedString() && prop->emit_store()) { |
428 prop->RecordTypeFeedback(oracle()); | 428 prop->RecordTypeFeedback(oracle()); |
429 } | 429 } |
430 } | 430 } |
431 | 431 |
432 RECURSE(Visit(prop->value())); | 432 RECURSE(Visit(prop->value())); |
433 } | 433 } |
434 | 434 |
435 NarrowType(expr, Bounds(Type::Object(), isolate_)); | 435 NarrowType(expr, Bounds(Type::Object(isolate_))); |
436 } | 436 } |
437 | 437 |
438 | 438 |
439 void AstTyper::VisitArrayLiteral(ArrayLiteral* expr) { | 439 void AstTyper::VisitArrayLiteral(ArrayLiteral* expr) { |
440 ZoneList<Expression*>* values = expr->values(); | 440 ZoneList<Expression*>* values = expr->values(); |
441 for (int i = 0; i < values->length(); ++i) { | 441 for (int i = 0; i < values->length(); ++i) { |
442 Expression* value = values->at(i); | 442 Expression* value = values->at(i); |
443 RECURSE(Visit(value)); | 443 RECURSE(Visit(value)); |
444 } | 444 } |
445 | 445 |
446 NarrowType(expr, Bounds(Type::Array(), isolate_)); | 446 NarrowType(expr, Bounds(Type::Array(isolate_))); |
447 } | 447 } |
448 | 448 |
449 | 449 |
450 void AstTyper::VisitAssignment(Assignment* expr) { | 450 void AstTyper::VisitAssignment(Assignment* expr) { |
451 // Collect type feedback. | 451 // Collect type feedback. |
452 Property* prop = expr->target()->AsProperty(); | 452 Property* prop = expr->target()->AsProperty(); |
453 if (prop != NULL) { | 453 if (prop != NULL) { |
454 TypeFeedbackId id = expr->AssignmentFeedbackId(); | 454 TypeFeedbackId id = expr->AssignmentFeedbackId(); |
455 expr->set_is_uninitialized(oracle()->StoreIsUninitialized(id)); | 455 expr->set_is_uninitialized(oracle()->StoreIsUninitialized(id)); |
456 if (!expr->IsUninitialized()) { | 456 if (!expr->IsUninitialized()) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 RECURSE(Visit(expr->expression())); | 488 RECURSE(Visit(expr->expression())); |
489 | 489 |
490 // We don't know anything about the result type. | 490 // We don't know anything about the result type. |
491 } | 491 } |
492 | 492 |
493 | 493 |
494 void AstTyper::VisitThrow(Throw* expr) { | 494 void AstTyper::VisitThrow(Throw* expr) { |
495 RECURSE(Visit(expr->exception())); | 495 RECURSE(Visit(expr->exception())); |
496 // TODO(rossberg): is it worth having a non-termination effect? | 496 // TODO(rossberg): is it worth having a non-termination effect? |
497 | 497 |
498 NarrowType(expr, Bounds(Type::None(), isolate_)); | 498 NarrowType(expr, Bounds(Type::None(isolate_))); |
499 } | 499 } |
500 | 500 |
501 | 501 |
502 void AstTyper::VisitProperty(Property* expr) { | 502 void AstTyper::VisitProperty(Property* expr) { |
503 // Collect type feedback. | 503 // Collect type feedback. |
504 TypeFeedbackId id = expr->PropertyFeedbackId(); | 504 TypeFeedbackId id = expr->PropertyFeedbackId(); |
505 expr->set_is_uninitialized(oracle()->LoadIsUninitialized(id)); | 505 expr->set_is_uninitialized(oracle()->LoadIsUninitialized(id)); |
506 if (!expr->IsUninitialized()) { | 506 if (!expr->IsUninitialized()) { |
507 expr->set_is_pre_monomorphic(oracle()->LoadIsPreMonomorphic(id)); | 507 expr->set_is_pre_monomorphic(oracle()->LoadIsPreMonomorphic(id)); |
508 if (expr->key()->IsPropertyName()) { | 508 if (expr->key()->IsPropertyName()) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 if (expr->op() == Token::NOT) { | 586 if (expr->op() == Token::NOT) { |
587 // TODO(rossberg): only do in test or value context. | 587 // TODO(rossberg): only do in test or value context. |
588 expr->expression()->RecordToBooleanTypeFeedback(oracle()); | 588 expr->expression()->RecordToBooleanTypeFeedback(oracle()); |
589 } | 589 } |
590 | 590 |
591 RECURSE(Visit(expr->expression())); | 591 RECURSE(Visit(expr->expression())); |
592 | 592 |
593 switch (expr->op()) { | 593 switch (expr->op()) { |
594 case Token::NOT: | 594 case Token::NOT: |
595 case Token::DELETE: | 595 case Token::DELETE: |
596 NarrowType(expr, Bounds(Type::Boolean(), isolate_)); | 596 NarrowType(expr, Bounds(Type::Boolean(isolate_))); |
597 break; | 597 break; |
598 case Token::VOID: | 598 case Token::VOID: |
599 NarrowType(expr, Bounds(Type::Undefined(), isolate_)); | 599 NarrowType(expr, Bounds(Type::Undefined(isolate_))); |
600 break; | 600 break; |
601 case Token::TYPEOF: | 601 case Token::TYPEOF: |
602 NarrowType(expr, Bounds(Type::InternalizedString(), isolate_)); | 602 NarrowType(expr, Bounds(Type::InternalizedString(isolate_))); |
603 break; | 603 break; |
604 default: | 604 default: |
605 UNREACHABLE(); | 605 UNREACHABLE(); |
606 } | 606 } |
607 } | 607 } |
608 | 608 |
609 | 609 |
610 void AstTyper::VisitCountOperation(CountOperation* expr) { | 610 void AstTyper::VisitCountOperation(CountOperation* expr) { |
611 // Collect type feedback. | 611 // Collect type feedback. |
612 TypeFeedbackId store_id = expr->CountStoreFeedbackId(); | 612 TypeFeedbackId store_id = expr->CountStoreFeedbackId(); |
613 expr->set_store_mode(oracle()->GetStoreMode(store_id)); | 613 expr->set_store_mode(oracle()->GetStoreMode(store_id)); |
614 oracle()->CountReceiverTypes(store_id, expr->GetReceiverTypes()); | 614 oracle()->CountReceiverTypes(store_id, expr->GetReceiverTypes()); |
615 expr->set_type(oracle()->CountType(expr->CountBinOpFeedbackId())); | 615 expr->set_type(oracle()->CountType(expr->CountBinOpFeedbackId())); |
616 // TODO(rossberg): merge the count type with the generic expression type. | 616 // TODO(rossberg): merge the count type with the generic expression type. |
617 | 617 |
618 RECURSE(Visit(expr->expression())); | 618 RECURSE(Visit(expr->expression())); |
619 | 619 |
620 NarrowType(expr, Bounds(Type::Smi(), Type::Number(), isolate_)); | 620 NarrowType(expr, Bounds(Type::Smi(isolate_), Type::Number(isolate_))); |
621 | 621 |
622 VariableProxy* proxy = expr->expression()->AsVariableProxy(); | 622 VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
623 if (proxy != NULL && proxy->var()->IsStackAllocated()) { | 623 if (proxy != NULL && proxy->var()->IsStackAllocated()) { |
624 store_.Seq(variable_index(proxy->var()), Effect(expr->bounds())); | 624 store_.Seq(variable_index(proxy->var()), Effect(expr->bounds())); |
625 } | 625 } |
626 } | 626 } |
627 | 627 |
628 | 628 |
629 void AstTyper::VisitBinaryOperation(BinaryOperation* expr) { | 629 void AstTyper::VisitBinaryOperation(BinaryOperation* expr) { |
630 // Collect type feedback. | 630 // Collect type feedback. |
(...skipping 30 matching lines...) Expand all Loading... |
661 store_.Seq(left_effects); | 661 store_.Seq(left_effects); |
662 | 662 |
663 NarrowType(expr, Bounds::Either( | 663 NarrowType(expr, Bounds::Either( |
664 expr->left()->bounds(), expr->right()->bounds(), isolate_)); | 664 expr->left()->bounds(), expr->right()->bounds(), isolate_)); |
665 break; | 665 break; |
666 } | 666 } |
667 case Token::BIT_OR: | 667 case Token::BIT_OR: |
668 case Token::BIT_AND: { | 668 case Token::BIT_AND: { |
669 RECURSE(Visit(expr->left())); | 669 RECURSE(Visit(expr->left())); |
670 RECURSE(Visit(expr->right())); | 670 RECURSE(Visit(expr->right())); |
671 Handle<Type> upper( | 671 Handle<Type> upper = Type::Union( |
672 Type::Union( | 672 expr->left()->bounds().upper, expr->right()->bounds().upper, |
673 expr->left()->bounds().upper, expr->right()->bounds().upper), | |
674 isolate_); | 673 isolate_); |
675 if (!upper->Is(Type::Signed32())) | 674 if (!upper->Is(Type::Signed32())) |
676 upper = handle(Type::Signed32(), isolate_); | 675 upper = Type::Signed32(isolate_); |
677 Handle<Type> lower(Type::Intersect( | 676 Handle<Type> lower = |
678 handle(Type::Smi(), isolate_), upper), isolate_); | 677 Type::Intersect(Type::Smi(isolate_), upper, isolate_); |
679 NarrowType(expr, Bounds(lower, upper)); | 678 NarrowType(expr, Bounds(lower, upper)); |
680 break; | 679 break; |
681 } | 680 } |
682 case Token::BIT_XOR: | 681 case Token::BIT_XOR: |
683 case Token::SHL: | 682 case Token::SHL: |
684 case Token::SAR: | 683 case Token::SAR: |
685 RECURSE(Visit(expr->left())); | 684 RECURSE(Visit(expr->left())); |
686 RECURSE(Visit(expr->right())); | 685 RECURSE(Visit(expr->right())); |
687 NarrowType(expr, Bounds(Type::Smi(), Type::Signed32(), isolate_)); | 686 NarrowType(expr, Bounds(Type::Smi(isolate_), Type::Signed32(isolate_))); |
688 break; | 687 break; |
689 case Token::SHR: | 688 case Token::SHR: |
690 RECURSE(Visit(expr->left())); | 689 RECURSE(Visit(expr->left())); |
691 RECURSE(Visit(expr->right())); | 690 RECURSE(Visit(expr->right())); |
692 // TODO(rossberg): The upper bound would be Unsigned32, but since there | 691 // TODO(rossberg): The upper bound would be Unsigned32, but since there |
693 // is no 'positive Smi' type for the lower bound, we use the smallest | 692 // is no 'positive Smi' type for the lower bound, we use the smallest |
694 // union of Smi and Unsigned32 as upper bound instead. | 693 // union of Smi and Unsigned32 as upper bound instead. |
695 NarrowType(expr, Bounds(Type::Smi(), Type::Number(), isolate_)); | 694 NarrowType(expr, Bounds(Type::Smi(isolate_), Type::Number(isolate_))); |
696 break; | 695 break; |
697 case Token::ADD: { | 696 case Token::ADD: { |
698 RECURSE(Visit(expr->left())); | 697 RECURSE(Visit(expr->left())); |
699 RECURSE(Visit(expr->right())); | 698 RECURSE(Visit(expr->right())); |
700 Bounds l = expr->left()->bounds(); | 699 Bounds l = expr->left()->bounds(); |
701 Bounds r = expr->right()->bounds(); | 700 Bounds r = expr->right()->bounds(); |
702 Type* lower = | 701 Handle<Type> lower = |
703 l.lower->Is(Type::None()) || r.lower->Is(Type::None()) ? | 702 l.lower->Is(Type::None()) || r.lower->Is(Type::None()) ? |
704 Type::None() : | 703 Type::None(isolate_) : |
705 l.lower->Is(Type::String()) || r.lower->Is(Type::String()) ? | 704 l.lower->Is(Type::String()) || r.lower->Is(Type::String()) ? |
706 Type::String() : | 705 Type::String(isolate_) : |
707 l.lower->Is(Type::Number()) && r.lower->Is(Type::Number()) ? | 706 l.lower->Is(Type::Number()) && r.lower->Is(Type::Number()) ? |
708 Type::Smi() : Type::None(); | 707 Type::Smi(isolate_) : Type::None(isolate_); |
709 Type* upper = | 708 Handle<Type> upper = |
710 l.upper->Is(Type::String()) || r.upper->Is(Type::String()) ? | 709 l.upper->Is(Type::String()) || r.upper->Is(Type::String()) ? |
711 Type::String() : | 710 Type::String(isolate_) : |
712 l.upper->Is(Type::Number()) && r.upper->Is(Type::Number()) ? | 711 l.upper->Is(Type::Number()) && r.upper->Is(Type::Number()) ? |
713 Type::Number() : Type::NumberOrString(); | 712 Type::Number(isolate_) : Type::NumberOrString(isolate_); |
714 NarrowType(expr, Bounds(lower, upper, isolate_)); | 713 NarrowType(expr, Bounds(lower, upper)); |
715 break; | 714 break; |
716 } | 715 } |
717 case Token::SUB: | 716 case Token::SUB: |
718 case Token::MUL: | 717 case Token::MUL: |
719 case Token::DIV: | 718 case Token::DIV: |
720 case Token::MOD: | 719 case Token::MOD: |
721 RECURSE(Visit(expr->left())); | 720 RECURSE(Visit(expr->left())); |
722 RECURSE(Visit(expr->right())); | 721 RECURSE(Visit(expr->right())); |
723 NarrowType(expr, Bounds(Type::Smi(), Type::Number(), isolate_)); | 722 NarrowType(expr, Bounds(Type::Smi(isolate_), Type::Number(isolate_))); |
724 break; | 723 break; |
725 default: | 724 default: |
726 UNREACHABLE(); | 725 UNREACHABLE(); |
727 } | 726 } |
728 } | 727 } |
729 | 728 |
730 | 729 |
731 void AstTyper::VisitCompareOperation(CompareOperation* expr) { | 730 void AstTyper::VisitCompareOperation(CompareOperation* expr) { |
732 // Collect type feedback. | 731 // Collect type feedback. |
733 Handle<Type> left_type, right_type, combined_type; | 732 Handle<Type> left_type, right_type, combined_type; |
734 oracle()->CompareType(expr->CompareOperationFeedbackId(), | 733 oracle()->CompareType(expr->CompareOperationFeedbackId(), |
735 &left_type, &right_type, &combined_type); | 734 &left_type, &right_type, &combined_type); |
736 NarrowLowerType(expr->left(), left_type); | 735 NarrowLowerType(expr->left(), left_type); |
737 NarrowLowerType(expr->right(), right_type); | 736 NarrowLowerType(expr->right(), right_type); |
738 expr->set_combined_type(combined_type); | 737 expr->set_combined_type(combined_type); |
739 | 738 |
740 RECURSE(Visit(expr->left())); | 739 RECURSE(Visit(expr->left())); |
741 RECURSE(Visit(expr->right())); | 740 RECURSE(Visit(expr->right())); |
742 | 741 |
743 NarrowType(expr, Bounds(Type::Boolean(), isolate_)); | 742 NarrowType(expr, Bounds(Type::Boolean(isolate_))); |
744 } | 743 } |
745 | 744 |
746 | 745 |
747 void AstTyper::VisitThisFunction(ThisFunction* expr) { | 746 void AstTyper::VisitThisFunction(ThisFunction* expr) { |
748 } | 747 } |
749 | 748 |
750 | 749 |
751 void AstTyper::VisitDeclarations(ZoneList<Declaration*>* decls) { | 750 void AstTyper::VisitDeclarations(ZoneList<Declaration*>* decls) { |
752 for (int i = 0; i < decls->length(); ++i) { | 751 for (int i = 0; i < decls->length(); ++i) { |
753 Declaration* decl = decls->at(i); | 752 Declaration* decl = decls->at(i); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 void AstTyper::VisitModuleUrl(ModuleUrl* module) { | 795 void AstTyper::VisitModuleUrl(ModuleUrl* module) { |
797 } | 796 } |
798 | 797 |
799 | 798 |
800 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { | 799 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { |
801 RECURSE(Visit(stmt->body())); | 800 RECURSE(Visit(stmt->body())); |
802 } | 801 } |
803 | 802 |
804 | 803 |
805 } } // namespace v8::internal | 804 } } // namespace v8::internal |
OLD | NEW |