Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Side by Side Diff: src/crankshaft/hydrogen.cc

Issue 2126233002: Devirtualize AstNode and subclasses, except for visiting-related methods. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove static assert again Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/crankshaft/hydrogen.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3526 matching lines...) Expand 10 before | Expand all | Expand 10 after
3537 return first; 3537 return first;
3538 } else { 3538 } else {
3539 HBasicBlock* join_block = graph()->CreateBasicBlock(); 3539 HBasicBlock* join_block = graph()->CreateBasicBlock();
3540 Goto(first, join_block); 3540 Goto(first, join_block);
3541 Goto(second, join_block); 3541 Goto(second, join_block);
3542 join_block->SetJoinId(join_id); 3542 join_block->SetJoinId(join_id);
3543 return join_block; 3543 return join_block;
3544 } 3544 }
3545 } 3545 }
3546 3546
3547
3548 HBasicBlock* HOptimizedGraphBuilder::JoinContinue(IterationStatement* statement, 3547 HBasicBlock* HOptimizedGraphBuilder::JoinContinue(IterationStatement* statement,
3548 BailoutId continue_id,
3549 HBasicBlock* exit_block, 3549 HBasicBlock* exit_block,
3550 HBasicBlock* continue_block) { 3550 HBasicBlock* continue_block) {
3551 if (continue_block != NULL) { 3551 if (continue_block != NULL) {
3552 if (exit_block != NULL) Goto(exit_block, continue_block); 3552 if (exit_block != NULL) Goto(exit_block, continue_block);
3553 continue_block->SetJoinId(statement->ContinueId()); 3553 continue_block->SetJoinId(continue_id);
3554 return continue_block; 3554 return continue_block;
3555 } 3555 }
3556 return exit_block; 3556 return exit_block;
3557 } 3557 }
3558 3558
3559 3559
3560 HBasicBlock* HOptimizedGraphBuilder::CreateLoop(IterationStatement* statement, 3560 HBasicBlock* HOptimizedGraphBuilder::CreateLoop(IterationStatement* statement,
3561 HBasicBlock* loop_entry, 3561 HBasicBlock* loop_entry,
3562 HBasicBlock* body_exit, 3562 HBasicBlock* body_exit,
3563 HBasicBlock* loop_successor, 3563 HBasicBlock* loop_successor,
(...skipping 1526 matching lines...) Expand 10 before | Expand all | Expand 10 after
5090 last_block, 5090 last_block,
5091 stmt->ExitId())); 5091 stmt->ExitId()));
5092 } else { 5092 } else {
5093 if (fall_through_block != NULL) Goto(fall_through_block, break_block); 5093 if (fall_through_block != NULL) Goto(fall_through_block, break_block);
5094 if (last_block != NULL) Goto(last_block, break_block); 5094 if (last_block != NULL) Goto(last_block, break_block);
5095 break_block->SetJoinId(stmt->ExitId()); 5095 break_block->SetJoinId(stmt->ExitId());
5096 set_current_block(break_block); 5096 set_current_block(break_block);
5097 } 5097 }
5098 } 5098 }
5099 5099
5100
5101 void HOptimizedGraphBuilder::VisitLoopBody(IterationStatement* stmt, 5100 void HOptimizedGraphBuilder::VisitLoopBody(IterationStatement* stmt,
5101 BailoutId stack_check_id,
5102 HBasicBlock* loop_entry) { 5102 HBasicBlock* loop_entry) {
5103 Add<HSimulate>(stmt->StackCheckId()); 5103 Add<HSimulate>(stack_check_id);
5104 HStackCheck* stack_check = 5104 HStackCheck* stack_check =
5105 HStackCheck::cast(Add<HStackCheck>(HStackCheck::kBackwardsBranch)); 5105 HStackCheck::cast(Add<HStackCheck>(HStackCheck::kBackwardsBranch));
5106 DCHECK(loop_entry->IsLoopHeader()); 5106 DCHECK(loop_entry->IsLoopHeader());
5107 loop_entry->loop_information()->set_stack_check(stack_check); 5107 loop_entry->loop_information()->set_stack_check(stack_check);
5108 CHECK_BAILOUT(Visit(stmt->body())); 5108 CHECK_BAILOUT(Visit(stmt->body()));
5109 } 5109 }
5110 5110
5111 5111
5112 void HOptimizedGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { 5112 void HOptimizedGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) {
5113 DCHECK(!HasStackOverflow()); 5113 DCHECK(!HasStackOverflow());
5114 DCHECK(current_block() != NULL); 5114 DCHECK(current_block() != NULL);
5115 DCHECK(current_block()->HasPredecessor()); 5115 DCHECK(current_block()->HasPredecessor());
5116 DCHECK(current_block() != NULL); 5116 DCHECK(current_block() != NULL);
5117 HBasicBlock* loop_entry = BuildLoopEntry(stmt); 5117 HBasicBlock* loop_entry = BuildLoopEntry(stmt);
5118 5118
5119 BreakAndContinueInfo break_info(stmt, scope()); 5119 BreakAndContinueInfo break_info(stmt, scope());
5120 { 5120 {
5121 BreakAndContinueScope push(&break_info, this); 5121 BreakAndContinueScope push(&break_info, this);
5122 CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry)); 5122 CHECK_BAILOUT(VisitLoopBody(stmt, stmt->StackCheckId(), loop_entry));
5123 } 5123 }
5124 HBasicBlock* body_exit = 5124 HBasicBlock* body_exit = JoinContinue(
5125 JoinContinue(stmt, current_block(), break_info.continue_block()); 5125 stmt, stmt->ContinueId(), current_block(), break_info.continue_block());
5126 HBasicBlock* loop_successor = NULL; 5126 HBasicBlock* loop_successor = NULL;
5127 if (body_exit != NULL) { 5127 if (body_exit != NULL) {
5128 set_current_block(body_exit); 5128 set_current_block(body_exit);
5129 loop_successor = graph()->CreateBasicBlock(); 5129 loop_successor = graph()->CreateBasicBlock();
5130 if (stmt->cond()->ToBooleanIsFalse()) { 5130 if (stmt->cond()->ToBooleanIsFalse()) {
5131 loop_entry->loop_information()->stack_check()->Eliminate(); 5131 loop_entry->loop_information()->stack_check()->Eliminate();
5132 Goto(loop_successor); 5132 Goto(loop_successor);
5133 body_exit = NULL; 5133 body_exit = NULL;
5134 } else { 5134 } else {
5135 // The block for a true condition, the actual predecessor block of the 5135 // The block for a true condition, the actual predecessor block of the
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5175 } 5175 }
5176 if (loop_successor->HasPredecessor()) { 5176 if (loop_successor->HasPredecessor()) {
5177 loop_successor->SetJoinId(stmt->ExitId()); 5177 loop_successor->SetJoinId(stmt->ExitId());
5178 } else { 5178 } else {
5179 loop_successor = NULL; 5179 loop_successor = NULL;
5180 } 5180 }
5181 5181
5182 BreakAndContinueInfo break_info(stmt, scope()); 5182 BreakAndContinueInfo break_info(stmt, scope());
5183 if (current_block() != NULL) { 5183 if (current_block() != NULL) {
5184 BreakAndContinueScope push(&break_info, this); 5184 BreakAndContinueScope push(&break_info, this);
5185 CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry)); 5185 CHECK_BAILOUT(VisitLoopBody(stmt, stmt->StackCheckId(), loop_entry));
5186 } 5186 }
5187 HBasicBlock* body_exit = 5187 HBasicBlock* body_exit = JoinContinue(
5188 JoinContinue(stmt, current_block(), break_info.continue_block()); 5188 stmt, stmt->ContinueId(), current_block(), break_info.continue_block());
5189 HBasicBlock* loop_exit = CreateLoop(stmt, 5189 HBasicBlock* loop_exit = CreateLoop(stmt,
5190 loop_entry, 5190 loop_entry,
5191 body_exit, 5191 body_exit,
5192 loop_successor, 5192 loop_successor,
5193 break_info.break_block()); 5193 break_info.break_block());
5194 set_current_block(loop_exit); 5194 set_current_block(loop_exit);
5195 } 5195 }
5196 5196
5197 5197
5198 void HOptimizedGraphBuilder::VisitForStatement(ForStatement* stmt) { 5198 void HOptimizedGraphBuilder::VisitForStatement(ForStatement* stmt) {
(...skipping 25 matching lines...) Expand all
5224 HControlInstruction* branch = New<HBranch>(graph()->GetConstantTrue()); 5224 HControlInstruction* branch = New<HBranch>(graph()->GetConstantTrue());
5225 branch->SetSuccessorAt(0, body_entry); 5225 branch->SetSuccessorAt(0, body_entry);
5226 branch->SetSuccessorAt(1, loop_successor); 5226 branch->SetSuccessorAt(1, loop_successor);
5227 FinishCurrentBlock(branch); 5227 FinishCurrentBlock(branch);
5228 set_current_block(body_entry); 5228 set_current_block(body_entry);
5229 } 5229 }
5230 5230
5231 BreakAndContinueInfo break_info(stmt, scope()); 5231 BreakAndContinueInfo break_info(stmt, scope());
5232 if (current_block() != NULL) { 5232 if (current_block() != NULL) {
5233 BreakAndContinueScope push(&break_info, this); 5233 BreakAndContinueScope push(&break_info, this);
5234 CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry)); 5234 CHECK_BAILOUT(VisitLoopBody(stmt, stmt->StackCheckId(), loop_entry));
5235 } 5235 }
5236 HBasicBlock* body_exit = 5236 HBasicBlock* body_exit = JoinContinue(
5237 JoinContinue(stmt, current_block(), break_info.continue_block()); 5237 stmt, stmt->ContinueId(), current_block(), break_info.continue_block());
5238 5238
5239 if (stmt->next() != NULL && body_exit != NULL) { 5239 if (stmt->next() != NULL && body_exit != NULL) {
5240 set_current_block(body_exit); 5240 set_current_block(body_exit);
5241 CHECK_BAILOUT(Visit(stmt->next())); 5241 CHECK_BAILOUT(Visit(stmt->next()));
5242 body_exit = current_block(); 5242 body_exit = current_block();
5243 } 5243 }
5244 5244
5245 HBasicBlock* loop_exit = CreateLoop(stmt, 5245 HBasicBlock* loop_exit = CreateLoop(stmt,
5246 loop_entry, 5246 loop_entry,
5247 body_exit, 5247 body_exit,
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
5423 key = Pop(); 5423 key = Pop();
5424 } 5424 }
5425 5425
5426 Bind(each_var, key); 5426 Bind(each_var, key);
5427 Add<HSimulate>(stmt->AssignmentId()); 5427 Add<HSimulate>(stmt->AssignmentId());
5428 5428
5429 BreakAndContinueInfo break_info(stmt, scope(), 5); 5429 BreakAndContinueInfo break_info(stmt, scope(), 5);
5430 break_info.set_continue_block(continue_block); 5430 break_info.set_continue_block(continue_block);
5431 { 5431 {
5432 BreakAndContinueScope push(&break_info, this); 5432 BreakAndContinueScope push(&break_info, this);
5433 CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry)); 5433 CHECK_BAILOUT(VisitLoopBody(stmt, stmt->StackCheckId(), loop_entry));
5434 } 5434 }
5435 5435
5436 HBasicBlock* body_exit = 5436 HBasicBlock* body_exit = JoinContinue(
5437 JoinContinue(stmt, current_block(), break_info.continue_block()); 5437 stmt, stmt->ContinueId(), current_block(), break_info.continue_block());
5438 5438
5439 if (body_exit != NULL) { 5439 if (body_exit != NULL) {
5440 set_current_block(body_exit); 5440 set_current_block(body_exit);
5441 5441
5442 HValue* current_index = Pop(); 5442 HValue* current_index = Pop();
5443 HValue* increment = 5443 HValue* increment =
5444 AddUncasted<HAdd>(current_index, graph()->GetConstant1()); 5444 AddUncasted<HAdd>(current_index, graph()->GetConstant1());
5445 increment->ClearFlag(HValue::kCanOverflow); 5445 increment->ClearFlag(HValue::kCanOverflow);
5446 Push(increment); 5446 Push(increment);
5447 body_exit = current_block(); 5447 body_exit = current_block();
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after
6710 } 6710 }
6711 } 6711 }
6712 6712
6713 static bool ComputeReceiverTypes(Expression* expr, HValue* receiver, 6713 static bool ComputeReceiverTypes(Expression* expr, HValue* receiver,
6714 SmallMapList** t, 6714 SmallMapList** t,
6715 HOptimizedGraphBuilder* builder) { 6715 HOptimizedGraphBuilder* builder) {
6716 Zone* zone = builder->zone(); 6716 Zone* zone = builder->zone();
6717 SmallMapList* maps = expr->GetReceiverTypes(); 6717 SmallMapList* maps = expr->GetReceiverTypes();
6718 *t = maps; 6718 *t = maps;
6719 bool monomorphic = expr->IsMonomorphic(); 6719 bool monomorphic = expr->IsMonomorphic();
6720 if (maps != NULL && receiver->HasMonomorphicJSObjectType()) { 6720 if (maps != nullptr && receiver->HasMonomorphicJSObjectType()) {
6721 if (maps->length() > 0) { 6721 if (maps->length() > 0) {
6722 Map* root_map = receiver->GetMonomorphicJSObjectMap()->FindRootMap(); 6722 Map* root_map = receiver->GetMonomorphicJSObjectMap()->FindRootMap();
6723 maps->FilterForPossibleTransitions(root_map); 6723 maps->FilterForPossibleTransitions(root_map);
6724 monomorphic = maps->length() == 1; 6724 monomorphic = maps->length() == 1;
6725 } else { 6725 } else {
6726 // No type feedback, see if we can infer the type. This is safely 6726 // No type feedback, see if we can infer the type. This is safely
6727 // possible if the receiver had a known map at some point, and no 6727 // possible if the receiver had a known map at some point, and no
6728 // map-changing stores have happened to it since. 6728 // map-changing stores have happened to it since.
6729 Handle<Map> candidate_map = receiver->GetMonomorphicJSObjectMap(); 6729 Handle<Map> candidate_map = receiver->GetMonomorphicJSObjectMap();
6730 for (HInstruction* current = builder->current_block()->last(); 6730 for (HInstruction* current = builder->current_block()->last();
(...skipping 25 matching lines...) Expand all
6756 } 6756 }
6757 6757
6758 6758
6759 static bool AreStringTypes(SmallMapList* maps) { 6759 static bool AreStringTypes(SmallMapList* maps) {
6760 for (int i = 0; i < maps->length(); i++) { 6760 for (int i = 0; i < maps->length(); i++) {
6761 if (maps->at(i)->instance_type() >= FIRST_NONSTRING_TYPE) return false; 6761 if (maps->at(i)->instance_type() >= FIRST_NONSTRING_TYPE) return false;
6762 } 6762 }
6763 return true; 6763 return true;
6764 } 6764 }
6765 6765
6766
6767 void HOptimizedGraphBuilder::BuildStore(Expression* expr, Property* prop, 6766 void HOptimizedGraphBuilder::BuildStore(Expression* expr, Property* prop,
6768 FeedbackVectorSlot slot, 6767 FeedbackVectorSlot slot,
6769 BailoutId ast_id, BailoutId return_id, 6768 BailoutId ast_id, BailoutId return_id,
6770 bool is_uninitialized) { 6769 bool is_uninitialized) {
6771 if (!prop->key()->IsPropertyName()) { 6770 if (!prop->key()->IsPropertyName()) {
6772 // Keyed store. 6771 // Keyed store.
6773 HValue* value = Pop(); 6772 HValue* value = Pop();
6774 HValue* key = Pop(); 6773 HValue* key = Pop();
6775 HValue* object = Pop(); 6774 HValue* object = Pop();
6776 bool has_side_effects = false; 6775 bool has_side_effects = false;
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
7589 // generic access in the case length() == 0. 7588 // generic access in the case length() == 0.
7590 DCHECK(join->predecessors()->length() > 0); 7589 DCHECK(join->predecessors()->length() > 0);
7591 // Deopt if none of the cases matched. 7590 // Deopt if none of the cases matched.
7592 NoObservableSideEffectsScope scope(this); 7591 NoObservableSideEffectsScope scope(this);
7593 FinishExitWithHardDeoptimization( 7592 FinishExitWithHardDeoptimization(
7594 Deoptimizer::kUnknownMapInPolymorphicElementAccess); 7593 Deoptimizer::kUnknownMapInPolymorphicElementAccess);
7595 set_current_block(join); 7594 set_current_block(join);
7596 return access_type == STORE ? val : Pop(); 7595 return access_type == STORE ? val : Pop();
7597 } 7596 }
7598 7597
7599
7600 HValue* HOptimizedGraphBuilder::HandleKeyedElementAccess( 7598 HValue* HOptimizedGraphBuilder::HandleKeyedElementAccess(
7601 HValue* obj, HValue* key, HValue* val, Expression* expr, 7599 HValue* obj, HValue* key, HValue* val, Expression* expr,
7602 FeedbackVectorSlot slot, BailoutId ast_id, BailoutId return_id, 7600 FeedbackVectorSlot slot, BailoutId ast_id, BailoutId return_id,
7603 PropertyAccessType access_type, bool* has_side_effects) { 7601 PropertyAccessType access_type, bool* has_side_effects) {
7604 // A keyed name access with type feedback may contain the name. 7602 // A keyed name access with type feedback may contain the name.
7605 Handle<TypeFeedbackVector> vector = 7603 Handle<TypeFeedbackVector> vector =
7606 handle(current_feedback_vector(), isolate()); 7604 handle(current_feedback_vector(), isolate());
7607 HValue* expected_key = key; 7605 HValue* expected_key = key;
7608 if (!key->ActualValue()->IsConstant()) { 7606 if (!key->ActualValue()->IsConstant()) {
7609 Name* name = nullptr; 7607 Name* name = nullptr;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
7802 arguments_environment()->parameter_count() - 1; 7800 arguments_environment()->parameter_count() - 1;
7803 HInstruction* length = Add<HConstant>(argument_count); 7801 HInstruction* length = Add<HConstant>(argument_count);
7804 HInstruction* checked_key = Add<HBoundsCheck>(key, length); 7802 HInstruction* checked_key = Add<HBoundsCheck>(key, length);
7805 result = New<HAccessArgumentsAt>(elements, length, checked_key); 7803 result = New<HAccessArgumentsAt>(elements, length, checked_key);
7806 } 7804 }
7807 } 7805 }
7808 ast_context()->ReturnInstruction(result, expr->id()); 7806 ast_context()->ReturnInstruction(result, expr->id());
7809 return true; 7807 return true;
7810 } 7808 }
7811 7809
7812
7813 HValue* HOptimizedGraphBuilder::BuildNamedAccess( 7810 HValue* HOptimizedGraphBuilder::BuildNamedAccess(
7814 PropertyAccessType access, BailoutId ast_id, BailoutId return_id, 7811 PropertyAccessType access, BailoutId ast_id, BailoutId return_id,
7815 Expression* expr, FeedbackVectorSlot slot, HValue* object, 7812 Expression* expr, FeedbackVectorSlot slot, HValue* object,
7816 Handle<Name> name, HValue* value, bool is_uninitialized) { 7813 Handle<Name> name, HValue* value, bool is_uninitialized) {
7817 SmallMapList* maps; 7814 SmallMapList* maps;
7818 ComputeReceiverTypes(expr, object, &maps, this); 7815 ComputeReceiverTypes(expr, object, &maps, this);
7819 DCHECK(maps != NULL); 7816 DCHECK(maps != NULL);
7820 7817
7821 if (maps->length() > 0) { 7818 if (maps->length() > 0) {
7822 PropertyAccessInfo info(this, access, maps->first(), name); 7819 PropertyAccessInfo info(this, access, maps->first(), name);
(...skipping 2885 matching lines...) Expand 10 before | Expand all | Expand 10 after
10708 if (instr->IsAdd()) { 10705 if (instr->IsAdd()) {
10709 HAdd* add = HAdd::cast(instr); 10706 HAdd* add = HAdd::cast(instr);
10710 add->set_observed_input_representation(1, rep); 10707 add->set_observed_input_representation(1, rep);
10711 add->set_observed_input_representation(2, Representation::Smi()); 10708 add->set_observed_input_representation(2, Representation::Smi());
10712 } 10709 }
10713 instr->ClearAllSideEffects(); 10710 instr->ClearAllSideEffects();
10714 instr->SetFlag(HInstruction::kCannotBeTagged); 10711 instr->SetFlag(HInstruction::kCannotBeTagged);
10715 return instr; 10712 return instr;
10716 } 10713 }
10717 10714
10718
10719 void HOptimizedGraphBuilder::BuildStoreForEffect( 10715 void HOptimizedGraphBuilder::BuildStoreForEffect(
10720 Expression* expr, Property* prop, FeedbackVectorSlot slot, BailoutId ast_id, 10716 Expression* expr, Property* prop, FeedbackVectorSlot slot, BailoutId ast_id,
10721 BailoutId return_id, HValue* object, HValue* key, HValue* value) { 10717 BailoutId return_id, HValue* object, HValue* key, HValue* value) {
10722 EffectContext for_effect(this); 10718 EffectContext for_effect(this);
10723 Push(object); 10719 Push(object);
10724 if (key != NULL) Push(key); 10720 if (key != NULL) Push(key);
10725 Push(value); 10721 Push(value);
10726 BuildStore(expr, prop, slot, ast_id, return_id); 10722 BuildStore(expr, prop, slot, ast_id, return_id);
10727 } 10723 }
10728 10724
(...skipping 2696 matching lines...) Expand 10 before | Expand all | Expand 10 after
13425 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 13421 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
13426 } 13422 }
13427 13423
13428 #ifdef DEBUG 13424 #ifdef DEBUG
13429 graph_->Verify(false); // No full verify. 13425 graph_->Verify(false); // No full verify.
13430 #endif 13426 #endif
13431 } 13427 }
13432 13428
13433 } // namespace internal 13429 } // namespace internal
13434 } // namespace v8 13430 } // namespace v8
OLDNEW
« no previous file with comments | « src/crankshaft/hydrogen.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698