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 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 class AstNumberingVisitor final : public AstVisitor<AstNumberingVisitor> { | 15 class AstNumberingVisitor final : public AstVisitor<AstNumberingVisitor> { |
16 public: | 16 public: |
17 AstNumberingVisitor(Isolate* isolate, Zone* zone, | 17 AstNumberingVisitor(uintptr_t stack_limit, Zone* zone, |
18 Compiler::EagerInnerFunctionLiterals* eager_literals) | 18 Compiler::EagerInnerFunctionLiterals* eager_literals) |
19 : isolate_(isolate), | 19 : zone_(zone), |
20 zone_(zone), | |
21 eager_literals_(eager_literals), | 20 eager_literals_(eager_literals), |
22 next_id_(BailoutId::FirstUsable().ToInt()), | 21 next_id_(BailoutId::FirstUsable().ToInt()), |
23 yield_count_(0), | 22 yield_count_(0), |
24 properties_(zone), | 23 properties_(zone), |
25 slot_cache_(zone), | 24 slot_cache_(zone), |
26 disable_crankshaft_reason_(kNoReason), | 25 disable_crankshaft_reason_(kNoReason), |
27 dont_optimize_reason_(kNoReason), | 26 dont_optimize_reason_(kNoReason), |
28 catch_prediction_(HandlerTable::UNCAUGHT) { | 27 catch_prediction_(HandlerTable::UNCAUGHT) { |
29 InitializeAstVisitor(isolate); | 28 InitializeAstVisitor(stack_limit); |
30 } | 29 } |
31 | 30 |
32 bool Renumber(FunctionLiteral* node); | 31 bool Renumber(FunctionLiteral* node); |
33 | 32 |
34 private: | 33 private: |
35 // AST node visitor interface. | 34 // AST node visitor interface. |
36 #define DEFINE_VISIT(type) void Visit##type(type* node); | 35 #define DEFINE_VISIT(type) void Visit##type(type* node); |
37 AST_NODE_LIST(DEFINE_VISIT) | 36 AST_NODE_LIST(DEFINE_VISIT) |
38 #undef DEFINE_VISIT | 37 #undef DEFINE_VISIT |
39 | 38 |
(...skipping 20 matching lines...) Expand all Loading... |
60 dont_optimize_reason_ = reason; | 59 dont_optimize_reason_ = reason; |
61 DisableSelfOptimization(); | 60 DisableSelfOptimization(); |
62 } | 61 } |
63 void DisableFullCodegenAndCrankshaft(BailoutReason reason) { | 62 void DisableFullCodegenAndCrankshaft(BailoutReason reason) { |
64 disable_crankshaft_reason_ = reason; | 63 disable_crankshaft_reason_ = reason; |
65 properties_.flags() |= AstProperties::kMustUseIgnitionTurbo; | 64 properties_.flags() |= AstProperties::kMustUseIgnitionTurbo; |
66 } | 65 } |
67 | 66 |
68 template <typename Node> | 67 template <typename Node> |
69 void ReserveFeedbackSlots(Node* node) { | 68 void ReserveFeedbackSlots(Node* node) { |
70 node->AssignFeedbackVectorSlots(isolate_, properties_.get_spec(), | 69 node->AssignFeedbackVectorSlots(properties_.get_spec(), &slot_cache_); |
71 &slot_cache_); | |
72 } | 70 } |
73 | 71 |
74 BailoutReason dont_optimize_reason() const { return dont_optimize_reason_; } | 72 BailoutReason dont_optimize_reason() const { return dont_optimize_reason_; } |
75 | 73 |
76 Zone* zone() const { return zone_; } | 74 Zone* zone() const { return zone_; } |
77 | 75 |
78 Isolate* isolate_; | |
79 Zone* zone_; | 76 Zone* zone_; |
80 Compiler::EagerInnerFunctionLiterals* eager_literals_; | 77 Compiler::EagerInnerFunctionLiterals* eager_literals_; |
81 int next_id_; | 78 int next_id_; |
82 int yield_count_; | 79 int yield_count_; |
83 AstProperties properties_; | 80 AstProperties properties_; |
84 // The slot cache allows us to reuse certain feedback vector slots. | 81 // The slot cache allows us to reuse certain feedback vector slots. |
85 FeedbackVectorSlotCache slot_cache_; | 82 FeedbackVectorSlotCache slot_cache_; |
86 BailoutReason disable_crankshaft_reason_; | 83 BailoutReason disable_crankshaft_reason_; |
87 BailoutReason dont_optimize_reason_; | 84 BailoutReason dont_optimize_reason_; |
88 HandlerTable::CatchPrediction catch_prediction_; | 85 HandlerTable::CatchPrediction catch_prediction_; |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 ReserveFeedbackSlots(node); | 522 ReserveFeedbackSlots(node); |
526 } | 523 } |
527 | 524 |
528 | 525 |
529 void AstNumberingVisitor::VisitObjectLiteral(ObjectLiteral* node) { | 526 void AstNumberingVisitor::VisitObjectLiteral(ObjectLiteral* node) { |
530 IncrementNodeCount(); | 527 IncrementNodeCount(); |
531 node->set_base_id(ReserveIdRange(node->num_ids())); | 528 node->set_base_id(ReserveIdRange(node->num_ids())); |
532 for (int i = 0; i < node->properties()->length(); i++) { | 529 for (int i = 0; i < node->properties()->length(); i++) { |
533 VisitLiteralProperty(node->properties()->at(i)); | 530 VisitLiteralProperty(node->properties()->at(i)); |
534 } | 531 } |
535 node->BuildConstantProperties(isolate_); | 532 node->InitDepthAndFlags(); |
536 // Mark all computed expressions that are bound to a key that | 533 // Mark all computed expressions that are bound to a key that |
537 // is shadowed by a later occurrence of the same key. For the | 534 // is shadowed by a later occurrence of the same key. For the |
538 // marked expressions, no store code will be is emitted. | 535 // marked expressions, no store code will be is emitted. |
539 node->CalculateEmitStore(zone_); | 536 node->CalculateEmitStore(zone_); |
540 ReserveFeedbackSlots(node); | 537 ReserveFeedbackSlots(node); |
541 } | 538 } |
542 | 539 |
543 void AstNumberingVisitor::VisitLiteralProperty(LiteralProperty* node) { | 540 void AstNumberingVisitor::VisitLiteralProperty(LiteralProperty* node) { |
544 if (node->is_computed_name()) | 541 if (node->is_computed_name()) |
545 DisableFullCodegenAndCrankshaft(kComputedPropertyName); | 542 DisableFullCodegenAndCrankshaft(kComputedPropertyName); |
546 Visit(node->key()); | 543 Visit(node->key()); |
547 Visit(node->value()); | 544 Visit(node->value()); |
548 } | 545 } |
549 | 546 |
550 void AstNumberingVisitor::VisitArrayLiteral(ArrayLiteral* node) { | 547 void AstNumberingVisitor::VisitArrayLiteral(ArrayLiteral* node) { |
551 IncrementNodeCount(); | 548 IncrementNodeCount(); |
552 node->set_base_id(ReserveIdRange(node->num_ids())); | 549 node->set_base_id(ReserveIdRange(node->num_ids())); |
553 for (int i = 0; i < node->values()->length(); i++) { | 550 for (int i = 0; i < node->values()->length(); i++) { |
554 Visit(node->values()->at(i)); | 551 Visit(node->values()->at(i)); |
555 } | 552 } |
556 node->BuildConstantElements(isolate_); | 553 node->InitDepthAndFlags(); |
557 ReserveFeedbackSlots(node); | 554 ReserveFeedbackSlots(node); |
558 } | 555 } |
559 | 556 |
560 | 557 |
561 void AstNumberingVisitor::VisitCall(Call* node) { | 558 void AstNumberingVisitor::VisitCall(Call* node) { |
562 if (node->is_possibly_eval()) { | 559 if (node->is_possibly_eval()) { |
563 DisableFullCodegenAndCrankshaft(kFunctionCallsEval); | 560 DisableFullCodegenAndCrankshaft(kFunctionCallsEval); |
564 } | 561 } |
565 IncrementNodeCount(); | 562 IncrementNodeCount(); |
566 ReserveFeedbackSlots(node); | 563 ReserveFeedbackSlots(node); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 PrintF("[enforcing Ignition and TurboFan for %s because: %s\n", | 652 PrintF("[enforcing Ignition and TurboFan for %s because: %s\n", |
656 node->debug_name()->ToCString().get(), | 653 node->debug_name()->ToCString().get(), |
657 GetBailoutReason(disable_crankshaft_reason_)); | 654 GetBailoutReason(disable_crankshaft_reason_)); |
658 } | 655 } |
659 } | 656 } |
660 | 657 |
661 return !HasStackOverflow(); | 658 return !HasStackOverflow(); |
662 } | 659 } |
663 | 660 |
664 bool AstNumbering::Renumber( | 661 bool AstNumbering::Renumber( |
665 Isolate* isolate, Zone* zone, FunctionLiteral* function, | 662 uintptr_t stack_limit, Zone* zone, FunctionLiteral* function, |
666 Compiler::EagerInnerFunctionLiterals* eager_literals) { | 663 Compiler::EagerInnerFunctionLiterals* eager_literals) { |
667 AstNumberingVisitor visitor(isolate, zone, eager_literals); | 664 DisallowHeapAllocation no_allocation; |
| 665 DisallowHandleAllocation no_handles; |
| 666 DisallowHandleDereference no_deref; |
| 667 |
| 668 AstNumberingVisitor visitor(stack_limit, zone, eager_literals); |
668 return visitor.Renumber(function); | 669 return visitor.Renumber(function); |
669 } | 670 } |
670 } // namespace internal | 671 } // namespace internal |
671 } // namespace v8 | 672 } // namespace v8 |
OLD | NEW |