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 };
426 enum HandlerArgumentsMode { DONT_PASS_ARGUMENTS, PASS_ARGUMENTS };
429 class CodeStubDescriptor {
431 explicit CodeStubDescriptor(CodeStub* stub);
433 CodeStubDescriptor(Isolate* isolate, uint32_t stub_key);
435 void Initialize(Address deoptimization_handler = NULL,
436 int hint_stack_parameter_count = -1,
437 StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE);
438 void Initialize(Register stack_parameter_count,
439 Address deoptimization_handler = NULL,
440 int hint_stack_parameter_count = -1,
441 StubFunctionMode function_mode = NOT_JS_FUNCTION_STUB_MODE,
442 HandlerArgumentsMode handler_mode = DONT_PASS_ARGUMENTS);
444 void SetMissHandler(ExternalReference handler) {
445 miss_handler_ = handler;
446 has_miss_handler_ = true;
447 // Our miss handler infrastructure doesn't currently support
448 // variable stack parameter counts.
449 DCHECK(!stack_parameter_count_.is_valid());
452 void set_call_descriptor(CallInterfaceDescriptor d) { call_descriptor_ = d; }
453 CallInterfaceDescriptor call_descriptor() const { return call_descriptor_; }
455 int GetRegisterParameterCount() const {
456 return call_descriptor().GetRegisterParameterCount();
459 Register GetRegisterParameter(int index) const {
460 return call_descriptor().GetRegisterParameter(index);
463 Type* GetParameterType(int index) const {
464 return call_descriptor().GetParameterType(index);
467 ExternalReference miss_handler() const {
468 DCHECK(has_miss_handler_);
469 return miss_handler_;
472 bool has_miss_handler() const {
473 return has_miss_handler_;
476 int GetHandlerParameterCount() const {
477 int params = GetRegisterParameterCount();
478 if (handler_arguments_mode_ == PASS_ARGUMENTS) {
484 int hint_stack_parameter_count() const { return hint_stack_parameter_count_; }
485 Register stack_parameter_count() const { return stack_parameter_count_; }
486 StubFunctionMode function_mode() const { return function_mode_; }
487 Address deoptimization_handler() const { return deoptimization_handler_; }
490 CallInterfaceDescriptor call_descriptor_;
491 Register stack_parameter_count_;
492 // If hint_stack_parameter_count_ > 0, the code stub can optimize the
493 // return sequence. Default value is -1, which means it is ignored.
494 int hint_stack_parameter_count_;
495 StubFunctionMode function_mode_;
497 Address deoptimization_handler_;
498 HandlerArgumentsMode handler_arguments_mode_;
500 ExternalReference miss_handler_;
501 bool has_miss_handler_;
505 class HydrogenCodeStub : public CodeStub {
507 enum InitializationState {
512 template<class SubClass>
513 static Handle<Code> GetUninitialized(Isolate* isolate) {
514 SubClass::GenerateAheadOfTime(isolate);
515 return SubClass().GetCode(isolate);
518 // Retrieve the code for the stub. Generate the code if needed.
519 Handle<Code> GenerateCode() override = 0;
521 bool IsUninitialized() const { return IsMissBits::decode(minor_key_); }
523 Handle<Code> GenerateLightweightMissCode(ExternalReference miss);
525 template<class StateType>
526 void TraceTransition(StateType from, StateType to);
529 explicit HydrogenCodeStub(Isolate* isolate,
530 InitializationState state = INITIALIZED)
531 : CodeStub(isolate) {
532 minor_key_ = IsMissBits::encode(state == UNINITIALIZED);
535 void set_sub_minor_key(uint32_t key) {
536 minor_key_ = SubMinorKeyBits::update(minor_key_, key);
539 uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); }
541 static const int kSubMinorKeyBits = kStubMinorKeyBits - 1;
544 class IsMissBits : public BitField<bool, kSubMinorKeyBits, 1> {};
545 class SubMinorKeyBits : public BitField<int, 0, kSubMinorKeyBits> {};
547 void GenerateLightweightMiss(MacroAssembler* masm, ExternalReference miss);
549 DEFINE_CODE_STUB_BASE(HydrogenCodeStub, CodeStub);
553 class TurboFanCodeStub : public CodeStub {
555 // Retrieve the code for the stub. Generate the code if needed.
556 Handle<Code> GenerateCode() override;
558 virtual int GetStackParameterCount() const override {
559 return GetCallInterfaceDescriptor().GetStackParameterCount();
562 Code::StubType GetStubType() const override { return Code::FAST; }
565 explicit TurboFanCodeStub(Isolate* isolate) : CodeStub(isolate) {}
568 DEFINE_CODE_STUB_BASE(TurboFanCodeStub, CodeStub);
572 class TurboFanIC : public TurboFanCodeStub {
574 enum CallMode { CALL_FROM_UNOPTIMIZED_CODE, CALL_FROM_OPTIMIZED_CODE };
577 explicit TurboFanIC(Isolate* isolate, CallMode mode)
578 : TurboFanCodeStub(isolate) {
579 minor_key_ = CallModeBits::encode(mode);
582 CallMode GetCallMode() const { return CallModeBits::decode(minor_key_); }
584 void set_sub_minor_key(uint32_t key) {
585 minor_key_ = SubMinorKeyBits::update(minor_key_, key);
588 uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); }
590 static const int kSubMinorKeyBits = kStubMinorKeyBits - 1;
593 class CallModeBits : public BitField<CallMode, 0, 1> {};
594 class SubMinorKeyBits : public BitField<int, 1, kSubMinorKeyBits> {};
595 DEFINE_CODE_STUB_BASE(TurboFanIC, TurboFanCodeStub);
599 // Helper interface to prepare to/restore after making runtime calls.
600 class RuntimeCallHelper {
602 virtual ~RuntimeCallHelper() {}
604 virtual void BeforeCall(MacroAssembler* masm) const = 0;
606 virtual void AfterCall(MacroAssembler* masm) const = 0;
609 RuntimeCallHelper() {}
612 DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper);
616 } } // namespace v8::internal
618 #if V8_TARGET_ARCH_IA32
619 #include "src/ia32/code-stubs-ia32.h"
620 #elif V8_TARGET_ARCH_X64
621 #include "src/x64/code-stubs-x64.h"
622 #elif V8_TARGET_ARCH_ARM64
623 #include "src/arm64/code-stubs-arm64.h"
624 #elif V8_TARGET_ARCH_ARM
625 #include "src/arm/code-stubs-arm.h"
626 #elif V8_TARGET_ARCH_PPC
627 #include "src/ppc/code-stubs-ppc.h"
628 #elif V8_TARGET_ARCH_MIPS
629 #include "src/mips/code-stubs-mips.h"
630 #elif V8_TARGET_ARCH_MIPS64
631 #include "src/mips64/code-stubs-mips64.h"
632 #elif V8_TARGET_ARCH_X87
633 #include "src/x87/code-stubs-x87.h"
635 #error Unsupported target architecture.
642 // RuntimeCallHelper implementation used in stubs: enters/leaves a
643 // newly created internal frame before/after the runtime call.
644 class StubRuntimeCallHelper : public RuntimeCallHelper {
646 StubRuntimeCallHelper() {}
648 virtual void BeforeCall(MacroAssembler* masm) const;
650 virtual void AfterCall(MacroAssembler* masm) const;
654 // Trivial RuntimeCallHelper implementation.
655 class NopRuntimeCallHelper : public RuntimeCallHelper {
657 NopRuntimeCallHelper() {}
659 virtual void BeforeCall(MacroAssembler* masm) const {}
661 virtual void AfterCall(MacroAssembler* masm) const {}
665 class MathFloorStub : public TurboFanIC {
667 explicit MathFloorStub(Isolate* isolate, TurboFanIC::CallMode mode)
668 : TurboFanIC(isolate, mode) {}
669 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
670 DEFINE_TURBOFAN_IC(MathFloor, TurboFanIC, MathRoundVariant);
674 class StringLengthTFStub : public TurboFanCodeStub {
676 explicit StringLengthTFStub(Isolate* isolate) : TurboFanCodeStub(isolate) {}
678 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
679 InlineCacheState GetICState() const override { return MONOMORPHIC; }
680 ExtraICState GetExtraICState() const override { return Code::LOAD_IC; }
682 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
683 DEFINE_CODE_STUB(StringLengthTF, TurboFanCodeStub);
687 enum StringAddFlags {
688 // Omit both parameter checks.
689 STRING_ADD_CHECK_NONE = 0,
690 // Check left parameter.
691 STRING_ADD_CHECK_LEFT = 1 << 0,
692 // Check right parameter.
693 STRING_ADD_CHECK_RIGHT = 1 << 1,
694 // Check both parameters.
695 STRING_ADD_CHECK_BOTH = STRING_ADD_CHECK_LEFT | STRING_ADD_CHECK_RIGHT
699 std::ostream& operator<<(std::ostream& os, const StringAddFlags& flags);
702 class StringAddTFStub : public TurboFanCodeStub {
704 StringAddTFStub(Isolate* isolate, StringAddFlags flags,
705 PretenureFlag pretenure_flag)
706 : TurboFanCodeStub(isolate) {
707 minor_key_ = StringAddFlagsBits::encode(flags) |
708 PretenureFlagBits::encode(pretenure_flag);
711 StringAddFlags flags() const {
712 return StringAddFlagsBits::decode(MinorKey());
715 PretenureFlag pretenure_flag() const {
716 return PretenureFlagBits::decode(MinorKey());
720 class StringAddFlagsBits : public BitField<StringAddFlags, 0, 2> {};
721 class PretenureFlagBits : public BitField<PretenureFlag, 2, 1> {};
723 void PrintBaseName(std::ostream& os) const override; // NOLINT
725 DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
726 DEFINE_CODE_STUB(StringAddTF, TurboFanCodeStub);
730 class NumberToStringStub final : public HydrogenCodeStub {
732 explicit NumberToStringStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
734 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
735 static const int kNumber = 0;
737 DEFINE_CALL_INTERFACE_DESCRIPTOR(NumberToString);
738 DEFINE_HYDROGEN_CODE_STUB(NumberToString, HydrogenCodeStub);
742 class TypeofStub final : public HydrogenCodeStub {
744 explicit TypeofStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
746 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
747 static const int kObject = 0;
749 static void GenerateAheadOfTime(Isolate* isolate);
751 DEFINE_CALL_INTERFACE_DESCRIPTOR(Typeof);
752 DEFINE_HYDROGEN_CODE_STUB(Typeof, HydrogenCodeStub);
756 class FastNewClosureStub : public HydrogenCodeStub {
758 FastNewClosureStub(Isolate* isolate, LanguageMode language_mode,
760 : HydrogenCodeStub(isolate) {
761 DCHECK(IsValidFunctionKind(kind));
762 set_sub_minor_key(LanguageModeBits::encode(language_mode) |
763 FunctionKindBits::encode(kind));
766 LanguageMode language_mode() const {
767 return LanguageModeBits::decode(sub_minor_key());
770 FunctionKind kind() const {
771 return FunctionKindBits::decode(sub_minor_key());
775 STATIC_ASSERT(LANGUAGE_END == 3);
776 class LanguageModeBits : public BitField<LanguageMode, 0, 2> {};
777 class FunctionKindBits : public BitField<FunctionKind, 2, 8> {};
779 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewClosure);
780 DEFINE_HYDROGEN_CODE_STUB(FastNewClosure, HydrogenCodeStub);
784 class FastNewContextStub final : public HydrogenCodeStub {
786 static const int kMaximumSlots = 64;
788 FastNewContextStub(Isolate* isolate, int slots) : HydrogenCodeStub(isolate) {
789 DCHECK(slots >= 0 && slots <= kMaximumSlots);
790 set_sub_minor_key(SlotsBits::encode(slots));
793 int slots() const { return SlotsBits::decode(sub_minor_key()); }
795 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
796 static const int kFunction = 0;
799 class SlotsBits : public BitField<int, 0, 8> {};
801 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastNewContext);
802 DEFINE_HYDROGEN_CODE_STUB(FastNewContext, HydrogenCodeStub);
806 class FastCloneShallowArrayStub : public HydrogenCodeStub {
808 FastCloneShallowArrayStub(Isolate* isolate,
809 AllocationSiteMode allocation_site_mode)
810 : HydrogenCodeStub(isolate) {
811 set_sub_minor_key(AllocationSiteModeBits::encode(allocation_site_mode));
814 AllocationSiteMode allocation_site_mode() const {
815 return AllocationSiteModeBits::decode(sub_minor_key());
819 class AllocationSiteModeBits: public BitField<AllocationSiteMode, 0, 1> {};
821 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowArray);
822 DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowArray, HydrogenCodeStub);
826 class FastCloneShallowObjectStub : public HydrogenCodeStub {
828 // Maximum number of properties in copied object.
829 static const int kMaximumClonedProperties = 6;
831 FastCloneShallowObjectStub(Isolate* isolate, int length)
832 : HydrogenCodeStub(isolate) {
833 DCHECK_GE(length, 0);
834 DCHECK_LE(length, kMaximumClonedProperties);
835 set_sub_minor_key(LengthBits::encode(length));
838 int length() const { return LengthBits::decode(sub_minor_key()); }
841 class LengthBits : public BitField<int, 0, 4> {};
843 DEFINE_CALL_INTERFACE_DESCRIPTOR(FastCloneShallowObject);
844 DEFINE_HYDROGEN_CODE_STUB(FastCloneShallowObject, HydrogenCodeStub);
848 class CreateAllocationSiteStub : public HydrogenCodeStub {
850 explicit CreateAllocationSiteStub(Isolate* isolate)
851 : HydrogenCodeStub(isolate) { }
853 static void GenerateAheadOfTime(Isolate* isolate);
855 DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateAllocationSite);
856 DEFINE_HYDROGEN_CODE_STUB(CreateAllocationSite, HydrogenCodeStub);
860 class CreateWeakCellStub : public HydrogenCodeStub {
862 explicit CreateWeakCellStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
864 static void GenerateAheadOfTime(Isolate* isolate);
866 DEFINE_CALL_INTERFACE_DESCRIPTOR(CreateWeakCell);
867 DEFINE_HYDROGEN_CODE_STUB(CreateWeakCell, HydrogenCodeStub);
871 class GrowArrayElementsStub : public HydrogenCodeStub {
873 GrowArrayElementsStub(Isolate* isolate, bool is_js_array, ElementsKind kind)
874 : HydrogenCodeStub(isolate) {
875 set_sub_minor_key(ElementsKindBits::encode(kind) |
876 IsJsArrayBits::encode(is_js_array));
879 ElementsKind elements_kind() const {
880 return ElementsKindBits::decode(sub_minor_key());
883 bool is_js_array() const { return IsJsArrayBits::decode(sub_minor_key()); }
886 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
887 class IsJsArrayBits : public BitField<bool, ElementsKindBits::kNext, 1> {};
889 DEFINE_CALL_INTERFACE_DESCRIPTOR(GrowArrayElements);
890 DEFINE_HYDROGEN_CODE_STUB(GrowArrayElements, HydrogenCodeStub);
893 class InstanceofStub: public PlatformCodeStub {
897 kArgsInRegisters = 1 << 0,
898 kCallSiteInlineCheck = 1 << 1,
899 kReturnTrueFalseObject = 1 << 2
902 InstanceofStub(Isolate* isolate, Flags flags) : PlatformCodeStub(isolate) {
903 minor_key_ = FlagBits::encode(flags);
906 static Register left() { return InstanceofDescriptor::left(); }
907 static Register right() { return InstanceofDescriptor::right(); }
909 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
910 if (HasArgsInRegisters()) {
911 return InstanceofDescriptor(isolate());
913 return ContextOnlyDescriptor(isolate());
917 Flags flags() const { return FlagBits::decode(minor_key_); }
919 bool HasArgsInRegisters() const { return (flags() & kArgsInRegisters) != 0; }
921 bool HasCallSiteInlineCheck() const {
922 return (flags() & kCallSiteInlineCheck) != 0;
925 bool ReturnTrueFalseObject() const {
926 return (flags() & kReturnTrueFalseObject) != 0;
929 void PrintName(std::ostream& os) const override; // NOLINT
931 class FlagBits : public BitField<Flags, 0, 3> {};
933 DEFINE_PLATFORM_CODE_STUB(Instanceof, PlatformCodeStub);
937 enum AllocationSiteOverrideMode {
939 DISABLE_ALLOCATION_SITES,
940 LAST_ALLOCATION_SITE_OVERRIDE_MODE = DISABLE_ALLOCATION_SITES
944 class ArrayConstructorStub: public PlatformCodeStub {
946 enum ArgumentCountKey { ANY, NONE, ONE, MORE_THAN_ONE };
948 ArrayConstructorStub(Isolate* isolate, int argument_count);
950 explicit ArrayConstructorStub(Isolate* isolate);
953 ArgumentCountKey argument_count() const {
954 return ArgumentCountBits::decode(minor_key_);
957 void GenerateDispatchToArrayStub(MacroAssembler* masm,
958 AllocationSiteOverrideMode mode);
960 void PrintName(std::ostream& os) const override; // NOLINT
962 class ArgumentCountBits : public BitField<ArgumentCountKey, 0, 2> {};
964 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
965 DEFINE_PLATFORM_CODE_STUB(ArrayConstructor, PlatformCodeStub);
969 class InternalArrayConstructorStub: public PlatformCodeStub {
971 explicit InternalArrayConstructorStub(Isolate* isolate);
974 void GenerateCase(MacroAssembler* masm, ElementsKind kind);
976 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
977 DEFINE_PLATFORM_CODE_STUB(InternalArrayConstructor, PlatformCodeStub);
981 class MathPowStub: public PlatformCodeStub {
983 enum ExponentType { INTEGER, DOUBLE, TAGGED, ON_STACK };
985 MathPowStub(Isolate* isolate, ExponentType exponent_type)
986 : PlatformCodeStub(isolate) {
987 minor_key_ = ExponentTypeBits::encode(exponent_type);
990 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
991 if (exponent_type() == TAGGED) {
992 return MathPowTaggedDescriptor(isolate());
993 } else if (exponent_type() == INTEGER) {
994 return MathPowIntegerDescriptor(isolate());
996 // A CallInterfaceDescriptor doesn't specify double registers (yet).
997 return ContextOnlyDescriptor(isolate());
1001 ExponentType exponent_type() const {
1002 return ExponentTypeBits::decode(minor_key_);
1005 class ExponentTypeBits : public BitField<ExponentType, 0, 2> {};
1007 DEFINE_PLATFORM_CODE_STUB(MathPow, PlatformCodeStub);
1011 class CallICStub: public PlatformCodeStub {
1013 CallICStub(Isolate* isolate, const CallICState& state)
1014 : PlatformCodeStub(isolate) {
1015 minor_key_ = state.GetExtraICState();
1018 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
1020 InlineCacheState GetICState() const override { return DEFAULT; }
1022 ExtraICState GetExtraICState() const final {
1023 return static_cast<ExtraICState>(minor_key_);
1027 bool CallAsMethod() const {
1028 return state().call_type() == CallICState::METHOD;
1031 int arg_count() const { return state().arg_count(); }
1033 CallICState state() const {
1034 return CallICState(static_cast<ExtraICState>(minor_key_));
1037 // Code generation helpers.
1038 void GenerateMiss(MacroAssembler* masm);
1041 void PrintState(std::ostream& os) const override; // NOLINT
1043 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedbackAndVector);
1044 DEFINE_PLATFORM_CODE_STUB(CallIC, PlatformCodeStub);
1048 class CallIC_ArrayStub: public CallICStub {
1050 CallIC_ArrayStub(Isolate* isolate, const CallICState& state_in)
1051 : CallICStub(isolate, state_in) {}
1053 InlineCacheState GetICState() const final { return MONOMORPHIC; }
1056 void PrintState(std::ostream& os) const override; // NOLINT
1058 DEFINE_PLATFORM_CODE_STUB(CallIC_Array, CallICStub);
1062 // TODO(verwaest): Translate to hydrogen code stub.
1063 class FunctionPrototypeStub : public PlatformCodeStub {
1065 explicit FunctionPrototypeStub(Isolate* isolate)
1066 : PlatformCodeStub(isolate) {}
1068 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1070 // TODO(mvstanton): only the receiver register is accessed. When this is
1071 // translated to a hydrogen code stub, a new CallInterfaceDescriptor
1072 // should be created that just uses that register for more efficient code.
1073 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1074 return LoadWithVectorDescriptor(isolate());
1077 DEFINE_PLATFORM_CODE_STUB(FunctionPrototype, PlatformCodeStub);
1081 // TODO(mvstanton): Translate to hydrogen code stub.
1082 class LoadIndexedInterceptorStub : public PlatformCodeStub {
1084 explicit LoadIndexedInterceptorStub(Isolate* isolate)
1085 : PlatformCodeStub(isolate) {}
1087 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1088 Code::StubType GetStubType() const override { return Code::FAST; }
1090 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
1091 DEFINE_PLATFORM_CODE_STUB(LoadIndexedInterceptor, PlatformCodeStub);
1095 class LoadIndexedStringStub : public PlatformCodeStub {
1097 explicit LoadIndexedStringStub(Isolate* isolate)
1098 : PlatformCodeStub(isolate) {}
1100 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1101 Code::StubType GetStubType() const override { return Code::FAST; }
1103 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
1104 DEFINE_PLATFORM_CODE_STUB(LoadIndexedString, PlatformCodeStub);
1108 class HandlerStub : public HydrogenCodeStub {
1110 Code::Kind GetCodeKind() const override { return Code::HANDLER; }
1111 ExtraICState GetExtraICState() const override { return kind(); }
1112 InlineCacheState GetICState() const override { return MONOMORPHIC; }
1114 void InitializeDescriptor(CodeStubDescriptor* descriptor) override;
1116 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override;
1119 explicit HandlerStub(Isolate* isolate) : HydrogenCodeStub(isolate) {}
1121 virtual Code::Kind kind() const = 0;
1123 DEFINE_CODE_STUB_BASE(HandlerStub, HydrogenCodeStub);
1127 class LoadFieldStub: public HandlerStub {
1129 LoadFieldStub(Isolate* isolate, FieldIndex index) : HandlerStub(isolate) {
1130 int property_index_key = index.GetFieldAccessStubKey();
1131 set_sub_minor_key(LoadFieldByIndexBits::encode(property_index_key));
1134 FieldIndex index() const {
1135 int property_index_key = LoadFieldByIndexBits::decode(sub_minor_key());
1136 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1140 Code::Kind kind() const override { return Code::LOAD_IC; }
1141 Code::StubType GetStubType() const override { return Code::FAST; }
1144 class LoadFieldByIndexBits : public BitField<int, 0, 13> {};
1146 DEFINE_HANDLER_CODE_STUB(LoadField, HandlerStub);
1150 class ArrayBufferViewLoadFieldStub : public HandlerStub {
1152 ArrayBufferViewLoadFieldStub(Isolate* isolate, FieldIndex index)
1153 : HandlerStub(isolate) {
1154 int property_index_key = index.GetFieldAccessStubKey();
1156 ArrayBufferViewLoadFieldByIndexBits::encode(property_index_key));
1159 FieldIndex index() const {
1160 int property_index_key =
1161 ArrayBufferViewLoadFieldByIndexBits::decode(sub_minor_key());
1162 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1166 Code::Kind kind() const override { return Code::LOAD_IC; }
1167 Code::StubType GetStubType() const override { return Code::FAST; }
1170 class ArrayBufferViewLoadFieldByIndexBits : public BitField<int, 0, 13> {};
1172 DEFINE_HANDLER_CODE_STUB(ArrayBufferViewLoadField, HandlerStub);
1176 class KeyedLoadSloppyArgumentsStub : public HandlerStub {
1178 explicit KeyedLoadSloppyArgumentsStub(Isolate* isolate)
1179 : HandlerStub(isolate) {}
1182 Code::Kind kind() const override { return Code::KEYED_LOAD_IC; }
1183 Code::StubType GetStubType() const override { return Code::FAST; }
1186 DEFINE_HANDLER_CODE_STUB(KeyedLoadSloppyArguments, HandlerStub);
1190 class KeyedStoreSloppyArgumentsStub : public HandlerStub {
1192 explicit KeyedStoreSloppyArgumentsStub(Isolate* isolate)
1193 : HandlerStub(isolate) {}
1196 Code::Kind kind() const override { return Code::KEYED_STORE_IC; }
1197 Code::StubType GetStubType() const override { return Code::FAST; }
1200 DEFINE_HANDLER_CODE_STUB(KeyedStoreSloppyArguments, HandlerStub);
1204 class LoadConstantStub : public HandlerStub {
1206 LoadConstantStub(Isolate* isolate, int constant_index)
1207 : HandlerStub(isolate) {
1208 set_sub_minor_key(ConstantIndexBits::encode(constant_index));
1211 int constant_index() const {
1212 return ConstantIndexBits::decode(sub_minor_key());
1216 Code::Kind kind() const override { return Code::LOAD_IC; }
1217 Code::StubType GetStubType() const override { return Code::FAST; }
1220 class ConstantIndexBits : public BitField<int, 0, kSubMinorKeyBits> {};
1222 DEFINE_HANDLER_CODE_STUB(LoadConstant, HandlerStub);
1226 class StringLengthStub: public HandlerStub {
1228 explicit StringLengthStub(Isolate* isolate) : HandlerStub(isolate) {}
1231 Code::Kind kind() const override { return Code::LOAD_IC; }
1232 Code::StubType GetStubType() const override { return Code::FAST; }
1234 DEFINE_HANDLER_CODE_STUB(StringLength, HandlerStub);
1238 class StoreFieldStub : public HandlerStub {
1240 StoreFieldStub(Isolate* isolate, FieldIndex index,
1241 Representation representation)
1242 : HandlerStub(isolate) {
1243 int property_index_key = index.GetFieldAccessStubKey();
1244 uint8_t repr = PropertyDetails::EncodeRepresentation(representation);
1245 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) |
1246 RepresentationBits::encode(repr));
1249 FieldIndex index() const {
1250 int property_index_key = StoreFieldByIndexBits::decode(sub_minor_key());
1251 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1254 Representation representation() {
1255 uint8_t repr = RepresentationBits::decode(sub_minor_key());
1256 return PropertyDetails::DecodeRepresentation(repr);
1260 Code::Kind kind() const override { return Code::STORE_IC; }
1261 Code::StubType GetStubType() const override { return Code::FAST; }
1264 class StoreFieldByIndexBits : public BitField<int, 0, 13> {};
1265 class RepresentationBits : public BitField<uint8_t, 13, 4> {};
1267 DEFINE_HANDLER_CODE_STUB(StoreField, HandlerStub);
1271 class StoreTransitionStub : public HandlerStub {
1276 ExtendStorageAndStoreMapAndValue
1279 explicit StoreTransitionStub(Isolate* isolate) : HandlerStub(isolate) {
1280 set_sub_minor_key(StoreModeBits::encode(StoreMapOnly));
1283 StoreTransitionStub(Isolate* isolate, FieldIndex index,
1284 Representation representation, StoreMode store_mode)
1285 : HandlerStub(isolate) {
1286 DCHECK(store_mode != StoreMapOnly);
1287 int property_index_key = index.GetFieldAccessStubKey();
1288 uint8_t repr = PropertyDetails::EncodeRepresentation(representation);
1289 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) |
1290 RepresentationBits::encode(repr) |
1291 StoreModeBits::encode(store_mode));
1294 FieldIndex index() const {
1295 DCHECK(store_mode() != StoreMapOnly);
1296 int property_index_key = StoreFieldByIndexBits::decode(sub_minor_key());
1297 return FieldIndex::FromFieldAccessStubKey(property_index_key);
1300 Representation representation() {
1301 DCHECK(store_mode() != StoreMapOnly);
1302 uint8_t repr = RepresentationBits::decode(sub_minor_key());
1303 return PropertyDetails::DecodeRepresentation(repr);
1306 StoreMode store_mode() const {
1307 return StoreModeBits::decode(sub_minor_key());
1310 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override;
1313 Code::Kind kind() const override { return Code::STORE_IC; }
1314 Code::StubType GetStubType() const override { return Code::FAST; }
1317 class StoreFieldByIndexBits : public BitField<int, 0, 13> {};
1318 class RepresentationBits : public BitField<uint8_t, 13, 4> {};
1319 class StoreModeBits : public BitField<StoreMode, 17, 2> {};
1321 DEFINE_HANDLER_CODE_STUB(StoreTransition, HandlerStub);
1325 class StoreGlobalStub : public HandlerStub {
1327 StoreGlobalStub(Isolate* isolate, PropertyCellType type,
1328 Maybe<PropertyCellConstantType> constant_type,
1330 : HandlerStub(isolate) {
1331 PropertyCellConstantType encoded_constant_type =
1332 constant_type.FromMaybe(PropertyCellConstantType::kSmi);
1333 set_sub_minor_key(CellTypeBits::encode(type) |
1334 ConstantTypeBits::encode(encoded_constant_type) |
1335 CheckGlobalBits::encode(check_global));
1338 static Handle<HeapObject> property_cell_placeholder(Isolate* isolate) {
1339 return isolate->factory()->uninitialized_value();
1342 static Handle<HeapObject> global_map_placeholder(Isolate* isolate) {
1343 return isolate->factory()->termination_exception();
1346 Handle<Code> GetCodeCopyFromTemplate(Handle<GlobalObject> global,
1347 Handle<PropertyCell> cell) {
1348 Code::FindAndReplacePattern pattern;
1349 if (check_global()) {
1350 pattern.Add(handle(global_map_placeholder(isolate())->map()),
1351 Map::WeakCellForMap(Handle<Map>(global->map())));
1353 pattern.Add(handle(property_cell_placeholder(isolate())->map()),
1354 isolate()->factory()->NewWeakCell(cell));
1355 return CodeStub::GetCodeCopy(pattern);
1358 Code::Kind kind() const override { return Code::STORE_IC; }
1360 PropertyCellType cell_type() const {
1361 return CellTypeBits::decode(sub_minor_key());
1364 PropertyCellConstantType constant_type() const {
1365 DCHECK(PropertyCellType::kConstantType == cell_type());
1366 return ConstantTypeBits::decode(sub_minor_key());
1369 bool check_global() const { return CheckGlobalBits::decode(sub_minor_key()); }
1371 Representation representation() {
1372 return Representation::FromKind(
1373 RepresentationBits::decode(sub_minor_key()));
1376 void set_representation(Representation r) {
1377 set_sub_minor_key(RepresentationBits::update(sub_minor_key(), r.kind()));
1381 class CellTypeBits : public BitField<PropertyCellType, 0, 2> {};
1382 class ConstantTypeBits : public BitField<PropertyCellConstantType, 2, 2> {};
1383 class RepresentationBits : public BitField<Representation::Kind, 4, 8> {};
1384 class CheckGlobalBits : public BitField<bool, 12, 1> {};
1386 DEFINE_HANDLER_CODE_STUB(StoreGlobal, HandlerStub);
1390 class LoadGlobalViaContextStub : public HydrogenCodeStub {
1392 // Use the loop version for depths higher than this one.
1393 static const int kDynamicDepth = 7;
1395 LoadGlobalViaContextStub(Isolate* isolate, int depth)
1396 : HydrogenCodeStub(isolate) {
1397 if (depth > kDynamicDepth) depth = kDynamicDepth;
1398 set_sub_minor_key(DepthBits::encode(depth));
1401 int depth() const { return DepthBits::decode(sub_minor_key()); }
1404 class DepthBits : public BitField<unsigned int, 0, 3> {};
1405 STATIC_ASSERT(kDynamicDepth <= DepthBits::kMax);
1407 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadGlobalViaContext);
1408 DEFINE_HYDROGEN_CODE_STUB(LoadGlobalViaContext, HydrogenCodeStub);
1412 class StoreGlobalViaContextStub : public HydrogenCodeStub {
1414 // Use the loop version for depths higher than this one.
1415 static const int kDynamicDepth = 7;
1417 StoreGlobalViaContextStub(Isolate* isolate, int depth,
1418 LanguageMode language_mode)
1419 : HydrogenCodeStub(isolate) {
1420 if (depth > kDynamicDepth) depth = kDynamicDepth;
1421 set_sub_minor_key(DepthBits::encode(depth) |
1422 LanguageModeBits::encode(language_mode));
1425 int depth() const { return DepthBits::decode(sub_minor_key()); }
1427 LanguageMode language_mode() const {
1428 return LanguageModeBits::decode(sub_minor_key());
1432 class DepthBits : public BitField<unsigned int, 0, 4> {};
1433 STATIC_ASSERT(kDynamicDepth <= DepthBits::kMax);
1435 class LanguageModeBits : public BitField<LanguageMode, 4, 2> {};
1436 STATIC_ASSERT(LANGUAGE_END == 3);
1439 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreGlobalViaContext);
1440 DEFINE_HYDROGEN_CODE_STUB(StoreGlobalViaContext, HydrogenCodeStub);
1444 class CallApiFunctionStub : public PlatformCodeStub {
1446 explicit CallApiFunctionStub(Isolate* isolate, bool call_data_undefined)
1447 : PlatformCodeStub(isolate) {
1448 minor_key_ = CallDataUndefinedBits::encode(call_data_undefined);
1452 bool call_data_undefined() const {
1453 return CallDataUndefinedBits::decode(minor_key_);
1456 class CallDataUndefinedBits : public BitField<bool, 0, 1> {};
1458 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiFunction);
1459 DEFINE_PLATFORM_CODE_STUB(CallApiFunction, PlatformCodeStub);
1463 class CallApiAccessorStub : public PlatformCodeStub {
1465 CallApiAccessorStub(Isolate* isolate, bool is_store, bool call_data_undefined)
1466 : PlatformCodeStub(isolate) {
1467 minor_key_ = IsStoreBits::encode(is_store) |
1468 CallDataUndefinedBits::encode(call_data_undefined) |
1469 ArgumentBits::encode(is_store ? 1 : 0);
1473 // For CallApiFunctionWithFixedArgsStub, see below.
1474 static const int kArgBits = 3;
1475 CallApiAccessorStub(Isolate* isolate, int argc, bool call_data_undefined)
1476 : PlatformCodeStub(isolate) {
1477 minor_key_ = IsStoreBits::encode(false) |
1478 CallDataUndefinedBits::encode(call_data_undefined) |
1479 ArgumentBits::encode(argc);
1483 bool is_store() const { return IsStoreBits::decode(minor_key_); }
1484 bool call_data_undefined() const {
1485 return CallDataUndefinedBits::decode(minor_key_);
1487 int argc() const { return ArgumentBits::decode(minor_key_); }
1489 class IsStoreBits: public BitField<bool, 0, 1> {};
1490 class CallDataUndefinedBits: public BitField<bool, 1, 1> {};
1491 class ArgumentBits : public BitField<int, 2, kArgBits> {};
1493 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiAccessor);
1494 DEFINE_PLATFORM_CODE_STUB(CallApiAccessor, PlatformCodeStub);
1498 // TODO(dcarney): see if it's possible to remove this later without performance
1500 // This is not a real stub, but a way of generating the CallApiAccessorStub
1501 // (which has the same abi) which makes it clear that it is not an accessor.
1502 class CallApiFunctionWithFixedArgsStub : public CallApiAccessorStub {
1504 static const int kMaxFixedArgs = (1 << kArgBits) - 1;
1505 CallApiFunctionWithFixedArgsStub(Isolate* isolate, int argc,
1506 bool call_data_undefined)
1507 : CallApiAccessorStub(isolate, argc, call_data_undefined) {
1508 DCHECK(0 <= argc && argc <= kMaxFixedArgs);
1513 typedef ApiAccessorDescriptor ApiFunctionWithFixedArgsDescriptor;
1516 class CallApiGetterStub : public PlatformCodeStub {
1518 explicit CallApiGetterStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
1520 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiGetter);
1521 DEFINE_PLATFORM_CODE_STUB(CallApiGetter, PlatformCodeStub);
1525 class BinaryOpICStub : public HydrogenCodeStub {
1527 BinaryOpICStub(Isolate* isolate, Token::Value op, Strength strength)
1528 : HydrogenCodeStub(isolate, UNINITIALIZED) {
1529 BinaryOpICState state(isolate, op, strength);
1530 set_sub_minor_key(state.GetExtraICState());
1533 BinaryOpICStub(Isolate* isolate, const BinaryOpICState& state)
1534 : HydrogenCodeStub(isolate) {
1535 set_sub_minor_key(state.GetExtraICState());
1538 static void GenerateAheadOfTime(Isolate* isolate);
1540 Code::Kind GetCodeKind() const override { return Code::BINARY_OP_IC; }
1542 InlineCacheState GetICState() const final { return state().GetICState(); }
1544 ExtraICState GetExtraICState() const final {
1545 return static_cast<ExtraICState>(sub_minor_key());
1548 BinaryOpICState state() const {
1549 return BinaryOpICState(isolate(), GetExtraICState());
1552 void PrintState(std::ostream& os) const final; // NOLINT
1554 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1555 static const int kLeft = 0;
1556 static const int kRight = 1;
1559 static void GenerateAheadOfTime(Isolate* isolate,
1560 const BinaryOpICState& state);
1562 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
1563 DEFINE_HYDROGEN_CODE_STUB(BinaryOpIC, HydrogenCodeStub);
1567 // TODO(bmeurer): Merge this into the BinaryOpICStub once we have proper tail
1568 // call support for stubs in Hydrogen.
1569 class BinaryOpICWithAllocationSiteStub final : public PlatformCodeStub {
1571 BinaryOpICWithAllocationSiteStub(Isolate* isolate,
1572 const BinaryOpICState& state)
1573 : PlatformCodeStub(isolate) {
1574 minor_key_ = state.GetExtraICState();
1577 static void GenerateAheadOfTime(Isolate* isolate);
1579 Handle<Code> GetCodeCopyFromTemplate(Handle<AllocationSite> allocation_site) {
1580 Code::FindAndReplacePattern pattern;
1581 pattern.Add(isolate()->factory()->undefined_map(), allocation_site);
1582 return CodeStub::GetCodeCopy(pattern);
1585 Code::Kind GetCodeKind() const override { return Code::BINARY_OP_IC; }
1587 InlineCacheState GetICState() const override { return state().GetICState(); }
1589 ExtraICState GetExtraICState() const override {
1590 return static_cast<ExtraICState>(minor_key_);
1593 void PrintState(std::ostream& os) const override; // NOLINT
1596 BinaryOpICState state() const {
1597 return BinaryOpICState(isolate(), static_cast<ExtraICState>(minor_key_));
1600 static void GenerateAheadOfTime(Isolate* isolate,
1601 const BinaryOpICState& state);
1603 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithAllocationSite);
1604 DEFINE_PLATFORM_CODE_STUB(BinaryOpICWithAllocationSite, PlatformCodeStub);
1608 class BinaryOpWithAllocationSiteStub final : public BinaryOpICStub {
1610 BinaryOpWithAllocationSiteStub(Isolate* isolate, Token::Value op,
1612 : BinaryOpICStub(isolate, op, strength) {}
1614 BinaryOpWithAllocationSiteStub(Isolate* isolate, const BinaryOpICState& state)
1615 : BinaryOpICStub(isolate, state) {}
1617 Code::Kind GetCodeKind() const final { return Code::STUB; }
1619 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1620 static const int kAllocationSite = 0;
1621 static const int kLeft = 1;
1622 static const int kRight = 2;
1624 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithAllocationSite);
1625 DEFINE_HYDROGEN_CODE_STUB(BinaryOpWithAllocationSite, BinaryOpICStub);
1629 class StringAddStub final : public HydrogenCodeStub {
1631 StringAddStub(Isolate* isolate, StringAddFlags flags,
1632 PretenureFlag pretenure_flag)
1633 : HydrogenCodeStub(isolate) {
1634 set_sub_minor_key(StringAddFlagsBits::encode(flags) |
1635 PretenureFlagBits::encode(pretenure_flag));
1638 StringAddFlags flags() const {
1639 return StringAddFlagsBits::decode(sub_minor_key());
1642 PretenureFlag pretenure_flag() const {
1643 return PretenureFlagBits::decode(sub_minor_key());
1646 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1647 static const int kLeft = 0;
1648 static const int kRight = 1;
1651 class StringAddFlagsBits: public BitField<StringAddFlags, 0, 2> {};
1652 class PretenureFlagBits: public BitField<PretenureFlag, 2, 1> {};
1654 void PrintBaseName(std::ostream& os) const override; // NOLINT
1656 DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
1657 DEFINE_HYDROGEN_CODE_STUB(StringAdd, HydrogenCodeStub);
1661 class CompareICStub : public PlatformCodeStub {
1663 CompareICStub(Isolate* isolate, Token::Value op, Strength strength,
1664 CompareICState::State left, CompareICState::State right,
1665 CompareICState::State state)
1666 : PlatformCodeStub(isolate) {
1667 DCHECK(Token::IsCompareOp(op));
1668 minor_key_ = OpBits::encode(op - Token::EQ) |
1669 StrengthBits::encode(is_strong(strength)) |
1670 LeftStateBits::encode(left) | RightStateBits::encode(right) |
1671 StateBits::encode(state);
1674 void set_known_map(Handle<Map> map) { known_map_ = map; }
1676 InlineCacheState GetICState() const override;
1678 Token::Value op() const {
1679 return static_cast<Token::Value>(Token::EQ + OpBits::decode(minor_key_));
1682 Strength strength() const {
1683 return StrengthBits::decode(minor_key_) ? Strength::STRONG : Strength::WEAK;
1686 CompareICState::State left() const {
1687 return LeftStateBits::decode(minor_key_);
1689 CompareICState::State right() const {
1690 return RightStateBits::decode(minor_key_);
1692 CompareICState::State state() const { return StateBits::decode(minor_key_); }
1695 Code::Kind GetCodeKind() const override { return Code::COMPARE_IC; }
1697 void GenerateSmis(MacroAssembler* masm);
1698 void GenerateNumbers(MacroAssembler* masm);
1699 void GenerateInternalizedStrings(MacroAssembler* masm);
1700 void GenerateStrings(MacroAssembler* masm);
1701 void GenerateUniqueNames(MacroAssembler* masm);
1702 void GenerateObjects(MacroAssembler* masm);
1703 void GenerateMiss(MacroAssembler* masm);
1704 void GenerateKnownObjects(MacroAssembler* masm);
1705 void GenerateGeneric(MacroAssembler* masm);
1707 bool strict() const { return op() == Token::EQ_STRICT; }
1708 Condition GetCondition() const;
1710 void AddToSpecialCache(Handle<Code> new_object) override;
1711 bool FindCodeInSpecialCache(Code** code_out) override;
1712 bool UseSpecialCache() override {
1713 return state() == CompareICState::KNOWN_OBJECT;
1716 class OpBits : public BitField<int, 0, 3> {};
1717 class StrengthBits : public BitField<bool, 3, 1> {};
1718 class LeftStateBits : public BitField<CompareICState::State, 4, 4> {};
1719 class RightStateBits : public BitField<CompareICState::State, 8, 4> {};
1720 class StateBits : public BitField<CompareICState::State, 12, 4> {};
1722 Handle<Map> known_map_;
1724 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
1725 DEFINE_PLATFORM_CODE_STUB(CompareIC, PlatformCodeStub);
1729 class CompareNilICStub : public HydrogenCodeStub {
1731 Type* GetType(Zone* zone, Handle<Map> map = Handle<Map>());
1732 Type* GetInputType(Zone* zone, Handle<Map> map);
1734 CompareNilICStub(Isolate* isolate, NilValue nil) : HydrogenCodeStub(isolate) {
1735 set_sub_minor_key(NilValueBits::encode(nil));
1738 CompareNilICStub(Isolate* isolate, ExtraICState ic_state,
1739 InitializationState init_state = INITIALIZED)
1740 : HydrogenCodeStub(isolate, init_state) {
1741 set_sub_minor_key(ic_state);
1744 static Handle<Code> GetUninitialized(Isolate* isolate,
1746 return CompareNilICStub(isolate, nil, UNINITIALIZED).GetCode();
1749 InlineCacheState GetICState() const override {
1750 State state = this->state();
1751 if (state.Contains(GENERIC)) {
1753 } else if (state.Contains(MONOMORPHIC_MAP)) {
1756 return PREMONOMORPHIC;
1760 Code::Kind GetCodeKind() const override { return Code::COMPARE_NIL_IC; }
1762 ExtraICState GetExtraICState() const override { return sub_minor_key(); }
1764 void UpdateStatus(Handle<Object> object);
1766 bool IsMonomorphic() const { return state().Contains(MONOMORPHIC_MAP); }
1768 NilValue nil_value() const { return NilValueBits::decode(sub_minor_key()); }
1771 set_sub_minor_key(TypesBits::update(sub_minor_key(), 0));
1774 void PrintState(std::ostream& os) const override; // NOLINT
1775 void PrintBaseName(std::ostream& os) const override; // NOLINT
1778 CompareNilICStub(Isolate* isolate, NilValue nil,
1779 InitializationState init_state)
1780 : HydrogenCodeStub(isolate, init_state) {
1781 set_sub_minor_key(NilValueBits::encode(nil));
1784 enum CompareNilType {
1792 // At most 6 different types can be distinguished, because the Code object
1793 // only has room for a single byte to hold a set and there are two more
1794 // boolean flags we need to store. :-P
1795 STATIC_ASSERT(NUMBER_OF_TYPES <= 6);
1797 class State : public EnumSet<CompareNilType, byte> {
1799 State() : EnumSet<CompareNilType, byte>(0) { }
1800 explicit State(byte bits) : EnumSet<CompareNilType, byte>(bits) { }
1802 friend std::ostream& operator<<(std::ostream& os, const State& s);
1804 State state() const { return State(TypesBits::decode(sub_minor_key())); }
1806 class NilValueBits : public BitField<NilValue, 0, 1> {};
1807 class TypesBits : public BitField<byte, 1, NUMBER_OF_TYPES> {};
1809 friend class CompareNilIC;
1811 DEFINE_CALL_INTERFACE_DESCRIPTOR(CompareNil);
1812 DEFINE_HYDROGEN_CODE_STUB(CompareNilIC, HydrogenCodeStub);
1816 std::ostream& operator<<(std::ostream& os, const CompareNilICStub::State& s);
1819 class CEntryStub : public PlatformCodeStub {
1821 CEntryStub(Isolate* isolate, int result_size,
1822 SaveFPRegsMode save_doubles = kDontSaveFPRegs)
1823 : PlatformCodeStub(isolate) {
1824 minor_key_ = SaveDoublesBits::encode(save_doubles == kSaveFPRegs);
1825 DCHECK(result_size == 1 || result_size == 2);
1826 #if _WIN64 || V8_TARGET_ARCH_PPC
1827 minor_key_ = ResultSizeBits::update(minor_key_, result_size);
1831 // The version of this stub that doesn't save doubles is generated ahead of
1832 // time, so it's OK to call it from other stubs that can't cope with GC during
1833 // their code generation. On machines that always have gp registers (x64) we
1834 // can generate both variants ahead of time.
1835 static void GenerateAheadOfTime(Isolate* isolate);
1838 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
1839 #if _WIN64 || V8_TARGET_ARCH_PPC
1840 int result_size() const { return ResultSizeBits::decode(minor_key_); }
1843 bool NeedsImmovableCode() override;
1845 class SaveDoublesBits : public BitField<bool, 0, 1> {};
1846 class ResultSizeBits : public BitField<int, 1, 3> {};
1848 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
1849 DEFINE_PLATFORM_CODE_STUB(CEntry, PlatformCodeStub);
1853 class JSEntryStub : public PlatformCodeStub {
1855 JSEntryStub(Isolate* isolate, StackFrame::Type type)
1856 : PlatformCodeStub(isolate) {
1857 DCHECK(type == StackFrame::ENTRY || type == StackFrame::ENTRY_CONSTRUCT);
1858 minor_key_ = StackFrameTypeBits::encode(type);
1862 void FinishCode(Handle<Code> code) override;
1864 void PrintName(std::ostream& os) const override { // NOLINT
1865 os << (type() == StackFrame::ENTRY ? "JSEntryStub"
1866 : "JSConstructEntryStub");
1869 StackFrame::Type type() const {
1870 return StackFrameTypeBits::decode(minor_key_);
1873 class StackFrameTypeBits : public BitField<StackFrame::Type, 0, 5> {};
1875 int handler_offset_;
1877 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
1878 DEFINE_PLATFORM_CODE_STUB(JSEntry, PlatformCodeStub);
1882 class ArgumentsAccessStub: public PlatformCodeStub {
1891 ArgumentsAccessStub(Isolate* isolate, Type type) : PlatformCodeStub(isolate) {
1892 minor_key_ = TypeBits::encode(type);
1895 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1896 if (type() == READ_ELEMENT) {
1897 return ArgumentsAccessReadDescriptor(isolate());
1899 return ContextOnlyDescriptor(isolate());
1903 Type type() const { return TypeBits::decode(minor_key_); }
1905 void GenerateReadElement(MacroAssembler* masm);
1906 void GenerateNewStrict(MacroAssembler* masm);
1907 void GenerateNewSloppyFast(MacroAssembler* masm);
1908 void GenerateNewSloppySlow(MacroAssembler* masm);
1910 void PrintName(std::ostream& os) const override; // NOLINT
1912 class TypeBits : public BitField<Type, 0, 2> {};
1914 DEFINE_PLATFORM_CODE_STUB(ArgumentsAccess, PlatformCodeStub);
1918 class RestParamAccessStub: public PlatformCodeStub {
1920 explicit RestParamAccessStub(Isolate* isolate) : PlatformCodeStub(isolate) { }
1922 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1923 return ContextOnlyDescriptor(isolate());
1927 void GenerateNew(MacroAssembler* masm);
1929 void PrintName(std::ostream& os) const override; // NOLINT
1931 DEFINE_PLATFORM_CODE_STUB(RestParamAccess, PlatformCodeStub);
1935 class RegExpExecStub: public PlatformCodeStub {
1937 explicit RegExpExecStub(Isolate* isolate) : PlatformCodeStub(isolate) { }
1939 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
1940 DEFINE_PLATFORM_CODE_STUB(RegExpExec, PlatformCodeStub);
1944 class RegExpConstructResultStub final : public HydrogenCodeStub {
1946 explicit RegExpConstructResultStub(Isolate* isolate)
1947 : HydrogenCodeStub(isolate) { }
1949 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1950 static const int kLength = 0;
1951 static const int kIndex = 1;
1952 static const int kInput = 2;
1954 DEFINE_CALL_INTERFACE_DESCRIPTOR(RegExpConstructResult);
1955 DEFINE_HYDROGEN_CODE_STUB(RegExpConstructResult, HydrogenCodeStub);
1959 class CallFunctionStub: public PlatformCodeStub {
1961 CallFunctionStub(Isolate* isolate, int argc, CallFunctionFlags flags)
1962 : PlatformCodeStub(isolate) {
1963 DCHECK(argc >= 0 && argc <= Code::kMaxArguments);
1964 minor_key_ = ArgcBits::encode(argc) | FlagBits::encode(flags);
1968 int argc() const { return ArgcBits::decode(minor_key_); }
1969 int flags() const { return FlagBits::decode(minor_key_); }
1971 bool CallAsMethod() const {
1972 return flags() == CALL_AS_METHOD || flags() == WRAP_AND_CALL;
1975 bool NeedsChecks() const { return flags() != WRAP_AND_CALL; }
1977 void PrintName(std::ostream& os) const override; // NOLINT
1979 // Minor key encoding in 32 bits with Bitfield <Type, shift, size>.
1980 class FlagBits : public BitField<CallFunctionFlags, 0, 2> {};
1981 class ArgcBits : public BitField<unsigned, 2, Code::kArgumentsBits> {};
1982 STATIC_ASSERT(Code::kArgumentsBits + 2 <= kStubMinorKeyBits);
1984 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction);
1985 DEFINE_PLATFORM_CODE_STUB(CallFunction, PlatformCodeStub);
1989 class CallConstructStub: public PlatformCodeStub {
1991 CallConstructStub(Isolate* isolate, CallConstructorFlags flags)
1992 : PlatformCodeStub(isolate) {
1993 minor_key_ = FlagBits::encode(flags);
1996 void FinishCode(Handle<Code> code) override {
1997 code->set_has_function_cache(RecordCallTarget());
2001 CallConstructorFlags flags() const { return FlagBits::decode(minor_key_); }
2003 bool RecordCallTarget() const {
2004 return (flags() & RECORD_CONSTRUCTOR_TARGET) != 0;
2007 bool IsSuperConstructorCall() const {
2008 return (flags() & SUPER_CONSTRUCTOR_CALL) != 0;
2011 void PrintName(std::ostream& os) const override; // NOLINT
2013 class FlagBits : public BitField<CallConstructorFlags, 0, 2> {};
2015 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallConstruct);
2016 DEFINE_PLATFORM_CODE_STUB(CallConstruct, PlatformCodeStub);
2020 enum StringIndexFlags {
2021 // Accepts smis or heap numbers.
2022 STRING_INDEX_IS_NUMBER,
2024 // Accepts smis or heap numbers that are valid array indices
2025 // (ECMA-262 15.4). Invalid indices are reported as being out of
2027 STRING_INDEX_IS_ARRAY_INDEX
2031 enum ReceiverCheckMode {
2032 // We don't know anything about the receiver.
2033 RECEIVER_IS_UNKNOWN,
2035 // We know the receiver is a string.
2041 // The code being generated is part of an IC handler, which may MISS
2042 // to an IC in failure cases.
2045 NOT_PART_OF_IC_HANDLER
2049 // Generates code implementing String.prototype.charCodeAt.
2051 // Only supports the case when the receiver is a string and the index
2052 // is a number (smi or heap number) that is a valid index into the
2053 // string. Additional index constraints are specified by the
2054 // flags. Otherwise, bails out to the provided labels.
2056 // Register usage: |object| may be changed to another string in a way
2057 // that doesn't affect charCodeAt/charAt semantics, |index| is
2058 // preserved, |scratch| and |result| are clobbered.
2059 class StringCharCodeAtGenerator {
2061 StringCharCodeAtGenerator(Register object, Register index, Register result,
2062 Label* receiver_not_string, Label* index_not_number,
2063 Label* index_out_of_range,
2064 StringIndexFlags index_flags,
2065 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
2069 receiver_not_string_(receiver_not_string),
2070 index_not_number_(index_not_number),
2071 index_out_of_range_(index_out_of_range),
2072 index_flags_(index_flags),
2073 check_mode_(check_mode) {
2074 DCHECK(!result_.is(object_));
2075 DCHECK(!result_.is(index_));
2078 // Generates the fast case code. On the fallthrough path |result|
2079 // register contains the result.
2080 void GenerateFast(MacroAssembler* masm);
2082 // Generates the slow case code. Must not be naturally
2083 // reachable. Expected to be put after a ret instruction (e.g., in
2084 // deferred code). Always jumps back to the fast case.
2085 void GenerateSlow(MacroAssembler* masm, EmbedMode embed_mode,
2086 const RuntimeCallHelper& call_helper);
2088 // Skip handling slow case and directly jump to bailout.
2089 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2090 masm->bind(&index_not_smi_);
2091 masm->bind(&call_runtime_);
2100 Label* receiver_not_string_;
2101 Label* index_not_number_;
2102 Label* index_out_of_range_;
2104 StringIndexFlags index_flags_;
2105 ReceiverCheckMode check_mode_;
2107 Label call_runtime_;
2108 Label index_not_smi_;
2109 Label got_smi_index_;
2112 DISALLOW_COPY_AND_ASSIGN(StringCharCodeAtGenerator);
2116 // Generates code for creating a one-char string from a char code.
2117 class StringCharFromCodeGenerator {
2119 StringCharFromCodeGenerator(Register code,
2123 DCHECK(!code_.is(result_));
2126 // Generates the fast case code. On the fallthrough path |result|
2127 // register contains the result.
2128 void GenerateFast(MacroAssembler* masm);
2130 // Generates the slow case code. Must not be naturally
2131 // reachable. Expected to be put after a ret instruction (e.g., in
2132 // deferred code). Always jumps back to the fast case.
2133 void GenerateSlow(MacroAssembler* masm,
2134 const RuntimeCallHelper& call_helper);
2136 // Skip handling slow case and directly jump to bailout.
2137 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2138 masm->bind(&slow_case_);
2149 DISALLOW_COPY_AND_ASSIGN(StringCharFromCodeGenerator);
2153 // Generates code implementing String.prototype.charAt.
2155 // Only supports the case when the receiver is a string and the index
2156 // is a number (smi or heap number) that is a valid index into the
2157 // string. Additional index constraints are specified by the
2158 // flags. Otherwise, bails out to the provided labels.
2160 // Register usage: |object| may be changed to another string in a way
2161 // that doesn't affect charCodeAt/charAt semantics, |index| is
2162 // preserved, |scratch1|, |scratch2|, and |result| are clobbered.
2163 class StringCharAtGenerator {
2165 StringCharAtGenerator(Register object, Register index, Register scratch,
2166 Register result, Label* receiver_not_string,
2167 Label* index_not_number, Label* index_out_of_range,
2168 StringIndexFlags index_flags,
2169 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
2170 : char_code_at_generator_(object, index, scratch, receiver_not_string,
2171 index_not_number, index_out_of_range,
2172 index_flags, check_mode),
2173 char_from_code_generator_(scratch, result) {}
2175 // Generates the fast case code. On the fallthrough path |result|
2176 // register contains the result.
2177 void GenerateFast(MacroAssembler* masm) {
2178 char_code_at_generator_.GenerateFast(masm);
2179 char_from_code_generator_.GenerateFast(masm);
2182 // Generates the slow case code. Must not be naturally
2183 // reachable. Expected to be put after a ret instruction (e.g., in
2184 // deferred code). Always jumps back to the fast case.
2185 void GenerateSlow(MacroAssembler* masm, EmbedMode embed_mode,
2186 const RuntimeCallHelper& call_helper) {
2187 char_code_at_generator_.GenerateSlow(masm, embed_mode, call_helper);
2188 char_from_code_generator_.GenerateSlow(masm, call_helper);
2191 // Skip handling slow case and directly jump to bailout.
2192 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2193 char_code_at_generator_.SkipSlow(masm, bailout);
2194 char_from_code_generator_.SkipSlow(masm, bailout);
2198 StringCharCodeAtGenerator char_code_at_generator_;
2199 StringCharFromCodeGenerator char_from_code_generator_;
2201 DISALLOW_COPY_AND_ASSIGN(StringCharAtGenerator);
2205 class LoadDictionaryElementStub : public HydrogenCodeStub {
2207 explicit LoadDictionaryElementStub(Isolate* isolate, const LoadICState& state)
2208 : HydrogenCodeStub(isolate) {
2209 minor_key_ = state.GetExtraICState();
2212 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
2213 return LoadWithVectorDescriptor(isolate());
2216 LanguageMode language_mode() const {
2217 return LoadICState::GetLanguageMode(MinorKey());
2220 DEFINE_HYDROGEN_CODE_STUB(LoadDictionaryElement, HydrogenCodeStub);
2224 class KeyedLoadGenericStub : public HydrogenCodeStub {
2226 explicit KeyedLoadGenericStub(Isolate* isolate, const LoadICState& state)
2227 : HydrogenCodeStub(isolate) {
2228 minor_key_ = state.GetExtraICState();
2231 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2232 InlineCacheState GetICState() const override { return GENERIC; }
2234 LanguageMode language_mode() const {
2235 return LoadICState::GetLanguageMode(MinorKey());
2238 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
2240 DEFINE_HYDROGEN_CODE_STUB(KeyedLoadGeneric, HydrogenCodeStub);
2244 class LoadICTrampolineStub : public PlatformCodeStub {
2246 LoadICTrampolineStub(Isolate* isolate, const LoadICState& state)
2247 : PlatformCodeStub(isolate) {
2248 minor_key_ = state.GetExtraICState();
2251 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
2253 InlineCacheState GetICState() const final { return DEFAULT; }
2255 ExtraICState GetExtraICState() const final {
2256 return static_cast<ExtraICState>(minor_key_);
2260 LoadICState state() const {
2261 return LoadICState(static_cast<ExtraICState>(minor_key_));
2264 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
2265 DEFINE_PLATFORM_CODE_STUB(LoadICTrampoline, PlatformCodeStub);
2269 class KeyedLoadICTrampolineStub : public LoadICTrampolineStub {
2271 explicit KeyedLoadICTrampolineStub(Isolate* isolate, const LoadICState& state)
2272 : LoadICTrampolineStub(isolate, state) {}
2274 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2276 DEFINE_PLATFORM_CODE_STUB(KeyedLoadICTrampoline, LoadICTrampolineStub);
2280 class VectorStoreICTrampolineStub : public PlatformCodeStub {
2282 VectorStoreICTrampolineStub(Isolate* isolate, const StoreICState& state)
2283 : PlatformCodeStub(isolate) {
2284 minor_key_ = state.GetExtraICState();
2287 Code::Kind GetCodeKind() const override { return Code::STORE_IC; }
2289 InlineCacheState GetICState() const final { return DEFAULT; }
2291 ExtraICState GetExtraICState() const final {
2292 return static_cast<ExtraICState>(minor_key_);
2296 StoreICState state() const {
2297 return StoreICState(static_cast<ExtraICState>(minor_key_));
2301 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreICTrampoline);
2302 DEFINE_PLATFORM_CODE_STUB(VectorStoreICTrampoline, PlatformCodeStub);
2306 class VectorKeyedStoreICTrampolineStub : public VectorStoreICTrampolineStub {
2308 VectorKeyedStoreICTrampolineStub(Isolate* isolate, const StoreICState& state)
2309 : VectorStoreICTrampolineStub(isolate, state) {}
2311 Code::Kind GetCodeKind() const override { return Code::KEYED_STORE_IC; }
2313 DEFINE_PLATFORM_CODE_STUB(VectorKeyedStoreICTrampoline,
2314 VectorStoreICTrampolineStub);
2318 class CallICTrampolineStub : public PlatformCodeStub {
2320 CallICTrampolineStub(Isolate* isolate, const CallICState& state)
2321 : PlatformCodeStub(isolate) {
2322 minor_key_ = state.GetExtraICState();
2325 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
2327 InlineCacheState GetICState() const final { return DEFAULT; }
2329 ExtraICState GetExtraICState() const final {
2330 return static_cast<ExtraICState>(minor_key_);
2334 CallICState state() const {
2335 return CallICState(static_cast<ExtraICState>(minor_key_));
2338 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedback);
2339 DEFINE_PLATFORM_CODE_STUB(CallICTrampoline, PlatformCodeStub);
2343 class CallIC_ArrayTrampolineStub : public CallICTrampolineStub {
2345 CallIC_ArrayTrampolineStub(Isolate* isolate, const CallICState& state)
2346 : CallICTrampolineStub(isolate, state) {}
2349 DEFINE_PLATFORM_CODE_STUB(CallIC_ArrayTrampoline, CallICTrampolineStub);
2353 class LoadICStub : public PlatformCodeStub {
2355 explicit LoadICStub(Isolate* isolate, const LoadICState& state)
2356 : PlatformCodeStub(isolate) {
2357 minor_key_ = state.GetExtraICState();
2360 void GenerateForTrampoline(MacroAssembler* masm);
2362 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
2363 InlineCacheState GetICState() const final { return DEFAULT; }
2364 ExtraICState GetExtraICState() const final {
2365 return static_cast<ExtraICState>(minor_key_);
2368 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2369 DEFINE_PLATFORM_CODE_STUB(LoadIC, PlatformCodeStub);
2372 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2376 class KeyedLoadICStub : public PlatformCodeStub {
2378 explicit KeyedLoadICStub(Isolate* isolate, const LoadICState& state)
2379 : PlatformCodeStub(isolate) {
2380 minor_key_ = state.GetExtraICState();
2383 void GenerateForTrampoline(MacroAssembler* masm);
2385 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2386 InlineCacheState GetICState() const final { return DEFAULT; }
2387 ExtraICState GetExtraICState() const final {
2388 return static_cast<ExtraICState>(minor_key_);
2391 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2392 DEFINE_PLATFORM_CODE_STUB(KeyedLoadIC, PlatformCodeStub);
2395 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2399 class VectorStoreICStub : public PlatformCodeStub {
2401 VectorStoreICStub(Isolate* isolate, const StoreICState& state)
2402 : PlatformCodeStub(isolate) {
2403 minor_key_ = state.GetExtraICState();
2406 void GenerateForTrampoline(MacroAssembler* masm);
2408 Code::Kind GetCodeKind() const final { return Code::STORE_IC; }
2409 InlineCacheState GetICState() const final { return DEFAULT; }
2410 ExtraICState GetExtraICState() const final {
2411 return static_cast<ExtraICState>(minor_key_);
2414 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreIC);
2415 DEFINE_PLATFORM_CODE_STUB(VectorStoreIC, PlatformCodeStub);
2418 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2422 class VectorKeyedStoreICStub : public PlatformCodeStub {
2424 VectorKeyedStoreICStub(Isolate* isolate, const StoreICState& state)
2425 : PlatformCodeStub(isolate) {
2426 minor_key_ = state.GetExtraICState();
2429 void GenerateForTrampoline(MacroAssembler* masm);
2431 Code::Kind GetCodeKind() const final { return Code::KEYED_STORE_IC; }
2432 InlineCacheState GetICState() const final { return DEFAULT; }
2433 virtual ExtraICState GetExtraICState() const final {
2434 return static_cast<ExtraICState>(minor_key_);
2437 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreIC);
2438 DEFINE_PLATFORM_CODE_STUB(VectorKeyedStoreIC, PlatformCodeStub);
2441 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2445 class DoubleToIStub : public PlatformCodeStub {
2447 DoubleToIStub(Isolate* isolate, Register source, Register destination,
2448 int offset, bool is_truncating, bool skip_fastpath = false)
2449 : PlatformCodeStub(isolate) {
2450 minor_key_ = SourceRegisterBits::encode(source.code()) |
2451 DestinationRegisterBits::encode(destination.code()) |
2452 OffsetBits::encode(offset) |
2453 IsTruncatingBits::encode(is_truncating) |
2454 SkipFastPathBits::encode(skip_fastpath) |
2455 SSE3Bits::encode(CpuFeatures::IsSupported(SSE3) ? 1 : 0);
2458 bool SometimesSetsUpAFrame() override { return false; }
2461 Register source() const {
2462 return Register::from_code(SourceRegisterBits::decode(minor_key_));
2464 Register destination() const {
2465 return Register::from_code(DestinationRegisterBits::decode(minor_key_));
2467 bool is_truncating() const { return IsTruncatingBits::decode(minor_key_); }
2468 bool skip_fastpath() const { return SkipFastPathBits::decode(minor_key_); }
2469 int offset() const { return OffsetBits::decode(minor_key_); }
2471 static const int kBitsPerRegisterNumber = 6;
2472 STATIC_ASSERT((1L << kBitsPerRegisterNumber) >= Register::kNumRegisters);
2473 class SourceRegisterBits:
2474 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT
2475 class DestinationRegisterBits:
2476 public BitField<int, kBitsPerRegisterNumber,
2477 kBitsPerRegisterNumber> {}; // NOLINT
2478 class IsTruncatingBits:
2479 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT
2481 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT
2482 class SkipFastPathBits:
2483 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT
2485 public BitField<int, 2 * kBitsPerRegisterNumber + 5, 1> {}; // NOLINT
2487 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2488 DEFINE_PLATFORM_CODE_STUB(DoubleToI, PlatformCodeStub);
2492 class ScriptContextFieldStub : public HandlerStub {
2494 ScriptContextFieldStub(Isolate* isolate,
2495 const ScriptContextTable::LookupResult* lookup_result)
2496 : HandlerStub(isolate) {
2497 DCHECK(Accepted(lookup_result));
2498 set_sub_minor_key(ContextIndexBits::encode(lookup_result->context_index) |
2499 SlotIndexBits::encode(lookup_result->slot_index));
2502 int context_index() const {
2503 return ContextIndexBits::decode(sub_minor_key());
2506 int slot_index() const { return SlotIndexBits::decode(sub_minor_key()); }
2508 static bool Accepted(const ScriptContextTable::LookupResult* lookup_result) {
2509 return ContextIndexBits::is_valid(lookup_result->context_index) &&
2510 SlotIndexBits::is_valid(lookup_result->slot_index);
2514 static const int kContextIndexBits = 13;
2515 static const int kSlotIndexBits = 13;
2516 class ContextIndexBits : public BitField<int, 0, kContextIndexBits> {};
2518 : public BitField<int, kContextIndexBits, kSlotIndexBits> {};
2520 Code::StubType GetStubType() const override { return Code::FAST; }
2522 DEFINE_CODE_STUB_BASE(ScriptContextFieldStub, HandlerStub);
2526 class LoadScriptContextFieldStub : public ScriptContextFieldStub {
2528 LoadScriptContextFieldStub(
2529 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2530 : ScriptContextFieldStub(isolate, lookup_result) {}
2533 Code::Kind kind() const override { return Code::LOAD_IC; }
2535 DEFINE_HANDLER_CODE_STUB(LoadScriptContextField, ScriptContextFieldStub);
2539 class StoreScriptContextFieldStub : public ScriptContextFieldStub {
2541 StoreScriptContextFieldStub(
2542 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2543 : ScriptContextFieldStub(isolate, lookup_result) {}
2546 Code::Kind kind() const override { return Code::STORE_IC; }
2548 DEFINE_HANDLER_CODE_STUB(StoreScriptContextField, ScriptContextFieldStub);
2552 class LoadFastElementStub : public HandlerStub {
2554 LoadFastElementStub(Isolate* isolate, bool is_js_array,
2555 ElementsKind elements_kind,
2556 bool convert_hole_to_undefined = false)
2557 : HandlerStub(isolate) {
2559 ElementsKindBits::encode(elements_kind) |
2560 IsJSArrayBits::encode(is_js_array) |
2561 CanConvertHoleToUndefined::encode(convert_hole_to_undefined));
2564 Code::Kind kind() const override { return Code::KEYED_LOAD_IC; }
2566 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2567 bool convert_hole_to_undefined() const {
2568 return CanConvertHoleToUndefined::decode(sub_minor_key());
2571 ElementsKind elements_kind() const {
2572 return ElementsKindBits::decode(sub_minor_key());
2576 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2577 class IsJSArrayBits: public BitField<bool, 8, 1> {};
2578 class CanConvertHoleToUndefined : public BitField<bool, 9, 1> {};
2580 DEFINE_HANDLER_CODE_STUB(LoadFastElement, HandlerStub);
2584 class StoreFastElementStub : public HydrogenCodeStub {
2586 StoreFastElementStub(Isolate* isolate, bool is_js_array,
2587 ElementsKind elements_kind, KeyedAccessStoreMode mode)
2588 : HydrogenCodeStub(isolate) {
2589 set_sub_minor_key(ElementsKindBits::encode(elements_kind) |
2590 IsJSArrayBits::encode(is_js_array) |
2591 StoreModeBits::encode(mode));
2594 static void GenerateAheadOfTime(Isolate* isolate);
2596 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2598 ElementsKind elements_kind() const {
2599 return ElementsKindBits::decode(sub_minor_key());
2602 KeyedAccessStoreMode store_mode() const {
2603 return StoreModeBits::decode(sub_minor_key());
2607 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2608 class StoreModeBits: public BitField<KeyedAccessStoreMode, 8, 4> {};
2609 class IsJSArrayBits: public BitField<bool, 12, 1> {};
2611 DEFINE_CALL_INTERFACE_DESCRIPTOR(Store);
2612 DEFINE_HYDROGEN_CODE_STUB(StoreFastElement, HydrogenCodeStub);
2616 class TransitionElementsKindStub : public HydrogenCodeStub {
2618 TransitionElementsKindStub(Isolate* isolate,
2619 ElementsKind from_kind,
2620 ElementsKind to_kind,
2621 bool is_js_array) : HydrogenCodeStub(isolate) {
2622 set_sub_minor_key(FromKindBits::encode(from_kind) |
2623 ToKindBits::encode(to_kind) |
2624 IsJSArrayBits::encode(is_js_array));
2627 ElementsKind from_kind() const {
2628 return FromKindBits::decode(sub_minor_key());
2631 ElementsKind to_kind() const { return ToKindBits::decode(sub_minor_key()); }
2633 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2636 class FromKindBits: public BitField<ElementsKind, 8, 8> {};
2637 class ToKindBits: public BitField<ElementsKind, 0, 8> {};
2638 class IsJSArrayBits: public BitField<bool, 16, 1> {};
2640 DEFINE_CALL_INTERFACE_DESCRIPTOR(TransitionElementsKind);
2641 DEFINE_HYDROGEN_CODE_STUB(TransitionElementsKind, HydrogenCodeStub);
2645 class AllocateHeapNumberStub final : public HydrogenCodeStub {
2647 explicit AllocateHeapNumberStub(Isolate* isolate)
2648 : HydrogenCodeStub(isolate) {}
2651 DEFINE_CALL_INTERFACE_DESCRIPTOR(AllocateHeapNumber);
2652 DEFINE_HYDROGEN_CODE_STUB(AllocateHeapNumber, HydrogenCodeStub);
2656 class ArrayConstructorStubBase : public HydrogenCodeStub {
2658 ArrayConstructorStubBase(Isolate* isolate,
2660 AllocationSiteOverrideMode override_mode)
2661 : HydrogenCodeStub(isolate) {
2662 // It only makes sense to override local allocation site behavior
2663 // if there is a difference between the global allocation site policy
2664 // for an ElementsKind and the desired usage of the stub.
2665 DCHECK(override_mode != DISABLE_ALLOCATION_SITES ||
2666 AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE);
2667 set_sub_minor_key(ElementsKindBits::encode(kind) |
2668 AllocationSiteOverrideModeBits::encode(override_mode));
2671 ElementsKind elements_kind() const {
2672 return ElementsKindBits::decode(sub_minor_key());
2675 AllocationSiteOverrideMode override_mode() const {
2676 return AllocationSiteOverrideModeBits::decode(sub_minor_key());
2679 static void GenerateStubsAheadOfTime(Isolate* isolate);
2681 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2682 static const int kConstructor = 0;
2683 static const int kAllocationSite = 1;
2686 std::ostream& BasePrintName(std::ostream& os,
2687 const char* name) const; // NOLINT
2690 // Ensure data fits within available bits.
2691 STATIC_ASSERT(LAST_ALLOCATION_SITE_OVERRIDE_MODE == 1);
2693 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2694 class AllocationSiteOverrideModeBits: public
2695 BitField<AllocationSiteOverrideMode, 8, 1> {}; // NOLINT
2697 DEFINE_CODE_STUB_BASE(ArrayConstructorStubBase, HydrogenCodeStub);
2701 class ArrayNoArgumentConstructorStub : public ArrayConstructorStubBase {
2703 ArrayNoArgumentConstructorStub(
2706 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2707 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2711 void PrintName(std::ostream& os) const override { // NOLINT
2712 BasePrintName(os, "ArrayNoArgumentConstructorStub");
2715 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructorConstantArgCount);
2716 DEFINE_HYDROGEN_CODE_STUB(ArrayNoArgumentConstructor,
2717 ArrayConstructorStubBase);
2721 class ArraySingleArgumentConstructorStub : public ArrayConstructorStubBase {
2723 ArraySingleArgumentConstructorStub(
2726 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2727 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2731 void PrintName(std::ostream& os) const override { // NOLINT
2732 BasePrintName(os, "ArraySingleArgumentConstructorStub");
2735 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
2736 DEFINE_HYDROGEN_CODE_STUB(ArraySingleArgumentConstructor,
2737 ArrayConstructorStubBase);
2741 class ArrayNArgumentsConstructorStub : public ArrayConstructorStubBase {
2743 ArrayNArgumentsConstructorStub(
2746 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2747 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2751 void PrintName(std::ostream& os) const override { // NOLINT
2752 BasePrintName(os, "ArrayNArgumentsConstructorStub");
2755 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
2756 DEFINE_HYDROGEN_CODE_STUB(ArrayNArgumentsConstructor,
2757 ArrayConstructorStubBase);
2761 class InternalArrayConstructorStubBase : public HydrogenCodeStub {
2763 InternalArrayConstructorStubBase(Isolate* isolate, ElementsKind kind)
2764 : HydrogenCodeStub(isolate) {
2765 set_sub_minor_key(ElementsKindBits::encode(kind));
2768 static void GenerateStubsAheadOfTime(Isolate* isolate);
2770 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2771 static const int kConstructor = 0;
2773 ElementsKind elements_kind() const {
2774 return ElementsKindBits::decode(sub_minor_key());
2778 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
2780 DEFINE_CODE_STUB_BASE(InternalArrayConstructorStubBase, HydrogenCodeStub);
2784 class InternalArrayNoArgumentConstructorStub : public
2785 InternalArrayConstructorStubBase {
2787 InternalArrayNoArgumentConstructorStub(Isolate* isolate,
2789 : InternalArrayConstructorStubBase(isolate, kind) { }
2791 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructorConstantArgCount);
2792 DEFINE_HYDROGEN_CODE_STUB(InternalArrayNoArgumentConstructor,
2793 InternalArrayConstructorStubBase);
2797 class InternalArraySingleArgumentConstructorStub : public
2798 InternalArrayConstructorStubBase {
2800 InternalArraySingleArgumentConstructorStub(Isolate* isolate,
2802 : InternalArrayConstructorStubBase(isolate, kind) { }
2804 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
2805 DEFINE_HYDROGEN_CODE_STUB(InternalArraySingleArgumentConstructor,
2806 InternalArrayConstructorStubBase);
2810 class InternalArrayNArgumentsConstructorStub : public
2811 InternalArrayConstructorStubBase {
2813 InternalArrayNArgumentsConstructorStub(Isolate* isolate, ElementsKind kind)
2814 : InternalArrayConstructorStubBase(isolate, kind) { }
2816 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
2817 DEFINE_HYDROGEN_CODE_STUB(InternalArrayNArgumentsConstructor,
2818 InternalArrayConstructorStubBase);
2822 class StoreElementStub : public PlatformCodeStub {
2824 StoreElementStub(Isolate* isolate, ElementsKind elements_kind)
2825 : PlatformCodeStub(isolate) {
2826 minor_key_ = ElementsKindBits::encode(elements_kind);
2830 ElementsKind elements_kind() const {
2831 return ElementsKindBits::decode(minor_key_);
2834 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
2836 DEFINE_CALL_INTERFACE_DESCRIPTOR(Store);
2837 DEFINE_PLATFORM_CODE_STUB(StoreElement, PlatformCodeStub);
2841 class ToBooleanStub: public HydrogenCodeStub {
2856 RESULT_AS_SMI, // For Smi(1) on truthy value, Smi(0) otherwise.
2857 RESULT_AS_ODDBALL, // For {true} on truthy value, {false} otherwise.
2858 RESULT_AS_INVERSE_ODDBALL // For {false} on truthy value, {true} otherwise.
2861 // At most 16 different types can be distinguished, because the Code object
2862 // only has room for two bytes to hold a set of these types. :-P
2863 STATIC_ASSERT(NUMBER_OF_TYPES <= 16);
2865 class Types : public EnumSet<Type, uint16_t> {
2867 Types() : EnumSet<Type, uint16_t>(0) {}
2868 explicit Types(uint16_t bits) : EnumSet<Type, uint16_t>(bits) {}
2870 bool UpdateStatus(Handle<Object> object);
2871 bool NeedsMap() const;
2872 bool CanBeUndetectable() const;
2873 bool IsGeneric() const { return ToIntegral() == Generic().ToIntegral(); }
2875 static Types Generic() { return Types((1 << NUMBER_OF_TYPES) - 1); }
2878 ToBooleanStub(Isolate* isolate, ResultMode mode, Types types = Types())
2879 : HydrogenCodeStub(isolate) {
2880 set_sub_minor_key(TypesBits::encode(types.ToIntegral()) |
2881 ResultModeBits::encode(mode));
2884 ToBooleanStub(Isolate* isolate, ExtraICState state)
2885 : HydrogenCodeStub(isolate) {
2886 set_sub_minor_key(TypesBits::encode(static_cast<uint16_t>(state)) |
2887 ResultModeBits::encode(RESULT_AS_SMI));
2890 bool UpdateStatus(Handle<Object> object);
2891 Types types() const { return Types(TypesBits::decode(sub_minor_key())); }
2892 ResultMode mode() const { return ResultModeBits::decode(sub_minor_key()); }
2894 Code::Kind GetCodeKind() const override { return Code::TO_BOOLEAN_IC; }
2895 void PrintState(std::ostream& os) const override; // NOLINT
2897 bool SometimesSetsUpAFrame() override { return false; }
2899 static Handle<Code> GetUninitialized(Isolate* isolate) {
2900 return ToBooleanStub(isolate, UNINITIALIZED).GetCode();
2903 ExtraICState GetExtraICState() const override { return types().ToIntegral(); }
2905 InlineCacheState GetICState() const override {
2906 if (types().IsEmpty()) {
2907 return ::v8::internal::UNINITIALIZED;
2914 ToBooleanStub(Isolate* isolate, InitializationState init_state)
2915 : HydrogenCodeStub(isolate, init_state) {
2916 set_sub_minor_key(ResultModeBits::encode(RESULT_AS_SMI));
2919 class TypesBits : public BitField<uint16_t, 0, NUMBER_OF_TYPES> {};
2920 class ResultModeBits : public BitField<ResultMode, NUMBER_OF_TYPES, 2> {};
2922 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToBoolean);
2923 DEFINE_HYDROGEN_CODE_STUB(ToBoolean, HydrogenCodeStub);
2927 std::ostream& operator<<(std::ostream& os, const ToBooleanStub::Types& t);
2930 class ElementsTransitionAndStoreStub : public HydrogenCodeStub {
2932 ElementsTransitionAndStoreStub(Isolate* isolate, ElementsKind from_kind,
2933 ElementsKind to_kind, bool is_jsarray,
2934 KeyedAccessStoreMode store_mode)
2935 : HydrogenCodeStub(isolate) {
2936 set_sub_minor_key(FromBits::encode(from_kind) | ToBits::encode(to_kind) |
2937 IsJSArrayBits::encode(is_jsarray) |
2938 StoreModeBits::encode(store_mode));
2941 ElementsKind from_kind() const { return FromBits::decode(sub_minor_key()); }
2942 ElementsKind to_kind() const { return ToBits::decode(sub_minor_key()); }
2943 bool is_jsarray() const { return IsJSArrayBits::decode(sub_minor_key()); }
2944 KeyedAccessStoreMode store_mode() const {
2945 return StoreModeBits::decode(sub_minor_key());
2948 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2949 enum ParameterIndices {
2957 static const Register ValueRegister() {
2958 return ElementTransitionAndStoreDescriptor::ValueRegister();
2960 static const Register MapRegister() {
2961 return ElementTransitionAndStoreDescriptor::MapRegister();
2963 static const Register KeyRegister() {
2964 return ElementTransitionAndStoreDescriptor::NameRegister();
2966 static const Register ObjectRegister() {
2967 return ElementTransitionAndStoreDescriptor::ReceiverRegister();
2971 class FromBits : public BitField<ElementsKind, 0, 8> {};
2972 class ToBits : public BitField<ElementsKind, 8, 8> {};
2973 class IsJSArrayBits : public BitField<bool, 16, 1> {};
2974 class StoreModeBits : public BitField<KeyedAccessStoreMode, 17, 4> {};
2976 DEFINE_CALL_INTERFACE_DESCRIPTOR(ElementTransitionAndStore);
2977 DEFINE_HYDROGEN_CODE_STUB(ElementsTransitionAndStore, HydrogenCodeStub);
2981 class StoreArrayLiteralElementStub : public PlatformCodeStub {
2983 explicit StoreArrayLiteralElementStub(Isolate* isolate)
2984 : PlatformCodeStub(isolate) { }
2986 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreArrayLiteralElement);
2987 DEFINE_PLATFORM_CODE_STUB(StoreArrayLiteralElement, PlatformCodeStub);
2991 class StubFailureTrampolineStub : public PlatformCodeStub {
2993 StubFailureTrampolineStub(Isolate* isolate, StubFunctionMode function_mode)
2994 : PlatformCodeStub(isolate) {
2995 minor_key_ = FunctionModeField::encode(function_mode);
2998 static void GenerateAheadOfTime(Isolate* isolate);
3001 StubFunctionMode function_mode() const {
3002 return FunctionModeField::decode(minor_key_);
3005 class FunctionModeField : public BitField<StubFunctionMode, 0, 1> {};
3007 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
3008 DEFINE_PLATFORM_CODE_STUB(StubFailureTrampoline, PlatformCodeStub);
3012 class ProfileEntryHookStub : public PlatformCodeStub {
3014 explicit ProfileEntryHookStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3016 // The profile entry hook function is not allowed to cause a GC.
3017 bool SometimesSetsUpAFrame() override { return false; }
3019 // Generates a call to the entry hook if it's enabled.
3020 static void MaybeCallEntryHook(MacroAssembler* masm);
3023 static void EntryHookTrampoline(intptr_t function,
3024 intptr_t stack_pointer,
3027 // ProfileEntryHookStub is called at the start of a function, so it has the
3028 // same register set.
3029 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction)
3030 DEFINE_PLATFORM_CODE_STUB(ProfileEntryHook, PlatformCodeStub);
3034 class StoreBufferOverflowStub : public PlatformCodeStub {
3036 StoreBufferOverflowStub(Isolate* isolate, SaveFPRegsMode save_fp)
3037 : PlatformCodeStub(isolate) {
3038 minor_key_ = SaveDoublesBits::encode(save_fp == kSaveFPRegs);
3041 static void GenerateFixedRegStubsAheadOfTime(Isolate* isolate);
3042 bool SometimesSetsUpAFrame() override { return false; }
3045 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
3047 class SaveDoublesBits : public BitField<bool, 0, 1> {};
3049 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
3050 DEFINE_PLATFORM_CODE_STUB(StoreBufferOverflow, PlatformCodeStub);
3054 class SubStringStub : public PlatformCodeStub {
3056 explicit SubStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3058 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
3059 DEFINE_PLATFORM_CODE_STUB(SubString, PlatformCodeStub);
3063 class ToNumberStub final : public PlatformCodeStub {
3065 explicit ToNumberStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3067 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToNumber);
3068 DEFINE_PLATFORM_CODE_STUB(ToNumber, PlatformCodeStub);
3072 class StringCompareStub : public PlatformCodeStub {
3074 explicit StringCompareStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3076 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
3077 DEFINE_PLATFORM_CODE_STUB(StringCompare, PlatformCodeStub);
3081 #undef DEFINE_CALL_INTERFACE_DESCRIPTOR
3082 #undef DEFINE_PLATFORM_CODE_STUB
3083 #undef DEFINE_HANDLER_CODE_STUB
3084 #undef DEFINE_HYDROGEN_CODE_STUB
3085 #undef DEFINE_CODE_STUB
3086 #undef DEFINE_CODE_STUB_BASE
3088 extern Representation RepresentationFromType(Type* type);
3089 } } // namespace v8::internal
3091 #endif // V8_CODE_STUBS_H_