| 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 { |
| 11 namespace internal { | 11 namespace internal { |
| 12 | 12 |
| 13 class AstNumberingVisitor final : public AstVisitor { | 13 class AstNumberingVisitor final : public AstVisitor { |
| 14 public: | 14 public: |
| 15 AstNumberingVisitor(Isolate* isolate, Zone* zone) | 15 AstNumberingVisitor(Isolate* isolate, Zone* zone) |
| 16 : AstVisitor(), | 16 : AstVisitor(), |
| 17 isolate_(isolate), | 17 isolate_(isolate), |
| 18 zone_(zone), | 18 zone_(zone), |
| 19 next_id_(BailoutId::FirstUsable().ToInt()), | 19 next_id_(BailoutId::FirstUsable().ToInt()), |
| 20 yield_count_(0), | 20 yield_count_(0), |
| 21 properties_(zone), | 21 properties_(zone), |
| 22 slot_cache_(zone), | 22 slot_cache_(zone), |
| 23 dont_optimize_reason_(kNoReason) { | 23 dont_optimize_reason_(kNoReason), |
| 24 catch_predicted_(false) { |
| 24 InitializeAstVisitor(isolate); | 25 InitializeAstVisitor(isolate); |
| 25 } | 26 } |
| 26 | 27 |
| 27 bool Renumber(FunctionLiteral* node); | 28 bool Renumber(FunctionLiteral* node); |
| 28 | 29 |
| 29 private: | 30 private: |
| 30 // AST node visitor interface. | 31 // AST node visitor interface. |
| 31 #define DEFINE_VISIT(type) void Visit##type(type* node) override; | 32 #define DEFINE_VISIT(type) void Visit##type(type* node) override; |
| 32 AST_NODE_LIST(DEFINE_VISIT) | 33 AST_NODE_LIST(DEFINE_VISIT) |
| 33 #undef DEFINE_VISIT | 34 #undef DEFINE_VISIT |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 BailoutReason dont_optimize_reason() const { return dont_optimize_reason_; } | 74 BailoutReason dont_optimize_reason() const { return dont_optimize_reason_; } |
| 74 | 75 |
| 75 Isolate* isolate_; | 76 Isolate* isolate_; |
| 76 Zone* zone_; | 77 Zone* zone_; |
| 77 int next_id_; | 78 int next_id_; |
| 78 int yield_count_; | 79 int yield_count_; |
| 79 AstProperties properties_; | 80 AstProperties properties_; |
| 80 // The slot cache allows us to reuse certain feedback vector slots. | 81 // The slot cache allows us to reuse certain feedback vector slots. |
| 81 FeedbackVectorSlotCache slot_cache_; | 82 FeedbackVectorSlotCache slot_cache_; |
| 82 BailoutReason dont_optimize_reason_; | 83 BailoutReason dont_optimize_reason_; |
| 84 bool catch_predicted_; |
| 83 | 85 |
| 84 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); | 86 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
| 85 DISALLOW_COPY_AND_ASSIGN(AstNumberingVisitor); | 87 DISALLOW_COPY_AND_ASSIGN(AstNumberingVisitor); |
| 86 }; | 88 }; |
| 87 | 89 |
| 88 | 90 |
| 89 void AstNumberingVisitor::VisitVariableDeclaration(VariableDeclaration* node) { | 91 void AstNumberingVisitor::VisitVariableDeclaration(VariableDeclaration* node) { |
| 90 IncrementNodeCount(); | 92 IncrementNodeCount(); |
| 91 VisitVariableProxy(node->proxy()); | 93 VisitVariableProxy(node->proxy()); |
| 92 } | 94 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 node->set_first_yield_id(yield_count_); | 292 node->set_first_yield_id(yield_count_); |
| 291 Visit(node->cond()); | 293 Visit(node->cond()); |
| 292 Visit(node->body()); | 294 Visit(node->body()); |
| 293 node->set_yield_count(yield_count_ - node->first_yield_id()); | 295 node->set_yield_count(yield_count_ - node->first_yield_id()); |
| 294 } | 296 } |
| 295 | 297 |
| 296 | 298 |
| 297 void AstNumberingVisitor::VisitTryCatchStatement(TryCatchStatement* node) { | 299 void AstNumberingVisitor::VisitTryCatchStatement(TryCatchStatement* node) { |
| 298 IncrementNodeCount(); | 300 IncrementNodeCount(); |
| 299 DisableCrankshaft(kTryCatchStatement); | 301 DisableCrankshaft(kTryCatchStatement); |
| 300 Visit(node->try_block()); | 302 { |
| 303 const bool old_catch_predicted = catch_predicted_; |
| 304 // If the node's clear_pending_message flag is unset, we assume that the |
| 305 // catch block is a ReThrow and hence predict uncaught (unless caught by |
| 306 // outer handlers). Otherwise, we predict caught. |
| 307 const bool not_rethrow = node->clear_pending_message(); |
| 308 catch_predicted_ = catch_predicted_ || not_rethrow; |
| 309 node->set_catch_predicted(catch_predicted_); |
| 310 Visit(node->try_block()); |
| 311 catch_predicted_ = old_catch_predicted; |
| 312 } |
| 301 Visit(node->catch_block()); | 313 Visit(node->catch_block()); |
| 302 } | 314 } |
| 303 | 315 |
| 304 | 316 |
| 305 void AstNumberingVisitor::VisitTryFinallyStatement(TryFinallyStatement* node) { | 317 void AstNumberingVisitor::VisitTryFinallyStatement(TryFinallyStatement* node) { |
| 306 IncrementNodeCount(); | 318 IncrementNodeCount(); |
| 307 DisableCrankshaft(kTryFinallyStatement); | 319 DisableCrankshaft(kTryFinallyStatement); |
| 320 // We can't know whether the finally block will override ("catch") an |
| 321 // exception thrown in the try block, so we just adopt the outer prediction. |
| 322 node->set_catch_predicted(catch_predicted_); |
| 308 Visit(node->try_block()); | 323 Visit(node->try_block()); |
| 309 Visit(node->finally_block()); | 324 Visit(node->finally_block()); |
| 310 } | 325 } |
| 311 | 326 |
| 312 | 327 |
| 313 void AstNumberingVisitor::VisitPropertyReference(Property* node) { | 328 void AstNumberingVisitor::VisitPropertyReference(Property* node) { |
| 314 IncrementNodeCount(); | 329 IncrementNodeCount(); |
| 315 node->set_base_id(ReserveIdRange(Property::num_ids())); | 330 node->set_base_id(ReserveIdRange(Property::num_ids())); |
| 316 Visit(node->key()); | 331 Visit(node->key()); |
| 317 Visit(node->obj()); | 332 Visit(node->obj()); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 } | 600 } |
| 586 | 601 |
| 587 | 602 |
| 588 bool AstNumbering::Renumber(Isolate* isolate, Zone* zone, | 603 bool AstNumbering::Renumber(Isolate* isolate, Zone* zone, |
| 589 FunctionLiteral* function) { | 604 FunctionLiteral* function) { |
| 590 AstNumberingVisitor visitor(isolate, zone); | 605 AstNumberingVisitor visitor(isolate, zone); |
| 591 return visitor.Renumber(function); | 606 return visitor.Renumber(function); |
| 592 } | 607 } |
| 593 } // namespace internal | 608 } // namespace internal |
| 594 } // namespace v8 | 609 } // namespace v8 |
| OLD | NEW |