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

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

Issue 25571002: Revert "Hydrogenisation of binops" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
206 protected: 203 protected:
207 static bool CanUseFPRegisters(); 204 static bool CanUseFPRegisters();
208 205
209 // Generates the assembler code for the stub. 206 // Generates the assembler code for the stub.
210 virtual Handle<Code> GenerateCode(Isolate* isolate) = 0; 207 virtual Handle<Code> GenerateCode(Isolate* isolate) = 0;
211 208
212 209
213 // Returns whether the code generated for this stub needs to be allocated as 210 // Returns whether the code generated for this stub needs to be allocated as
214 // a fixed (non-moveable) code object. 211 // a fixed (non-moveable) code object.
215 virtual bool NeedsImmovableCode() { return false; } 212 virtual bool NeedsImmovableCode() { return false; }
216 213
214 // Returns a name for logging/debugging purposes.
215 SmartArrayPointer<const char> GetName();
217 virtual void PrintBaseName(StringStream* stream); 216 virtual void PrintBaseName(StringStream* stream);
218 virtual void PrintState(StringStream* stream) { } 217 virtual void PrintState(StringStream* stream) { }
219 218
220 private: 219 private:
221 // Perform bookkeeping required after code generation when stub code is 220 // Perform bookkeeping required after code generation when stub code is
222 // initially generated. 221 // initially generated.
223 void RecordCodeGeneration(Code* code, Isolate* isolate); 222 void RecordCodeGeneration(Code* code, Isolate* isolate);
224 223
225 // Finish the code object after it has been generated. 224 // Finish the code object after it has been generated.
226 virtual void FinishCode(Handle<Code> code) { } 225 virtual void FinishCode(Handle<Code> code) { }
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 Isolate* isolate, 988 Isolate* isolate,
990 CodeStubInterfaceDescriptor* descriptor); 989 CodeStubInterfaceDescriptor* descriptor);
991 990
992 virtual Handle<Code> GenerateCode(Isolate* isolate); 991 virtual Handle<Code> GenerateCode(Isolate* isolate);
993 992
994 private: 993 private:
995 virtual CodeStub::Major MajorKey() { return KeyedLoadField; } 994 virtual CodeStub::Major MajorKey() { return KeyedLoadField; }
996 }; 995 };
997 996
998 997
999 class BinaryOpStub: public HydrogenCodeStub { 998 class BinaryOpStub: public PlatformCodeStub {
1000 public: 999 public:
1001 BinaryOpStub(Token::Value op, OverwriteMode mode) 1000 BinaryOpStub(Token::Value op, OverwriteMode mode)
1002 : HydrogenCodeStub(UNINITIALIZED), op_(op), mode_(mode) { 1001 : op_(op),
1003 ASSERT(op <= LAST_TOKEN && op >= FIRST_TOKEN); 1002 mode_(mode),
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)) {
1004 Initialize(); 1008 Initialize();
1009 ASSERT(OpBits::is_valid(Token::NUM_TOKENS));
1005 } 1010 }
1006 1011
1007 explicit BinaryOpStub(Code::ExtraICState state) 1012 BinaryOpStub(
1008 : op_(decode_token(OpBits::decode(state))), 1013 int key,
1009 mode_(OverwriteModeField::decode(state)), 1014 BinaryOpIC::TypeInfo left_type,
1010 fixed_right_arg_( 1015 BinaryOpIC::TypeInfo right_type,
1011 Maybe<int>(HasFixedRightArgBits::decode(state), 1016 BinaryOpIC::TypeInfo result_type,
1012 decode_arg_value(FixedRightArgValueBits::decode(state)))), 1017 Maybe<int32_t> fixed_right_arg)
1013 left_state_(LeftStateField::decode(state)), 1018 : op_(OpBits::decode(key)),
1014 left_bool_(LeftBoolField::decode(state)), 1019 mode_(ModeBits::decode(key)),
1015 right_state_(fixed_right_arg_.has_value 1020 platform_specific_bit_(PlatformSpecificBits::decode(key)),
1016 ? ((fixed_right_arg_.value <= Smi::kMaxValue) ? SMI : INT32) 1021 left_type_(left_type),
1017 : RightStateField::decode(state)), 1022 right_type_(right_type),
1018 right_bool_(fixed_right_arg_.has_value 1023 result_type_(result_type),
1019 ? false : RightBoolField::decode(state)), 1024 encoded_right_arg_(fixed_right_arg.has_value,
1020 result_state_(ResultStateField::decode(state)) { 1025 encode_arg_value(fixed_right_arg.value)) { }
1021 // We don't deserialize the SSE2 Field, since this is only used to be able 1026
1022 // to include SSE2 as well as non-SSE2 versions in the snapshot. For code 1027 static void decode_types_from_minor_key(int minor_key,
1023 // generation we always want it to reflect the current state. 1028 BinaryOpIC::TypeInfo* left_type,
1024 ASSERT(!fixed_right_arg_.has_value || 1029 BinaryOpIC::TypeInfo* right_type,
1025 can_encode_arg_value(fixed_right_arg_.value)); 1030 BinaryOpIC::TypeInfo* result_type) {
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));
1026 } 1037 }
1027 1038
1028 static const int FIRST_TOKEN = Token::BIT_OR; 1039 static Token::Value decode_op_from_minor_key(int minor_key) {
1029 static const int LAST_TOKEN = Token::MOD; 1040 return static_cast<Token::Value>(OpBits::decode(minor_key));
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));
1038 } 1041 }
1039 1042
1040 virtual Code::Kind GetCodeKind() const { return Code::BINARY_OP_IC; } 1043 static Maybe<int> decode_fixed_right_arg_from_minor_key(int minor_key) {
1041 virtual InlineCacheState GetICState() { 1044 return Maybe<int>(
1042 if (Max(left_state_, right_state_) == NONE && !left_bool_ && !right_bool_) { 1045 HasFixedRightArgBits::decode(minor_key),
1043 return ::v8::internal::UNINITIALIZED; 1046 decode_arg_value(FixedRightArgValueBits::decode(minor_key)));
1044 }
1045 if (Max(left_state_, right_state_) == GENERIC) return MEGAMORPHIC;
1046 return MONOMORPHIC;
1047 } 1047 }
1048 1048
1049 virtual Code::ExtraICState GetExtraICState() { 1049 int fixed_right_arg_value() const {
1050 bool sse_field = Max(result_state_, Max(left_state_, right_state_)) > SMI && 1050 return decode_arg_value(encoded_right_arg_.value);
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_);
1069 } 1051 }
1070 1052
1071 bool CanReuseDoubleBox() { 1053 static bool can_encode_arg_value(int32_t value) {
1072 return result_state_ <= NUMBER && result_state_ > SMI && 1054 return value > 0 &&
1073 ((left_state_ > SMI && left_state_ <= NUMBER && 1055 IsPowerOf2(value) &&
1074 mode_ == OVERWRITE_LEFT) || 1056 FixedRightArgValueBits::is_valid(WhichPowerOf2(value));
1075 (right_state_ > SMI && right_state_ <= NUMBER &&
1076 mode_ == OVERWRITE_RIGHT));
1077 } 1057 }
1078 1058
1079 bool HasSideEffects(Isolate* isolate) const { 1059 enum SmiCodeGenerateHeapNumberResults {
1080 return GetLeftType(isolate)->Maybe(Type::Receiver()) || 1060 ALLOW_HEAPNUMBER_RESULTS,
1081 GetRightType(isolate)->Maybe(Type::Receiver()); 1061 NO_HEAPNUMBER_RESULTS
1062 };
1063
1064 private:
1065 Token::Value op_;
1066 OverwriteMode mode_;
1067 bool platform_specific_bit_; // Indicates SSE3 on IA32.
1068
1069 // Operand type information determined at runtime.
1070 BinaryOpIC::TypeInfo left_type_;
1071 BinaryOpIC::TypeInfo right_type_;
1072 BinaryOpIC::TypeInfo result_type_;
1073
1074 Maybe<int> encoded_right_arg_;
1075
1076 static int encode_arg_value(int32_t value) {
1077 ASSERT(can_encode_arg_value(value));
1078 return WhichPowerOf2(value);
1082 } 1079 }
1083 1080
1084 virtual Handle<Code> GenerateCode(Isolate* isolate); 1081 static int32_t decode_arg_value(int value) {
1085 1082 return 1 << value;
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);
1103
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 } 1083 }
1156 1084
1157 const char* StateToName(State state); 1085 virtual void PrintName(StringStream* stream);
1158 1086
1159 void PrintBaseName(StringStream* stream); 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> {};
1160 1098
1161 Token::Value op_; 1099 Major MajorKey() { return BinaryOp; }
1162 OverwriteMode mode_; 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 }
1163 1110
1164 Maybe<int> fixed_right_arg_; 1111
1165 State left_state_; 1112 // Platform-independent implementation.
1166 bool left_bool_; 1113 void Generate(MacroAssembler* masm);
1167 State right_state_; 1114 void GenerateCallRuntime(MacroAssembler* masm);
1168 bool right_bool_; 1115
1169 State result_state_; 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;
1170 }; 1148 };
1171 1149
1172 1150
1173 class ICCompareStub: public PlatformCodeStub { 1151 class ICCompareStub: public PlatformCodeStub {
1174 public: 1152 public:
1175 ICCompareStub(Token::Value op, 1153 ICCompareStub(Token::Value op,
1176 CompareIC::State left, 1154 CompareIC::State left,
1177 CompareIC::State right, 1155 CompareIC::State right,
1178 CompareIC::State handler) 1156 CompareIC::State handler)
1179 : op_(op), 1157 : op_(op),
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1732 public: 1710 public:
1733 DoubleToIStub(Register source, 1711 DoubleToIStub(Register source,
1734 Register destination, 1712 Register destination,
1735 int offset, 1713 int offset,
1736 bool is_truncating, 1714 bool is_truncating,
1737 bool skip_fastpath = false) : bit_field_(0) { 1715 bool skip_fastpath = false) : bit_field_(0) {
1738 bit_field_ = SourceRegisterBits::encode(source.code_) | 1716 bit_field_ = SourceRegisterBits::encode(source.code_) |
1739 DestinationRegisterBits::encode(destination.code_) | 1717 DestinationRegisterBits::encode(destination.code_) |
1740 OffsetBits::encode(offset) | 1718 OffsetBits::encode(offset) |
1741 IsTruncatingBits::encode(is_truncating) | 1719 IsTruncatingBits::encode(is_truncating) |
1742 SkipFastPathBits::encode(skip_fastpath) | 1720 SkipFastPathBits::encode(skip_fastpath);
1743 SSEBits::encode(CpuFeatures::IsSafeForSnapshot(SSE2) ?
1744 CpuFeatures::IsSafeForSnapshot(SSE3) ? 2 : 1 : 0);
1745 } 1721 }
1746 1722
1747 Register source() { 1723 Register source() {
1748 Register result = { SourceRegisterBits::decode(bit_field_) }; 1724 Register result = { SourceRegisterBits::decode(bit_field_) };
1749 return result; 1725 return result;
1750 } 1726 }
1751 1727
1752 Register destination() { 1728 Register destination() {
1753 Register result = { DestinationRegisterBits::decode(bit_field_) }; 1729 Register result = { DestinationRegisterBits::decode(bit_field_) };
1754 return result; 1730 return result;
(...skipping 22 matching lines...) Expand all
1777 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT 1753 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT
1778 class DestinationRegisterBits: 1754 class DestinationRegisterBits:
1779 public BitField<int, kBitsPerRegisterNumber, 1755 public BitField<int, kBitsPerRegisterNumber,
1780 kBitsPerRegisterNumber> {}; // NOLINT 1756 kBitsPerRegisterNumber> {}; // NOLINT
1781 class IsTruncatingBits: 1757 class IsTruncatingBits:
1782 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT 1758 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT
1783 class OffsetBits: 1759 class OffsetBits:
1784 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT 1760 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT
1785 class SkipFastPathBits: 1761 class SkipFastPathBits:
1786 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT 1762 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT
1787 class SSEBits:
1788 public BitField<int, 2 * kBitsPerRegisterNumber + 5, 2> {}; // NOLINT
1789 1763
1790 Major MajorKey() { return DoubleToI; } 1764 Major MajorKey() { return DoubleToI; }
1791 int MinorKey() { return bit_field_; } 1765 int MinorKey() { return bit_field_; }
1792 1766
1793 int bit_field_; 1767 int bit_field_;
1794 1768
1795 DISALLOW_COPY_AND_ASSIGN(DoubleToIStub); 1769 DISALLOW_COPY_AND_ASSIGN(DoubleToIStub);
1796 }; 1770 };
1797 1771
1798 1772
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 int MinorKey() { return 0; } 2319 int MinorKey() { return 0; }
2346 2320
2347 void Generate(MacroAssembler* masm); 2321 void Generate(MacroAssembler* masm);
2348 2322
2349 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub); 2323 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub);
2350 }; 2324 };
2351 2325
2352 } } // namespace v8::internal 2326 } } // namespace v8::internal
2353 2327
2354 #endif // V8_CODE_STUBS_H_ 2328 #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