| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 | 66 |
| 67 template <typename Node> | 67 template <typename Node> |
| 68 void ReserveFeedbackSlots(Node* node) { | 68 void ReserveFeedbackSlots(Node* node) { |
| 69 node->AssignFeedbackVectorSlots(isolate_, properties_.get_spec(), | 69 node->AssignFeedbackVectorSlots(isolate_, properties_.get_spec(), |
| 70 &slot_cache_); | 70 &slot_cache_); |
| 71 } | 71 } |
| 72 | 72 |
| 73 BailoutReason dont_optimize_reason() const { return dont_optimize_reason_; } | 73 BailoutReason dont_optimize_reason() const { return dont_optimize_reason_; } |
| 74 | 74 |
| 75 int GetAndResetYieldCount() { | |
| 76 int old_yield_count = yield_count_; | |
| 77 yield_count_ = 0; | |
| 78 return old_yield_count; | |
| 79 } | |
| 80 | |
| 81 void StoreAndUpdateYieldCount(IterationStatement* node, int old_yield_count) { | |
| 82 node->set_yield_count(yield_count_); | |
| 83 yield_count_ += old_yield_count; | |
| 84 } | |
| 85 | |
| 86 Isolate* isolate_; | 75 Isolate* isolate_; |
| 87 Zone* zone_; | 76 Zone* zone_; |
| 88 int next_id_; | 77 int next_id_; |
| 89 int yield_count_; | 78 int yield_count_; |
| 90 AstProperties properties_; | 79 AstProperties properties_; |
| 91 // The slot cache allows us to reuse certain feedback vector slots. | 80 // The slot cache allows us to reuse certain feedback vector slots. |
| 92 FeedbackVectorSlotCache slot_cache_; | 81 FeedbackVectorSlotCache slot_cache_; |
| 93 BailoutReason dont_optimize_reason_; | 82 BailoutReason dont_optimize_reason_; |
| 94 | 83 |
| 95 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); | 84 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } | 210 } |
| 222 | 211 |
| 223 | 212 |
| 224 void AstNumberingVisitor::VisitReturnStatement(ReturnStatement* node) { | 213 void AstNumberingVisitor::VisitReturnStatement(ReturnStatement* node) { |
| 225 IncrementNodeCount(); | 214 IncrementNodeCount(); |
| 226 Visit(node->expression()); | 215 Visit(node->expression()); |
| 227 } | 216 } |
| 228 | 217 |
| 229 | 218 |
| 230 void AstNumberingVisitor::VisitYield(Yield* node) { | 219 void AstNumberingVisitor::VisitYield(Yield* node) { |
| 220 node->set_yield_id(yield_count_); |
| 231 yield_count_++; | 221 yield_count_++; |
| 232 IncrementNodeCount(); | 222 IncrementNodeCount(); |
| 233 DisableOptimization(kYield); | 223 DisableOptimization(kYield); |
| 234 ReserveFeedbackSlots(node); | 224 ReserveFeedbackSlots(node); |
| 235 node->set_base_id(ReserveIdRange(Yield::num_ids())); | 225 node->set_base_id(ReserveIdRange(Yield::num_ids())); |
| 236 Visit(node->generator_object()); | 226 Visit(node->generator_object()); |
| 237 Visit(node->expression()); | 227 Visit(node->expression()); |
| 238 } | 228 } |
| 239 | 229 |
| 240 | 230 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 node->set_base_id(ReserveIdRange(WithStatement::num_ids())); | 279 node->set_base_id(ReserveIdRange(WithStatement::num_ids())); |
| 290 Visit(node->expression()); | 280 Visit(node->expression()); |
| 291 Visit(node->statement()); | 281 Visit(node->statement()); |
| 292 } | 282 } |
| 293 | 283 |
| 294 | 284 |
| 295 void AstNumberingVisitor::VisitDoWhileStatement(DoWhileStatement* node) { | 285 void AstNumberingVisitor::VisitDoWhileStatement(DoWhileStatement* node) { |
| 296 IncrementNodeCount(); | 286 IncrementNodeCount(); |
| 297 DisableSelfOptimization(); | 287 DisableSelfOptimization(); |
| 298 node->set_base_id(ReserveIdRange(DoWhileStatement::num_ids())); | 288 node->set_base_id(ReserveIdRange(DoWhileStatement::num_ids())); |
| 299 int old_yield_count = GetAndResetYieldCount(); | 289 node->set_first_yield_id(yield_count_); |
| 300 Visit(node->body()); | 290 Visit(node->body()); |
| 301 Visit(node->cond()); | 291 Visit(node->cond()); |
| 302 StoreAndUpdateYieldCount(node, old_yield_count); | 292 node->set_yield_count(yield_count_ - node->first_yield_id()); |
| 303 } | 293 } |
| 304 | 294 |
| 305 | 295 |
| 306 void AstNumberingVisitor::VisitWhileStatement(WhileStatement* node) { | 296 void AstNumberingVisitor::VisitWhileStatement(WhileStatement* node) { |
| 307 IncrementNodeCount(); | 297 IncrementNodeCount(); |
| 308 DisableSelfOptimization(); | 298 DisableSelfOptimization(); |
| 309 node->set_base_id(ReserveIdRange(WhileStatement::num_ids())); | 299 node->set_base_id(ReserveIdRange(WhileStatement::num_ids())); |
| 310 int old_yield_count = GetAndResetYieldCount(); | 300 node->set_first_yield_id(yield_count_); |
| 311 Visit(node->cond()); | 301 Visit(node->cond()); |
| 312 Visit(node->body()); | 302 Visit(node->body()); |
| 313 StoreAndUpdateYieldCount(node, old_yield_count); | 303 node->set_yield_count(yield_count_ - node->first_yield_id()); |
| 314 } | 304 } |
| 315 | 305 |
| 316 | 306 |
| 317 void AstNumberingVisitor::VisitTryCatchStatement(TryCatchStatement* node) { | 307 void AstNumberingVisitor::VisitTryCatchStatement(TryCatchStatement* node) { |
| 318 IncrementNodeCount(); | 308 IncrementNodeCount(); |
| 319 DisableOptimization(kTryCatchStatement); | 309 DisableOptimization(kTryCatchStatement); |
| 320 Visit(node->try_block()); | 310 Visit(node->try_block()); |
| 321 Visit(node->catch_block()); | 311 Visit(node->catch_block()); |
| 322 } | 312 } |
| 323 | 313 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 void AstNumberingVisitor::VisitEmptyParentheses(EmptyParentheses* node) { | 377 void AstNumberingVisitor::VisitEmptyParentheses(EmptyParentheses* node) { |
| 388 UNREACHABLE(); | 378 UNREACHABLE(); |
| 389 } | 379 } |
| 390 | 380 |
| 391 | 381 |
| 392 void AstNumberingVisitor::VisitForInStatement(ForInStatement* node) { | 382 void AstNumberingVisitor::VisitForInStatement(ForInStatement* node) { |
| 393 IncrementNodeCount(); | 383 IncrementNodeCount(); |
| 394 DisableSelfOptimization(); | 384 DisableSelfOptimization(); |
| 395 node->set_base_id(ReserveIdRange(ForInStatement::num_ids())); | 385 node->set_base_id(ReserveIdRange(ForInStatement::num_ids())); |
| 396 Visit(node->enumerable()); // Not part of loop. | 386 Visit(node->enumerable()); // Not part of loop. |
| 397 int old_yield_count = GetAndResetYieldCount(); | 387 node->set_first_yield_id(yield_count_); |
| 398 Visit(node->each()); | 388 Visit(node->each()); |
| 399 Visit(node->body()); | 389 Visit(node->body()); |
| 400 StoreAndUpdateYieldCount(node, old_yield_count); | 390 node->set_yield_count(yield_count_ - node->first_yield_id()); |
| 401 ReserveFeedbackSlots(node); | 391 ReserveFeedbackSlots(node); |
| 402 } | 392 } |
| 403 | 393 |
| 404 | 394 |
| 405 void AstNumberingVisitor::VisitForOfStatement(ForOfStatement* node) { | 395 void AstNumberingVisitor::VisitForOfStatement(ForOfStatement* node) { |
| 406 IncrementNodeCount(); | 396 IncrementNodeCount(); |
| 407 DisableCrankshaft(kForOfStatement); | 397 DisableCrankshaft(kForOfStatement); |
| 408 node->set_base_id(ReserveIdRange(ForOfStatement::num_ids())); | 398 node->set_base_id(ReserveIdRange(ForOfStatement::num_ids())); |
| 409 Visit(node->assign_iterator()); // Not part of loop. | 399 Visit(node->assign_iterator()); // Not part of loop. |
| 410 int old_yield_count = GetAndResetYieldCount(); | 400 node->set_first_yield_id(yield_count_); |
| 411 Visit(node->next_result()); | 401 Visit(node->next_result()); |
| 412 Visit(node->result_done()); | 402 Visit(node->result_done()); |
| 413 Visit(node->assign_each()); | 403 Visit(node->assign_each()); |
| 414 Visit(node->body()); | 404 Visit(node->body()); |
| 415 StoreAndUpdateYieldCount(node, old_yield_count); | 405 node->set_yield_count(yield_count_ - node->first_yield_id()); |
| 416 ReserveFeedbackSlots(node); | 406 ReserveFeedbackSlots(node); |
| 417 } | 407 } |
| 418 | 408 |
| 419 | 409 |
| 420 void AstNumberingVisitor::VisitConditional(Conditional* node) { | 410 void AstNumberingVisitor::VisitConditional(Conditional* node) { |
| 421 IncrementNodeCount(); | 411 IncrementNodeCount(); |
| 422 node->set_base_id(ReserveIdRange(Conditional::num_ids())); | 412 node->set_base_id(ReserveIdRange(Conditional::num_ids())); |
| 423 Visit(node->condition()); | 413 Visit(node->condition()); |
| 424 Visit(node->then_expression()); | 414 Visit(node->then_expression()); |
| 425 Visit(node->else_expression()); | 415 Visit(node->else_expression()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 454 if (!node->is_default()) Visit(node->label()); | 444 if (!node->is_default()) Visit(node->label()); |
| 455 VisitStatements(node->statements()); | 445 VisitStatements(node->statements()); |
| 456 } | 446 } |
| 457 | 447 |
| 458 | 448 |
| 459 void AstNumberingVisitor::VisitForStatement(ForStatement* node) { | 449 void AstNumberingVisitor::VisitForStatement(ForStatement* node) { |
| 460 IncrementNodeCount(); | 450 IncrementNodeCount(); |
| 461 DisableSelfOptimization(); | 451 DisableSelfOptimization(); |
| 462 node->set_base_id(ReserveIdRange(ForStatement::num_ids())); | 452 node->set_base_id(ReserveIdRange(ForStatement::num_ids())); |
| 463 if (node->init() != NULL) Visit(node->init()); // Not part of loop. | 453 if (node->init() != NULL) Visit(node->init()); // Not part of loop. |
| 464 int old_yield_count = GetAndResetYieldCount(); | 454 node->set_first_yield_id(yield_count_); |
| 465 if (node->cond() != NULL) Visit(node->cond()); | 455 if (node->cond() != NULL) Visit(node->cond()); |
| 466 if (node->next() != NULL) Visit(node->next()); | 456 if (node->next() != NULL) Visit(node->next()); |
| 467 Visit(node->body()); | 457 Visit(node->body()); |
| 468 StoreAndUpdateYieldCount(node, old_yield_count); | 458 node->set_yield_count(yield_count_ - node->first_yield_id()); |
| 469 } | 459 } |
| 470 | 460 |
| 471 | 461 |
| 472 void AstNumberingVisitor::VisitClassLiteral(ClassLiteral* node) { | 462 void AstNumberingVisitor::VisitClassLiteral(ClassLiteral* node) { |
| 473 IncrementNodeCount(); | 463 IncrementNodeCount(); |
| 474 DisableCrankshaft(kClassLiteral); | 464 DisableCrankshaft(kClassLiteral); |
| 475 node->set_base_id(ReserveIdRange(node->num_ids())); | 465 node->set_base_id(ReserveIdRange(node->num_ids())); |
| 476 if (node->extends()) Visit(node->extends()); | 466 if (node->extends()) Visit(node->extends()); |
| 477 if (node->constructor()) Visit(node->constructor()); | 467 if (node->constructor()) Visit(node->constructor()); |
| 478 if (node->class_variable_proxy()) { | 468 if (node->class_variable_proxy()) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 } | 589 } |
| 600 | 590 |
| 601 | 591 |
| 602 bool AstNumbering::Renumber(Isolate* isolate, Zone* zone, | 592 bool AstNumbering::Renumber(Isolate* isolate, Zone* zone, |
| 603 FunctionLiteral* function) { | 593 FunctionLiteral* function) { |
| 604 AstNumberingVisitor visitor(isolate, zone); | 594 AstNumberingVisitor visitor(isolate, zone); |
| 605 return visitor.Renumber(function); | 595 return visitor.Renumber(function); |
| 606 } | 596 } |
| 607 } // namespace internal | 597 } // namespace internal |
| 608 } // namespace v8 | 598 } // namespace v8 |
| OLD | NEW |