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 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 int num_parameters = graph()->info()->num_parameters(); | 1001 int num_parameters = graph()->info()->num_parameters(); |
1002 HValue* params = AddInstruction(new(graph()->zone()) | 1002 HValue* params = AddInstruction(new(graph()->zone()) |
1003 HConstant(num_parameters)); | 1003 HConstant(num_parameters)); |
1004 HReturn* return_instruction = new(graph()->zone()) | 1004 HReturn* return_instruction = new(graph()->zone()) |
1005 HReturn(value, context, params); | 1005 HReturn(value, context, params); |
1006 current_block()->FinishExit(return_instruction); | 1006 current_block()->FinishExit(return_instruction); |
1007 return return_instruction; | 1007 return return_instruction; |
1008 } | 1008 } |
1009 | 1009 |
1010 | 1010 |
| 1011 void HGraphBuilder::AddSoftDeoptimize() { |
| 1012 if (FLAG_always_opt) return; |
| 1013 if (current_block()->IsDeoptimizing()) return; |
| 1014 AddInstruction(new(zone()) HSoftDeoptimize()); |
| 1015 current_block()->MarkAsDeoptimizing(); |
| 1016 graph()->set_has_soft_deoptimize(true); |
| 1017 } |
| 1018 |
| 1019 |
| 1020 // TODO(rossberg): this should die eventually. |
| 1021 Representation HGraphBuilder::ToRepresentation(TypeInfo info) { |
| 1022 if (info.IsUninitialized()) return Representation::None(); |
| 1023 // TODO(verwaest): Return Smi rather than Integer32. |
| 1024 if (info.IsSmi()) return Representation::Integer32(); |
| 1025 if (info.IsInteger32()) return Representation::Integer32(); |
| 1026 if (info.IsDouble()) return Representation::Double(); |
| 1027 if (info.IsNumber()) return Representation::Double(); |
| 1028 return Representation::Tagged(); |
| 1029 } |
| 1030 |
| 1031 |
| 1032 Representation HGraphBuilder::ToRepresentation(Handle<Type> type) { |
| 1033 if (type->Is(Type::None())) return Representation::None(); |
| 1034 if (type->Is(Type::Integer32())) return Representation::Integer32(); |
| 1035 if (type->Is(Type::Number())) return Representation::Double(); |
| 1036 return Representation::Tagged(); |
| 1037 } |
| 1038 |
| 1039 |
1011 HBasicBlock* HGraphBuilder::CreateBasicBlock(HEnvironment* env) { | 1040 HBasicBlock* HGraphBuilder::CreateBasicBlock(HEnvironment* env) { |
1012 HBasicBlock* b = graph()->CreateBasicBlock(); | 1041 HBasicBlock* b = graph()->CreateBasicBlock(); |
1013 b->SetInitialEnvironment(env); | 1042 b->SetInitialEnvironment(env); |
1014 return b; | 1043 return b; |
1015 } | 1044 } |
1016 | 1045 |
1017 | 1046 |
1018 HBasicBlock* HGraphBuilder::CreateLoopHeaderBlock() { | 1047 HBasicBlock* HGraphBuilder::CreateLoopHeaderBlock() { |
1019 HBasicBlock* header = graph()->CreateBasicBlock(); | 1048 HBasicBlock* header = graph()->CreateBasicBlock(); |
1020 HEnvironment* entry_env = environment()->CopyAsLoopHeader(header); | 1049 HEnvironment* entry_env = environment()->CopyAsLoopHeader(header); |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 key_constant, | 1700 key_constant, |
1672 value, | 1701 value, |
1673 kind)); | 1702 kind)); |
1674 } | 1703 } |
1675 } | 1704 } |
1676 | 1705 |
1677 return object; | 1706 return object; |
1678 } | 1707 } |
1679 | 1708 |
1680 | 1709 |
| 1710 HInstruction* HGraphBuilder::BuildSub( |
| 1711 HValue* value, Handle<Type> type, HValue* context) { |
| 1712 HInstruction* instr = |
| 1713 HMul::New(zone(), context, value, graph()->GetConstantMinus1()); |
| 1714 Representation rep = ToRepresentation(type); |
| 1715 if (type->Is(Type::None())) { |
| 1716 AddSoftDeoptimize(); |
| 1717 type = handle(Type::Any(), isolate()); |
| 1718 } |
| 1719 if (instr->IsBinaryOperation()) { |
| 1720 HBinaryOperation::cast(instr)->set_observed_input_representation(1, rep); |
| 1721 HBinaryOperation::cast(instr)->set_observed_input_representation(2, rep); |
| 1722 } |
| 1723 return instr; |
| 1724 } |
| 1725 |
| 1726 |
| 1727 HInstruction* HGraphBuilder::BuildBitNot(HValue* value, Handle<Type> type) { |
| 1728 if (type->Is(Type::None())) { |
| 1729 AddSoftDeoptimize(); |
| 1730 } |
| 1731 return new(zone()) HBitNot(value); |
| 1732 } |
| 1733 |
| 1734 |
1681 void HGraphBuilder::BuildCompareNil( | 1735 void HGraphBuilder::BuildCompareNil( |
1682 HValue* value, | 1736 HValue* value, |
1683 Handle<Type> type, | 1737 Handle<Type> type, |
1684 int position, | 1738 int position, |
1685 HIfContinuation* continuation) { | 1739 HIfContinuation* continuation) { |
1686 IfBuilder if_nil(this, position); | 1740 IfBuilder if_nil(this, position); |
1687 bool needs_or = false; | 1741 bool needs_or = false; |
1688 if (type->Maybe(Type::Null())) { | 1742 if (type->Maybe(Type::Null())) { |
1689 if (needs_or) if_nil.Or(); | 1743 if (needs_or) if_nil.Or(); |
1690 if_nil.If<HCompareObjectEqAndBranch>(value, graph()->GetConstantNull()); | 1744 if_nil.If<HCompareObjectEqAndBranch>(value, graph()->GetConstantNull()); |
(...skipping 2965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4656 current_block()->AddPhi(instr); | 4710 current_block()->AddPhi(instr); |
4657 } | 4711 } |
4658 | 4712 |
4659 | 4713 |
4660 void HOptimizedGraphBuilder::PushAndAdd(HInstruction* instr) { | 4714 void HOptimizedGraphBuilder::PushAndAdd(HInstruction* instr) { |
4661 Push(instr); | 4715 Push(instr); |
4662 AddInstruction(instr); | 4716 AddInstruction(instr); |
4663 } | 4717 } |
4664 | 4718 |
4665 | 4719 |
4666 void HOptimizedGraphBuilder::AddSoftDeoptimize() { | |
4667 if (FLAG_always_opt) return; | |
4668 if (current_block()->IsDeoptimizing()) return; | |
4669 AddInstruction(new(zone()) HSoftDeoptimize()); | |
4670 current_block()->MarkAsDeoptimizing(); | |
4671 graph()->set_has_soft_deoptimize(true); | |
4672 } | |
4673 | |
4674 | |
4675 template <class Instruction> | 4720 template <class Instruction> |
4676 HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) { | 4721 HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) { |
4677 int count = call->argument_count(); | 4722 int count = call->argument_count(); |
4678 ZoneList<HValue*> arguments(count, zone()); | 4723 ZoneList<HValue*> arguments(count, zone()); |
4679 for (int i = 0; i < count; ++i) { | 4724 for (int i = 0; i < count; ++i) { |
4680 arguments.Add(Pop(), zone()); | 4725 arguments.Add(Pop(), zone()); |
4681 } | 4726 } |
4682 | 4727 |
4683 while (!arguments.is_empty()) { | 4728 while (!arguments.is_empty()) { |
4684 AddInstruction(new(zone()) HPushArgument(arguments.RemoveLast())); | 4729 AddInstruction(new(zone()) HPushArgument(arguments.RemoveLast())); |
(...skipping 4340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9025 HValue* context = environment()->LookupContext(); | 9070 HValue* context = environment()->LookupContext(); |
9026 HInstruction* instr = new(zone()) HTypeof(context, value); | 9071 HInstruction* instr = new(zone()) HTypeof(context, value); |
9027 return ast_context()->ReturnInstruction(instr, expr->id()); | 9072 return ast_context()->ReturnInstruction(instr, expr->id()); |
9028 } | 9073 } |
9029 | 9074 |
9030 | 9075 |
9031 void HOptimizedGraphBuilder::VisitSub(UnaryOperation* expr) { | 9076 void HOptimizedGraphBuilder::VisitSub(UnaryOperation* expr) { |
9032 CHECK_ALIVE(VisitForValue(expr->expression())); | 9077 CHECK_ALIVE(VisitForValue(expr->expression())); |
9033 HValue* value = Pop(); | 9078 HValue* value = Pop(); |
9034 HValue* context = environment()->LookupContext(); | 9079 HValue* context = environment()->LookupContext(); |
9035 HInstruction* instr = | |
9036 HMul::New(zone(), context, value, graph()->GetConstantMinus1()); | |
9037 Handle<Type> type = expr->type(); | 9080 Handle<Type> type = expr->type(); |
9038 Representation rep = ToRepresentation(type); | 9081 HInstruction* instr = BuildSub(value, type, context); |
9039 if (type->Is(Type::None())) { | |
9040 AddSoftDeoptimize(); | |
9041 type = handle(Type::Any(), isolate()); | |
9042 } | |
9043 if (instr->IsBinaryOperation()) { | |
9044 HBinaryOperation::cast(instr)->set_observed_input_representation(1, rep); | |
9045 HBinaryOperation::cast(instr)->set_observed_input_representation(2, rep); | |
9046 } | |
9047 return ast_context()->ReturnInstruction(instr, expr->id()); | 9082 return ast_context()->ReturnInstruction(instr, expr->id()); |
9048 } | 9083 } |
9049 | 9084 |
9050 | 9085 |
9051 void HOptimizedGraphBuilder::VisitBitNot(UnaryOperation* expr) { | 9086 void HOptimizedGraphBuilder::VisitBitNot(UnaryOperation* expr) { |
9052 CHECK_ALIVE(VisitForValue(expr->expression())); | 9087 CHECK_ALIVE(VisitForValue(expr->expression())); |
9053 HValue* value = Pop(); | 9088 HValue* value = Pop(); |
9054 Handle<Type> info = expr->type(); | 9089 Handle<Type> info = expr->type(); |
9055 if (info->Is(Type::None())) { | 9090 HInstruction* instr = BuildBitNot(value, info); |
9056 AddSoftDeoptimize(); | |
9057 } | |
9058 HInstruction* instr = new(zone()) HBitNot(value); | |
9059 return ast_context()->ReturnInstruction(instr, expr->id()); | 9091 return ast_context()->ReturnInstruction(instr, expr->id()); |
9060 } | 9092 } |
9061 | 9093 |
9062 | 9094 |
9063 void HOptimizedGraphBuilder::VisitNot(UnaryOperation* expr) { | 9095 void HOptimizedGraphBuilder::VisitNot(UnaryOperation* expr) { |
9064 if (ast_context()->IsTest()) { | 9096 if (ast_context()->IsTest()) { |
9065 TestContext* context = TestContext::cast(ast_context()); | 9097 TestContext* context = TestContext::cast(ast_context()); |
9066 VisitForControl(expr->expression(), | 9098 VisitForControl(expr->expression(), |
9067 context->if_false(), | 9099 context->if_false(), |
9068 context->if_true()); | 9100 context->if_true()); |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9647 CHECK_ALIVE(VisitForValue(expr->left())); | 9679 CHECK_ALIVE(VisitForValue(expr->left())); |
9648 CHECK_ALIVE(VisitForValue(expr->right())); | 9680 CHECK_ALIVE(VisitForValue(expr->right())); |
9649 HValue* right = Pop(); | 9681 HValue* right = Pop(); |
9650 HValue* left = Pop(); | 9682 HValue* left = Pop(); |
9651 HInstruction* instr = BuildBinaryOperation(expr, left, right); | 9683 HInstruction* instr = BuildBinaryOperation(expr, left, right); |
9652 instr->set_position(expr->position()); | 9684 instr->set_position(expr->position()); |
9653 return ast_context()->ReturnInstruction(instr, expr->id()); | 9685 return ast_context()->ReturnInstruction(instr, expr->id()); |
9654 } | 9686 } |
9655 | 9687 |
9656 | 9688 |
9657 // TODO(rossberg): this should die eventually. | |
9658 Representation HOptimizedGraphBuilder::ToRepresentation(TypeInfo info) { | |
9659 if (info.IsUninitialized()) return Representation::None(); | |
9660 // TODO(verwaest): Return Smi rather than Integer32. | |
9661 if (info.IsSmi()) return Representation::Integer32(); | |
9662 if (info.IsInteger32()) return Representation::Integer32(); | |
9663 if (info.IsDouble()) return Representation::Double(); | |
9664 if (info.IsNumber()) return Representation::Double(); | |
9665 return Representation::Tagged(); | |
9666 } | |
9667 | |
9668 | |
9669 Representation HOptimizedGraphBuilder::ToRepresentation(Handle<Type> type) { | |
9670 if (type->Is(Type::None())) return Representation::None(); | |
9671 if (type->Is(Type::Integer32())) return Representation::Integer32(); | |
9672 if (type->Is(Type::Number())) return Representation::Double(); | |
9673 return Representation::Tagged(); | |
9674 } | |
9675 | |
9676 | |
9677 void HOptimizedGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr, | 9689 void HOptimizedGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr, |
9678 HTypeof* typeof_expr, | 9690 HTypeof* typeof_expr, |
9679 Handle<String> check) { | 9691 Handle<String> check) { |
9680 // Note: The HTypeof itself is removed during canonicalization, if possible. | 9692 // Note: The HTypeof itself is removed during canonicalization, if possible. |
9681 HValue* value = typeof_expr->value(); | 9693 HValue* value = typeof_expr->value(); |
9682 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check); | 9694 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check); |
9683 instr->set_position(expr->position()); | 9695 instr->set_position(expr->position()); |
9684 return ast_context()->ReturnControl(instr, expr->id()); | 9696 return ast_context()->ReturnControl(instr, expr->id()); |
9685 } | 9697 } |
9686 | 9698 |
(...skipping 1901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11588 } | 11600 } |
11589 } | 11601 } |
11590 | 11602 |
11591 #ifdef DEBUG | 11603 #ifdef DEBUG |
11592 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 11604 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
11593 if (allocator_ != NULL) allocator_->Verify(); | 11605 if (allocator_ != NULL) allocator_->Verify(); |
11594 #endif | 11606 #endif |
11595 } | 11607 } |
11596 | 11608 |
11597 } } // namespace v8::internal | 11609 } } // namespace v8::internal |
OLD | NEW |