OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 5650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5661 | 5661 |
5662 Representation HGraphBuilder::ToRepresentation(TypeInfo info) { | 5662 Representation HGraphBuilder::ToRepresentation(TypeInfo info) { |
5663 if (info.IsSmi()) return Representation::Integer32(); | 5663 if (info.IsSmi()) return Representation::Integer32(); |
5664 if (info.IsInteger32()) return Representation::Integer32(); | 5664 if (info.IsInteger32()) return Representation::Integer32(); |
5665 if (info.IsDouble()) return Representation::Double(); | 5665 if (info.IsDouble()) return Representation::Double(); |
5666 if (info.IsNumber()) return Representation::Double(); | 5666 if (info.IsNumber()) return Representation::Double(); |
5667 return Representation::Tagged(); | 5667 return Representation::Tagged(); |
5668 } | 5668 } |
5669 | 5669 |
5670 | 5670 |
5671 void HGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* compare_expr, | 5671 void HGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr, |
5672 Expression* expr, | 5672 Expression* sub_expr, |
5673 Handle<String> check) { | 5673 Handle<String> check) { |
5674 CHECK_ALIVE(VisitForTypeOf(expr)); | 5674 CHECK_ALIVE(VisitForTypeOf(sub_expr)); |
5675 HValue* expr_value = Pop(); | 5675 HValue* value = Pop(); |
5676 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(expr_value, check); | 5676 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check); |
5677 instr->set_position(compare_expr->position()); | 5677 instr->set_position(expr->position()); |
5678 return ast_context()->ReturnControl(instr, compare_expr->id()); | 5678 return ast_context()->ReturnControl(instr, expr->id()); |
5679 } | 5679 } |
5680 | 5680 |
5681 | 5681 |
5682 void HGraphBuilder::HandleLiteralCompareUndefined( | 5682 bool HGraphBuilder::TryLiteralCompare(CompareOperation* expr) { |
5683 CompareOperation* compare_expr, Expression* expr) { | 5683 Expression *sub_expr; |
5684 CHECK_ALIVE(VisitForValue(expr)); | 5684 Handle<String> check; |
5685 HValue* lhs = Pop(); | 5685 if (expr->IsLiteralCompareTypeof(&sub_expr, &check)) { |
5686 HValue* rhs = graph()->GetConstantUndefined(); | 5686 HandleLiteralCompareTypeof(expr, sub_expr, check); |
5687 HCompareObjectEqAndBranch* instr = | 5687 return true; |
5688 new(zone()) HCompareObjectEqAndBranch(lhs, rhs); | 5688 } |
5689 instr->set_position(compare_expr->position()); | 5689 |
5690 return ast_context()->ReturnControl(instr, compare_expr->id()); | 5690 if (expr->IsLiteralCompareUndefined(&sub_expr)) { |
| 5691 HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue); |
| 5692 return true; |
| 5693 } |
| 5694 |
| 5695 if (expr->IsLiteralCompareNull(&sub_expr)) { |
| 5696 HandleLiteralCompareNil(expr, sub_expr, kNullValue); |
| 5697 return true; |
| 5698 } |
| 5699 |
| 5700 return false; |
5691 } | 5701 } |
5692 | 5702 |
5693 | 5703 |
5694 void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) { | 5704 void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) { |
5695 ASSERT(!HasStackOverflow()); | 5705 ASSERT(!HasStackOverflow()); |
5696 ASSERT(current_block() != NULL); | 5706 ASSERT(current_block() != NULL); |
5697 ASSERT(current_block()->HasPredecessor()); | 5707 ASSERT(current_block()->HasPredecessor()); |
5698 if (IsClassOfTest(expr)) { | 5708 if (IsClassOfTest(expr)) { |
5699 CallRuntime* call = expr->left()->AsCallRuntime(); | 5709 CallRuntime* call = expr->left()->AsCallRuntime(); |
5700 ASSERT(call->arguments()->length() == 1); | 5710 ASSERT(call->arguments()->length() == 1); |
5701 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | 5711 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
5702 HValue* value = Pop(); | 5712 HValue* value = Pop(); |
5703 Literal* literal = expr->right()->AsLiteral(); | 5713 Literal* literal = expr->right()->AsLiteral(); |
5704 Handle<String> rhs = Handle<String>::cast(literal->handle()); | 5714 Handle<String> rhs = Handle<String>::cast(literal->handle()); |
5705 HClassOfTestAndBranch* instr = | 5715 HClassOfTestAndBranch* instr = |
5706 new(zone()) HClassOfTestAndBranch(value, rhs); | 5716 new(zone()) HClassOfTestAndBranch(value, rhs); |
5707 instr->set_position(expr->position()); | 5717 instr->set_position(expr->position()); |
5708 return ast_context()->ReturnControl(instr, expr->id()); | 5718 return ast_context()->ReturnControl(instr, expr->id()); |
5709 } | 5719 } |
5710 | 5720 |
5711 // Check for special cases that compare against literals. | 5721 // Check for special cases that compare against literals. |
5712 Expression *sub_expr; | 5722 if (TryLiteralCompare(expr)) return; |
5713 Handle<String> check; | |
5714 if (expr->IsLiteralCompareTypeof(&sub_expr, &check)) { | |
5715 HandleLiteralCompareTypeof(expr, sub_expr, check); | |
5716 return; | |
5717 } | |
5718 | |
5719 if (expr->IsLiteralCompareUndefined(&sub_expr)) { | |
5720 HandleLiteralCompareUndefined(expr, sub_expr); | |
5721 return; | |
5722 } | |
5723 | |
5724 if (expr->IsLiteralCompareNull(&sub_expr)) { | |
5725 HandleLiteralCompareNull(expr, sub_expr); | |
5726 return; | |
5727 } | |
5728 | 5723 |
5729 TypeInfo type_info = oracle()->CompareType(expr); | 5724 TypeInfo type_info = oracle()->CompareType(expr); |
5730 // Check if this expression was ever executed according to type feedback. | 5725 // Check if this expression was ever executed according to type feedback. |
5731 if (type_info.IsUninitialized()) { | 5726 if (type_info.IsUninitialized()) { |
5732 AddInstruction(new(zone()) HSoftDeoptimize); | 5727 AddInstruction(new(zone()) HSoftDeoptimize); |
5733 current_block()->MarkAsDeoptimizing(); | 5728 current_block()->MarkAsDeoptimizing(); |
5734 type_info = TypeInfo::Unknown(); | 5729 type_info = TypeInfo::Unknown(); |
5735 } | 5730 } |
5736 | 5731 |
5737 CHECK_ALIVE(VisitForValue(expr->left())); | 5732 CHECK_ALIVE(VisitForValue(expr->left())); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5822 HCompareIDAndBranch* result = | 5817 HCompareIDAndBranch* result = |
5823 new(zone()) HCompareIDAndBranch(left, right, op); | 5818 new(zone()) HCompareIDAndBranch(left, right, op); |
5824 result->set_position(expr->position()); | 5819 result->set_position(expr->position()); |
5825 result->SetInputRepresentation(r); | 5820 result->SetInputRepresentation(r); |
5826 return ast_context()->ReturnControl(result, expr->id()); | 5821 return ast_context()->ReturnControl(result, expr->id()); |
5827 } | 5822 } |
5828 } | 5823 } |
5829 } | 5824 } |
5830 | 5825 |
5831 | 5826 |
5832 void HGraphBuilder::HandleLiteralCompareNull(CompareOperation* compare_expr, | 5827 void HGraphBuilder::HandleLiteralCompareNil(CompareOperation* expr, |
5833 Expression* expr) { | 5828 Expression* sub_expr, |
| 5829 NilValue nil) { |
5834 ASSERT(!HasStackOverflow()); | 5830 ASSERT(!HasStackOverflow()); |
5835 ASSERT(current_block() != NULL); | 5831 ASSERT(current_block() != NULL); |
5836 ASSERT(current_block()->HasPredecessor()); | 5832 ASSERT(current_block()->HasPredecessor()); |
5837 CHECK_ALIVE(VisitForValue(expr)); | 5833 CHECK_ALIVE(VisitForValue(sub_expr)); |
5838 HValue* value = Pop(); | 5834 HValue* value = Pop(); |
5839 bool is_strict = compare_expr->op() == Token::EQ_STRICT; | 5835 EqualityKind kind = |
5840 HIsNullAndBranch* instr = new(zone()) HIsNullAndBranch(value, is_strict); | 5836 expr->op() == Token::EQ_STRICT ? kStrictEquality : kNonStrictEquality; |
5841 return ast_context()->ReturnControl(instr, compare_expr->id()); | 5837 HIsNilAndBranch* instr = new(zone()) HIsNilAndBranch(value, kind, nil); |
| 5838 instr->set_position(expr->position()); |
| 5839 return ast_context()->ReturnControl(instr, expr->id()); |
5842 } | 5840 } |
5843 | 5841 |
5844 | 5842 |
5845 void HGraphBuilder::VisitThisFunction(ThisFunction* expr) { | 5843 void HGraphBuilder::VisitThisFunction(ThisFunction* expr) { |
5846 ASSERT(!HasStackOverflow()); | 5844 ASSERT(!HasStackOverflow()); |
5847 ASSERT(current_block() != NULL); | 5845 ASSERT(current_block() != NULL); |
5848 ASSERT(current_block()->HasPredecessor()); | 5846 ASSERT(current_block()->HasPredecessor()); |
5849 HThisFunction* self = new(zone()) HThisFunction; | 5847 HThisFunction* self = new(zone()) HThisFunction; |
5850 return ast_context()->ReturnInstruction(self, expr->id()); | 5848 return ast_context()->ReturnInstruction(self, expr->id()); |
5851 } | 5849 } |
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6821 } | 6819 } |
6822 } | 6820 } |
6823 | 6821 |
6824 #ifdef DEBUG | 6822 #ifdef DEBUG |
6825 if (graph_ != NULL) graph_->Verify(); | 6823 if (graph_ != NULL) graph_->Verify(); |
6826 if (allocator_ != NULL) allocator_->Verify(); | 6824 if (allocator_ != NULL) allocator_->Verify(); |
6827 #endif | 6825 #endif |
6828 } | 6826 } |
6829 | 6827 |
6830 } } // namespace v8::internal | 6828 } } // namespace v8::internal |
OLD | NEW |