| 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 #ifndef V8_FULL_CODEGEN_H_ | 5 #ifndef V8_FULL_CODEGEN_H_ |
| 6 #define V8_FULL_CODEGEN_H_ | 6 #define V8_FULL_CODEGEN_H_ |
| 7 | 7 |
| 8 #include "v8.h" | 8 #include "v8.h" |
| 9 | 9 |
| 10 #include "allocation.h" | 10 #include "allocation.h" |
| 11 #include "assert-scope.h" | 11 #include "assert-scope.h" |
| 12 #include "ast.h" | 12 #include "ast.h" |
| 13 #include "code-stubs.h" | 13 #include "code-stubs.h" |
| 14 #include "codegen.h" | 14 #include "codegen.h" |
| 15 #include "compiler.h" | 15 #include "compiler.h" |
| 16 #include "data-flow.h" | 16 #include "data-flow.h" |
| 17 #include "globals.h" | 17 #include "globals.h" |
| 18 #include "objects.h" | 18 #include "objects.h" |
| 19 | 19 |
| 20 namespace v8 { | 20 namespace v8 { |
| 21 namespace internal { | 21 namespace internal { |
| 22 | 22 |
| 23 #if defined(COMPARE_OPT_STACK_HEIGHT) |
| 24 |
| 25 class StackHeightWrapper { |
| 26 public: |
| 27 StackHeightWrapper() : stack_height_(0) { } |
| 28 |
| 29 void updateBy(int incrementBy) { |
| 30 stack_height_ += incrementBy; |
| 31 ASSERT(stack_height_ >= 0); |
| 32 } |
| 33 |
| 34 int get() const { return stack_height_; } |
| 35 |
| 36 private: |
| 37 int stack_height_; |
| 38 }; |
| 39 |
| 40 #else |
| 41 |
| 42 class StackHeightWrapper { |
| 43 public: |
| 44 StackHeightWrapper() { } |
| 45 void updateBy(int incrementBy) { } |
| 46 int get() const { return 0; } |
| 47 }; |
| 48 |
| 49 #endif // defined(COMPARE_OPT_STACK_HEIGHT) |
| 50 |
| 23 // Forward declarations. | 51 // Forward declarations. |
| 24 class JumpPatchSite; | 52 class JumpPatchSite; |
| 25 | 53 |
| 26 // AST node visitor which can tell whether a given statement will be breakable | 54 // AST node visitor which can tell whether a given statement will be breakable |
| 27 // when the code is compiled by the full compiler in the debugger. This means | 55 // when the code is compiled by the full compiler in the debugger. This means |
| 28 // that there will be an IC (load/store/call) in the code generated for the | 56 // that there will be an IC (load/store/call) in the code generated for the |
| 29 // debugger to piggybag on. | 57 // debugger to piggybag on. |
| 30 class BreakableStatementChecker: public AstVisitor { | 58 class BreakableStatementChecker: public AstVisitor { |
| 31 public: | 59 public: |
| 32 explicit BreakableStatementChecker(Zone* zone) : is_breakable_(false) { | 60 explicit BreakableStatementChecker(Zone* zone) : is_breakable_(false) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 // return and give it a chance to generate cleanup code. Return the | 176 // return and give it a chance to generate cleanup code. Return the |
| 149 // next outer statement in the nesting stack. We accumulate in | 177 // next outer statement in the nesting stack. We accumulate in |
| 150 // *stack_depth the amount to drop the stack and in *context_length the | 178 // *stack_depth the amount to drop the stack and in *context_length the |
| 151 // number of context chain links to unwind as we traverse the nesting | 179 // number of context chain links to unwind as we traverse the nesting |
| 152 // stack from an exit to its target. | 180 // stack from an exit to its target. |
| 153 virtual NestedStatement* Exit(int* stack_depth, int* context_length) { | 181 virtual NestedStatement* Exit(int* stack_depth, int* context_length) { |
| 154 return previous_; | 182 return previous_; |
| 155 } | 183 } |
| 156 | 184 |
| 157 protected: | 185 protected: |
| 186 FullCodeGenerator* codegen() { return codegen_; } |
| 187 |
| 158 MacroAssembler* masm() { return codegen_->masm(); } | 188 MacroAssembler* masm() { return codegen_->masm(); } |
| 159 | 189 |
| 160 FullCodeGenerator* codegen_; | 190 FullCodeGenerator* codegen_; |
| 161 NestedStatement* previous_; | 191 NestedStatement* previous_; |
| 162 | 192 |
| 163 private: | 193 private: |
| 164 DISALLOW_COPY_AND_ASSIGN(NestedStatement); | 194 DISALLOW_COPY_AND_ASSIGN(NestedStatement); |
| 165 }; | 195 }; |
| 166 | 196 |
| 167 // A breakable statement such as a block. | 197 // A breakable statement such as a block. |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 TypeFeedbackId id = TypeFeedbackId::None()); | 588 TypeFeedbackId id = TypeFeedbackId::None()); |
| 559 void CallStoreIC(TypeFeedbackId id = TypeFeedbackId::None()); | 589 void CallStoreIC(TypeFeedbackId id = TypeFeedbackId::None()); |
| 560 | 590 |
| 561 void SetFunctionPosition(FunctionLiteral* fun); | 591 void SetFunctionPosition(FunctionLiteral* fun); |
| 562 void SetReturnPosition(FunctionLiteral* fun); | 592 void SetReturnPosition(FunctionLiteral* fun); |
| 563 void SetStatementPosition(Statement* stmt); | 593 void SetStatementPosition(Statement* stmt); |
| 564 void SetExpressionPosition(Expression* expr); | 594 void SetExpressionPosition(Expression* expr); |
| 565 void SetStatementPosition(int pos); | 595 void SetStatementPosition(int pos); |
| 566 void SetSourcePosition(int pos); | 596 void SetSourcePosition(int pos); |
| 567 | 597 |
| 598 void AsmPush(Register reg) { |
| 599 masm()->push(reg); |
| 600 UpdateStackHeight(1); |
| 601 } |
| 602 |
| 603 void AsmPush(const Operand& op); |
| 604 |
| 605 void AsmPushHandle(Handle<Object> handle) { |
| 606 masm()->Push(handle); |
| 607 UpdateStackHeight(1); |
| 608 } |
| 609 |
| 610 void AsmPushSmi(Smi* smi) { |
| 611 masm()->Push(smi); |
| 612 UpdateStackHeight(1); |
| 613 } |
| 614 |
| 615 void AsmPop(Register reg) { |
| 616 masm()->pop(reg); |
| 617 UpdateStackHeight(-1); |
| 618 } |
| 619 |
| 620 void AsmInvokeBuiltin(Builtins::JavaScript id, |
| 621 InvokeFlag flag, |
| 622 int arg_count, |
| 623 const CallWrapper& call_wrapper = NullCallWrapper()) { |
| 624 masm()->InvokeBuiltin(id, flag, call_wrapper); |
| 625 UpdateStackHeight(-arg_count); |
| 626 } |
| 627 |
| 628 void AsmDrop(int n) { |
| 629 masm()->Drop(n); |
| 630 UpdateStackHeight(-n); |
| 631 } |
| 632 |
| 633 void AsmCallRuntime(const Runtime::Function* f, |
| 634 int num_arguments, |
| 635 SaveFPRegsMode save_doubles = kDontSaveFPRegs) { |
| 636 masm()->CallRuntime(f, num_arguments, save_doubles); |
| 637 UpdateStackHeight(-num_arguments); |
| 638 } |
| 639 |
| 640 void AsmCallRuntime(Runtime::FunctionId id, |
| 641 int num_arguments, |
| 642 SaveFPRegsMode save_doubles = kDontSaveFPRegs) { |
| 643 masm()->CallRuntime(id, num_arguments, save_doubles); |
| 644 UpdateStackHeight(-num_arguments); |
| 645 } |
| 646 |
| 647 void AsmPushTryHandler(StackHandler::Kind kind, int handler_index) { |
| 648 masm()->PushTryHandler(kind, handler_index); |
| 649 UpdateStackHeight(StackHandlerConstants::kSize / kPointerSize); |
| 650 } |
| 651 |
| 652 void AsmPopTryHandler() { |
| 653 masm()->PopTryHandler(); |
| 654 UpdateStackHeight(-StackHandlerConstants::kSize / kPointerSize); |
| 655 } |
| 656 |
| 657 // Call a code stub. Generate the code if necessary. |
| 658 void AsmCallStub(CodeStub* stub, |
| 659 int arg_count) { |
| 660 masm()->CallStub(stub); |
| 661 UpdateStackHeight(-arg_count); |
| 662 } |
| 663 |
| 568 // Non-local control flow support. | 664 // Non-local control flow support. |
| 569 void EnterFinallyBlock(); | 665 void EnterFinallyBlock(); |
| 570 void ExitFinallyBlock(); | 666 void ExitFinallyBlock(); |
| 571 | 667 |
| 572 // Loop nesting counter. | 668 // Loop nesting counter. |
| 573 int loop_depth() { return loop_depth_; } | 669 int loop_depth() { return loop_depth_; } |
| 574 void increment_loop_depth() { loop_depth_++; } | 670 void increment_loop_depth() { loop_depth_++; } |
| 575 void decrement_loop_depth() { | 671 void decrement_loop_depth() { |
| 576 ASSERT(loop_depth_ > 0); | 672 ASSERT(loop_depth_ > 0); |
| 577 loop_depth_--; | 673 loop_depth_--; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 | 714 |
| 619 void Generate(); | 715 void Generate(); |
| 620 void PopulateDeoptimizationData(Handle<Code> code); | 716 void PopulateDeoptimizationData(Handle<Code> code); |
| 621 void PopulateTypeFeedbackInfo(Handle<Code> code); | 717 void PopulateTypeFeedbackInfo(Handle<Code> code); |
| 622 | 718 |
| 623 Handle<FixedArray> handler_table() { return handler_table_; } | 719 Handle<FixedArray> handler_table() { return handler_table_; } |
| 624 | 720 |
| 625 struct BailoutEntry { | 721 struct BailoutEntry { |
| 626 BailoutId id; | 722 BailoutId id; |
| 627 unsigned pc_and_state; | 723 unsigned pc_and_state; |
| 724 int stack_height; |
| 628 }; | 725 }; |
| 629 | 726 |
| 630 struct BackEdgeEntry { | 727 struct BackEdgeEntry { |
| 631 BailoutId id; | 728 BailoutId id; |
| 632 unsigned pc; | 729 unsigned pc; |
| 633 uint32_t loop_depth; | 730 uint32_t loop_depth; |
| 634 }; | 731 }; |
| 635 | 732 |
| 636 class ExpressionContext BASE_EMBEDDED { | 733 class ExpressionContext BASE_EMBEDDED { |
| 637 public: | 734 public: |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 virtual void PlugTOS() const; | 899 virtual void PlugTOS() const; |
| 803 virtual void DropAndPlug(int count, Register reg) const; | 900 virtual void DropAndPlug(int count, Register reg) const; |
| 804 virtual void PrepareTest(Label* materialize_true, | 901 virtual void PrepareTest(Label* materialize_true, |
| 805 Label* materialize_false, | 902 Label* materialize_false, |
| 806 Label** if_true, | 903 Label** if_true, |
| 807 Label** if_false, | 904 Label** if_false, |
| 808 Label** fall_through) const; | 905 Label** fall_through) const; |
| 809 virtual bool IsEffect() const { return true; } | 906 virtual bool IsEffect() const { return true; } |
| 810 }; | 907 }; |
| 811 | 908 |
| 909 void CheckStackHeight() { |
| 910 #if defined(VERIFY_STACK_HEIGHT) |
| 911 AddStackHeightVerifier(); |
| 912 #endif // defined(VERIFY_STACK_HEIGHT) |
| 913 } |
| 914 |
| 915 void UpdateStackHeight(int difference) { |
| 916 stack_height_.updateBy(difference); |
| 917 } |
| 918 |
| 919 void SetStackHeight(StackHeightWrapper height) { |
| 920 stack_height_ = height; |
| 921 } |
| 922 |
| 923 StackHeightWrapper CurrentStackHeight() { |
| 924 return stack_height_; |
| 925 } |
| 926 |
| 927 #if defined(VERIFY_STACK_HEIGHT) |
| 928 void AddStackHeightVerifier(); |
| 929 #endif // defined(VERIFY_STACK_HEIGHT) |
| 930 |
| 812 MacroAssembler* masm_; | 931 MacroAssembler* masm_; |
| 813 CompilationInfo* info_; | 932 CompilationInfo* info_; |
| 814 Scope* scope_; | 933 Scope* scope_; |
| 815 Label return_label_; | 934 Label return_label_; |
| 816 NestedStatement* nesting_stack_; | 935 NestedStatement* nesting_stack_; |
| 817 int loop_depth_; | 936 int loop_depth_; |
| 937 StackHeightWrapper stack_height_; |
| 818 ZoneList<Handle<Object> >* globals_; | 938 ZoneList<Handle<Object> >* globals_; |
| 819 Handle<FixedArray> modules_; | 939 Handle<FixedArray> modules_; |
| 820 int module_index_; | 940 int module_index_; |
| 821 const ExpressionContext* context_; | 941 const ExpressionContext* context_; |
| 822 ZoneList<BailoutEntry> bailout_entries_; | 942 ZoneList<BailoutEntry> bailout_entries_; |
| 823 ZoneList<BackEdgeEntry> back_edges_; | 943 ZoneList<BackEdgeEntry> back_edges_; |
| 824 int ic_total_count_; | 944 int ic_total_count_; |
| 825 Handle<FixedArray> handler_table_; | 945 Handle<FixedArray> handler_table_; |
| 826 Handle<Cell> profiling_counter_; | 946 Handle<Cell> profiling_counter_; |
| 827 bool generate_debug_code_; | 947 bool generate_debug_code_; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 | 1058 |
| 939 Address start_; | 1059 Address start_; |
| 940 Address instruction_start_; | 1060 Address instruction_start_; |
| 941 uint32_t length_; | 1061 uint32_t length_; |
| 942 }; | 1062 }; |
| 943 | 1063 |
| 944 | 1064 |
| 945 } } // namespace v8::internal | 1065 } } // namespace v8::internal |
| 946 | 1066 |
| 947 #endif // V8_FULL_CODEGEN_H_ | 1067 #endif // V8_FULL_CODEGEN_H_ |
| OLD | NEW |