OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_VM_INTERMEDIATE_LANGUAGE_H_ | 5 #ifndef RUNTIME_VM_INTERMEDIATE_LANGUAGE_H_ |
6 #define RUNTIME_VM_INTERMEDIATE_LANGUAGE_H_ | 6 #define RUNTIME_VM_INTERMEDIATE_LANGUAGE_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 #define PRINT_TO_SUPPORT | 541 #define PRINT_TO_SUPPORT |
542 #endif // !PRODUCT | 542 #endif // !PRODUCT |
543 | 543 |
544 #ifndef PRODUCT | 544 #ifndef PRODUCT |
545 #define PRINT_OPERANDS_TO_SUPPORT \ | 545 #define PRINT_OPERANDS_TO_SUPPORT \ |
546 virtual void PrintOperandsTo(BufferFormatter* f) const; | 546 virtual void PrintOperandsTo(BufferFormatter* f) const; |
547 #else | 547 #else |
548 #define PRINT_OPERANDS_TO_SUPPORT | 548 #define PRINT_OPERANDS_TO_SUPPORT |
549 #endif // !PRODUCT | 549 #endif // !PRODUCT |
550 | 550 |
| 551 |
| 552 // Represents a mapping from a range of class-ids to a method for a given |
| 553 // selector (method name). Also can contain an indication of how frequently a |
| 554 // given method has been called at a call site. This information can be |
| 555 // harvested from the inline caches (ICs). |
| 556 struct CidRangeTarget { |
| 557 intptr_t cid_start; |
| 558 intptr_t cid_end; |
| 559 Function* target; |
| 560 intptr_t count; |
| 561 CidRangeTarget(intptr_t cid_start_arg, |
| 562 intptr_t cid_end_arg, |
| 563 Function* target_arg, |
| 564 intptr_t count_arg) |
| 565 : cid_start(cid_start_arg), |
| 566 cid_end(cid_end_arg), |
| 567 target(target_arg), |
| 568 count(count_arg) { |
| 569 ASSERT(target->IsZoneHandle()); |
| 570 } |
| 571 }; |
| 572 |
| 573 |
| 574 class CallTargets : public ZoneAllocated { |
| 575 public: |
| 576 // Creates the off-heap CallTargets object that reflects the contents |
| 577 // of the on-VM-heap IC data. Also expands the class-ids to neighbouring |
| 578 // classes that inherit the same method. |
| 579 static CallTargets* Create(Zone* zone, const ICData& ic_data); |
| 580 |
| 581 void Add(const CidRangeTarget& target) { cid_ranges_.Add(target); } |
| 582 |
| 583 CidRangeTarget& operator[](intptr_t index) const { |
| 584 return cid_ranges_[index]; |
| 585 } |
| 586 |
| 587 CidRangeTarget At(int index) { return cid_ranges_.At(index); } |
| 588 |
| 589 intptr_t length() const { return cid_ranges_.length(); } |
| 590 |
| 591 void SetLength(intptr_t len) { cid_ranges_.SetLength(len); } |
| 592 |
| 593 bool is_empty() const { return cid_ranges_.is_empty(); } |
| 594 |
| 595 void Sort(int compare(const CidRangeTarget* a, const CidRangeTarget* b)) { |
| 596 cid_ranges_.Sort(compare); |
| 597 } |
| 598 |
| 599 intptr_t AggregateCallCount() const; |
| 600 |
| 601 bool HasSingleTarget() const; |
| 602 bool HasSingleRecognizedTarget() const; |
| 603 Function& FirstTarget() const; |
| 604 Function& MostPopularTarget() const; |
| 605 bool IsMonomorphic() const; |
| 606 intptr_t MonomorphicReceiverCid() const; |
| 607 |
| 608 private: |
| 609 GrowableArray<CidRangeTarget> cid_ranges_; |
| 610 }; |
| 611 |
| 612 |
551 class Instruction : public ZoneAllocated { | 613 class Instruction : public ZoneAllocated { |
552 public: | 614 public: |
553 #define DECLARE_TAG(type) k##type, | 615 #define DECLARE_TAG(type) k##type, |
554 enum Tag { FOR_EACH_INSTRUCTION(DECLARE_TAG) }; | 616 enum Tag { FOR_EACH_INSTRUCTION(DECLARE_TAG) }; |
555 #undef DECLARE_TAG | 617 #undef DECLARE_TAG |
556 | 618 |
557 explicit Instruction(intptr_t deopt_id = Thread::kNoDeoptId) | 619 explicit Instruction(intptr_t deopt_id = Thread::kNoDeoptId) |
558 : deopt_id_(deopt_id), | 620 : deopt_id_(deopt_id), |
559 lifetime_position_(kNoPlaceId), | 621 lifetime_position_(kNoPlaceId), |
560 previous_(NULL), | 622 previous_(NULL), |
(...skipping 2218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2779 const intptr_t checked_argument_count_; | 2841 const intptr_t checked_argument_count_; |
2780 bool has_unique_selector_; | 2842 bool has_unique_selector_; |
2781 | 2843 |
2782 DISALLOW_COPY_AND_ASSIGN(InstanceCallInstr); | 2844 DISALLOW_COPY_AND_ASSIGN(InstanceCallInstr); |
2783 }; | 2845 }; |
2784 | 2846 |
2785 | 2847 |
2786 class PolymorphicInstanceCallInstr : public TemplateDefinition<0, Throws> { | 2848 class PolymorphicInstanceCallInstr : public TemplateDefinition<0, Throws> { |
2787 public: | 2849 public: |
2788 PolymorphicInstanceCallInstr(InstanceCallInstr* instance_call, | 2850 PolymorphicInstanceCallInstr(InstanceCallInstr* instance_call, |
2789 const ICData& ic_data, | 2851 const CallTargets& targets, |
2790 bool with_checks, | 2852 bool with_checks, |
2791 bool complete) | 2853 bool complete) |
2792 : TemplateDefinition(instance_call->deopt_id()), | 2854 : TemplateDefinition(instance_call->deopt_id()), |
2793 instance_call_(instance_call), | 2855 instance_call_(instance_call), |
2794 ic_data_(ic_data), | 2856 targets_(targets), |
2795 with_checks_(with_checks), | 2857 with_checks_(with_checks), |
2796 complete_(complete) { | 2858 complete_(complete) { |
2797 ASSERT(instance_call_ != NULL); | 2859 ASSERT(instance_call_ != NULL); |
2798 ASSERT(!ic_data.NumberOfChecksIs(0)); | 2860 ASSERT(targets.length() != 0); |
2799 total_call_count_ = CallCount(); | 2861 total_call_count_ = CallCount(); |
2800 } | 2862 } |
2801 | 2863 |
2802 InstanceCallInstr* instance_call() const { return instance_call_; } | 2864 InstanceCallInstr* instance_call() const { return instance_call_; } |
2803 bool with_checks() const { return with_checks_; } | 2865 bool with_checks() const { return with_checks_; } |
2804 void set_with_checks(bool b) { with_checks_ = b; } | 2866 void set_with_checks(bool b) { with_checks_ = b; } |
2805 bool complete() const { return complete_; } | 2867 bool complete() const { return complete_; } |
2806 virtual TokenPosition token_pos() const { | 2868 virtual TokenPosition token_pos() const { |
2807 return instance_call_->token_pos(); | 2869 return instance_call_->token_pos(); |
2808 } | 2870 } |
2809 | 2871 |
2810 virtual CompileType ComputeType() const; | 2872 virtual CompileType ComputeType() const; |
2811 | 2873 |
2812 virtual intptr_t ArgumentCount() const { | 2874 virtual intptr_t ArgumentCount() const { |
2813 return instance_call()->ArgumentCount(); | 2875 return instance_call()->ArgumentCount(); |
2814 } | 2876 } |
2815 virtual PushArgumentInstr* PushArgumentAt(intptr_t index) const { | 2877 virtual PushArgumentInstr* PushArgumentAt(intptr_t index) const { |
2816 return instance_call()->PushArgumentAt(index); | 2878 return instance_call()->PushArgumentAt(index); |
2817 } | 2879 } |
2818 | 2880 |
2819 bool HasSingleRecognizedTarget() const; | 2881 bool HasOnlyDispatcherOrImplicitAccessorTargets() const; |
2820 | 2882 |
2821 virtual intptr_t CallCount() const { return ic_data().AggregateCount(); } | 2883 const CallTargets& targets() const { return targets_; } |
| 2884 intptr_t NumberOfChecks() const { return targets_.length(); } |
| 2885 |
| 2886 virtual intptr_t CallCount() const; |
2822 | 2887 |
2823 // If this polymophic call site was created to cover the remaining cids after | 2888 // If this polymophic call site was created to cover the remaining cids after |
2824 // inlinng then we need to keep track of the total number of calls including | 2889 // inlinng then we need to keep track of the total number of calls including |
2825 // the ones that wer inlined. This is different from the CallCount above: Eg | 2890 // the ones that wer inlined. This is different from the CallCount above: Eg |
2826 // if there were 100 calls originally, distributed across three class-ids in | 2891 // if there were 100 calls originally, distributed across three class-ids in |
2827 // the ratio 50, 40, 7, 3. The first two were inlined, so now we have only | 2892 // the ratio 50, 40, 7, 3. The first two were inlined, so now we have only |
2828 // 10 calls in the CallCount above, but the heuristics need to know that the | 2893 // 10 calls in the CallCount above, but the heuristics need to know that the |
2829 // last two cids cover 7% and 3% of the calls, not 70% and 30%. | 2894 // last two cids cover 7% and 3% of the calls, not 70% and 30%. |
2830 intptr_t total_call_count() { return total_call_count_; } | 2895 intptr_t total_call_count() { return total_call_count_; } |
2831 | 2896 |
2832 void set_total_call_count(intptr_t count) { total_call_count_ = count; } | 2897 void set_total_call_count(intptr_t count) { total_call_count_ = count; } |
2833 | 2898 |
2834 DECLARE_INSTRUCTION(PolymorphicInstanceCall) | 2899 DECLARE_INSTRUCTION(PolymorphicInstanceCall) |
2835 | 2900 |
2836 const ICData& ic_data() const { return ic_data_; } | |
2837 | |
2838 virtual bool ComputeCanDeoptimize() const { return true; } | 2901 virtual bool ComputeCanDeoptimize() const { return true; } |
2839 | 2902 |
2840 virtual EffectSet Effects() const { return EffectSet::All(); } | 2903 virtual EffectSet Effects() const { return EffectSet::All(); } |
2841 | 2904 |
2842 virtual Definition* Canonicalize(FlowGraph* graph); | 2905 virtual Definition* Canonicalize(FlowGraph* graph); |
2843 | 2906 |
2844 static RawType* ComputeRuntimeType(const ICData& ic_data); | 2907 static RawType* ComputeRuntimeType(const CallTargets& targets); |
2845 | 2908 |
2846 PRINT_OPERANDS_TO_SUPPORT | 2909 PRINT_OPERANDS_TO_SUPPORT |
2847 | 2910 |
2848 private: | 2911 private: |
2849 InstanceCallInstr* instance_call_; | 2912 InstanceCallInstr* instance_call_; |
2850 const ICData& ic_data_; | 2913 const CallTargets& targets_; |
2851 bool with_checks_; | 2914 bool with_checks_; |
2852 const bool complete_; | 2915 const bool complete_; |
2853 intptr_t total_call_count_; | 2916 intptr_t total_call_count_; |
2854 | 2917 |
| 2918 friend class PolymorphicInliner; |
| 2919 |
2855 DISALLOW_COPY_AND_ASSIGN(PolymorphicInstanceCallInstr); | 2920 DISALLOW_COPY_AND_ASSIGN(PolymorphicInstanceCallInstr); |
2856 }; | 2921 }; |
2857 | 2922 |
2858 | 2923 |
2859 class StrictCompareInstr : public TemplateComparison<2, NoThrow, Pure> { | 2924 class StrictCompareInstr : public TemplateComparison<2, NoThrow, Pure> { |
2860 public: | 2925 public: |
2861 StrictCompareInstr(TokenPosition token_pos, | 2926 StrictCompareInstr(TokenPosition token_pos, |
2862 Token::Kind kind, | 2927 Token::Kind kind, |
2863 Value* left, | 2928 Value* left, |
2864 Value* right, | 2929 Value* right, |
(...skipping 5178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8043 LocationSummary* Name::MakeLocationSummary(Zone* zone, bool opt) const { \ | 8108 LocationSummary* Name::MakeLocationSummary(Zone* zone, bool opt) const { \ |
8044 UNIMPLEMENTED(); \ | 8109 UNIMPLEMENTED(); \ |
8045 return NULL; \ | 8110 return NULL; \ |
8046 } \ | 8111 } \ |
8047 void Name::EmitNativeCode(FlowGraphCompiler* compiler) { UNIMPLEMENTED(); } | 8112 void Name::EmitNativeCode(FlowGraphCompiler* compiler) { UNIMPLEMENTED(); } |
8048 | 8113 |
8049 | 8114 |
8050 } // namespace dart | 8115 } // namespace dart |
8051 | 8116 |
8052 #endif // RUNTIME_VM_INTERMEDIATE_LANGUAGE_H_ | 8117 #endif // RUNTIME_VM_INTERMEDIATE_LANGUAGE_H_ |
OLD | NEW |