| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef V8_COMPILER_AST_GRAPH_BUILDER_H_ | 5 #ifndef V8_COMPILER_AST_GRAPH_BUILDER_H_ |
| 6 #define V8_COMPILER_AST_GRAPH_BUILDER_H_ | 6 #define V8_COMPILER_AST_GRAPH_BUILDER_H_ |
| 7 | 7 |
| 8 #include "src/ast.h" | 8 #include "src/ast.h" |
| 9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
| 10 #include "src/compiler/liveness-analyzer.h" | 10 #include "src/compiler/liveness-analyzer.h" |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 // values are stored in one list using the following layout: | 377 // values are stored in one list using the following layout: |
| 378 // | 378 // |
| 379 // [parameters (+receiver)] [locals] [operand stack] | 379 // [parameters (+receiver)] [locals] [operand stack] |
| 380 // | 380 // |
| 381 class AstGraphBuilder::Environment : public ZoneObject { | 381 class AstGraphBuilder::Environment : public ZoneObject { |
| 382 public: | 382 public: |
| 383 Environment(AstGraphBuilder* builder, Scope* scope, Node* control_dependency); | 383 Environment(AstGraphBuilder* builder, Scope* scope, Node* control_dependency); |
| 384 | 384 |
| 385 int parameters_count() const { return parameters_count_; } | 385 int parameters_count() const { return parameters_count_; } |
| 386 int locals_count() const { return locals_count_; } | 386 int locals_count() const { return locals_count_; } |
| 387 int context_chain_length() { return static_cast<int>(contexts_.size()); } |
| 387 int stack_height() { | 388 int stack_height() { |
| 388 return static_cast<int>(values()->size()) - parameters_count_ - | 389 return static_cast<int>(values()->size()) - parameters_count_ - |
| 389 locals_count_; | 390 locals_count_; |
| 390 } | 391 } |
| 391 | 392 |
| 392 // Operations on parameter or local variables. | 393 // Operations on parameter or local variables. |
| 393 void Bind(Variable* variable, Node* node); | 394 void Bind(Variable* variable, Node* node); |
| 394 Node* Lookup(Variable* variable); | 395 Node* Lookup(Variable* variable); |
| 395 void MarkAllLocalsLive(); | 396 void MarkAllLocalsLive(); |
| 396 | 397 |
| 398 // Operations on the context chain. |
| 397 Node* Context() const { return contexts_.back(); } | 399 Node* Context() const { return contexts_.back(); } |
| 398 void PushContext(Node* context) { contexts()->push_back(context); } | 400 void PushContext(Node* context) { contexts()->push_back(context); } |
| 399 void PopContext() { contexts()->pop_back(); } | 401 void PopContext() { contexts()->pop_back(); } |
| 402 void TrimContextChain(int trim_to_length) { |
| 403 contexts()->resize(trim_to_length); |
| 404 } |
| 400 | 405 |
| 401 // Operations on the operand stack. | 406 // Operations on the operand stack. |
| 402 void Push(Node* node) { | 407 void Push(Node* node) { |
| 403 values()->push_back(node); | 408 values()->push_back(node); |
| 404 } | 409 } |
| 405 Node* Top() { | 410 Node* Top() { |
| 406 DCHECK(stack_height() > 0); | 411 DCHECK(stack_height() > 0); |
| 407 return values()->back(); | 412 return values()->back(); |
| 408 } | 413 } |
| 409 Node* Pop() { | 414 Node* Pop() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 421 } | 426 } |
| 422 Node* Peek(int depth) { | 427 Node* Peek(int depth) { |
| 423 DCHECK(depth >= 0 && depth < stack_height()); | 428 DCHECK(depth >= 0 && depth < stack_height()); |
| 424 int index = static_cast<int>(values()->size()) - depth - 1; | 429 int index = static_cast<int>(values()->size()) - depth - 1; |
| 425 return values()->at(index); | 430 return values()->at(index); |
| 426 } | 431 } |
| 427 void Drop(int depth) { | 432 void Drop(int depth) { |
| 428 DCHECK(depth >= 0 && depth <= stack_height()); | 433 DCHECK(depth >= 0 && depth <= stack_height()); |
| 429 values()->erase(values()->end() - depth, values()->end()); | 434 values()->erase(values()->end() - depth, values()->end()); |
| 430 } | 435 } |
| 431 void Trim(int trim_to_height) { | 436 void TrimStack(int trim_to_height) { |
| 432 int depth = stack_height() - trim_to_height; | 437 int depth = stack_height() - trim_to_height; |
| 433 DCHECK(depth >= 0 && depth <= stack_height()); | 438 DCHECK(depth >= 0 && depth <= stack_height()); |
| 434 values()->erase(values()->end() - depth, values()->end()); | 439 values()->erase(values()->end() - depth, values()->end()); |
| 435 } | 440 } |
| 436 | 441 |
| 437 // Preserve a checkpoint of the environment for the IR graph. Any | 442 // Preserve a checkpoint of the environment for the IR graph. Any |
| 438 // further mutation of the environment will not affect checkpoints. | 443 // further mutation of the environment will not affect checkpoints. |
| 439 Node* Checkpoint(BailoutId ast_id, OutputFrameStateCombine combine = | 444 Node* Checkpoint(BailoutId ast_id, OutputFrameStateCombine combine = |
| 440 OutputFrameStateCombine::Ignore()); | 445 OutputFrameStateCombine::Ignore()); |
| 441 | 446 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 471 env->MarkAsUnreachable(); | 476 env->MarkAsUnreachable(); |
| 472 return env; | 477 return env; |
| 473 } | 478 } |
| 474 | 479 |
| 475 // Copies this environment at a loop header control-flow point. | 480 // Copies this environment at a loop header control-flow point. |
| 476 Environment* CopyForLoop(BitVector* assigned, bool is_osr = false) { | 481 Environment* CopyForLoop(BitVector* assigned, bool is_osr = false) { |
| 477 PrepareForLoop(assigned, is_osr); | 482 PrepareForLoop(assigned, is_osr); |
| 478 return CopyAndShareLiveness(); | 483 return CopyAndShareLiveness(); |
| 479 } | 484 } |
| 480 | 485 |
| 481 int ContextStackDepth() { return static_cast<int>(contexts_.size()); } | |
| 482 | |
| 483 private: | 486 private: |
| 484 AstGraphBuilder* builder_; | 487 AstGraphBuilder* builder_; |
| 485 int parameters_count_; | 488 int parameters_count_; |
| 486 int locals_count_; | 489 int locals_count_; |
| 487 LivenessAnalyzerBlock* liveness_block_; | 490 LivenessAnalyzerBlock* liveness_block_; |
| 488 NodeVector values_; | 491 NodeVector values_; |
| 489 NodeVector contexts_; | 492 NodeVector contexts_; |
| 490 Node* control_dependency_; | 493 Node* control_dependency_; |
| 491 Node* effect_dependency_; | 494 Node* effect_dependency_; |
| 492 Node* parameters_node_; | 495 Node* parameters_node_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 508 | 511 |
| 509 // Prepare environment to be used as loop header. | 512 // Prepare environment to be used as loop header. |
| 510 void PrepareForLoop(BitVector* assigned, bool is_osr = false); | 513 void PrepareForLoop(BitVector* assigned, bool is_osr = false); |
| 511 }; | 514 }; |
| 512 | 515 |
| 513 } // namespace compiler | 516 } // namespace compiler |
| 514 } // namespace internal | 517 } // namespace internal |
| 515 } // namespace v8 | 518 } // namespace v8 |
| 516 | 519 |
| 517 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ | 520 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ |
| OLD | NEW |