1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef V8_CODE_STUBS_H_
6 #define V8_CODE_STUBS_H_
8 #include "src/allocation.h"
9 #include "src/assembler.h"
10 #include "src/codegen.h"
11 #include "src/globals.h"
12 #include "src/ic/ic-state.h"
13 #include "src/interface-descriptors.h"
14 #include "src/macro-assembler.h"
15 #include "src/ostreams.h"
20 // List of code stubs used on all platforms.
21 #define CODE_STUB_LIST_ALL_PLATFORMS(V) \
22 /* PlatformCodeStubs */ \
25 V(BinaryOpICWithAllocationSite) \
36 V(FunctionPrototype) \
38 V(InternalArrayConstructor) \
40 V(KeyedLoadICTrampoline) \
43 V(CallIC_ArrayTrampoline) \
44 V(LoadIndexedInterceptor) \
45 V(LoadIndexedString) \
50 V(StoreArrayLiteralElement) \
51 V(StoreBufferOverflow) \
54 V(StubFailureTrampoline) \
57 V(VectorStoreICTrampoline) \
58 V(VectorKeyedStoreICTrampoline) \
60 V(VectorKeyedStoreIC) \
61 /* HydrogenCodeStubs */ \
62 V(AllocateHeapNumber) \
63 V(ArrayNArgumentsConstructor) \
64 V(ArrayNoArgumentConstructor) \
65 V(ArraySingleArgumentConstructor) \
67 V(BinaryOpWithAllocationSite) \
69 V(CreateAllocationSite) \
71 V(ElementsTransitionAndStore) \
72 V(FastCloneShallowArray) \
73 V(FastCloneShallowObject) \
76 V(GrowArrayElements) \
77 V(InternalArrayNArgumentsConstructor) \
78 V(InternalArrayNoArgumentConstructor) \
79 V(InternalArraySingleArgumentConstructor) \
81 V(LoadGlobalViaContext) \
82 V(LoadScriptContextField) \
83 V(LoadDictionaryElement) \
84 V(NameDictionaryLookup) \
87 V(RegExpConstructResult) \
89 V(StoreGlobalViaContext) \
90 V(StoreScriptContextField) \
93 V(TransitionElementsKind) \
96 /* TurboFanCodeStubs */ \
101 /* IC Handler stubs */ \
102 V(ArrayBufferViewLoadField) \
106 V(KeyedLoadSloppyArguments) \
107 V(KeyedStoreSloppyArguments) \
114 // List of code stubs only used on ARM 32 bits platforms.
115 #if V8_TARGET_ARCH_ARM
116 #define CODE_STUB_LIST_ARM(V) V(DirectCEntry)
119 #define CODE_STUB_LIST_ARM(V)
122 // List of code stubs only used on ARM 64 bits platforms.
123 #if V8_TARGET_ARCH_ARM64
124 #define CODE_STUB_LIST_ARM64(V) \
126 V(RestoreRegistersState) \
127 V(StoreRegistersState)
130 #define CODE_STUB_LIST_ARM64(V)
133 // List of code stubs only used on PPC platforms.
134 #ifdef V8_TARGET_ARCH_PPC
135 #define CODE_STUB_LIST_PPC(V) \
137 V(StoreRegistersState) \
138 V(RestoreRegistersState)
140 #define CODE_STUB_LIST_PPC(V)
143 // List of code stubs only used on MIPS platforms.
144 #if V8_TARGET_ARCH_MIPS
145 #define CODE_STUB_LIST_MIPS(V) \
147 V(RestoreRegistersState) \
148 V(StoreRegistersState)
149 #elif V8_TARGET_ARCH_MIPS64
150 #define CODE_STUB_LIST_MIPS(V) \
152 V(RestoreRegistersState) \
153 V(StoreRegistersState)
155 #define CODE_STUB_LIST_MIPS(V)
158 // Combined list of code stubs.
159 #define CODE_STUB_LIST(V) \
160 CODE_STUB_LIST_ALL_PLATFORMS(V) \
161 CODE_STUB_LIST_ARM(V) \
162 CODE_STUB_LIST_ARM64(V) \
163 CODE_STUB_LIST_PPC(V) \
164 CODE_STUB_LIST_MIPS(V)
166 static const int kHasReturnedMinusZeroSentinel = 1;
168 // Stub is base classes of all stubs.
169 class CodeStub BASE_EMBEDDED {
172 // TODO(mvstanton): eliminate the NoCache key by getting rid
173 // of the non-monomorphic-cache.
174 NoCache = 0, // marker for stubs that do custom caching]
175 #define DEF_ENUM(name) name,
176 CODE_STUB_LIST(DEF_ENUM)
181 // Retrieve the code for the stub. Generate the code if needed.
182 Handle<Code> GetCode();
184 // Retrieve the code for the stub, make and return a copy of the code.
185 Handle<Code> GetCodeCopy(const Code::FindAndReplacePattern& pattern);
187 static Major MajorKeyFromKey(uint32_t key) {
188 return static_cast<Major>(MajorKeyBits::decode(key));
190 static uint32_t MinorKeyFromKey(uint32_t key) {
191 return MinorKeyBits::decode(key);
194 // Gets the major key from a code object that is a code stub or binary op IC.
195 static Major GetMajorKey(Code* code_stub) {
196 return MajorKeyFromKey(code_stub->stub_key());
199 static uint32_t NoCacheKey() { return MajorKeyBits::encode(NoCache); }
201 static const char* MajorName(Major major_key, bool allow_unknown_keys);
203 explicit CodeStub(Isolate* isolate) : minor_key_(0), isolate_(isolate) {}
204 virtual ~CodeStub() {}
206 static void GenerateStubsAheadOfTime(Isolate* isolate);
207 static void GenerateFPStubs(Isolate* isolate);
209 // Some stubs put untagged junk on the stack that cannot be scanned by the
210 // GC. This means that we must be statically sure that no GC can occur while
211 // they are running. If that is the case they should override this to return
212 // true, which will cause an assertion if we try to call something that can
213 // GC or if we try to put a stack frame on top of the junk, which would not
214 // result in a traversable stack.
215 virtual bool SometimesSetsUpAFrame() { return true; }
217 // Lookup the code in the (possibly custom) cache.
218 bool FindCodeInCache(Code** code_out);
220 virtual CallInterfaceDescriptor GetCallInterfaceDescriptor() const = 0;
222 virtual int GetStackParameterCount() const {
223 return GetCallInterfaceDescriptor().GetStackParameterCount();
226 virtual void InitializeDescriptor(CodeStubDescriptor* descriptor) {}
228 static void InitializeDescriptor(Isolate* isolate, uint32_t key,
229 CodeStubDescriptor* desc);
231 static MaybeHandle<Code> GetCode(Isolate* isolate, uint32_t key);
233 // Returns information for computing the number key.
234 virtual Major MajorKey() const = 0;
235 uint32_t MinorKey() const { return minor_key_; }
237 // BinaryOpStub needs to override this.
238 virtual Code::Kind GetCodeKind() const;
240 virtual InlineCacheState GetICState() const { return UNINITIALIZED; }
241 virtual ExtraICState GetExtraICState() const { return kNoExtraICState; }
242 virtual Code::StubType GetStubType() const { return Code::NORMAL; }
244 friend std::ostream& operator<<(std::ostream& os, const CodeStub& s) {
249 Isolate* isolate() const { return isolate_; }
252 CodeStub(uint32_t key, Isolate* isolate)
253 : minor_key_(MinorKeyFromKey(key)), isolate_(isolate) {}
255 // Generates the assembler code for the stub.
256 virtual Handle<Code> GenerateCode() = 0;
258 // Returns whether the code generated for this stub needs to be allocated as
259 // a fixed (non-moveable) code object.
260 virtual bool NeedsImmovableCode() { return false; }
262 virtual void PrintName(std::ostream& os) const; // NOLINT
263 virtual void PrintBaseName(std::ostream& os) const; // NOLINT
264 virtual void PrintState(std::ostream& os) const { ; } // NOLINT
266 // Computes the key based on major and minor.
268 DCHECK(static_cast<int>(MajorKey()) < NUMBER_OF_IDS);
269 return MinorKeyBits::encode(MinorKey()) | MajorKeyBits::encode(MajorKey());
275 // Perform bookkeeping required after code generation when stub code is
276 // initially generated.
277 void RecordCodeGeneration(Handle<Code> code);
279 // Finish the code object after it has been generated.
280 virtual void FinishCode(Handle<Code> code) { }
282 // Activate newly generated stub. Is called after
283 // registering stub in the stub cache.
284 virtual void Activate(Code* code) { }
286 // Add the code to a specialized cache, specific to an individual
287 // stub type. Please note, this method must add the code object to a
288 // roots object, otherwise we will remove the code during GC.
289 virtual void AddToSpecialCache(Handle<Code> new_object) { }
291 // Find code in a specialized cache, work is delegated to the specific stub.
292 virtual bool FindCodeInSpecialCache(Code** code_out) {
296 // If a stub uses a special cache override this.
297 virtual bool UseSpecialCache() { return false; }
299 // We use this dispatch to statically instantiate the correct code stub for
300 // the given stub key and call the passed function with that code stub.
301 typedef void (*DispatchedCall)(CodeStub* stub, void** value_out);
302 static void Dispatch(Isolate* isolate, uint32_t key, void** value_out,
303 DispatchedCall call);
305 static void GetCodeDispatchCall(CodeStub* stub, void** value_out);
307 STATIC_ASSERT(NUMBER_OF_IDS < (1 << kStubMajorKeyBits));
308 class MajorKeyBits: public BitField<uint32_t, 0, kStubMajorKeyBits> {};
309 class MinorKeyBits: public BitField<uint32_t,
310 kStubMajorKeyBits, kStubMinorKeyBits> {}; // NOLINT
312 friend class BreakPointIterator;
318 // TODO(svenpanne) This class is only used to construct a more or less sensible
319 // CompilationInfo for testing purposes, basically pretending that we are
320 // currently compiling some kind of code stub. Remove this when the pipeline and
321 // testing machinery is restructured in such a way that we don't have to come up
322 // with a CompilationInfo out of thin air, although we only need a few parts of
324 struct FakeStubForTesting : public CodeStub {
325 explicit FakeStubForTesting(Isolate* isolate) : CodeStub(isolate) {}
327 // Only used by pipeline.cc's GetDebugName in DEBUG mode.
328 Major MajorKey() const override { return CodeStub::NoCache; }
330 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
332 return CallInterfaceDescriptor();
335 Handle<Code> GenerateCode() override {
337 return Handle<Code>();
342 #define DEFINE_CODE_STUB_BASE(NAME, SUPER) \
344 NAME(uint32_t key, Isolate* isolate) : SUPER(key, isolate) {} \
347 DISALLOW_COPY_AND_ASSIGN(NAME)
350 #define DEFINE_CODE_STUB(NAME, SUPER) \
352 inline Major MajorKey() const override { return NAME; }; \
353 DEFINE_CODE_STUB_BASE(NAME##Stub, SUPER)
356 #define DEFINE_PLATFORM_CODE_STUB(NAME, SUPER) \
358 void Generate(MacroAssembler* masm) override; \
359 DEFINE_CODE_STUB(NAME, SUPER)
362 #define DEFINE_HYDROGEN_CODE_STUB(NAME, SUPER) \
364 void InitializeDescriptor(CodeStubDescriptor* descriptor) override; \
365 Handle<Code> GenerateCode() override; \
366 DEFINE_CODE_STUB(NAME, SUPER)
368 #define DEFINE_TURBOFAN_CODE_STUB(NAME, SUPER) \
370 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
371 return DESC##Descriptor(isolate()); \
373 DEFINE_CODE_STUB(NAME, SUPER)
375 #define DEFINE_TURBOFAN_IC(NAME, SUPER, DESC) \
377 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
378 if (GetCallMode() == CALL_FROM_OPTIMIZED_CODE) { \
379 return DESC##CallFromOptimizedCodeDescriptor(isolate()); \
381 return DESC##CallFromUnoptimizedCodeDescriptor(isolate()); \
386 DEFINE_CODE_STUB(NAME, SUPER)
388 #define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \
390 Handle<Code> GenerateCode() override; \
391 DEFINE_CODE_STUB(NAME, SUPER)
393 #define DEFINE_CALL_INTERFACE_DESCRIPTOR(NAME) \
395 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
396 return NAME##Descriptor(isolate()); \
399 // There are some code stubs we just can't describe right now with a
400 // CallInterfaceDescriptor. Isolate behavior for those cases with this macro.
401 // An attempt to retrieve a descriptor will fail.
402 #define DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR() \
404 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \
406 return CallInterfaceDescriptor(); \
410 class PlatformCodeStub : public CodeStub {
412 // Retrieve the code for the stub. Generate the code if needed.
413 Handle<Code> GenerateCode() override;
416 explicit PlatformCodeStub(Isolate* isolate) : CodeStub(isolate) {}
418 // Generates the assembler code for the stub.
419 virtual void Generate(MacroAssembler* masm) = 0;
421 DEFINE_CODE_STUB_BASE(PlatformCodeStub, CodeStub);
425 enum StubFunctionMode { NOT_JS_FUNCTION_STUB_MODE, JS_FUNCTION_STUB_MODE };
428 class CodeStubDescriptor {
430 explicit CodeStubDescriptor(CodeStub* stub);
432 CodeStubDescriptor(Isolate* isolate, uint32_t stub_key);
434 void Initialize(Address deoptimization_handler = NULL,
435 int hint_stack_parameter_count = -1,
436 StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
437 void Initialize(Register stack_parameter_count,
438 Address deoptimization_handler = NULL,
439 int hint_stack_parameter_count = -1,
440 StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
442 void SetMissHandler(ExternalReference handler) {
443 miss_handler_ = handler;
444 has_miss_handler_ = true;
445 // Our miss handler infrastructure doesn't currently support
446 // variable stack parameter counts.
447 DCHECK(!stack_parameter_count_.is_valid());
450 void set_call_descriptor(CallInterfaceDescriptor d) { call_descriptor_ = d; }
451 CallInterfaceDescriptor call_descriptor() const { return call_descriptor_; }
453 int GetRegisterParameterCount() const {
454 return call_descriptor().GetRegisterParameterCount();
457 int GetStackParameterCount() const {
458 return call_descriptor().GetStackParameterCount();
461 int GetParameterCount() const {
462 return call_descriptor().GetParameterCount();
465 Register GetRegisterParameter(int index) const {
466 return call_descriptor().GetRegisterParameter(index);
469 Type* GetParameterType(int index) const {
470 return call_descriptor().GetParameterType(index);
473 ExternalReference miss_handler() const {
474 DCHECK(has_miss_handler_);
475 return miss_handler_;
478 bool has_miss_handler() const {
479 return has_miss_handler_;
482 int GetHandlerParameterCount() const {
483 int params = GetParameterCount();
484 if (PassesArgumentsToDeoptimizationHandler()) {
490 int hint_stack_parameter_count() const { return hint_stack_parameter_count_; }
491 Register stack_parameter_count() const { return stack_parameter_count_; }
492 StubFunctionMode function_mode() const { return function_mode_; }
493 Address deoptimization_handler() const { return deoptimization_handler_; }
496 bool PassesArgumentsToDeoptimizationHandler() const {
497 return stack_parameter_count_.is_valid();
500 CallInterfaceDescriptor call_descriptor_;
501 Register stack_parameter_count_;
502 // If hint_stack_parameter_count_ > 0, the code stub can optimize the
503 // return sequence. Default value is -1, which means it is ignored.
504 int hint_stack_parameter_count_;
505 StubFunctionMode function_mode_;
507 Address deoptimization_handler_;
509 ExternalReference miss_handler_;
510 bool has_miss_handler_;
514 class HydrogenCodeStub : public CodeStub {
516 enum InitializationState {
521 template<class SubClass>
522 static Handle<Code> GetUninitialized(Isolate* isolate) {
523 SubClass::GenerateAheadOfTime(isolate);
524 return SubClass().GetCode(isolate);
527 // Retrieve the code for the stub. Generate the code if needed.
528 Handle<Code> GenerateCode() override = 0;
530 bool IsUninitialized() const { return IsMissBits::decode(minor_key_); }
532 Handle<Code> GenerateLightweightMissCode(ExternalReference miss);
534 template<class StateType>
535 void TraceTransition(StateType from, StateType to);
538 explicit HydrogenCodeStub(Isolate* isolate,
539 InitializationState state = INITIALIZED)
540 : CodeStub(isolate) {
541 minor_key_ = IsMissBits::encode(state == UNINITIALIZED);
544 void set_sub_minor_key(uint32_t key) {
545 minor_key_ = SubMinorKeyBits::update(minor_key_, key);
548 uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); }
550 static const int kSubMinorKeyBits = kStubMinorKeyBits - 1;
553 class IsMissBits : public BitField<bool, kSubMinorKeyBits, 1> {};
554 class SubMinorKeyBits : public BitField<int, 0, kSubMinorKeyBits> {};
556 void GenerateLightweightMiss(MacroAssembler* masm, ExternalReference miss);
558 DEFINE_CODE_STUB_BASE(HydrogenCodeStub, CodeStub);
562 class TurboFanCodeStub : public CodeStub {
564 // Retrieve the code for the stub. Generate the code if needed.
565 Handle<Code> GenerateCode() override;
567 virtual int GetStackParameterCount() const override {
568 return GetCallInterfaceDescriptor().GetStackParameterCount();
571 Code::StubType GetStubType() const override { return Code::FAST; }
574 explicit TurboFanCodeStub(Isolate* isolate) : CodeStub(isolate) {}
577 DEFINE_CODE_STUB_BASE(TurboFanCodeStub, CodeStub);
581 class TurboFanIC : public TurboFanCodeStub {
583 enum CallMode { CALL_FROM_UNOPTIMIZED_CODE, CALL_FROM_OPTIMIZED_CODE };
586 explicit TurboFanIC(Isolate* isolate, CallMode mode)
587 : TurboFanCodeStub(isolate) {
588 minor_key_ = CallModeBits::encode(mode);
591 CallMode GetCallMode() const { return CallModeBits::decode(minor_key_); }
593 void set_sub_minor_key(uint32_t key) {
594 minor_key_ = SubMinorKeyBits::update(minor_key_, key);
597 uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); }
599 static const int kSubMinorKeyBits = kStubMinorKeyBits - 1;
602 class CallModeBits : public BitField<CallMode, 0, 1> {};
603 class SubMinorKeyBits : public BitField<int, 1, kSubMinorKeyBits> {};
604 DEFINE_CODE_STUB_BASE(TurboFanIC, TurboFanCodeStub);
608 // Helper interface to prepare to/restore after making runtime calls.
609 class RuntimeCallHelper {
611 virtual ~RuntimeCallHelper() {}
613 virtual void BeforeCall(MacroAssembler* masm) const = 0;
615 virtual void AfterCall(MacroAssembler* masm) const = 0;
618 RuntimeCallHelper() {}
621 DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper);
625 } } // namespace v8::internal
627 #if V8_TARGET_ARCH_IA32
628 #include "src/ia32/code-stubs-ia32.h"
629 #elif V8_TARGET_ARCH_X64
630 #include "src/x64/code-stubs-x64.h"
631 #elif V8_TARGET_ARCH_ARM64
632 #include "src/arm64/code-stubs-arm64.h"
633 #elif V8_TARGET_ARCH_ARM
634 #include "src/arm/code-stubs-arm.h"
635 #elif V8_TARGET_ARCH_PPC
636 #include "src/ppc/code-stubs-ppc.h"
637 #elif V8_TARGET_ARCH_MIPS
638 #include "src/mips/code-stubs-mips.h"
639 #elif V8_TARGET_ARCH_MIPS64
640 #include "src/mips64/code-stubs-mips64.h"
641 #elif V8_TARGET_ARCH_X87
642 #include "src/x87/code-stubs-x87.h"
644 #error Unsupported target architecture.
651 // RuntimeCallHelper implementation used in stubs: enters/leaves a
652 // newly created internal frame before/after the runtime call.
653 class StubRuntimeCallHelper : public RuntimeCallHelper {
655 StubRuntimeCallHelper() {}
657 virtual void BeforeCall(MacroAssembler* masm) const;
659 virtual void AfterCall(MacroAssembler* masm) const;
663 // Trivial RuntimeCallHelper implementation.
664 class NopRuntimeCallHelper : public RuntimeCallHelper {
666 NopRuntimeCallHelper() {}
668 virtual void BeforeCall(MacroAssembler* masm) const {}
670 virtual void AfterCall(MacroAssembler* masm) const {}
674 class MathFloorStub : public TurboFanIC {
676 explicit MathFloorStub(Isolate* isolate, TurboFanIC::CallMode mode)
677 : TurboFanIC(isolate, mode) {}
678 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
679 DEFINE_TURBOFAN_IC(MathFloor, TurboFanIC, MathRoundVariant);
683 class StringLengthTFStub : public TurboFanCodeStub {
685 explicit StringLengthTFStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
687 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
688 InlineCacheState GetICState() const override { return MONOMORPHIC; }
689 ExtraICState GetExtraICState() const override { return Code::LOAD_IC; }
691 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
692 DEFINE_CODE_STUB(StringLengthTF, TurboFanCodeStub);
696 enum StringAddFlags {
697 // Omit both parameter checks.
698 STRING_ADD_CHECK_NONE = 0,
699 // Check left parameter.
700 STRING_ADD_CHECK_LEFT = 1 << 0,
701 // Check right parameter.
702 STRING_ADD_CHECK_RIGHT = 1 << 1,
703 // Check both parameters.
704 STRING_ADD_CHECK_BOTH = STRING_ADD_CHECK_LEFT | STRING_ADD_CHECK_RIGHT
708 std::ostream& operator<<(std::ostream& os, const StringAddFlags& flags);
711 class StringAddTFStub : public TurboFanCodeStub {
713 StringAddTFStub(Isolate* isolate, StringAddFlags flags,
714 PretenureFlag pretenure_flag)
715 : TurboFanCodeStub(isolate) {
716 minor_key_ = StringAddFlagsBits::encode(flags) |
717 PretenureFlagBits::encode(pretenure_flag);
720 StringAddFlags flags() const {
721 return StringAddFlagsBits::decode(MinorKey());
724 PretenureFlag pretenure_flag() const {
725 return PretenureFlagBits::decode(MinorKey());
729 class StringAddFlagsBits : public BitField<StringAddFlags, 0, 2> {};
730 class PretenureFlagBits : public BitField<PretenureFlag, 2, 1> {};
732 void PrintBaseName(std::ostream& os) const override; // NOLINT
734 DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
735 DEFINE_CODE_STUB(StringAddTF, TurboFanCodeStub);
739 class NumberToStringStub final : public HydrogenCodeStub {
741 explicit NumberToStringStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
743 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
744 static const int kNumber = 0;
746 DEFINE_CALL_INTERFACE_DESCRIPTOR(NumberToString);
747 DEFINE_HYDROGEN_CODE_STUB(NumberToString, HydrogenCodeStub);
751 class TypeofStub final : public HydrogenCodeStub {
753 explicit TypeofStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
755 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
756 static const int kObject = 0;
758 static void GenerateAheadOfTime(Isolate* isolate);
760 DEFINE_CALL_INTERFACE_DESCRIPTOR(Typeof);
761 DEFINE_HYDROGEN_CODE_STUB(Typeof, HydrogenCodeStub);
765 class FastNewClosureStub : public HydrogenCodeStub {
767 FastNewClosureStub(Isolate* isolate, LanguageMode language_mode,
769 : HydrogenCodeStub(isolate) {
770 DCHECK(IsValidFunctionKind(kind));
771 set_sub_minor_key(LanguageModeBits::encode(language_mode) |
772 FunctionKindBits::encode(kind));
775 LanguageMode language_mode() const {
776 return LanguageModeBits::decode(sub_minor_key());
779 FunctionKind kind() const {
780 return FunctionKindBits::decode(sub_minor_key());
784 STATIC_ASSERT(LANGUAGE_END == 3);
785 class LanguageModeBits : public BitField<LanguageMode, 0, 2> {};
786 class FunctionKindBits : public BitField<FunctionKind, 2, 8> {};
788 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewClosure);
789 DEFINE_HYDROGEN_CODE_STUB(FastNewClosure, HydrogenCodeStub);
793 class FastNewContextStub final : public HydrogenCodeStub {
795 static const int kMaximumSlots = 64;
797 FastNewContextStub(Isolate* isolate, int slots) : HydrogenCodeStub(isolate) {
798 DCHECK(slots >= 0 && slots <= kMaximumSlots);
799 set_sub_minor_key(SlotsBits::encode(slots));
802 int slots() const { return SlotsBits::decode(sub_minor_key()); }
804 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
805 static const int kFunction = 0;
808 class SlotsBits : public BitField<int, 0, 8> {};
810 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewContext);
811 DEFINE_HYDROGEN_CODE_STUB(FastNewContext, HydrogenCodeStub);
815 class FastCloneShallowArrayStub : public HydrogenCodeStub {
817 FastCloneShallowArrayStub(Isolate* isolate,
818 AllocationSiteMode allocation_site_mode)
819 : HydrogenCodeStub(isolate) {
820 set_sub_minor_key(AllocationSiteModeBits::encode(allocation_site_mode));
823 AllocationSiteMode allocation_site_mode() const {
824 return AllocationSiteModeBits::decode(sub_minor_key());
828 class AllocationSiteModeBits: public BitField<AllocationSiteMode, 0, 1> {};
830 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowArray);
831 DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowArray, HydrogenCodeStub);
835 class FastCloneShallowObjectStub : public HydrogenCodeStub {
837 // Maximum number of properties in copied object.
838 static const int kMaximumClonedProperties = 6;
840 FastCloneShallowObjectStub(Isolate* isolate, int length)
841 : HydrogenCodeStub(isolate) {
842 DCHECK_GE(length, 0);
843 DCHECK_LE(length, kMaximumClonedProperties);
844 set_sub_minor_key(LengthBits::encode(length));
847 int length() const { return LengthBits::decode(sub_minor_key()); }
850 class LengthBits : public BitField<int, 0, 4> {};
852 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowObject);
853 DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowObject, HydrogenCodeStub);
857 class CreateAllocationSiteStub : public HydrogenCodeStub {
859 explicit CreateAllocationSiteStub(Isolate* isolate)
860 : HydrogenCodeStub(isolate) { }
862 static void GenerateAheadOfTime(Isolate* isolate);
864 DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateAllocationSite);
865 DEFINE_HYDROGEN_CODE_STUB(CreateAllocationSite, HydrogenCodeStub);
869 class CreateWeakCellStub : public HydrogenCodeStub {
871 explicit CreateWeakCellStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
873 static void GenerateAheadOfTime(Isolate* isolate);
875 DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateWeakCell);
876 DEFINE_HYDROGEN_CODE_STUB(CreateWeakCell, HydrogenCodeStub);
880 class GrowArrayElementsStub : public HydrogenCodeStub {
882 GrowArrayElementsStub(Isolate* isolate, bool is_js_array, ElementsKind kind)
883 : HydrogenCodeStub(isolate) {
884 set_sub_minor_key(ElementsKindBits::encode(kind) |
885 IsJsArrayBits::encode(is_js_array));
888 ElementsKind elements_kind() const {
889 return ElementsKindBits::decode(sub_minor_key());
892 bool is_js_array() const { return IsJsArrayBits::decode(sub_minor_key()); }
895 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
896 class IsJsArrayBits : public BitField<bool, ElementsKindBits::kNext, 1> {};
898 DEFINE_CALL_INTERFACE_DESCRIPTOR(GrowArrayElements);
899 DEFINE_HYDROGEN_CODE_STUB(GrowArrayElements, HydrogenCodeStub);
902 class InstanceofStub: public PlatformCodeStub {
906 kArgsInRegisters = 1 << 0,
907 kCallSiteInlineCheck = 1 << 1,
908 kReturnTrueFalseObject = 1 << 2
911 InstanceofStub(Isolate* isolate, Flags flags) : PlatformCodeStub(isolate) {
912 minor_key_ = FlagBits::encode(flags);
915 static Register left() { return InstanceofDescriptor::left(); }
916 static Register right() { return InstanceofDescriptor::right(); }
918 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
919 if (HasArgsInRegisters()) {
920 return InstanceofDescriptor(isolate());
922 return ContextOnlyDescriptor(isolate());
926 Flags flags() const { return FlagBits::decode(minor_key_); }
928 bool HasArgsInRegisters() const { return (flags() & kArgsInRegisters) != 0; }
930 bool HasCallSiteInlineCheck() const {
931 return (flags() & kCallSiteInlineCheck) != 0;
934 bool ReturnTrueFalseObject() const {
935 return (flags() & kReturnTrueFalseObject) != 0;
938 void PrintName(std::ostream& os) const override; // NOLINT
940 class FlagBits : public BitField<Flags, 0, 3> {};
942 DEFINE_PLATFORM_CODE_STUB(Instanceof, PlatformCodeStub);
946 enum AllocationSiteOverrideMode {
948 DISABLE_ALLOCATION_SITES,
949 LAST_ALLOCATION_SITE_OVERRIDE_MODE = DISABLE_ALLOCATION_SITES
953 class ArrayConstructorStub: public PlatformCodeStub {
955 enum ArgumentCountKey { ANY, NONE, ONE, MORE_THAN_ONE };
957 ArrayConstructorStub(Isolate* isolate, int argument_count);
959 explicit ArrayConstructorStub(Isolate* isolate);
962 ArgumentCountKey argument_count() const {
963 return ArgumentCountBits::decode(minor_key_);
966 void GenerateDispatchToArrayStub(MacroAssembler* masm,
967 AllocationSiteOverrideMode mode);
969 void PrintName(std::ostream& os) const override; // NOLINT
971 class ArgumentCountBits : public BitField<ArgumentCountKey, 0, 2> {};
973 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
974 DEFINE_PLATFORM_CODE_STUB(ArrayConstructor, PlatformCodeStub);
978 class InternalArrayConstructorStub: public PlatformCodeStub {
980 explicit InternalArrayConstructorStub(Isolate* isolate);
983 void GenerateCase(MacroAssembler* masm, ElementsKind kind);
985 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
986 DEFINE_PLATFORM_CODE_STUB(InternalArrayConstructor, PlatformCodeStub);
990 class MathPowStub: public PlatformCodeStub {
992 enum ExponentType { INTEGER, DOUBLE, TAGGED, ON_STACK };
994 MathPowStub(Isolate* isolate, ExponentType exponent_type)
995 : PlatformCodeStub(isolate) {
996 minor_key_ = ExponentTypeBits::encode(exponent_type);
999 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1000 if (exponent_type() == TAGGED) {
1001 return MathPowTaggedDescriptor(isolate());
1002 } else if (exponent_type() == INTEGER) {
1003 return MathPowIntegerDescriptor(isolate());
1005 // A CallInterfaceDescriptor doesn't specify double registers (yet).
1006 return ContextOnlyDescriptor(isolate());
1010 ExponentType exponent_type() const {
1011 return ExponentTypeBits::decode(minor_key_);
1014 class ExponentTypeBits : public BitField<ExponentType, 0, 2> {};
1016 DEFINE_PLATFORM_CODE_STUB(MathPow, PlatformCodeStub);
1020 class CallICStub: public PlatformCodeStub {
1022 CallICStub(Isolate* isolate, const CallICState& state)
1023 : PlatformCodeStub(isolate) {
1024 minor_key_ = state.GetExtraICState();
1027 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
1029 InlineCacheState GetICState() const override { return DEFAULT; }
1031 ExtraICState GetExtraICState() const final {
1032 return static_cast<ExtraICState>(minor_key_);
1036 bool CallAsMethod() const {
1037 return state().call_type() == CallICState::METHOD;
1040 int arg_count() const { return state().arg_count(); }
1042 CallICState state() const {
1043 return CallICState(static_cast<ExtraICState>(minor_key_));
1046 // Code generation helpers.
1047 void GenerateMiss(MacroAssembler* masm);
1050 void PrintState(std::ostream& os) const override; // NOLINT
1052 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedbackAndVector);
1053 DEFINE_PLATFORM_CODE_STUB(CallIC, PlatformCodeStub);
1057 class CallIC_ArrayStub: public CallICStub {
1059 CallIC_ArrayStub(Isolate* isolate, const CallICState& state_in)
1060 : CallICStub(isolate, state_in) {}
1062 InlineCacheState GetICState() const final { return MONOMORPHIC; }
1065 void PrintState(std::ostream& os) const override; // NOLINT
1067 DEFINE_PLATFORM_CODE_STUB(CallIC_Array, CallICStub);
1071 // TODO(verwaest): Translate to hydrogen code stub.
1072 class FunctionPrototypeStub : public PlatformCodeStub {
1074 explicit FunctionPrototypeStub(Isolate* isolate)
1075 : PlatformCodeStub(isolate) {}
1077 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1079 // TODO(mvstanton): only the receiver register is accessed. When this is
1080 // translated to a hydrogen code stub, a new CallInterfaceDescriptor
1081 // should be created that just uses that register for more efficient code.
1082 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1083 return LoadWithVectorDescriptor(isolate());
1086 DEFINE_PLATFORM_CODE_STUB(FunctionPrototype, PlatformCodeStub);
1090 // TODO(mvstanton): Translate to hydrogen code stub.
1091 class LoadIndexedInterceptorStub : public PlatformCodeStub {
1093 explicit LoadIndexedInterceptorStub(Isolate* isolate)
1094 : PlatformCodeStub(isolate) {}
1096 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1097 Code::StubType GetStubType() const override { return Code::FAST; }
1099 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
1100 DEFINE_PLATFORM_CODE_STUB(LoadIndexedInterceptor, PlatformCodeStub);
1104 class LoadIndexedStringStub : public PlatformCodeStub {
1106 explicit LoadIndexedStringStub(Isolate* isolate)
1107 : PlatformCodeStub(isolate) {}
1109 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1110 Code::StubType GetStubType() const override { return Code::FAST; }
1112 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
1113 DEFINE_PLATFORM_CODE_STUB(LoadIndexedString, PlatformCodeStub);
1117 class HandlerStub : public HydrogenCodeStub {
1119 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1120 ExtraICState GetExtraICState() const override { return kind(); }
1121 InlineCacheState GetICState() const override { return MONOMORPHIC; }
1123 void InitializeDescriptor(CodeStubDescriptor* descriptor) override;
1125 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override;
1128 explicit HandlerStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
1130 virtual Code::Kind kind() const = 0;
1132 DEFINE_CODE_STUB_BASE(HandlerStub, HydrogenCodeStub);
1136 class LoadFieldStub: public HandlerStub {
1138 LoadFieldStub(Isolate* isolate, FieldIndex index) : HandlerStub(isolate) {
1139 int property_index_key = index.GetFieldAccessStubKey();
1140 set_sub_minor_key(LoadFieldByIndexBits::encode(property_index_key));
1143 FieldIndex index() const {
1144 int property_index_key = LoadFieldByIndexBits::decode(sub_minor_key());
1145 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1149 Code::Kind kind() const override { return Code::LOAD_IC; }
1150 Code::StubType GetStubType() const override { return Code::FAST; }
1153 class LoadFieldByIndexBits : public BitField<int, 0, 13> {};
1155 DEFINE_HANDLER_CODE_STUB(LoadField, HandlerStub);
1159 class ArrayBufferViewLoadFieldStub : public HandlerStub {
1161 ArrayBufferViewLoadFieldStub(Isolate* isolate, FieldIndex index)
1162 : HandlerStub(isolate) {
1163 int property_index_key = index.GetFieldAccessStubKey();
1165 ArrayBufferViewLoadFieldByIndexBits::encode(property_index_key));
1168 FieldIndex index() const {
1169 int property_index_key =
1170 ArrayBufferViewLoadFieldByIndexBits::decode(sub_minor_key());
1171 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1175 Code::Kind kind() const override { return Code::LOAD_IC; }
1176 Code::StubType GetStubType() const override { return Code::FAST; }
1179 class ArrayBufferViewLoadFieldByIndexBits : public BitField<int, 0, 13> {};
1181 DEFINE_HANDLER_CODE_STUB(ArrayBufferViewLoadField, HandlerStub);
1185 class KeyedLoadSloppyArgumentsStub : public HandlerStub {
1187 explicit KeyedLoadSloppyArgumentsStub(Isolate* isolate)
1188 : HandlerStub(isolate) {}
1191 Code::Kind kind() const override { return Code::KEYED_LOAD_IC; }
1192 Code::StubType GetStubType() const override { return Code::FAST; }
1195 DEFINE_HANDLER_CODE_STUB(KeyedLoadSloppyArguments, HandlerStub);
1199 class KeyedStoreSloppyArgumentsStub : public HandlerStub {
1201 explicit KeyedStoreSloppyArgumentsStub(Isolate* isolate)
1202 : HandlerStub(isolate) {}
1205 Code::Kind kind() const override { return Code::KEYED_STORE_IC; }
1206 Code::StubType GetStubType() const override { return Code::FAST; }
1209 DEFINE_HANDLER_CODE_STUB(KeyedStoreSloppyArguments, HandlerStub);
1213 class LoadConstantStub : public HandlerStub {
1215 LoadConstantStub(Isolate* isolate, int constant_index)
1216 : HandlerStub(isolate) {
1217 set_sub_minor_key(ConstantIndexBits::encode(constant_index));
1220 int constant_index() const {
1221 return ConstantIndexBits::decode(sub_minor_key());
1225 Code::Kind kind() const override { return Code::LOAD_IC; }
1226 Code::StubType GetStubType() const override { return Code::FAST; }
1229 class ConstantIndexBits : public BitField<int, 0, kSubMinorKeyBits> {};
1231 DEFINE_HANDLER_CODE_STUB(LoadConstant, HandlerStub);
1235 class StringLengthStub: public HandlerStub {
1237 explicit StringLengthStub(Isolate* isolate) : HandlerStub(isolate) {}
1240 Code::Kind kind() const override { return Code::LOAD_IC; }
1241 Code::StubType GetStubType() const override { return Code::FAST; }
1243 DEFINE_HANDLER_CODE_STUB(StringLength, HandlerStub);
1247 class StoreFieldStub : public HandlerStub {
1249 StoreFieldStub(Isolate* isolate, FieldIndex index,
1250 Representation representation)
1251 : HandlerStub(isolate) {
1252 int property_index_key = index.GetFieldAccessStubKey();
1253 uint8_t repr = PropertyDetails::EncodeRepresentation(representation);
1254 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) |
1255 RepresentationBits::encode(repr));
1258 FieldIndex index() const {
1259 int property_index_key = StoreFieldByIndexBits::decode(sub_minor_key());
1260 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1263 Representation representation() {
1264 uint8_t repr = RepresentationBits::decode(sub_minor_key());
1265 return PropertyDetails::DecodeRepresentation(repr);
1269 Code::Kind kind() const override { return Code::STORE_IC; }
1270 Code::StubType GetStubType() const override { return Code::FAST; }
1273 class StoreFieldByIndexBits : public BitField<int, 0, 13> {};
1274 class RepresentationBits : public BitField<uint8_t, 13, 4> {};
1276 DEFINE_HANDLER_CODE_STUB(StoreField, HandlerStub);
1280 class StoreTransitionStub : public HandlerStub {
1285 ExtendStorageAndStoreMapAndValue
1288 explicit StoreTransitionStub(Isolate* isolate) : HandlerStub(isolate) {
1289 set_sub_minor_key(StoreModeBits::encode(StoreMapOnly));
1292 StoreTransitionStub(Isolate* isolate, FieldIndex index,
1293 Representation representation, StoreMode store_mode)
1294 : HandlerStub(isolate) {
1295 DCHECK(store_mode != StoreMapOnly);
1296 int property_index_key = index.GetFieldAccessStubKey();
1297 uint8_t repr = PropertyDetails::EncodeRepresentation(representation);
1298 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) |
1299 RepresentationBits::encode(repr) |
1300 StoreModeBits::encode(store_mode));
1303 FieldIndex index() const {
1304 DCHECK(store_mode() != StoreMapOnly);
1305 int property_index_key = StoreFieldByIndexBits::decode(sub_minor_key());
1306 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1309 Representation representation() {
1310 DCHECK(store_mode() != StoreMapOnly);
1311 uint8_t repr = RepresentationBits::decode(sub_minor_key());
1312 return PropertyDetails::DecodeRepresentation(repr);
1315 StoreMode store_mode() const {
1316 return StoreModeBits::decode(sub_minor_key());
1319 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override;
1322 Code::Kind kind() const override { return Code::STORE_IC; }
1323 Code::StubType GetStubType() const override { return Code::FAST; }
1326 class StoreFieldByIndexBits : public BitField<int, 0, 13> {};
1327 class RepresentationBits : public BitField<uint8_t, 13, 4> {};
1328 class StoreModeBits : public BitField<StoreMode, 17, 2> {};
1330 DEFINE_HANDLER_CODE_STUB(StoreTransition, HandlerStub);
1334 class StoreGlobalStub : public HandlerStub {
1336 StoreGlobalStub(Isolate* isolate, PropertyCellType type,
1337 Maybe<PropertyCellConstantType> constant_type,
1339 : HandlerStub(isolate) {
1340 PropertyCellConstantType encoded_constant_type =
1341 constant_type.FromMaybe(PropertyCellConstantType::kSmi);
1342 set_sub_minor_key(CellTypeBits::encode(type) |
1343 ConstantTypeBits::encode(encoded_constant_type) |
1344 CheckGlobalBits::encode(check_global));
1347 static Handle<HeapObject> property_cell_placeholder(Isolate* isolate) {
1348 return isolate->factory()->uninitialized_value();
1351 static Handle<HeapObject> global_map_placeholder(Isolate* isolate) {
1352 return isolate->factory()->termination_exception();
1355 Handle<Code> GetCodeCopyFromTemplate(Handle<GlobalObject> global,
1356 Handle<PropertyCell> cell) {
1357 Code::FindAndReplacePattern pattern;
1358 if (check_global()) {
1359 pattern.Add(handle(global_map_placeholder(isolate())->map()),
1360 Map::WeakCellForMap(Handle<Map>(global->map())));
1362 pattern.Add(handle(property_cell_placeholder(isolate())->map()),
1363 isolate()->factory()->NewWeakCell(cell));
1364 return CodeStub::GetCodeCopy(pattern);
1367 Code::Kind kind() const override { return Code::STORE_IC; }
1369 PropertyCellType cell_type() const {
1370 return CellTypeBits::decode(sub_minor_key());
1373 PropertyCellConstantType constant_type() const {
1374 DCHECK(PropertyCellType::kConstantType == cell_type());
1375 return ConstantTypeBits::decode(sub_minor_key());
1378 bool check_global() const { return CheckGlobalBits::decode(sub_minor_key()); }
1380 Representation representation() {
1381 return Representation::FromKind(
1382 RepresentationBits::decode(sub_minor_key()));
1385 void set_representation(Representation r) {
1386 set_sub_minor_key(RepresentationBits::update(sub_minor_key(), r.kind()));
1390 class CellTypeBits : public BitField<PropertyCellType, 0, 2> {};
1391 class ConstantTypeBits : public BitField<PropertyCellConstantType, 2, 2> {};
1392 class RepresentationBits : public BitField<Representation::Kind, 4, 8> {};
1393 class CheckGlobalBits : public BitField<bool, 12, 1> {};
1395 DEFINE_HANDLER_CODE_STUB(StoreGlobal, HandlerStub);
1399 class LoadGlobalViaContextStub : public HydrogenCodeStub {
1401 // Use the loop version for depths higher than this one.
1402 static const int kDynamicDepth = 7;
1404 LoadGlobalViaContextStub(Isolate* isolate, int depth)
1405 : HydrogenCodeStub(isolate) {
1406 if (depth > kDynamicDepth) depth = kDynamicDepth;
1407 set_sub_minor_key(DepthBits::encode(depth));
1410 int depth() const { return DepthBits::decode(sub_minor_key()); }
1413 class DepthBits : public BitField<unsigned int, 0, 3> {};
1414 STATIC_ASSERT(kDynamicDepth <= DepthBits::kMax);
1416 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadGlobalViaContext);
1417 DEFINE_HYDROGEN_CODE_STUB(LoadGlobalViaContext, HydrogenCodeStub);
1421 class StoreGlobalViaContextStub : public HydrogenCodeStub {
1423 // Use the loop version for depths higher than this one.
1424 static const int kDynamicDepth = 7;
1426 StoreGlobalViaContextStub(Isolate* isolate, int depth,
1427 LanguageMode language_mode)
1428 : HydrogenCodeStub(isolate) {
1429 if (depth > kDynamicDepth) depth = kDynamicDepth;
1430 set_sub_minor_key(DepthBits::encode(depth) |
1431 LanguageModeBits::encode(language_mode));
1434 int depth() const { return DepthBits::decode(sub_minor_key()); }
1436 LanguageMode language_mode() const {
1437 return LanguageModeBits::decode(sub_minor_key());
1441 class DepthBits : public BitField<unsigned int, 0, 4> {};
1442 STATIC_ASSERT(kDynamicDepth <= DepthBits::kMax);
1444 class LanguageModeBits : public BitField<LanguageMode, 4, 2> {};
1445 STATIC_ASSERT(LANGUAGE_END == 3);
1448 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreGlobalViaContext);
1449 DEFINE_HYDROGEN_CODE_STUB(StoreGlobalViaContext, HydrogenCodeStub);
1453 class CallApiFunctionStub : public PlatformCodeStub {
1455 explicit CallApiFunctionStub(Isolate* isolate, bool call_data_undefined)
1456 : PlatformCodeStub(isolate) {
1457 minor_key_ = CallDataUndefinedBits::encode(call_data_undefined);
1461 bool call_data_undefined() const {
1462 return CallDataUndefinedBits::decode(minor_key_);
1465 class CallDataUndefinedBits : public BitField<bool, 0, 1> {};
1467 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiFunction);
1468 DEFINE_PLATFORM_CODE_STUB(CallApiFunction, PlatformCodeStub);
1472 class CallApiAccessorStub : public PlatformCodeStub {
1474 CallApiAccessorStub(Isolate* isolate, bool is_store, bool call_data_undefined)
1475 : PlatformCodeStub(isolate) {
1476 minor_key_ = IsStoreBits::encode(is_store) |
1477 CallDataUndefinedBits::encode(call_data_undefined) |
1478 ArgumentBits::encode(is_store ? 1 : 0);
1482 // For CallApiFunctionWithFixedArgsStub, see below.
1483 static const int kArgBits = 3;
1484 CallApiAccessorStub(Isolate* isolate, int argc, bool call_data_undefined)
1485 : PlatformCodeStub(isolate) {
1486 minor_key_ = IsStoreBits::encode(false) |
1487 CallDataUndefinedBits::encode(call_data_undefined) |
1488 ArgumentBits::encode(argc);
1492 bool is_store() const { return IsStoreBits::decode(minor_key_); }
1493 bool call_data_undefined() const {
1494 return CallDataUndefinedBits::decode(minor_key_);
1496 int argc() const { return ArgumentBits::decode(minor_key_); }
1498 class IsStoreBits: public BitField<bool, 0, 1> {};
1499 class CallDataUndefinedBits: public BitField<bool, 1, 1> {};
1500 class ArgumentBits : public BitField<int, 2, kArgBits> {};
1502 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiAccessor);
1503 DEFINE_PLATFORM_CODE_STUB(CallApiAccessor, PlatformCodeStub);
1507 // TODO(dcarney): see if it's possible to remove this later without performance
1509 // This is not a real stub, but a way of generating the CallApiAccessorStub
1510 // (which has the same abi) which makes it clear that it is not an accessor.
1511 class CallApiFunctionWithFixedArgsStub : public CallApiAccessorStub {
1513 static const int kMaxFixedArgs = (1 << kArgBits) - 1;
1514 CallApiFunctionWithFixedArgsStub(Isolate* isolate, int argc,
1515 bool call_data_undefined)
1516 : CallApiAccessorStub(isolate, argc, call_data_undefined) {
1517 DCHECK(0 <= argc && argc <= kMaxFixedArgs);
1522 typedef ApiAccessorDescriptor ApiFunctionWithFixedArgsDescriptor;
1525 class CallApiGetterStub : public PlatformCodeStub {
1527 explicit CallApiGetterStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
1529 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiGetter);
1530 DEFINE_PLATFORM_CODE_STUB(CallApiGetter, PlatformCodeStub);
1534 class BinaryOpICStub : public HydrogenCodeStub {
1536 BinaryOpICStub(Isolate* isolate, Token::Value op, Strength strength)
1537 : HydrogenCodeStub(isolate, UNINITIALIZED) {
1538 BinaryOpICState state(isolate, op, strength);
1539 set_sub_minor_key(state.GetExtraICState());
1542 BinaryOpICStub(Isolate* isolate, const BinaryOpICState& state)
1543 : HydrogenCodeStub(isolate) {
1544 set_sub_minor_key(state.GetExtraICState());
1547 static void GenerateAheadOfTime(Isolate* isolate);
1549 Code::Kind GetCodeKind() const override { return Code::BINARY_OP_IC; }
1551 InlineCacheState GetICState() const final { return state().GetICState(); }
1553 ExtraICState GetExtraICState() const final {
1554 return static_cast<ExtraICState>(sub_minor_key());
1557 BinaryOpICState state() const {
1558 return BinaryOpICState(isolate(), GetExtraICState());
1561 void PrintState(std::ostream& os) const final; // NOLINT
1563 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1564 static const int kLeft = 0;
1565 static const int kRight = 1;
1568 static void GenerateAheadOfTime(Isolate* isolate,
1569 const BinaryOpICState& state);
1571 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
1572 DEFINE_HYDROGEN_CODE_STUB(BinaryOpIC, HydrogenCodeStub);
1576 // TODO(bmeurer): Merge this into the BinaryOpICStub once we have proper tail
1577 // call support for stubs in Hydrogen.
1578 class BinaryOpICWithAllocationSiteStub final : public PlatformCodeStub {
1580 BinaryOpICWithAllocationSiteStub(Isolate* isolate,
1581 const BinaryOpICState& state)
1582 : PlatformCodeStub(isolate) {
1583 minor_key_ = state.GetExtraICState();
1586 static void GenerateAheadOfTime(Isolate* isolate);
1588 Handle<Code> GetCodeCopyFromTemplate(Handle<AllocationSite> allocation_site) {
1589 Code::FindAndReplacePattern pattern;
1590 pattern.Add(isolate()->factory()->undefined_map(), allocation_site);
1591 return CodeStub::GetCodeCopy(pattern);
1594 Code::Kind GetCodeKind() const override { return Code::BINARY_OP_IC; }
1596 InlineCacheState GetICState() const override { return state().GetICState(); }
1598 ExtraICState GetExtraICState() const override {
1599 return static_cast<ExtraICState>(minor_key_);
1602 void PrintState(std::ostream& os) const override; // NOLINT
1605 BinaryOpICState state() const {
1606 return BinaryOpICState(isolate(), static_cast<ExtraICState>(minor_key_));
1609 static void GenerateAheadOfTime(Isolate* isolate,
1610 const BinaryOpICState& state);
1612 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithAllocationSite);
1613 DEFINE_PLATFORM_CODE_STUB(BinaryOpICWithAllocationSite, PlatformCodeStub);
1617 class BinaryOpWithAllocationSiteStub final : public BinaryOpICStub {
1619 BinaryOpWithAllocationSiteStub(Isolate* isolate, Token::Value op,
1621 : BinaryOpICStub(isolate, op, strength) {}
1623 BinaryOpWithAllocationSiteStub(Isolate* isolate, const BinaryOpICState& state)
1624 : BinaryOpICStub(isolate, state) {}
1626 Code::Kind GetCodeKind() const final { return Code::STUB; }
1628 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1629 static const int kAllocationSite = 0;
1630 static const int kLeft = 1;
1631 static const int kRight = 2;
1633 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithAllocationSite);
1634 DEFINE_HYDROGEN_CODE_STUB(BinaryOpWithAllocationSite, BinaryOpICStub);
1638 class StringAddStub final : public HydrogenCodeStub {
1640 StringAddStub(Isolate* isolate, StringAddFlags flags,
1641 PretenureFlag pretenure_flag)
1642 : HydrogenCodeStub(isolate) {
1643 set_sub_minor_key(StringAddFlagsBits::encode(flags) |
1644 PretenureFlagBits::encode(pretenure_flag));
1647 StringAddFlags flags() const {
1648 return StringAddFlagsBits::decode(sub_minor_key());
1651 PretenureFlag pretenure_flag() const {
1652 return PretenureFlagBits::decode(sub_minor_key());
1655 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1656 static const int kLeft = 0;
1657 static const int kRight = 1;
1660 class StringAddFlagsBits: public BitField<StringAddFlags, 0, 2> {};
1661 class PretenureFlagBits: public BitField<PretenureFlag, 2, 1> {};
1663 void PrintBaseName(std::ostream& os) const override; // NOLINT
1665 DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
1666 DEFINE_HYDROGEN_CODE_STUB(StringAdd, HydrogenCodeStub);
1670 class CompareICStub : public PlatformCodeStub {
1672 CompareICStub(Isolate* isolate, Token::Value op, Strength strength,
1673 CompareICState::State left, CompareICState::State right,
1674 CompareICState::State state)
1675 : PlatformCodeStub(isolate) {
1676 DCHECK(Token::IsCompareOp(op));
1677 minor_key_ = OpBits::encode(op - Token::EQ) |
1678 StrengthBits::encode(is_strong(strength)) |
1679 LeftStateBits::encode(left) | RightStateBits::encode(right) |
1680 StateBits::encode(state);
1683 void set_known_map(Handle<Map> map) { known_map_ = map; }
1685 InlineCacheState GetICState() const override;
1687 Token::Value op() const {
1688 return static_cast<Token::Value>(Token::EQ + OpBits::decode(minor_key_));
1691 Strength strength() const {
1692 return StrengthBits::decode(minor_key_) ? Strength::STRONG : Strength::WEAK;
1695 CompareICState::State left() const {
1696 return LeftStateBits::decode(minor_key_);
1698 CompareICState::State right() const {
1699 return RightStateBits::decode(minor_key_);
1701 CompareICState::State state() const { return StateBits::decode(minor_key_); }
1704 Code::Kind GetCodeKind() const override { return Code::COMPARE_IC; }
1706 void GenerateSmis(MacroAssembler* masm);
1707 void GenerateNumbers(MacroAssembler* masm);
1708 void GenerateInternalizedStrings(MacroAssembler* masm);
1709 void GenerateStrings(MacroAssembler* masm);
1710 void GenerateUniqueNames(MacroAssembler* masm);
1711 void GenerateObjects(MacroAssembler* masm);
1712 void GenerateMiss(MacroAssembler* masm);
1713 void GenerateKnownObjects(MacroAssembler* masm);
1714 void GenerateGeneric(MacroAssembler* masm);
1716 bool strict() const { return op() == Token::EQ_STRICT; }
1717 Condition GetCondition() const;
1719 void AddToSpecialCache(Handle<Code> new_object) override;
1720 bool FindCodeInSpecialCache(Code** code_out) override;
1721 bool UseSpecialCache() override {
1722 return state() == CompareICState::KNOWN_OBJECT;
1725 class OpBits : public BitField<int, 0, 3> {};
1726 class StrengthBits : public BitField<bool, 3, 1> {};
1727 class LeftStateBits : public BitField<CompareICState::State, 4, 4> {};
1728 class RightStateBits : public BitField<CompareICState::State, 8, 4> {};
1729 class StateBits : public BitField<CompareICState::State, 12, 4> {};
1731 Handle<Map> known_map_;
1733 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
1734 DEFINE_PLATFORM_CODE_STUB(CompareIC, PlatformCodeStub);
1738 class CompareNilICStub : public HydrogenCodeStub {
1740 Type* GetType(Zone* zone, Handle<Map> map = Handle<Map>());
1741 Type* GetInputType(Zone* zone, Handle<Map> map);
1743 CompareNilICStub(Isolate* isolate, NilValue nil) : HydrogenCodeStub(isolate) {
1744 set_sub_minor_key(NilValueBits::encode(nil));
1747 CompareNilICStub(Isolate* isolate, ExtraICState ic_state,
1748 InitializationState init_state = INITIALIZED)
1749 : HydrogenCodeStub(isolate, init_state) {
1750 set_sub_minor_key(ic_state);
1753 static Handle<Code> GetUninitialized(Isolate* isolate,
1755 return CompareNilICStub(isolate, nil, UNINITIALIZED).GetCode();
1758 InlineCacheState GetICState() const override {
1759 State state = this->state();
1760 if (state.Contains(GENERIC)) {
1762 } else if (state.Contains(MONOMORPHIC_MAP)) {
1765 return PREMONOMORPHIC;
1769 Code::Kind GetCodeKind() const override { return Code::COMPARE_NIL_IC; }
1771 ExtraICState GetExtraICState() const override { return sub_minor_key(); }
1773 void UpdateStatus(Handle<Object> object);
1775 bool IsMonomorphic() const { return state().Contains(MONOMORPHIC_MAP); }
1777 NilValue nil_value() const { return NilValueBits::decode(sub_minor_key()); }
1780 set_sub_minor_key(TypesBits::update(sub_minor_key(), 0));
1783 void PrintState(std::ostream& os) const override; // NOLINT
1784 void PrintBaseName(std::ostream& os) const override; // NOLINT
1787 CompareNilICStub(Isolate* isolate, NilValue nil,
1788 InitializationState init_state)
1789 : HydrogenCodeStub(isolate, init_state) {
1790 set_sub_minor_key(NilValueBits::encode(nil));
1793 enum CompareNilType {
1801 // At most 6 different types can be distinguished, because the Code object
1802 // only has room for a single byte to hold a set and there are two more
1803 // boolean flags we need to store. :-P
1804 STATIC_ASSERT(NUMBER_OF_TYPES <= 6);
1806 class State : public EnumSet<CompareNilType, byte> {
1808 State() : EnumSet<CompareNilType, byte>(0) { }
1809 explicit State(byte bits) : EnumSet<CompareNilType, byte>(bits) { }
1811 friend std::ostream& operator<<(std::ostream& os, const State& s);
1813 State state() const { return State(TypesBits::decode(sub_minor_key())); }
1815 class NilValueBits : public BitField<NilValue, 0, 1> {};
1816 class TypesBits : public BitField<byte, 1, NUMBER_OF_TYPES> {};
1818 friend class CompareNilIC;
1820 DEFINE_CALL_INTERFACE_DESCRIPTOR(CompareNil);
1821 DEFINE_HYDROGEN_CODE_STUB(CompareNilIC, HydrogenCodeStub);
1825 std::ostream& operator<<(std::ostream& os, const CompareNilICStub::State& s);
1828 class CEntryStub : public PlatformCodeStub {
1830 CEntryStub(Isolate* isolate, int result_size,
1831 SaveFPRegsMode save_doubles = kDontSaveFPRegs)
1832 : PlatformCodeStub(isolate) {
1833 minor_key_ = SaveDoublesBits::encode(save_doubles == kSaveFPRegs);
1834 DCHECK(result_size == 1 || result_size == 2);
1835 #if _WIN64 || V8_TARGET_ARCH_PPC
1836 minor_key_ = ResultSizeBits::update(minor_key_, result_size);
1840 // The version of this stub that doesn't save doubles is generated ahead of
1841 // time, so it's OK to call it from other stubs that can't cope with GC during
1842 // their code generation. On machines that always have gp registers (x64) we
1843 // can generate both variants ahead of time.
1844 static void GenerateAheadOfTime(Isolate* isolate);
1847 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
1848 #if _WIN64 || V8_TARGET_ARCH_PPC
1849 int result_size() const { return ResultSizeBits::decode(minor_key_); }
1852 bool NeedsImmovableCode() override;
1854 class SaveDoublesBits : public BitField<bool, 0, 1> {};
1855 class ResultSizeBits : public BitField<int, 1, 3> {};
1857 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
1858 DEFINE_PLATFORM_CODE_STUB(CEntry, PlatformCodeStub);
1862 class JSEntryStub : public PlatformCodeStub {
1864 JSEntryStub(Isolate* isolate, StackFrame::Type type)
1865 : PlatformCodeStub(isolate) {
1866 DCHECK(type == StackFrame::ENTRY || type == StackFrame::ENTRY_CONSTRUCT);
1867 minor_key_ = StackFrameTypeBits::encode(type);
1871 void FinishCode(Handle<Code> code) override;
1873 void PrintName(std::ostream& os) const override { // NOLINT
1874 os << (type() == StackFrame::ENTRY ? "JSEntryStub"
1875 : "JSConstructEntryStub");
1878 StackFrame::Type type() const {
1879 return StackFrameTypeBits::decode(minor_key_);
1882 class StackFrameTypeBits : public BitField<StackFrame::Type, 0, 5> {};
1884 int handler_offset_;
1886 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
1887 DEFINE_PLATFORM_CODE_STUB(JSEntry, PlatformCodeStub);
1891 class ArgumentsAccessStub: public PlatformCodeStub {
1900 ArgumentsAccessStub(Isolate* isolate, Type type) : PlatformCodeStub(isolate) {
1901 minor_key_ = TypeBits::encode(type);
1904 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1905 if (type() == READ_ELEMENT) {
1906 return ArgumentsAccessReadDescriptor(isolate());
1908 return ContextOnlyDescriptor(isolate());
1912 Type type() const { return TypeBits::decode(minor_key_); }
1914 void GenerateReadElement(MacroAssembler* masm);
1915 void GenerateNewStrict(MacroAssembler* masm);
1916 void GenerateNewSloppyFast(MacroAssembler* masm);
1917 void GenerateNewSloppySlow(MacroAssembler* masm);
1919 void PrintName(std::ostream& os) const override; // NOLINT
1921 class TypeBits : public BitField<Type, 0, 2> {};
1923 DEFINE_PLATFORM_CODE_STUB(ArgumentsAccess, PlatformCodeStub);
1927 class RestParamAccessStub: public PlatformCodeStub {
1929 explicit RestParamAccessStub(Isolate* isolate) : PlatformCodeStub(isolate) { }
1931 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1932 return ContextOnlyDescriptor(isolate());
1936 void GenerateNew(MacroAssembler* masm);
1938 void PrintName(std::ostream& os) const override; // NOLINT
1940 DEFINE_PLATFORM_CODE_STUB(RestParamAccess, PlatformCodeStub);
1944 class RegExpExecStub: public PlatformCodeStub {
1946 explicit RegExpExecStub(Isolate* isolate) : PlatformCodeStub(isolate) { }
1948 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
1949 DEFINE_PLATFORM_CODE_STUB(RegExpExec, PlatformCodeStub);
1953 class RegExpConstructResultStub final : public HydrogenCodeStub {
1955 explicit RegExpConstructResultStub(Isolate* isolate)
1956 : HydrogenCodeStub(isolate) { }
1958 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1959 static const int kLength = 0;
1960 static const int kIndex = 1;
1961 static const int kInput = 2;
1963 DEFINE_CALL_INTERFACE_DESCRIPTOR(RegExpConstructResult);
1964 DEFINE_HYDROGEN_CODE_STUB(RegExpConstructResult, HydrogenCodeStub);
1968 class CallFunctionStub: public PlatformCodeStub {
1970 CallFunctionStub(Isolate* isolate, int argc, CallFunctionFlags flags)
1971 : PlatformCodeStub(isolate) {
1972 DCHECK(argc >= 0 && argc <= Code::kMaxArguments);
1973 minor_key_ = ArgcBits::encode(argc) | FlagBits::encode(flags);
1977 int argc() const { return ArgcBits::decode(minor_key_); }
1978 int flags() const { return FlagBits::decode(minor_key_); }
1980 bool CallAsMethod() const {
1981 return flags() == CALL_AS_METHOD || flags() == WRAP_AND_CALL;
1984 bool NeedsChecks() const { return flags() != WRAP_AND_CALL; }
1986 void PrintName(std::ostream& os) const override; // NOLINT
1988 // Minor key encoding in 32 bits with Bitfield <Type, shift, size>.
1989 class FlagBits : public BitField<CallFunctionFlags, 0, 2> {};
1990 class ArgcBits : public BitField<unsigned, 2, Code::kArgumentsBits> {};
1991 STATIC_ASSERT(Code::kArgumentsBits + 2 <= kStubMinorKeyBits);
1993 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction);
1994 DEFINE_PLATFORM_CODE_STUB(CallFunction, PlatformCodeStub);
1998 class CallConstructStub: public PlatformCodeStub {
2000 CallConstructStub(Isolate* isolate, CallConstructorFlags flags)
2001 : PlatformCodeStub(isolate) {
2002 minor_key_ = FlagBits::encode(flags);
2005 void FinishCode(Handle<Code> code) override {
2006 code->set_has_function_cache(RecordCallTarget());
2010 CallConstructorFlags flags() const { return FlagBits::decode(minor_key_); }
2012 bool RecordCallTarget() const {
2013 return (flags() & RECORD_CONSTRUCTOR_TARGET) != 0;
2016 bool IsSuperConstructorCall() const {
2017 return (flags() & SUPER_CONSTRUCTOR_CALL) != 0;
2020 void PrintName(std::ostream& os) const override; // NOLINT
2022 class FlagBits : public BitField<CallConstructorFlags, 0, 2> {};
2024 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallConstruct);
2025 DEFINE_PLATFORM_CODE_STUB(CallConstruct, PlatformCodeStub);
2029 enum StringIndexFlags {
2030 // Accepts smis or heap numbers.
2031 STRING_INDEX_IS_NUMBER,
2033 // Accepts smis or heap numbers that are valid array indices
2034 // (ECMA-262 15.4). Invalid indices are reported as being out of
2036 STRING_INDEX_IS_ARRAY_INDEX
2040 enum ReceiverCheckMode {
2041 // We don't know anything about the receiver.
2042 RECEIVER_IS_UNKNOWN,
2044 // We know the receiver is a string.
2050 // The code being generated is part of an IC handler, which may MISS
2051 // to an IC in failure cases.
2054 NOT_PART_OF_IC_HANDLER
2058 // Generates code implementing String.prototype.charCodeAt.
2060 // Only supports the case when the receiver is a string and the index
2061 // is a number (smi or heap number) that is a valid index into the
2062 // string. Additional index constraints are specified by the
2063 // flags. Otherwise, bails out to the provided labels.
2065 // Register usage: |object| may be changed to another string in a way
2066 // that doesn't affect charCodeAt/charAt semantics, |index| is
2067 // preserved, |scratch| and |result| are clobbered.
2068 class StringCharCodeAtGenerator {
2070 StringCharCodeAtGenerator(Register object, Register index, Register result,
2071 Label* receiver_not_string, Label* index_not_number,
2072 Label* index_out_of_range,
2073 StringIndexFlags index_flags,
2074 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
2078 receiver_not_string_(receiver_not_string),
2079 index_not_number_(index_not_number),
2080 index_out_of_range_(index_out_of_range),
2081 index_flags_(index_flags),
2082 check_mode_(check_mode) {
2083 DCHECK(!result_.is(object_));
2084 DCHECK(!result_.is(index_));
2087 // Generates the fast case code. On the fallthrough path |result|
2088 // register contains the result.
2089 void GenerateFast(MacroAssembler* masm);
2091 // Generates the slow case code. Must not be naturally
2092 // reachable. Expected to be put after a ret instruction (e.g., in
2093 // deferred code). Always jumps back to the fast case.
2094 void GenerateSlow(MacroAssembler* masm, EmbedMode embed_mode,
2095 const RuntimeCallHelper& call_helper);
2097 // Skip handling slow case and directly jump to bailout.
2098 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2099 masm->bind(&index_not_smi_);
2100 masm->bind(&call_runtime_);
2109 Label* receiver_not_string_;
2110 Label* index_not_number_;
2111 Label* index_out_of_range_;
2113 StringIndexFlags index_flags_;
2114 ReceiverCheckMode check_mode_;
2116 Label call_runtime_;
2117 Label index_not_smi_;
2118 Label got_smi_index_;
2121 DISALLOW_COPY_AND_ASSIGN(StringCharCodeAtGenerator);
2125 // Generates code for creating a one-char string from a char code.
2126 class StringCharFromCodeGenerator {
2128 StringCharFromCodeGenerator(Register code,
2132 DCHECK(!code_.is(result_));
2135 // Generates the fast case code. On the fallthrough path |result|
2136 // register contains the result.
2137 void GenerateFast(MacroAssembler* masm);
2139 // Generates the slow case code. Must not be naturally
2140 // reachable. Expected to be put after a ret instruction (e.g., in
2141 // deferred code). Always jumps back to the fast case.
2142 void GenerateSlow(MacroAssembler* masm,
2143 const RuntimeCallHelper& call_helper);
2145 // Skip handling slow case and directly jump to bailout.
2146 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2147 masm->bind(&slow_case_);
2158 DISALLOW_COPY_AND_ASSIGN(StringCharFromCodeGenerator);
2162 // Generates code implementing String.prototype.charAt.
2164 // Only supports the case when the receiver is a string and the index
2165 // is a number (smi or heap number) that is a valid index into the
2166 // string. Additional index constraints are specified by the
2167 // flags. Otherwise, bails out to the provided labels.
2169 // Register usage: |object| may be changed to another string in a way
2170 // that doesn't affect charCodeAt/charAt semantics, |index| is
2171 // preserved, |scratch1|, |scratch2|, and |result| are clobbered.
2172 class StringCharAtGenerator {
2174 StringCharAtGenerator(Register object, Register index, Register scratch,
2175 Register result, Label* receiver_not_string,
2176 Label* index_not_number, Label* index_out_of_range,
2177 StringIndexFlags index_flags,
2178 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
2179 : char_code_at_generator_(object, index, scratch, receiver_not_string,
2180 index_not_number, index_out_of_range,
2181 index_flags, check_mode),
2182 char_from_code_generator_(scratch, result) {}
2184 // Generates the fast case code. On the fallthrough path |result|
2185 // register contains the result.
2186 void GenerateFast(MacroAssembler* masm) {
2187 char_code_at_generator_.GenerateFast(masm);
2188 char_from_code_generator_.GenerateFast(masm);
2191 // Generates the slow case code. Must not be naturally
2192 // reachable. Expected to be put after a ret instruction (e.g., in
2193 // deferred code). Always jumps back to the fast case.
2194 void GenerateSlow(MacroAssembler* masm, EmbedMode embed_mode,
2195 const RuntimeCallHelper& call_helper) {
2196 char_code_at_generator_.GenerateSlow(masm, embed_mode, call_helper);
2197 char_from_code_generator_.GenerateSlow(masm, call_helper);
2200 // Skip handling slow case and directly jump to bailout.
2201 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2202 char_code_at_generator_.SkipSlow(masm, bailout);
2203 char_from_code_generator_.SkipSlow(masm, bailout);
2207 StringCharCodeAtGenerator char_code_at_generator_;
2208 StringCharFromCodeGenerator char_from_code_generator_;
2210 DISALLOW_COPY_AND_ASSIGN(StringCharAtGenerator);
2214 class LoadDictionaryElementStub : public HydrogenCodeStub {
2216 explicit LoadDictionaryElementStub(Isolate* isolate, const LoadICState& state)
2217 : HydrogenCodeStub(isolate) {
2218 minor_key_ = state.GetExtraICState();
2221 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
2222 return LoadWithVectorDescriptor(isolate());
2225 LanguageMode language_mode() const {
2226 return LoadICState::GetLanguageMode(MinorKey());
2229 DEFINE_HYDROGEN_CODE_STUB(LoadDictionaryElement, HydrogenCodeStub);
2233 class KeyedLoadGenericStub : public HydrogenCodeStub {
2235 explicit KeyedLoadGenericStub(Isolate* isolate, const LoadICState& state)
2236 : HydrogenCodeStub(isolate) {
2237 minor_key_ = state.GetExtraICState();
2240 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2241 InlineCacheState GetICState() const override { return GENERIC; }
2243 LanguageMode language_mode() const {
2244 return LoadICState::GetLanguageMode(MinorKey());
2247 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
2249 DEFINE_HYDROGEN_CODE_STUB(KeyedLoadGeneric, HydrogenCodeStub);
2253 class LoadICTrampolineStub : public PlatformCodeStub {
2255 LoadICTrampolineStub(Isolate* isolate, const LoadICState& state)
2256 : PlatformCodeStub(isolate) {
2257 minor_key_ = state.GetExtraICState();
2260 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
2262 InlineCacheState GetICState() const final { return DEFAULT; }
2264 ExtraICState GetExtraICState() const final {
2265 return static_cast<ExtraICState>(minor_key_);
2269 LoadICState state() const {
2270 return LoadICState(static_cast<ExtraICState>(minor_key_));
2273 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
2274 DEFINE_PLATFORM_CODE_STUB(LoadICTrampoline, PlatformCodeStub);
2278 class KeyedLoadICTrampolineStub : public LoadICTrampolineStub {
2280 explicit KeyedLoadICTrampolineStub(Isolate* isolate, const LoadICState& state)
2281 : LoadICTrampolineStub(isolate, state) {}
2283 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2285 DEFINE_PLATFORM_CODE_STUB(KeyedLoadICTrampoline, LoadICTrampolineStub);
2289 class VectorStoreICTrampolineStub : public PlatformCodeStub {
2291 VectorStoreICTrampolineStub(Isolate* isolate, const StoreICState& state)
2292 : PlatformCodeStub(isolate) {
2293 minor_key_ = state.GetExtraICState();
2296 Code::Kind GetCodeKind() const override { return Code::STORE_IC; }
2298 InlineCacheState GetICState() const final { return DEFAULT; }
2300 ExtraICState GetExtraICState() const final {
2301 return static_cast<ExtraICState>(minor_key_);
2305 StoreICState state() const {
2306 return StoreICState(static_cast<ExtraICState>(minor_key_));
2310 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreICTrampoline);
2311 DEFINE_PLATFORM_CODE_STUB(VectorStoreICTrampoline, PlatformCodeStub);
2315 class VectorKeyedStoreICTrampolineStub : public VectorStoreICTrampolineStub {
2317 VectorKeyedStoreICTrampolineStub(Isolate* isolate, const StoreICState& state)
2318 : VectorStoreICTrampolineStub(isolate, state) {}
2320 Code::Kind GetCodeKind() const override { return Code::KEYED_STORE_IC; }
2322 DEFINE_PLATFORM_CODE_STUB(VectorKeyedStoreICTrampoline,
2323 VectorStoreICTrampolineStub);
2327 class CallICTrampolineStub : public PlatformCodeStub {
2329 CallICTrampolineStub(Isolate* isolate, const CallICState& state)
2330 : PlatformCodeStub(isolate) {
2331 minor_key_ = state.GetExtraICState();
2334 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
2336 InlineCacheState GetICState() const final { return DEFAULT; }
2338 ExtraICState GetExtraICState() const final {
2339 return static_cast<ExtraICState>(minor_key_);
2343 CallICState state() const {
2344 return CallICState(static_cast<ExtraICState>(minor_key_));
2347 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedback);
2348 DEFINE_PLATFORM_CODE_STUB(CallICTrampoline, PlatformCodeStub);
2352 class CallIC_ArrayTrampolineStub : public CallICTrampolineStub {
2354 CallIC_ArrayTrampolineStub(Isolate* isolate, const CallICState& state)
2355 : CallICTrampolineStub(isolate, state) {}
2358 DEFINE_PLATFORM_CODE_STUB(CallIC_ArrayTrampoline, CallICTrampolineStub);
2362 class LoadICStub : public PlatformCodeStub {
2364 explicit LoadICStub(Isolate* isolate, const LoadICState& state)
2365 : PlatformCodeStub(isolate) {
2366 minor_key_ = state.GetExtraICState();
2369 void GenerateForTrampoline(MacroAssembler* masm);
2371 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
2372 InlineCacheState GetICState() const final { return DEFAULT; }
2373 ExtraICState GetExtraICState() const final {
2374 return static_cast<ExtraICState>(minor_key_);
2377 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2378 DEFINE_PLATFORM_CODE_STUB(LoadIC, PlatformCodeStub);
2381 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2385 class KeyedLoadICStub : public PlatformCodeStub {
2387 explicit KeyedLoadICStub(Isolate* isolate, const LoadICState& state)
2388 : PlatformCodeStub(isolate) {
2389 minor_key_ = state.GetExtraICState();
2392 void GenerateForTrampoline(MacroAssembler* masm);
2394 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2395 InlineCacheState GetICState() const final { return DEFAULT; }
2396 ExtraICState GetExtraICState() const final {
2397 return static_cast<ExtraICState>(minor_key_);
2400 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2401 DEFINE_PLATFORM_CODE_STUB(KeyedLoadIC, PlatformCodeStub);
2404 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2408 class VectorStoreICStub : public PlatformCodeStub {
2410 VectorStoreICStub(Isolate* isolate, const StoreICState& state)
2411 : PlatformCodeStub(isolate) {
2412 minor_key_ = state.GetExtraICState();
2415 void GenerateForTrampoline(MacroAssembler* masm);
2417 Code::Kind GetCodeKind() const final { return Code::STORE_IC; }
2418 InlineCacheState GetICState() const final { return DEFAULT; }
2419 ExtraICState GetExtraICState() const final {
2420 return static_cast<ExtraICState>(minor_key_);
2423 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreIC);
2424 DEFINE_PLATFORM_CODE_STUB(VectorStoreIC, PlatformCodeStub);
2427 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2431 class VectorKeyedStoreICStub : public PlatformCodeStub {
2433 VectorKeyedStoreICStub(Isolate* isolate, const StoreICState& state)
2434 : PlatformCodeStub(isolate) {
2435 minor_key_ = state.GetExtraICState();
2438 void GenerateForTrampoline(MacroAssembler* masm);
2440 Code::Kind GetCodeKind() const final { return Code::KEYED_STORE_IC; }
2441 InlineCacheState GetICState() const final { return DEFAULT; }
2442 virtual ExtraICState GetExtraICState() const final {
2443 return static_cast<ExtraICState>(minor_key_);
2446 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreIC);
2447 DEFINE_PLATFORM_CODE_STUB(VectorKeyedStoreIC, PlatformCodeStub);
2450 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2454 class DoubleToIStub : public PlatformCodeStub {
2456 DoubleToIStub(Isolate* isolate, Register source, Register destination,
2457 int offset, bool is_truncating, bool skip_fastpath = false)
2458 : PlatformCodeStub(isolate) {
2459 minor_key_ = SourceRegisterBits::encode(source.code()) |
2460 DestinationRegisterBits::encode(destination.code()) |
2461 OffsetBits::encode(offset) |
2462 IsTruncatingBits::encode(is_truncating) |
2463 SkipFastPathBits::encode(skip_fastpath) |
2464 SSE3Bits::encode(CpuFeatures::IsSupported(SSE3) ? 1 : 0);
2467 bool SometimesSetsUpAFrame() override { return false; }
2470 Register source() const {
2471 return Register::from_code(SourceRegisterBits::decode(minor_key_));
2473 Register destination() const {
2474 return Register::from_code(DestinationRegisterBits::decode(minor_key_));
2476 bool is_truncating() const { return IsTruncatingBits::decode(minor_key_); }
2477 bool skip_fastpath() const { return SkipFastPathBits::decode(minor_key_); }
2478 int offset() const { return OffsetBits::decode(minor_key_); }
2480 static const int kBitsPerRegisterNumber = 6;
2481 STATIC_ASSERT((1L << kBitsPerRegisterNumber) >= Register::kNumRegisters);
2482 class SourceRegisterBits:
2483 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT
2484 class DestinationRegisterBits:
2485 public BitField<int, kBitsPerRegisterNumber,
2486 kBitsPerRegisterNumber> {}; // NOLINT
2487 class IsTruncatingBits:
2488 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT
2490 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT
2491 class SkipFastPathBits:
2492 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT
2494 public BitField<int, 2 * kBitsPerRegisterNumber + 5, 1> {}; // NOLINT
2496 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2497 DEFINE_PLATFORM_CODE_STUB(DoubleToI, PlatformCodeStub);
2501 class ScriptContextFieldStub : public HandlerStub {
2503 ScriptContextFieldStub(Isolate* isolate,
2504 const ScriptContextTable::LookupResult* lookup_result)
2505 : HandlerStub(isolate) {
2506 DCHECK(Accepted(lookup_result));
2507 set_sub_minor_key(ContextIndexBits::encode(lookup_result->context_index) |
2508 SlotIndexBits::encode(lookup_result->slot_index));
2511 int context_index() const {
2512 return ContextIndexBits::decode(sub_minor_key());
2515 int slot_index() const { return SlotIndexBits::decode(sub_minor_key()); }
2517 static bool Accepted(const ScriptContextTable::LookupResult* lookup_result) {
2518 return ContextIndexBits::is_valid(lookup_result->context_index) &&
2519 SlotIndexBits::is_valid(lookup_result->slot_index);
2523 static const int kContextIndexBits = 13;
2524 static const int kSlotIndexBits = 13;
2525 class ContextIndexBits : public BitField<int, 0, kContextIndexBits> {};
2527 : public BitField<int, kContextIndexBits, kSlotIndexBits> {};
2529 Code::StubType GetStubType() const override { return Code::FAST; }
2531 DEFINE_CODE_STUB_BASE(ScriptContextFieldStub, HandlerStub);
2535 class LoadScriptContextFieldStub : public ScriptContextFieldStub {
2537 LoadScriptContextFieldStub(
2538 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2539 : ScriptContextFieldStub(isolate, lookup_result) {}
2542 Code::Kind kind() const override { return Code::LOAD_IC; }
2544 DEFINE_HANDLER_CODE_STUB(LoadScriptContextField, ScriptContextFieldStub);
2548 class StoreScriptContextFieldStub : public ScriptContextFieldStub {
2550 StoreScriptContextFieldStub(
2551 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2552 : ScriptContextFieldStub(isolate, lookup_result) {}
2555 Code::Kind kind() const override { return Code::STORE_IC; }
2557 DEFINE_HANDLER_CODE_STUB(StoreScriptContextField, ScriptContextFieldStub);
2561 class LoadFastElementStub : public HandlerStub {
2563 LoadFastElementStub(Isolate* isolate, bool is_js_array,
2564 ElementsKind elements_kind,
2565 bool convert_hole_to_undefined = false)
2566 : HandlerStub(isolate) {
2568 ElementsKindBits::encode(elements_kind) |
2569 IsJSArrayBits::encode(is_js_array) |
2570 CanConvertHoleToUndefined::encode(convert_hole_to_undefined));
2573 Code::Kind kind() const override { return Code::KEYED_LOAD_IC; }
2575 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2576 bool convert_hole_to_undefined() const {
2577 return CanConvertHoleToUndefined::decode(sub_minor_key());
2580 ElementsKind elements_kind() const {
2581 return ElementsKindBits::decode(sub_minor_key());
2585 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2586 class IsJSArrayBits: public BitField<bool, 8, 1> {};
2587 class CanConvertHoleToUndefined : public BitField<bool, 9, 1> {};
2589 DEFINE_HANDLER_CODE_STUB(LoadFastElement, HandlerStub);
2593 class StoreFastElementStub : public HydrogenCodeStub {
2595 StoreFastElementStub(Isolate* isolate, bool is_js_array,
2596 ElementsKind elements_kind, KeyedAccessStoreMode mode)
2597 : HydrogenCodeStub(isolate) {
2598 set_sub_minor_key(ElementsKindBits::encode(elements_kind) |
2599 IsJSArrayBits::encode(is_js_array) |
2600 StoreModeBits::encode(mode));
2603 static void GenerateAheadOfTime(Isolate* isolate);
2605 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2607 ElementsKind elements_kind() const {
2608 return ElementsKindBits::decode(sub_minor_key());
2611 KeyedAccessStoreMode store_mode() const {
2612 return StoreModeBits::decode(sub_minor_key());
2616 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2617 class StoreModeBits: public BitField<KeyedAccessStoreMode, 8, 4> {};
2618 class IsJSArrayBits: public BitField<bool, 12, 1> {};
2620 DEFINE_CALL_INTERFACE_DESCRIPTOR(Store);
2621 DEFINE_HYDROGEN_CODE_STUB(StoreFastElement, HydrogenCodeStub);
2625 class TransitionElementsKindStub : public HydrogenCodeStub {
2627 TransitionElementsKindStub(Isolate* isolate,
2628 ElementsKind from_kind,
2629 ElementsKind to_kind,
2630 bool is_js_array) : HydrogenCodeStub(isolate) {
2631 set_sub_minor_key(FromKindBits::encode(from_kind) |
2632 ToKindBits::encode(to_kind) |
2633 IsJSArrayBits::encode(is_js_array));
2636 ElementsKind from_kind() const {
2637 return FromKindBits::decode(sub_minor_key());
2640 ElementsKind to_kind() const { return ToKindBits::decode(sub_minor_key()); }
2642 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2645 class FromKindBits: public BitField<ElementsKind, 8, 8> {};
2646 class ToKindBits: public BitField<ElementsKind, 0, 8> {};
2647 class IsJSArrayBits: public BitField<bool, 16, 1> {};
2649 DEFINE_CALL_INTERFACE_DESCRIPTOR(TransitionElementsKind);
2650 DEFINE_HYDROGEN_CODE_STUB(TransitionElementsKind, HydrogenCodeStub);
2654 class AllocateHeapNumberStub final : public HydrogenCodeStub {
2656 explicit AllocateHeapNumberStub(Isolate* isolate)
2657 : HydrogenCodeStub(isolate) {}
2660 DEFINE_CALL_INTERFACE_DESCRIPTOR(AllocateHeapNumber);
2661 DEFINE_HYDROGEN_CODE_STUB(AllocateHeapNumber, HydrogenCodeStub);
2665 class ArrayConstructorStubBase : public HydrogenCodeStub {
2667 ArrayConstructorStubBase(Isolate* isolate,
2669 AllocationSiteOverrideMode override_mode)
2670 : HydrogenCodeStub(isolate) {
2671 // It only makes sense to override local allocation site behavior
2672 // if there is a difference between the global allocation site policy
2673 // for an ElementsKind and the desired usage of the stub.
2674 DCHECK(override_mode != DISABLE_ALLOCATION_SITES ||
2675 AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE);
2676 set_sub_minor_key(ElementsKindBits::encode(kind) |
2677 AllocationSiteOverrideModeBits::encode(override_mode));
2680 ElementsKind elements_kind() const {
2681 return ElementsKindBits::decode(sub_minor_key());
2684 AllocationSiteOverrideMode override_mode() const {
2685 return AllocationSiteOverrideModeBits::decode(sub_minor_key());
2688 static void GenerateStubsAheadOfTime(Isolate* isolate);
2690 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2691 static const int kConstructor = 0;
2692 static const int kAllocationSite = 1;
2695 std::ostream& BasePrintName(std::ostream& os,
2696 const char* name) const; // NOLINT
2699 // Ensure data fits within available bits.
2700 STATIC_ASSERT(LAST_ALLOCATION_SITE_OVERRIDE_MODE == 1);
2702 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2703 class AllocationSiteOverrideModeBits: public
2704 BitField<AllocationSiteOverrideMode, 8, 1> {}; // NOLINT
2706 DEFINE_CODE_STUB_BASE(ArrayConstructorStubBase, HydrogenCodeStub);
2710 class ArrayNoArgumentConstructorStub : public ArrayConstructorStubBase {
2712 ArrayNoArgumentConstructorStub(
2715 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2716 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2720 void PrintName(std::ostream& os) const override { // NOLINT
2721 BasePrintName(os, "ArrayNoArgumentConstructorStub");
2724 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructorConstantArgCount);
2725 DEFINE_HYDROGEN_CODE_STUB(ArrayNoArgumentConstructor,
2726 ArrayConstructorStubBase);
2730 class ArraySingleArgumentConstructorStub : public ArrayConstructorStubBase {
2732 ArraySingleArgumentConstructorStub(
2735 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2736 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2740 void PrintName(std::ostream& os) const override { // NOLINT
2741 BasePrintName(os, "ArraySingleArgumentConstructorStub");
2744 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
2745 DEFINE_HYDROGEN_CODE_STUB(ArraySingleArgumentConstructor,
2746 ArrayConstructorStubBase);
2750 class ArrayNArgumentsConstructorStub : public ArrayConstructorStubBase {
2752 ArrayNArgumentsConstructorStub(
2755 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2756 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2760 void PrintName(std::ostream& os) const override { // NOLINT
2761 BasePrintName(os, "ArrayNArgumentsConstructorStub");
2764 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
2765 DEFINE_HYDROGEN_CODE_STUB(ArrayNArgumentsConstructor,
2766 ArrayConstructorStubBase);
2770 class InternalArrayConstructorStubBase : public HydrogenCodeStub {
2772 InternalArrayConstructorStubBase(Isolate* isolate, ElementsKind kind)
2773 : HydrogenCodeStub(isolate) {
2774 set_sub_minor_key(ElementsKindBits::encode(kind));
2777 static void GenerateStubsAheadOfTime(Isolate* isolate);
2779 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2780 static const int kConstructor = 0;
2782 ElementsKind elements_kind() const {
2783 return ElementsKindBits::decode(sub_minor_key());
2787 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
2789 DEFINE_CODE_STUB_BASE(InternalArrayConstructorStubBase, HydrogenCodeStub);
2793 class InternalArrayNoArgumentConstructorStub : public
2794 InternalArrayConstructorStubBase {
2796 InternalArrayNoArgumentConstructorStub(Isolate* isolate,
2798 : InternalArrayConstructorStubBase(isolate, kind) { }
2800 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructorConstantArgCount);
2801 DEFINE_HYDROGEN_CODE_STUB(InternalArrayNoArgumentConstructor,
2802 InternalArrayConstructorStubBase);
2806 class InternalArraySingleArgumentConstructorStub : public
2807 InternalArrayConstructorStubBase {
2809 InternalArraySingleArgumentConstructorStub(Isolate* isolate,
2811 : InternalArrayConstructorStubBase(isolate, kind) { }
2813 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
2814 DEFINE_HYDROGEN_CODE_STUB(InternalArraySingleArgumentConstructor,
2815 InternalArrayConstructorStubBase);
2819 class InternalArrayNArgumentsConstructorStub : public
2820 InternalArrayConstructorStubBase {
2822 InternalArrayNArgumentsConstructorStub(Isolate* isolate, ElementsKind kind)
2823 : InternalArrayConstructorStubBase(isolate, kind) { }
2825 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
2826 DEFINE_HYDROGEN_CODE_STUB(InternalArrayNArgumentsConstructor,
2827 InternalArrayConstructorStubBase);
2831 class StoreElementStub : public PlatformCodeStub {
2833 StoreElementStub(Isolate* isolate, ElementsKind elements_kind)
2834 : PlatformCodeStub(isolate) {
2835 minor_key_ = ElementsKindBits::encode(elements_kind);
2839 ElementsKind elements_kind() const {
2840 return ElementsKindBits::decode(minor_key_);
2843 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
2845 DEFINE_CALL_INTERFACE_DESCRIPTOR(Store);
2846 DEFINE_PLATFORM_CODE_STUB(StoreElement, PlatformCodeStub);
2850 class ToBooleanStub: public HydrogenCodeStub {
2866 RESULT_AS_SMI, // For Smi(1) on truthy value, Smi(0) otherwise.
2867 RESULT_AS_ODDBALL, // For {true} on truthy value, {false} otherwise.
2868 RESULT_AS_INVERSE_ODDBALL // For {false} on truthy value, {true} otherwise.
2871 // At most 16 different types can be distinguished, because the Code object
2872 // only has room for two bytes to hold a set of these types. :-P
2873 STATIC_ASSERT(NUMBER_OF_TYPES <= 16);
2875 class Types : public EnumSet<Type, uint16_t> {
2877 Types() : EnumSet<Type, uint16_t>(0) {}
2878 explicit Types(uint16_t bits) : EnumSet<Type, uint16_t>(bits) {}
2880 bool UpdateStatus(Handle<Object> object);
2881 bool NeedsMap() const;
2882 bool CanBeUndetectable() const;
2883 bool IsGeneric() const { return ToIntegral() == Generic().ToIntegral(); }
2885 static Types Generic() { return Types((1 << NUMBER_OF_TYPES) - 1); }
2888 ToBooleanStub(Isolate* isolate, ResultMode mode, Types types = Types())
2889 : HydrogenCodeStub(isolate) {
2890 set_sub_minor_key(TypesBits::encode(types.ToIntegral()) |
2891 ResultModeBits::encode(mode));
2894 ToBooleanStub(Isolate* isolate, ExtraICState state)
2895 : HydrogenCodeStub(isolate) {
2896 set_sub_minor_key(TypesBits::encode(static_cast<uint16_t>(state)) |
2897 ResultModeBits::encode(RESULT_AS_SMI));
2900 bool UpdateStatus(Handle<Object> object);
2901 Types types() const { return Types(TypesBits::decode(sub_minor_key())); }
2902 ResultMode mode() const { return ResultModeBits::decode(sub_minor_key()); }
2904 Code::Kind GetCodeKind() const override { return Code::TO_BOOLEAN_IC; }
2905 void PrintState(std::ostream& os) const override; // NOLINT
2907 bool SometimesSetsUpAFrame() override { return false; }
2909 static Handle<Code> GetUninitialized(Isolate* isolate) {
2910 return ToBooleanStub(isolate, UNINITIALIZED).GetCode();
2913 ExtraICState GetExtraICState() const override { return types().ToIntegral(); }
2915 InlineCacheState GetICState() const override {
2916 if (types().IsEmpty()) {
2917 return ::v8::internal::UNINITIALIZED;
2924 ToBooleanStub(Isolate* isolate, InitializationState init_state)
2925 : HydrogenCodeStub(isolate, init_state) {
2926 set_sub_minor_key(ResultModeBits::encode(RESULT_AS_SMI));
2929 class TypesBits : public BitField<uint16_t, 0, NUMBER_OF_TYPES> {};
2930 class ResultModeBits : public BitField<ResultMode, NUMBER_OF_TYPES, 2> {};
2932 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToBoolean);
2933 DEFINE_HYDROGEN_CODE_STUB(ToBoolean, HydrogenCodeStub);
2937 std::ostream& operator<<(std::ostream& os, const ToBooleanStub::Types& t);
2940 class ElementsTransitionAndStoreStub : public HydrogenCodeStub {
2942 ElementsTransitionAndStoreStub(Isolate* isolate, ElementsKind from_kind,
2943 ElementsKind to_kind, bool is_jsarray,
2944 KeyedAccessStoreMode store_mode)
2945 : HydrogenCodeStub(isolate) {
2946 set_sub_minor_key(FromBits::encode(from_kind) | ToBits::encode(to_kind) |
2947 IsJSArrayBits::encode(is_jsarray) |
2948 StoreModeBits::encode(store_mode));
2951 ElementsKind from_kind() const { return FromBits::decode(sub_minor_key()); }
2952 ElementsKind to_kind() const { return ToBits::decode(sub_minor_key()); }
2953 bool is_jsarray() const { return IsJSArrayBits::decode(sub_minor_key()); }
2954 KeyedAccessStoreMode store_mode() const {
2955 return StoreModeBits::decode(sub_minor_key());
2959 class FromBits : public BitField<ElementsKind, 0, 8> {};
2960 class ToBits : public BitField<ElementsKind, 8, 8> {};
2961 class IsJSArrayBits : public BitField<bool, 16, 1> {};
2962 class StoreModeBits : public BitField<KeyedAccessStoreMode, 17, 4> {};
2964 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreTransition);
2965 DEFINE_HYDROGEN_CODE_STUB(ElementsTransitionAndStore, HydrogenCodeStub);
2969 class StoreArrayLiteralElementStub : public PlatformCodeStub {
2971 explicit StoreArrayLiteralElementStub(Isolate* isolate)
2972 : PlatformCodeStub(isolate) { }
2974 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreArrayLiteralElement);
2975 DEFINE_PLATFORM_CODE_STUB(StoreArrayLiteralElement, PlatformCodeStub);
2979 class StubFailureTrampolineStub : public PlatformCodeStub {
2981 StubFailureTrampolineStub(Isolate* isolate, StubFunctionMode function_mode)
2982 : PlatformCodeStub(isolate) {
2983 minor_key_ = FunctionModeField::encode(function_mode);
2986 static void GenerateAheadOfTime(Isolate* isolate);
2989 StubFunctionMode function_mode() const {
2990 return FunctionModeField::decode(minor_key_);
2993 class FunctionModeField : public BitField<StubFunctionMode, 0, 1> {};
2995 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2996 DEFINE_PLATFORM_CODE_STUB(StubFailureTrampoline, PlatformCodeStub);
3000 class ProfileEntryHookStub : public PlatformCodeStub {
3002 explicit ProfileEntryHookStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3004 // The profile entry hook function is not allowed to cause a GC.
3005 bool SometimesSetsUpAFrame() override { return false; }
3007 // Generates a call to the entry hook if it's enabled.
3008 static void MaybeCallEntryHook(MacroAssembler* masm);
3011 static void EntryHookTrampoline(intptr_t function,
3012 intptr_t stack_pointer,
3015 // ProfileEntryHookStub is called at the start of a function, so it has the
3016 // same register set.
3017 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction)
3018 DEFINE_PLATFORM_CODE_STUB(ProfileEntryHook, PlatformCodeStub);
3022 class StoreBufferOverflowStub : public PlatformCodeStub {
3024 StoreBufferOverflowStub(Isolate* isolate, SaveFPRegsMode save_fp)
3025 : PlatformCodeStub(isolate) {
3026 minor_key_ = SaveDoublesBits::encode(save_fp == kSaveFPRegs);
3029 static void GenerateFixedRegStubsAheadOfTime(Isolate* isolate);
3030 bool SometimesSetsUpAFrame() override { return false; }
3033 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
3035 class SaveDoublesBits : public BitField<bool, 0, 1> {};
3037 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
3038 DEFINE_PLATFORM_CODE_STUB(StoreBufferOverflow, PlatformCodeStub);
3042 class SubStringStub : public PlatformCodeStub {
3044 explicit SubStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3046 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
3047 DEFINE_PLATFORM_CODE_STUB(SubString, PlatformCodeStub);
3051 class ToNumberStub final : public PlatformCodeStub {
3053 explicit ToNumberStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3055 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToNumber);
3056 DEFINE_PLATFORM_CODE_STUB(ToNumber, PlatformCodeStub);
3060 class StringCompareStub : public PlatformCodeStub {
3062 explicit StringCompareStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3064 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
3065 DEFINE_PLATFORM_CODE_STUB(StringCompare, PlatformCodeStub);
3069 #undef DEFINE_CALL_INTERFACE_DESCRIPTOR
3070 #undef DEFINE_PLATFORM_CODE_STUB
3071 #undef DEFINE_HANDLER_CODE_STUB
3072 #undef DEFINE_HYDROGEN_CODE_STUB
3073 #undef DEFINE_CODE_STUB
3074 #undef DEFINE_CODE_STUB_BASE
3076 extern Representation RepresentationFromType(Type* type);
3077 } } // namespace v8::internal
3079 #endif // V8_CODE_STUBS_H_