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_CODE_STUBS_H_ | 5 #ifndef V8_CODE_STUBS_H_ |
6 #define V8_CODE_STUBS_H_ | 6 #define V8_CODE_STUBS_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/assembler.h" | 9 #include "src/assembler.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 2729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2740 NULL_TYPE, | 2740 NULL_TYPE, |
2741 SMI, | 2741 SMI, |
2742 SPEC_OBJECT, | 2742 SPEC_OBJECT, |
2743 STRING, | 2743 STRING, |
2744 SYMBOL, | 2744 SYMBOL, |
2745 HEAP_NUMBER, | 2745 HEAP_NUMBER, |
2746 SIMD_VALUE, | 2746 SIMD_VALUE, |
2747 NUMBER_OF_TYPES | 2747 NUMBER_OF_TYPES |
2748 }; | 2748 }; |
2749 | 2749 |
2750 enum ResultMode { | |
2751 RESULT_AS_SMI, // For Smi(1) on truthy value, Smi(0) otherwise. | |
2752 RESULT_AS_ODDBALL, // For {true} on truthy value, {false} otherwise. | |
2753 RESULT_AS_INVERSE_ODDBALL // For {false} on truthy value, {true} otherwise. | |
2754 }; | |
2755 | |
2756 // At most 16 different types can be distinguished, because the Code object | 2750 // At most 16 different types can be distinguished, because the Code object |
2757 // only has room for two bytes to hold a set of these types. :-P | 2751 // only has room for two bytes to hold a set of these types. :-P |
2758 STATIC_ASSERT(NUMBER_OF_TYPES <= 16); | 2752 STATIC_ASSERT(NUMBER_OF_TYPES <= 16); |
2759 | 2753 |
2760 class Types : public EnumSet<Type, uint16_t> { | 2754 class Types : public EnumSet<Type, uint16_t> { |
2761 public: | 2755 public: |
2762 Types() : EnumSet<Type, uint16_t>(0) {} | 2756 Types() : EnumSet<Type, uint16_t>(0) {} |
2763 explicit Types(uint16_t bits) : EnumSet<Type, uint16_t>(bits) {} | 2757 explicit Types(uint16_t bits) : EnumSet<Type, uint16_t>(bits) {} |
2764 | 2758 |
2765 bool UpdateStatus(Handle<Object> object); | 2759 bool UpdateStatus(Handle<Object> object); |
2766 bool NeedsMap() const; | 2760 bool NeedsMap() const; |
2767 bool CanBeUndetectable() const { | 2761 bool CanBeUndetectable() const { |
2768 return Contains(ToBooleanStub::SPEC_OBJECT); | 2762 return Contains(ToBooleanStub::SPEC_OBJECT); |
2769 } | 2763 } |
2770 bool IsGeneric() const { return ToIntegral() == Generic().ToIntegral(); } | 2764 bool IsGeneric() const { return ToIntegral() == Generic().ToIntegral(); } |
2771 | 2765 |
2772 static Types Generic() { return Types((1 << NUMBER_OF_TYPES) - 1); } | 2766 static Types Generic() { return Types((1 << NUMBER_OF_TYPES) - 1); } |
2773 }; | 2767 }; |
2774 | 2768 |
2775 ToBooleanStub(Isolate* isolate, ResultMode mode, Types types = Types()) | |
2776 : HydrogenCodeStub(isolate) { | |
2777 set_sub_minor_key(TypesBits::encode(types.ToIntegral()) | | |
2778 ResultModeBits::encode(mode)); | |
2779 } | |
2780 | |
2781 ToBooleanStub(Isolate* isolate, ExtraICState state) | 2769 ToBooleanStub(Isolate* isolate, ExtraICState state) |
2782 : HydrogenCodeStub(isolate) { | 2770 : HydrogenCodeStub(isolate) { |
2783 set_sub_minor_key(TypesBits::encode(static_cast<uint16_t>(state)) | | 2771 set_sub_minor_key(TypesBits::encode(static_cast<uint16_t>(state))); |
2784 ResultModeBits::encode(RESULT_AS_SMI)); | |
2785 } | 2772 } |
2786 | 2773 |
2787 bool UpdateStatus(Handle<Object> object); | 2774 bool UpdateStatus(Handle<Object> object); |
2788 Types types() const { return Types(TypesBits::decode(sub_minor_key())); } | 2775 Types types() const { return Types(TypesBits::decode(sub_minor_key())); } |
2789 ResultMode mode() const { return ResultModeBits::decode(sub_minor_key()); } | |
2790 | 2776 |
2791 Code::Kind GetCodeKind() const override { return Code::TO_BOOLEAN_IC; } | 2777 Code::Kind GetCodeKind() const override { return Code::TO_BOOLEAN_IC; } |
2792 void PrintState(std::ostream& os) const override; // NOLINT | 2778 void PrintState(std::ostream& os) const override; // NOLINT |
2793 | 2779 |
2794 bool SometimesSetsUpAFrame() override { return false; } | 2780 bool SometimesSetsUpAFrame() override { return false; } |
2795 | 2781 |
2796 static Handle<Code> GetUninitialized(Isolate* isolate) { | 2782 static Handle<Code> GetUninitialized(Isolate* isolate) { |
2797 return ToBooleanStub(isolate, UNINITIALIZED).GetCode(); | 2783 return ToBooleanStub(isolate, UNINITIALIZED).GetCode(); |
2798 } | 2784 } |
2799 | 2785 |
2800 ExtraICState GetExtraICState() const override { return types().ToIntegral(); } | 2786 ExtraICState GetExtraICState() const override { return types().ToIntegral(); } |
2801 | 2787 |
2802 InlineCacheState GetICState() const override { | 2788 InlineCacheState GetICState() const override { |
2803 if (types().IsEmpty()) { | 2789 if (types().IsEmpty()) { |
2804 return ::v8::internal::UNINITIALIZED; | 2790 return ::v8::internal::UNINITIALIZED; |
2805 } else { | 2791 } else { |
2806 return MONOMORPHIC; | 2792 return MONOMORPHIC; |
2807 } | 2793 } |
2808 } | 2794 } |
2809 | 2795 |
2810 private: | 2796 private: |
2811 ToBooleanStub(Isolate* isolate, InitializationState init_state) | 2797 ToBooleanStub(Isolate* isolate, InitializationState init_state) |
2812 : HydrogenCodeStub(isolate, init_state) { | 2798 : HydrogenCodeStub(isolate, init_state) { |
2813 set_sub_minor_key(ResultModeBits::encode(RESULT_AS_SMI)); | |
2814 } | 2799 } |
2815 | 2800 |
2816 class TypesBits : public BitField<uint16_t, 0, NUMBER_OF_TYPES> {}; | 2801 class TypesBits : public BitField<uint16_t, 0, NUMBER_OF_TYPES> {}; |
2817 class ResultModeBits : public BitField<ResultMode, NUMBER_OF_TYPES, 2> {}; | |
2818 | 2802 |
2819 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToBoolean); | 2803 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToBoolean); |
2820 DEFINE_HYDROGEN_CODE_STUB(ToBoolean, HydrogenCodeStub); | 2804 DEFINE_HYDROGEN_CODE_STUB(ToBoolean, HydrogenCodeStub); |
2821 }; | 2805 }; |
2822 | 2806 |
2823 | 2807 |
2824 std::ostream& operator<<(std::ostream& os, const ToBooleanStub::Types& t); | 2808 std::ostream& operator<<(std::ostream& os, const ToBooleanStub::Types& t); |
2825 | 2809 |
2826 | 2810 |
2827 class ElementsTransitionAndStoreStub : public HydrogenCodeStub { | 2811 class ElementsTransitionAndStoreStub : public HydrogenCodeStub { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2977 #undef DEFINE_HYDROGEN_CODE_STUB | 2961 #undef DEFINE_HYDROGEN_CODE_STUB |
2978 #undef DEFINE_CODE_STUB | 2962 #undef DEFINE_CODE_STUB |
2979 #undef DEFINE_CODE_STUB_BASE | 2963 #undef DEFINE_CODE_STUB_BASE |
2980 | 2964 |
2981 extern Representation RepresentationFromType(Type* type); | 2965 extern Representation RepresentationFromType(Type* type); |
2982 | 2966 |
2983 } // namespace internal | 2967 } // namespace internal |
2984 } // namespace v8 | 2968 } // namespace v8 |
2985 | 2969 |
2986 #endif // V8_CODE_STUBS_H_ | 2970 #endif // V8_CODE_STUBS_H_ |
OLD | NEW |