blob: 85b0883db849033869eae4c5df248d9f907d7c83 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_CODE_STUBS_H_
6#define V8_CODE_STUBS_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/allocation.h"
9#include "src/assembler.h"
Ben Murdochc5610432016-08-08 18:44:38 +010010#include "src/code-stub-assembler.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#include "src/codegen.h"
12#include "src/globals.h"
13#include "src/ic/ic-state.h"
14#include "src/interface-descriptors.h"
15#include "src/macro-assembler.h"
16#include "src/ostreams.h"
Steve Block6ded16b2010-05-10 14:33:55 +010017
Steve Blocka7e24c12009-10-30 11:49:00 +000018namespace v8 {
19namespace internal {
20
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000021// List of code stubs used on all platforms.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000022#define CODE_STUB_LIST_ALL_PLATFORMS(V) \
23 /* PlatformCodeStubs */ \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000024 V(ArrayConstructor) \
25 V(BinaryOpICWithAllocationSite) \
Ben Murdochda12d292016-06-02 14:46:10 +010026 V(CallApiCallback) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027 V(CallApiGetter) \
28 V(CallConstruct) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000029 V(CallIC) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030 V(CEntry) \
31 V(CompareIC) \
32 V(DoubleToI) \
33 V(FunctionPrototype) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000034 V(InternalArrayConstructor) \
35 V(JSEntry) \
36 V(KeyedLoadICTrampoline) \
37 V(LoadICTrampoline) \
Ben Murdoch61f157c2016-09-16 13:49:30 +010038 V(LoadGlobalICTrampoline) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000039 V(CallICTrampoline) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -040040 V(LoadIndexedString) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000041 V(MathPow) \
42 V(ProfileEntryHook) \
43 V(RecordWrite) \
44 V(RegExpExec) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045 V(StoreBufferOverflow) \
46 V(StoreElement) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000047 V(StubFailureTrampoline) \
48 V(SubString) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000049 V(ToString) \
Ben Murdoch097c5b22016-05-18 11:27:45 +010050 V(ToName) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000051 V(ToObject) \
52 V(VectorStoreICTrampoline) \
53 V(VectorKeyedStoreICTrampoline) \
54 V(VectorStoreIC) \
55 V(VectorKeyedStoreIC) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056 /* HydrogenCodeStubs */ \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000057 V(BinaryOpIC) \
58 V(BinaryOpWithAllocationSite) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059 V(CreateAllocationSite) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000060 V(CreateWeakCell) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000061 V(ElementsTransitionAndStore) \
Ben Murdochda12d292016-06-02 14:46:10 +010062 V(FastArrayPush) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000063 V(FastCloneRegExp) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000064 V(FastCloneShallowArray) \
Ben Murdoch61f157c2016-09-16 13:49:30 +010065 V(FastFunctionBind) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066 V(FastNewClosure) \
67 V(FastNewContext) \
Ben Murdoch097c5b22016-05-18 11:27:45 +010068 V(FastNewObject) \
69 V(FastNewRestParameter) \
70 V(FastNewSloppyArguments) \
71 V(FastNewStrictArguments) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000072 V(GrowArrayElements) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000073 V(KeyedLoadGeneric) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -040074 V(LoadScriptContextField) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000075 V(LoadDictionaryElement) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000076 V(NameDictionaryLookup) \
77 V(NumberToString) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000078 V(Typeof) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079 V(RegExpConstructResult) \
80 V(StoreFastElement) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000081 V(StoreGlobalViaContext) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -040082 V(StoreScriptContextField) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000083 V(StringAdd) \
Ben Murdochda12d292016-06-02 14:46:10 +010084 V(ToBooleanIC) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000085 V(TransitionElementsKind) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000086 V(KeyedLoadIC) \
87 V(LoadIC) \
Ben Murdoch61f157c2016-09-16 13:49:30 +010088 V(LoadGlobalIC) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000089 /* TurboFanCodeStubs */ \
Ben Murdochda12d292016-06-02 14:46:10 +010090 V(AllocateHeapNumber) \
Ben Murdochda12d292016-06-02 14:46:10 +010091 V(AllocateFloat32x4) \
92 V(AllocateInt32x4) \
93 V(AllocateUint32x4) \
94 V(AllocateBool32x4) \
95 V(AllocateInt16x8) \
96 V(AllocateUint16x8) \
97 V(AllocateBool16x8) \
98 V(AllocateInt8x16) \
99 V(AllocateUint8x16) \
100 V(AllocateBool8x16) \
Ben Murdochc5610432016-08-08 18:44:38 +0100101 V(ArrayNoArgumentConstructor) \
Ben Murdoch61f157c2016-09-16 13:49:30 +0100102 V(ArraySingleArgumentConstructor) \
103 V(ArrayNArgumentsConstructor) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000104 V(StringLength) \
Ben Murdochda12d292016-06-02 14:46:10 +0100105 V(Add) \
106 V(Subtract) \
Ben Murdochc5610432016-08-08 18:44:38 +0100107 V(Multiply) \
108 V(Divide) \
109 V(Modulus) \
110 V(ShiftRight) \
111 V(ShiftRightLogical) \
112 V(ShiftLeft) \
Ben Murdochda12d292016-06-02 14:46:10 +0100113 V(BitwiseAnd) \
114 V(BitwiseOr) \
115 V(BitwiseXor) \
Ben Murdochc5610432016-08-08 18:44:38 +0100116 V(Inc) \
117 V(InternalArrayNoArgumentConstructor) \
Ben Murdoch61f157c2016-09-16 13:49:30 +0100118 V(InternalArraySingleArgumentConstructor) \
Ben Murdochc5610432016-08-08 18:44:38 +0100119 V(Dec) \
120 V(FastCloneShallowObject) \
121 V(InstanceOf) \
Ben Murdochda12d292016-06-02 14:46:10 +0100122 V(LessThan) \
123 V(LessThanOrEqual) \
124 V(GreaterThan) \
125 V(GreaterThanOrEqual) \
126 V(Equal) \
127 V(NotEqual) \
128 V(StrictEqual) \
129 V(StrictNotEqual) \
130 V(StringEqual) \
131 V(StringNotEqual) \
132 V(StringLessThan) \
133 V(StringLessThanOrEqual) \
134 V(StringGreaterThan) \
135 V(StringGreaterThanOrEqual) \
136 V(ToBoolean) \
137 V(ToInteger) \
138 V(ToLength) \
Ben Murdochc5610432016-08-08 18:44:38 +0100139 V(HasProperty) \
Ben Murdoch61f157c2016-09-16 13:49:30 +0100140 V(LoadICTrampolineTF) \
141 V(LoadICTF) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000142 /* IC Handler stubs */ \
Ben Murdochc5610432016-08-08 18:44:38 +0100143 V(KeyedLoadSloppyArguments) \
144 V(KeyedStoreSloppyArguments) \
145 V(LoadApiGetter) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000146 V(LoadConstant) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000147 V(LoadFastElement) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000148 V(LoadField) \
Ben Murdochda12d292016-06-02 14:46:10 +0100149 V(LoadIndexedInterceptor) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000150 V(StoreField) \
151 V(StoreGlobal) \
Ben Murdochc5610432016-08-08 18:44:38 +0100152 V(StoreInterceptor) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000153 V(StoreTransition)
Steve Blockd0582a62009-12-15 09:54:21 +0000154
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000155// List of code stubs only used on ARM 32 bits platforms.
156#if V8_TARGET_ARCH_ARM
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400157#define CODE_STUB_LIST_ARM(V) V(DirectCEntry)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000158
Steve Blockd0582a62009-12-15 09:54:21 +0000159#else
160#define CODE_STUB_LIST_ARM(V)
161#endif
162
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000163// List of code stubs only used on ARM 64 bits platforms.
164#if V8_TARGET_ARCH_ARM64
165#define CODE_STUB_LIST_ARM64(V) \
166 V(DirectCEntry) \
167 V(RestoreRegistersState) \
168 V(StoreRegistersState)
169
170#else
171#define CODE_STUB_LIST_ARM64(V)
172#endif
173
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000174// List of code stubs only used on PPC platforms.
175#ifdef V8_TARGET_ARCH_PPC
176#define CODE_STUB_LIST_PPC(V) \
177 V(DirectCEntry) \
178 V(StoreRegistersState) \
179 V(RestoreRegistersState)
180#else
181#define CODE_STUB_LIST_PPC(V)
182#endif
183
Steve Block44f0eee2011-05-26 01:26:41 +0100184// List of code stubs only used on MIPS platforms.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000185#if V8_TARGET_ARCH_MIPS
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400186#define CODE_STUB_LIST_MIPS(V) \
187 V(DirectCEntry) \
188 V(RestoreRegistersState) \
189 V(StoreRegistersState)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000190#elif V8_TARGET_ARCH_MIPS64
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400191#define CODE_STUB_LIST_MIPS(V) \
192 V(DirectCEntry) \
193 V(RestoreRegistersState) \
194 V(StoreRegistersState)
Steve Block44f0eee2011-05-26 01:26:41 +0100195#else
196#define CODE_STUB_LIST_MIPS(V)
197#endif
198
Ben Murdochda12d292016-06-02 14:46:10 +0100199// List of code stubs only used on S390 platforms.
200#ifdef V8_TARGET_ARCH_S390
201#define CODE_STUB_LIST_S390(V) \
202 V(DirectCEntry) \
203 V(StoreRegistersState) \
204 V(RestoreRegistersState)
205#else
206#define CODE_STUB_LIST_S390(V)
207#endif
208
Steve Blockd0582a62009-12-15 09:54:21 +0000209// Combined list of code stubs.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000210#define CODE_STUB_LIST(V) \
211 CODE_STUB_LIST_ALL_PLATFORMS(V) \
212 CODE_STUB_LIST_ARM(V) \
213 CODE_STUB_LIST_ARM64(V) \
214 CODE_STUB_LIST_PPC(V) \
Ben Murdochda12d292016-06-02 14:46:10 +0100215 CODE_STUB_LIST_MIPS(V) \
216 CODE_STUB_LIST_S390(V)
Steve Blocka7e24c12009-10-30 11:49:00 +0000217
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000218static const int kHasReturnedMinusZeroSentinel = 1;
219
Steve Blocka7e24c12009-10-30 11:49:00 +0000220// Stub is base classes of all stubs.
221class CodeStub BASE_EMBEDDED {
222 public:
223 enum Major {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400224 // TODO(mvstanton): eliminate the NoCache key by getting rid
225 // of the non-monomorphic-cache.
226 NoCache = 0, // marker for stubs that do custom caching]
Steve Blockd0582a62009-12-15 09:54:21 +0000227#define DEF_ENUM(name) name,
228 CODE_STUB_LIST(DEF_ENUM)
229#undef DEF_ENUM
Steve Blocka7e24c12009-10-30 11:49:00 +0000230 NUMBER_OF_IDS
231 };
232
233 // Retrieve the code for the stub. Generate the code if needed.
234 Handle<Code> GetCode();
235
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000236 // Retrieve the code for the stub, make and return a copy of the code.
237 Handle<Code> GetCodeCopy(const Code::FindAndReplacePattern& pattern);
238
Steve Blocka7e24c12009-10-30 11:49:00 +0000239 static Major MajorKeyFromKey(uint32_t key) {
240 return static_cast<Major>(MajorKeyBits::decode(key));
Iain Merrick9ac36c92010-09-13 15:29:50 +0100241 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000242 static uint32_t MinorKeyFromKey(uint32_t key) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000243 return MinorKeyBits::decode(key);
Iain Merrick9ac36c92010-09-13 15:29:50 +0100244 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100245
246 // Gets the major key from a code object that is a code stub or binary op IC.
247 static Major GetMajorKey(Code* code_stub) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000248 return MajorKeyFromKey(code_stub->stub_key());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100249 }
250
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000251 static uint32_t NoCacheKey() { return MajorKeyBits::encode(NoCache); }
252
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000253 static const char* MajorName(Major major_key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000254
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000255 explicit CodeStub(Isolate* isolate) : minor_key_(0), isolate_(isolate) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000256 virtual ~CodeStub() {}
257
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000258 static void GenerateStubsAheadOfTime(Isolate* isolate);
259 static void GenerateFPStubs(Isolate* isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100260
261 // Some stubs put untagged junk on the stack that cannot be scanned by the
262 // GC. This means that we must be statically sure that no GC can occur while
263 // they are running. If that is the case they should override this to return
264 // true, which will cause an assertion if we try to call something that can
265 // GC or if we try to put a stack frame on top of the junk, which would not
266 // result in a traversable stack.
267 virtual bool SometimesSetsUpAFrame() { return true; }
268
269 // Lookup the code in the (possibly custom) cache.
270 bool FindCodeInCache(Code** code_out);
271
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000272 virtual CallInterfaceDescriptor GetCallInterfaceDescriptor() const = 0;
273
274 virtual int GetStackParameterCount() const {
275 return GetCallInterfaceDescriptor().GetStackParameterCount();
276 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000277
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000278 virtual void InitializeDescriptor(CodeStubDescriptor* descriptor) {}
279
280 static void InitializeDescriptor(Isolate* isolate, uint32_t key,
281 CodeStubDescriptor* desc);
282
283 static MaybeHandle<Code> GetCode(Isolate* isolate, uint32_t key);
284
285 // Returns information for computing the number key.
286 virtual Major MajorKey() const = 0;
287 uint32_t MinorKey() const { return minor_key_; }
288
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000289 // BinaryOpStub needs to override this.
290 virtual Code::Kind GetCodeKind() const;
291
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000292 virtual ExtraICState GetExtraICState() const { return kNoExtraICState; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000293
Ben Murdoch097c5b22016-05-18 11:27:45 +0100294 Code::Flags GetCodeFlags() const;
295
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400296 friend std::ostream& operator<<(std::ostream& os, const CodeStub& s) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000297 s.PrintName(os);
298 return os;
299 }
300
301 Isolate* isolate() const { return isolate_; }
302
303 protected:
304 CodeStub(uint32_t key, Isolate* isolate)
305 : minor_key_(MinorKeyFromKey(key)), isolate_(isolate) {}
Leon Clarkee46be812010-01-19 14:06:41 +0000306
Steve Blocka7e24c12009-10-30 11:49:00 +0000307 // Generates the assembler code for the stub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000308 virtual Handle<Code> GenerateCode() = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000309
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000310 // Returns whether the code generated for this stub needs to be allocated as
311 // a fixed (non-moveable) code object.
312 virtual bool NeedsImmovableCode() { return false; }
313
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400314 virtual void PrintName(std::ostream& os) const; // NOLINT
315 virtual void PrintBaseName(std::ostream& os) const; // NOLINT
316 virtual void PrintState(std::ostream& os) const { ; } // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000317
318 // Computes the key based on major and minor.
319 uint32_t GetKey() {
320 DCHECK(static_cast<int>(MajorKey()) < NUMBER_OF_IDS);
321 return MinorKeyBits::encode(MinorKey()) | MajorKeyBits::encode(MajorKey());
322 }
323
324 uint32_t minor_key_;
325
326 private:
Leon Clarkee46be812010-01-19 14:06:41 +0000327 // Perform bookkeeping required after code generation when stub code is
328 // initially generated.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000329 void RecordCodeGeneration(Handle<Code> code);
Leon Clarkee46be812010-01-19 14:06:41 +0000330
Ben Murdochb0fe1622011-05-05 13:52:32 +0100331 // Finish the code object after it has been generated.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100332 virtual void FinishCode(Handle<Code> code) { }
333
334 // Activate newly generated stub. Is called after
335 // registering stub in the stub cache.
336 virtual void Activate(Code* code) { }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100337
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100338 // Add the code to a specialized cache, specific to an individual
339 // stub type. Please note, this method must add the code object to a
340 // roots object, otherwise we will remove the code during GC.
341 virtual void AddToSpecialCache(Handle<Code> new_object) { }
342
343 // Find code in a specialized cache, work is delegated to the specific stub.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000344 virtual bool FindCodeInSpecialCache(Code** code_out) {
345 return false;
346 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100347
348 // If a stub uses a special cache override this.
349 virtual bool UseSpecialCache() { return false; }
350
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000351 // We use this dispatch to statically instantiate the correct code stub for
352 // the given stub key and call the passed function with that code stub.
353 typedef void (*DispatchedCall)(CodeStub* stub, void** value_out);
354 static void Dispatch(Isolate* isolate, uint32_t key, void** value_out,
355 DispatchedCall call);
Steve Blocka7e24c12009-10-30 11:49:00 +0000356
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000357 static void GetCodeDispatchCall(CodeStub* stub, void** value_out);
Steve Block44f0eee2011-05-26 01:26:41 +0100358
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000359 STATIC_ASSERT(NUMBER_OF_IDS < (1 << kStubMajorKeyBits));
360 class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {};
361 class MinorKeyBits: public BitField<uint32_t,
362 kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000363
364 friend class BreakPointIterator;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000365
366 Isolate* isolate_;
367};
368
369
370#define DEFINE_CODE_STUB_BASE(NAME, SUPER) \
371 public: \
372 NAME(uint32_t key, Isolate* isolate) : SUPER(key, isolate) {} \
373 \
374 private: \
375 DISALLOW_COPY_AND_ASSIGN(NAME)
376
377
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400378#define DEFINE_CODE_STUB(NAME, SUPER) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100379 public: \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000380 inline Major MajorKey() const override { return NAME; }; \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100381 \
382 protected: \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000383 DEFINE_CODE_STUB_BASE(NAME##Stub, SUPER)
384
385
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400386#define DEFINE_PLATFORM_CODE_STUB(NAME, SUPER) \
387 private: \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000388 void Generate(MacroAssembler* masm) override; \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000389 DEFINE_CODE_STUB(NAME, SUPER)
390
391
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400392#define DEFINE_HYDROGEN_CODE_STUB(NAME, SUPER) \
393 public: \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000394 void InitializeDescriptor(CodeStubDescriptor* descriptor) override; \
395 Handle<Code> GenerateCode() override; \
396 DEFINE_CODE_STUB(NAME, SUPER)
397
Ben Murdochc5610432016-08-08 18:44:38 +0100398#define DEFINE_TURBOFAN_CODE_STUB(NAME, SUPER) \
399 public: \
400 void GenerateAssembly(CodeStubAssembler* assembler) const override; \
401 DEFINE_CODE_STUB(NAME, SUPER)
402
403#define DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(NAME, SUPER) \
404 public: \
405 static compiler::Node* Generate(CodeStubAssembler* assembler, \
406 compiler::Node* left, compiler::Node* right, \
407 compiler::Node* context); \
408 void GenerateAssembly(CodeStubAssembler* assembler) const override { \
409 assembler->Return(Generate(assembler, assembler->Parameter(0), \
410 assembler->Parameter(1), \
411 assembler->Parameter(2))); \
412 } \
413 DEFINE_CODE_STUB(NAME, SUPER)
414
415#define DEFINE_TURBOFAN_UNARY_OP_CODE_STUB(NAME, SUPER) \
416 public: \
417 static compiler::Node* Generate(CodeStubAssembler* assembler, \
418 compiler::Node* value, \
419 compiler::Node* context); \
420 void GenerateAssembly(CodeStubAssembler* assembler) const override { \
421 assembler->Return(Generate(assembler, assembler->Parameter(0), \
422 assembler->Parameter(1))); \
423 } \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000424 DEFINE_CODE_STUB(NAME, SUPER)
425
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400426#define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \
427 public: \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000428 Handle<Code> GenerateCode() override; \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000429 DEFINE_CODE_STUB(NAME, SUPER)
430
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000431#define DEFINE_CALL_INTERFACE_DESCRIPTOR(NAME) \
432 public: \
433 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
434 return NAME##Descriptor(isolate()); \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000435 }
436
Ben Murdoch61f157c2016-09-16 13:49:30 +0100437#define DEFINE_ON_STACK_CALL_INTERFACE_DESCRIPTOR(PARAMETER_COUNT) \
438 public: \
439 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
440 return OnStackArgsDescriptorBase::ForArgs(isolate(), PARAMETER_COUNT); \
441 }
442
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000443// There are some code stubs we just can't describe right now with a
444// CallInterfaceDescriptor. Isolate behavior for those cases with this macro.
445// An attempt to retrieve a descriptor will fail.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000446#define DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR() \
447 public: \
448 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
449 UNREACHABLE(); \
450 return CallInterfaceDescriptor(); \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000451 }
452
453
454class PlatformCodeStub : public CodeStub {
455 public:
456 // Retrieve the code for the stub. Generate the code if needed.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000457 Handle<Code> GenerateCode() override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000458
459 protected:
460 explicit PlatformCodeStub(Isolate* isolate) : CodeStub(isolate) {}
461
462 // Generates the assembler code for the stub.
463 virtual void Generate(MacroAssembler* masm) = 0;
464
465 DEFINE_CODE_STUB_BASE(PlatformCodeStub, CodeStub);
466};
467
468
469enum StubFunctionMode { NOT_JS_FUNCTION_STUB_MODE, JS_FUNCTION_STUB_MODE };
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000470
471
472class CodeStubDescriptor {
473 public:
474 explicit CodeStubDescriptor(CodeStub* stub);
475
476 CodeStubDescriptor(Isolate* isolate, uint32_t stub_key);
477
478 void Initialize(Address deoptimization_handler = NULL,
479 int hint_stack_parameter_count = -1,
480 StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
481 void Initialize(Register stack_parameter_count,
482 Address deoptimization_handler = NULL,
483 int hint_stack_parameter_count = -1,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000484 StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000485
486 void SetMissHandler(ExternalReference handler) {
487 miss_handler_ = handler;
488 has_miss_handler_ = true;
489 // Our miss handler infrastructure doesn't currently support
490 // variable stack parameter counts.
491 DCHECK(!stack_parameter_count_.is_valid());
492 }
493
494 void set_call_descriptor(CallInterfaceDescriptor d) { call_descriptor_ = d; }
495 CallInterfaceDescriptor call_descriptor() const { return call_descriptor_; }
496
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000497 int GetRegisterParameterCount() const {
498 return call_descriptor().GetRegisterParameterCount();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000499 }
500
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000501 int GetStackParameterCount() const {
502 return call_descriptor().GetStackParameterCount();
503 }
504
505 int GetParameterCount() const {
506 return call_descriptor().GetParameterCount();
507 }
508
509 Register GetRegisterParameter(int index) const {
510 return call_descriptor().GetRegisterParameter(index);
511 }
512
513 Type* GetParameterType(int index) const {
514 return call_descriptor().GetParameterType(index);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000515 }
516
517 ExternalReference miss_handler() const {
518 DCHECK(has_miss_handler_);
519 return miss_handler_;
520 }
521
522 bool has_miss_handler() const {
523 return has_miss_handler_;
524 }
525
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000526 int GetHandlerParameterCount() const {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000527 int params = GetParameterCount();
528 if (PassesArgumentsToDeoptimizationHandler()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000529 params += 1;
530 }
531 return params;
532 }
533
534 int hint_stack_parameter_count() const { return hint_stack_parameter_count_; }
535 Register stack_parameter_count() const { return stack_parameter_count_; }
536 StubFunctionMode function_mode() const { return function_mode_; }
537 Address deoptimization_handler() const { return deoptimization_handler_; }
538
539 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000540 bool PassesArgumentsToDeoptimizationHandler() const {
541 return stack_parameter_count_.is_valid();
542 }
543
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000544 CallInterfaceDescriptor call_descriptor_;
545 Register stack_parameter_count_;
546 // If hint_stack_parameter_count_ > 0, the code stub can optimize the
547 // return sequence. Default value is -1, which means it is ignored.
548 int hint_stack_parameter_count_;
549 StubFunctionMode function_mode_;
550
551 Address deoptimization_handler_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000552
553 ExternalReference miss_handler_;
554 bool has_miss_handler_;
555};
556
557
558class HydrogenCodeStub : public CodeStub {
559 public:
560 enum InitializationState {
561 UNINITIALIZED,
562 INITIALIZED
563 };
564
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000565 template<class SubClass>
566 static Handle<Code> GetUninitialized(Isolate* isolate) {
567 SubClass::GenerateAheadOfTime(isolate);
568 return SubClass().GetCode(isolate);
569 }
570
571 // Retrieve the code for the stub. Generate the code if needed.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000572 Handle<Code> GenerateCode() override = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000573
574 bool IsUninitialized() const { return IsMissBits::decode(minor_key_); }
575
576 Handle<Code> GenerateLightweightMissCode(ExternalReference miss);
577
578 template<class StateType>
579 void TraceTransition(StateType from, StateType to);
580
581 protected:
582 explicit HydrogenCodeStub(Isolate* isolate,
583 InitializationState state = INITIALIZED)
584 : CodeStub(isolate) {
585 minor_key_ = IsMissBits::encode(state == UNINITIALIZED);
586 }
587
588 void set_sub_minor_key(uint32_t key) {
589 minor_key_ = SubMinorKeyBits::update(minor_key_, key);
590 }
591
592 uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); }
593
594 static const int kSubMinorKeyBits = kStubMinorKeyBits - 1;
595
596 private:
597 class IsMissBits : public BitField<bool, kSubMinorKeyBits, 1> {};
598 class SubMinorKeyBits : public BitField<int, 0, kSubMinorKeyBits> {};
599
600 void GenerateLightweightMiss(MacroAssembler* masm, ExternalReference miss);
601
602 DEFINE_CODE_STUB_BASE(HydrogenCodeStub, CodeStub);
Steve Blocka7e24c12009-10-30 11:49:00 +0000603};
604
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100605
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000606class TurboFanCodeStub : public CodeStub {
607 public:
608 // Retrieve the code for the stub. Generate the code if needed.
609 Handle<Code> GenerateCode() override;
610
611 int GetStackParameterCount() const override {
612 return GetCallInterfaceDescriptor().GetStackParameterCount();
613 }
614
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000615 protected:
616 explicit TurboFanCodeStub(Isolate* isolate) : CodeStub(isolate) {}
617
Ben Murdochc5610432016-08-08 18:44:38 +0100618 virtual void GenerateAssembly(CodeStubAssembler* assembler) const = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000619
620 private:
621 DEFINE_CODE_STUB_BASE(TurboFanCodeStub, CodeStub);
622};
623
624
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100625// Helper interface to prepare to/restore after making runtime calls.
626class RuntimeCallHelper {
627 public:
628 virtual ~RuntimeCallHelper() {}
629
630 virtual void BeforeCall(MacroAssembler* masm) const = 0;
631
632 virtual void AfterCall(MacroAssembler* masm) const = 0;
633
634 protected:
635 RuntimeCallHelper() {}
636
637 private:
638 DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper);
639};
640
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000641
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000642} // namespace internal
643} // namespace v8
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100644
645#if V8_TARGET_ARCH_IA32
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000646#include "src/ia32/code-stubs-ia32.h"
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100647#elif V8_TARGET_ARCH_X64
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000648#include "src/x64/code-stubs-x64.h"
649#elif V8_TARGET_ARCH_ARM64
650#include "src/arm64/code-stubs-arm64.h"
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100651#elif V8_TARGET_ARCH_ARM
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000652#include "src/arm/code-stubs-arm.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000653#elif V8_TARGET_ARCH_PPC
654#include "src/ppc/code-stubs-ppc.h"
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100655#elif V8_TARGET_ARCH_MIPS
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000656#include "src/mips/code-stubs-mips.h"
657#elif V8_TARGET_ARCH_MIPS64
658#include "src/mips64/code-stubs-mips64.h"
Ben Murdochda12d292016-06-02 14:46:10 +0100659#elif V8_TARGET_ARCH_S390
660#include "src/s390/code-stubs-s390.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000661#elif V8_TARGET_ARCH_X87
662#include "src/x87/code-stubs-x87.h"
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100663#else
664#error Unsupported target architecture.
665#endif
666
667namespace v8 {
668namespace internal {
669
670
Ben Murdochb0fe1622011-05-05 13:52:32 +0100671// RuntimeCallHelper implementation used in stubs: enters/leaves a
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100672// newly created internal frame before/after the runtime call.
Ben Murdochb0fe1622011-05-05 13:52:32 +0100673class StubRuntimeCallHelper : public RuntimeCallHelper {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100674 public:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100675 StubRuntimeCallHelper() {}
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100676
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000677 void BeforeCall(MacroAssembler* masm) const override;
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100678
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000679 void AfterCall(MacroAssembler* masm) const override;
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100680};
681
682
683// Trivial RuntimeCallHelper implementation.
684class NopRuntimeCallHelper : public RuntimeCallHelper {
685 public:
686 NopRuntimeCallHelper() {}
687
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000688 void BeforeCall(MacroAssembler* masm) const override {}
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100689
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000690 void AfterCall(MacroAssembler* masm) const override {}
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100691};
692
693
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000694class StringLengthStub : public TurboFanCodeStub {
695 public:
696 explicit StringLengthStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
697
698 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000699 ExtraICState GetExtraICState() const override { return Code::LOAD_IC; }
700
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000701 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
Ben Murdochda12d292016-06-02 14:46:10 +0100702 DEFINE_TURBOFAN_CODE_STUB(StringLength, TurboFanCodeStub);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000703};
704
Ben Murdochda12d292016-06-02 14:46:10 +0100705class AddStub final : public TurboFanCodeStub {
706 public:
707 explicit AddStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
708
709 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
Ben Murdochc5610432016-08-08 18:44:38 +0100710 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(Add, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100711};
712
713class SubtractStub final : public TurboFanCodeStub {
714 public:
715 explicit SubtractStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
716
717 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
Ben Murdochc5610432016-08-08 18:44:38 +0100718 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(Subtract, TurboFanCodeStub);
719};
720
721class MultiplyStub final : public TurboFanCodeStub {
722 public:
723 explicit MultiplyStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
724
725 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
726 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(Multiply, TurboFanCodeStub);
727};
728
729class DivideStub final : public TurboFanCodeStub {
730 public:
731 explicit DivideStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
732
733 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
734 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(Divide, TurboFanCodeStub);
735};
736
737class ModulusStub final : public TurboFanCodeStub {
738 public:
739 explicit ModulusStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
740
741 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
742 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(Modulus, TurboFanCodeStub);
743};
744
745class ShiftRightStub final : public TurboFanCodeStub {
746 public:
747 explicit ShiftRightStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
748
749 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
750 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(ShiftRight, TurboFanCodeStub);
751};
752
753class ShiftRightLogicalStub final : public TurboFanCodeStub {
754 public:
755 explicit ShiftRightLogicalStub(Isolate* isolate)
756 : TurboFanCodeStub(isolate) {}
757
758 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
759 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(ShiftRightLogical, TurboFanCodeStub);
760};
761
762class ShiftLeftStub final : public TurboFanCodeStub {
763 public:
764 explicit ShiftLeftStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
765
766 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
767 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(ShiftLeft, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100768};
769
770class BitwiseAndStub final : public TurboFanCodeStub {
771 public:
772 explicit BitwiseAndStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
773
774 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
Ben Murdochc5610432016-08-08 18:44:38 +0100775 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(BitwiseAnd, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100776};
777
778class BitwiseOrStub final : public TurboFanCodeStub {
779 public:
780 explicit BitwiseOrStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
781
782 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
Ben Murdochc5610432016-08-08 18:44:38 +0100783 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(BitwiseOr, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100784};
785
786class BitwiseXorStub final : public TurboFanCodeStub {
787 public:
788 explicit BitwiseXorStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
789
790 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
Ben Murdochc5610432016-08-08 18:44:38 +0100791 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(BitwiseXor, TurboFanCodeStub);
792};
793
794class IncStub final : public TurboFanCodeStub {
795 public:
796 explicit IncStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
797
798 DEFINE_CALL_INTERFACE_DESCRIPTOR(CountOp);
799 DEFINE_TURBOFAN_UNARY_OP_CODE_STUB(Inc, TurboFanCodeStub);
800};
801
802class DecStub final : public TurboFanCodeStub {
803 public:
804 explicit DecStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
805
806 DEFINE_CALL_INTERFACE_DESCRIPTOR(CountOp);
807 DEFINE_TURBOFAN_UNARY_OP_CODE_STUB(Dec, TurboFanCodeStub);
808};
809
810class InstanceOfStub final : public TurboFanCodeStub {
811 public:
812 explicit InstanceOfStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
813
814 private:
815 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100816 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(InstanceOf, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100817};
818
819class LessThanStub final : public TurboFanCodeStub {
820 public:
821 explicit LessThanStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
822
823 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100824 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(LessThan, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100825};
826
827class LessThanOrEqualStub final : public TurboFanCodeStub {
828 public:
829 explicit LessThanOrEqualStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
830
831 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100832 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(LessThanOrEqual, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100833};
834
835class GreaterThanStub final : public TurboFanCodeStub {
836 public:
837 explicit GreaterThanStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
838
839 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100840 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(GreaterThan, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100841};
842
843class GreaterThanOrEqualStub final : public TurboFanCodeStub {
844 public:
845 explicit GreaterThanOrEqualStub(Isolate* isolate)
846 : TurboFanCodeStub(isolate) {}
847
848 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100849 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(GreaterThanOrEqual, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100850};
851
852class EqualStub final : public TurboFanCodeStub {
853 public:
854 explicit EqualStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
855
856 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100857 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(Equal, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100858};
859
860class NotEqualStub final : public TurboFanCodeStub {
861 public:
862 explicit NotEqualStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
863
864 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100865 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(NotEqual, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100866};
867
868class StrictEqualStub final : public TurboFanCodeStub {
869 public:
870 explicit StrictEqualStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
871
872 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100873 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(StrictEqual, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100874};
875
876class StrictNotEqualStub final : public TurboFanCodeStub {
877 public:
878 explicit StrictNotEqualStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
879
880 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100881 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(StrictNotEqual, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100882};
883
884class StringEqualStub final : public TurboFanCodeStub {
885 public:
886 explicit StringEqualStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
887
888 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
889 DEFINE_TURBOFAN_CODE_STUB(StringEqual, TurboFanCodeStub);
890};
891
892class StringNotEqualStub final : public TurboFanCodeStub {
893 public:
894 explicit StringNotEqualStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
895
896 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
897 DEFINE_TURBOFAN_CODE_STUB(StringNotEqual, TurboFanCodeStub);
898};
899
900class StringLessThanStub final : public TurboFanCodeStub {
901 public:
902 explicit StringLessThanStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
903
904 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
905 DEFINE_TURBOFAN_CODE_STUB(StringLessThan, TurboFanCodeStub);
906};
907
908class StringLessThanOrEqualStub final : public TurboFanCodeStub {
909 public:
910 explicit StringLessThanOrEqualStub(Isolate* isolate)
911 : TurboFanCodeStub(isolate) {}
912
913 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
914 DEFINE_TURBOFAN_CODE_STUB(StringLessThanOrEqual, TurboFanCodeStub);
915};
916
917class StringGreaterThanStub final : public TurboFanCodeStub {
918 public:
919 explicit StringGreaterThanStub(Isolate* isolate)
920 : TurboFanCodeStub(isolate) {}
921
922 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
923 DEFINE_TURBOFAN_CODE_STUB(StringGreaterThan, TurboFanCodeStub);
924};
925
926class StringGreaterThanOrEqualStub final : public TurboFanCodeStub {
927 public:
928 explicit StringGreaterThanOrEqualStub(Isolate* isolate)
929 : TurboFanCodeStub(isolate) {}
930
931 DEFINE_CALL_INTERFACE_DESCRIPTOR(Compare);
932 DEFINE_TURBOFAN_CODE_STUB(StringGreaterThanOrEqual, TurboFanCodeStub);
933};
934
935class ToBooleanStub final : public TurboFanCodeStub {
936 public:
937 explicit ToBooleanStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
938
939 DEFINE_CALL_INTERFACE_DESCRIPTOR(TypeConversion);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100940 DEFINE_TURBOFAN_UNARY_OP_CODE_STUB(ToBoolean, TurboFanCodeStub);
Ben Murdochda12d292016-06-02 14:46:10 +0100941};
942
943class ToIntegerStub final : public TurboFanCodeStub {
944 public:
945 explicit ToIntegerStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
946
947 DEFINE_CALL_INTERFACE_DESCRIPTOR(TypeConversion);
948 DEFINE_TURBOFAN_CODE_STUB(ToInteger, TurboFanCodeStub);
949};
950
951class ToLengthStub final : public TurboFanCodeStub {
952 public:
953 explicit ToLengthStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
954
955 DEFINE_CALL_INTERFACE_DESCRIPTOR(TypeConversion);
956 DEFINE_TURBOFAN_CODE_STUB(ToLength, TurboFanCodeStub);
957};
958
959class StoreInterceptorStub : public TurboFanCodeStub {
960 public:
961 explicit StoreInterceptorStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
962
Ben Murdochc5610432016-08-08 18:44:38 +0100963 void GenerateAssembly(CodeStubAssembler* assember) const override;
Ben Murdochda12d292016-06-02 14:46:10 +0100964
965 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
Ben Murdochc5610432016-08-08 18:44:38 +0100966 ExtraICState GetExtraICState() const override { return Code::STORE_IC; }
Ben Murdochda12d292016-06-02 14:46:10 +0100967
968 DEFINE_CALL_INTERFACE_DESCRIPTOR(Store);
969 DEFINE_CODE_STUB(StoreInterceptor, TurboFanCodeStub);
970};
971
972class LoadIndexedInterceptorStub : public TurboFanCodeStub {
973 public:
974 explicit LoadIndexedInterceptorStub(Isolate* isolate)
975 : TurboFanCodeStub(isolate) {}
976
977 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
Ben Murdochc5610432016-08-08 18:44:38 +0100978 ExtraICState GetExtraICState() const override { return Code::KEYED_LOAD_IC; }
Ben Murdochda12d292016-06-02 14:46:10 +0100979
980 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
981 DEFINE_TURBOFAN_CODE_STUB(LoadIndexedInterceptor, TurboFanCodeStub);
982};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000983
Ben Murdochc5610432016-08-08 18:44:38 +0100984// ES6 section 12.10.3 "in" operator evaluation.
985class HasPropertyStub : public TurboFanCodeStub {
986 public:
987 explicit HasPropertyStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
988
989 DEFINE_CALL_INTERFACE_DESCRIPTOR(HasProperty);
Ben Murdoch61f157c2016-09-16 13:49:30 +0100990 DEFINE_TURBOFAN_BINARY_OP_CODE_STUB(HasProperty, TurboFanCodeStub);
Ben Murdochc5610432016-08-08 18:44:38 +0100991};
992
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000993enum StringAddFlags {
994 // Omit both parameter checks.
995 STRING_ADD_CHECK_NONE = 0,
996 // Check left parameter.
997 STRING_ADD_CHECK_LEFT = 1 << 0,
998 // Check right parameter.
999 STRING_ADD_CHECK_RIGHT = 1 << 1,
1000 // Check both parameters.
1001 STRING_ADD_CHECK_BOTH = STRING_ADD_CHECK_LEFT | STRING_ADD_CHECK_RIGHT,
1002 // Convert parameters when check fails (instead of throwing an exception).
1003 STRING_ADD_CONVERT = 1 << 2,
1004 STRING_ADD_CONVERT_LEFT = STRING_ADD_CHECK_LEFT | STRING_ADD_CONVERT,
1005 STRING_ADD_CONVERT_RIGHT = STRING_ADD_CHECK_RIGHT | STRING_ADD_CONVERT
1006};
1007
1008
1009std::ostream& operator<<(std::ostream& os, const StringAddFlags& flags);
1010
1011
1012class NumberToStringStub final : public HydrogenCodeStub {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001013 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001014 explicit NumberToStringStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001015
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001016 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1017 static const int kNumber = 0;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001018
Ben Murdochda12d292016-06-02 14:46:10 +01001019 DEFINE_CALL_INTERFACE_DESCRIPTOR(TypeConversion);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001020 DEFINE_HYDROGEN_CODE_STUB(NumberToString, HydrogenCodeStub);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001021};
1022
1023
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001024class TypeofStub final : public HydrogenCodeStub {
1025 public:
1026 explicit TypeofStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
1027
1028 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1029 static const int kObject = 0;
1030
1031 static void GenerateAheadOfTime(Isolate* isolate);
1032
1033 DEFINE_CALL_INTERFACE_DESCRIPTOR(Typeof);
1034 DEFINE_HYDROGEN_CODE_STUB(Typeof, HydrogenCodeStub);
1035};
1036
1037
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001038class FastNewClosureStub : public HydrogenCodeStub {
Steve Block1e0659c2011-05-24 12:43:12 +01001039 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001040 FastNewClosureStub(Isolate* isolate, LanguageMode language_mode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001041 FunctionKind kind)
1042 : HydrogenCodeStub(isolate) {
1043 DCHECK(IsValidFunctionKind(kind));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001044 set_sub_minor_key(LanguageModeBits::encode(language_mode) |
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001045 FunctionKindBits::encode(kind));
1046 }
Steve Block1e0659c2011-05-24 12:43:12 +01001047
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001048 LanguageMode language_mode() const {
1049 return LanguageModeBits::decode(sub_minor_key());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001050 }
1051
1052 FunctionKind kind() const {
1053 return FunctionKindBits::decode(sub_minor_key());
1054 }
Steve Block1e0659c2011-05-24 12:43:12 +01001055
1056 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001057 STATIC_ASSERT(LANGUAGE_END == 3);
1058 class LanguageModeBits : public BitField<LanguageMode, 0, 2> {};
Ben Murdochc5610432016-08-08 18:44:38 +01001059 class FunctionKindBits : public BitField<FunctionKind, 2, 9> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001060
1061 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewClosure);
1062 DEFINE_HYDROGEN_CODE_STUB(FastNewClosure, HydrogenCodeStub);
Steve Block1e0659c2011-05-24 12:43:12 +01001063};
1064
1065
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001066class FastNewContextStub final : public HydrogenCodeStub {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001067 public:
1068 static const int kMaximumSlots = 64;
1069
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001070 FastNewContextStub(Isolate* isolate, int slots) : HydrogenCodeStub(isolate) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001071 DCHECK(slots >= 0 && slots <= kMaximumSlots);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001072 set_sub_minor_key(SlotsBits::encode(slots));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001073 }
1074
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001075 int slots() const { return SlotsBits::decode(sub_minor_key()); }
1076
1077 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1078 static const int kFunction = 0;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001079
1080 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001081 class SlotsBits : public BitField<int, 0, 8> {};
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001082
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001083 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewContext);
1084 DEFINE_HYDROGEN_CODE_STUB(FastNewContext, HydrogenCodeStub);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001085};
1086
1087
Ben Murdoch097c5b22016-05-18 11:27:45 +01001088class FastNewObjectStub final : public PlatformCodeStub {
1089 public:
1090 explicit FastNewObjectStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
1091
1092 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewObject);
1093 DEFINE_PLATFORM_CODE_STUB(FastNewObject, PlatformCodeStub);
1094};
1095
1096
1097// TODO(turbofan): This stub should be possible to write in TurboFan
1098// using the CodeStubAssembler very soon in a way that is as efficient
1099// and easy as the current handwritten version, which is partly a copy
1100// of the strict arguments object materialization code.
1101class FastNewRestParameterStub final : public PlatformCodeStub {
1102 public:
Ben Murdochc5610432016-08-08 18:44:38 +01001103 explicit FastNewRestParameterStub(Isolate* isolate,
1104 bool skip_stub_frame = false)
1105 : PlatformCodeStub(isolate) {
1106 minor_key_ = SkipStubFrameBits::encode(skip_stub_frame);
1107 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01001108
1109 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewRestParameter);
1110 DEFINE_PLATFORM_CODE_STUB(FastNewRestParameter, PlatformCodeStub);
Ben Murdochc5610432016-08-08 18:44:38 +01001111
1112 int skip_stub_frame() const { return SkipStubFrameBits::decode(minor_key_); }
1113
1114 private:
1115 class SkipStubFrameBits : public BitField<bool, 0, 1> {};
Ben Murdoch097c5b22016-05-18 11:27:45 +01001116};
1117
1118
1119// TODO(turbofan): This stub should be possible to write in TurboFan
1120// using the CodeStubAssembler very soon in a way that is as efficient
1121// and easy as the current handwritten version.
1122class FastNewSloppyArgumentsStub final : public PlatformCodeStub {
1123 public:
Ben Murdochc5610432016-08-08 18:44:38 +01001124 explicit FastNewSloppyArgumentsStub(Isolate* isolate,
1125 bool skip_stub_frame = false)
1126 : PlatformCodeStub(isolate) {
1127 minor_key_ = SkipStubFrameBits::encode(skip_stub_frame);
1128 }
1129
1130 int skip_stub_frame() const { return SkipStubFrameBits::decode(minor_key_); }
Ben Murdoch097c5b22016-05-18 11:27:45 +01001131
1132 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewSloppyArguments);
1133 DEFINE_PLATFORM_CODE_STUB(FastNewSloppyArguments, PlatformCodeStub);
Ben Murdochc5610432016-08-08 18:44:38 +01001134
1135 private:
1136 class SkipStubFrameBits : public BitField<bool, 0, 1> {};
Ben Murdoch097c5b22016-05-18 11:27:45 +01001137};
1138
1139
1140// TODO(turbofan): This stub should be possible to write in TurboFan
1141// using the CodeStubAssembler very soon in a way that is as efficient
1142// and easy as the current handwritten version.
1143class FastNewStrictArgumentsStub final : public PlatformCodeStub {
1144 public:
Ben Murdochc5610432016-08-08 18:44:38 +01001145 explicit FastNewStrictArgumentsStub(Isolate* isolate,
1146 bool skip_stub_frame = false)
1147 : PlatformCodeStub(isolate) {
1148 minor_key_ = SkipStubFrameBits::encode(skip_stub_frame);
1149 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01001150
1151 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewStrictArguments);
1152 DEFINE_PLATFORM_CODE_STUB(FastNewStrictArguments, PlatformCodeStub);
Ben Murdochc5610432016-08-08 18:44:38 +01001153
1154 int skip_stub_frame() const { return SkipStubFrameBits::decode(minor_key_); }
1155
1156 private:
1157 class SkipStubFrameBits : public BitField<bool, 0, 1> {};
Ben Murdoch097c5b22016-05-18 11:27:45 +01001158};
1159
1160
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001161class FastCloneRegExpStub final : public HydrogenCodeStub {
1162 public:
1163 explicit FastCloneRegExpStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
1164
1165 private:
1166 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneRegExp);
1167 DEFINE_HYDROGEN_CODE_STUB(FastCloneRegExp, HydrogenCodeStub);
1168};
1169
1170
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001171class FastCloneShallowArrayStub : public HydrogenCodeStub {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001172 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001173 FastCloneShallowArrayStub(Isolate* isolate,
1174 AllocationSiteMode allocation_site_mode)
1175 : HydrogenCodeStub(isolate) {
1176 set_sub_minor_key(AllocationSiteModeBits::encode(allocation_site_mode));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001177 }
1178
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001179 AllocationSiteMode allocation_site_mode() const {
1180 return AllocationSiteModeBits::decode(sub_minor_key());
1181 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001182
1183 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001184 class AllocationSiteModeBits: public BitField<AllocationSiteMode, 0, 1> {};
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001185
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001186 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowArray);
1187 DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowArray, HydrogenCodeStub);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001188};
1189
Ben Murdochc5610432016-08-08 18:44:38 +01001190class FastCloneShallowObjectStub : public TurboFanCodeStub {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001191 public:
1192 // Maximum number of properties in copied object.
1193 static const int kMaximumClonedProperties = 6;
1194
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001195 FastCloneShallowObjectStub(Isolate* isolate, int length)
Ben Murdochc5610432016-08-08 18:44:38 +01001196 : TurboFanCodeStub(isolate) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001197 DCHECK_GE(length, 0);
1198 DCHECK_LE(length, kMaximumClonedProperties);
Ben Murdochc5610432016-08-08 18:44:38 +01001199 minor_key_ = LengthBits::encode(LengthBits::encode(length));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001200 }
1201
Ben Murdochc5610432016-08-08 18:44:38 +01001202 static compiler::Node* GenerateFastPath(
1203 CodeStubAssembler* assembler,
1204 compiler::CodeAssembler::Label* call_runtime, compiler::Node* closure,
1205 compiler::Node* literals_index, compiler::Node* properties_count);
1206
1207 static bool IsSupported(ObjectLiteral* expr);
1208 static int PropertiesCount(int literal_length);
1209
1210 int length() const { return LengthBits::decode(minor_key_); }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001211
1212 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001213 class LengthBits : public BitField<int, 0, 4> {};
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001214
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001215 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowObject);
Ben Murdochc5610432016-08-08 18:44:38 +01001216 DEFINE_TURBOFAN_CODE_STUB(FastCloneShallowObject, TurboFanCodeStub);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001217};
1218
1219
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001220class CreateAllocationSiteStub : public HydrogenCodeStub {
1221 public:
1222 explicit CreateAllocationSiteStub(Isolate* isolate)
1223 : HydrogenCodeStub(isolate) { }
1224
1225 static void GenerateAheadOfTime(Isolate* isolate);
1226
1227 DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateAllocationSite);
1228 DEFINE_HYDROGEN_CODE_STUB(CreateAllocationSite, HydrogenCodeStub);
1229};
1230
1231
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001232class CreateWeakCellStub : public HydrogenCodeStub {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001233 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001234 explicit CreateWeakCellStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001235
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001236 static void GenerateAheadOfTime(Isolate* isolate);
1237
1238 DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateWeakCell);
1239 DEFINE_HYDROGEN_CODE_STUB(CreateWeakCell, HydrogenCodeStub);
1240};
1241
1242
1243class GrowArrayElementsStub : public HydrogenCodeStub {
1244 public:
1245 GrowArrayElementsStub(Isolate* isolate, bool is_js_array, ElementsKind kind)
1246 : HydrogenCodeStub(isolate) {
1247 set_sub_minor_key(ElementsKindBits::encode(kind) |
1248 IsJsArrayBits::encode(is_js_array));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001249 }
1250
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001251 ElementsKind elements_kind() const {
1252 return ElementsKindBits::decode(sub_minor_key());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001253 }
1254
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001255 bool is_js_array() const { return IsJsArrayBits::decode(sub_minor_key()); }
1256
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001257 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001258 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
1259 class IsJsArrayBits : public BitField<bool, ElementsKindBits::kNext, 1> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001260
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001261 DEFINE_CALL_INTERFACE_DESCRIPTOR(GrowArrayElements);
1262 DEFINE_HYDROGEN_CODE_STUB(GrowArrayElements, HydrogenCodeStub);
1263};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001264
Ben Murdochda12d292016-06-02 14:46:10 +01001265class FastArrayPushStub : public HydrogenCodeStub {
1266 public:
1267 explicit FastArrayPushStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
1268
1269 private:
Ben Murdoch61f157c2016-09-16 13:49:30 +01001270 DEFINE_CALL_INTERFACE_DESCRIPTOR(VarArgFunction);
Ben Murdochda12d292016-06-02 14:46:10 +01001271 DEFINE_HYDROGEN_CODE_STUB(FastArrayPush, HydrogenCodeStub);
1272};
Ben Murdoch086aeea2011-05-13 15:57:08 +01001273
Ben Murdoch61f157c2016-09-16 13:49:30 +01001274class FastFunctionBindStub : public HydrogenCodeStub {
1275 public:
1276 explicit FastFunctionBindStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
1277
1278 private:
1279 DEFINE_CALL_INTERFACE_DESCRIPTOR(VarArgFunction);
1280 DEFINE_HYDROGEN_CODE_STUB(FastFunctionBind, HydrogenCodeStub);
1281};
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001282
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001283enum AllocationSiteOverrideMode {
1284 DONT_OVERRIDE,
1285 DISABLE_ALLOCATION_SITES,
1286 LAST_ALLOCATION_SITE_OVERRIDE_MODE = DISABLE_ALLOCATION_SITES
1287};
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001288
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001289
1290class ArrayConstructorStub: public PlatformCodeStub {
1291 public:
1292 enum ArgumentCountKey { ANY, NONE, ONE, MORE_THAN_ONE };
1293
1294 ArrayConstructorStub(Isolate* isolate, int argument_count);
1295
1296 explicit ArrayConstructorStub(Isolate* isolate);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001297
1298 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001299 ArgumentCountKey argument_count() const {
1300 return ArgumentCountBits::decode(minor_key_);
1301 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001302
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001303 void GenerateDispatchToArrayStub(MacroAssembler* masm,
1304 AllocationSiteOverrideMode mode);
1305
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001306 void PrintName(std::ostream& os) const override; // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001307
1308 class ArgumentCountBits : public BitField<ArgumentCountKey, 0, 2> {};
1309
Ben Murdoch61f157c2016-09-16 13:49:30 +01001310 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayNArgumentsConstructor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001311 DEFINE_PLATFORM_CODE_STUB(ArrayConstructor, PlatformCodeStub);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001312};
1313
1314
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001315class InternalArrayConstructorStub: public PlatformCodeStub {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001316 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001317 explicit InternalArrayConstructorStub(Isolate* isolate);
1318
1319 private:
1320 void GenerateCase(MacroAssembler* masm, ElementsKind kind);
1321
Ben Murdoch61f157c2016-09-16 13:49:30 +01001322 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayNArgumentsConstructor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001323 DEFINE_PLATFORM_CODE_STUB(InternalArrayConstructor, PlatformCodeStub);
1324};
1325
1326
1327class MathPowStub: public PlatformCodeStub {
1328 public:
1329 enum ExponentType { INTEGER, DOUBLE, TAGGED, ON_STACK };
1330
1331 MathPowStub(Isolate* isolate, ExponentType exponent_type)
1332 : PlatformCodeStub(isolate) {
1333 minor_key_ = ExponentTypeBits::encode(exponent_type);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001334 }
1335
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001336 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
Ben Murdoch61f157c2016-09-16 13:49:30 +01001337 if (exponent_type() == ON_STACK) {
1338 return OnStackArgsDescriptorBase::ForArgs(isolate(), 2);
1339 } else if (exponent_type() == TAGGED) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001340 return MathPowTaggedDescriptor(isolate());
1341 } else if (exponent_type() == INTEGER) {
1342 return MathPowIntegerDescriptor(isolate());
Ben Murdoch61f157c2016-09-16 13:49:30 +01001343 } else {
1344 // A CallInterfaceDescriptor doesn't specify double registers (yet).
1345 DCHECK_EQ(DOUBLE, exponent_type());
1346 return ContextOnlyDescriptor(isolate());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001347 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001348 }
1349
1350 private:
1351 ExponentType exponent_type() const {
1352 return ExponentTypeBits::decode(minor_key_);
1353 }
1354
1355 class ExponentTypeBits : public BitField<ExponentType, 0, 2> {};
1356
1357 DEFINE_PLATFORM_CODE_STUB(MathPow, PlatformCodeStub);
1358};
1359
1360
1361class CallICStub: public PlatformCodeStub {
1362 public:
1363 CallICStub(Isolate* isolate, const CallICState& state)
1364 : PlatformCodeStub(isolate) {
1365 minor_key_ = state.GetExtraICState();
1366 }
1367
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001368 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001369
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001370 ExtraICState GetExtraICState() const final {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001371 return static_cast<ExtraICState>(minor_key_);
1372 }
1373
1374 protected:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001375 int arg_count() const { return state().argc(); }
1376 ConvertReceiverMode convert_mode() const { return state().convert_mode(); }
Ben Murdoch097c5b22016-05-18 11:27:45 +01001377 TailCallMode tail_call_mode() const { return state().tail_call_mode(); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001378
Ben Murdoch61f157c2016-09-16 13:49:30 +01001379 CallICState state() const { return CallICState(GetExtraICState()); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001380
1381 // Code generation helpers.
1382 void GenerateMiss(MacroAssembler* masm);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001383 void HandleArrayCase(MacroAssembler* masm, Label* miss);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001384
1385 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001386 void PrintState(std::ostream& os) const override; // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001387
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001388 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedbackAndVector);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001389 DEFINE_PLATFORM_CODE_STUB(CallIC, PlatformCodeStub);
1390};
1391
1392
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001393// TODO(verwaest): Translate to hydrogen code stub.
1394class FunctionPrototypeStub : public PlatformCodeStub {
1395 public:
1396 explicit FunctionPrototypeStub(Isolate* isolate)
1397 : PlatformCodeStub(isolate) {}
1398
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001399 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001400
1401 // TODO(mvstanton): only the receiver register is accessed. When this is
1402 // translated to a hydrogen code stub, a new CallInterfaceDescriptor
1403 // should be created that just uses that register for more efficient code.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001404 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1405 return LoadWithVectorDescriptor(isolate());
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001406 }
1407
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001408 DEFINE_PLATFORM_CODE_STUB(FunctionPrototype, PlatformCodeStub);
1409};
1410
1411
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001412class LoadIndexedStringStub : public PlatformCodeStub {
1413 public:
1414 explicit LoadIndexedStringStub(Isolate* isolate)
1415 : PlatformCodeStub(isolate) {}
1416
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001417 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001418
1419 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
1420 DEFINE_PLATFORM_CODE_STUB(LoadIndexedString, PlatformCodeStub);
1421};
1422
1423
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001424class HandlerStub : public HydrogenCodeStub {
1425 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001426 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1427 ExtraICState GetExtraICState() const override { return kind(); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001428
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001429 void InitializeDescriptor(CodeStubDescriptor* descriptor) override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001430
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001431 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001432
1433 protected:
1434 explicit HandlerStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
1435
1436 virtual Code::Kind kind() const = 0;
1437
1438 DEFINE_CODE_STUB_BASE(HandlerStub, HydrogenCodeStub);
1439};
1440
1441
1442class LoadFieldStub: public HandlerStub {
1443 public:
1444 LoadFieldStub(Isolate* isolate, FieldIndex index) : HandlerStub(isolate) {
1445 int property_index_key = index.GetFieldAccessStubKey();
1446 set_sub_minor_key(LoadFieldByIndexBits::encode(property_index_key));
1447 }
1448
1449 FieldIndex index() const {
1450 int property_index_key = LoadFieldByIndexBits::decode(sub_minor_key());
1451 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1452 }
1453
1454 protected:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001455 Code::Kind kind() const override { return Code::LOAD_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001456
1457 private:
1458 class LoadFieldByIndexBits : public BitField<int, 0, 13> {};
1459
1460 DEFINE_HANDLER_CODE_STUB(LoadField, HandlerStub);
1461};
1462
1463
1464class KeyedLoadSloppyArgumentsStub : public HandlerStub {
1465 public:
1466 explicit KeyedLoadSloppyArgumentsStub(Isolate* isolate)
1467 : HandlerStub(isolate) {}
1468
1469 protected:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001470 Code::Kind kind() const override { return Code::KEYED_LOAD_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001471
1472 private:
1473 DEFINE_HANDLER_CODE_STUB(KeyedLoadSloppyArguments, HandlerStub);
1474};
1475
1476
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001477class CommonStoreModeBits : public BitField<KeyedAccessStoreMode, 0, 3> {};
1478
1479class KeyedStoreSloppyArgumentsStub : public HandlerStub {
1480 public:
1481 explicit KeyedStoreSloppyArgumentsStub(Isolate* isolate,
1482 KeyedAccessStoreMode mode)
1483 : HandlerStub(isolate) {
1484 set_sub_minor_key(CommonStoreModeBits::encode(mode));
1485 }
1486
1487 protected:
1488 Code::Kind kind() const override { return Code::KEYED_STORE_IC; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001489
1490 private:
1491 DEFINE_HANDLER_CODE_STUB(KeyedStoreSloppyArguments, HandlerStub);
1492};
1493
1494
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001495class LoadConstantStub : public HandlerStub {
1496 public:
1497 LoadConstantStub(Isolate* isolate, int constant_index)
1498 : HandlerStub(isolate) {
1499 set_sub_minor_key(ConstantIndexBits::encode(constant_index));
1500 }
1501
1502 int constant_index() const {
1503 return ConstantIndexBits::decode(sub_minor_key());
1504 }
1505
1506 protected:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001507 Code::Kind kind() const override { return Code::LOAD_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001508
1509 private:
1510 class ConstantIndexBits : public BitField<int, 0, kSubMinorKeyBits> {};
1511
1512 DEFINE_HANDLER_CODE_STUB(LoadConstant, HandlerStub);
1513};
1514
Ben Murdochc5610432016-08-08 18:44:38 +01001515class LoadApiGetterStub : public TurboFanCodeStub {
1516 public:
1517 LoadApiGetterStub(Isolate* isolate, bool receiver_is_holder, int index)
1518 : TurboFanCodeStub(isolate) {
1519 // If that's not true, we need to ensure that the receiver is actually a
1520 // JSReceiver. http://crbug.com/609134
1521 DCHECK(receiver_is_holder);
1522 minor_key_ = IndexBits::encode(index) |
1523 ReceiverIsHolderBits::encode(receiver_is_holder);
1524 }
1525
1526 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1527 ExtraICState GetExtraICState() const override { return Code::LOAD_IC; }
Ben Murdochc5610432016-08-08 18:44:38 +01001528
1529 int index() const { return IndexBits::decode(minor_key_); }
1530 bool receiver_is_holder() const {
1531 return ReceiverIsHolderBits::decode(minor_key_);
1532 }
1533
1534 private:
1535 class ReceiverIsHolderBits : public BitField<bool, 0, 1> {};
1536 class IndexBits : public BitField<int, 1, kDescriptorIndexBitCount> {};
1537
1538 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
1539 DEFINE_TURBOFAN_CODE_STUB(LoadApiGetter, TurboFanCodeStub);
1540};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001541
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001542class StoreFieldStub : public HandlerStub {
1543 public:
1544 StoreFieldStub(Isolate* isolate, FieldIndex index,
1545 Representation representation)
1546 : HandlerStub(isolate) {
1547 int property_index_key = index.GetFieldAccessStubKey();
1548 uint8_t repr = PropertyDetails::EncodeRepresentation(representation);
1549 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) |
1550 RepresentationBits::encode(repr));
1551 }
1552
1553 FieldIndex index() const {
1554 int property_index_key = StoreFieldByIndexBits::decode(sub_minor_key());
1555 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1556 }
1557
1558 Representation representation() {
1559 uint8_t repr = RepresentationBits::decode(sub_minor_key());
1560 return PropertyDetails::DecodeRepresentation(repr);
1561 }
1562
1563 protected:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001564 Code::Kind kind() const override { return Code::STORE_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001565
1566 private:
1567 class StoreFieldByIndexBits : public BitField<int, 0, 13> {};
1568 class RepresentationBits : public BitField<uint8_t, 13, 4> {};
1569
1570 DEFINE_HANDLER_CODE_STUB(StoreField, HandlerStub);
1571};
1572
1573
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001574// Register and parameter access methods are specified here instead of in
1575// the CallInterfaceDescriptor because the stub uses a different descriptor
1576// if FLAG_vector_stores is on.
1577class StoreTransitionHelper {
1578 public:
1579 static Register ReceiverRegister() {
1580 return StoreTransitionDescriptor::ReceiverRegister();
1581 }
1582
1583 static Register NameRegister() {
1584 return StoreTransitionDescriptor::NameRegister();
1585 }
1586
1587 static Register ValueRegister() {
1588 return StoreTransitionDescriptor::ValueRegister();
1589 }
1590
1591 static Register SlotRegister() {
1592 return VectorStoreTransitionDescriptor::SlotRegister();
1593 }
1594
1595 static Register VectorRegister() {
1596 return VectorStoreTransitionDescriptor::VectorRegister();
1597 }
1598
1599 static Register MapRegister() {
1600 return VectorStoreTransitionDescriptor::MapRegister();
1601 }
1602
1603 static int ReceiverIndex() {
1604 return StoreTransitionDescriptor::kReceiverIndex;
1605 }
1606
1607 static int NameIndex() { return StoreTransitionDescriptor::kReceiverIndex; }
1608
1609 static int ValueIndex() { return StoreTransitionDescriptor::kValueIndex; }
1610
1611 static int MapIndex() {
1612 DCHECK(static_cast<int>(VectorStoreTransitionDescriptor::kMapIndex) ==
1613 static_cast<int>(StoreTransitionDescriptor::kMapIndex));
1614 return StoreTransitionDescriptor::kMapIndex;
1615 }
1616
1617 static int VectorIndex() {
1618 if (HasVirtualSlotArg()) {
1619 return VectorStoreTransitionDescriptor::kVirtualSlotVectorIndex;
1620 }
1621 return VectorStoreTransitionDescriptor::kVectorIndex;
1622 }
1623
1624 // Some platforms don't have a slot arg.
1625 static bool HasVirtualSlotArg() {
1626 return SlotRegister().is(no_reg);
1627 }
1628};
1629
1630
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001631class StoreTransitionStub : public HandlerStub {
1632 public:
1633 enum StoreMode {
1634 StoreMapOnly,
1635 StoreMapAndValue,
1636 ExtendStorageAndStoreMapAndValue
1637 };
1638
1639 explicit StoreTransitionStub(Isolate* isolate) : HandlerStub(isolate) {
1640 set_sub_minor_key(StoreModeBits::encode(StoreMapOnly));
1641 }
1642
1643 StoreTransitionStub(Isolate* isolate, FieldIndex index,
1644 Representation representation, StoreMode store_mode)
1645 : HandlerStub(isolate) {
1646 DCHECK(store_mode != StoreMapOnly);
1647 int property_index_key = index.GetFieldAccessStubKey();
1648 uint8_t repr = PropertyDetails::EncodeRepresentation(representation);
1649 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) |
1650 RepresentationBits::encode(repr) |
1651 StoreModeBits::encode(store_mode));
1652 }
1653
1654 FieldIndex index() const {
1655 DCHECK(store_mode() != StoreMapOnly);
1656 int property_index_key = StoreFieldByIndexBits::decode(sub_minor_key());
1657 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1658 }
1659
1660 Representation representation() {
1661 DCHECK(store_mode() != StoreMapOnly);
1662 uint8_t repr = RepresentationBits::decode(sub_minor_key());
1663 return PropertyDetails::DecodeRepresentation(repr);
1664 }
1665
1666 StoreMode store_mode() const {
1667 return StoreModeBits::decode(sub_minor_key());
1668 }
1669
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001670 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001671
1672 protected:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001673 Code::Kind kind() const override { return Code::STORE_IC; }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001674
1675 private:
1676 class StoreFieldByIndexBits : public BitField<int, 0, 13> {};
1677 class RepresentationBits : public BitField<uint8_t, 13, 4> {};
1678 class StoreModeBits : public BitField<StoreMode, 17, 2> {};
1679
1680 DEFINE_HANDLER_CODE_STUB(StoreTransition, HandlerStub);
1681};
1682
1683
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001684class StoreGlobalStub : public HandlerStub {
1685 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001686 StoreGlobalStub(Isolate* isolate, PropertyCellType type,
1687 Maybe<PropertyCellConstantType> constant_type,
1688 bool check_global)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001689 : HandlerStub(isolate) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001690 PropertyCellConstantType encoded_constant_type =
1691 constant_type.FromMaybe(PropertyCellConstantType::kSmi);
1692 set_sub_minor_key(CellTypeBits::encode(type) |
1693 ConstantTypeBits::encode(encoded_constant_type) |
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001694 CheckGlobalBits::encode(check_global));
1695 }
1696
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001697 static Handle<HeapObject> property_cell_placeholder(Isolate* isolate) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001698 return isolate->factory()->uninitialized_value();
1699 }
1700
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001701 static Handle<HeapObject> global_map_placeholder(Isolate* isolate) {
1702 return isolate->factory()->termination_exception();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001703 }
1704
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001705 Handle<Code> GetCodeCopyFromTemplate(Handle<JSGlobalObject> global,
1706 Handle<PropertyCell> cell) {
1707 Code::FindAndReplacePattern pattern;
1708 if (check_global()) {
1709 pattern.Add(handle(global_map_placeholder(isolate())->map()),
1710 Map::WeakCellForMap(Handle<Map>(global->map())));
1711 }
1712 pattern.Add(handle(property_cell_placeholder(isolate())->map()),
1713 isolate()->factory()->NewWeakCell(cell));
1714 return CodeStub::GetCodeCopy(pattern);
1715 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001716
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001717 Code::Kind kind() const override { return Code::STORE_IC; }
1718
1719 PropertyCellType cell_type() const {
1720 return CellTypeBits::decode(sub_minor_key());
1721 }
1722
1723 PropertyCellConstantType constant_type() const {
1724 DCHECK(PropertyCellType::kConstantType == cell_type());
1725 return ConstantTypeBits::decode(sub_minor_key());
1726 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001727
1728 bool check_global() const { return CheckGlobalBits::decode(sub_minor_key()); }
1729
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001730 Representation representation() {
1731 return Representation::FromKind(
1732 RepresentationBits::decode(sub_minor_key()));
1733 }
1734
1735 void set_representation(Representation r) {
1736 set_sub_minor_key(RepresentationBits::update(sub_minor_key(), r.kind()));
1737 }
1738
1739 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001740 class CellTypeBits : public BitField<PropertyCellType, 0, 2> {};
1741 class ConstantTypeBits : public BitField<PropertyCellConstantType, 2, 2> {};
1742 class RepresentationBits : public BitField<Representation::Kind, 4, 8> {};
1743 class CheckGlobalBits : public BitField<bool, 12, 1> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001744
1745 DEFINE_HANDLER_CODE_STUB(StoreGlobal, HandlerStub);
1746};
1747
1748
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001749class StoreGlobalViaContextStub final : public PlatformCodeStub {
1750 public:
1751 static const int kMaximumDepth = 15;
1752
1753 StoreGlobalViaContextStub(Isolate* isolate, int depth,
1754 LanguageMode language_mode)
1755 : PlatformCodeStub(isolate) {
1756 minor_key_ =
1757 DepthBits::encode(depth) | LanguageModeBits::encode(language_mode);
1758 }
1759
1760 int depth() const { return DepthBits::decode(minor_key_); }
1761 LanguageMode language_mode() const {
1762 return LanguageModeBits::decode(minor_key_);
1763 }
1764
1765 private:
1766 class DepthBits : public BitField<int, 0, 4> {};
1767 STATIC_ASSERT(DepthBits::kMax == kMaximumDepth);
1768 class LanguageModeBits : public BitField<LanguageMode, 4, 2> {};
1769 STATIC_ASSERT(LANGUAGE_END == 3);
1770
1771 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreGlobalViaContext);
1772 DEFINE_PLATFORM_CODE_STUB(StoreGlobalViaContext, PlatformCodeStub);
1773};
1774
Ben Murdochda12d292016-06-02 14:46:10 +01001775class CallApiCallbackStub : public PlatformCodeStub {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001776 public:
Ben Murdochda12d292016-06-02 14:46:10 +01001777 static const int kArgBits = 3;
1778 static const int kArgMax = (1 << kArgBits) - 1;
1779
1780 // CallApiCallbackStub for regular setters and getters.
1781 CallApiCallbackStub(Isolate* isolate, bool is_store, bool call_data_undefined,
1782 bool is_lazy)
1783 : CallApiCallbackStub(isolate, is_store ? 1 : 0, is_store,
1784 call_data_undefined, is_lazy) {}
1785
1786 // CallApiCallbackStub for callback functions.
1787 CallApiCallbackStub(Isolate* isolate, int argc, bool call_data_undefined)
1788 : CallApiCallbackStub(isolate, argc, false, call_data_undefined, false) {}
1789
1790 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1791 return ApiCallbackDescriptorBase::ForArgs(isolate(), argc());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001792 }
1793
1794 private:
Ben Murdochda12d292016-06-02 14:46:10 +01001795 CallApiCallbackStub(Isolate* isolate, int argc, bool is_store,
1796 bool call_data_undefined, bool is_lazy)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001797 : PlatformCodeStub(isolate) {
Ben Murdochda12d292016-06-02 14:46:10 +01001798 CHECK(0 <= argc && argc <= kArgMax);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001799 minor_key_ = IsStoreBits::encode(is_store) |
1800 CallDataUndefinedBits::encode(call_data_undefined) |
Ben Murdochda12d292016-06-02 14:46:10 +01001801 ArgumentBits::encode(argc) |
Ben Murdoch097c5b22016-05-18 11:27:45 +01001802 IsLazyAccessorBits::encode(is_lazy);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001803 }
1804
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001805 bool is_store() const { return IsStoreBits::decode(minor_key_); }
Ben Murdoch097c5b22016-05-18 11:27:45 +01001806 bool is_lazy() const { return IsLazyAccessorBits::decode(minor_key_); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001807 bool call_data_undefined() const {
1808 return CallDataUndefinedBits::decode(minor_key_);
1809 }
1810 int argc() const { return ArgumentBits::decode(minor_key_); }
1811
1812 class IsStoreBits: public BitField<bool, 0, 1> {};
1813 class CallDataUndefinedBits: public BitField<bool, 1, 1> {};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001814 class ArgumentBits : public BitField<int, 2, kArgBits> {};
Ben Murdoch097c5b22016-05-18 11:27:45 +01001815 class IsLazyAccessorBits : public BitField<bool, 3 + kArgBits, 1> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001816
Ben Murdochda12d292016-06-02 14:46:10 +01001817 DEFINE_PLATFORM_CODE_STUB(CallApiCallback, PlatformCodeStub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001818};
1819
1820
1821class CallApiGetterStub : public PlatformCodeStub {
1822 public:
1823 explicit CallApiGetterStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
1824
1825 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiGetter);
1826 DEFINE_PLATFORM_CODE_STUB(CallApiGetter, PlatformCodeStub);
1827};
1828
1829
1830class BinaryOpICStub : public HydrogenCodeStub {
1831 public:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001832 BinaryOpICStub(Isolate* isolate, Token::Value op)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001833 : HydrogenCodeStub(isolate, UNINITIALIZED) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001834 BinaryOpICState state(isolate, op);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001835 set_sub_minor_key(state.GetExtraICState());
1836 }
1837
1838 BinaryOpICStub(Isolate* isolate, const BinaryOpICState& state)
1839 : HydrogenCodeStub(isolate) {
1840 set_sub_minor_key(state.GetExtraICState());
1841 }
1842
1843 static void GenerateAheadOfTime(Isolate* isolate);
1844
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001845 Code::Kind GetCodeKind() const override { return Code::BINARY_OP_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001846
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001847 ExtraICState GetExtraICState() const final {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001848 return static_cast<ExtraICState>(sub_minor_key());
1849 }
1850
1851 BinaryOpICState state() const {
1852 return BinaryOpICState(isolate(), GetExtraICState());
1853 }
1854
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001855 void PrintState(std::ostream& os) const final; // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001856
1857 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1858 static const int kLeft = 0;
1859 static const int kRight = 1;
1860
1861 private:
1862 static void GenerateAheadOfTime(Isolate* isolate,
1863 const BinaryOpICState& state);
1864
1865 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
1866 DEFINE_HYDROGEN_CODE_STUB(BinaryOpIC, HydrogenCodeStub);
1867};
1868
1869
1870// TODO(bmeurer): Merge this into the BinaryOpICStub once we have proper tail
1871// call support for stubs in Hydrogen.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001872class BinaryOpICWithAllocationSiteStub final : public PlatformCodeStub {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001873 public:
1874 BinaryOpICWithAllocationSiteStub(Isolate* isolate,
1875 const BinaryOpICState& state)
1876 : PlatformCodeStub(isolate) {
1877 minor_key_ = state.GetExtraICState();
1878 }
1879
1880 static void GenerateAheadOfTime(Isolate* isolate);
1881
1882 Handle<Code> GetCodeCopyFromTemplate(Handle<AllocationSite> allocation_site) {
1883 Code::FindAndReplacePattern pattern;
1884 pattern.Add(isolate()->factory()->undefined_map(), allocation_site);
1885 return CodeStub::GetCodeCopy(pattern);
1886 }
1887
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001888 Code::Kind GetCodeKind() const override { return Code::BINARY_OP_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001889
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001890 ExtraICState GetExtraICState() const override {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001891 return static_cast<ExtraICState>(minor_key_);
1892 }
1893
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001894 void PrintState(std::ostream& os) const override; // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001895
1896 private:
1897 BinaryOpICState state() const {
Ben Murdoch61f157c2016-09-16 13:49:30 +01001898 return BinaryOpICState(isolate(), GetExtraICState());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001899 }
1900
1901 static void GenerateAheadOfTime(Isolate* isolate,
1902 const BinaryOpICState& state);
1903
1904 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithAllocationSite);
1905 DEFINE_PLATFORM_CODE_STUB(BinaryOpICWithAllocationSite, PlatformCodeStub);
1906};
1907
1908
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001909class BinaryOpWithAllocationSiteStub final : public BinaryOpICStub {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001910 public:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001911 BinaryOpWithAllocationSiteStub(Isolate* isolate, Token::Value op)
1912 : BinaryOpICStub(isolate, op) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001913
1914 BinaryOpWithAllocationSiteStub(Isolate* isolate, const BinaryOpICState& state)
1915 : BinaryOpICStub(isolate, state) {}
1916
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001917 Code::Kind GetCodeKind() const final { return Code::STUB; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001918
1919 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1920 static const int kAllocationSite = 0;
1921 static const int kLeft = 1;
1922 static const int kRight = 2;
1923
1924 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithAllocationSite);
1925 DEFINE_HYDROGEN_CODE_STUB(BinaryOpWithAllocationSite, BinaryOpICStub);
1926};
1927
1928
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001929class StringAddStub final : public HydrogenCodeStub {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001930 public:
1931 StringAddStub(Isolate* isolate, StringAddFlags flags,
1932 PretenureFlag pretenure_flag)
1933 : HydrogenCodeStub(isolate) {
1934 set_sub_minor_key(StringAddFlagsBits::encode(flags) |
1935 PretenureFlagBits::encode(pretenure_flag));
1936 }
1937
1938 StringAddFlags flags() const {
1939 return StringAddFlagsBits::decode(sub_minor_key());
1940 }
1941
1942 PretenureFlag pretenure_flag() const {
1943 return PretenureFlagBits::decode(sub_minor_key());
1944 }
1945
1946 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1947 static const int kLeft = 0;
1948 static const int kRight = 1;
1949
1950 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001951 class StringAddFlagsBits : public BitField<StringAddFlags, 0, 3> {};
1952 class PretenureFlagBits : public BitField<PretenureFlag, 3, 1> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001953
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001954 void PrintBaseName(std::ostream& os) const override; // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001955
1956 DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
1957 DEFINE_HYDROGEN_CODE_STUB(StringAdd, HydrogenCodeStub);
1958};
1959
1960
1961class CompareICStub : public PlatformCodeStub {
1962 public:
Ben Murdoch097c5b22016-05-18 11:27:45 +01001963 CompareICStub(Isolate* isolate, Token::Value op, CompareICState::State left,
1964 CompareICState::State right, CompareICState::State state)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001965 : PlatformCodeStub(isolate) {
1966 DCHECK(Token::IsCompareOp(op));
Ben Murdoch61f157c2016-09-16 13:49:30 +01001967 DCHECK(OpBits::is_valid(op - Token::EQ));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001968 minor_key_ = OpBits::encode(op - Token::EQ) |
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001969 LeftStateBits::encode(left) | RightStateBits::encode(right) |
1970 StateBits::encode(state);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001971 }
Ben Murdoch61f157c2016-09-16 13:49:30 +01001972 CompareICStub(Isolate* isolate, ExtraICState extra_ic_state)
1973 : PlatformCodeStub(isolate) {
1974 minor_key_ = extra_ic_state;
1975 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001976
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001977 void set_known_map(Handle<Map> map) { known_map_ = map; }
1978
Ben Murdoch61f157c2016-09-16 13:49:30 +01001979 InlineCacheState GetICState() const;
Ben Murdochb0fe1622011-05-05 13:52:32 +01001980
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001981 Token::Value op() const {
1982 return static_cast<Token::Value>(Token::EQ + OpBits::decode(minor_key_));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001983 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001984
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001985 CompareICState::State left() const {
1986 return LeftStateBits::decode(minor_key_);
1987 }
1988 CompareICState::State right() const {
1989 return RightStateBits::decode(minor_key_);
1990 }
1991 CompareICState::State state() const { return StateBits::decode(minor_key_); }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001992
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001993 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001994 Code::Kind GetCodeKind() const override { return Code::COMPARE_IC; }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001995
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001996 void GenerateBooleans(MacroAssembler* masm);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001997 void GenerateSmis(MacroAssembler* masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001998 void GenerateNumbers(MacroAssembler* masm);
1999 void GenerateInternalizedStrings(MacroAssembler* masm);
Ben Murdoch257744e2011-11-30 15:57:28 +00002000 void GenerateStrings(MacroAssembler* masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002001 void GenerateUniqueNames(MacroAssembler* masm);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002002 void GenerateReceivers(MacroAssembler* masm);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002003 void GenerateMiss(MacroAssembler* masm);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002004 void GenerateKnownReceivers(MacroAssembler* masm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002005 void GenerateGeneric(MacroAssembler* masm);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002007 bool strict() const { return op() == Token::EQ_STRICT; }
2008 Condition GetCondition() const;
Ben Murdochb0fe1622011-05-05 13:52:32 +01002009
Ben Murdoch61f157c2016-09-16 13:49:30 +01002010 // Although we don't cache anything in the special cache we have to define
2011 // this predicate to avoid appearance of code stubs with embedded maps in
2012 // the global stub cache.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002013 bool UseSpecialCache() override {
2014 return state() == CompareICState::KNOWN_RECEIVER;
Ben Murdochb0fe1622011-05-05 13:52:32 +01002015 }
2016
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002017 class OpBits : public BitField<int, 0, 3> {};
Ben Murdoch097c5b22016-05-18 11:27:45 +01002018 class LeftStateBits : public BitField<CompareICState::State, 3, 4> {};
2019 class RightStateBits : public BitField<CompareICState::State, 7, 4> {};
2020 class StateBits : public BitField<CompareICState::State, 11, 4> {};
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002021
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002022 Handle<Map> known_map_;
2023
2024 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
2025 DEFINE_PLATFORM_CODE_STUB(CompareIC, PlatformCodeStub);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002026};
2027
2028
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002029class CEntryStub : public PlatformCodeStub {
2030 public:
2031 CEntryStub(Isolate* isolate, int result_size,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002032 SaveFPRegsMode save_doubles = kDontSaveFPRegs,
2033 ArgvMode argv_mode = kArgvOnStack)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002034 : PlatformCodeStub(isolate) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002035 minor_key_ = SaveDoublesBits::encode(save_doubles == kSaveFPRegs) |
2036 ArgvMode::encode(argv_mode == kArgvInRegister);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002037 DCHECK(result_size == 1 || result_size == 2 || result_size == 3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002038 minor_key_ = ResultSizeBits::update(minor_key_, result_size);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002039 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002040
2041 // The version of this stub that doesn't save doubles is generated ahead of
2042 // time, so it's OK to call it from other stubs that can't cope with GC during
2043 // their code generation. On machines that always have gp registers (x64) we
2044 // can generate both variants ahead of time.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002045 static void GenerateAheadOfTime(Isolate* isolate);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002046
2047 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002048 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002049 bool argv_in_register() const { return ArgvMode::decode(minor_key_); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002050 int result_size() const { return ResultSizeBits::decode(minor_key_); }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002051
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002052 bool NeedsImmovableCode() override;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002053
2054 class SaveDoublesBits : public BitField<bool, 0, 1> {};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002055 class ArgvMode : public BitField<bool, 1, 1> {};
2056 class ResultSizeBits : public BitField<int, 2, 3> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002057
2058 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2059 DEFINE_PLATFORM_CODE_STUB(CEntry, PlatformCodeStub);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002060};
2061
2062
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002063class JSEntryStub : public PlatformCodeStub {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002064 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002065 JSEntryStub(Isolate* isolate, StackFrame::Type type)
2066 : PlatformCodeStub(isolate) {
2067 DCHECK(type == StackFrame::ENTRY || type == StackFrame::ENTRY_CONSTRUCT);
2068 minor_key_ = StackFrameTypeBits::encode(type);
2069 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002070
2071 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002072 void FinishCode(Handle<Code> code) override;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002073
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002074 void PrintName(std::ostream& os) const override { // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002075 os << (type() == StackFrame::ENTRY ? "JSEntryStub"
2076 : "JSConstructEntryStub");
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002077 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002078
2079 StackFrame::Type type() const {
2080 return StackFrameTypeBits::decode(minor_key_);
2081 }
2082
2083 class StackFrameTypeBits : public BitField<StackFrame::Type, 0, 5> {};
2084
2085 int handler_offset_;
2086
2087 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2088 DEFINE_PLATFORM_CODE_STUB(JSEntry, PlatformCodeStub);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002089};
2090
2091
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002092class RegExpExecStub: public PlatformCodeStub {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002093 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002094 explicit RegExpExecStub(Isolate* isolate) : PlatformCodeStub(isolate) { }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002095
Ben Murdoch61f157c2016-09-16 13:49:30 +01002096 DEFINE_ON_STACK_CALL_INTERFACE_DESCRIPTOR(4);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002097 DEFINE_PLATFORM_CODE_STUB(RegExpExec, PlatformCodeStub);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002098};
2099
2100
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002101class RegExpConstructResultStub final : public HydrogenCodeStub {
Ben Murdochb0fe1622011-05-05 13:52:32 +01002102 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002103 explicit RegExpConstructResultStub(Isolate* isolate)
2104 : HydrogenCodeStub(isolate) { }
Ben Murdochb0fe1622011-05-05 13:52:32 +01002105
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002106 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2107 static const int kLength = 0;
2108 static const int kIndex = 1;
2109 static const int kInput = 2;
Ben Murdochb0fe1622011-05-05 13:52:32 +01002110
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002111 DEFINE_CALL_INTERFACE_DESCRIPTOR(RegExpConstructResult);
2112 DEFINE_HYDROGEN_CODE_STUB(RegExpConstructResult, HydrogenCodeStub);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002113};
2114
2115
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002116// TODO(bmeurer/mvstanton): Turn CallConstructStub into ConstructICStub.
2117class CallConstructStub final : public PlatformCodeStub {
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002118 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002119 explicit CallConstructStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002120
2121 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallConstruct);
2122 DEFINE_PLATFORM_CODE_STUB(CallConstruct, PlatformCodeStub);
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +01002123};
2124
2125
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002126enum ReceiverCheckMode {
2127 // We don't know anything about the receiver.
2128 RECEIVER_IS_UNKNOWN,
2129
2130 // We know the receiver is a string.
2131 RECEIVER_IS_STRING
2132};
2133
2134
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002135enum EmbedMode {
2136 // The code being generated is part of an IC handler, which may MISS
2137 // to an IC in failure cases.
2138 PART_OF_IC_HANDLER,
2139
2140 NOT_PART_OF_IC_HANDLER
2141};
2142
2143
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002144// Generates code implementing String.prototype.charCodeAt.
2145//
2146// Only supports the case when the receiver is a string and the index
2147// is a number (smi or heap number) that is a valid index into the
2148// string. Additional index constraints are specified by the
2149// flags. Otherwise, bails out to the provided labels.
2150//
2151// Register usage: |object| may be changed to another string in a way
2152// that doesn't affect charCodeAt/charAt semantics, |index| is
2153// preserved, |scratch| and |result| are clobbered.
2154class StringCharCodeAtGenerator {
2155 public:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002156 StringCharCodeAtGenerator(Register object, Register index, Register result,
2157 Label* receiver_not_string, Label* index_not_number,
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002158 Label* index_out_of_range,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002159 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002160 : object_(object),
2161 index_(index),
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002162 result_(result),
2163 receiver_not_string_(receiver_not_string),
2164 index_not_number_(index_not_number),
2165 index_out_of_range_(index_out_of_range),
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002166 check_mode_(check_mode) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002167 DCHECK(!result_.is(object_));
2168 DCHECK(!result_.is(index_));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002169 }
2170
2171 // Generates the fast case code. On the fallthrough path |result|
2172 // register contains the result.
2173 void GenerateFast(MacroAssembler* masm);
2174
2175 // Generates the slow case code. Must not be naturally
2176 // reachable. Expected to be put after a ret instruction (e.g., in
2177 // deferred code). Always jumps back to the fast case.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002178 void GenerateSlow(MacroAssembler* masm, EmbedMode embed_mode,
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002179 const RuntimeCallHelper& call_helper);
2180
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002181 // Skip handling slow case and directly jump to bailout.
2182 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2183 masm->bind(&index_not_smi_);
2184 masm->bind(&call_runtime_);
2185 masm->jmp(bailout);
2186 }
2187
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002188 private:
2189 Register object_;
2190 Register index_;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002191 Register result_;
2192
2193 Label* receiver_not_string_;
2194 Label* index_not_number_;
2195 Label* index_out_of_range_;
2196
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002197 ReceiverCheckMode check_mode_;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002198
2199 Label call_runtime_;
2200 Label index_not_smi_;
2201 Label got_smi_index_;
2202 Label exit_;
2203
2204 DISALLOW_COPY_AND_ASSIGN(StringCharCodeAtGenerator);
2205};
2206
2207
2208// Generates code for creating a one-char string from a char code.
2209class StringCharFromCodeGenerator {
2210 public:
2211 StringCharFromCodeGenerator(Register code,
2212 Register result)
2213 : code_(code),
2214 result_(result) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002215 DCHECK(!code_.is(result_));
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002216 }
2217
2218 // Generates the fast case code. On the fallthrough path |result|
2219 // register contains the result.
2220 void GenerateFast(MacroAssembler* masm);
2221
2222 // Generates the slow case code. Must not be naturally
2223 // reachable. Expected to be put after a ret instruction (e.g., in
2224 // deferred code). Always jumps back to the fast case.
2225 void GenerateSlow(MacroAssembler* masm,
2226 const RuntimeCallHelper& call_helper);
2227
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002228 // Skip handling slow case and directly jump to bailout.
2229 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2230 masm->bind(&slow_case_);
2231 masm->jmp(bailout);
2232 }
2233
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002234 private:
2235 Register code_;
2236 Register result_;
2237
2238 Label slow_case_;
2239 Label exit_;
2240
2241 DISALLOW_COPY_AND_ASSIGN(StringCharFromCodeGenerator);
2242};
2243
2244
2245// Generates code implementing String.prototype.charAt.
2246//
2247// Only supports the case when the receiver is a string and the index
2248// is a number (smi or heap number) that is a valid index into the
2249// string. Additional index constraints are specified by the
2250// flags. Otherwise, bails out to the provided labels.
2251//
2252// Register usage: |object| may be changed to another string in a way
2253// that doesn't affect charCodeAt/charAt semantics, |index| is
2254// preserved, |scratch1|, |scratch2|, and |result| are clobbered.
2255class StringCharAtGenerator {
2256 public:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002257 StringCharAtGenerator(Register object, Register index, Register scratch,
2258 Register result, Label* receiver_not_string,
2259 Label* index_not_number, Label* index_out_of_range,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002260 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
2261 : char_code_at_generator_(object, index, scratch, receiver_not_string,
2262 index_not_number, index_out_of_range,
Ben Murdoch61f157c2016-09-16 13:49:30 +01002263 check_mode),
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002264 char_from_code_generator_(scratch, result) {}
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002265
2266 // Generates the fast case code. On the fallthrough path |result|
2267 // register contains the result.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002268 void GenerateFast(MacroAssembler* masm) {
2269 char_code_at_generator_.GenerateFast(masm);
2270 char_from_code_generator_.GenerateFast(masm);
2271 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002272
2273 // Generates the slow case code. Must not be naturally
2274 // reachable. Expected to be put after a ret instruction (e.g., in
2275 // deferred code). Always jumps back to the fast case.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002276 void GenerateSlow(MacroAssembler* masm, EmbedMode embed_mode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002277 const RuntimeCallHelper& call_helper) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002278 char_code_at_generator_.GenerateSlow(masm, embed_mode, call_helper);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002279 char_from_code_generator_.GenerateSlow(masm, call_helper);
2280 }
2281
2282 // Skip handling slow case and directly jump to bailout.
2283 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2284 char_code_at_generator_.SkipSlow(masm, bailout);
2285 char_from_code_generator_.SkipSlow(masm, bailout);
2286 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002287
2288 private:
2289 StringCharCodeAtGenerator char_code_at_generator_;
2290 StringCharFromCodeGenerator char_from_code_generator_;
2291
2292 DISALLOW_COPY_AND_ASSIGN(StringCharAtGenerator);
2293};
2294
Ben Murdoch086aeea2011-05-13 15:57:08 +01002295
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002296class LoadDictionaryElementStub : public HydrogenCodeStub {
Ben Murdoch086aeea2011-05-13 15:57:08 +01002297 public:
Ben Murdoch61f157c2016-09-16 13:49:30 +01002298 explicit LoadDictionaryElementStub(Isolate* isolate)
2299 : HydrogenCodeStub(isolate) {}
Ben Murdoch086aeea2011-05-13 15:57:08 +01002300
Ben Murdoch61f157c2016-09-16 13:49:30 +01002301 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002302 DEFINE_HYDROGEN_CODE_STUB(LoadDictionaryElement, HydrogenCodeStub);
Ben Murdoch086aeea2011-05-13 15:57:08 +01002303};
2304
Ben Murdoch257744e2011-11-30 15:57:28 +00002305
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002306class KeyedLoadGenericStub : public HydrogenCodeStub {
Ben Murdoch257744e2011-11-30 15:57:28 +00002307 public:
Ben Murdoch61f157c2016-09-16 13:49:30 +01002308 explicit KeyedLoadGenericStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
Ben Murdoch257744e2011-11-30 15:57:28 +00002309
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002310 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
Ben Murdoch257744e2011-11-30 15:57:28 +00002311
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002312 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
2313 DEFINE_HYDROGEN_CODE_STUB(KeyedLoadGeneric, HydrogenCodeStub);
Ben Murdoch257744e2011-11-30 15:57:28 +00002314};
2315
2316
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002317class LoadICTrampolineStub : public PlatformCodeStub {
Ben Murdoch257744e2011-11-30 15:57:28 +00002318 public:
Ben Murdoch61f157c2016-09-16 13:49:30 +01002319 explicit LoadICTrampolineStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
Ben Murdoch257744e2011-11-30 15:57:28 +00002320
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002321 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002322
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002323 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002324 DEFINE_PLATFORM_CODE_STUB(LoadICTrampoline, PlatformCodeStub);
Ben Murdoch257744e2011-11-30 15:57:28 +00002325};
2326
Ben Murdoch61f157c2016-09-16 13:49:30 +01002327class LoadICTrampolineTFStub : public TurboFanCodeStub {
2328 public:
2329 explicit LoadICTrampolineTFStub(Isolate* isolate)
2330 : TurboFanCodeStub(isolate) {}
2331
2332 void GenerateAssembly(CodeStubAssembler* assembler) const override;
2333
2334 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
2335
2336 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
2337 DEFINE_CODE_STUB(LoadICTrampolineTF, TurboFanCodeStub);
2338};
2339
2340class LoadGlobalICTrampolineStub : public TurboFanCodeStub {
2341 public:
2342 explicit LoadGlobalICTrampolineStub(Isolate* isolate,
2343 const LoadGlobalICState& state)
2344 : TurboFanCodeStub(isolate) {
2345 minor_key_ = state.GetExtraICState();
2346 }
2347
2348 void GenerateAssembly(CodeStubAssembler* assembler) const override;
2349
2350 Code::Kind GetCodeKind() const override { return Code::LOAD_GLOBAL_IC; }
2351
2352 ExtraICState GetExtraICState() const final {
2353 return static_cast<ExtraICState>(minor_key_);
2354 }
2355
2356 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadGlobal);
2357 DEFINE_CODE_STUB(LoadGlobalICTrampoline, TurboFanCodeStub);
2358};
Ben Murdoch257744e2011-11-30 15:57:28 +00002359
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002360class KeyedLoadICTrampolineStub : public LoadICTrampolineStub {
2361 public:
Ben Murdoch61f157c2016-09-16 13:49:30 +01002362 explicit KeyedLoadICTrampolineStub(Isolate* isolate)
2363 : LoadICTrampolineStub(isolate) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002364
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002365 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002366
2367 DEFINE_PLATFORM_CODE_STUB(KeyedLoadICTrampoline, LoadICTrampolineStub);
2368};
2369
2370
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002371class VectorStoreICTrampolineStub : public PlatformCodeStub {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002372 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002373 VectorStoreICTrampolineStub(Isolate* isolate, const StoreICState& state)
2374 : PlatformCodeStub(isolate) {
2375 minor_key_ = state.GetExtraICState();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002376 }
2377
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002378 Code::Kind GetCodeKind() const override { return Code::STORE_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002379
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002380 ExtraICState GetExtraICState() const final {
2381 return static_cast<ExtraICState>(minor_key_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002382 }
2383
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002384 protected:
2385 StoreICState state() const {
2386 return StoreICState(static_cast<ExtraICState>(minor_key_));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002387 }
2388
2389 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002390 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreICTrampoline);
2391 DEFINE_PLATFORM_CODE_STUB(VectorStoreICTrampoline, PlatformCodeStub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002392};
2393
2394
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002395class VectorKeyedStoreICTrampolineStub : public VectorStoreICTrampolineStub {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002396 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002397 VectorKeyedStoreICTrampolineStub(Isolate* isolate, const StoreICState& state)
2398 : VectorStoreICTrampolineStub(isolate, state) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002399
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002400 Code::Kind GetCodeKind() const override { return Code::KEYED_STORE_IC; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002401
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002402 DEFINE_PLATFORM_CODE_STUB(VectorKeyedStoreICTrampoline,
2403 VectorStoreICTrampolineStub);
2404};
2405
2406
2407class CallICTrampolineStub : public PlatformCodeStub {
2408 public:
2409 CallICTrampolineStub(Isolate* isolate, const CallICState& state)
2410 : PlatformCodeStub(isolate) {
2411 minor_key_ = state.GetExtraICState();
2412 }
2413
2414 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
2415
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002416 ExtraICState GetExtraICState() const final {
2417 return static_cast<ExtraICState>(minor_key_);
2418 }
2419
2420 protected:
2421 CallICState state() const {
2422 return CallICState(static_cast<ExtraICState>(minor_key_));
2423 }
2424
2425 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedback);
2426 DEFINE_PLATFORM_CODE_STUB(CallICTrampoline, PlatformCodeStub);
2427};
2428
2429
2430class LoadICStub : public PlatformCodeStub {
2431 public:
Ben Murdoch61f157c2016-09-16 13:49:30 +01002432 explicit LoadICStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002433
2434 void GenerateForTrampoline(MacroAssembler* masm);
2435
2436 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002437
2438 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2439 DEFINE_PLATFORM_CODE_STUB(LoadIC, PlatformCodeStub);
2440
2441 protected:
2442 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2443};
2444
Ben Murdoch61f157c2016-09-16 13:49:30 +01002445class LoadICTFStub : public TurboFanCodeStub {
2446 public:
2447 explicit LoadICTFStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
2448
2449 void GenerateAssembly(CodeStubAssembler* assembler) const override;
2450
2451 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
2452
2453 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2454 DEFINE_CODE_STUB(LoadICTF, TurboFanCodeStub);
2455};
2456
2457class LoadGlobalICStub : public TurboFanCodeStub {
2458 public:
2459 explicit LoadGlobalICStub(Isolate* isolate, const LoadGlobalICState& state)
2460 : TurboFanCodeStub(isolate) {
2461 minor_key_ = state.GetExtraICState();
2462 }
2463
2464 void GenerateAssembly(CodeStubAssembler* assembler) const override;
2465
2466 Code::Kind GetCodeKind() const override { return Code::LOAD_GLOBAL_IC; }
2467
2468 ExtraICState GetExtraICState() const final {
2469 return static_cast<ExtraICState>(minor_key_);
2470 }
2471
2472 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadGlobalWithVector);
2473 DEFINE_CODE_STUB(LoadGlobalIC, TurboFanCodeStub);
2474};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002475
2476class KeyedLoadICStub : public PlatformCodeStub {
2477 public:
Ben Murdoch61f157c2016-09-16 13:49:30 +01002478 explicit KeyedLoadICStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002479
2480 void GenerateForTrampoline(MacroAssembler* masm);
2481
2482 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002483
2484 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2485 DEFINE_PLATFORM_CODE_STUB(KeyedLoadIC, PlatformCodeStub);
2486
2487 protected:
2488 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2489};
2490
2491
2492class VectorStoreICStub : public PlatformCodeStub {
2493 public:
2494 VectorStoreICStub(Isolate* isolate, const StoreICState& state)
2495 : PlatformCodeStub(isolate) {
2496 minor_key_ = state.GetExtraICState();
2497 }
2498
2499 void GenerateForTrampoline(MacroAssembler* masm);
2500
2501 Code::Kind GetCodeKind() const final { return Code::STORE_IC; }
Ben Murdoch61f157c2016-09-16 13:49:30 +01002502
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002503 ExtraICState GetExtraICState() const final {
2504 return static_cast<ExtraICState>(minor_key_);
2505 }
2506
2507 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreIC);
2508 DEFINE_PLATFORM_CODE_STUB(VectorStoreIC, PlatformCodeStub);
2509
2510 protected:
2511 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2512};
2513
2514
2515class VectorKeyedStoreICStub : public PlatformCodeStub {
2516 public:
2517 VectorKeyedStoreICStub(Isolate* isolate, const StoreICState& state)
2518 : PlatformCodeStub(isolate) {
2519 minor_key_ = state.GetExtraICState();
2520 }
2521
2522 void GenerateForTrampoline(MacroAssembler* masm);
2523
2524 Code::Kind GetCodeKind() const final { return Code::KEYED_STORE_IC; }
Ben Murdoch61f157c2016-09-16 13:49:30 +01002525
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002526 ExtraICState GetExtraICState() const final {
2527 return static_cast<ExtraICState>(minor_key_);
2528 }
2529
2530 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreIC);
2531 DEFINE_PLATFORM_CODE_STUB(VectorKeyedStoreIC, PlatformCodeStub);
2532
2533 protected:
2534 void GenerateImpl(MacroAssembler* masm, bool in_frame);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002535};
2536
2537
2538class DoubleToIStub : public PlatformCodeStub {
2539 public:
2540 DoubleToIStub(Isolate* isolate, Register source, Register destination,
2541 int offset, bool is_truncating, bool skip_fastpath = false)
2542 : PlatformCodeStub(isolate) {
2543 minor_key_ = SourceRegisterBits::encode(source.code()) |
2544 DestinationRegisterBits::encode(destination.code()) |
2545 OffsetBits::encode(offset) |
2546 IsTruncatingBits::encode(is_truncating) |
2547 SkipFastPathBits::encode(skip_fastpath) |
2548 SSE3Bits::encode(CpuFeatures::IsSupported(SSE3) ? 1 : 0);
2549 }
2550
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002551 bool SometimesSetsUpAFrame() override { return false; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002552
2553 private:
2554 Register source() const {
2555 return Register::from_code(SourceRegisterBits::decode(minor_key_));
2556 }
2557 Register destination() const {
2558 return Register::from_code(DestinationRegisterBits::decode(minor_key_));
2559 }
2560 bool is_truncating() const { return IsTruncatingBits::decode(minor_key_); }
2561 bool skip_fastpath() const { return SkipFastPathBits::decode(minor_key_); }
2562 int offset() const { return OffsetBits::decode(minor_key_); }
2563
2564 static const int kBitsPerRegisterNumber = 6;
2565 STATIC_ASSERT((1L << kBitsPerRegisterNumber) >= Register::kNumRegisters);
2566 class SourceRegisterBits:
2567 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT
2568 class DestinationRegisterBits:
2569 public BitField<int, kBitsPerRegisterNumber,
2570 kBitsPerRegisterNumber> {}; // NOLINT
2571 class IsTruncatingBits:
2572 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT
2573 class OffsetBits:
2574 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT
2575 class SkipFastPathBits:
2576 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT
2577 class SSE3Bits:
2578 public BitField<int, 2 * kBitsPerRegisterNumber + 5, 1> {}; // NOLINT
2579
2580 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2581 DEFINE_PLATFORM_CODE_STUB(DoubleToI, PlatformCodeStub);
2582};
2583
2584
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002585class ScriptContextFieldStub : public HandlerStub {
2586 public:
2587 ScriptContextFieldStub(Isolate* isolate,
2588 const ScriptContextTable::LookupResult* lookup_result)
2589 : HandlerStub(isolate) {
2590 DCHECK(Accepted(lookup_result));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002591 STATIC_ASSERT(kContextIndexBits + kSlotIndexBits <= kSubMinorKeyBits);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002592 set_sub_minor_key(ContextIndexBits::encode(lookup_result->context_index) |
2593 SlotIndexBits::encode(lookup_result->slot_index));
2594 }
2595
2596 int context_index() const {
2597 return ContextIndexBits::decode(sub_minor_key());
2598 }
2599
2600 int slot_index() const { return SlotIndexBits::decode(sub_minor_key()); }
2601
2602 static bool Accepted(const ScriptContextTable::LookupResult* lookup_result) {
2603 return ContextIndexBits::is_valid(lookup_result->context_index) &&
2604 SlotIndexBits::is_valid(lookup_result->slot_index);
2605 }
2606
2607 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002608 static const int kContextIndexBits = 9;
Ben Murdochc5610432016-08-08 18:44:38 +01002609 static const int kSlotIndexBits = 12;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002610 class ContextIndexBits : public BitField<int, 0, kContextIndexBits> {};
2611 class SlotIndexBits
2612 : public BitField<int, kContextIndexBits, kSlotIndexBits> {};
2613
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002614 DEFINE_CODE_STUB_BASE(ScriptContextFieldStub, HandlerStub);
2615};
2616
2617
2618class LoadScriptContextFieldStub : public ScriptContextFieldStub {
2619 public:
2620 LoadScriptContextFieldStub(
2621 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2622 : ScriptContextFieldStub(isolate, lookup_result) {}
2623
2624 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002625 Code::Kind kind() const override { return Code::LOAD_IC; }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002626
2627 DEFINE_HANDLER_CODE_STUB(LoadScriptContextField, ScriptContextFieldStub);
2628};
2629
2630
2631class StoreScriptContextFieldStub : public ScriptContextFieldStub {
2632 public:
2633 StoreScriptContextFieldStub(
2634 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2635 : ScriptContextFieldStub(isolate, lookup_result) {}
2636
2637 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002638 Code::Kind kind() const override { return Code::STORE_IC; }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002639
2640 DEFINE_HANDLER_CODE_STUB(StoreScriptContextField, ScriptContextFieldStub);
2641};
2642
2643
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002644class LoadFastElementStub : public HandlerStub {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002645 public:
2646 LoadFastElementStub(Isolate* isolate, bool is_js_array,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002647 ElementsKind elements_kind,
2648 bool convert_hole_to_undefined = false)
2649 : HandlerStub(isolate) {
2650 set_sub_minor_key(
2651 ElementsKindBits::encode(elements_kind) |
2652 IsJSArrayBits::encode(is_js_array) |
2653 CanConvertHoleToUndefined::encode(convert_hole_to_undefined));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002654 }
2655
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002656 Code::Kind kind() const override { return Code::KEYED_LOAD_IC; }
2657
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002658 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002659 bool convert_hole_to_undefined() const {
2660 return CanConvertHoleToUndefined::decode(sub_minor_key());
2661 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002662
2663 ElementsKind elements_kind() const {
2664 return ElementsKindBits::decode(sub_minor_key());
2665 }
2666
2667 private:
2668 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2669 class IsJSArrayBits: public BitField<bool, 8, 1> {};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002670 class CanConvertHoleToUndefined : public BitField<bool, 9, 1> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002671
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002672 DEFINE_HANDLER_CODE_STUB(LoadFastElement, HandlerStub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002673};
2674
2675
2676class StoreFastElementStub : public HydrogenCodeStub {
2677 public:
2678 StoreFastElementStub(Isolate* isolate, bool is_js_array,
2679 ElementsKind elements_kind, KeyedAccessStoreMode mode)
2680 : HydrogenCodeStub(isolate) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002681 set_sub_minor_key(CommonStoreModeBits::encode(mode) |
2682 ElementsKindBits::encode(elements_kind) |
2683 IsJSArrayBits::encode(is_js_array));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002684 }
2685
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002686 static void GenerateAheadOfTime(Isolate* isolate);
2687
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002688 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2689
2690 ElementsKind elements_kind() const {
2691 return ElementsKindBits::decode(sub_minor_key());
2692 }
2693
2694 KeyedAccessStoreMode store_mode() const {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002695 return CommonStoreModeBits::decode(sub_minor_key());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002696 }
2697
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002698 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
2699 return VectorStoreICDescriptor(isolate());
2700 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002701
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002702 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
2703
2704 private:
2705 class ElementsKindBits : public BitField<ElementsKind, 3, 8> {};
2706 class IsJSArrayBits : public BitField<bool, 11, 1> {};
2707
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002708 DEFINE_HYDROGEN_CODE_STUB(StoreFastElement, HydrogenCodeStub);
2709};
2710
2711
2712class TransitionElementsKindStub : public HydrogenCodeStub {
2713 public:
Ben Murdoch61f157c2016-09-16 13:49:30 +01002714 TransitionElementsKindStub(Isolate* isolate, ElementsKind from_kind,
2715 ElementsKind to_kind)
2716 : HydrogenCodeStub(isolate) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002717 set_sub_minor_key(FromKindBits::encode(from_kind) |
Ben Murdoch61f157c2016-09-16 13:49:30 +01002718 ToKindBits::encode(to_kind));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002719 }
2720
2721 ElementsKind from_kind() const {
2722 return FromKindBits::decode(sub_minor_key());
2723 }
2724
2725 ElementsKind to_kind() const { return ToKindBits::decode(sub_minor_key()); }
2726
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002727 private:
2728 class FromKindBits: public BitField<ElementsKind, 8, 8> {};
2729 class ToKindBits: public BitField<ElementsKind, 0, 8> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002730
2731 DEFINE_CALL_INTERFACE_DESCRIPTOR(TransitionElementsKind);
2732 DEFINE_HYDROGEN_CODE_STUB(TransitionElementsKind, HydrogenCodeStub);
2733};
2734
Ben Murdochda12d292016-06-02 14:46:10 +01002735class AllocateHeapNumberStub : public TurboFanCodeStub {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002736 public:
2737 explicit AllocateHeapNumberStub(Isolate* isolate)
Ben Murdochda12d292016-06-02 14:46:10 +01002738 : TurboFanCodeStub(isolate) {}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002739
Ben Murdochda12d292016-06-02 14:46:10 +01002740 void InitializeDescriptor(CodeStubDescriptor* descriptor) override;
Ben Murdochc5610432016-08-08 18:44:38 +01002741 void GenerateAssembly(CodeStubAssembler* assembler) const override;
Ben Murdochda12d292016-06-02 14:46:10 +01002742
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002743 DEFINE_CALL_INTERFACE_DESCRIPTOR(AllocateHeapNumber);
Ben Murdochda12d292016-06-02 14:46:10 +01002744 DEFINE_CODE_STUB(AllocateHeapNumber, TurboFanCodeStub);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002745};
2746
Ben Murdochda12d292016-06-02 14:46:10 +01002747#define SIMD128_ALLOC_STUB(TYPE, Type, type, lane_count, lane_type) \
2748 class Allocate##Type##Stub : public TurboFanCodeStub { \
2749 public: \
2750 explicit Allocate##Type##Stub(Isolate* isolate) \
2751 : TurboFanCodeStub(isolate) {} \
2752 \
2753 void InitializeDescriptor(CodeStubDescriptor* descriptor) override; \
Ben Murdochc5610432016-08-08 18:44:38 +01002754 void GenerateAssembly(CodeStubAssembler* assembler) const override; \
Ben Murdochda12d292016-06-02 14:46:10 +01002755 \
2756 DEFINE_CALL_INTERFACE_DESCRIPTOR(Allocate##Type); \
2757 DEFINE_CODE_STUB(Allocate##Type, TurboFanCodeStub); \
2758 };
2759SIMD128_TYPES(SIMD128_ALLOC_STUB)
2760#undef SIMD128_ALLOC_STUB
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002761
Ben Murdochc5610432016-08-08 18:44:38 +01002762class CommonArrayConstructorStub : public TurboFanCodeStub {
2763 protected:
2764 CommonArrayConstructorStub(Isolate* isolate, ElementsKind kind,
2765 AllocationSiteOverrideMode override_mode)
2766 : TurboFanCodeStub(isolate) {
2767 // It only makes sense to override local allocation site behavior
2768 // if there is a difference between the global allocation site policy
2769 // for an ElementsKind and the desired usage of the stub.
2770 DCHECK(override_mode != DISABLE_ALLOCATION_SITES ||
2771 AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE);
2772 set_sub_minor_key(ElementsKindBits::encode(kind) |
2773 AllocationSiteOverrideModeBits::encode(override_mode));
2774 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002775
Ben Murdochc5610432016-08-08 18:44:38 +01002776 void set_sub_minor_key(uint32_t key) { minor_key_ = key; }
2777
2778 uint32_t sub_minor_key() const { return minor_key_; }
2779
2780 CommonArrayConstructorStub(uint32_t key, Isolate* isolate)
2781 : TurboFanCodeStub(key, isolate) {}
2782
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002783 public:
Ben Murdochc5610432016-08-08 18:44:38 +01002784 ElementsKind elements_kind() const {
2785 return ElementsKindBits::decode(sub_minor_key());
2786 }
2787
2788 AllocationSiteOverrideMode override_mode() const {
2789 return AllocationSiteOverrideModeBits::decode(sub_minor_key());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002790 }
2791
Ben Murdoch61f157c2016-09-16 13:49:30 +01002792 static void GenerateStubsAheadOfTime(Isolate* isolate);
2793
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002794 private:
Ben Murdochc5610432016-08-08 18:44:38 +01002795 // Ensure data fits within available bits.
2796 STATIC_ASSERT(LAST_ALLOCATION_SITE_OVERRIDE_MODE == 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002797
Ben Murdochc5610432016-08-08 18:44:38 +01002798 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
2799 class AllocationSiteOverrideModeBits
2800 : public BitField<AllocationSiteOverrideMode, 8, 1> {}; // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002801};
2802
Ben Murdochc5610432016-08-08 18:44:38 +01002803class ArrayNoArgumentConstructorStub : public CommonArrayConstructorStub {
2804 public:
2805 ArrayNoArgumentConstructorStub(
2806 Isolate* isolate, ElementsKind kind,
2807 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2808 : CommonArrayConstructorStub(isolate, kind, override_mode) {}
2809
2810 private:
2811 void PrintName(std::ostream& os) const override { // NOLINT
2812 os << "ArrayNoArgumentConstructorStub";
2813 }
2814
2815 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayNoArgumentConstructor);
2816 DEFINE_TURBOFAN_CODE_STUB(ArrayNoArgumentConstructor,
2817 CommonArrayConstructorStub);
2818};
2819
2820class InternalArrayNoArgumentConstructorStub
2821 : public CommonArrayConstructorStub {
2822 public:
2823 InternalArrayNoArgumentConstructorStub(Isolate* isolate, ElementsKind kind)
2824 : CommonArrayConstructorStub(isolate, kind, DONT_OVERRIDE) {}
2825
2826 private:
2827 void PrintName(std::ostream& os) const override { // NOLINT
2828 os << "InternalArrayNoArgumentConstructorStub";
2829 }
2830
2831 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayNoArgumentConstructor);
2832 DEFINE_TURBOFAN_CODE_STUB(InternalArrayNoArgumentConstructor,
2833 CommonArrayConstructorStub);
2834};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002835
Ben Murdoch61f157c2016-09-16 13:49:30 +01002836class ArraySingleArgumentConstructorStub : public CommonArrayConstructorStub {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002837 public:
2838 ArraySingleArgumentConstructorStub(
Ben Murdoch61f157c2016-09-16 13:49:30 +01002839 Isolate* isolate, ElementsKind kind,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002840 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
Ben Murdoch61f157c2016-09-16 13:49:30 +01002841 : CommonArrayConstructorStub(isolate, kind, override_mode) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002842
2843 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002844 void PrintName(std::ostream& os) const override { // NOLINT
Ben Murdoch61f157c2016-09-16 13:49:30 +01002845 os << "ArraySingleArgumentConstructorStub";
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002846 }
2847
Ben Murdoch61f157c2016-09-16 13:49:30 +01002848 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArraySingleArgumentConstructor);
2849 DEFINE_TURBOFAN_CODE_STUB(ArraySingleArgumentConstructor,
2850 CommonArrayConstructorStub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002851};
2852
Ben Murdoch61f157c2016-09-16 13:49:30 +01002853class InternalArraySingleArgumentConstructorStub
2854 : public CommonArrayConstructorStub {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002855 public:
2856 InternalArraySingleArgumentConstructorStub(Isolate* isolate,
2857 ElementsKind kind)
Ben Murdoch61f157c2016-09-16 13:49:30 +01002858 : CommonArrayConstructorStub(isolate, kind, DONT_OVERRIDE) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002859
Ben Murdoch61f157c2016-09-16 13:49:30 +01002860 private:
2861 void PrintName(std::ostream& os) const override { // NOLINT
2862 os << "InternalArraySingleArgumentConstructorStub";
2863 }
2864
2865 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArraySingleArgumentConstructor);
2866 DEFINE_TURBOFAN_CODE_STUB(InternalArraySingleArgumentConstructor,
2867 CommonArrayConstructorStub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002868};
2869
Ben Murdoch61f157c2016-09-16 13:49:30 +01002870class ArrayNArgumentsConstructorStub : public PlatformCodeStub {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002871 public:
Ben Murdoch61f157c2016-09-16 13:49:30 +01002872 explicit ArrayNArgumentsConstructorStub(Isolate* isolate)
2873 : PlatformCodeStub(isolate) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002874
Ben Murdoch61f157c2016-09-16 13:49:30 +01002875 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
2876 return ArrayNArgumentsConstructorDescriptor(isolate());
2877 }
2878
2879 private:
2880 DEFINE_PLATFORM_CODE_STUB(ArrayNArgumentsConstructor, PlatformCodeStub);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002881};
2882
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002883class StoreElementStub : public PlatformCodeStub {
2884 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002885 StoreElementStub(Isolate* isolate, ElementsKind elements_kind,
2886 KeyedAccessStoreMode mode)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002887 : PlatformCodeStub(isolate) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01002888 // TODO(jkummerow): Rename this stub to StoreSlowElementStub,
2889 // drop elements_kind parameter.
2890 DCHECK_EQ(DICTIONARY_ELEMENTS, elements_kind);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002891 minor_key_ = ElementsKindBits::encode(elements_kind) |
2892 CommonStoreModeBits::encode(mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002893 }
2894
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002895 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
2896 return VectorStoreICDescriptor(isolate());
2897 }
2898
2899 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
2900
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002901 private:
2902 ElementsKind elements_kind() const {
2903 return ElementsKindBits::decode(minor_key_);
2904 }
2905
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002906 class ElementsKindBits : public BitField<ElementsKind, 3, 8> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002907
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002908 DEFINE_PLATFORM_CODE_STUB(StoreElement, PlatformCodeStub);
2909};
2910
Ben Murdochda12d292016-06-02 14:46:10 +01002911class ToBooleanICStub : public HydrogenCodeStub {
Ben Murdoch257744e2011-11-30 15:57:28 +00002912 public:
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002913 enum Type {
2914 UNDEFINED,
2915 BOOLEAN,
2916 NULL_TYPE,
2917 SMI,
2918 SPEC_OBJECT,
2919 STRING,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002920 SYMBOL,
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002921 HEAP_NUMBER,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002922 SIMD_VALUE,
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002923 NUMBER_OF_TYPES
2924 };
2925
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002926 // At most 16 different types can be distinguished, because the Code object
2927 // only has room for two bytes to hold a set of these types. :-P
2928 STATIC_ASSERT(NUMBER_OF_TYPES <= 16);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002929
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002930 class Types : public EnumSet<Type, uint16_t> {
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002931 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002932 Types() : EnumSet<Type, uint16_t>(0) {}
2933 explicit Types(uint16_t bits) : EnumSet<Type, uint16_t>(bits) {}
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002934
Ben Murdoch61f157c2016-09-16 13:49:30 +01002935 bool UpdateStatus(Isolate* isolate, Handle<Object> object);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002936 bool NeedsMap() const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002937 bool CanBeUndetectable() const {
Ben Murdochda12d292016-06-02 14:46:10 +01002938 return Contains(ToBooleanICStub::SPEC_OBJECT);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002939 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002940 bool IsGeneric() const { return ToIntegral() == Generic().ToIntegral(); }
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002941
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002942 static Types Generic() { return Types((1 << NUMBER_OF_TYPES) - 1); }
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002943 };
2944
Ben Murdochda12d292016-06-02 14:46:10 +01002945 ToBooleanICStub(Isolate* isolate, ExtraICState state)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002946 : HydrogenCodeStub(isolate) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002947 set_sub_minor_key(TypesBits::encode(static_cast<uint16_t>(state)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002948 }
Ben Murdoch257744e2011-11-30 15:57:28 +00002949
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002950 bool UpdateStatus(Handle<Object> object);
2951 Types types() const { return Types(TypesBits::decode(sub_minor_key())); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002952
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002953 Code::Kind GetCodeKind() const override { return Code::TO_BOOLEAN_IC; }
2954 void PrintState(std::ostream& os) const override; // NOLINT
Ben Murdoch257744e2011-11-30 15:57:28 +00002955
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002956 bool SometimesSetsUpAFrame() override { return false; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002957
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002958 static Handle<Code> GetUninitialized(Isolate* isolate) {
Ben Murdochda12d292016-06-02 14:46:10 +01002959 return ToBooleanICStub(isolate, UNINITIALIZED).GetCode();
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002960 }
2961
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002962 ExtraICState GetExtraICState() const override { return types().ToIntegral(); }
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002963
Ben Murdoch61f157c2016-09-16 13:49:30 +01002964 InlineCacheState GetICState() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002965 if (types().IsEmpty()) {
2966 return ::v8::internal::UNINITIALIZED;
2967 } else {
2968 return MONOMORPHIC;
2969 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002970 }
2971
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002972 private:
Ben Murdochda12d292016-06-02 14:46:10 +01002973 ToBooleanICStub(Isolate* isolate, InitializationState init_state)
2974 : HydrogenCodeStub(isolate, init_state) {}
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002975
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002976 class TypesBits : public BitField<uint16_t, 0, NUMBER_OF_TYPES> {};
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002977
Ben Murdochda12d292016-06-02 14:46:10 +01002978 DEFINE_CALL_INTERFACE_DESCRIPTOR(TypeConversion);
2979 DEFINE_HYDROGEN_CODE_STUB(ToBooleanIC, HydrogenCodeStub);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002980};
2981
Ben Murdochda12d292016-06-02 14:46:10 +01002982std::ostream& operator<<(std::ostream& os, const ToBooleanICStub::Types& t);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002983
2984class ElementsTransitionAndStoreStub : public HydrogenCodeStub {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002985 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002986 ElementsTransitionAndStoreStub(Isolate* isolate, ElementsKind from_kind,
2987 ElementsKind to_kind, bool is_jsarray,
2988 KeyedAccessStoreMode store_mode)
2989 : HydrogenCodeStub(isolate) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002990 set_sub_minor_key(CommonStoreModeBits::encode(store_mode) |
2991 FromBits::encode(from_kind) | ToBits::encode(to_kind) |
2992 IsJSArrayBits::encode(is_jsarray));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002993 }
2994
2995 ElementsKind from_kind() const { return FromBits::decode(sub_minor_key()); }
2996 ElementsKind to_kind() const { return ToBits::decode(sub_minor_key()); }
2997 bool is_jsarray() const { return IsJSArrayBits::decode(sub_minor_key()); }
2998 KeyedAccessStoreMode store_mode() const {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002999 return CommonStoreModeBits::decode(sub_minor_key());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003000 }
3001
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003002 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override;
3003 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003004
3005 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003006 class FromBits : public BitField<ElementsKind, 3, 8> {};
3007 class ToBits : public BitField<ElementsKind, 11, 8> {};
3008 class IsJSArrayBits : public BitField<bool, 19, 1> {};
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003009
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003010 DEFINE_HYDROGEN_CODE_STUB(ElementsTransitionAndStore, HydrogenCodeStub);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003011};
3012
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003013
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003014class StubFailureTrampolineStub : public PlatformCodeStub {
3015 public:
3016 StubFailureTrampolineStub(Isolate* isolate, StubFunctionMode function_mode)
3017 : PlatformCodeStub(isolate) {
3018 minor_key_ = FunctionModeField::encode(function_mode);
3019 }
3020
3021 static void GenerateAheadOfTime(Isolate* isolate);
3022
3023 private:
3024 StubFunctionMode function_mode() const {
3025 return FunctionModeField::decode(minor_key_);
3026 }
3027
3028 class FunctionModeField : public BitField<StubFunctionMode, 0, 1> {};
3029
3030 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
3031 DEFINE_PLATFORM_CODE_STUB(StubFailureTrampoline, PlatformCodeStub);
3032};
3033
3034
3035class ProfileEntryHookStub : public PlatformCodeStub {
3036 public:
3037 explicit ProfileEntryHookStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3038
3039 // The profile entry hook function is not allowed to cause a GC.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003040 bool SometimesSetsUpAFrame() override { return false; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003041
3042 // Generates a call to the entry hook if it's enabled.
3043 static void MaybeCallEntryHook(MacroAssembler* masm);
3044
3045 private:
3046 static void EntryHookTrampoline(intptr_t function,
3047 intptr_t stack_pointer,
3048 Isolate* isolate);
3049
3050 // ProfileEntryHookStub is called at the start of a function, so it has the
3051 // same register set.
3052 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction)
3053 DEFINE_PLATFORM_CODE_STUB(ProfileEntryHook, PlatformCodeStub);
3054};
3055
3056
3057class StoreBufferOverflowStub : public PlatformCodeStub {
3058 public:
3059 StoreBufferOverflowStub(Isolate* isolate, SaveFPRegsMode save_fp)
3060 : PlatformCodeStub(isolate) {
3061 minor_key_ = SaveDoublesBits::encode(save_fp == kSaveFPRegs);
3062 }
3063
3064 static void GenerateFixedRegStubsAheadOfTime(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003065 bool SometimesSetsUpAFrame() override { return false; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003066
3067 private:
3068 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
3069
3070 class SaveDoublesBits : public BitField<bool, 0, 1> {};
3071
3072 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
3073 DEFINE_PLATFORM_CODE_STUB(StoreBufferOverflow, PlatformCodeStub);
3074};
3075
3076
3077class SubStringStub : public PlatformCodeStub {
3078 public:
3079 explicit SubStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3080
Ben Murdoch61f157c2016-09-16 13:49:30 +01003081 DEFINE_ON_STACK_CALL_INTERFACE_DESCRIPTOR(3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003082 DEFINE_PLATFORM_CODE_STUB(SubString, PlatformCodeStub);
3083};
3084
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003085class ToStringStub final : public PlatformCodeStub {
3086 public:
3087 explicit ToStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3088
Ben Murdochda12d292016-06-02 14:46:10 +01003089 DEFINE_CALL_INTERFACE_DESCRIPTOR(TypeConversion);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003090 DEFINE_PLATFORM_CODE_STUB(ToString, PlatformCodeStub);
3091};
3092
Ben Murdoch097c5b22016-05-18 11:27:45 +01003093class ToNameStub final : public PlatformCodeStub {
3094 public:
3095 explicit ToNameStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3096
Ben Murdochda12d292016-06-02 14:46:10 +01003097 DEFINE_CALL_INTERFACE_DESCRIPTOR(TypeConversion);
Ben Murdoch097c5b22016-05-18 11:27:45 +01003098 DEFINE_PLATFORM_CODE_STUB(ToName, PlatformCodeStub);
3099};
3100
3101
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003102class ToObjectStub final : public HydrogenCodeStub {
3103 public:
3104 explicit ToObjectStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
3105
Ben Murdochda12d292016-06-02 14:46:10 +01003106 DEFINE_CALL_INTERFACE_DESCRIPTOR(TypeConversion);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003107 DEFINE_HYDROGEN_CODE_STUB(ToObject, HydrogenCodeStub);
3108};
3109
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003110#undef DEFINE_CALL_INTERFACE_DESCRIPTOR
3111#undef DEFINE_PLATFORM_CODE_STUB
3112#undef DEFINE_HANDLER_CODE_STUB
3113#undef DEFINE_HYDROGEN_CODE_STUB
3114#undef DEFINE_CODE_STUB
3115#undef DEFINE_CODE_STUB_BASE
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003116
3117extern Representation RepresentationFromType(Type* type);
3118
3119} // namespace internal
3120} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00003121
3122#endif // V8_CODE_STUBS_H_