| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/ast/ast-numbering.h" | 5 #include "src/ast/ast-numbering.h" |
| 6 | 6 |
| 7 #include "src/ast/ast.h" | 7 #include "src/ast/ast.h" |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 void IncrementNodeCount() { properties_.add_node_count(1); } | 50 void IncrementNodeCount() { properties_.add_node_count(1); } |
| 51 void DisableSelfOptimization() { | 51 void DisableSelfOptimization() { |
| 52 properties_.flags() |= AstProperties::kDontSelfOptimize; | 52 properties_.flags() |= AstProperties::kDontSelfOptimize; |
| 53 } | 53 } |
| 54 void DisableOptimization(BailoutReason reason) { | 54 void DisableOptimization(BailoutReason reason) { |
| 55 dont_optimize_reason_ = reason; | 55 dont_optimize_reason_ = reason; |
| 56 DisableSelfOptimization(); | 56 DisableSelfOptimization(); |
| 57 } | 57 } |
| 58 void DisableCrankshaft(BailoutReason reason) { | 58 void DisableFullCodegenAndCrankshaft(BailoutReason reason) { |
| 59 properties_.flags() |= AstProperties::kDontCrankshaft; | 59 properties_.flags() |= AstProperties::kMustUseIgnitionTurbo; |
| 60 } | 60 } |
| 61 | 61 |
| 62 template <typename Node> | 62 template <typename Node> |
| 63 void ReserveFeedbackSlots(Node* node) { | 63 void ReserveFeedbackSlots(Node* node) { |
| 64 node->AssignFeedbackVectorSlots(isolate_, properties_.get_spec(), | 64 node->AssignFeedbackVectorSlots(isolate_, properties_.get_spec(), |
| 65 &slot_cache_); | 65 &slot_cache_); |
| 66 } | 66 } |
| 67 | 67 |
| 68 BailoutReason dont_optimize_reason() const { return dont_optimize_reason_; } | 68 BailoutReason dont_optimize_reason() const { return dont_optimize_reason_; } |
| 69 | 69 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 void AstNumberingVisitor::VisitRegExpLiteral(RegExpLiteral* node) { | 142 void AstNumberingVisitor::VisitRegExpLiteral(RegExpLiteral* node) { |
| 143 IncrementNodeCount(); | 143 IncrementNodeCount(); |
| 144 node->set_base_id(ReserveIdRange(RegExpLiteral::num_ids())); | 144 node->set_base_id(ReserveIdRange(RegExpLiteral::num_ids())); |
| 145 } | 145 } |
| 146 | 146 |
| 147 | 147 |
| 148 void AstNumberingVisitor::VisitVariableProxyReference(VariableProxy* node) { | 148 void AstNumberingVisitor::VisitVariableProxyReference(VariableProxy* node) { |
| 149 IncrementNodeCount(); | 149 IncrementNodeCount(); |
| 150 switch (node->var()->location()) { | 150 switch (node->var()->location()) { |
| 151 case VariableLocation::LOOKUP: | 151 case VariableLocation::LOOKUP: |
| 152 DisableCrankshaft(kReferenceToAVariableWhichRequiresDynamicLookup); | 152 DisableFullCodegenAndCrankshaft( |
| 153 kReferenceToAVariableWhichRequiresDynamicLookup); |
| 153 break; | 154 break; |
| 154 case VariableLocation::MODULE: | 155 case VariableLocation::MODULE: |
| 155 DisableCrankshaft(kReferenceToModuleVariable); | 156 DisableFullCodegenAndCrankshaft(kReferenceToModuleVariable); |
| 156 break; | 157 break; |
| 157 default: | 158 default: |
| 158 break; | 159 break; |
| 159 } | 160 } |
| 160 node->set_base_id(ReserveIdRange(VariableProxy::num_ids())); | 161 node->set_base_id(ReserveIdRange(VariableProxy::num_ids())); |
| 161 } | 162 } |
| 162 | 163 |
| 163 | 164 |
| 164 void AstNumberingVisitor::VisitVariableProxy(VariableProxy* node) { | 165 void AstNumberingVisitor::VisitVariableProxy(VariableProxy* node) { |
| 165 VisitVariableProxyReference(node); | 166 VisitVariableProxyReference(node); |
| 166 ReserveFeedbackSlots(node); | 167 ReserveFeedbackSlots(node); |
| 167 } | 168 } |
| 168 | 169 |
| 169 | 170 |
| 170 void AstNumberingVisitor::VisitThisFunction(ThisFunction* node) { | 171 void AstNumberingVisitor::VisitThisFunction(ThisFunction* node) { |
| 171 IncrementNodeCount(); | 172 IncrementNodeCount(); |
| 172 node->set_base_id(ReserveIdRange(ThisFunction::num_ids())); | 173 node->set_base_id(ReserveIdRange(ThisFunction::num_ids())); |
| 173 } | 174 } |
| 174 | 175 |
| 175 | 176 |
| 176 void AstNumberingVisitor::VisitSuperPropertyReference( | 177 void AstNumberingVisitor::VisitSuperPropertyReference( |
| 177 SuperPropertyReference* node) { | 178 SuperPropertyReference* node) { |
| 178 IncrementNodeCount(); | 179 IncrementNodeCount(); |
| 179 DisableCrankshaft(kSuperReference); | 180 DisableFullCodegenAndCrankshaft(kSuperReference); |
| 180 node->set_base_id(ReserveIdRange(SuperPropertyReference::num_ids())); | 181 node->set_base_id(ReserveIdRange(SuperPropertyReference::num_ids())); |
| 181 Visit(node->this_var()); | 182 Visit(node->this_var()); |
| 182 Visit(node->home_object()); | 183 Visit(node->home_object()); |
| 183 } | 184 } |
| 184 | 185 |
| 185 | 186 |
| 186 void AstNumberingVisitor::VisitSuperCallReference(SuperCallReference* node) { | 187 void AstNumberingVisitor::VisitSuperCallReference(SuperCallReference* node) { |
| 187 IncrementNodeCount(); | 188 IncrementNodeCount(); |
| 188 DisableCrankshaft(kSuperReference); | 189 DisableFullCodegenAndCrankshaft(kSuperReference); |
| 189 node->set_base_id(ReserveIdRange(SuperCallReference::num_ids())); | 190 node->set_base_id(ReserveIdRange(SuperCallReference::num_ids())); |
| 190 Visit(node->this_var()); | 191 Visit(node->this_var()); |
| 191 Visit(node->new_target_var()); | 192 Visit(node->new_target_var()); |
| 192 Visit(node->this_function_var()); | 193 Visit(node->this_function_var()); |
| 193 } | 194 } |
| 194 | 195 |
| 195 | 196 |
| 196 void AstNumberingVisitor::VisitExpressionStatement(ExpressionStatement* node) { | 197 void AstNumberingVisitor::VisitExpressionStatement(ExpressionStatement* node) { |
| 197 IncrementNodeCount(); | 198 IncrementNodeCount(); |
| 198 Visit(node->expression()); | 199 Visit(node->expression()); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 if (node->is_jsruntime() && | 276 if (node->is_jsruntime() && |
| 276 node->context_index() == Context::ASYNC_FUNCTION_AWAIT_CAUGHT_INDEX && | 277 node->context_index() == Context::ASYNC_FUNCTION_AWAIT_CAUGHT_INDEX && |
| 277 catch_prediction_ == HandlerTable::ASYNC_AWAIT) { | 278 catch_prediction_ == HandlerTable::ASYNC_AWAIT) { |
| 278 node->set_context_index(Context::ASYNC_FUNCTION_AWAIT_UNCAUGHT_INDEX); | 279 node->set_context_index(Context::ASYNC_FUNCTION_AWAIT_UNCAUGHT_INDEX); |
| 279 } | 280 } |
| 280 } | 281 } |
| 281 | 282 |
| 282 | 283 |
| 283 void AstNumberingVisitor::VisitWithStatement(WithStatement* node) { | 284 void AstNumberingVisitor::VisitWithStatement(WithStatement* node) { |
| 284 IncrementNodeCount(); | 285 IncrementNodeCount(); |
| 285 DisableCrankshaft(kWithStatement); | 286 DisableFullCodegenAndCrankshaft(kWithStatement); |
| 286 node->set_base_id(ReserveIdRange(WithStatement::num_ids())); | 287 node->set_base_id(ReserveIdRange(WithStatement::num_ids())); |
| 287 Visit(node->expression()); | 288 Visit(node->expression()); |
| 288 Visit(node->statement()); | 289 Visit(node->statement()); |
| 289 } | 290 } |
| 290 | 291 |
| 291 | 292 |
| 292 void AstNumberingVisitor::VisitDoWhileStatement(DoWhileStatement* node) { | 293 void AstNumberingVisitor::VisitDoWhileStatement(DoWhileStatement* node) { |
| 293 IncrementNodeCount(); | 294 IncrementNodeCount(); |
| 294 DisableSelfOptimization(); | 295 DisableSelfOptimization(); |
| 295 node->set_base_id(ReserveIdRange(DoWhileStatement::num_ids())); | 296 node->set_base_id(ReserveIdRange(DoWhileStatement::num_ids())); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 306 node->set_base_id(ReserveIdRange(WhileStatement::num_ids())); | 307 node->set_base_id(ReserveIdRange(WhileStatement::num_ids())); |
| 307 node->set_first_yield_id(yield_count_); | 308 node->set_first_yield_id(yield_count_); |
| 308 Visit(node->cond()); | 309 Visit(node->cond()); |
| 309 Visit(node->body()); | 310 Visit(node->body()); |
| 310 node->set_yield_count(yield_count_ - node->first_yield_id()); | 311 node->set_yield_count(yield_count_ - node->first_yield_id()); |
| 311 } | 312 } |
| 312 | 313 |
| 313 | 314 |
| 314 void AstNumberingVisitor::VisitTryCatchStatement(TryCatchStatement* node) { | 315 void AstNumberingVisitor::VisitTryCatchStatement(TryCatchStatement* node) { |
| 315 IncrementNodeCount(); | 316 IncrementNodeCount(); |
| 316 DisableCrankshaft(kTryCatchStatement); | 317 DisableFullCodegenAndCrankshaft(kTryCatchStatement); |
| 317 { | 318 { |
| 318 const HandlerTable::CatchPrediction old_prediction = catch_prediction_; | 319 const HandlerTable::CatchPrediction old_prediction = catch_prediction_; |
| 319 // This node uses its own prediction, unless it's "uncaught", in which case | 320 // This node uses its own prediction, unless it's "uncaught", in which case |
| 320 // we adopt the prediction of the outer try-block. | 321 // we adopt the prediction of the outer try-block. |
| 321 HandlerTable::CatchPrediction catch_prediction = node->catch_prediction(); | 322 HandlerTable::CatchPrediction catch_prediction = node->catch_prediction(); |
| 322 if (catch_prediction != HandlerTable::UNCAUGHT) { | 323 if (catch_prediction != HandlerTable::UNCAUGHT) { |
| 323 catch_prediction_ = catch_prediction; | 324 catch_prediction_ = catch_prediction; |
| 324 } | 325 } |
| 325 node->set_catch_prediction(catch_prediction_); | 326 node->set_catch_prediction(catch_prediction_); |
| 326 Visit(node->try_block()); | 327 Visit(node->try_block()); |
| 327 catch_prediction_ = old_prediction; | 328 catch_prediction_ = old_prediction; |
| 328 } | 329 } |
| 329 Visit(node->catch_block()); | 330 Visit(node->catch_block()); |
| 330 } | 331 } |
| 331 | 332 |
| 332 | 333 |
| 333 void AstNumberingVisitor::VisitTryFinallyStatement(TryFinallyStatement* node) { | 334 void AstNumberingVisitor::VisitTryFinallyStatement(TryFinallyStatement* node) { |
| 334 IncrementNodeCount(); | 335 IncrementNodeCount(); |
| 335 DisableCrankshaft(kTryFinallyStatement); | 336 DisableFullCodegenAndCrankshaft(kTryFinallyStatement); |
| 336 // We can't know whether the finally block will override ("catch") an | 337 // We can't know whether the finally block will override ("catch") an |
| 337 // exception thrown in the try block, so we just adopt the outer prediction. | 338 // exception thrown in the try block, so we just adopt the outer prediction. |
| 338 node->set_catch_prediction(catch_prediction_); | 339 node->set_catch_prediction(catch_prediction_); |
| 339 Visit(node->try_block()); | 340 Visit(node->try_block()); |
| 340 Visit(node->finally_block()); | 341 Visit(node->finally_block()); |
| 341 } | 342 } |
| 342 | 343 |
| 343 | 344 |
| 344 void AstNumberingVisitor::VisitPropertyReference(Property* node) { | 345 void AstNumberingVisitor::VisitPropertyReference(Property* node) { |
| 345 IncrementNodeCount(); | 346 IncrementNodeCount(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 node->set_first_yield_id(yield_count_); | 411 node->set_first_yield_id(yield_count_); |
| 411 Visit(node->each()); | 412 Visit(node->each()); |
| 412 Visit(node->body()); | 413 Visit(node->body()); |
| 413 node->set_yield_count(yield_count_ - node->first_yield_id()); | 414 node->set_yield_count(yield_count_ - node->first_yield_id()); |
| 414 ReserveFeedbackSlots(node); | 415 ReserveFeedbackSlots(node); |
| 415 } | 416 } |
| 416 | 417 |
| 417 | 418 |
| 418 void AstNumberingVisitor::VisitForOfStatement(ForOfStatement* node) { | 419 void AstNumberingVisitor::VisitForOfStatement(ForOfStatement* node) { |
| 419 IncrementNodeCount(); | 420 IncrementNodeCount(); |
| 420 DisableCrankshaft(kForOfStatement); | 421 DisableFullCodegenAndCrankshaft(kForOfStatement); |
| 421 node->set_base_id(ReserveIdRange(ForOfStatement::num_ids())); | 422 node->set_base_id(ReserveIdRange(ForOfStatement::num_ids())); |
| 422 Visit(node->assign_iterator()); // Not part of loop. | 423 Visit(node->assign_iterator()); // Not part of loop. |
| 423 node->set_first_yield_id(yield_count_); | 424 node->set_first_yield_id(yield_count_); |
| 424 Visit(node->next_result()); | 425 Visit(node->next_result()); |
| 425 Visit(node->result_done()); | 426 Visit(node->result_done()); |
| 426 Visit(node->assign_each()); | 427 Visit(node->assign_each()); |
| 427 Visit(node->body()); | 428 Visit(node->body()); |
| 428 node->set_yield_count(yield_count_ - node->first_yield_id()); | 429 node->set_yield_count(yield_count_ - node->first_yield_id()); |
| 429 } | 430 } |
| 430 | 431 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 node->set_first_yield_id(yield_count_); | 478 node->set_first_yield_id(yield_count_); |
| 478 if (node->cond() != NULL) Visit(node->cond()); | 479 if (node->cond() != NULL) Visit(node->cond()); |
| 479 if (node->next() != NULL) Visit(node->next()); | 480 if (node->next() != NULL) Visit(node->next()); |
| 480 Visit(node->body()); | 481 Visit(node->body()); |
| 481 node->set_yield_count(yield_count_ - node->first_yield_id()); | 482 node->set_yield_count(yield_count_ - node->first_yield_id()); |
| 482 } | 483 } |
| 483 | 484 |
| 484 | 485 |
| 485 void AstNumberingVisitor::VisitClassLiteral(ClassLiteral* node) { | 486 void AstNumberingVisitor::VisitClassLiteral(ClassLiteral* node) { |
| 486 IncrementNodeCount(); | 487 IncrementNodeCount(); |
| 487 DisableCrankshaft(kClassLiteral); | 488 DisableFullCodegenAndCrankshaft(kClassLiteral); |
| 488 node->set_base_id(ReserveIdRange(node->num_ids())); | 489 node->set_base_id(ReserveIdRange(node->num_ids())); |
| 489 if (node->extends()) Visit(node->extends()); | 490 if (node->extends()) Visit(node->extends()); |
| 490 if (node->constructor()) Visit(node->constructor()); | 491 if (node->constructor()) Visit(node->constructor()); |
| 491 if (node->class_variable_proxy()) { | 492 if (node->class_variable_proxy()) { |
| 492 VisitVariableProxy(node->class_variable_proxy()); | 493 VisitVariableProxy(node->class_variable_proxy()); |
| 493 } | 494 } |
| 494 for (int i = 0; i < node->properties()->length(); i++) { | 495 for (int i = 0; i < node->properties()->length(); i++) { |
| 495 VisitLiteralProperty(node->properties()->at(i)); | 496 VisitLiteralProperty(node->properties()->at(i)); |
| 496 } | 497 } |
| 497 ReserveFeedbackSlots(node); | 498 ReserveFeedbackSlots(node); |
| 498 } | 499 } |
| 499 | 500 |
| 500 | 501 |
| 501 void AstNumberingVisitor::VisitObjectLiteral(ObjectLiteral* node) { | 502 void AstNumberingVisitor::VisitObjectLiteral(ObjectLiteral* node) { |
| 502 IncrementNodeCount(); | 503 IncrementNodeCount(); |
| 503 node->set_base_id(ReserveIdRange(node->num_ids())); | 504 node->set_base_id(ReserveIdRange(node->num_ids())); |
| 504 for (int i = 0; i < node->properties()->length(); i++) { | 505 for (int i = 0; i < node->properties()->length(); i++) { |
| 505 VisitLiteralProperty(node->properties()->at(i)); | 506 VisitLiteralProperty(node->properties()->at(i)); |
| 506 } | 507 } |
| 507 node->BuildConstantProperties(isolate_); | 508 node->BuildConstantProperties(isolate_); |
| 508 // Mark all computed expressions that are bound to a key that | 509 // Mark all computed expressions that are bound to a key that |
| 509 // is shadowed by a later occurrence of the same key. For the | 510 // is shadowed by a later occurrence of the same key. For the |
| 510 // marked expressions, no store code will be is emitted. | 511 // marked expressions, no store code will be is emitted. |
| 511 node->CalculateEmitStore(zone_); | 512 node->CalculateEmitStore(zone_); |
| 512 ReserveFeedbackSlots(node); | 513 ReserveFeedbackSlots(node); |
| 513 } | 514 } |
| 514 | 515 |
| 515 void AstNumberingVisitor::VisitLiteralProperty(LiteralProperty* node) { | 516 void AstNumberingVisitor::VisitLiteralProperty(LiteralProperty* node) { |
| 516 if (node->is_computed_name()) DisableCrankshaft(kComputedPropertyName); | 517 if (node->is_computed_name()) |
| 518 DisableFullCodegenAndCrankshaft(kComputedPropertyName); |
| 517 Visit(node->key()); | 519 Visit(node->key()); |
| 518 Visit(node->value()); | 520 Visit(node->value()); |
| 519 } | 521 } |
| 520 | 522 |
| 521 void AstNumberingVisitor::VisitArrayLiteral(ArrayLiteral* node) { | 523 void AstNumberingVisitor::VisitArrayLiteral(ArrayLiteral* node) { |
| 522 IncrementNodeCount(); | 524 IncrementNodeCount(); |
| 523 node->set_base_id(ReserveIdRange(node->num_ids())); | 525 node->set_base_id(ReserveIdRange(node->num_ids())); |
| 524 for (int i = 0; i < node->values()->length(); i++) { | 526 for (int i = 0; i < node->values()->length(); i++) { |
| 525 Visit(node->values()->at(i)); | 527 Visit(node->values()->at(i)); |
| 526 } | 528 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 void AstNumberingVisitor::VisitRewritableExpression( | 579 void AstNumberingVisitor::VisitRewritableExpression( |
| 578 RewritableExpression* node) { | 580 RewritableExpression* node) { |
| 579 IncrementNodeCount(); | 581 IncrementNodeCount(); |
| 580 node->set_base_id(ReserveIdRange(RewritableExpression::num_ids())); | 582 node->set_base_id(ReserveIdRange(RewritableExpression::num_ids())); |
| 581 Visit(node->expression()); | 583 Visit(node->expression()); |
| 582 } | 584 } |
| 583 | 585 |
| 584 | 586 |
| 585 bool AstNumberingVisitor::Renumber(FunctionLiteral* node) { | 587 bool AstNumberingVisitor::Renumber(FunctionLiteral* node) { |
| 586 DeclarationScope* scope = node->scope(); | 588 DeclarationScope* scope = node->scope(); |
| 587 if (scope->new_target_var()) DisableCrankshaft(kSuperReference); | 589 if (scope->new_target_var()) DisableFullCodegenAndCrankshaft(kSuperReference); |
| 588 if (scope->calls_eval()) DisableCrankshaft(kFunctionCallsEval); | 590 if (scope->calls_eval()) DisableFullCodegenAndCrankshaft(kFunctionCallsEval); |
| 589 if (scope->arguments() != NULL && !scope->arguments()->IsStackAllocated()) { | 591 if (scope->arguments() != NULL && !scope->arguments()->IsStackAllocated()) { |
| 590 DisableCrankshaft(kContextAllocatedArguments); | 592 DisableFullCodegenAndCrankshaft(kContextAllocatedArguments); |
| 591 } | 593 } |
| 592 | 594 |
| 593 if (scope->rest_parameter() != nullptr) { | 595 if (scope->rest_parameter() != nullptr) { |
| 594 DisableCrankshaft(kRestParameter); | 596 DisableFullCodegenAndCrankshaft(kRestParameter); |
| 595 } | 597 } |
| 596 | 598 |
| 597 if (IsResumableFunction(node->kind())) { | 599 if (IsResumableFunction(node->kind())) { |
| 598 DisableCrankshaft(kGenerator); | 600 DisableFullCodegenAndCrankshaft(kGenerator); |
| 599 } | 601 } |
| 600 | 602 |
| 601 if (IsClassConstructor(node->kind())) { | 603 if (IsClassConstructor(node->kind())) { |
| 602 DisableCrankshaft(kClassConstructorFunction); | 604 DisableFullCodegenAndCrankshaft(kClassConstructorFunction); |
| 603 } | 605 } |
| 604 | 606 |
| 605 VisitDeclarations(scope->declarations()); | 607 VisitDeclarations(scope->declarations()); |
| 606 VisitStatements(node->body()); | 608 VisitStatements(node->body()); |
| 607 | 609 |
| 608 node->set_ast_properties(&properties_); | 610 node->set_ast_properties(&properties_); |
| 609 node->set_dont_optimize_reason(dont_optimize_reason()); | 611 node->set_dont_optimize_reason(dont_optimize_reason()); |
| 610 node->set_yield_count(yield_count_); | 612 node->set_yield_count(yield_count_); |
| 611 return !HasStackOverflow(); | 613 return !HasStackOverflow(); |
| 612 } | 614 } |
| 613 | 615 |
| 614 | 616 |
| 615 bool AstNumbering::Renumber(Isolate* isolate, Zone* zone, | 617 bool AstNumbering::Renumber(Isolate* isolate, Zone* zone, |
| 616 FunctionLiteral* function) { | 618 FunctionLiteral* function) { |
| 617 AstNumberingVisitor visitor(isolate, zone); | 619 AstNumberingVisitor visitor(isolate, zone); |
| 618 return visitor.Renumber(function); | 620 return visitor.Renumber(function); |
| 619 } | 621 } |
| 620 } // namespace internal | 622 } // namespace internal |
| 621 } // namespace v8 | 623 } // namespace v8 |
| OLD | NEW |