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 final : public PlatformCodeStub {
1401 static const int kMaximumDepth = 15;
1403 LoadGlobalViaContextStub(Isolate* isolate, int depth)
1404 : PlatformCodeStub(isolate) {
1405 minor_key_ = DepthBits::encode(depth);
1408 int depth() const { return DepthBits::decode(minor_key_); }
1411 class DepthBits : public BitField<int, 0, 4> {};
1412 STATIC_ASSERT(DepthBits::kMax == kMaximumDepth);
1414 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadGlobalViaContext);
1415 DEFINE_PLATFORM_CODE_STUB(LoadGlobalViaContext, PlatformCodeStub);
1419 class StoreGlobalViaContextStub final : public PlatformCodeStub {
1421 static const int kMaximumDepth = 15;
1423 StoreGlobalViaContextStub(Isolate* isolate, int depth,
1424 LanguageMode language_mode)
1425 : PlatformCodeStub(isolate) {
1427 DepthBits::encode(depth) | LanguageModeBits::encode(language_mode);
1430 int depth() const { return DepthBits::decode(minor_key_); }
1431 LanguageMode language_mode() const {
1432 return LanguageModeBits::decode(minor_key_);
1436 class DepthBits : public BitField<int, 0, 4> {};
1437 STATIC_ASSERT(DepthBits::kMax == kMaximumDepth);
1438 class LanguageModeBits : public BitField<LanguageMode, 4, 2> {};
1439 STATIC_ASSERT(LANGUAGE_END == 3);
1441 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreGlobalViaContext);
1442 DEFINE_PLATFORM_CODE_STUB(StoreGlobalViaContext, PlatformCodeStub);
1446 class CallApiFunctionStub : public PlatformCodeStub {
1448 explicit CallApiFunctionStub(Isolate* isolate, bool call_data_undefined)
1449 : PlatformCodeStub(isolate) {
1450 minor_key_ = CallDataUndefinedBits::encode(call_data_undefined);
1454 bool call_data_undefined() const {
1455 return CallDataUndefinedBits::decode(minor_key_);
1458 class CallDataUndefinedBits : public BitField<bool, 0, 1> {};
1460 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiFunction);
1461 DEFINE_PLATFORM_CODE_STUB(CallApiFunction, PlatformCodeStub);
1465 class CallApiAccessorStub : public PlatformCodeStub {
1467 CallApiAccessorStub(Isolate* isolate, bool is_store, bool call_data_undefined)
1468 : PlatformCodeStub(isolate) {
1469 minor_key_ = IsStoreBits::encode(is_store) |
1470 CallDataUndefinedBits::encode(call_data_undefined) |
1471 ArgumentBits::encode(is_store ? 1 : 0);
1475 // For CallApiFunctionWithFixedArgsStub, see below.
1476 static const int kArgBits = 3;
1477 CallApiAccessorStub(Isolate* isolate, int argc, bool call_data_undefined)
1478 : PlatformCodeStub(isolate) {
1479 minor_key_ = IsStoreBits::encode(false) |
1480 CallDataUndefinedBits::encode(call_data_undefined) |
1481 ArgumentBits::encode(argc);
1485 bool is_store() const { return IsStoreBits::decode(minor_key_); }
1486 bool call_data_undefined() const {
1487 return CallDataUndefinedBits::decode(minor_key_);
1489 int argc() const { return ArgumentBits::decode(minor_key_); }
1491 class IsStoreBits: public BitField<bool, 0, 1> {};
1492 class CallDataUndefinedBits: public BitField<bool, 1, 1> {};
1493 class ArgumentBits : public BitField<int, 2, kArgBits> {};
1495 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiAccessor);
1496 DEFINE_PLATFORM_CODE_STUB(CallApiAccessor, PlatformCodeStub);
1500 // TODO(dcarney): see if it's possible to remove this later without performance
1502 // This is not a real stub, but a way of generating the CallApiAccessorStub
1503 // (which has the same abi) which makes it clear that it is not an accessor.
1504 class CallApiFunctionWithFixedArgsStub : public CallApiAccessorStub {
1506 static const int kMaxFixedArgs = (1 << kArgBits) - 1;
1507 CallApiFunctionWithFixedArgsStub(Isolate* isolate, int argc,
1508 bool call_data_undefined)
1509 : CallApiAccessorStub(isolate, argc, call_data_undefined) {
1510 DCHECK(0 <= argc && argc <= kMaxFixedArgs);
1515 typedef ApiAccessorDescriptor ApiFunctionWithFixedArgsDescriptor;
1518 class CallApiGetterStub : public PlatformCodeStub {
1520 explicit CallApiGetterStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
1522 DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiGetter);
1523 DEFINE_PLATFORM_CODE_STUB(CallApiGetter, PlatformCodeStub);
1527 class BinaryOpICStub : public HydrogenCodeStub {
1529 BinaryOpICStub(Isolate* isolate, Token::Value op, Strength strength)
1530 : HydrogenCodeStub(isolate, UNINITIALIZED) {
1531 BinaryOpICState state(isolate, op, strength);
1532 set_sub_minor_key(state.GetExtraICState());
1535 BinaryOpICStub(Isolate* isolate, const BinaryOpICState& state)
1536 : HydrogenCodeStub(isolate) {
1537 set_sub_minor_key(state.GetExtraICState());
1540 static void GenerateAheadOfTime(Isolate* isolate);
1542 Code::Kind GetCodeKind() const override { return Code::BINARY_OP_IC; }
1544 InlineCacheState GetICState() const final { return state().GetICState(); }
1546 ExtraICState GetExtraICState() const final {
1547 return static_cast<ExtraICState>(sub_minor_key());
1550 BinaryOpICState state() const {
1551 return BinaryOpICState(isolate(), GetExtraICState());
1554 void PrintState(std::ostream& os) const final; // NOLINT
1556 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1557 static const int kLeft = 0;
1558 static const int kRight = 1;
1561 static void GenerateAheadOfTime(Isolate* isolate,
1562 const BinaryOpICState& state);
1564 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
1565 DEFINE_HYDROGEN_CODE_STUB(BinaryOpIC, HydrogenCodeStub);
1569 // TODO(bmeurer): Merge this into the BinaryOpICStub once we have proper tail
1570 // call support for stubs in Hydrogen.
1571 class BinaryOpICWithAllocationSiteStub final : public PlatformCodeStub {
1573 BinaryOpICWithAllocationSiteStub(Isolate* isolate,
1574 const BinaryOpICState& state)
1575 : PlatformCodeStub(isolate) {
1576 minor_key_ = state.GetExtraICState();
1579 static void GenerateAheadOfTime(Isolate* isolate);
1581 Handle<Code> GetCodeCopyFromTemplate(Handle<AllocationSite> allocation_site) {
1582 Code::FindAndReplacePattern pattern;
1583 pattern.Add(isolate()->factory()->undefined_map(), allocation_site);
1584 return CodeStub::GetCodeCopy(pattern);
1587 Code::Kind GetCodeKind() const override { return Code::BINARY_OP_IC; }
1589 InlineCacheState GetICState() const override { return state().GetICState(); }
1591 ExtraICState GetExtraICState() const override {
1592 return static_cast<ExtraICState>(minor_key_);
1595 void PrintState(std::ostream& os) const override; // NOLINT
1598 BinaryOpICState state() const {
1599 return BinaryOpICState(isolate(), static_cast<ExtraICState>(minor_key_));
1602 static void GenerateAheadOfTime(Isolate* isolate,
1603 const BinaryOpICState& state);
1605 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithAllocationSite);
1606 DEFINE_PLATFORM_CODE_STUB(BinaryOpICWithAllocationSite, PlatformCodeStub);
1610 class BinaryOpWithAllocationSiteStub final : public BinaryOpICStub {
1612 BinaryOpWithAllocationSiteStub(Isolate* isolate, Token::Value op,
1614 : BinaryOpICStub(isolate, op, strength) {}
1616 BinaryOpWithAllocationSiteStub(Isolate* isolate, const BinaryOpICState& state)
1617 : BinaryOpICStub(isolate, state) {}
1619 Code::Kind GetCodeKind() const final { return Code::STUB; }
1621 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1622 static const int kAllocationSite = 0;
1623 static const int kLeft = 1;
1624 static const int kRight = 2;
1626 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOpWithAllocationSite);
1627 DEFINE_HYDROGEN_CODE_STUB(BinaryOpWithAllocationSite, BinaryOpICStub);
1631 class StringAddStub final : public HydrogenCodeStub {
1633 StringAddStub(Isolate* isolate, StringAddFlags flags,
1634 PretenureFlag pretenure_flag)
1635 : HydrogenCodeStub(isolate) {
1636 set_sub_minor_key(StringAddFlagsBits::encode(flags) |
1637 PretenureFlagBits::encode(pretenure_flag));
1640 StringAddFlags flags() const {
1641 return StringAddFlagsBits::decode(sub_minor_key());
1644 PretenureFlag pretenure_flag() const {
1645 return PretenureFlagBits::decode(sub_minor_key());
1648 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1649 static const int kLeft = 0;
1650 static const int kRight = 1;
1653 class StringAddFlagsBits: public BitField<StringAddFlags, 0, 2> {};
1654 class PretenureFlagBits: public BitField<PretenureFlag, 2, 1> {};
1656 void PrintBaseName(std::ostream& os) const override; // NOLINT
1658 DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
1659 DEFINE_HYDROGEN_CODE_STUB(StringAdd, HydrogenCodeStub);
1663 class CompareICStub : public PlatformCodeStub {
1665 CompareICStub(Isolate* isolate, Token::Value op, Strength strength,
1666 CompareICState::State left, CompareICState::State right,
1667 CompareICState::State state)
1668 : PlatformCodeStub(isolate) {
1669 DCHECK(Token::IsCompareOp(op));
1670 minor_key_ = OpBits::encode(op - Token::EQ) |
1671 StrengthBits::encode(is_strong(strength)) |
1672 LeftStateBits::encode(left) | RightStateBits::encode(right) |
1673 StateBits::encode(state);
1676 void set_known_map(Handle<Map> map) { known_map_ = map; }
1678 InlineCacheState GetICState() const override;
1680 Token::Value op() const {
1681 return static_cast<Token::Value>(Token::EQ + OpBits::decode(minor_key_));
1684 Strength strength() const {
1685 return StrengthBits::decode(minor_key_) ? Strength::STRONG : Strength::WEAK;
1688 CompareICState::State left() const {
1689 return LeftStateBits::decode(minor_key_);
1691 CompareICState::State right() const {
1692 return RightStateBits::decode(minor_key_);
1694 CompareICState::State state() const { return StateBits::decode(minor_key_); }
1697 Code::Kind GetCodeKind() const override { return Code::COMPARE_IC; }
1699 void GenerateSmis(MacroAssembler* masm);
1700 void GenerateNumbers(MacroAssembler* masm);
1701 void GenerateInternalizedStrings(MacroAssembler* masm);
1702 void GenerateStrings(MacroAssembler* masm);
1703 void GenerateUniqueNames(MacroAssembler* masm);
1704 void GenerateObjects(MacroAssembler* masm);
1705 void GenerateMiss(MacroAssembler* masm);
1706 void GenerateKnownObjects(MacroAssembler* masm);
1707 void GenerateGeneric(MacroAssembler* masm);
1709 bool strict() const { return op() == Token::EQ_STRICT; }
1710 Condition GetCondition() const;
1712 void AddToSpecialCache(Handle<Code> new_object) override;
1713 bool FindCodeInSpecialCache(Code** code_out) override;
1714 bool UseSpecialCache() override {
1715 return state() == CompareICState::KNOWN_OBJECT;
1718 class OpBits : public BitField<int, 0, 3> {};
1719 class StrengthBits : public BitField<bool, 3, 1> {};
1720 class LeftStateBits : public BitField<CompareICState::State, 4, 4> {};
1721 class RightStateBits : public BitField<CompareICState::State, 8, 4> {};
1722 class StateBits : public BitField<CompareICState::State, 12, 4> {};
1724 Handle<Map> known_map_;
1726 DEFINE_CALL_INTERFACE_DESCRIPTOR(BinaryOp);
1727 DEFINE_PLATFORM_CODE_STUB(CompareIC, PlatformCodeStub);
1731 class CompareNilICStub : public HydrogenCodeStub {
1733 Type* GetType(Zone* zone, Handle<Map> map = Handle<Map>());
1734 Type* GetInputType(Zone* zone, Handle<Map> map);
1736 CompareNilICStub(Isolate* isolate, NilValue nil) : HydrogenCodeStub(isolate) {
1737 set_sub_minor_key(NilValueBits::encode(nil));
1740 CompareNilICStub(Isolate* isolate, ExtraICState ic_state,
1741 InitializationState init_state = INITIALIZED)
1742 : HydrogenCodeStub(isolate, init_state) {
1743 set_sub_minor_key(ic_state);
1746 static Handle<Code> GetUninitialized(Isolate* isolate,
1748 return CompareNilICStub(isolate, nil, UNINITIALIZED).GetCode();
1751 InlineCacheState GetICState() const override {
1752 State state = this->state();
1753 if (state.Contains(GENERIC)) {
1755 } else if (state.Contains(MONOMORPHIC_MAP)) {
1758 return PREMONOMORPHIC;
1762 Code::Kind GetCodeKind() const override { return Code::COMPARE_NIL_IC; }
1764 ExtraICState GetExtraICState() const override { return sub_minor_key(); }
1766 void UpdateStatus(Handle<Object> object);
1768 bool IsMonomorphic() const { return state().Contains(MONOMORPHIC_MAP); }
1770 NilValue nil_value() const { return NilValueBits::decode(sub_minor_key()); }
1773 set_sub_minor_key(TypesBits::update(sub_minor_key(), 0));
1776 void PrintState(std::ostream& os) const override; // NOLINT
1777 void PrintBaseName(std::ostream& os) const override; // NOLINT
1780 CompareNilICStub(Isolate* isolate, NilValue nil,
1781 InitializationState init_state)
1782 : HydrogenCodeStub(isolate, init_state) {
1783 set_sub_minor_key(NilValueBits::encode(nil));
1786 enum CompareNilType {
1794 // At most 6 different types can be distinguished, because the Code object
1795 // only has room for a single byte to hold a set and there are two more
1796 // boolean flags we need to store. :-P
1797 STATIC_ASSERT(NUMBER_OF_TYPES <= 6);
1799 class State : public EnumSet<CompareNilType, byte> {
1801 State() : EnumSet<CompareNilType, byte>(0) { }
1802 explicit State(byte bits) : EnumSet<CompareNilType, byte>(bits) { }
1804 friend std::ostream& operator<<(std::ostream& os, const State& s);
1806 State state() const { return State(TypesBits::decode(sub_minor_key())); }
1808 class NilValueBits : public BitField<NilValue, 0, 1> {};
1809 class TypesBits : public BitField<byte, 1, NUMBER_OF_TYPES> {};
1811 friend class CompareNilIC;
1813 DEFINE_CALL_INTERFACE_DESCRIPTOR(CompareNil);
1814 DEFINE_HYDROGEN_CODE_STUB(CompareNilIC, HydrogenCodeStub);
1818 std::ostream& operator<<(std::ostream& os, const CompareNilICStub::State& s);
1821 class CEntryStub : public PlatformCodeStub {
1823 CEntryStub(Isolate* isolate, int result_size,
1824 SaveFPRegsMode save_doubles = kDontSaveFPRegs)
1825 : PlatformCodeStub(isolate) {
1826 minor_key_ = SaveDoublesBits::encode(save_doubles == kSaveFPRegs);
1827 DCHECK(result_size == 1 || result_size == 2);
1828 #if _WIN64 || V8_TARGET_ARCH_PPC
1829 minor_key_ = ResultSizeBits::update(minor_key_, result_size);
1833 // The version of this stub that doesn't save doubles is generated ahead of
1834 // time, so it's OK to call it from other stubs that can't cope with GC during
1835 // their code generation. On machines that always have gp registers (x64) we
1836 // can generate both variants ahead of time.
1837 static void GenerateAheadOfTime(Isolate* isolate);
1840 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
1841 #if _WIN64 || V8_TARGET_ARCH_PPC
1842 int result_size() const { return ResultSizeBits::decode(minor_key_); }
1845 bool NeedsImmovableCode() override;
1847 class SaveDoublesBits : public BitField<bool, 0, 1> {};
1848 class ResultSizeBits : public BitField<int, 1, 3> {};
1850 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
1851 DEFINE_PLATFORM_CODE_STUB(CEntry, PlatformCodeStub);
1855 class JSEntryStub : public PlatformCodeStub {
1857 JSEntryStub(Isolate* isolate, StackFrame::Type type)
1858 : PlatformCodeStub(isolate) {
1859 DCHECK(type == StackFrame::ENTRY || type == StackFrame::ENTRY_CONSTRUCT);
1860 minor_key_ = StackFrameTypeBits::encode(type);
1864 void FinishCode(Handle<Code> code) override;
1866 void PrintName(std::ostream& os) const override { // NOLINT
1867 os << (type() == StackFrame::ENTRY ? "JSEntryStub"
1868 : "JSConstructEntryStub");
1871 StackFrame::Type type() const {
1872 return StackFrameTypeBits::decode(minor_key_);
1875 class StackFrameTypeBits : public BitField<StackFrame::Type, 0, 5> {};
1877 int handler_offset_;
1879 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
1880 DEFINE_PLATFORM_CODE_STUB(JSEntry, PlatformCodeStub);
1884 class ArgumentsAccessStub: public PlatformCodeStub {
1893 ArgumentsAccessStub(Isolate* isolate, Type type) : PlatformCodeStub(isolate) {
1894 minor_key_ = TypeBits::encode(type);
1897 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1898 if (type() == READ_ELEMENT) {
1899 return ArgumentsAccessReadDescriptor(isolate());
1901 return ContextOnlyDescriptor(isolate());
1905 Type type() const { return TypeBits::decode(minor_key_); }
1907 void GenerateReadElement(MacroAssembler* masm);
1908 void GenerateNewStrict(MacroAssembler* masm);
1909 void GenerateNewSloppyFast(MacroAssembler* masm);
1910 void GenerateNewSloppySlow(MacroAssembler* masm);
1912 void PrintName(std::ostream& os) const override; // NOLINT
1914 class TypeBits : public BitField<Type, 0, 2> {};
1916 DEFINE_PLATFORM_CODE_STUB(ArgumentsAccess, PlatformCodeStub);
1920 class RestParamAccessStub: public PlatformCodeStub {
1922 explicit RestParamAccessStub(Isolate* isolate) : PlatformCodeStub(isolate) { }
1924 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
1925 return ContextOnlyDescriptor(isolate());
1929 void GenerateNew(MacroAssembler* masm);
1931 void PrintName(std::ostream& os) const override; // NOLINT
1933 DEFINE_PLATFORM_CODE_STUB(RestParamAccess, PlatformCodeStub);
1937 class RegExpExecStub: public PlatformCodeStub {
1939 explicit RegExpExecStub(Isolate* isolate) : PlatformCodeStub(isolate) { }
1941 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
1942 DEFINE_PLATFORM_CODE_STUB(RegExpExec, PlatformCodeStub);
1946 class RegExpConstructResultStub final : public HydrogenCodeStub {
1948 explicit RegExpConstructResultStub(Isolate* isolate)
1949 : HydrogenCodeStub(isolate) { }
1951 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
1952 static const int kLength = 0;
1953 static const int kIndex = 1;
1954 static const int kInput = 2;
1956 DEFINE_CALL_INTERFACE_DESCRIPTOR(RegExpConstructResult);
1957 DEFINE_HYDROGEN_CODE_STUB(RegExpConstructResult, HydrogenCodeStub);
1961 class CallFunctionStub: public PlatformCodeStub {
1963 CallFunctionStub(Isolate* isolate, int argc, CallFunctionFlags flags)
1964 : PlatformCodeStub(isolate) {
1965 DCHECK(argc >= 0 && argc <= Code::kMaxArguments);
1966 minor_key_ = ArgcBits::encode(argc) | FlagBits::encode(flags);
1970 int argc() const { return ArgcBits::decode(minor_key_); }
1971 int flags() const { return FlagBits::decode(minor_key_); }
1973 bool CallAsMethod() const {
1974 return flags() == CALL_AS_METHOD || flags() == WRAP_AND_CALL;
1977 bool NeedsChecks() const { return flags() != WRAP_AND_CALL; }
1979 void PrintName(std::ostream& os) const override; // NOLINT
1981 // Minor key encoding in 32 bits with Bitfield <Type, shift, size>.
1982 class FlagBits : public BitField<CallFunctionFlags, 0, 2> {};
1983 class ArgcBits : public BitField<unsigned, 2, Code::kArgumentsBits> {};
1984 STATIC_ASSERT(Code::kArgumentsBits + 2 <= kStubMinorKeyBits);
1986 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction);
1987 DEFINE_PLATFORM_CODE_STUB(CallFunction, PlatformCodeStub);
1991 class CallConstructStub: public PlatformCodeStub {
1993 CallConstructStub(Isolate* isolate, CallConstructorFlags flags)
1994 : PlatformCodeStub(isolate) {
1995 minor_key_ = FlagBits::encode(flags);
1998 void FinishCode(Handle<Code> code) override {
1999 code->set_has_function_cache(RecordCallTarget());
2003 CallConstructorFlags flags() const { return FlagBits::decode(minor_key_); }
2005 bool RecordCallTarget() const {
2006 return (flags() & RECORD_CONSTRUCTOR_TARGET) != 0;
2009 bool IsSuperConstructorCall() const {
2010 return (flags() & SUPER_CONSTRUCTOR_CALL) != 0;
2013 void PrintName(std::ostream& os) const override; // NOLINT
2015 class FlagBits : public BitField<CallConstructorFlags, 0, 2> {};
2017 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallConstruct);
2018 DEFINE_PLATFORM_CODE_STUB(CallConstruct, PlatformCodeStub);
2022 enum StringIndexFlags {
2023 // Accepts smis or heap numbers.
2024 STRING_INDEX_IS_NUMBER,
2026 // Accepts smis or heap numbers that are valid array indices
2027 // (ECMA-262 15.4). Invalid indices are reported as being out of
2029 STRING_INDEX_IS_ARRAY_INDEX
2033 enum ReceiverCheckMode {
2034 // We don't know anything about the receiver.
2035 RECEIVER_IS_UNKNOWN,
2037 // We know the receiver is a string.
2043 // The code being generated is part of an IC handler, which may MISS
2044 // to an IC in failure cases.
2047 NOT_PART_OF_IC_HANDLER
2051 // Generates code implementing String.prototype.charCodeAt.
2053 // Only supports the case when the receiver is a string and the index
2054 // is a number (smi or heap number) that is a valid index into the
2055 // string. Additional index constraints are specified by the
2056 // flags. Otherwise, bails out to the provided labels.
2058 // Register usage: |object| may be changed to another string in a way
2059 // that doesn't affect charCodeAt/charAt semantics, |index| is
2060 // preserved, |scratch| and |result| are clobbered.
2061 class StringCharCodeAtGenerator {
2063 StringCharCodeAtGenerator(Register object, Register index, Register result,
2064 Label* receiver_not_string, Label* index_not_number,
2065 Label* index_out_of_range,
2066 StringIndexFlags index_flags,
2067 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
2071 receiver_not_string_(receiver_not_string),
2072 index_not_number_(index_not_number),
2073 index_out_of_range_(index_out_of_range),
2074 index_flags_(index_flags),
2075 check_mode_(check_mode) {
2076 DCHECK(!result_.is(object_));
2077 DCHECK(!result_.is(index_));
2080 // Generates the fast case code. On the fallthrough path |result|
2081 // register contains the result.
2082 void GenerateFast(MacroAssembler* masm);
2084 // Generates the slow case code. Must not be naturally
2085 // reachable. Expected to be put after a ret instruction (e.g., in
2086 // deferred code). Always jumps back to the fast case.
2087 void GenerateSlow(MacroAssembler* masm, EmbedMode embed_mode,
2088 const RuntimeCallHelper& call_helper);
2090 // Skip handling slow case and directly jump to bailout.
2091 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2092 masm->bind(&index_not_smi_);
2093 masm->bind(&call_runtime_);
2102 Label* receiver_not_string_;
2103 Label* index_not_number_;
2104 Label* index_out_of_range_;
2106 StringIndexFlags index_flags_;
2107 ReceiverCheckMode check_mode_;
2109 Label call_runtime_;
2110 Label index_not_smi_;
2111 Label got_smi_index_;
2114 DISALLOW_COPY_AND_ASSIGN(StringCharCodeAtGenerator);
2118 // Generates code for creating a one-char string from a char code.
2119 class StringCharFromCodeGenerator {
2121 StringCharFromCodeGenerator(Register code,
2125 DCHECK(!code_.is(result_));
2128 // Generates the fast case code. On the fallthrough path |result|
2129 // register contains the result.
2130 void GenerateFast(MacroAssembler* masm);
2132 // Generates the slow case code. Must not be naturally
2133 // reachable. Expected to be put after a ret instruction (e.g., in
2134 // deferred code). Always jumps back to the fast case.
2135 void GenerateSlow(MacroAssembler* masm,
2136 const RuntimeCallHelper& call_helper);
2138 // Skip handling slow case and directly jump to bailout.
2139 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2140 masm->bind(&slow_case_);
2151 DISALLOW_COPY_AND_ASSIGN(StringCharFromCodeGenerator);
2155 // Generates code implementing String.prototype.charAt.
2157 // Only supports the case when the receiver is a string and the index
2158 // is a number (smi or heap number) that is a valid index into the
2159 // string. Additional index constraints are specified by the
2160 // flags. Otherwise, bails out to the provided labels.
2162 // Register usage: |object| may be changed to another string in a way
2163 // that doesn't affect charCodeAt/charAt semantics, |index| is
2164 // preserved, |scratch1|, |scratch2|, and |result| are clobbered.
2165 class StringCharAtGenerator {
2167 StringCharAtGenerator(Register object, Register index, Register scratch,
2168 Register result, Label* receiver_not_string,
2169 Label* index_not_number, Label* index_out_of_range,
2170 StringIndexFlags index_flags,
2171 ReceiverCheckMode check_mode = RECEIVER_IS_UNKNOWN)
2172 : char_code_at_generator_(object, index, scratch, receiver_not_string,
2173 index_not_number, index_out_of_range,
2174 index_flags, check_mode),
2175 char_from_code_generator_(scratch, result) {}
2177 // Generates the fast case code. On the fallthrough path |result|
2178 // register contains the result.
2179 void GenerateFast(MacroAssembler* masm) {
2180 char_code_at_generator_.GenerateFast(masm);
2181 char_from_code_generator_.GenerateFast(masm);
2184 // Generates the slow case code. Must not be naturally
2185 // reachable. Expected to be put after a ret instruction (e.g., in
2186 // deferred code). Always jumps back to the fast case.
2187 void GenerateSlow(MacroAssembler* masm, EmbedMode embed_mode,
2188 const RuntimeCallHelper& call_helper) {
2189 char_code_at_generator_.GenerateSlow(masm, embed_mode, call_helper);
2190 char_from_code_generator_.GenerateSlow(masm, call_helper);
2193 // Skip handling slow case and directly jump to bailout.
2194 void SkipSlow(MacroAssembler* masm, Label* bailout) {
2195 char_code_at_generator_.SkipSlow(masm, bailout);
2196 char_from_code_generator_.SkipSlow(masm, bailout);
2200 StringCharCodeAtGenerator char_code_at_generator_;
2201 StringCharFromCodeGenerator char_from_code_generator_;
2203 DISALLOW_COPY_AND_ASSIGN(StringCharAtGenerator);
2207 class LoadDictionaryElementStub : public HydrogenCodeStub {
2209 explicit LoadDictionaryElementStub(Isolate* isolate, const LoadICState& state)
2210 : HydrogenCodeStub(isolate) {
2211 minor_key_ = state.GetExtraICState();
2214 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override {
2215 return LoadWithVectorDescriptor(isolate());
2218 LanguageMode language_mode() const {
2219 return LoadICState::GetLanguageMode(MinorKey());
2222 DEFINE_HYDROGEN_CODE_STUB(LoadDictionaryElement, HydrogenCodeStub);
2226 class KeyedLoadGenericStub : public HydrogenCodeStub {
2228 explicit KeyedLoadGenericStub(Isolate* isolate, const LoadICState& state)
2229 : HydrogenCodeStub(isolate) {
2230 minor_key_ = state.GetExtraICState();
2233 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2234 InlineCacheState GetICState() const override { return GENERIC; }
2236 LanguageMode language_mode() const {
2237 return LoadICState::GetLanguageMode(MinorKey());
2240 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
2242 DEFINE_HYDROGEN_CODE_STUB(KeyedLoadGeneric, HydrogenCodeStub);
2246 class LoadICTrampolineStub : public PlatformCodeStub {
2248 LoadICTrampolineStub(Isolate* isolate, const LoadICState& state)
2249 : PlatformCodeStub(isolate) {
2250 minor_key_ = state.GetExtraICState();
2253 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
2255 InlineCacheState GetICState() const final { return DEFAULT; }
2257 ExtraICState GetExtraICState() const final {
2258 return static_cast<ExtraICState>(minor_key_);
2262 LoadICState state() const {
2263 return LoadICState(static_cast<ExtraICState>(minor_key_));
2266 DEFINE_CALL_INTERFACE_DESCRIPTOR(Load);
2267 DEFINE_PLATFORM_CODE_STUB(LoadICTrampoline, PlatformCodeStub);
2271 class KeyedLoadICTrampolineStub : public LoadICTrampolineStub {
2273 explicit KeyedLoadICTrampolineStub(Isolate* isolate, const LoadICState& state)
2274 : LoadICTrampolineStub(isolate, state) {}
2276 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2278 DEFINE_PLATFORM_CODE_STUB(KeyedLoadICTrampoline, LoadICTrampolineStub);
2282 class VectorStoreICTrampolineStub : public PlatformCodeStub {
2284 VectorStoreICTrampolineStub(Isolate* isolate, const StoreICState& state)
2285 : PlatformCodeStub(isolate) {
2286 minor_key_ = state.GetExtraICState();
2289 Code::Kind GetCodeKind() const override { return Code::STORE_IC; }
2291 InlineCacheState GetICState() const final { return DEFAULT; }
2293 ExtraICState GetExtraICState() const final {
2294 return static_cast<ExtraICState>(minor_key_);
2298 StoreICState state() const {
2299 return StoreICState(static_cast<ExtraICState>(minor_key_));
2303 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreICTrampoline);
2304 DEFINE_PLATFORM_CODE_STUB(VectorStoreICTrampoline, PlatformCodeStub);
2308 class VectorKeyedStoreICTrampolineStub : public VectorStoreICTrampolineStub {
2310 VectorKeyedStoreICTrampolineStub(Isolate* isolate, const StoreICState& state)
2311 : VectorStoreICTrampolineStub(isolate, state) {}
2313 Code::Kind GetCodeKind() const override { return Code::KEYED_STORE_IC; }
2315 DEFINE_PLATFORM_CODE_STUB(VectorKeyedStoreICTrampoline,
2316 VectorStoreICTrampolineStub);
2320 class CallICTrampolineStub : public PlatformCodeStub {
2322 CallICTrampolineStub(Isolate* isolate, const CallICState& state)
2323 : PlatformCodeStub(isolate) {
2324 minor_key_ = state.GetExtraICState();
2327 Code::Kind GetCodeKind() const override { return Code::CALL_IC; }
2329 InlineCacheState GetICState() const final { return DEFAULT; }
2331 ExtraICState GetExtraICState() const final {
2332 return static_cast<ExtraICState>(minor_key_);
2336 CallICState state() const {
2337 return CallICState(static_cast<ExtraICState>(minor_key_));
2340 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunctionWithFeedback);
2341 DEFINE_PLATFORM_CODE_STUB(CallICTrampoline, PlatformCodeStub);
2345 class CallIC_ArrayTrampolineStub : public CallICTrampolineStub {
2347 CallIC_ArrayTrampolineStub(Isolate* isolate, const CallICState& state)
2348 : CallICTrampolineStub(isolate, state) {}
2351 DEFINE_PLATFORM_CODE_STUB(CallIC_ArrayTrampoline, CallICTrampolineStub);
2355 class LoadICStub : public PlatformCodeStub {
2357 explicit LoadICStub(Isolate* isolate, const LoadICState& state)
2358 : PlatformCodeStub(isolate) {
2359 minor_key_ = state.GetExtraICState();
2362 void GenerateForTrampoline(MacroAssembler* masm);
2364 Code::Kind GetCodeKind() const override { return Code::LOAD_IC; }
2365 InlineCacheState GetICState() const final { return DEFAULT; }
2366 ExtraICState GetExtraICState() const final {
2367 return static_cast<ExtraICState>(minor_key_);
2370 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2371 DEFINE_PLATFORM_CODE_STUB(LoadIC, PlatformCodeStub);
2374 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2378 class KeyedLoadICStub : public PlatformCodeStub {
2380 explicit KeyedLoadICStub(Isolate* isolate, const LoadICState& state)
2381 : PlatformCodeStub(isolate) {
2382 minor_key_ = state.GetExtraICState();
2385 void GenerateForTrampoline(MacroAssembler* masm);
2387 Code::Kind GetCodeKind() const override { return Code::KEYED_LOAD_IC; }
2388 InlineCacheState GetICState() const final { return DEFAULT; }
2389 ExtraICState GetExtraICState() const final {
2390 return static_cast<ExtraICState>(minor_key_);
2393 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
2394 DEFINE_PLATFORM_CODE_STUB(KeyedLoadIC, PlatformCodeStub);
2397 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2401 class VectorStoreICStub : public PlatformCodeStub {
2403 VectorStoreICStub(Isolate* isolate, const StoreICState& state)
2404 : PlatformCodeStub(isolate) {
2405 minor_key_ = state.GetExtraICState();
2408 void GenerateForTrampoline(MacroAssembler* masm);
2410 Code::Kind GetCodeKind() const final { return Code::STORE_IC; }
2411 InlineCacheState GetICState() const final { return DEFAULT; }
2412 ExtraICState GetExtraICState() const final {
2413 return static_cast<ExtraICState>(minor_key_);
2416 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreIC);
2417 DEFINE_PLATFORM_CODE_STUB(VectorStoreIC, PlatformCodeStub);
2420 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2424 class VectorKeyedStoreICStub : public PlatformCodeStub {
2426 VectorKeyedStoreICStub(Isolate* isolate, const StoreICState& state)
2427 : PlatformCodeStub(isolate) {
2428 minor_key_ = state.GetExtraICState();
2431 void GenerateForTrampoline(MacroAssembler* masm);
2433 Code::Kind GetCodeKind() const final { return Code::KEYED_STORE_IC; }
2434 InlineCacheState GetICState() const final { return DEFAULT; }
2435 virtual ExtraICState GetExtraICState() const final {
2436 return static_cast<ExtraICState>(minor_key_);
2439 DEFINE_CALL_INTERFACE_DESCRIPTOR(VectorStoreIC);
2440 DEFINE_PLATFORM_CODE_STUB(VectorKeyedStoreIC, PlatformCodeStub);
2443 void GenerateImpl(MacroAssembler* masm, bool in_frame);
2447 class DoubleToIStub : public PlatformCodeStub {
2449 DoubleToIStub(Isolate* isolate, Register source, Register destination,
2450 int offset, bool is_truncating, bool skip_fastpath = false)
2451 : PlatformCodeStub(isolate) {
2452 minor_key_ = SourceRegisterBits::encode(source.code()) |
2453 DestinationRegisterBits::encode(destination.code()) |
2454 OffsetBits::encode(offset) |
2455 IsTruncatingBits::encode(is_truncating) |
2456 SkipFastPathBits::encode(skip_fastpath) |
2457 SSE3Bits::encode(CpuFeatures::IsSupported(SSE3) ? 1 : 0);
2460 bool SometimesSetsUpAFrame() override { return false; }
2463 Register source() const {
2464 return Register::from_code(SourceRegisterBits::decode(minor_key_));
2466 Register destination() const {
2467 return Register::from_code(DestinationRegisterBits::decode(minor_key_));
2469 bool is_truncating() const { return IsTruncatingBits::decode(minor_key_); }
2470 bool skip_fastpath() const { return SkipFastPathBits::decode(minor_key_); }
2471 int offset() const { return OffsetBits::decode(minor_key_); }
2473 static const int kBitsPerRegisterNumber = 6;
2474 STATIC_ASSERT((1L << kBitsPerRegisterNumber) >= Register::kNumRegisters);
2475 class SourceRegisterBits:
2476 public BitField<int, 0, kBitsPerRegisterNumber> {}; // NOLINT
2477 class DestinationRegisterBits:
2478 public BitField<int, kBitsPerRegisterNumber,
2479 kBitsPerRegisterNumber> {}; // NOLINT
2480 class IsTruncatingBits:
2481 public BitField<bool, 2 * kBitsPerRegisterNumber, 1> {}; // NOLINT
2483 public BitField<int, 2 * kBitsPerRegisterNumber + 1, 3> {}; // NOLINT
2484 class SkipFastPathBits:
2485 public BitField<int, 2 * kBitsPerRegisterNumber + 4, 1> {}; // NOLINT
2487 public BitField<int, 2 * kBitsPerRegisterNumber + 5, 1> {}; // NOLINT
2489 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2490 DEFINE_PLATFORM_CODE_STUB(DoubleToI, PlatformCodeStub);
2494 class ScriptContextFieldStub : public HandlerStub {
2496 ScriptContextFieldStub(Isolate* isolate,
2497 const ScriptContextTable::LookupResult* lookup_result)
2498 : HandlerStub(isolate) {
2499 DCHECK(Accepted(lookup_result));
2500 set_sub_minor_key(ContextIndexBits::encode(lookup_result->context_index) |
2501 SlotIndexBits::encode(lookup_result->slot_index));
2504 int context_index() const {
2505 return ContextIndexBits::decode(sub_minor_key());
2508 int slot_index() const { return SlotIndexBits::decode(sub_minor_key()); }
2510 static bool Accepted(const ScriptContextTable::LookupResult* lookup_result) {
2511 return ContextIndexBits::is_valid(lookup_result->context_index) &&
2512 SlotIndexBits::is_valid(lookup_result->slot_index);
2516 static const int kContextIndexBits = 13;
2517 static const int kSlotIndexBits = 13;
2518 class ContextIndexBits : public BitField<int, 0, kContextIndexBits> {};
2520 : public BitField<int, kContextIndexBits, kSlotIndexBits> {};
2522 Code::StubType GetStubType() const override { return Code::FAST; }
2524 DEFINE_CODE_STUB_BASE(ScriptContextFieldStub, HandlerStub);
2528 class LoadScriptContextFieldStub : public ScriptContextFieldStub {
2530 LoadScriptContextFieldStub(
2531 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2532 : ScriptContextFieldStub(isolate, lookup_result) {}
2535 Code::Kind kind() const override { return Code::LOAD_IC; }
2537 DEFINE_HANDLER_CODE_STUB(LoadScriptContextField, ScriptContextFieldStub);
2541 class StoreScriptContextFieldStub : public ScriptContextFieldStub {
2543 StoreScriptContextFieldStub(
2544 Isolate* isolate, const ScriptContextTable::LookupResult* lookup_result)
2545 : ScriptContextFieldStub(isolate, lookup_result) {}
2548 Code::Kind kind() const override { return Code::STORE_IC; }
2550 DEFINE_HANDLER_CODE_STUB(StoreScriptContextField, ScriptContextFieldStub);
2554 class LoadFastElementStub : public HandlerStub {
2556 LoadFastElementStub(Isolate* isolate, bool is_js_array,
2557 ElementsKind elements_kind,
2558 bool convert_hole_to_undefined = false)
2559 : HandlerStub(isolate) {
2561 ElementsKindBits::encode(elements_kind) |
2562 IsJSArrayBits::encode(is_js_array) |
2563 CanConvertHoleToUndefined::encode(convert_hole_to_undefined));
2566 Code::Kind kind() const override { return Code::KEYED_LOAD_IC; }
2568 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2569 bool convert_hole_to_undefined() const {
2570 return CanConvertHoleToUndefined::decode(sub_minor_key());
2573 ElementsKind elements_kind() const {
2574 return ElementsKindBits::decode(sub_minor_key());
2578 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2579 class IsJSArrayBits: public BitField<bool, 8, 1> {};
2580 class CanConvertHoleToUndefined : public BitField<bool, 9, 1> {};
2582 DEFINE_HANDLER_CODE_STUB(LoadFastElement, HandlerStub);
2586 class StoreFastElementStub : public HydrogenCodeStub {
2588 StoreFastElementStub(Isolate* isolate, bool is_js_array,
2589 ElementsKind elements_kind, KeyedAccessStoreMode mode)
2590 : HydrogenCodeStub(isolate) {
2591 set_sub_minor_key(ElementsKindBits::encode(elements_kind) |
2592 IsJSArrayBits::encode(is_js_array) |
2593 StoreModeBits::encode(mode));
2596 static void GenerateAheadOfTime(Isolate* isolate);
2598 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2600 ElementsKind elements_kind() const {
2601 return ElementsKindBits::decode(sub_minor_key());
2604 KeyedAccessStoreMode store_mode() const {
2605 return StoreModeBits::decode(sub_minor_key());
2609 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2610 class StoreModeBits: public BitField<KeyedAccessStoreMode, 8, 4> {};
2611 class IsJSArrayBits: public BitField<bool, 12, 1> {};
2613 DEFINE_CALL_INTERFACE_DESCRIPTOR(Store);
2614 DEFINE_HYDROGEN_CODE_STUB(StoreFastElement, HydrogenCodeStub);
2618 class TransitionElementsKindStub : public HydrogenCodeStub {
2620 TransitionElementsKindStub(Isolate* isolate,
2621 ElementsKind from_kind,
2622 ElementsKind to_kind,
2623 bool is_js_array) : HydrogenCodeStub(isolate) {
2624 set_sub_minor_key(FromKindBits::encode(from_kind) |
2625 ToKindBits::encode(to_kind) |
2626 IsJSArrayBits::encode(is_js_array));
2629 ElementsKind from_kind() const {
2630 return FromKindBits::decode(sub_minor_key());
2633 ElementsKind to_kind() const { return ToKindBits::decode(sub_minor_key()); }
2635 bool is_js_array() const { return IsJSArrayBits::decode(sub_minor_key()); }
2638 class FromKindBits: public BitField<ElementsKind, 8, 8> {};
2639 class ToKindBits: public BitField<ElementsKind, 0, 8> {};
2640 class IsJSArrayBits: public BitField<bool, 16, 1> {};
2642 DEFINE_CALL_INTERFACE_DESCRIPTOR(TransitionElementsKind);
2643 DEFINE_HYDROGEN_CODE_STUB(TransitionElementsKind, HydrogenCodeStub);
2647 class AllocateHeapNumberStub final : public HydrogenCodeStub {
2649 explicit AllocateHeapNumberStub(Isolate* isolate)
2650 : HydrogenCodeStub(isolate) {}
2653 DEFINE_CALL_INTERFACE_DESCRIPTOR(AllocateHeapNumber);
2654 DEFINE_HYDROGEN_CODE_STUB(AllocateHeapNumber, HydrogenCodeStub);
2658 class ArrayConstructorStubBase : public HydrogenCodeStub {
2660 ArrayConstructorStubBase(Isolate* isolate,
2662 AllocationSiteOverrideMode override_mode)
2663 : HydrogenCodeStub(isolate) {
2664 // It only makes sense to override local allocation site behavior
2665 // if there is a difference between the global allocation site policy
2666 // for an ElementsKind and the desired usage of the stub.
2667 DCHECK(override_mode != DISABLE_ALLOCATION_SITES ||
2668 AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE);
2669 set_sub_minor_key(ElementsKindBits::encode(kind) |
2670 AllocationSiteOverrideModeBits::encode(override_mode));
2673 ElementsKind elements_kind() const {
2674 return ElementsKindBits::decode(sub_minor_key());
2677 AllocationSiteOverrideMode override_mode() const {
2678 return AllocationSiteOverrideModeBits::decode(sub_minor_key());
2681 static void GenerateStubsAheadOfTime(Isolate* isolate);
2683 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2684 static const int kConstructor = 0;
2685 static const int kAllocationSite = 1;
2688 std::ostream& BasePrintName(std::ostream& os,
2689 const char* name) const; // NOLINT
2692 // Ensure data fits within available bits.
2693 STATIC_ASSERT(LAST_ALLOCATION_SITE_OVERRIDE_MODE == 1);
2695 class ElementsKindBits: public BitField<ElementsKind, 0, 8> {};
2696 class AllocationSiteOverrideModeBits: public
2697 BitField<AllocationSiteOverrideMode, 8, 1> {}; // NOLINT
2699 DEFINE_CODE_STUB_BASE(ArrayConstructorStubBase, HydrogenCodeStub);
2703 class ArrayNoArgumentConstructorStub : public ArrayConstructorStubBase {
2705 ArrayNoArgumentConstructorStub(
2708 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2709 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2713 void PrintName(std::ostream& os) const override { // NOLINT
2714 BasePrintName(os, "ArrayNoArgumentConstructorStub");
2717 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructorConstantArgCount);
2718 DEFINE_HYDROGEN_CODE_STUB(ArrayNoArgumentConstructor,
2719 ArrayConstructorStubBase);
2723 class ArraySingleArgumentConstructorStub : public ArrayConstructorStubBase {
2725 ArraySingleArgumentConstructorStub(
2728 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2729 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2733 void PrintName(std::ostream& os) const override { // NOLINT
2734 BasePrintName(os, "ArraySingleArgumentConstructorStub");
2737 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
2738 DEFINE_HYDROGEN_CODE_STUB(ArraySingleArgumentConstructor,
2739 ArrayConstructorStubBase);
2743 class ArrayNArgumentsConstructorStub : public ArrayConstructorStubBase {
2745 ArrayNArgumentsConstructorStub(
2748 AllocationSiteOverrideMode override_mode = DONT_OVERRIDE)
2749 : ArrayConstructorStubBase(isolate, kind, override_mode) {
2753 void PrintName(std::ostream& os) const override { // NOLINT
2754 BasePrintName(os, "ArrayNArgumentsConstructorStub");
2757 DEFINE_CALL_INTERFACE_DESCRIPTOR(ArrayConstructor);
2758 DEFINE_HYDROGEN_CODE_STUB(ArrayNArgumentsConstructor,
2759 ArrayConstructorStubBase);
2763 class InternalArrayConstructorStubBase : public HydrogenCodeStub {
2765 InternalArrayConstructorStubBase(Isolate* isolate, ElementsKind kind)
2766 : HydrogenCodeStub(isolate) {
2767 set_sub_minor_key(ElementsKindBits::encode(kind));
2770 static void GenerateStubsAheadOfTime(Isolate* isolate);
2772 // Parameters accessed via CodeStubGraphBuilder::GetParameter()
2773 static const int kConstructor = 0;
2775 ElementsKind elements_kind() const {
2776 return ElementsKindBits::decode(sub_minor_key());
2780 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
2782 DEFINE_CODE_STUB_BASE(InternalArrayConstructorStubBase, HydrogenCodeStub);
2786 class InternalArrayNoArgumentConstructorStub : public
2787 InternalArrayConstructorStubBase {
2789 InternalArrayNoArgumentConstructorStub(Isolate* isolate,
2791 : InternalArrayConstructorStubBase(isolate, kind) { }
2793 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructorConstantArgCount);
2794 DEFINE_HYDROGEN_CODE_STUB(InternalArrayNoArgumentConstructor,
2795 InternalArrayConstructorStubBase);
2799 class InternalArraySingleArgumentConstructorStub : public
2800 InternalArrayConstructorStubBase {
2802 InternalArraySingleArgumentConstructorStub(Isolate* isolate,
2804 : InternalArrayConstructorStubBase(isolate, kind) { }
2806 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
2807 DEFINE_HYDROGEN_CODE_STUB(InternalArraySingleArgumentConstructor,
2808 InternalArrayConstructorStubBase);
2812 class InternalArrayNArgumentsConstructorStub : public
2813 InternalArrayConstructorStubBase {
2815 InternalArrayNArgumentsConstructorStub(Isolate* isolate, ElementsKind kind)
2816 : InternalArrayConstructorStubBase(isolate, kind) { }
2818 DEFINE_CALL_INTERFACE_DESCRIPTOR(InternalArrayConstructor);
2819 DEFINE_HYDROGEN_CODE_STUB(InternalArrayNArgumentsConstructor,
2820 InternalArrayConstructorStubBase);
2824 class StoreElementStub : public PlatformCodeStub {
2826 StoreElementStub(Isolate* isolate, ElementsKind elements_kind)
2827 : PlatformCodeStub(isolate) {
2828 minor_key_ = ElementsKindBits::encode(elements_kind);
2832 ElementsKind elements_kind() const {
2833 return ElementsKindBits::decode(minor_key_);
2836 class ElementsKindBits : public BitField<ElementsKind, 0, 8> {};
2838 DEFINE_CALL_INTERFACE_DESCRIPTOR(Store);
2839 DEFINE_PLATFORM_CODE_STUB(StoreElement, PlatformCodeStub);
2843 class ToBooleanStub: public HydrogenCodeStub {
2859 RESULT_AS_SMI, // For Smi(1) on truthy value, Smi(0) otherwise.
2860 RESULT_AS_ODDBALL, // For {true} on truthy value, {false} otherwise.
2861 RESULT_AS_INVERSE_ODDBALL // For {false} on truthy value, {true} otherwise.
2864 // At most 16 different types can be distinguished, because the Code object
2865 // only has room for two bytes to hold a set of these types. :-P
2866 STATIC_ASSERT(NUMBER_OF_TYPES <= 16);
2868 class Types : public EnumSet<Type, uint16_t> {
2870 Types() : EnumSet<Type, uint16_t>(0) {}
2871 explicit Types(uint16_t bits) : EnumSet<Type, uint16_t>(bits) {}
2873 bool UpdateStatus(Handle<Object> object);
2874 bool NeedsMap() const;
2875 bool CanBeUndetectable() const;
2876 bool IsGeneric() const { return ToIntegral() == Generic().ToIntegral(); }
2878 static Types Generic() { return Types((1 << NUMBER_OF_TYPES) - 1); }
2881 ToBooleanStub(Isolate* isolate, ResultMode mode, Types types = Types())
2882 : HydrogenCodeStub(isolate) {
2883 set_sub_minor_key(TypesBits::encode(types.ToIntegral()) |
2884 ResultModeBits::encode(mode));
2887 ToBooleanStub(Isolate* isolate, ExtraICState state)
2888 : HydrogenCodeStub(isolate) {
2889 set_sub_minor_key(TypesBits::encode(static_cast<uint16_t>(state)) |
2890 ResultModeBits::encode(RESULT_AS_SMI));
2893 bool UpdateStatus(Handle<Object> object);
2894 Types types() const { return Types(TypesBits::decode(sub_minor_key())); }
2895 ResultMode mode() const { return ResultModeBits::decode(sub_minor_key()); }
2897 Code::Kind GetCodeKind() const override { return Code::TO_BOOLEAN_IC; }
2898 void PrintState(std::ostream& os) const override; // NOLINT
2900 bool SometimesSetsUpAFrame() override { return false; }
2902 static Handle<Code> GetUninitialized(Isolate* isolate) {
2903 return ToBooleanStub(isolate, UNINITIALIZED).GetCode();
2906 ExtraICState GetExtraICState() const override { return types().ToIntegral(); }
2908 InlineCacheState GetICState() const override {
2909 if (types().IsEmpty()) {
2910 return ::v8::internal::UNINITIALIZED;
2917 ToBooleanStub(Isolate* isolate, InitializationState init_state)
2918 : HydrogenCodeStub(isolate, init_state) {
2919 set_sub_minor_key(ResultModeBits::encode(RESULT_AS_SMI));
2922 class TypesBits : public BitField<uint16_t, 0, NUMBER_OF_TYPES> {};
2923 class ResultModeBits : public BitField<ResultMode, NUMBER_OF_TYPES, 2> {};
2925 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToBoolean);
2926 DEFINE_HYDROGEN_CODE_STUB(ToBoolean, HydrogenCodeStub);
2930 std::ostream& operator<<(std::ostream& os, const ToBooleanStub::Types& t);
2933 class ElementsTransitionAndStoreStub : public HydrogenCodeStub {
2935 ElementsTransitionAndStoreStub(Isolate* isolate, ElementsKind from_kind,
2936 ElementsKind to_kind, bool is_jsarray,
2937 KeyedAccessStoreMode store_mode)
2938 : HydrogenCodeStub(isolate) {
2939 set_sub_minor_key(FromBits::encode(from_kind) | ToBits::encode(to_kind) |
2940 IsJSArrayBits::encode(is_jsarray) |
2941 StoreModeBits::encode(store_mode));
2944 ElementsKind from_kind() const { return FromBits::decode(sub_minor_key()); }
2945 ElementsKind to_kind() const { return ToBits::decode(sub_minor_key()); }
2946 bool is_jsarray() const { return IsJSArrayBits::decode(sub_minor_key()); }
2947 KeyedAccessStoreMode store_mode() const {
2948 return StoreModeBits::decode(sub_minor_key());
2952 class FromBits : public BitField<ElementsKind, 0, 8> {};
2953 class ToBits : public BitField<ElementsKind, 8, 8> {};
2954 class IsJSArrayBits : public BitField<bool, 16, 1> {};
2955 class StoreModeBits : public BitField<KeyedAccessStoreMode, 17, 4> {};
2957 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreTransition);
2958 DEFINE_HYDROGEN_CODE_STUB(ElementsTransitionAndStore, HydrogenCodeStub);
2962 class StoreArrayLiteralElementStub : public PlatformCodeStub {
2964 explicit StoreArrayLiteralElementStub(Isolate* isolate)
2965 : PlatformCodeStub(isolate) { }
2967 DEFINE_CALL_INTERFACE_DESCRIPTOR(StoreArrayLiteralElement);
2968 DEFINE_PLATFORM_CODE_STUB(StoreArrayLiteralElement, PlatformCodeStub);
2972 class StubFailureTrampolineStub : public PlatformCodeStub {
2974 StubFailureTrampolineStub(Isolate* isolate, StubFunctionMode function_mode)
2975 : PlatformCodeStub(isolate) {
2976 minor_key_ = FunctionModeField::encode(function_mode);
2979 static void GenerateAheadOfTime(Isolate* isolate);
2982 StubFunctionMode function_mode() const {
2983 return FunctionModeField::decode(minor_key_);
2986 class FunctionModeField : public BitField<StubFunctionMode, 0, 1> {};
2988 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
2989 DEFINE_PLATFORM_CODE_STUB(StubFailureTrampoline, PlatformCodeStub);
2993 class ProfileEntryHookStub : public PlatformCodeStub {
2995 explicit ProfileEntryHookStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
2997 // The profile entry hook function is not allowed to cause a GC.
2998 bool SometimesSetsUpAFrame() override { return false; }
3000 // Generates a call to the entry hook if it's enabled.
3001 static void MaybeCallEntryHook(MacroAssembler* masm);
3004 static void EntryHookTrampoline(intptr_t function,
3005 intptr_t stack_pointer,
3008 // ProfileEntryHookStub is called at the start of a function, so it has the
3009 // same register set.
3010 DEFINE_CALL_INTERFACE_DESCRIPTOR(CallFunction)
3011 DEFINE_PLATFORM_CODE_STUB(ProfileEntryHook, PlatformCodeStub);
3015 class StoreBufferOverflowStub : public PlatformCodeStub {
3017 StoreBufferOverflowStub(Isolate* isolate, SaveFPRegsMode save_fp)
3018 : PlatformCodeStub(isolate) {
3019 minor_key_ = SaveDoublesBits::encode(save_fp == kSaveFPRegs);
3022 static void GenerateFixedRegStubsAheadOfTime(Isolate* isolate);
3023 bool SometimesSetsUpAFrame() override { return false; }
3026 bool save_doubles() const { return SaveDoublesBits::decode(minor_key_); }
3028 class SaveDoublesBits : public BitField<bool, 0, 1> {};
3030 DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
3031 DEFINE_PLATFORM_CODE_STUB(StoreBufferOverflow, PlatformCodeStub);
3035 class SubStringStub : public PlatformCodeStub {
3037 explicit SubStringStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3039 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
3040 DEFINE_PLATFORM_CODE_STUB(SubString, PlatformCodeStub);
3044 class ToNumberStub final : public PlatformCodeStub {
3046 explicit ToNumberStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3048 DEFINE_CALL_INTERFACE_DESCRIPTOR(ToNumber);
3049 DEFINE_PLATFORM_CODE_STUB(ToNumber, PlatformCodeStub);
3053 class StringCompareStub : public PlatformCodeStub {
3055 explicit StringCompareStub(Isolate* isolate) : PlatformCodeStub(isolate) {}
3057 DEFINE_CALL_INTERFACE_DESCRIPTOR(ContextOnly);
3058 DEFINE_PLATFORM_CODE_STUB(StringCompare, PlatformCodeStub);
3062 #undef DEFINE_CALL_INTERFACE_DESCRIPTOR
3063 #undef DEFINE_PLATFORM_CODE_STUB
3064 #undef DEFINE_HANDLER_CODE_STUB
3065 #undef DEFINE_HYDROGEN_CODE_STUB
3066 #undef DEFINE_CODE_STUB
3067 #undef DEFINE_CODE_STUB_BASE
3069 extern Representation RepresentationFromType(Type* type);
3070 } } // namespace v8::internal
3072 #endif // V8_CODE_STUBS_H_