| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/crankshaft/hydrogen.h" | 5 #include "src/crankshaft/hydrogen.h" |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "src/allocation-site-scopes.h" | 9 #include "src/allocation-site-scopes.h" |
| 10 #include "src/ast/ast-numbering.h" | 10 #include "src/ast/ast-numbering.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 if (IsGeneratorFunction(info()->shared_info()->kind())) { | 161 if (IsGeneratorFunction(info()->shared_info()->kind())) { |
| 162 // Crankshaft does not support generators. | 162 // Crankshaft does not support generators. |
| 163 return AbortOptimization(kGenerator); | 163 return AbortOptimization(kGenerator); |
| 164 } | 164 } |
| 165 | 165 |
| 166 if (FLAG_trace_hydrogen) { | 166 if (FLAG_trace_hydrogen) { |
| 167 isolate()->GetHTracer()->TraceCompilation(info()); | 167 isolate()->GetHTracer()->TraceCompilation(info()); |
| 168 } | 168 } |
| 169 | 169 |
| 170 // Type-check the function. | |
| 171 AstTyper(info()->isolate(), info()->zone(), info()->closure(), | |
| 172 info()->scope(), info()->osr_ast_id(), info()->literal()) | |
| 173 .Run(); | |
| 174 | |
| 175 // Optimization could have been disabled by the parser. Note that this check | 170 // Optimization could have been disabled by the parser. Note that this check |
| 176 // is only needed because the Hydrogen graph builder is missing some bailouts. | 171 // is only needed because the Hydrogen graph builder is missing some bailouts. |
| 177 if (info()->shared_info()->optimization_disabled()) { | 172 if (info()->shared_info()->optimization_disabled()) { |
| 178 return AbortOptimization( | 173 return AbortOptimization( |
| 179 info()->shared_info()->disable_optimization_reason()); | 174 info()->shared_info()->disable_optimization_reason()); |
| 180 } | 175 } |
| 181 | 176 |
| 182 HOptimizedGraphBuilder* graph_builder = | 177 HOptimizedGraphBuilder* graph_builder = |
| 183 (info()->is_tracking_positions() || FLAG_trace_ic) | 178 (info()->is_tracking_positions() || FLAG_trace_ic) |
| 184 ? new (info()->zone()) HOptimizedGraphBuilderWithPositions(info()) | 179 ? new (info()->zone()) HOptimizedGraphBuilderWithPositions(info()) |
| 185 : new (info()->zone()) HOptimizedGraphBuilder(info()); | 180 : new (info()->zone()) HOptimizedGraphBuilder(info()); |
| 186 | 181 |
| 182 // Type-check the function. |
| 183 AstTyper(info()->isolate(), info()->zone(), info()->closure(), |
| 184 info()->scope(), info()->osr_ast_id(), info()->literal(), |
| 185 graph_builder->bounds()) |
| 186 .Run(); |
| 187 |
| 187 graph_ = graph_builder->CreateGraph(); | 188 graph_ = graph_builder->CreateGraph(); |
| 188 | 189 |
| 189 if (isolate()->has_pending_exception()) { | 190 if (isolate()->has_pending_exception()) { |
| 190 return FAILED; | 191 return FAILED; |
| 191 } | 192 } |
| 192 | 193 |
| 193 if (graph_ == NULL) return FAILED; | 194 if (graph_ == NULL) return FAILED; |
| 194 | 195 |
| 195 if (info()->dependencies()->HasAborted()) { | 196 if (info()->dependencies()->HasAborted()) { |
| 196 // Dependency has changed during graph creation. Let's try again later. | 197 // Dependency has changed during graph creation. Let's try again later. |
| (...skipping 3479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3676 | 3677 |
| 3677 HOptimizedGraphBuilder::HOptimizedGraphBuilder(CompilationInfo* info) | 3678 HOptimizedGraphBuilder::HOptimizedGraphBuilder(CompilationInfo* info) |
| 3678 : HGraphBuilder(info, CallInterfaceDescriptor()), | 3679 : HGraphBuilder(info, CallInterfaceDescriptor()), |
| 3679 function_state_(NULL), | 3680 function_state_(NULL), |
| 3680 initial_function_state_(this, info, NORMAL_RETURN, 0, | 3681 initial_function_state_(this, info, NORMAL_RETURN, 0, |
| 3681 TailCallMode::kAllow), | 3682 TailCallMode::kAllow), |
| 3682 ast_context_(NULL), | 3683 ast_context_(NULL), |
| 3683 break_scope_(NULL), | 3684 break_scope_(NULL), |
| 3684 inlined_count_(0), | 3685 inlined_count_(0), |
| 3685 globals_(10, info->zone()), | 3686 globals_(10, info->zone()), |
| 3686 osr_(new (info->zone()) HOsrBuilder(this)) { | 3687 osr_(new (info->zone()) HOsrBuilder(this)), |
| 3688 bounds_(info->zone()) { |
| 3687 // This is not initialized in the initializer list because the | 3689 // This is not initialized in the initializer list because the |
| 3688 // constructor for the initial state relies on function_state_ == NULL | 3690 // constructor for the initial state relies on function_state_ == NULL |
| 3689 // to know it's the initial state. | 3691 // to know it's the initial state. |
| 3690 function_state_ = &initial_function_state_; | 3692 function_state_ = &initial_function_state_; |
| 3691 InitializeAstVisitor(info->isolate()); | 3693 InitializeAstVisitor(info->isolate()); |
| 3692 if (top_info()->is_tracking_positions()) { | 3694 if (top_info()->is_tracking_positions()) { |
| 3693 SetSourcePosition(info->shared_info()->start_position()); | 3695 SetSourcePosition(info->shared_info()->start_position()); |
| 3694 } | 3696 } |
| 3695 } | 3697 } |
| 3696 | 3698 |
| (...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5165 DCHECK(current_block() != NULL); | 5167 DCHECK(current_block() != NULL); |
| 5166 DCHECK(current_block()->HasPredecessor()); | 5168 DCHECK(current_block()->HasPredecessor()); |
| 5167 | 5169 |
| 5168 ZoneList<CaseClause*>* clauses = stmt->cases(); | 5170 ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 5169 int clause_count = clauses->length(); | 5171 int clause_count = clauses->length(); |
| 5170 ZoneList<HBasicBlock*> body_blocks(clause_count, zone()); | 5172 ZoneList<HBasicBlock*> body_blocks(clause_count, zone()); |
| 5171 | 5173 |
| 5172 CHECK_ALIVE(VisitForValue(stmt->tag())); | 5174 CHECK_ALIVE(VisitForValue(stmt->tag())); |
| 5173 Add<HSimulate>(stmt->EntryId()); | 5175 Add<HSimulate>(stmt->EntryId()); |
| 5174 HValue* tag_value = Top(); | 5176 HValue* tag_value = Top(); |
| 5175 Type* tag_type = stmt->tag()->bounds().lower; | 5177 Type* tag_type = bounds_.get(stmt->tag()).lower; |
| 5176 | 5178 |
| 5177 // 1. Build all the tests, with dangling true branches | 5179 // 1. Build all the tests, with dangling true branches |
| 5178 BailoutId default_id = BailoutId::None(); | 5180 BailoutId default_id = BailoutId::None(); |
| 5179 for (int i = 0; i < clause_count; ++i) { | 5181 for (int i = 0; i < clause_count; ++i) { |
| 5180 CaseClause* clause = clauses->at(i); | 5182 CaseClause* clause = clauses->at(i); |
| 5181 if (clause->is_default()) { | 5183 if (clause->is_default()) { |
| 5182 body_blocks.Add(NULL, zone()); | 5184 body_blocks.Add(NULL, zone()); |
| 5183 if (default_id.IsNone()) default_id = clause->EntryId(); | 5185 if (default_id.IsNone()) default_id = clause->EntryId(); |
| 5184 continue; | 5186 continue; |
| 5185 } | 5187 } |
| 5186 | 5188 |
| 5187 // Generate a compare and branch. | 5189 // Generate a compare and branch. |
| 5188 CHECK_BAILOUT(VisitForValue(clause->label())); | 5190 CHECK_BAILOUT(VisitForValue(clause->label())); |
| 5189 if (current_block() == NULL) return Bailout(kUnsupportedSwitchStatement); | 5191 if (current_block() == NULL) return Bailout(kUnsupportedSwitchStatement); |
| 5190 HValue* label_value = Pop(); | 5192 HValue* label_value = Pop(); |
| 5191 | 5193 |
| 5192 Type* label_type = clause->label()->bounds().lower; | 5194 Type* label_type = bounds_.get(clause->label()).lower; |
| 5193 Type* combined_type = clause->compare_type(); | 5195 Type* combined_type = clause->compare_type(); |
| 5194 HControlInstruction* compare = BuildCompareInstruction( | 5196 HControlInstruction* compare = BuildCompareInstruction( |
| 5195 Token::EQ_STRICT, tag_value, label_value, tag_type, label_type, | 5197 Token::EQ_STRICT, tag_value, label_value, tag_type, label_type, |
| 5196 combined_type, | 5198 combined_type, |
| 5197 ScriptPositionToSourcePosition(stmt->tag()->position()), | 5199 ScriptPositionToSourcePosition(stmt->tag()->position()), |
| 5198 ScriptPositionToSourcePosition(clause->label()->position()), | 5200 ScriptPositionToSourcePosition(clause->label()->position()), |
| 5199 PUSH_BEFORE_SIMULATE, clause->id()); | 5201 PUSH_BEFORE_SIMULATE, clause->id()); |
| 5200 | 5202 |
| 5201 HBasicBlock* next_test_block = graph()->CreateBasicBlock(); | 5203 HBasicBlock* next_test_block = graph()->CreateBasicBlock(); |
| 5202 HBasicBlock* body_block = graph()->CreateBasicBlock(); | 5204 HBasicBlock* body_block = graph()->CreateBasicBlock(); |
| (...skipping 3443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8646 // does not remove the code with the deoptimization support. | 8648 // does not remove the code with the deoptimization support. |
| 8647 top_info()->AddInlinedFunction(target_info.shared_info()); | 8649 top_info()->AddInlinedFunction(target_info.shared_info()); |
| 8648 | 8650 |
| 8649 // ---------------------------------------------------------------- | 8651 // ---------------------------------------------------------------- |
| 8650 // After this point, we've made a decision to inline this function (so | 8652 // After this point, we've made a decision to inline this function (so |
| 8651 // TryInline should always return true). | 8653 // TryInline should always return true). |
| 8652 | 8654 |
| 8653 // Type-check the inlined function. | 8655 // Type-check the inlined function. |
| 8654 DCHECK(target_shared->has_deoptimization_support()); | 8656 DCHECK(target_shared->has_deoptimization_support()); |
| 8655 AstTyper(target_info.isolate(), target_info.zone(), target_info.closure(), | 8657 AstTyper(target_info.isolate(), target_info.zone(), target_info.closure(), |
| 8656 target_info.scope(), target_info.osr_ast_id(), target_info.literal()) | 8658 target_info.scope(), target_info.osr_ast_id(), target_info.literal(), |
| 8659 &bounds_) |
| 8657 .Run(); | 8660 .Run(); |
| 8658 | 8661 |
| 8659 int inlining_id = 0; | 8662 int inlining_id = 0; |
| 8660 if (top_info()->is_tracking_positions()) { | 8663 if (top_info()->is_tracking_positions()) { |
| 8661 inlining_id = TraceInlinedFunction(target_shared, source_position(), | 8664 inlining_id = TraceInlinedFunction(target_shared, source_position(), |
| 8662 function_state()->inlining_id()); | 8665 function_state()->inlining_id()); |
| 8663 } | 8666 } |
| 8664 | 8667 |
| 8665 // Save the pending call context. Set up new one for the inlined function. | 8668 // Save the pending call context. Set up new one for the inlined function. |
| 8666 // The function state is new-allocated because we need to delete it | 8669 // The function state is new-allocated because we need to delete it |
| (...skipping 2453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11120 | 11123 |
| 11121 return value; | 11124 return value; |
| 11122 } | 11125 } |
| 11123 | 11126 |
| 11124 | 11127 |
| 11125 HValue* HOptimizedGraphBuilder::BuildBinaryOperation( | 11128 HValue* HOptimizedGraphBuilder::BuildBinaryOperation( |
| 11126 BinaryOperation* expr, | 11129 BinaryOperation* expr, |
| 11127 HValue* left, | 11130 HValue* left, |
| 11128 HValue* right, | 11131 HValue* right, |
| 11129 PushBeforeSimulateBehavior push_sim_result) { | 11132 PushBeforeSimulateBehavior push_sim_result) { |
| 11130 Type* left_type = expr->left()->bounds().lower; | 11133 Type* left_type = bounds_.get(expr->left()).lower; |
| 11131 Type* right_type = expr->right()->bounds().lower; | 11134 Type* right_type = bounds_.get(expr->right()).lower; |
| 11132 Type* result_type = expr->bounds().lower; | 11135 Type* result_type = bounds_.get(expr).lower; |
| 11133 Maybe<int> fixed_right_arg = expr->fixed_right_arg(); | 11136 Maybe<int> fixed_right_arg = expr->fixed_right_arg(); |
| 11134 Handle<AllocationSite> allocation_site = expr->allocation_site(); | 11137 Handle<AllocationSite> allocation_site = expr->allocation_site(); |
| 11135 | 11138 |
| 11136 HAllocationMode allocation_mode; | 11139 HAllocationMode allocation_mode; |
| 11137 if (FLAG_allocation_site_pretenuring && !allocation_site.is_null()) { | 11140 if (FLAG_allocation_site_pretenuring && !allocation_site.is_null()) { |
| 11138 allocation_mode = HAllocationMode(allocation_site); | 11141 allocation_mode = HAllocationMode(allocation_site); |
| 11139 } | 11142 } |
| 11140 HValue* result = HGraphBuilder::BuildBinaryOperation( | 11143 HValue* result = HGraphBuilder::BuildBinaryOperation( |
| 11141 expr->op(), left, right, left_type, right_type, result_type, | 11144 expr->op(), left, right, left_type, right_type, result_type, |
| 11142 fixed_right_arg, allocation_mode, expr->id()); | 11145 fixed_right_arg, allocation_mode, expr->id()); |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11657 CallRuntime* call = expr->left()->AsCallRuntime(); | 11660 CallRuntime* call = expr->left()->AsCallRuntime(); |
| 11658 DCHECK(call->arguments()->length() == 1); | 11661 DCHECK(call->arguments()->length() == 1); |
| 11659 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | 11662 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
| 11660 HValue* value = Pop(); | 11663 HValue* value = Pop(); |
| 11661 Literal* literal = expr->right()->AsLiteral(); | 11664 Literal* literal = expr->right()->AsLiteral(); |
| 11662 Handle<String> rhs = Handle<String>::cast(literal->value()); | 11665 Handle<String> rhs = Handle<String>::cast(literal->value()); |
| 11663 HClassOfTestAndBranch* instr = New<HClassOfTestAndBranch>(value, rhs); | 11666 HClassOfTestAndBranch* instr = New<HClassOfTestAndBranch>(value, rhs); |
| 11664 return ast_context()->ReturnControl(instr, expr->id()); | 11667 return ast_context()->ReturnControl(instr, expr->id()); |
| 11665 } | 11668 } |
| 11666 | 11669 |
| 11667 Type* left_type = expr->left()->bounds().lower; | 11670 Type* left_type = bounds_.get(expr->left()).lower; |
| 11668 Type* right_type = expr->right()->bounds().lower; | 11671 Type* right_type = bounds_.get(expr->right()).lower; |
| 11669 Type* combined_type = expr->combined_type(); | 11672 Type* combined_type = expr->combined_type(); |
| 11670 | 11673 |
| 11671 CHECK_ALIVE(VisitForValue(expr->left())); | 11674 CHECK_ALIVE(VisitForValue(expr->left())); |
| 11672 CHECK_ALIVE(VisitForValue(expr->right())); | 11675 CHECK_ALIVE(VisitForValue(expr->right())); |
| 11673 | 11676 |
| 11674 HValue* right = Pop(); | 11677 HValue* right = Pop(); |
| 11675 HValue* left = Pop(); | 11678 HValue* left = Pop(); |
| 11676 Token::Value op = expr->op(); | 11679 Token::Value op = expr->op(); |
| 11677 | 11680 |
| 11678 if (IsLiteralCompareBool(isolate(), left, op, right)) { | 11681 if (IsLiteralCompareBool(isolate(), left, op, right)) { |
| (...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13745 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 13748 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
| 13746 } | 13749 } |
| 13747 | 13750 |
| 13748 #ifdef DEBUG | 13751 #ifdef DEBUG |
| 13749 graph_->Verify(false); // No full verify. | 13752 graph_->Verify(false); // No full verify. |
| 13750 #endif | 13753 #endif |
| 13751 } | 13754 } |
| 13752 | 13755 |
| 13753 } // namespace internal | 13756 } // namespace internal |
| 13754 } // namespace v8 | 13757 } // namespace v8 |
| OLD | NEW |