Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: src/code-stubs.h

Issue 24072013: Hydrogenisation of binops (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix rewrite mode & finetune type feedback Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ast.h ('k') | src/code-stubs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 193 }
194 virtual Code::StubType GetStubType() { 194 virtual Code::StubType GetStubType() {
195 return Code::NORMAL; 195 return Code::NORMAL;
196 } 196 }
197 virtual int GetStubFlags() { 197 virtual int GetStubFlags() {
198 return -1; 198 return -1;
199 } 199 }
200 200
201 virtual void PrintName(StringStream* stream); 201 virtual void PrintName(StringStream* stream);
202 202
203 // Returns a name for logging/debugging purposes.
204 SmartArrayPointer<const char> GetName();
205
203 protected: 206 protected:
204 static bool CanUseFPRegisters(); 207 static bool CanUseFPRegisters();
205 208
206 // Generates the assembler code for the stub. 209 // Generates the assembler code for the stub.
207 virtual Handle<Code> GenerateCode(Isolate* isolate) = 0; 210 virtual Handle<Code> GenerateCode(Isolate* isolate) = 0;
208 211
209 212
210 // Returns whether the code generated for this stub needs to be allocated as 213 // Returns whether the code generated for this stub needs to be allocated as
211 // a fixed (non-moveable) code object. 214 // a fixed (non-moveable) code object.
212 virtual bool NeedsImmovableCode() { return false; } 215 virtual bool NeedsImmovableCode() { return false; }
213 216
214 // Returns a name for logging/debugging purposes.
215 SmartArrayPointer<const char> GetName();
216 virtual void PrintBaseName(StringStream* stream); 217 virtual void PrintBaseName(StringStream* stream);
217 virtual void PrintState(StringStream* stream) { } 218 virtual void PrintState(StringStream* stream) { }
218 219
219 private: 220 private:
220 // Perform bookkeeping required after code generation when stub code is 221 // Perform bookkeeping required after code generation when stub code is
221 // initially generated. 222 // initially generated.
222 void RecordCodeGeneration(Code* code, Isolate* isolate); 223 void RecordCodeGeneration(Code* code, Isolate* isolate);
223 224
224 // Finish the code object after it has been generated. 225 // Finish the code object after it has been generated.
225 virtual void FinishCode(Handle<Code> code) { } 226 virtual void FinishCode(Handle<Code> code) { }
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 Isolate* isolate, 989 Isolate* isolate,
989 CodeStubInterfaceDescriptor* descriptor); 990 CodeStubInterfaceDescriptor* descriptor);
990 991
991 virtual Handle<Code> GenerateCode(Isolate* isolate); 992 virtual Handle<Code> GenerateCode(Isolate* isolate);
992 993
993 private: 994 private:
994 virtual CodeStub::Major MajorKey() { return KeyedLoadField; } 995 virtual CodeStub::Major MajorKey() { return KeyedLoadField; }
995 }; 996 };
996 997
997 998
998 class BinaryOpStub: public PlatformCodeStub { 999 class BinaryOpStub: public HydrogenCodeStub {
999 public: 1000 public:
1000 BinaryOpStub(Token::Value op, OverwriteMode mode) 1001 BinaryOpStub(Token::Value op, OverwriteMode mode)
1001 : op_(op), 1002 : HydrogenCodeStub(UNINITIALIZED), op_(op), mode_(mode) {
1002 mode_(mode), 1003 ASSERT(op <= LAST_TOKEN && op >= FIRST_TOKEN);
1003 platform_specific_bit_(false),
1004 left_type_(BinaryOpIC::UNINITIALIZED),
1005 right_type_(BinaryOpIC::UNINITIALIZED),
1006 result_type_(BinaryOpIC::UNINITIALIZED),
1007 encoded_right_arg_(false, encode_arg_value(1)) {
1008 Initialize(); 1004 Initialize();
1009 ASSERT(OpBits::is_valid(Token::NUM_TOKENS));
1010 } 1005 }
1011 1006
1012 BinaryOpStub( 1007 explicit BinaryOpStub(Code::ExtraICState state)
1013 int key, 1008 : op_(decode_token(OpBits::decode(state))),
1014 BinaryOpIC::TypeInfo left_type, 1009 mode_(OverwriteModeField::decode(state)),
1015 BinaryOpIC::TypeInfo right_type, 1010 fixed_right_arg_(
1016 BinaryOpIC::TypeInfo result_type, 1011 Maybe<int>(HasFixedRightArgBits::decode(state),
1017 Maybe<int32_t> fixed_right_arg) 1012 decode_arg_value(FixedRightArgValueBits::decode(state)))),
1018 : op_(OpBits::decode(key)), 1013 left_state_(LeftStateField::decode(state)),
1019 mode_(ModeBits::decode(key)), 1014 left_bool_(LeftBoolField::decode(state)),
1020 platform_specific_bit_(PlatformSpecificBits::decode(key)), 1015 right_state_(fixed_right_arg_.has_value
1021 left_type_(left_type), 1016 ? ((fixed_right_arg_.value <= Smi::kMaxValue) ? SMI : INT32)
1022 right_type_(right_type), 1017 : RightStateField::decode(state)),
1023 result_type_(result_type), 1018 right_bool_(fixed_right_arg_.has_value
1024 encoded_right_arg_(fixed_right_arg.has_value, 1019 ? false : RightBoolField::decode(state)),
1025 encode_arg_value(fixed_right_arg.value)) { } 1020 result_state_(ResultStateField::decode(state)) {
1026 1021 // We don't deserialize the SSE2 Field, since this is only used to be able
1027 static void decode_types_from_minor_key(int minor_key, 1022 // to include SSE2 as well as non-SSE2 versions in the snapshot. For code
1028 BinaryOpIC::TypeInfo* left_type, 1023 // generation we always want it to reflect the current state.
1029 BinaryOpIC::TypeInfo* right_type, 1024 ASSERT(!fixed_right_arg_.has_value ||
1030 BinaryOpIC::TypeInfo* result_type) { 1025 can_encode_arg_value(fixed_right_arg_.value));
1031 *left_type =
1032 static_cast<BinaryOpIC::TypeInfo>(LeftTypeBits::decode(minor_key));
1033 *right_type =
1034 static_cast<BinaryOpIC::TypeInfo>(RightTypeBits::decode(minor_key));
1035 *result_type =
1036 static_cast<BinaryOpIC::TypeInfo>(ResultTypeBits::decode(minor_key));
1037 } 1026 }
1038 1027
1039 static Token::Value decode_op_from_minor_key(int minor_key) { 1028 static const int FIRST_TOKEN = Token::BIT_OR;
1040 return static_cast<Token::Value>(OpBits::decode(minor_key)); 1029 static const int LAST_TOKEN = Token::MOD;
1030
1031 static void GenerateAheadOfTime(Isolate* isolate);
1032 virtual void InitializeInterfaceDescriptor(
1033 Isolate* isolate, CodeStubInterfaceDescriptor* descriptor);
1034 static void InitializeForIsolate(Isolate* isolate) {
1035 BinaryOpStub binopStub(UNINITIALIZED);
1036 binopStub.InitializeInterfaceDescriptor(
1037 isolate, isolate->code_stub_interface_descriptor(CodeStub::BinaryOp));
1041 } 1038 }
1042 1039
1043 static Maybe<int> decode_fixed_right_arg_from_minor_key(int minor_key) { 1040 virtual Code::Kind GetCodeKind() const { return Code::BINARY_OP_IC; }
1044 return Maybe<int>( 1041 virtual InlineCacheState GetICState() {
1045 HasFixedRightArgBits::decode(minor_key), 1042 if (Max(left_state_, right_state_) == NONE && !left_bool_ && !right_bool_) {
1046 decode_arg_value(FixedRightArgValueBits::decode(minor_key))); 1043 return ::v8::internal::UNINITIALIZED;
1044 }
1045 if (Max(left_state_, right_state_) == GENERIC) return MEGAMORPHIC;
1046 return MONOMORPHIC;
1047 } 1047 }
1048 1048
1049 int fixed_right_arg_value() const { 1049 virtual Code::ExtraICState GetExtraICState() {
1050 return decode_arg_value(encoded_right_arg_.value); 1050 bool sse_field = Max(result_state_, Max(left_state_, right_state_)) > SMI &&
1051 CpuFeatures::IsSafeForSnapshot(SSE2);
1052
1053 return OpBits::encode(encode_token(op_))
1054 | LeftStateField::encode(left_state_)
1055 | LeftBoolField::encode(left_bool_)
1056 | RightStateField::encode(fixed_right_arg_.has_value
1057 ? NONE : right_state_)
1058 | RightBoolField::encode(fixed_right_arg_.has_value
1059 ? false
1060 : right_bool_)
1061 | ResultStateField::encode(result_state_)
1062 | HasFixedRightArgBits::encode(fixed_right_arg_.has_value)
1063 | FixedRightArgValueBits::encode(fixed_right_arg_.has_value
1064 ? encode_arg_value(
1065 fixed_right_arg_.value)
1066 : 0)
1067 | SSE2Field::encode(sse_field)
1068 | OverwriteModeField::encode(mode_);
1051 } 1069 }
1052 1070
1053 static bool can_encode_arg_value(int32_t value) { 1071 bool CanReuseDoubleBox() {
1054 return value > 0 && 1072 return result_state_ <= NUMBER && result_state_ > SMI &&
1055 IsPowerOf2(value) && 1073 ((left_state_ > SMI && left_state_ <= NUMBER &&
1056 FixedRightArgValueBits::is_valid(WhichPowerOf2(value)); 1074 mode_ == OVERWRITE_LEFT) ||
1075 (right_state_ > SMI && right_state_ <= NUMBER &&
1076 mode_ == OVERWRITE_RIGHT));
1057 } 1077 }
1058 1078
1059 enum SmiCodeGenerateHeapNumberResults { 1079 bool HasSideEffects(Isolate* isolate) const {
1060 ALLOW_HEAPNUMBER_RESULTS, 1080 return GetLeftType(isolate)->Maybe(Type::Receiver()) ||
1061 NO_HEAPNUMBER_RESULTS 1081 GetRightType(isolate)->Maybe(Type::Receiver());
1062 }; 1082 }
1083
1084 virtual Handle<Code> GenerateCode(Isolate* isolate);
1085
1086 Maybe<Handle<Object> > Result(Handle<Object> left,
1087 Handle<Object> right,
1088 Isolate* isolate);
1089
1090 Token::Value operation() const { return op_; }
1091 OverwriteMode mode() const { return mode_; }
1092 Maybe<int> fixed_right_arg() const { return fixed_right_arg_; }
1093
1094 Handle<Type> GetLeftType(Isolate* isolate) const;
1095 Handle<Type> GetRightType(Isolate* isolate) const;
1096 Handle<Type> GetResultType(Isolate* isolate) const;
1097
1098 void UpdateStatus(Handle<Object> left,
1099 Handle<Object> right,
1100 Maybe<Handle<Object> > result);
1101
1102 void PrintState(StringStream* stream);
1063 1103
1064 private: 1104 private:
1105 explicit BinaryOpStub(InitializationState state) : HydrogenCodeStub(state),
1106 op_(Token::ADD),
1107 mode_(NO_OVERWRITE) {
1108 Initialize();
1109 }
1110 void Initialize();
1111
1112 enum State { NONE, SMI, INT32, NUMBER, STRING, GENERIC };
1113
1114 // We truncate the last bit of the token.
1115 STATIC_ASSERT(LAST_TOKEN - FIRST_TOKEN < (1 << 5));
1116 class LeftStateField: public BitField<State, 0, 3> {};
1117 class LeftBoolField: public BitField<bool, 3, 1> {};
1118 // When fixed right arg is set, we don't need to store the right state.
1119 // Thus the two fields can overlap.
1120 class HasFixedRightArgBits: public BitField<bool, 4, 1> {};
1121 class FixedRightArgValueBits: public BitField<int, 5, 4> {};
1122 class RightStateField: public BitField<State, 5, 3> {};
1123 class RightBoolField: public BitField<bool, 8, 1> {};
1124 class ResultStateField: public BitField<State, 9, 3> {};
1125 class SSE2Field: public BitField<bool, 12, 1> {};
1126 class OverwriteModeField: public BitField<OverwriteMode, 13, 2> {};
1127 class OpBits: public BitField<int, 15, 5> {};
1128
1129 virtual CodeStub::Major MajorKey() { return BinaryOp; }
1130 virtual int NotMissMinorKey() { return GetExtraICState(); }
1131
1132 static Handle<Type> StateToType(State state,
1133 bool seen_bool,
1134 Isolate* isolate);
1135
1136 static void Generate(Token::Value op,
1137 State left,
1138 State right,
1139 State result,
1140 Isolate* isolate);
1141
1142 void UpdateStatus(Handle<Object> object,
1143 State* state,
1144 bool* bool_state);
1145
1146 bool can_encode_arg_value(int32_t value) const;
1147 int encode_arg_value(int32_t value) const;
1148 int32_t decode_arg_value(int value) const;
1149 int encode_token(Token::Value op) const;
1150 Token::Value decode_token(int op) const;
1151
1152 bool has_int_result() const {
1153 return op_ == Token::BIT_XOR || op_ == Token::BIT_AND ||
1154 op_ == Token::BIT_OR || op_ == Token::SAR;
1155 }
1156
1157 const char* StateToName(State state);
1158
1159 void PrintBaseName(StringStream* stream);
1160
1065 Token::Value op_; 1161 Token::Value op_;
1066 OverwriteMode mode_; 1162 OverwriteMode mode_;
1067 bool platform_specific_bit_; // Indicates SSE3 on IA32.
1068 1163
1069 // Operand type information determined at runtime. 1164 Maybe<int> fixed_right_arg_;
1070 BinaryOpIC::TypeInfo left_type_; 1165 State left_state_;
1071 BinaryOpIC::TypeInfo right_type_; 1166 bool left_bool_;
1072 BinaryOpIC::TypeInfo result_type_; 1167 State right_state_;
1073 1168 bool right_bool_;
1074 Maybe<int> encoded_right_arg_; 1169 State result_state_;
1075
1076 static int encode_arg_value(int32_t value) {
1077 ASSERT(can_encode_arg_value(value));
1078 return WhichPowerOf2(value);
1079 }
1080
1081 static int32_t decode_arg_value(int value) {
1082 return 1 << value;
1083 }
1084
1085 virtual void PrintName(StringStream* stream);
1086
1087 // Minor key encoding in all 25 bits FFFFFHTTTRRRLLLPOOOOOOOMM.
1088 // Note: We actually do not need 7 bits for the operation, just 4 bits to
1089 // encode ADD, SUB, MUL, DIV, MOD, BIT_OR, BIT_AND, BIT_XOR, SAR, SHL, SHR.
1090 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
1091 class OpBits: public BitField<Token::Value, 2, 7> {};
1092 class PlatformSpecificBits: public BitField<bool, 9, 1> {};
1093 class LeftTypeBits: public BitField<BinaryOpIC::TypeInfo, 10, 3> {};
1094 class RightTypeBits: public BitField<BinaryOpIC::TypeInfo, 13, 3> {};
1095 class ResultTypeBits: public BitField<BinaryOpIC::TypeInfo, 16, 3> {};
1096 class HasFixedRightArgBits: public BitField<bool, 19, 1> {};
1097 class FixedRightArgValueBits: public BitField<int, 20, 5> {};
1098
1099 Major MajorKey() { return BinaryOp; }
1100 int MinorKey() {
1101 return OpBits::encode(op_)
1102 | ModeBits::encode(mode_)
1103 | PlatformSpecificBits::encode(platform_specific_bit_)
1104 | LeftTypeBits::encode(left_type_)
1105 | RightTypeBits::encode(right_type_)
1106 | ResultTypeBits::encode(result_type_)
1107 | HasFixedRightArgBits::encode(encoded_right_arg_.has_value)
1108 | FixedRightArgValueBits::encode(encoded_right_arg_.value);
1109 }
1110
1111
1112 // Platform-independent implementation.
1113 void Generate(MacroAssembler* masm);
1114 void GenerateCallRuntime(MacroAssembler* masm);
1115
1116 // Platform-independent signature, platform-specific implementation.
1117 void Initialize();
1118 void GenerateAddStrings(MacroAssembler* masm);
1119 void GenerateBothStringStub(MacroAssembler* masm);
1120 void GenerateGeneric(MacroAssembler* masm);
1121 void GenerateGenericStub(MacroAssembler* masm);
1122 void GenerateNumberStub(MacroAssembler* masm);
1123 void GenerateInt32Stub(MacroAssembler* masm);
1124 void GenerateLoadArguments(MacroAssembler* masm);
1125 void GenerateOddballStub(MacroAssembler* masm);
1126 void GenerateRegisterArgsPush(MacroAssembler* masm);
1127 void GenerateReturn(MacroAssembler* masm);
1128 void GenerateSmiStub(MacroAssembler* masm);
1129 void GenerateStringStub(MacroAssembler* masm);
1130 void GenerateTypeTransition(MacroAssembler* masm);
1131 void GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm);
1132 void GenerateUninitializedStub(MacroAssembler* masm);
1133
1134 // Entirely platform-specific methods are defined as static helper
1135 // functions in the <arch>/code-stubs-<arch>.cc files.
1136
1137 virtual Code::Kind GetCodeKind() const { return Code::BINARY_OP_IC; }
1138
1139 virtual InlineCacheState GetICState() {
1140 return BinaryOpIC::ToState(Max(left_type_, right_type_));
1141 }
1142
1143 virtual void FinishCode(Handle<Code> code) {
1144 code->set_stub_info(MinorKey());
1145 }
1146
1147 friend class CodeGenerator;
1148 }; 1170 };
1149 1171
1150 1172
1151 class ICCompareStub: public PlatformCodeStub { 1173 class ICCompareStub: public PlatformCodeStub {
1152 public: 1174 public:
1153 ICCompareStub(Token::Value op, 1175 ICCompareStub(Token::Value op,
1154 CompareIC::State left, 1176 CompareIC::State left,
1155 CompareIC::State right, 1177 CompareIC::State right,
1156 CompareIC::State handler) 1178 CompareIC::State handler)
1157 : op_(op), 1179 : op_(op),
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 public: 1732 public:
1711 DoubleToIStub(Register source, 1733 DoubleToIStub(Register source,
1712 Register destination, 1734 Register destination,
1713 int offset, 1735 int offset,
1714 bool is_truncating, 1736 bool is_truncating,
1715 bool skip_fastpath = false) : bit_field_(0) { 1737 bool skip_fastpath = false) : bit_field_(0) {
1716 bit_field_ = SourceRegisterBits::encode(source.code_) | 1738 bit_field_ = SourceRegisterBits::encode(source.code_) |
1717 DestinationRegisterBits::encode(destination.code_) | 1739 DestinationRegisterBits::encode(destination.code_) |
1718 OffsetBits::encode(offset) | 1740 OffsetBits::encode(offset) |
1719 IsTruncatingBits::encode(is_truncating) | 1741 IsTruncatingBits::encode(is_truncating) |
1720 SkipFastPathBits::encode(skip_fastpath); 1742 SkipFastPathBits::encode(skip_fastpath) |
1743 SSEBits::encode(CpuFeatures::IsSafeForSnapshot(SSE2) ?
1744 CpuFeatures::IsSafeForSnapshot(SSE3) ? 2 : 1 : 0);
1721 } 1745 }
1722 1746
1723 Register source() { 1747 Register source() {
1724 Register result = { SourceRegisterBits::decode(bit_field_) }; 1748 Register result = { SourceRegisterBits::decode(bit_field_) };
1725 return result; 1749 return result;
1726 } 1750 }
1727 1751
1728 Register destination() { 1752 Register destination() {
1729 Register result = { DestinationRegisterBits::decode(bit_field_) }; 1753 Register result = { DestinationRegisterBits::decode(bit_field_) };
1730 return result; 1754 return result;
(...skipping 22 matching lines...) Expand all
1753 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT 1777 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT
1754 class DestinationRegisterBits: 1778 class DestinationRegisterBits:
1755 public BitField<int, kBitsPerRegisterNumber, 1779 public BitField<int, kBitsPerRegisterNumber,
1756 kBitsPerRegisterNumber> {}; // NOLINT 1780 kBitsPerRegisterNumber> {}; // NOLINT
1757 class IsTruncatingBits: 1781 class IsTruncatingBits:
1758 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT 1782 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT
1759 class OffsetBits: 1783 class OffsetBits:
1760 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT 1784 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT
1761 class SkipFastPathBits: 1785 class SkipFastPathBits:
1762 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT 1786 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT
1787 class SSEBits:
1788 public BitField<int, 2 * kBitsPerRegisterNumber + 5, 2> {}; // NOLINT
1763 1789
1764 Major MajorKey() { return DoubleToI; } 1790 Major MajorKey() { return DoubleToI; }
1765 int MinorKey() { return bit_field_; } 1791 int MinorKey() { return bit_field_; }
1766 1792
1767 int bit_field_; 1793 int bit_field_;
1768 1794
1769 DISALLOW_COPY_AND_ASSIGN(DoubleToIStub); 1795 DISALLOW_COPY_AND_ASSIGN(DoubleToIStub);
1770 }; 1796 };
1771 1797
1772 1798
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
2319 int MinorKey() { return 0; } 2345 int MinorKey() { return 0; }
2320 2346
2321 void Generate(MacroAssembler* masm); 2347 void Generate(MacroAssembler* masm);
2322 2348
2323 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub); 2349 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub);
2324 }; 2350 };
2325 2351
2326 } } // namespace v8::internal 2352 } } // namespace v8::internal
2327 2353
2328 #endif // V8_CODE_STUBS_H_ 2354 #endif // V8_CODE_STUBS_H_
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/code-stubs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698