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

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

Issue 18712002: Convert UnaryOpStub to a HydrogenCodeStub (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: address review Created 7 years, 5 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/arm/lithium-codegen-arm.cc ('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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 #endif 116 #endif
117 117
118 // Combined list of code stubs. 118 // Combined list of code stubs.
119 #define CODE_STUB_LIST(V) \ 119 #define CODE_STUB_LIST(V) \
120 CODE_STUB_LIST_ALL_PLATFORMS(V) \ 120 CODE_STUB_LIST_ALL_PLATFORMS(V) \
121 CODE_STUB_LIST_ARM(V) \ 121 CODE_STUB_LIST_ARM(V) \
122 CODE_STUB_LIST_MIPS(V) 122 CODE_STUB_LIST_MIPS(V)
123 123
124 // Mode to overwrite BinaryExpression values. 124 // Mode to overwrite BinaryExpression values.
125 enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT }; 125 enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT };
126 enum UnaryOverwriteMode { UNARY_OVERWRITE, UNARY_NO_OVERWRITE };
127
128 126
129 // Stub is base classes of all stubs. 127 // Stub is base classes of all stubs.
130 class CodeStub BASE_EMBEDDED { 128 class CodeStub BASE_EMBEDDED {
131 public: 129 public:
132 enum Major { 130 enum Major {
133 #define DEF_ENUM(name) name, 131 #define DEF_ENUM(name) name,
134 CODE_STUB_LIST(DEF_ENUM) 132 CODE_STUB_LIST(DEF_ENUM)
135 #undef DEF_ENUM 133 #undef DEF_ENUM
136 NoCache, // marker for stubs that do custom caching 134 NoCache, // marker for stubs that do custom caching
137 NUMBER_OF_IDS 135 NUMBER_OF_IDS
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 virtual Code::ExtraICState GetExtraICState() { 188 virtual Code::ExtraICState GetExtraICState() {
191 return Code::kNoExtraICState; 189 return Code::kNoExtraICState;
192 } 190 }
193 virtual Code::StubType GetStubType() { 191 virtual Code::StubType GetStubType() {
194 return Code::NORMAL; 192 return Code::NORMAL;
195 } 193 }
196 virtual int GetStubFlags() { 194 virtual int GetStubFlags() {
197 return -1; 195 return -1;
198 } 196 }
199 197
198 virtual void PrintName(StringStream* stream);
199
200 protected: 200 protected:
201 static bool CanUseFPRegisters(); 201 static bool CanUseFPRegisters();
202 202
203 // Generates the assembler code for the stub. 203 // Generates the assembler code for the stub.
204 virtual Handle<Code> GenerateCode() = 0; 204 virtual Handle<Code> GenerateCode() = 0;
205 205
206 206
207 // Returns whether the code generated for this stub needs to be allocated as 207 // Returns whether the code generated for this stub needs to be allocated as
208 // a fixed (non-moveable) code object. 208 // a fixed (non-moveable) code object.
209 virtual bool NeedsImmovableCode() { return false; } 209 virtual bool NeedsImmovableCode() { return false; }
210 210
211 // Returns a name for logging/debugging purposes.
212 SmartArrayPointer<const char> GetName();
213 virtual void PrintBaseName(StringStream* stream);
214 virtual void PrintState(StringStream* stream) { }
215
211 private: 216 private:
212 // Perform bookkeeping required after code generation when stub code is 217 // Perform bookkeeping required after code generation when stub code is
213 // initially generated. 218 // initially generated.
214 void RecordCodeGeneration(Code* code, Isolate* isolate); 219 void RecordCodeGeneration(Code* code, Isolate* isolate);
215 220
216 // Finish the code object after it has been generated. 221 // Finish the code object after it has been generated.
217 virtual void FinishCode(Handle<Code> code) { } 222 virtual void FinishCode(Handle<Code> code) { }
218 223
219 // Activate newly generated stub. Is called after 224 // Activate newly generated stub. Is called after
220 // registering stub in the stub cache. 225 // registering stub in the stub cache.
221 virtual void Activate(Code* code) { } 226 virtual void Activate(Code* code) { }
222 227
223 // BinaryOpStub needs to override this. 228 // BinaryOpStub needs to override this.
224 virtual Code::Kind GetCodeKind() const; 229 virtual Code::Kind GetCodeKind() const;
225 230
226 // Add the code to a specialized cache, specific to an individual 231 // Add the code to a specialized cache, specific to an individual
227 // stub type. Please note, this method must add the code object to a 232 // stub type. Please note, this method must add the code object to a
228 // roots object, otherwise we will remove the code during GC. 233 // roots object, otherwise we will remove the code during GC.
229 virtual void AddToSpecialCache(Handle<Code> new_object) { } 234 virtual void AddToSpecialCache(Handle<Code> new_object) { }
230 235
231 // Find code in a specialized cache, work is delegated to the specific stub. 236 // Find code in a specialized cache, work is delegated to the specific stub.
232 virtual bool FindCodeInSpecialCache(Code** code_out, Isolate* isolate) { 237 virtual bool FindCodeInSpecialCache(Code** code_out, Isolate* isolate) {
233 return false; 238 return false;
234 } 239 }
235 240
236 // If a stub uses a special cache override this. 241 // If a stub uses a special cache override this.
237 virtual bool UseSpecialCache() { return false; } 242 virtual bool UseSpecialCache() { return false; }
238 243
239 // Returns a name for logging/debugging purposes.
240 SmartArrayPointer<const char> GetName();
241 virtual void PrintName(StringStream* stream);
242
243 // Computes the key based on major and minor. 244 // Computes the key based on major and minor.
244 uint32_t GetKey() { 245 uint32_t GetKey() {
245 ASSERT(static_cast<int>(MajorKey()) < NUMBER_OF_IDS); 246 ASSERT(static_cast<int>(MajorKey()) < NUMBER_OF_IDS);
246 return MinorKeyBits::encode(MinorKey()) | 247 return MinorKeyBits::encode(MinorKey()) |
247 MajorKeyBits::encode(MajorKey()); 248 MajorKeyBits::encode(MajorKey());
248 } 249 }
249 250
250 class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {}; 251 class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {};
251 class MinorKeyBits: public BitField<uint32_t, 252 class MinorKeyBits: public BitField<uint32_t,
252 kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT 253 kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 Isolate* isolate, 348 Isolate* isolate,
348 CodeStubInterfaceDescriptor* descriptor) = 0; 349 CodeStubInterfaceDescriptor* descriptor) = 0;
349 350
350 // Retrieve the code for the stub. Generate the code if needed. 351 // Retrieve the code for the stub. Generate the code if needed.
351 virtual Handle<Code> GenerateCode() = 0; 352 virtual Handle<Code> GenerateCode() = 0;
352 353
353 virtual int NotMissMinorKey() = 0; 354 virtual int NotMissMinorKey() = 0;
354 355
355 Handle<Code> GenerateLightweightMissCode(Isolate* isolate); 356 Handle<Code> GenerateLightweightMissCode(Isolate* isolate);
356 357
358 template<class StateType>
359 void TraceTransition(StateType from, StateType to);
360
357 private: 361 private:
358 class MinorKeyBits: public BitField<int, 0, kStubMinorKeyBits - 1> {}; 362 class MinorKeyBits: public BitField<int, 0, kStubMinorKeyBits - 1> {};
359 class IsMissBits: public BitField<bool, kStubMinorKeyBits - 1, 1> {}; 363 class IsMissBits: public BitField<bool, kStubMinorKeyBits - 1, 1> {};
360 364
361 void GenerateLightweightMiss(MacroAssembler* masm); 365 void GenerateLightweightMiss(MacroAssembler* masm);
362 virtual int MinorKey() { 366 virtual int MinorKey() {
363 return IsMissBits::encode(is_uninitialized_) | 367 return IsMissBits::encode(is_uninitialized_) |
364 MinorKeyBits::encode(NotMissMinorKey()); 368 MinorKeyBits::encode(NotMissMinorKey());
365 } 369 }
366 370
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 void Generate(MacroAssembler* masm); 517 void Generate(MacroAssembler* masm);
514 518
515 private: 519 private:
516 int slots_; 520 int slots_;
517 521
518 Major MajorKey() { return FastNewBlockContext; } 522 Major MajorKey() { return FastNewBlockContext; }
519 int MinorKey() { return slots_; } 523 int MinorKey() { return slots_; }
520 }; 524 };
521 525
522 526
527 class UnaryOpStub : public HydrogenCodeStub {
528 public:
529 // Stub without type info available -> construct uninitialized
530 explicit UnaryOpStub(Token::Value operation)
531 : HydrogenCodeStub(UNINITIALIZED), operation_(operation) { }
532 explicit UnaryOpStub(Code::ExtraICState ic_state) :
533 state_(StateBits::decode(ic_state)),
534 operation_(OperatorBits::decode(ic_state)) { }
535
536 virtual void InitializeInterfaceDescriptor(
537 Isolate* isolate,
538 CodeStubInterfaceDescriptor* descriptor);
539
540 virtual Code::Kind GetCodeKind() const { return Code::UNARY_OP_IC; }
541 virtual InlineCacheState GetICState() {
542 if (state_.Contains(GENERIC)) {
543 return MEGAMORPHIC;
544 } else if (state_.IsEmpty()) {
545 return PREMONOMORPHIC;
546 } else {
547 return MONOMORPHIC;
548 }
549 }
550 virtual Code::ExtraICState GetExtraICState() {
551 return OperatorBits::encode(operation_) |
552 StateBits::encode(state_.ToIntegral());
553 }
554
555 Token::Value operation() { return operation_; }
556 Handle<JSFunction> ToJSFunction(Isolate* isolate);
557 Builtins::JavaScript ToJSBuiltin();
558
559 void UpdateStatus(Handle<Object> object);
560 MaybeObject* Result(Handle<Object> object, Isolate* isolate);
561 Handle<Code> GenerateCode();
562 Handle<Type> GetType(Isolate* isolate);
563
564 protected:
565 void PrintState(StringStream* stream);
566 void PrintBaseName(StringStream* stream);
567
568 private:
569 enum UnaryOpType {
570 SMI,
571 HEAP_NUMBER,
572 GENERIC,
573 NUMBER_OF_TYPES
574 };
575
576 class State : public EnumSet<UnaryOpType, byte> {
577 public:
578 State() : EnumSet<UnaryOpType, byte>() { }
579 explicit State(byte bits) : EnumSet<UnaryOpType, byte>(bits) { }
580 void Print(StringStream* stream) const;
581 };
582
583 class StateBits : public BitField<int, 0, NUMBER_OF_TYPES> { };
584 class OperatorBits : public BitField<Token::Value, NUMBER_OF_TYPES, 8> { };
585
586 State state_;
587 Token::Value operation_;
588
589 virtual CodeStub::Major MajorKey() { return UnaryOp; }
590 virtual int NotMissMinorKey() { return GetExtraICState(); }
591 };
592
593
523 class FastCloneShallowArrayStub : public HydrogenCodeStub { 594 class FastCloneShallowArrayStub : public HydrogenCodeStub {
524 public: 595 public:
525 // Maximum length of copied elements array. 596 // Maximum length of copied elements array.
526 static const int kMaximumClonedLength = 8; 597 static const int kMaximumClonedLength = 8;
527 enum Mode { 598 enum Mode {
528 CLONE_ELEMENTS, 599 CLONE_ELEMENTS,
529 CLONE_DOUBLE_ELEMENTS, 600 CLONE_DOUBLE_ELEMENTS,
530 COPY_ON_WRITE_ELEMENTS, 601 COPY_ON_WRITE_ELEMENTS,
531 CLONE_ANY_ELEMENTS, 602 CLONE_ANY_ELEMENTS,
532 LAST_CLONE_MODE = CLONE_ANY_ELEMENTS 603 LAST_CLONE_MODE = CLONE_ANY_ELEMENTS
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 static State Generic() { 1207 static State Generic() {
1137 State set; 1208 State set;
1138 set.Add(UNDEFINED); 1209 set.Add(UNDEFINED);
1139 set.Add(NULL_TYPE); 1210 set.Add(NULL_TYPE);
1140 set.Add(UNDETECTABLE); 1211 set.Add(UNDETECTABLE);
1141 set.Add(GENERIC); 1212 set.Add(GENERIC);
1142 return set; 1213 return set;
1143 } 1214 }
1144 1215
1145 void Print(StringStream* stream) const; 1216 void Print(StringStream* stream) const;
1146 void TraceTransition(State to) const;
1147 }; 1217 };
1148 1218
1149 static Handle<Type> StateToType( 1219 static Handle<Type> StateToType(
1150 Isolate* isolate, State state, Handle<Map> map = Handle<Map>()); 1220 Isolate* isolate, State state, Handle<Map> map = Handle<Map>());
1151 1221
1152 // At most 6 different types can be distinguished, because the Code object 1222 // At most 6 different types can be distinguished, because the Code object
1153 // only has room for a single byte to hold a set and there are two more 1223 // only has room for a single byte to hold a set and there are two more
1154 // boolean flags we need to store. :-P 1224 // boolean flags we need to store. :-P
1155 STATIC_ASSERT(NUMBER_OF_TYPES <= 6); 1225 STATIC_ASSERT(NUMBER_OF_TYPES <= 6);
1156 1226
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 virtual Code::ExtraICState GetExtraICState() { 1269 virtual Code::ExtraICState GetExtraICState() {
1200 return NilValueField::encode(nil_value_) | state_.ToIntegral(); 1270 return NilValueField::encode(nil_value_) | state_.ToIntegral();
1201 } 1271 }
1202 static byte ExtractTypesFromExtraICState(Code::ExtraICState state) { 1272 static byte ExtractTypesFromExtraICState(Code::ExtraICState state) {
1203 return state & ((1 << NUMBER_OF_TYPES) - 1); 1273 return state & ((1 << NUMBER_OF_TYPES) - 1);
1204 } 1274 }
1205 static NilValue ExtractNilValueFromExtraICState(Code::ExtraICState state) { 1275 static NilValue ExtractNilValueFromExtraICState(Code::ExtraICState state) {
1206 return NilValueField::decode(state); 1276 return NilValueField::decode(state);
1207 } 1277 }
1208 1278
1209 void Record(Handle<Object> object); 1279 void UpdateStatus(Handle<Object> object);
1210 1280
1211 bool IsMonomorphic() const { return state_.Contains(MONOMORPHIC_MAP); } 1281 bool IsMonomorphic() const { return state_.Contains(MONOMORPHIC_MAP); }
1212 NilValue GetNilValue() const { return nil_value_; } 1282 NilValue GetNilValue() const { return nil_value_; }
1213 State GetState() const { return state_; } 1283 State GetState() const { return state_; }
1214 void ClearState() { state_.RemoveAll(); } 1284 void ClearState() { state_.RemoveAll(); }
1215 1285
1216 virtual void PrintName(StringStream* stream); 1286 virtual void PrintState(StringStream* stream);
1287 virtual void PrintBaseName(StringStream* stream);
1217 1288
1218 private: 1289 private:
1219 friend class CompareNilIC; 1290 friend class CompareNilIC;
1220 1291
1221 CompareNilICStub(NilValue nil, InitializationState init_state) 1292 CompareNilICStub(NilValue nil, InitializationState init_state)
1222 : HydrogenCodeStub(init_state) { 1293 : HydrogenCodeStub(init_state) {
1223 nil_value_ = nil; 1294 nil_value_ = nil;
1224 } 1295 }
1225 1296
1226 class NilValueField : public BitField<NilValue, NUMBER_OF_TYPES, 1> {}; 1297 class NilValueField : public BitField<NilValue, NUMBER_OF_TYPES, 1> {};
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 // only has room for a single byte to hold a set of these types. :-P 2073 // only has room for a single byte to hold a set of these types. :-P
2003 STATIC_ASSERT(NUMBER_OF_TYPES <= 8); 2074 STATIC_ASSERT(NUMBER_OF_TYPES <= 8);
2004 2075
2005 class Types : public EnumSet<Type, byte> { 2076 class Types : public EnumSet<Type, byte> {
2006 public: 2077 public:
2007 Types() : EnumSet<Type, byte>(0) {} 2078 Types() : EnumSet<Type, byte>(0) {}
2008 explicit Types(byte bits) : EnumSet<Type, byte>(bits) {} 2079 explicit Types(byte bits) : EnumSet<Type, byte>(bits) {}
2009 2080
2010 byte ToByte() const { return ToIntegral(); } 2081 byte ToByte() const { return ToIntegral(); }
2011 void Print(StringStream* stream) const; 2082 void Print(StringStream* stream) const;
2012 void TraceTransition(Types to) const; 2083 bool UpdateStatus(Handle<Object> object);
2013 bool Record(Handle<Object> object);
2014 bool NeedsMap() const; 2084 bool NeedsMap() const;
2015 bool CanBeUndetectable() const; 2085 bool CanBeUndetectable() const;
2016 bool IsGeneric() const { return ToIntegral() == Generic().ToIntegral(); } 2086 bool IsGeneric() const { return ToIntegral() == Generic().ToIntegral(); }
2017 2087
2018 static Types Generic() { return Types((1 << NUMBER_OF_TYPES) - 1); } 2088 static Types Generic() { return Types((1 << NUMBER_OF_TYPES) - 1); }
2019 }; 2089 };
2020 2090
2021 explicit ToBooleanStub(Types types = Types()) 2091 explicit ToBooleanStub(Types types = Types())
2022 : types_(types) { } 2092 : types_(types) { }
2023 explicit ToBooleanStub(Code::ExtraICState state) 2093 explicit ToBooleanStub(Code::ExtraICState state)
2024 : types_(static_cast<byte>(state)) { } 2094 : types_(static_cast<byte>(state)) { }
2025 2095
2026 bool Record(Handle<Object> object); 2096 bool UpdateStatus(Handle<Object> object);
2027 Types GetTypes() { return types_; } 2097 Types GetTypes() { return types_; }
2028 2098
2029 virtual Handle<Code> GenerateCode(); 2099 virtual Handle<Code> GenerateCode();
2030 virtual void InitializeInterfaceDescriptor( 2100 virtual void InitializeInterfaceDescriptor(
2031 Isolate* isolate, 2101 Isolate* isolate,
2032 CodeStubInterfaceDescriptor* descriptor); 2102 CodeStubInterfaceDescriptor* descriptor);
2033 2103
2034 virtual Code::Kind GetCodeKind() const { return Code::TO_BOOLEAN_IC; } 2104 virtual Code::Kind GetCodeKind() const { return Code::TO_BOOLEAN_IC; }
2035 virtual void PrintName(StringStream* stream); 2105 virtual void PrintState(StringStream* stream);
2036 2106
2037 virtual bool SometimesSetsUpAFrame() { return false; } 2107 virtual bool SometimesSetsUpAFrame() { return false; }
2038 2108
2039 static void InitializeForIsolate(Isolate* isolate) { 2109 static void InitializeForIsolate(Isolate* isolate) {
2040 ToBooleanStub stub; 2110 ToBooleanStub stub;
2041 stub.InitializeInterfaceDescriptor( 2111 stub.InitializeInterfaceDescriptor(
2042 isolate, 2112 isolate,
2043 isolate->code_stub_interface_descriptor(CodeStub::ToBoolean)); 2113 isolate->code_stub_interface_descriptor(CodeStub::ToBoolean));
2044 } 2114 }
2045 2115
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2176 int MinorKey() { return 0; } 2246 int MinorKey() { return 0; }
2177 2247
2178 void Generate(MacroAssembler* masm); 2248 void Generate(MacroAssembler* masm);
2179 2249
2180 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub); 2250 DISALLOW_COPY_AND_ASSIGN(ProfileEntryHookStub);
2181 }; 2251 };
2182 2252
2183 } } // namespace v8::internal 2253 } } // namespace v8::internal
2184 2254
2185 #endif // V8_CODE_STUBS_H_ 2255 #endif // V8_CODE_STUBS_H_
OLDNEW
« no previous file with comments | « src/arm/lithium-codegen-arm.cc ('k') | src/code-stubs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698