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 TrimContext(int trim_to_length) { contexts()->resize(trim_to_length); } | |
titzer
2015/04/02 11:03:28
TrimContextChain?
Michael Starzinger
2015/04/02 11:29:20
Done.
| |
400 | 403 |
401 // Operations on the operand stack. | 404 // Operations on the operand stack. |
402 void Push(Node* node) { | 405 void Push(Node* node) { |
403 values()->push_back(node); | 406 values()->push_back(node); |
404 } | 407 } |
405 Node* Top() { | 408 Node* Top() { |
406 DCHECK(stack_height() > 0); | 409 DCHECK(stack_height() > 0); |
407 return values()->back(); | 410 return values()->back(); |
408 } | 411 } |
409 Node* Pop() { | 412 Node* Pop() { |
(...skipping 11 matching lines...) Expand all Loading... | |
421 } | 424 } |
422 Node* Peek(int depth) { | 425 Node* Peek(int depth) { |
423 DCHECK(depth >= 0 && depth < stack_height()); | 426 DCHECK(depth >= 0 && depth < stack_height()); |
424 int index = static_cast<int>(values()->size()) - depth - 1; | 427 int index = static_cast<int>(values()->size()) - depth - 1; |
425 return values()->at(index); | 428 return values()->at(index); |
426 } | 429 } |
427 void Drop(int depth) { | 430 void Drop(int depth) { |
428 DCHECK(depth >= 0 && depth <= stack_height()); | 431 DCHECK(depth >= 0 && depth <= stack_height()); |
429 values()->erase(values()->end() - depth, values()->end()); | 432 values()->erase(values()->end() - depth, values()->end()); |
430 } | 433 } |
431 void Trim(int trim_to_height) { | 434 void Trim(int trim_to_height) { |
titzer
2015/04/02 11:03:28
Can we also rename this to TrimStack?
Michael Starzinger
2015/04/02 11:29:20
Done.
| |
432 int depth = stack_height() - trim_to_height; | 435 int depth = stack_height() - trim_to_height; |
433 DCHECK(depth >= 0 && depth <= stack_height()); | 436 DCHECK(depth >= 0 && depth <= stack_height()); |
434 values()->erase(values()->end() - depth, values()->end()); | 437 values()->erase(values()->end() - depth, values()->end()); |
435 } | 438 } |
436 | 439 |
437 // Preserve a checkpoint of the environment for the IR graph. Any | 440 // Preserve a checkpoint of the environment for the IR graph. Any |
438 // further mutation of the environment will not affect checkpoints. | 441 // further mutation of the environment will not affect checkpoints. |
439 Node* Checkpoint(BailoutId ast_id, OutputFrameStateCombine combine = | 442 Node* Checkpoint(BailoutId ast_id, OutputFrameStateCombine combine = |
440 OutputFrameStateCombine::Ignore()); | 443 OutputFrameStateCombine::Ignore()); |
441 | 444 |
(...skipping 29 matching lines...) Expand all Loading... | |
471 env->MarkAsUnreachable(); | 474 env->MarkAsUnreachable(); |
472 return env; | 475 return env; |
473 } | 476 } |
474 | 477 |
475 // Copies this environment at a loop header control-flow point. | 478 // Copies this environment at a loop header control-flow point. |
476 Environment* CopyForLoop(BitVector* assigned, bool is_osr = false) { | 479 Environment* CopyForLoop(BitVector* assigned, bool is_osr = false) { |
477 PrepareForLoop(assigned, is_osr); | 480 PrepareForLoop(assigned, is_osr); |
478 return CopyAndShareLiveness(); | 481 return CopyAndShareLiveness(); |
479 } | 482 } |
480 | 483 |
481 int ContextStackDepth() { return static_cast<int>(contexts_.size()); } | |
482 | |
483 private: | 484 private: |
484 AstGraphBuilder* builder_; | 485 AstGraphBuilder* builder_; |
485 int parameters_count_; | 486 int parameters_count_; |
486 int locals_count_; | 487 int locals_count_; |
487 LivenessAnalyzerBlock* liveness_block_; | 488 LivenessAnalyzerBlock* liveness_block_; |
488 NodeVector values_; | 489 NodeVector values_; |
489 NodeVector contexts_; | 490 NodeVector contexts_; |
490 Node* control_dependency_; | 491 Node* control_dependency_; |
491 Node* effect_dependency_; | 492 Node* effect_dependency_; |
492 Node* parameters_node_; | 493 Node* parameters_node_; |
(...skipping 15 matching lines...) Expand all Loading... | |
508 | 509 |
509 // Prepare environment to be used as loop header. | 510 // Prepare environment to be used as loop header. |
510 void PrepareForLoop(BitVector* assigned, bool is_osr = false); | 511 void PrepareForLoop(BitVector* assigned, bool is_osr = false); |
511 }; | 512 }; |
512 | 513 |
513 } // namespace compiler | 514 } // namespace compiler |
514 } // namespace internal | 515 } // namespace internal |
515 } // namespace v8 | 516 } // namespace v8 |
516 | 517 |
517 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ | 518 #endif // V8_COMPILER_AST_GRAPH_BUILDER_H_ |
OLD | NEW |