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.h" | 5 #include "src/ast.h" |
6 #include "src/ast-numbering.h" | 6 #include "src/ast-numbering.h" |
7 #include "src/scopes.h" | 7 #include "src/scopes.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
11 | 11 |
12 class AstNumberingVisitor final : public AstVisitor { | 12 class AstNumberingVisitor final : public AstVisitor { |
13 public: | 13 public: |
14 explicit AstNumberingVisitor(Isolate* isolate, Zone* zone) | 14 AstNumberingVisitor(Isolate* isolate, Zone* zone) |
15 : AstVisitor(), | 15 : AstVisitor(), |
16 next_id_(BailoutId::FirstUsable().ToInt()), | 16 next_id_(BailoutId::FirstUsable().ToInt()), |
17 properties_(zone), | 17 properties_(zone), |
18 ic_slot_cache_(4), | 18 ic_slot_cache_(4), |
19 dont_optimize_reason_(kNoReason) { | 19 dont_optimize_reason_(kNoReason) { |
20 InitializeAstVisitor(isolate, zone); | 20 InitializeAstVisitor(isolate, zone); |
21 } | 21 } |
22 | 22 |
23 bool Renumber(FunctionLiteral* node); | 23 bool Renumber(FunctionLiteral* node); |
24 | 24 |
25 private: | 25 private: |
26 // AST node visitor interface. | 26 // AST node visitor interface. |
27 #define DEFINE_VISIT(type) virtual void Visit##type(type* node) override; | 27 #define DEFINE_VISIT(type) virtual void Visit##type(type* node) override; |
28 AST_NODE_LIST(DEFINE_VISIT) | 28 AST_NODE_LIST(DEFINE_VISIT) |
29 #undef DEFINE_VISIT | 29 #undef DEFINE_VISIT |
30 | 30 |
31 bool Finish(FunctionLiteral* node); | 31 bool Finish(FunctionLiteral* node); |
32 | 32 |
| 33 void VisitVariableProxyReference(VariableProxy* node); |
| 34 void VisitPropertyReference(Property* node); |
| 35 void VisitReference(Expression* expr); |
| 36 |
33 void VisitStatements(ZoneList<Statement*>* statements) override; | 37 void VisitStatements(ZoneList<Statement*>* statements) override; |
34 void VisitDeclarations(ZoneList<Declaration*>* declarations) override; | 38 void VisitDeclarations(ZoneList<Declaration*>* declarations) override; |
35 void VisitArguments(ZoneList<Expression*>* arguments); | 39 void VisitArguments(ZoneList<Expression*>* arguments); |
36 void VisitObjectLiteralProperty(ObjectLiteralProperty* property); | 40 void VisitObjectLiteralProperty(ObjectLiteralProperty* property); |
37 | 41 |
38 int ReserveIdRange(int n) { | 42 int ReserveIdRange(int n) { |
39 int tmp = next_id_; | 43 int tmp = next_id_; |
40 next_id_ += n; | 44 next_id_ += n; |
41 return tmp; | 45 return tmp; |
42 } | 46 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 node->set_base_id(ReserveIdRange(Literal::num_ids())); | 142 node->set_base_id(ReserveIdRange(Literal::num_ids())); |
139 } | 143 } |
140 | 144 |
141 | 145 |
142 void AstNumberingVisitor::VisitRegExpLiteral(RegExpLiteral* node) { | 146 void AstNumberingVisitor::VisitRegExpLiteral(RegExpLiteral* node) { |
143 IncrementNodeCount(); | 147 IncrementNodeCount(); |
144 node->set_base_id(ReserveIdRange(RegExpLiteral::num_ids())); | 148 node->set_base_id(ReserveIdRange(RegExpLiteral::num_ids())); |
145 } | 149 } |
146 | 150 |
147 | 151 |
| 152 void AstNumberingVisitor::VisitVariableProxyReference(VariableProxy* node) { |
| 153 IncrementNodeCount(); |
| 154 if (node->var()->IsLookupSlot()) { |
| 155 DisableCrankshaft(kReferenceToAVariableWhichRequiresDynamicLookup); |
| 156 } |
| 157 node->set_base_id(ReserveIdRange(VariableProxy::num_ids())); |
| 158 } |
| 159 |
| 160 |
148 void AstNumberingVisitor::VisitVariableProxy(VariableProxy* node) { | 161 void AstNumberingVisitor::VisitVariableProxy(VariableProxy* node) { |
149 IncrementNodeCount(); | 162 VisitVariableProxyReference(node); |
150 if (node->var()->IsLookupSlot()) { | |
151 DisableCrankshaft(kReferenceToAVariableWhichRequiresDynamicLookup); | |
152 } | |
153 ReserveFeedbackSlots(node); | 163 ReserveFeedbackSlots(node); |
154 node->set_base_id(ReserveIdRange(VariableProxy::num_ids())); | |
155 } | 164 } |
156 | 165 |
157 | 166 |
158 void AstNumberingVisitor::VisitThisFunction(ThisFunction* node) { | 167 void AstNumberingVisitor::VisitThisFunction(ThisFunction* node) { |
159 IncrementNodeCount(); | 168 IncrementNodeCount(); |
160 node->set_base_id(ReserveIdRange(ThisFunction::num_ids())); | 169 node->set_base_id(ReserveIdRange(ThisFunction::num_ids())); |
161 } | 170 } |
162 | 171 |
163 | 172 |
164 void AstNumberingVisitor::VisitSuperPropertyReference( | 173 void AstNumberingVisitor::VisitSuperPropertyReference( |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 306 |
298 void AstNumberingVisitor::VisitTryFinallyStatement(TryFinallyStatement* node) { | 307 void AstNumberingVisitor::VisitTryFinallyStatement(TryFinallyStatement* node) { |
299 IncrementNodeCount(); | 308 IncrementNodeCount(); |
300 DisableOptimization(kTryFinallyStatement); | 309 DisableOptimization(kTryFinallyStatement); |
301 node->set_base_id(ReserveIdRange(TryFinallyStatement::num_ids())); | 310 node->set_base_id(ReserveIdRange(TryFinallyStatement::num_ids())); |
302 Visit(node->try_block()); | 311 Visit(node->try_block()); |
303 Visit(node->finally_block()); | 312 Visit(node->finally_block()); |
304 } | 313 } |
305 | 314 |
306 | 315 |
| 316 void AstNumberingVisitor::VisitPropertyReference(Property* node) { |
| 317 IncrementNodeCount(); |
| 318 node->set_base_id(ReserveIdRange(Property::num_ids())); |
| 319 Visit(node->key()); |
| 320 Visit(node->obj()); |
| 321 } |
| 322 |
| 323 |
| 324 void AstNumberingVisitor::VisitReference(Expression* expr) { |
| 325 DCHECK(expr->IsProperty() || expr->IsVariableProxy()); |
| 326 if (expr->IsProperty()) { |
| 327 VisitPropertyReference(expr->AsProperty()); |
| 328 } else { |
| 329 VisitVariableProxyReference(expr->AsVariableProxy()); |
| 330 } |
| 331 } |
| 332 |
| 333 |
307 void AstNumberingVisitor::VisitProperty(Property* node) { | 334 void AstNumberingVisitor::VisitProperty(Property* node) { |
308 IncrementNodeCount(); | 335 VisitPropertyReference(node); |
309 ReserveFeedbackSlots(node); | 336 ReserveFeedbackSlots(node); |
310 node->set_base_id(ReserveIdRange(Property::num_ids())); | |
311 Visit(node->key()); | |
312 Visit(node->obj()); | |
313 } | 337 } |
314 | 338 |
315 | 339 |
316 void AstNumberingVisitor::VisitAssignment(Assignment* node) { | 340 void AstNumberingVisitor::VisitAssignment(Assignment* node) { |
317 IncrementNodeCount(); | 341 IncrementNodeCount(); |
318 node->set_base_id(ReserveIdRange(Assignment::num_ids())); | 342 node->set_base_id(ReserveIdRange(Assignment::num_ids())); |
319 if (node->is_compound()) VisitBinaryOperation(node->binary_operation()); | 343 if (node->is_compound()) VisitBinaryOperation(node->binary_operation()); |
320 Visit(node->target()); | 344 VisitReference(node->target()); |
321 Visit(node->value()); | 345 Visit(node->value()); |
322 ReserveFeedbackSlots(node); | 346 ReserveFeedbackSlots(node); |
323 } | 347 } |
324 | 348 |
325 | 349 |
326 void AstNumberingVisitor::VisitBinaryOperation(BinaryOperation* node) { | 350 void AstNumberingVisitor::VisitBinaryOperation(BinaryOperation* node) { |
327 IncrementNodeCount(); | 351 IncrementNodeCount(); |
328 node->set_base_id(ReserveIdRange(BinaryOperation::num_ids())); | 352 node->set_base_id(ReserveIdRange(BinaryOperation::num_ids())); |
329 Visit(node->left()); | 353 Visit(node->left()); |
330 Visit(node->right()); | 354 Visit(node->right()); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 } | 568 } |
545 | 569 |
546 | 570 |
547 bool AstNumbering::Renumber(Isolate* isolate, Zone* zone, | 571 bool AstNumbering::Renumber(Isolate* isolate, Zone* zone, |
548 FunctionLiteral* function) { | 572 FunctionLiteral* function) { |
549 AstNumberingVisitor visitor(isolate, zone); | 573 AstNumberingVisitor visitor(isolate, zone); |
550 return visitor.Renumber(function); | 574 return visitor.Renumber(function); |
551 } | 575 } |
552 } // namespace internal | 576 } // namespace internal |
553 } // namespace v8 | 577 } // namespace v8 |
OLD | NEW |