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

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

Issue 23618002: Hydrogenisation of binops (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 7 years, 3 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 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 Isolate* isolate, 977 Isolate* isolate,
977 CodeStubInterfaceDescriptor* descriptor); 978 CodeStubInterfaceDescriptor* descriptor);
978 979
979 virtual Handle<Code> GenerateCode(Isolate* isolate); 980 virtual Handle<Code> GenerateCode(Isolate* isolate);
980 981
981 private: 982 private:
982 virtual CodeStub::Major MajorKey() { return KeyedLoadField; } 983 virtual CodeStub::Major MajorKey() { return KeyedLoadField; }
983 }; 984 };
984 985
985 986
986 class BinaryOpStub: public PlatformCodeStub { 987 class BinaryOpStub: public HydrogenCodeStub {
987 public: 988 public:
988 BinaryOpStub(Token::Value op, OverwriteMode mode) 989 explicit BinaryOpStub(Token::Value op) : HydrogenCodeStub(UNINITIALIZED),
989 : op_(op), 990 op_(op) {
990 mode_(mode), 991 ASSERT(op <= LAST_TOKEN && op >= FIRST_TOKEN);
991 platform_specific_bit_(false), 992 init();
992 left_type_(BinaryOpIC::UNINITIALIZED),
993 right_type_(BinaryOpIC::UNINITIALIZED),
994 result_type_(BinaryOpIC::UNINITIALIZED),
995 encoded_right_arg_(false, encode_arg_value(1)) {
996 Initialize();
997 ASSERT(OpBits::is_valid(Token::NUM_TOKENS));
998 } 993 }
999 994
1000 BinaryOpStub( 995 explicit BinaryOpStub(Code::ExtraICState state)
1001 int key, 996 : op_(decode_token(OpBits::decode(state))),
1002 BinaryOpIC::TypeInfo left_type, 997 fixed_right_arg_(
1003 BinaryOpIC::TypeInfo right_type, 998 Maybe<int>(HasFixedRightArgBits::decode(state),
1004 BinaryOpIC::TypeInfo result_type, 999 decode_arg_value(FixedRightArgValueBits::decode(state)))),
1005 Maybe<int32_t> fixed_right_arg) 1000 left_state_(LeftStateField::decode(state)),
1006 : op_(OpBits::decode(key)), 1001 left_oddball_state_(LeftOddballStateField::decode(state)),
1007 mode_(ModeBits::decode(key)), 1002 right_state_(fixed_right_arg_.has_value
1008 platform_specific_bit_(PlatformSpecificBits::decode(key)), 1003 ? ((fixed_right_arg_.value <= Smi::kMaxValue) ? SMI : INT32)
1009 left_type_(left_type), 1004 : RightStateField::decode(state)),
1010 right_type_(right_type), 1005 right_oddball_state_(fixed_right_arg_.has_value
1011 result_type_(result_type), 1006 ? NO_ODDBALL : RightOddballStateField::decode(state)),
1012 encoded_right_arg_(fixed_right_arg.has_value, 1007 result_state_(ResultStateField::decode(state)) {
1013 encode_arg_value(fixed_right_arg.value)) { } 1008 // We don't deserialize the SSE2 Field, since this is only used to be able
1014 1009 // to include SSE2 as well as non-SSE2 versions in the snapshot. For code
1015 static void decode_types_from_minor_key(int minor_key, 1010 // generation we always want it to reflect the current state.
1016 BinaryOpIC::TypeInfo* left_type, 1011 ASSERT(!fixed_right_arg_.has_value ||
1017 BinaryOpIC::TypeInfo* right_type, 1012 can_encode_arg_value(fixed_right_arg_.value));
1018 BinaryOpIC::TypeInfo* result_type) {
1019 *left_type =
1020 static_cast<BinaryOpIC::TypeInfo>(LeftTypeBits::decode(minor_key));
1021 *right_type =
1022 static_cast<BinaryOpIC::TypeInfo>(RightTypeBits::decode(minor_key));
1023 *result_type =
1024 static_cast<BinaryOpIC::TypeInfo>(ResultTypeBits::decode(minor_key));
1025 } 1013 }
1026 1014
1027 static Token::Value decode_op_from_minor_key(int minor_key) { 1015 static const int FIRST_TOKEN = Token::BIT_OR;
1028 return static_cast<Token::Value>(OpBits::decode(minor_key)); 1016 static const int LAST_TOKEN = Token::MOD;
1017
1018 static void GenerateAheadOfTime(Isolate* isolate);
1019 virtual void InitializeInterfaceDescriptor(
1020 Isolate* isolate, CodeStubInterfaceDescriptor* descriptor);
1021
1022 virtual Code::Kind GetCodeKind() const { return Code::BINARY_OP_IC; }
1023 virtual InlineCacheState GetICState() {
1024 if (Max(left_state_, right_state_) == NONE &&
1025 Max(left_oddball_state_, right_oddball_state_) == NO_ODDBALL) {
1026 return ::v8::internal::UNINITIALIZED;
1027 }
1028 if (Max(left_state_, right_state_) == GENERIC) return MEGAMORPHIC;
1029 return MONOMORPHIC;
1029 } 1030 }
1030 1031
1031 static Maybe<int> decode_fixed_right_arg_from_minor_key(int minor_key) { 1032 virtual Code::ExtraICState GetExtraICState() {
1032 return Maybe<int>( 1033 bool sse_field = Max(result_state_, Max(left_state_, right_state_)) > SMI &&
1033 HasFixedRightArgBits::decode(minor_key), 1034 CpuFeatures::IsSafeForSnapshot(SSE2);
1034 decode_arg_value(FixedRightArgValueBits::decode(minor_key))); 1035
1036 return OpBits::encode(encode_token(op_))
1037 | LeftStateField::encode(left_state_)
1038 | LeftOddballStateField::encode(left_oddball_state_)
1039 | RightStateField::encode(fixed_right_arg_.has_value
1040 ? NONE : right_state_)
1041 | RightOddballStateField::encode(fixed_right_arg_.has_value
1042 ? NO_ODDBALL
1043 : right_oddball_state_)
1044 | ResultStateField::encode(result_state_)
1045 | HasFixedRightArgBits::encode(fixed_right_arg_.has_value)
1046 | FixedRightArgValueBits::encode(fixed_right_arg_.has_value
1047 ? encode_arg_value(
1048 fixed_right_arg_.value)
1049 : 0)
1050 | SSE2Field::encode(sse_field);
1035 } 1051 }
1036 1052
1037 int fixed_right_arg_value() const { 1053 virtual Handle<Code> GenerateCode(Isolate* isolate);
1038 return decode_arg_value(encoded_right_arg_.value); 1054
1055 Maybe<Handle<Object> > Result(Handle<Object> left,
1056 Handle<Object> right,
1057 Isolate* isolate);
1058
1059 Token::Value operation() { return op_; }
1060 Maybe<int> fixed_right_arg() { return fixed_right_arg_; }
1061
1062 Handle<Type> GetLeftType(Isolate* isolate) const;
1063 Handle<Type> GetRightType(Isolate* isolate) const;
1064 Handle<Type> GetResultType(Isolate* isolate) const;
1065
1066 bool HasSideEffects(Isolate* isolate) const {
1067 return GetLeftType(isolate)->Maybe(Type::Receiver()) ||
1068 GetRightType(isolate)->Maybe(Type::Receiver());
1039 } 1069 }
1040 1070
1041 static bool can_encode_arg_value(int32_t value) { 1071 void UpdateStatus(Handle<Object> left,
1042 return value > 0 && 1072 Handle<Object> right,
1043 IsPowerOf2(value) && 1073 Maybe<Handle<Object> > result);
1044 FixedRightArgValueBits::is_valid(WhichPowerOf2(value)); 1074
1075 void PrintState(StringStream* stream);
1076
1077 private:
1078 explicit BinaryOpStub(InitializationState state) : HydrogenCodeStub(state),
1079 op_(Token::ADD) {
1080 init();
1081 }
1082 void init();
1083
1084 static void GenerateAheadOfTimeAllOps(Isolate* isolate, BinaryOpStub stub);
1085
1086 enum State { NONE, SMI, INT32, NUMBER, STRING, GENERIC };
1087 enum OddballState { NO_ODDBALL, BOOLEAN, NULL_VALUE, BOOLEN_AND_NULL };
1088
1089 // We truncate the last bit of the token.
1090 STATIC_ASSERT(LAST_TOKEN - FIRST_TOKEN < (1 << 5));
1091 class OpBits: public BitField<int, 0, 5> {};
1092 class LeftStateField: public BitField<State, 5, 3> {};
1093 class LeftOddballStateField: public BitField<OddballState, 8, 2> {};
1094 class ResultStateField: public BitField<State, 16, 3> {};
1095 // When fixed right arg is set, we don't need to store the right state.
1096 // Thus the two fields can overlap.
1097 class HasFixedRightArgBits: public BitField<bool, 10, 1> {};
1098 class FixedRightArgValueBits: public BitField<int, 11, 5> {};
1099 class RightStateField: public BitField<State, 11, 3> {};
1100 class RightOddballStateField: public BitField<OddballState, 14, 2> {};
1101 class SSE2Field: public BitField<bool, 19, 1> {};
1102
1103 virtual CodeStub::Major MajorKey() { return BinaryOp; }
1104 virtual int NotMissMinorKey() { return GetExtraICState(); }
1105
1106 static Handle<Type> StateToType(State state,
1107 OddballState oddball_state,
1108 Isolate* isolate);
1109
1110 void UpdateStatus(Handle<Object> object,
1111 State* state,
1112 OddballState* oddball_state = NULL);
1113
1114 bool can_encode_arg_value(int32_t value) const;
1115 int encode_arg_value(int32_t value) const;
1116 int32_t decode_arg_value(int value) const;
1117 int encode_token(Token::Value op) const;
1118 Token::Value decode_token(int op) const;
1119
1120 bool has_int_result() const {
1121 return op_ == Token::BIT_XOR || op_ == Token::BIT_AND ||
1122 op_ == Token::BIT_OR || op_ == Token::SAR;
1045 } 1123 }
1046 1124
1047 enum SmiCodeGenerateHeapNumberResults { 1125 const char* StateToName(State state);
1048 ALLOW_HEAPNUMBER_RESULTS, 1126 const char* OddballStateToName(OddballState state);
1049 NO_HEAPNUMBER_RESULTS
1050 };
1051 1127
1052 private: 1128 void PrintBaseName(StringStream* stream);
1129
1053 Token::Value op_; 1130 Token::Value op_;
1054 OverwriteMode mode_;
1055 bool platform_specific_bit_; // Indicates SSE3 on IA32.
1056 1131
1057 // Operand type information determined at runtime. 1132 Maybe<int> fixed_right_arg_;
1058 BinaryOpIC::TypeInfo left_type_; 1133 State left_state_;
1059 BinaryOpIC::TypeInfo right_type_; 1134 OddballState left_oddball_state_;
1060 BinaryOpIC::TypeInfo result_type_; 1135 State right_state_;
1061 1136 OddballState right_oddball_state_;
1062 Maybe<int> encoded_right_arg_; 1137 State result_state_;
1063
1064 static int encode_arg_value(int32_t value) {
1065 ASSERT(can_encode_arg_value(value));
1066 return WhichPowerOf2(value);
1067 }
1068
1069 static int32_t decode_arg_value(int value) {
1070 return 1 << value;
1071 }
1072
1073 virtual void PrintName(StringStream* stream);
1074
1075 // Minor key encoding in all 25 bits FFFFFHTTTRRRLLLPOOOOOOOMM.
1076 // Note: We actually do not need 7 bits for the operation, just 4 bits to
1077 // encode ADD, SUB, MUL, DIV, MOD, BIT_OR, BIT_AND, BIT_XOR, SAR, SHL, SHR.
1078 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
1079 class OpBits: public BitField<Token::Value, 2, 7> {};
1080 class PlatformSpecificBits: public BitField<bool, 9, 1> {};
1081 class LeftTypeBits: public BitField<BinaryOpIC::TypeInfo, 10, 3> {};
1082 class RightTypeBits: public BitField<BinaryOpIC::TypeInfo, 13, 3> {};
1083 class ResultTypeBits: public BitField<BinaryOpIC::TypeInfo, 16, 3> {};
1084 class HasFixedRightArgBits: public BitField<bool, 19, 1> {};
1085 class FixedRightArgValueBits: public BitField<int, 20, 5> {};
1086
1087 Major MajorKey() { return BinaryOp; }
1088 int MinorKey() {
1089 return OpBits::encode(op_)
1090 | ModeBits::encode(mode_)
1091 | PlatformSpecificBits::encode(platform_specific_bit_)
1092 | LeftTypeBits::encode(left_type_)
1093 | RightTypeBits::encode(right_type_)
1094 | ResultTypeBits::encode(result_type_)
1095 | HasFixedRightArgBits::encode(encoded_right_arg_.has_value)
1096 | FixedRightArgValueBits::encode(encoded_right_arg_.value);
1097 }
1098
1099
1100 // Platform-independent implementation.
1101 void Generate(MacroAssembler* masm);
1102 void GenerateCallRuntime(MacroAssembler* masm);
1103
1104 // Platform-independent signature, platform-specific implementation.
1105 void Initialize();
1106 void GenerateAddStrings(MacroAssembler* masm);
1107 void GenerateBothStringStub(MacroAssembler* masm);
1108 void GenerateGeneric(MacroAssembler* masm);
1109 void GenerateGenericStub(MacroAssembler* masm);
1110 void GenerateNumberStub(MacroAssembler* masm);
1111 void GenerateInt32Stub(MacroAssembler* masm);
1112 void GenerateLoadArguments(MacroAssembler* masm);
1113 void GenerateOddballStub(MacroAssembler* masm);
1114 void GenerateRegisterArgsPush(MacroAssembler* masm);
1115 void GenerateReturn(MacroAssembler* masm);
1116 void GenerateSmiStub(MacroAssembler* masm);
1117 void GenerateStringStub(MacroAssembler* masm);
1118 void GenerateTypeTransition(MacroAssembler* masm);
1119 void GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm);
1120 void GenerateUninitializedStub(MacroAssembler* masm);
1121
1122 // Entirely platform-specific methods are defined as static helper
1123 // functions in the <arch>/code-stubs-<arch>.cc files.
1124
1125 virtual Code::Kind GetCodeKind() const { return Code::BINARY_OP_IC; }
1126
1127 virtual InlineCacheState GetICState() {
1128 return BinaryOpIC::ToState(Max(left_type_, right_type_));
1129 }
1130
1131 virtual void FinishCode(Handle<Code> code) {
1132 code->set_stub_info(MinorKey());
1133 }
1134
1135 friend class CodeGenerator;
1136 }; 1138 };
1137 1139
1138 1140
1139 class ICCompareStub: public PlatformCodeStub { 1141 class ICCompareStub: public PlatformCodeStub {
1140 public: 1142 public:
1141 ICCompareStub(Token::Value op, 1143 ICCompareStub(Token::Value op,
1142 CompareIC::State left, 1144 CompareIC::State left,
1143 CompareIC::State right, 1145 CompareIC::State right,
1144 CompareIC::State handler) 1146 CompareIC::State handler)
1145 : op_(op), 1147 : op_(op),
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 public: 1700 public:
1699 DoubleToIStub(Register source, 1701 DoubleToIStub(Register source,
1700 Register destination, 1702 Register destination,
1701 int offset, 1703 int offset,
1702 bool is_truncating, 1704 bool is_truncating,
1703 bool skip_fastpath = false) : bit_field_(0) { 1705 bool skip_fastpath = false) : bit_field_(0) {
1704 bit_field_ = SourceRegisterBits::encode(source.code_) | 1706 bit_field_ = SourceRegisterBits::encode(source.code_) |
1705 DestinationRegisterBits::encode(destination.code_) | 1707 DestinationRegisterBits::encode(destination.code_) |
1706 OffsetBits::encode(offset) | 1708 OffsetBits::encode(offset) |
1707 IsTruncatingBits::encode(is_truncating) | 1709 IsTruncatingBits::encode(is_truncating) |
1708 SkipFastPathBits::encode(skip_fastpath); 1710 SkipFastPathBits::encode(skip_fastpath) |
1711 SSEBits::encode(CpuFeatures::IsSafeForSnapshot(SSE2) ?
1712 CpuFeatures::IsSafeForSnapshot(SSE3) ? 2 : 1 : 0);
1709 } 1713 }
1710 1714
1711 Register source() { 1715 Register source() {
1712 Register result = { SourceRegisterBits::decode(bit_field_) }; 1716 Register result = { SourceRegisterBits::decode(bit_field_) };
1713 return result; 1717 return result;
1714 } 1718 }
1715 1719
1716 Register destination() { 1720 Register destination() {
1717 Register result = { DestinationRegisterBits::decode(bit_field_) }; 1721 Register result = { DestinationRegisterBits::decode(bit_field_) };
1718 return result; 1722 return result;
(...skipping 22 matching lines...) Expand all
1741 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT 1745 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT
1742 class DestinationRegisterBits: 1746 class DestinationRegisterBits:
1743 public BitField<int, kBitsPerRegisterNumber, 1747 public BitField<int, kBitsPerRegisterNumber,
1744 kBitsPerRegisterNumber> {}; // NOLINT 1748 kBitsPerRegisterNumber> {}; // NOLINT
1745 class IsTruncatingBits: 1749 class IsTruncatingBits:
1746 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT 1750 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT
1747 class OffsetBits: 1751 class OffsetBits:
1748 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT 1752 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT
1749 class SkipFastPathBits: 1753 class SkipFastPathBits:
1750 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT 1754 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT
1755 class SSEBits:
1756 public BitField<int, 2 * kBitsPerRegisterNumber + 5, 2> {}; // NOLINT
1751 1757
1752 Major MajorKey() { return DoubleToI; } 1758 Major MajorKey() { return DoubleToI; }
1753 int MinorKey() { return bit_field_; } 1759 int MinorKey() { return bit_field_; }
1754 1760
1755 int bit_field_; 1761 int bit_field_;
1756 1762
1757 DISALLOW_COPY_AND_ASSIGN(DoubleToIStub); 1763 DISALLOW_COPY_AND_ASSIGN(DoubleToIStub);
1758 }; 1764 };
1759 1765
1760 1766
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 int MinorKey() { return 0; } 2313 int MinorKey() { return 0; }
2308 2314
2309 void Generate(MacroAssembler* masm); 2315 void Generate(MacroAssembler* masm);
2310 2316
2311 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub); 2317 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub);
2312 }; 2318 };
2313 2319
2314 } } // namespace v8::internal 2320 } } // namespace v8::internal
2315 2321
2316 #endif // V8_CODE_STUBS_H_ 2322 #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