| 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 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 if (!pointer->is_set()) { | 572 if (!pointer->is_set()) { |
| 573 HConstant* constant = new(zone()) HConstant(value, | 573 HConstant* constant = new(zone()) HConstant(value, |
| 574 Representation::Tagged()); | 574 Representation::Tagged()); |
| 575 constant->InsertAfter(GetConstantUndefined()); | 575 constant->InsertAfter(GetConstantUndefined()); |
| 576 pointer->set(constant); | 576 pointer->set(constant); |
| 577 } | 577 } |
| 578 return pointer->get(); | 578 return pointer->get(); |
| 579 } | 579 } |
| 580 | 580 |
| 581 | 581 |
| 582 HConstant* HGraph::GetConstantInt32(SetOncePointer<HConstant>* pointer, |
| 583 int32_t value) { |
| 584 if (!pointer->is_set()) { |
| 585 HConstant* constant = new(zone()) HConstant(value, |
| 586 Representation::Integer32(), |
| 587 Handle<Object>::null()); |
| 588 constant->InsertAfter(GetConstantUndefined()); |
| 589 pointer->set(constant); |
| 590 } |
| 591 return pointer->get(); |
| 592 } |
| 593 |
| 594 |
| 582 HConstant* HGraph::GetConstant1() { | 595 HConstant* HGraph::GetConstant1() { |
| 583 return GetConstant(&constant_1_, Handle<Smi>(Smi::FromInt(1))); | 596 return GetConstantInt32(&constant_1_, 1); |
| 584 } | 597 } |
| 585 | 598 |
| 586 | 599 |
| 587 HConstant* HGraph::GetConstantMinus1() { | 600 HConstant* HGraph::GetConstantMinus1() { |
| 588 return GetConstant(&constant_minus1_, Handle<Smi>(Smi::FromInt(-1))); | 601 return GetConstantInt32(&constant_minus1_, -1); |
| 589 } | 602 } |
| 590 | 603 |
| 591 | 604 |
| 592 HConstant* HGraph::GetConstantTrue() { | 605 HConstant* HGraph::GetConstantTrue() { |
| 593 return GetConstant(&constant_true_, isolate()->factory()->true_value()); | 606 return GetConstant(&constant_true_, isolate()->factory()->true_value()); |
| 594 } | 607 } |
| 595 | 608 |
| 596 | 609 |
| 597 HConstant* HGraph::GetConstantFalse() { | 610 HConstant* HGraph::GetConstantFalse() { |
| 598 return GetConstant(&constant_false_, isolate()->factory()->false_value()); | 611 return GetConstant(&constant_false_, isolate()->factory()->false_value()); |
| (...skipping 2445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3044 for (int i = 0; i < exprs->length(); ++i) { | 3057 for (int i = 0; i < exprs->length(); ++i) { |
| 3045 CHECK_ALIVE(VisitForValue(exprs->at(i))); | 3058 CHECK_ALIVE(VisitForValue(exprs->at(i))); |
| 3046 } | 3059 } |
| 3047 } | 3060 } |
| 3048 | 3061 |
| 3049 | 3062 |
| 3050 HGraph* HGraphBuilder::CreateGraph() { | 3063 HGraph* HGraphBuilder::CreateGraph() { |
| 3051 graph_ = new(zone()) HGraph(info()); | 3064 graph_ = new(zone()) HGraph(info()); |
| 3052 if (FLAG_hydrogen_stats) HStatistics::Instance()->Initialize(info()); | 3065 if (FLAG_hydrogen_stats) HStatistics::Instance()->Initialize(info()); |
| 3053 | 3066 |
| 3067 Factory* f = info()->isolate()->factory(); |
| 3068 constant_undefined_ = new(zone()) HConstant(f->undefined_value(), |
| 3069 Representation::Tagged()); |
| 3070 constant_null_ = new(zone()) HConstant(f->null_value(), |
| 3071 Representation::Tagged()); |
| 3072 |
| 3054 { | 3073 { |
| 3055 HPhase phase("H_Block building"); | 3074 HPhase phase("H_Block building"); |
| 3056 CompilationHandleScope handle_scope(info()); | 3075 CompilationHandleScope handle_scope(info()); |
| 3057 current_block_ = graph()->entry_block(); | 3076 current_block_ = graph()->entry_block(); |
| 3058 | 3077 |
| 3059 Scope* scope = info()->scope(); | 3078 Scope* scope = info()->scope(); |
| 3060 if (scope->HasIllegalRedeclaration()) { | 3079 if (scope->HasIllegalRedeclaration()) { |
| 3061 Bailout("function with illegal redeclaration"); | 3080 Bailout("function with illegal redeclaration"); |
| 3062 return NULL; | 3081 return NULL; |
| 3063 } | 3082 } |
| (...skipping 4801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7865 instr = HShl::NewHShl(zone(), context, left, right); | 7884 instr = HShl::NewHShl(zone(), context, left, right); |
| 7866 break; | 7885 break; |
| 7867 default: | 7886 default: |
| 7868 UNREACHABLE(); | 7887 UNREACHABLE(); |
| 7869 } | 7888 } |
| 7870 | 7889 |
| 7871 // If we hit an uninitialized binary op stub we will get type info | 7890 // If we hit an uninitialized binary op stub we will get type info |
| 7872 // for a smi operation. If one of the operands is a constant string | 7891 // for a smi operation. If one of the operands is a constant string |
| 7873 // do not generate code assuming it is a smi operation. | 7892 // do not generate code assuming it is a smi operation. |
| 7874 if (info.IsSmi() && | 7893 if (info.IsSmi() && |
| 7875 ((left->IsConstant() && HConstant::cast(left)->HasStringValue()) || | 7894 ((left->IsConstant() && HConstant::cast(left)->handle()->IsString()) || |
| 7876 (right->IsConstant() && HConstant::cast(right)->HasStringValue()))) { | 7895 (right->IsConstant() && HConstant::cast(right)->handle()->IsString()))) { |
| 7877 return instr; | 7896 return instr; |
| 7878 } | 7897 } |
| 7879 Representation rep = ToRepresentation(info); | 7898 Representation rep = ToRepresentation(info); |
| 7880 // We only generate either int32 or generic tagged bitwise operations. | 7899 // We only generate either int32 or generic tagged bitwise operations. |
| 7881 if (instr->IsBitwiseBinaryOperation()) { | 7900 if (instr->IsBitwiseBinaryOperation()) { |
| 7882 HBitwiseBinaryOperation::cast(instr)-> | 7901 HBitwiseBinaryOperation::cast(instr)-> |
| 7883 InitializeObservedInputRepresentation(rep); | 7902 InitializeObservedInputRepresentation(rep); |
| 7884 if (rep.IsDouble()) rep = Representation::Integer32(); | 7903 if (rep.IsDouble()) rep = Representation::Integer32(); |
| 7885 } | 7904 } |
| 7886 TraceRepresentation(expr->op(), info, instr, rep); | 7905 TraceRepresentation(expr->op(), info, instr, rep); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8064 HValue* value = typeof_expr->value(); | 8083 HValue* value = typeof_expr->value(); |
| 8065 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check); | 8084 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check); |
| 8066 instr->set_position(expr->position()); | 8085 instr->set_position(expr->position()); |
| 8067 return ast_context()->ReturnControl(instr, expr->id()); | 8086 return ast_context()->ReturnControl(instr, expr->id()); |
| 8068 } | 8087 } |
| 8069 | 8088 |
| 8070 | 8089 |
| 8071 static bool MatchLiteralCompareNil(HValue* left, | 8090 static bool MatchLiteralCompareNil(HValue* left, |
| 8072 Token::Value op, | 8091 Token::Value op, |
| 8073 HValue* right, | 8092 HValue* right, |
| 8074 Handle<Object> nil, | 8093 HConstant* nil, |
| 8075 HValue** expr) { | 8094 HValue** expr) { |
| 8095 ASSERT(nil->IsTagged()); |
| 8076 if (left->IsConstant() && | 8096 if (left->IsConstant() && |
| 8077 HConstant::cast(left)->handle().is_identical_to(nil) && | 8097 HConstant::cast(left)->IsTagged() && |
| 8098 HConstant::cast(left)->handle().is_identical_to(nil->handle()) && |
| 8078 Token::IsEqualityOp(op)) { | 8099 Token::IsEqualityOp(op)) { |
| 8079 *expr = right; | 8100 *expr = right; |
| 8080 return true; | 8101 return true; |
| 8081 } | 8102 } |
| 8082 return false; | 8103 return false; |
| 8083 } | 8104 } |
| 8084 | 8105 |
| 8085 | 8106 |
| 8086 static bool MatchLiteralCompareTypeof(HValue* left, | 8107 static bool MatchLiteralCompareTypeof(HValue* left, |
| 8087 Token::Value op, | 8108 Token::Value op, |
| 8088 HValue* right, | 8109 HValue* right, |
| 8089 HTypeof** typeof_expr, | 8110 HTypeof** typeof_expr, |
| 8090 Handle<String>* check) { | 8111 Handle<String>* check) { |
| 8091 if (left->IsTypeof() && | 8112 if (left->IsTypeof() && |
| 8092 Token::IsEqualityOp(op) && | 8113 Token::IsEqualityOp(op) && |
| 8093 right->IsConstant() && | 8114 right->IsConstant() && |
| 8094 HConstant::cast(right)->HasStringValue()) { | 8115 HConstant::cast(right)->handle()->IsString()) { |
| 8095 *typeof_expr = HTypeof::cast(left); | 8116 *typeof_expr = HTypeof::cast(left); |
| 8096 *check = Handle<String>::cast(HConstant::cast(right)->handle()); | 8117 *check = Handle<String>::cast(HConstant::cast(right)->handle()); |
| 8097 return true; | 8118 return true; |
| 8098 } | 8119 } |
| 8099 return false; | 8120 return false; |
| 8100 } | 8121 } |
| 8101 | 8122 |
| 8102 | 8123 |
| 8103 static bool IsLiteralCompareTypeof(HValue* left, | 8124 static bool IsLiteralCompareTypeof(HValue* left, |
| 8104 Token::Value op, | 8125 Token::Value op, |
| 8105 HValue* right, | 8126 HValue* right, |
| 8106 HTypeof** typeof_expr, | 8127 HTypeof** typeof_expr, |
| 8107 Handle<String>* check) { | 8128 Handle<String>* check) { |
| 8108 return MatchLiteralCompareTypeof(left, op, right, typeof_expr, check) || | 8129 return MatchLiteralCompareTypeof(left, op, right, typeof_expr, check) || |
| 8109 MatchLiteralCompareTypeof(right, op, left, typeof_expr, check); | 8130 MatchLiteralCompareTypeof(right, op, left, typeof_expr, check); |
| 8110 } | 8131 } |
| 8111 | 8132 |
| 8112 | 8133 |
| 8113 static bool IsLiteralCompareNil(HValue* left, | 8134 static bool IsLiteralCompareNil(HValue* left, |
| 8114 Token::Value op, | 8135 Token::Value op, |
| 8115 HValue* right, | 8136 HValue* right, |
| 8116 Handle<Object> nil, | 8137 HConstant* nil, |
| 8117 HValue** expr) { | 8138 HValue** expr) { |
| 8118 return MatchLiteralCompareNil(left, op, right, nil, expr) || | 8139 return MatchLiteralCompareNil(left, op, right, nil, expr) || |
| 8119 MatchLiteralCompareNil(right, op, left, nil, expr); | 8140 MatchLiteralCompareNil(right, op, left, nil, expr); |
| 8120 } | 8141 } |
| 8121 | 8142 |
| 8122 | 8143 |
| 8123 static bool IsLiteralCompareBool(HValue* left, | 8144 static bool IsLiteralCompareBool(HValue* left, |
| 8124 Token::Value op, | 8145 Token::Value op, |
| 8125 HValue* right) { | 8146 HValue* right) { |
| 8126 return op == Token::EQ_STRICT && | 8147 return op == Token::EQ_STRICT && |
| 8127 ((left->IsConstant() && HConstant::cast(left)->handle()->IsBoolean()) || | 8148 ((left->IsConstant() && |
| 8128 (right->IsConstant() && HConstant::cast(right)->handle()->IsBoolean())); | 8149 HConstant::cast(left)->handle()->IsBoolean()) || |
| 8150 (right->IsConstant() && |
| 8151 HConstant::cast(right)->handle()->IsBoolean())); |
| 8129 } | 8152 } |
| 8130 | 8153 |
| 8131 | 8154 |
| 8132 void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) { | 8155 void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) { |
| 8133 ASSERT(!HasStackOverflow()); | 8156 ASSERT(!HasStackOverflow()); |
| 8134 ASSERT(current_block() != NULL); | 8157 ASSERT(current_block() != NULL); |
| 8135 ASSERT(current_block()->HasPredecessor()); | 8158 ASSERT(current_block()->HasPredecessor()); |
| 8136 if (IsClassOfTest(expr)) { | 8159 if (IsClassOfTest(expr)) { |
| 8137 CallRuntime* call = expr->left()->AsCallRuntime(); | 8160 CallRuntime* call = expr->left()->AsCallRuntime(); |
| 8138 ASSERT(call->arguments()->length() == 1); | 8161 ASSERT(call->arguments()->length() == 1); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 8162 HValue* right = Pop(); | 8185 HValue* right = Pop(); |
| 8163 HValue* left = Pop(); | 8186 HValue* left = Pop(); |
| 8164 Token::Value op = expr->op(); | 8187 Token::Value op = expr->op(); |
| 8165 | 8188 |
| 8166 HTypeof* typeof_expr = NULL; | 8189 HTypeof* typeof_expr = NULL; |
| 8167 Handle<String> check; | 8190 Handle<String> check; |
| 8168 if (IsLiteralCompareTypeof(left, op, right, &typeof_expr, &check)) { | 8191 if (IsLiteralCompareTypeof(left, op, right, &typeof_expr, &check)) { |
| 8169 return HandleLiteralCompareTypeof(expr, typeof_expr, check); | 8192 return HandleLiteralCompareTypeof(expr, typeof_expr, check); |
| 8170 } | 8193 } |
| 8171 HValue* sub_expr = NULL; | 8194 HValue* sub_expr = NULL; |
| 8172 Factory* f = graph()->isolate()->factory(); | 8195 if (IsLiteralCompareNil(left, op, right, constant_undefined_, &sub_expr)) { |
| 8173 if (IsLiteralCompareNil(left, op, right, f->undefined_value(), &sub_expr)) { | |
| 8174 return HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue); | 8196 return HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue); |
| 8175 } | 8197 } |
| 8176 if (IsLiteralCompareNil(left, op, right, f->null_value(), &sub_expr)) { | 8198 if (IsLiteralCompareNil(left, op, right, constant_null_, &sub_expr)) { |
| 8177 return HandleLiteralCompareNil(expr, sub_expr, kNullValue); | 8199 return HandleLiteralCompareNil(expr, sub_expr, kNullValue); |
| 8178 } | 8200 } |
| 8179 if (IsLiteralCompareBool(left, op, right)) { | 8201 if (IsLiteralCompareBool(left, op, right)) { |
| 8180 HCompareObjectEqAndBranch* result = | 8202 HCompareObjectEqAndBranch* result = |
| 8181 new(zone()) HCompareObjectEqAndBranch(left, right); | 8203 new(zone()) HCompareObjectEqAndBranch(left, right); |
| 8182 result->set_position(expr->position()); | 8204 result->set_position(expr->position()); |
| 8183 return ast_context()->ReturnControl(result, expr->id()); | 8205 return ast_context()->ReturnControl(result, expr->id()); |
| 8184 } | 8206 } |
| 8185 | 8207 |
| 8186 if (op == Token::INSTANCEOF) { | 8208 if (op == Token::INSTANCEOF) { |
| (...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9519 } | 9541 } |
| 9520 } | 9542 } |
| 9521 | 9543 |
| 9522 #ifdef DEBUG | 9544 #ifdef DEBUG |
| 9523 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 9545 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 9524 if (allocator_ != NULL) allocator_->Verify(); | 9546 if (allocator_ != NULL) allocator_->Verify(); |
| 9525 #endif | 9547 #endif |
| 9526 } | 9548 } |
| 9527 | 9549 |
| 9528 } } // namespace v8::internal | 9550 } } // namespace v8::internal |
| OLD | NEW |