| 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::BuildUnaryMathOp( | 
|  | 1711     HValue* input, Handle<Type> type, Token::Value operation) { | 
|  | 1712   // We only handle the numeric cases here | 
|  | 1713   type = handle( | 
|  | 1714       Type::Intersect(type, handle(Type::Number(), isolate())), isolate()); | 
|  | 1715 | 
|  | 1716   switch (operation) { | 
|  | 1717     default: | 
|  | 1718       UNREACHABLE(); | 
|  | 1719     case Token::SUB: { | 
|  | 1720         HInstruction* instr = | 
|  | 1721             HMul::New(zone(), environment()->LookupContext(), | 
|  | 1722                       input, graph()->GetConstantMinus1()); | 
|  | 1723         Representation rep = ToRepresentation(type); | 
|  | 1724         if (type->Is(Type::None())) { | 
|  | 1725           AddSoftDeoptimize(); | 
|  | 1726           type = handle(Type::Any(), isolate()); | 
|  | 1727         } | 
|  | 1728         if (instr->IsBinaryOperation()) { | 
|  | 1729           HBinaryOperation* binop = HBinaryOperation::cast(instr); | 
|  | 1730           binop->set_observed_input_representation(1, rep); | 
|  | 1731           binop->set_observed_input_representation(2, rep); | 
|  | 1732         } | 
|  | 1733         return instr; | 
|  | 1734       } | 
|  | 1735     case Token::BIT_NOT: | 
|  | 1736       if (type->Is(Type::None())) { | 
|  | 1737         AddSoftDeoptimize(); | 
|  | 1738       } | 
|  | 1739       return new(zone()) HBitNot(input); | 
|  | 1740   } | 
|  | 1741 } | 
|  | 1742 | 
|  | 1743 | 
| 1681 void HGraphBuilder::BuildCompareNil( | 1744 void HGraphBuilder::BuildCompareNil( | 
| 1682     HValue* value, | 1745     HValue* value, | 
| 1683     Handle<Type> type, | 1746     Handle<Type> type, | 
| 1684     int position, | 1747     int position, | 
| 1685     HIfContinuation* continuation) { | 1748     HIfContinuation* continuation) { | 
| 1686   IfBuilder if_nil(this, position); | 1749   IfBuilder if_nil(this, position); | 
| 1687   bool needs_or = false; | 1750   bool needs_or = false; | 
| 1688   if (type->Maybe(Type::Null())) { | 1751   if (type->Maybe(Type::Null())) { | 
| 1689     if (needs_or) if_nil.Or(); | 1752     if (needs_or) if_nil.Or(); | 
| 1690     if_nil.If<HCompareObjectEqAndBranch>(value, graph()->GetConstantNull()); | 1753     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); | 4719   current_block()->AddPhi(instr); | 
| 4657 } | 4720 } | 
| 4658 | 4721 | 
| 4659 | 4722 | 
| 4660 void HOptimizedGraphBuilder::PushAndAdd(HInstruction* instr) { | 4723 void HOptimizedGraphBuilder::PushAndAdd(HInstruction* instr) { | 
| 4661   Push(instr); | 4724   Push(instr); | 
| 4662   AddInstruction(instr); | 4725   AddInstruction(instr); | 
| 4663 } | 4726 } | 
| 4664 | 4727 | 
| 4665 | 4728 | 
| 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> | 4729 template <class Instruction> | 
| 4676 HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) { | 4730 HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) { | 
| 4677   int count = call->argument_count(); | 4731   int count = call->argument_count(); | 
| 4678   ZoneList<HValue*> arguments(count, zone()); | 4732   ZoneList<HValue*> arguments(count, zone()); | 
| 4679   for (int i = 0; i < count; ++i) { | 4733   for (int i = 0; i < count; ++i) { | 
| 4680     arguments.Add(Pop(), zone()); | 4734     arguments.Add(Pop(), zone()); | 
| 4681   } | 4735   } | 
| 4682 | 4736 | 
| 4683   while (!arguments.is_empty()) { | 4737   while (!arguments.is_empty()) { | 
| 4684     AddInstruction(new(zone()) HPushArgument(arguments.RemoveLast())); | 4738     AddInstruction(new(zone()) HPushArgument(arguments.RemoveLast())); | 
| (...skipping 4339 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 9024   HValue* value = Pop(); | 9078   HValue* value = Pop(); | 
| 9025   HValue* context = environment()->LookupContext(); | 9079   HValue* context = environment()->LookupContext(); | 
| 9026   HInstruction* instr = new(zone()) HTypeof(context, value); | 9080   HInstruction* instr = new(zone()) HTypeof(context, value); | 
| 9027   return ast_context()->ReturnInstruction(instr, expr->id()); | 9081   return ast_context()->ReturnInstruction(instr, expr->id()); | 
| 9028 } | 9082 } | 
| 9029 | 9083 | 
| 9030 | 9084 | 
| 9031 void HOptimizedGraphBuilder::VisitSub(UnaryOperation* expr) { | 9085 void HOptimizedGraphBuilder::VisitSub(UnaryOperation* expr) { | 
| 9032   CHECK_ALIVE(VisitForValue(expr->expression())); | 9086   CHECK_ALIVE(VisitForValue(expr->expression())); | 
| 9033   HValue* value = Pop(); | 9087   HValue* value = Pop(); | 
| 9034   HValue* context = environment()->LookupContext(); |  | 
| 9035   HInstruction* instr = |  | 
| 9036       HMul::New(zone(), context, value, graph()->GetConstantMinus1()); |  | 
| 9037   Handle<Type> type = expr->type(); | 9088   Handle<Type> type = expr->type(); | 
| 9038   Representation rep = ToRepresentation(type); | 9089   HInstruction* instr = BuildUnaryMathOp(value, type, Token::SUB); | 
| 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()); | 9090   return ast_context()->ReturnInstruction(instr, expr->id()); | 
| 9048 } | 9091 } | 
| 9049 | 9092 | 
| 9050 | 9093 | 
| 9051 void HOptimizedGraphBuilder::VisitBitNot(UnaryOperation* expr) { | 9094 void HOptimizedGraphBuilder::VisitBitNot(UnaryOperation* expr) { | 
| 9052   CHECK_ALIVE(VisitForValue(expr->expression())); | 9095   CHECK_ALIVE(VisitForValue(expr->expression())); | 
| 9053   HValue* value = Pop(); | 9096   HValue* value = Pop(); | 
| 9054   Handle<Type> info = expr->type(); | 9097   Handle<Type> info = expr->type(); | 
| 9055   if (info->Is(Type::None())) { | 9098   HInstruction* instr = BuildUnaryMathOp(value, info, Token::BIT_NOT); | 
| 9056     AddSoftDeoptimize(); |  | 
| 9057   } |  | 
| 9058   HInstruction* instr = new(zone()) HBitNot(value); |  | 
| 9059   return ast_context()->ReturnInstruction(instr, expr->id()); | 9099   return ast_context()->ReturnInstruction(instr, expr->id()); | 
| 9060 } | 9100 } | 
| 9061 | 9101 | 
| 9062 | 9102 | 
| 9063 void HOptimizedGraphBuilder::VisitNot(UnaryOperation* expr) { | 9103 void HOptimizedGraphBuilder::VisitNot(UnaryOperation* expr) { | 
| 9064   if (ast_context()->IsTest()) { | 9104   if (ast_context()->IsTest()) { | 
| 9065     TestContext* context = TestContext::cast(ast_context()); | 9105     TestContext* context = TestContext::cast(ast_context()); | 
| 9066     VisitForControl(expr->expression(), | 9106     VisitForControl(expr->expression(), | 
| 9067                     context->if_false(), | 9107                     context->if_false(), | 
| 9068                     context->if_true()); | 9108                     context->if_true()); | 
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 9647   CHECK_ALIVE(VisitForValue(expr->left())); | 9687   CHECK_ALIVE(VisitForValue(expr->left())); | 
| 9648   CHECK_ALIVE(VisitForValue(expr->right())); | 9688   CHECK_ALIVE(VisitForValue(expr->right())); | 
| 9649   HValue* right = Pop(); | 9689   HValue* right = Pop(); | 
| 9650   HValue* left = Pop(); | 9690   HValue* left = Pop(); | 
| 9651   HInstruction* instr = BuildBinaryOperation(expr, left, right); | 9691   HInstruction* instr = BuildBinaryOperation(expr, left, right); | 
| 9652   instr->set_position(expr->position()); | 9692   instr->set_position(expr->position()); | 
| 9653   return ast_context()->ReturnInstruction(instr, expr->id()); | 9693   return ast_context()->ReturnInstruction(instr, expr->id()); | 
| 9654 } | 9694 } | 
| 9655 | 9695 | 
| 9656 | 9696 | 
| 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, | 9697 void HOptimizedGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr, | 
| 9678                                                         HTypeof* typeof_expr, | 9698                                                         HTypeof* typeof_expr, | 
| 9679                                                         Handle<String> check) { | 9699                                                         Handle<String> check) { | 
| 9680   // Note: The HTypeof itself is removed during canonicalization, if possible. | 9700   // Note: The HTypeof itself is removed during canonicalization, if possible. | 
| 9681   HValue* value = typeof_expr->value(); | 9701   HValue* value = typeof_expr->value(); | 
| 9682   HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check); | 9702   HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check); | 
| 9683   instr->set_position(expr->position()); | 9703   instr->set_position(expr->position()); | 
| 9684   return ast_context()->ReturnControl(instr, expr->id()); | 9704   return ast_context()->ReturnControl(instr, expr->id()); | 
| 9685 } | 9705 } | 
| 9686 | 9706 | 
| (...skipping 1901 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 11588     } | 11608     } | 
| 11589   } | 11609   } | 
| 11590 | 11610 | 
| 11591 #ifdef DEBUG | 11611 #ifdef DEBUG | 
| 11592   if (graph_ != NULL) graph_->Verify(false);  // No full verify. | 11612   if (graph_ != NULL) graph_->Verify(false);  // No full verify. | 
| 11593   if (allocator_ != NULL) allocator_->Verify(); | 11613   if (allocator_ != NULL) allocator_->Verify(); | 
| 11594 #endif | 11614 #endif | 
| 11595 } | 11615 } | 
| 11596 | 11616 | 
| 11597 } }  // namespace v8::internal | 11617 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|