| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 // Forward declarations. | 46 // Forward declarations. |
| 47 class JumpPatchSite; | 47 class JumpPatchSite; |
| 48 | 48 |
| 49 // AST node visitor which can tell whether a given statement will be breakable | 49 // AST node visitor which can tell whether a given statement will be breakable |
| 50 // when the code is compiled by the full compiler in the debugger. This means | 50 // when the code is compiled by the full compiler in the debugger. This means |
| 51 // that there will be an IC (load/store/call) in the code generated for the | 51 // that there will be an IC (load/store/call) in the code generated for the |
| 52 // debugger to piggybag on. | 52 // debugger to piggybag on. |
| 53 class BreakableStatementChecker: public AstVisitor { | 53 class BreakableStatementChecker: public AstVisitor { |
| 54 public: | 54 public: |
| 55 explicit BreakableStatementChecker(Isolate* isolate) : is_breakable_(false) { | 55 explicit BreakableStatementChecker(Zone* zone) : is_breakable_(false) { |
| 56 InitializeAstVisitor(isolate); | 56 InitializeAstVisitor(zone); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void Check(Statement* stmt); | 59 void Check(Statement* stmt); |
| 60 void Check(Expression* stmt); | 60 void Check(Expression* stmt); |
| 61 | 61 |
| 62 bool is_breakable() { return is_breakable_; } | 62 bool is_breakable() { return is_breakable_; } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 // AST node visit functions. | 65 // AST node visit functions. |
| 66 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); | 66 #define DECLARE_VISIT(type) virtual void Visit##type(type* node); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 89 info_(info), | 89 info_(info), |
| 90 scope_(info->scope()), | 90 scope_(info->scope()), |
| 91 nesting_stack_(NULL), | 91 nesting_stack_(NULL), |
| 92 loop_depth_(0), | 92 loop_depth_(0), |
| 93 globals_(NULL), | 93 globals_(NULL), |
| 94 context_(NULL), | 94 context_(NULL), |
| 95 bailout_entries_(info->HasDeoptimizationSupport() | 95 bailout_entries_(info->HasDeoptimizationSupport() |
| 96 ? info->function()->ast_node_count() : 0, | 96 ? info->function()->ast_node_count() : 0, |
| 97 info->zone()), | 97 info->zone()), |
| 98 back_edges_(2, info->zone()), | 98 back_edges_(2, info->zone()), |
| 99 type_feedback_cells_(info->HasDeoptimizationSupport() | 99 ic_total_count_(0) { |
| 100 ? info->function()->ast_node_count() : 0, | |
| 101 info->zone()), | |
| 102 ic_total_count_(0), | |
| 103 zone_(info->zone()) { | |
| 104 Initialize(); | 100 Initialize(); |
| 105 } | 101 } |
| 106 | 102 |
| 107 void Initialize(); | 103 void Initialize(); |
| 108 | 104 |
| 109 static bool MakeCode(CompilationInfo* info); | 105 static bool MakeCode(CompilationInfo* info); |
| 110 | 106 |
| 111 // Encode state and pc-offset as a BitField<type, start, size>. | 107 // Encode state and pc-offset as a BitField<type, start, size>. |
| 112 // Only use 30 bits because we encode the result as a smi. | 108 // Only use 30 bits because we encode the result as a smi. |
| 113 class StateField : public BitField<State, 0, 1> { }; | 109 class StateField : public BitField<State, 0, 1> { }; |
| 114 class PcField : public BitField<unsigned, 1, 30-1> { }; | 110 class PcField : public BitField<unsigned, 1, 30-1> { }; |
| 115 | 111 |
| 116 static const char* State2String(State state) { | 112 static const char* State2String(State state) { |
| 117 switch (state) { | 113 switch (state) { |
| 118 case NO_REGISTERS: return "NO_REGISTERS"; | 114 case NO_REGISTERS: return "NO_REGISTERS"; |
| 119 case TOS_REG: return "TOS_REG"; | 115 case TOS_REG: return "TOS_REG"; |
| 120 } | 116 } |
| 121 UNREACHABLE(); | 117 UNREACHABLE(); |
| 122 return NULL; | 118 return NULL; |
| 123 } | 119 } |
| 124 | 120 |
| 125 Zone* zone() const { return zone_; } | |
| 126 | |
| 127 static const int kMaxBackEdgeWeight = 127; | 121 static const int kMaxBackEdgeWeight = 127; |
| 128 | 122 |
| 129 // Platform-specific code size multiplier. | 123 // Platform-specific code size multiplier. |
| 130 #if V8_TARGET_ARCH_IA32 | 124 #if V8_TARGET_ARCH_IA32 |
| 131 static const int kCodeSizeMultiplier = 100; | 125 static const int kCodeSizeMultiplier = 100; |
| 132 #elif V8_TARGET_ARCH_X64 | 126 #elif V8_TARGET_ARCH_X64 |
| 133 static const int kCodeSizeMultiplier = 162; | 127 static const int kCodeSizeMultiplier = 162; |
| 134 #elif V8_TARGET_ARCH_ARM | 128 #elif V8_TARGET_ARCH_ARM |
| 135 static const int kCodeSizeMultiplier = 142; | 129 static const int kCodeSizeMultiplier = 142; |
| 130 #elif V8_TARGET_ARCH_A64 |
| 131 // TODO(all): Copied ARM value. Check this is sensible for A64. |
| 132 static const int kCodeSizeMultiplier = 142; |
| 136 #elif V8_TARGET_ARCH_MIPS | 133 #elif V8_TARGET_ARCH_MIPS |
| 137 static const int kCodeSizeMultiplier = 142; | 134 static const int kCodeSizeMultiplier = 142; |
| 138 #else | 135 #else |
| 139 #error Unsupported target architecture. | 136 #error Unsupported target architecture. |
| 140 #endif | 137 #endif |
| 141 | 138 |
| 142 private: | 139 private: |
| 143 class Breakable; | 140 class Breakable; |
| 144 class Iteration; | 141 class Iteration; |
| 145 | 142 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 427 |
| 431 // Platform-specific code for equality comparison with a nil-like value. | 428 // Platform-specific code for equality comparison with a nil-like value. |
| 432 void EmitLiteralCompareNil(CompareOperation* expr, | 429 void EmitLiteralCompareNil(CompareOperation* expr, |
| 433 Expression* sub_expr, | 430 Expression* sub_expr, |
| 434 NilValue nil); | 431 NilValue nil); |
| 435 | 432 |
| 436 // Bailout support. | 433 // Bailout support. |
| 437 void PrepareForBailout(Expression* node, State state); | 434 void PrepareForBailout(Expression* node, State state); |
| 438 void PrepareForBailoutForId(BailoutId id, State state); | 435 void PrepareForBailoutForId(BailoutId id, State state); |
| 439 | 436 |
| 440 // Cache cell support. This associates AST ids with global property cells | 437 // Feedback slot support. The feedback vector will be cleared during gc and |
| 441 // that will be cleared during GC and collected by the type-feedback oracle. | 438 // collected by the type-feedback oracle. |
| 442 void RecordTypeFeedbackCell(TypeFeedbackId id, Handle<Cell> cell); | 439 Handle<FixedArray> FeedbackVector() { |
| 440 return feedback_vector_; |
| 441 } |
| 442 void StoreFeedbackVectorSlot(int slot, Handle<Object> object) { |
| 443 feedback_vector_->set(slot, *object); |
| 444 } |
| 445 void InitializeFeedbackVector(); |
| 443 | 446 |
| 444 // Record a call's return site offset, used to rebuild the frame if the | 447 // Record a call's return site offset, used to rebuild the frame if the |
| 445 // called function was inlined at the site. | 448 // called function was inlined at the site. |
| 446 void RecordJSReturnSite(Call* call); | 449 void RecordJSReturnSite(Call* call); |
| 447 | 450 |
| 448 // Prepare for bailout before a test (or compare) and branch. If | 451 // Prepare for bailout before a test (or compare) and branch. If |
| 449 // should_normalize, then the following comparison will not handle the | 452 // should_normalize, then the following comparison will not handle the |
| 450 // canonical JS true value so we will insert a (dead) test against true at | 453 // canonical JS true value so we will insert a (dead) test against true at |
| 451 // the actual bailout target from the optimized code. If not | 454 // the actual bailout target from the optimized code. If not |
| 452 // should_normalize, the true and false labels are ignored. | 455 // should_normalize, the true and false labels are ignored. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 476 // Emit code to pop values from the stack associated with nested statements | 479 // Emit code to pop values from the stack associated with nested statements |
| 477 // like try/catch, try/finally, etc, running the finallies and unwinding the | 480 // like try/catch, try/finally, etc, running the finallies and unwinding the |
| 478 // handlers as needed. | 481 // handlers as needed. |
| 479 void EmitUnwindBeforeReturn(); | 482 void EmitUnwindBeforeReturn(); |
| 480 | 483 |
| 481 // Platform-specific return sequence | 484 // Platform-specific return sequence |
| 482 void EmitReturnSequence(); | 485 void EmitReturnSequence(); |
| 483 | 486 |
| 484 // Platform-specific code sequences for calls | 487 // Platform-specific code sequences for calls |
| 485 void EmitCallWithStub(Call* expr); | 488 void EmitCallWithStub(Call* expr); |
| 486 void EmitCallWithIC(Call* expr, Handle<Object> name, ContextualMode mode); | 489 void EmitCallWithIC(Call* expr); |
| 487 void EmitKeyedCallWithIC(Call* expr, Expression* key); | 490 void EmitKeyedCallWithIC(Call* expr, Expression* key); |
| 488 | 491 |
| 489 // Platform-specific code for inline runtime calls. | 492 // Platform-specific code for inline runtime calls. |
| 490 InlineFunctionGenerator FindInlineFunctionGenerator(Runtime::FunctionId id); | 493 InlineFunctionGenerator FindInlineFunctionGenerator(Runtime::FunctionId id); |
| 491 | 494 |
| 492 void EmitInlineRuntimeCall(CallRuntime* expr); | 495 void EmitInlineRuntimeCall(CallRuntime* expr); |
| 493 | 496 |
| 494 #define EMIT_INLINE_RUNTIME_CALL(name, x, y) \ | 497 #define EMIT_INLINE_RUNTIME_CALL(name, x, y) \ |
| 495 void Emit##name(CallRuntime* expr); | 498 void Emit##name(CallRuntime* expr); |
| 496 INLINE_FUNCTION_LIST(EMIT_INLINE_RUNTIME_CALL) | 499 INLINE_FUNCTION_LIST(EMIT_INLINE_RUNTIME_CALL) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 | 551 |
| 549 // Assign to the given expression as if via '='. The right-hand-side value | 552 // Assign to the given expression as if via '='. The right-hand-side value |
| 550 // is expected in the accumulator. | 553 // is expected in the accumulator. |
| 551 void EmitAssignment(Expression* expr); | 554 void EmitAssignment(Expression* expr); |
| 552 | 555 |
| 553 // Complete a variable assignment. The right-hand-side value is expected | 556 // Complete a variable assignment. The right-hand-side value is expected |
| 554 // in the accumulator. | 557 // in the accumulator. |
| 555 void EmitVariableAssignment(Variable* var, | 558 void EmitVariableAssignment(Variable* var, |
| 556 Token::Value op); | 559 Token::Value op); |
| 557 | 560 |
| 561 // Helper functions to EmitVariableAssignment |
| 562 void EmitStoreToStackLocalOrContextSlot(Variable* var, |
| 563 MemOperand location); |
| 564 void EmitCallStoreContextSlot(Handle<String> name, LanguageMode mode); |
| 565 |
| 558 // Complete a named property assignment. The receiver is expected on top | 566 // Complete a named property assignment. The receiver is expected on top |
| 559 // of the stack and the right-hand-side value in the accumulator. | 567 // of the stack and the right-hand-side value in the accumulator. |
| 560 void EmitNamedPropertyAssignment(Assignment* expr); | 568 void EmitNamedPropertyAssignment(Assignment* expr); |
| 561 | 569 |
| 562 // Complete a keyed property assignment. The receiver and key are | 570 // Complete a keyed property assignment. The receiver and key are |
| 563 // expected on top of the stack and the right-hand-side value in the | 571 // expected on top of the stack and the right-hand-side value in the |
| 564 // accumulator. | 572 // accumulator. |
| 565 void EmitKeyedPropertyAssignment(Assignment* expr); | 573 void EmitKeyedPropertyAssignment(Assignment* expr); |
| 566 | 574 |
| 567 void CallIC(Handle<Code> code, | 575 void CallIC(Handle<Code> code, |
| 568 ContextualMode mode = NOT_CONTEXTUAL, | |
| 569 TypeFeedbackId id = TypeFeedbackId::None()); | 576 TypeFeedbackId id = TypeFeedbackId::None()); |
| 570 | 577 |
| 571 void CallLoadIC(ContextualMode mode, | 578 void CallLoadIC(ContextualMode mode, |
| 572 TypeFeedbackId id = TypeFeedbackId::None()); | 579 TypeFeedbackId id = TypeFeedbackId::None()); |
| 573 void CallStoreIC(ContextualMode mode, | 580 void CallStoreIC(TypeFeedbackId id = TypeFeedbackId::None()); |
| 574 TypeFeedbackId id = TypeFeedbackId::None()); | |
| 575 | 581 |
| 576 void SetFunctionPosition(FunctionLiteral* fun); | 582 void SetFunctionPosition(FunctionLiteral* fun); |
| 577 void SetReturnPosition(FunctionLiteral* fun); | 583 void SetReturnPosition(FunctionLiteral* fun); |
| 578 void SetStatementPosition(Statement* stmt); | 584 void SetStatementPosition(Statement* stmt); |
| 579 void SetExpressionPosition(Expression* expr); | 585 void SetExpressionPosition(Expression* expr); |
| 580 void SetStatementPosition(int pos); | 586 void SetStatementPosition(int pos); |
| 581 void SetSourcePosition(int pos); | 587 void SetSourcePosition(int pos); |
| 582 | 588 |
| 583 // Non-local control flow support. | 589 // Non-local control flow support. |
| 584 void EnterFinallyBlock(); | 590 void EnterFinallyBlock(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 | 637 |
| 632 void VisitComma(BinaryOperation* expr); | 638 void VisitComma(BinaryOperation* expr); |
| 633 void VisitLogicalExpression(BinaryOperation* expr); | 639 void VisitLogicalExpression(BinaryOperation* expr); |
| 634 void VisitArithmeticExpression(BinaryOperation* expr); | 640 void VisitArithmeticExpression(BinaryOperation* expr); |
| 635 | 641 |
| 636 void VisitForTypeofValue(Expression* expr); | 642 void VisitForTypeofValue(Expression* expr); |
| 637 | 643 |
| 638 void Generate(); | 644 void Generate(); |
| 639 void PopulateDeoptimizationData(Handle<Code> code); | 645 void PopulateDeoptimizationData(Handle<Code> code); |
| 640 void PopulateTypeFeedbackInfo(Handle<Code> code); | 646 void PopulateTypeFeedbackInfo(Handle<Code> code); |
| 641 void PopulateTypeFeedbackCells(Handle<Code> code); | |
| 642 | 647 |
| 643 Handle<FixedArray> handler_table() { return handler_table_; } | 648 Handle<FixedArray> handler_table() { return handler_table_; } |
| 644 | 649 |
| 645 struct BailoutEntry { | 650 struct BailoutEntry { |
| 646 BailoutId id; | 651 BailoutId id; |
| 647 unsigned pc_and_state; | 652 unsigned pc_and_state; |
| 648 }; | 653 }; |
| 649 | 654 |
| 650 struct BackEdgeEntry { | 655 struct BackEdgeEntry { |
| 651 BailoutId id; | 656 BailoutId id; |
| 652 unsigned pc; | 657 unsigned pc; |
| 653 uint32_t loop_depth; | 658 uint32_t loop_depth; |
| 654 }; | 659 }; |
| 655 | 660 |
| 656 struct TypeFeedbackCellEntry { | |
| 657 TypeFeedbackId ast_id; | |
| 658 Handle<Cell> cell; | |
| 659 }; | |
| 660 | |
| 661 | |
| 662 class ExpressionContext BASE_EMBEDDED { | 661 class ExpressionContext BASE_EMBEDDED { |
| 663 public: | 662 public: |
| 664 explicit ExpressionContext(FullCodeGenerator* codegen) | 663 explicit ExpressionContext(FullCodeGenerator* codegen) |
| 665 : masm_(codegen->masm()), old_(codegen->context()), codegen_(codegen) { | 664 : masm_(codegen->masm()), old_(codegen->context()), codegen_(codegen) { |
| 666 codegen->set_new_context(this); | 665 codegen->set_new_context(this); |
| 667 } | 666 } |
| 668 | 667 |
| 669 virtual ~ExpressionContext() { | 668 virtual ~ExpressionContext() { |
| 670 codegen_->set_new_context(old_); | 669 codegen_->set_new_context(old_); |
| 671 } | 670 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 Label return_label_; | 840 Label return_label_; |
| 842 NestedStatement* nesting_stack_; | 841 NestedStatement* nesting_stack_; |
| 843 int loop_depth_; | 842 int loop_depth_; |
| 844 ZoneList<Handle<Object> >* globals_; | 843 ZoneList<Handle<Object> >* globals_; |
| 845 Handle<FixedArray> modules_; | 844 Handle<FixedArray> modules_; |
| 846 int module_index_; | 845 int module_index_; |
| 847 const ExpressionContext* context_; | 846 const ExpressionContext* context_; |
| 848 ZoneList<BailoutEntry> bailout_entries_; | 847 ZoneList<BailoutEntry> bailout_entries_; |
| 849 GrowableBitVector prepared_bailout_ids_; | 848 GrowableBitVector prepared_bailout_ids_; |
| 850 ZoneList<BackEdgeEntry> back_edges_; | 849 ZoneList<BackEdgeEntry> back_edges_; |
| 851 ZoneList<TypeFeedbackCellEntry> type_feedback_cells_; | |
| 852 int ic_total_count_; | 850 int ic_total_count_; |
| 853 Handle<FixedArray> handler_table_; | 851 Handle<FixedArray> handler_table_; |
| 852 Handle<FixedArray> feedback_vector_; |
| 854 Handle<Cell> profiling_counter_; | 853 Handle<Cell> profiling_counter_; |
| 855 bool generate_debug_code_; | 854 bool generate_debug_code_; |
| 856 Zone* zone_; | |
| 857 | 855 |
| 858 friend class NestedStatement; | 856 friend class NestedStatement; |
| 859 | 857 |
| 860 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); | 858 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
| 861 DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator); | 859 DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator); |
| 862 }; | 860 }; |
| 863 | 861 |
| 864 | 862 |
| 865 // A map from property names to getter/setter pairs allocated in the zone. | 863 // A map from property names to getter/setter pairs allocated in the zone. |
| 866 class AccessorTable: public TemplateHashMap<Literal, | 864 class AccessorTable: public TemplateHashMap<Literal, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 | 965 |
| 968 Address start_; | 966 Address start_; |
| 969 Address instruction_start_; | 967 Address instruction_start_; |
| 970 uint32_t length_; | 968 uint32_t length_; |
| 971 }; | 969 }; |
| 972 | 970 |
| 973 | 971 |
| 974 } } // namespace v8::internal | 972 } } // namespace v8::internal |
| 975 | 973 |
| 976 #endif // V8_FULL_CODEGEN_H_ | 974 #endif // V8_FULL_CODEGEN_H_ |
| OLD | NEW |