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

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 overwrite mode & better result typefeedback 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') | src/code-stubs.cc » ('J')
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 init();
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();
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
1035 virtual Code::Kind GetCodeKind() const { return Code::BINARY_OP_IC; }
1036 virtual InlineCacheState GetICState() {
1037 if (Max(left_state_, right_state_) == NONE && !left_bool_ && !right_bool_) {
1038 return ::v8::internal::UNINITIALIZED;
1039 }
1040 if (Max(left_state_, right_state_) == GENERIC) return MEGAMORPHIC;
1041 return MONOMORPHIC;
1041 } 1042 }
1042 1043
1043 static Maybe<int> decode_fixed_right_arg_from_minor_key(int minor_key) { 1044 virtual Code::ExtraICState GetExtraICState() {
1044 return Maybe<int>( 1045 bool sse_field = Max(result_state_, Max(left_state_, right_state_)) > SMI &&
1045 HasFixedRightArgBits::decode(minor_key), 1046 CpuFeatures::IsSafeForSnapshot(SSE2);
1046 decode_arg_value(FixedRightArgValueBits::decode(minor_key))); 1047
1048 return OpBits::encode(encode_token(op_))
1049 | LeftStateField::encode(left_state_)
1050 | LeftBoolField::encode(left_bool_)
1051 | RightStateField::encode(fixed_right_arg_.has_value
1052 ? NONE : right_state_)
1053 | RightBoolField::encode(fixed_right_arg_.has_value
1054 ? false
1055 : right_bool_)
1056 | ResultStateField::encode(result_state_)
1057 | HasFixedRightArgBits::encode(fixed_right_arg_.has_value)
1058 | FixedRightArgValueBits::encode(fixed_right_arg_.has_value
1059 ? encode_arg_value(
1060 fixed_right_arg_.value)
1061 : 0)
1062 | SSE2Field::encode(sse_field)
1063 | OverwriteModeField::encode(mode_);
1047 } 1064 }
1048 1065
1049 int fixed_right_arg_value() const { 1066 bool CanReuseDoubleBox() {
1050 return decode_arg_value(encoded_right_arg_.value); 1067 return result_state_ <= NUMBER &&
1068 ((left_state_ > SMI && left_state_ <= NUMBER &&
1069 mode_ == OVERWRITE_LEFT) ||
1070 (right_state_ > SMI && right_state_ <= NUMBER &&
1071 mode_ == OVERWRITE_RIGHT));
1051 } 1072 }
1052 1073
1053 static bool can_encode_arg_value(int32_t value) { 1074 virtual Handle<Code> GenerateCode(Isolate* isolate);
1054 return value > 0 && 1075
1055 IsPowerOf2(value) && 1076 Maybe<Handle<Object> > Result(Handle<Object> left,
1056 FixedRightArgValueBits::is_valid(WhichPowerOf2(value)); 1077 Handle<Object> right,
1078 Isolate* isolate);
1079
1080 Token::Value operation() { return op_; }
1081 OverwriteMode mode() { return mode_; }
Michael Starzinger 2013/09/27 08:36:11 nit: These three can be made const.
1082 Maybe<int> fixed_right_arg() { return fixed_right_arg_; }
1083
1084 Handle<Type> GetLeftType(Isolate* isolate) const;
1085 Handle<Type> GetRightType(Isolate* isolate) const;
1086 Handle<Type> GetResultType(Isolate* isolate) const;
1087
1088 bool HasSideEffects(Isolate* isolate) const {
1089 return GetLeftType(isolate)->Maybe(Type::Receiver()) ||
1090 GetRightType(isolate)->Maybe(Type::Receiver());
1057 } 1091 }
1058 1092
1059 enum SmiCodeGenerateHeapNumberResults { 1093 void UpdateStatus(Handle<Object> left,
1060 ALLOW_HEAPNUMBER_RESULTS, 1094 Handle<Object> right,
1061 NO_HEAPNUMBER_RESULTS 1095 Maybe<Handle<Object> > result);
1062 }; 1096
1097 void PrintState(StringStream* stream);
1063 1098
1064 private: 1099 private:
1100 explicit BinaryOpStub(InitializationState state) : HydrogenCodeStub(state),
1101 op_(Token::ADD),
1102 mode_(NO_OVERWRITE) {
1103 init();
1104 }
1105 void init();
Michael Starzinger 2013/09/27 08:36:11 nit: s/init/Initialize/
1106
1107 enum State { NONE, SMI, INT32, NUMBER, STRING, GENERIC };
1108
1109 // We truncate the last bit of the token.
1110 STATIC_ASSERT(LAST_TOKEN - FIRST_TOKEN < (1 << 5));
1111 class LeftStateField: public BitField<State, 0, 3> {};
1112 class LeftBoolField: public BitField<bool, 3, 1> {};
1113 class ResultStateField: public BitField<State, 9, 3> {};
Michael Starzinger 2013/09/27 08:36:11 nit: Move the ResultStateField down to after the R
1114 // When fixed right arg is set, we don't need to store the right state.
1115 // Thus the two fields can overlap.
1116 class HasFixedRightArgBits: public BitField<bool, 4, 1> {};
1117 class FixedRightArgValueBits: public BitField<int, 5, 4> {};
1118 class RightStateField: public BitField<State, 5, 3> {};
1119 class RightBoolField: public BitField<bool, 8, 1> {};
1120 class SSE2Field: public BitField<bool, 12, 1> {};
1121 class OverwriteModeField: public BitField<OverwriteMode, 13, 2> {};
1122 class OpBits: public BitField<int, 15, 5> {};
1123
1124 virtual CodeStub::Major MajorKey() { return BinaryOp; }
1125 virtual int NotMissMinorKey() { return GetExtraICState(); }
1126
1127 static Handle<Type> StateToType(State state,
1128 bool seen_bool,
1129 Isolate* isolate);
1130
1131 static void Generate(Token::Value op,
1132 State left,
1133 State right,
1134 State result,
1135 Isolate* isolate);
1136
1137 void UpdateStatus(Handle<Object> object,
1138 State* state,
1139 bool* bool_state);
1140
1141 bool can_encode_arg_value(int32_t value) const;
1142 int encode_arg_value(int32_t value) const;
1143 int32_t decode_arg_value(int value) const;
1144 int encode_token(Token::Value op) const;
1145 Token::Value decode_token(int op) const;
1146
1147 bool has_int_result() const {
1148 return op_ == Token::BIT_XOR || op_ == Token::BIT_AND ||
1149 op_ == Token::BIT_OR || op_ == Token::SAR;
1150 }
1151
1152 const char* StateToName(State state);
1153
1154 void PrintBaseName(StringStream* stream);
1155
1065 Token::Value op_; 1156 Token::Value op_;
1066 OverwriteMode mode_; 1157 OverwriteMode mode_;
1067 bool platform_specific_bit_; // Indicates SSE3 on IA32.
1068 1158
1069 // Operand type information determined at runtime. 1159 Maybe<int> fixed_right_arg_;
1070 BinaryOpIC::TypeInfo left_type_; 1160 State left_state_;
1071 BinaryOpIC::TypeInfo right_type_; 1161 bool left_bool_;
1072 BinaryOpIC::TypeInfo result_type_; 1162 State right_state_;
1073 1163 bool right_bool_;
1074 Maybe<int> encoded_right_arg_; 1164 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 }; 1165 };
1149 1166
1150 1167
1151 class ICCompareStub: public PlatformCodeStub { 1168 class ICCompareStub: public PlatformCodeStub {
1152 public: 1169 public:
1153 ICCompareStub(Token::Value op, 1170 ICCompareStub(Token::Value op,
1154 CompareIC::State left, 1171 CompareIC::State left,
1155 CompareIC::State right, 1172 CompareIC::State right,
1156 CompareIC::State handler) 1173 CompareIC::State handler)
1157 : op_(op), 1174 : op_(op),
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 public: 1727 public:
1711 DoubleToIStub(Register source, 1728 DoubleToIStub(Register source,
1712 Register destination, 1729 Register destination,
1713 int offset, 1730 int offset,
1714 bool is_truncating, 1731 bool is_truncating,
1715 bool skip_fastpath = false) : bit_field_(0) { 1732 bool skip_fastpath = false) : bit_field_(0) {
1716 bit_field_ = SourceRegisterBits::encode(source.code_) | 1733 bit_field_ = SourceRegisterBits::encode(source.code_) |
1717 DestinationRegisterBits::encode(destination.code_) | 1734 DestinationRegisterBits::encode(destination.code_) |
1718 OffsetBits::encode(offset) | 1735 OffsetBits::encode(offset) |
1719 IsTruncatingBits::encode(is_truncating) | 1736 IsTruncatingBits::encode(is_truncating) |
1720 SkipFastPathBits::encode(skip_fastpath); 1737 SkipFastPathBits::encode(skip_fastpath) |
1738 SSEBits::encode(CpuFeatures::IsSafeForSnapshot(SSE2) ?
1739 CpuFeatures::IsSafeForSnapshot(SSE3) ? 2 : 1 : 0);
1721 } 1740 }
1722 1741
1723 Register source() { 1742 Register source() {
1724 Register result = { SourceRegisterBits::decode(bit_field_) }; 1743 Register result = { SourceRegisterBits::decode(bit_field_) };
1725 return result; 1744 return result;
1726 } 1745 }
1727 1746
1728 Register destination() { 1747 Register destination() {
1729 Register result = { DestinationRegisterBits::decode(bit_field_) }; 1748 Register result = { DestinationRegisterBits::decode(bit_field_) };
1730 return result; 1749 return result;
(...skipping 22 matching lines...) Expand all
1753 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT 1772 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT
1754 class DestinationRegisterBits: 1773 class DestinationRegisterBits:
1755 public BitField<int, kBitsPerRegisterNumber, 1774 public BitField<int, kBitsPerRegisterNumber,
1756 kBitsPerRegisterNumber> {}; // NOLINT 1775 kBitsPerRegisterNumber> {}; // NOLINT
1757 class IsTruncatingBits: 1776 class IsTruncatingBits:
1758 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT 1777 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT
1759 class OffsetBits: 1778 class OffsetBits:
1760 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT 1779 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT
1761 class SkipFastPathBits: 1780 class SkipFastPathBits:
1762 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT 1781 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT
1782 class SSEBits:
1783 public BitField<int, 2 * kBitsPerRegisterNumber + 5, 2> {}; // NOLINT
1763 1784
1764 Major MajorKey() { return DoubleToI; } 1785 Major MajorKey() { return DoubleToI; }
1765 int MinorKey() { return bit_field_; } 1786 int MinorKey() { return bit_field_; }
1766 1787
1767 int bit_field_; 1788 int bit_field_;
1768 1789
1769 DISALLOW_COPY_AND_ASSIGN(DoubleToIStub); 1790 DISALLOW_COPY_AND_ASSIGN(DoubleToIStub);
1770 }; 1791 };
1771 1792
1772 1793
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
2319 int MinorKey() { return 0; } 2340 int MinorKey() { return 0; }
2320 2341
2321 void Generate(MacroAssembler* masm); 2342 void Generate(MacroAssembler* masm);
2322 2343
2323 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub); 2344 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub);
2324 }; 2345 };
2325 2346
2326 } } // namespace v8::internal 2347 } } // namespace v8::internal
2327 2348
2328 #endif // V8_CODE_STUBS_H_ 2349 #endif // V8_CODE_STUBS_H_
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/code-stubs.cc » ('j') | src/code-stubs.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698