OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 3597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3608 | 3608 |
3609 void TestContext::BuildBranch(HValue* value) { | 3609 void TestContext::BuildBranch(HValue* value) { |
3610 // We expect the graph to be in edge-split form: there is no edge that | 3610 // We expect the graph to be in edge-split form: there is no edge that |
3611 // connects a branch node to a join node. We conservatively ensure that | 3611 // connects a branch node to a join node. We conservatively ensure that |
3612 // property by always adding an empty block on the outgoing edges of this | 3612 // property by always adding an empty block on the outgoing edges of this |
3613 // branch. | 3613 // branch. |
3614 HOptimizedGraphBuilder* builder = owner(); | 3614 HOptimizedGraphBuilder* builder = owner(); |
3615 if (value != NULL && value->CheckFlag(HValue::kIsArguments)) { | 3615 if (value != NULL && value->CheckFlag(HValue::kIsArguments)) { |
3616 builder->Bailout("arguments object value in a test context"); | 3616 builder->Bailout("arguments object value in a test context"); |
3617 } | 3617 } |
| 3618 if (value->IsConstant()) { |
| 3619 HConstant* constant_value = HConstant::cast(value); |
| 3620 if (constant_value->ToBoolean()) { |
| 3621 builder->current_block()->Goto(if_true(), builder->function_state()); |
| 3622 } else { |
| 3623 builder->current_block()->Goto(if_false(), builder->function_state()); |
| 3624 } |
| 3625 builder->set_current_block(NULL); |
| 3626 return; |
| 3627 } |
3618 HBasicBlock* empty_true = builder->graph()->CreateBasicBlock(); | 3628 HBasicBlock* empty_true = builder->graph()->CreateBasicBlock(); |
3619 HBasicBlock* empty_false = builder->graph()->CreateBasicBlock(); | 3629 HBasicBlock* empty_false = builder->graph()->CreateBasicBlock(); |
3620 TypeFeedbackId test_id = condition()->test_id(); | 3630 TypeFeedbackId test_id = condition()->test_id(); |
3621 ToBooleanStub::Types expected(oracle()->ToBooleanTypes(test_id)); | 3631 ToBooleanStub::Types expected(oracle()->ToBooleanTypes(test_id)); |
3622 HBranch* test = new(zone()) HBranch(value, empty_true, empty_false, expected); | 3632 HBranch* test = new(zone()) HBranch(value, empty_true, empty_false, expected); |
3623 builder->current_block()->Finish(test); | 3633 builder->current_block()->Finish(test); |
3624 | 3634 |
3625 empty_true->Goto(if_true(), owner()->function_state()); | 3635 empty_true->Goto(if_true(), builder->function_state()); |
3626 empty_false->Goto(if_false(), owner()->function_state()); | 3636 empty_false->Goto(if_false(), builder->function_state()); |
3627 builder->set_current_block(NULL); | 3637 builder->set_current_block(NULL); |
3628 } | 3638 } |
3629 | 3639 |
3630 | 3640 |
3631 // HOptimizedGraphBuilder infrastructure for bailing out and checking bailouts. | 3641 // HOptimizedGraphBuilder infrastructure for bailing out and checking bailouts. |
3632 #define CHECK_BAILOUT(call) \ | 3642 #define CHECK_BAILOUT(call) \ |
3633 do { \ | 3643 do { \ |
3634 call; \ | 3644 call; \ |
3635 if (HasStackOverflow()) return; \ | 3645 if (HasStackOverflow()) return; \ |
3636 } while (false) | 3646 } while (false) |
(...skipping 5388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9025 // context as the entire expression. | 9035 // context as the entire expression. |
9026 if (eval_right->HasPredecessor()) { | 9036 if (eval_right->HasPredecessor()) { |
9027 eval_right->SetJoinId(expr->RightId()); | 9037 eval_right->SetJoinId(expr->RightId()); |
9028 set_current_block(eval_right); | 9038 set_current_block(eval_right); |
9029 Visit(expr->right()); | 9039 Visit(expr->right()); |
9030 } | 9040 } |
9031 | 9041 |
9032 } else if (ast_context()->IsValue()) { | 9042 } else if (ast_context()->IsValue()) { |
9033 CHECK_ALIVE(VisitForValue(expr->left())); | 9043 CHECK_ALIVE(VisitForValue(expr->left())); |
9034 ASSERT(current_block() != NULL); | 9044 ASSERT(current_block() != NULL); |
| 9045 HValue* left_value = Top(); |
| 9046 |
| 9047 if (left_value->IsConstant()) { |
| 9048 HConstant* left_constant = HConstant::cast(left_value); |
| 9049 if ((is_logical_and && left_constant->ToBoolean()) || |
| 9050 (!is_logical_and && !left_constant->ToBoolean())) { |
| 9051 Drop(1); // left_value. |
| 9052 CHECK_BAILOUT(VisitForValue(expr->right())); |
| 9053 } |
| 9054 return ast_context()->ReturnValue(Pop()); |
| 9055 } |
9035 | 9056 |
9036 // We need an extra block to maintain edge-split form. | 9057 // We need an extra block to maintain edge-split form. |
9037 HBasicBlock* empty_block = graph()->CreateBasicBlock(); | 9058 HBasicBlock* empty_block = graph()->CreateBasicBlock(); |
9038 HBasicBlock* eval_right = graph()->CreateBasicBlock(); | 9059 HBasicBlock* eval_right = graph()->CreateBasicBlock(); |
9039 TypeFeedbackId test_id = expr->left()->test_id(); | 9060 TypeFeedbackId test_id = expr->left()->test_id(); |
9040 ToBooleanStub::Types expected(oracle()->ToBooleanTypes(test_id)); | 9061 ToBooleanStub::Types expected(oracle()->ToBooleanTypes(test_id)); |
9041 HBranch* test = is_logical_and | 9062 HBranch* test = is_logical_and |
9042 ? new(zone()) HBranch(Top(), eval_right, empty_block, expected) | 9063 ? new(zone()) HBranch(left_value, eval_right, empty_block, expected) |
9043 : new(zone()) HBranch(Top(), empty_block, eval_right, expected); | 9064 : new(zone()) HBranch(left_value, empty_block, eval_right, expected); |
9044 current_block()->Finish(test); | 9065 current_block()->Finish(test); |
9045 | 9066 |
9046 set_current_block(eval_right); | 9067 set_current_block(eval_right); |
9047 Drop(1); // Value of the left subexpression. | 9068 Drop(1); // Value of the left subexpression. |
9048 CHECK_BAILOUT(VisitForValue(expr->right())); | 9069 CHECK_BAILOUT(VisitForValue(expr->right())); |
9049 | 9070 |
9050 HBasicBlock* join_block = | 9071 HBasicBlock* join_block = |
9051 CreateJoin(empty_block, current_block(), expr->id()); | 9072 CreateJoin(empty_block, current_block(), expr->id()); |
9052 set_current_block(join_block); | 9073 set_current_block(join_block); |
9053 return ast_context()->ReturnValue(Pop()); | 9074 return ast_context()->ReturnValue(Pop()); |
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10672 } | 10693 } |
10673 } | 10694 } |
10674 | 10695 |
10675 #ifdef DEBUG | 10696 #ifdef DEBUG |
10676 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 10697 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
10677 if (allocator_ != NULL) allocator_->Verify(); | 10698 if (allocator_ != NULL) allocator_->Verify(); |
10678 #endif | 10699 #endif |
10679 } | 10700 } |
10680 | 10701 |
10681 } } // namespace v8::internal | 10702 } } // namespace v8::internal |
OLD | NEW |