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 5383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9020 // context as the entire expression. | 9030 // context as the entire expression. |
9021 if (eval_right->HasPredecessor()) { | 9031 if (eval_right->HasPredecessor()) { |
9022 eval_right->SetJoinId(expr->RightId()); | 9032 eval_right->SetJoinId(expr->RightId()); |
9023 set_current_block(eval_right); | 9033 set_current_block(eval_right); |
9024 Visit(expr->right()); | 9034 Visit(expr->right()); |
9025 } | 9035 } |
9026 | 9036 |
9027 } else if (ast_context()->IsValue()) { | 9037 } else if (ast_context()->IsValue()) { |
9028 CHECK_ALIVE(VisitForValue(expr->left())); | 9038 CHECK_ALIVE(VisitForValue(expr->left())); |
9029 ASSERT(current_block() != NULL); | 9039 ASSERT(current_block() != NULL); |
| 9040 HValue* left_value = Top(); |
| 9041 |
| 9042 if (left_value->IsConstant()) { |
| 9043 HConstant* left_constant = HConstant::cast(left_value); |
| 9044 if ((is_logical_and && left_constant->ToBoolean()) || |
| 9045 (!is_logical_and && !left_constant->ToBoolean())) { |
| 9046 Drop(1); // left_value. |
| 9047 CHECK_BAILOUT(VisitForValue(expr->right())); |
| 9048 } |
| 9049 return ast_context()->ReturnValue(Pop()); |
| 9050 } |
9030 | 9051 |
9031 // We need an extra block to maintain edge-split form. | 9052 // We need an extra block to maintain edge-split form. |
9032 HBasicBlock* empty_block = graph()->CreateBasicBlock(); | 9053 HBasicBlock* empty_block = graph()->CreateBasicBlock(); |
9033 HBasicBlock* eval_right = graph()->CreateBasicBlock(); | 9054 HBasicBlock* eval_right = graph()->CreateBasicBlock(); |
9034 TypeFeedbackId test_id = expr->left()->test_id(); | 9055 TypeFeedbackId test_id = expr->left()->test_id(); |
9035 ToBooleanStub::Types expected(oracle()->ToBooleanTypes(test_id)); | 9056 ToBooleanStub::Types expected(oracle()->ToBooleanTypes(test_id)); |
9036 HBranch* test = is_logical_and | 9057 HBranch* test = is_logical_and |
9037 ? new(zone()) HBranch(Top(), eval_right, empty_block, expected) | 9058 ? new(zone()) HBranch(left_value, eval_right, empty_block, expected) |
9038 : new(zone()) HBranch(Top(), empty_block, eval_right, expected); | 9059 : new(zone()) HBranch(left_value, empty_block, eval_right, expected); |
9039 current_block()->Finish(test); | 9060 current_block()->Finish(test); |
9040 | 9061 |
9041 set_current_block(eval_right); | 9062 set_current_block(eval_right); |
9042 Drop(1); // Value of the left subexpression. | 9063 Drop(1); // Value of the left subexpression. |
9043 CHECK_BAILOUT(VisitForValue(expr->right())); | 9064 CHECK_BAILOUT(VisitForValue(expr->right())); |
9044 | 9065 |
9045 HBasicBlock* join_block = | 9066 HBasicBlock* join_block = |
9046 CreateJoin(empty_block, current_block(), expr->id()); | 9067 CreateJoin(empty_block, current_block(), expr->id()); |
9047 set_current_block(join_block); | 9068 set_current_block(join_block); |
9048 return ast_context()->ReturnValue(Pop()); | 9069 return ast_context()->ReturnValue(Pop()); |
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10667 } | 10688 } |
10668 } | 10689 } |
10669 | 10690 |
10670 #ifdef DEBUG | 10691 #ifdef DEBUG |
10671 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 10692 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
10672 if (allocator_ != NULL) allocator_->Verify(); | 10693 if (allocator_ != NULL) allocator_->Verify(); |
10673 #endif | 10694 #endif |
10674 } | 10695 } |
10675 | 10696 |
10676 } } // namespace v8::internal | 10697 } } // namespace v8::internal |
OLD | NEW |