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.
8 #include "src/macro-assembler.h"
14 const int kMaxKeyedPolymorphism = 4;
17 // IC_UTIL_LIST defines all utility functions called from generated
18 // inline caching code. The argument for the macro, ICU, is the function name.
19 #define IC_UTIL_LIST(ICU) \
21 ICU(KeyedLoadIC_Miss) \
23 ICU(CallIC_Customization_Miss) \
26 ICU(SharedStoreIC_ExtendStorage) \
27 ICU(KeyedStoreIC_Miss) \
28 ICU(KeyedStoreIC_Slow) \
29 /* Utilities for IC stubs. */ \
30 ICU(StoreCallbackProperty) \
31 ICU(LoadPropertyWithInterceptorOnly) \
32 ICU(LoadPropertyWithInterceptor) \
33 ICU(LoadElementWithInterceptor) \
34 ICU(StorePropertyWithInterceptor) \
36 ICU(BinaryOpIC_Miss) \
37 ICU(CompareNilIC_Miss) \
41 // IC is the base class for LoadIC, StoreIC, KeyedLoadIC, and KeyedStoreIC.
45 // The ids for utility called from the generated code.
47 #define CONST_NAME(name) k##name,
48 IC_UTIL_LIST(CONST_NAME)
53 // Looks up the address of the named utility.
54 static Address AddressFromUtilityId(UtilityId id);
56 // Alias the inline cache state type to make the IC code more readable.
57 typedef InlineCacheState State;
59 // The IC code is either invoked with no extra frames on the stack
60 // or with a single extra frame for supporting calls.
61 enum FrameDepth { NO_EXTRA_FRAME = 0, EXTRA_CALL_FRAME = 1 };
63 // Construct the IC structure with the given number of extra
64 // JavaScript frames on the stack.
65 IC(FrameDepth depth, Isolate* isolate);
68 State state() const { return state_; }
69 inline Address address() const;
71 // Compute the current IC state based on the target stub, receiver and name.
72 void UpdateState(Handle<Object> receiver, Handle<Object> name);
74 bool IsNameCompatibleWithPrototypeFailure(Handle<Object> name);
75 void MarkPrototypeFailure(Handle<Object> name) {
76 DCHECK(IsNameCompatibleWithPrototypeFailure(name));
77 state_ = PROTOTYPE_FAILURE;
80 // If the stub contains weak maps then this function adds the stub to
81 // the dependent code array of each weak map.
82 static void RegisterWeakMapDependency(Handle<Code> stub);
84 // This function is called when a weak map in the stub is dying,
85 // invalidates the stub by setting maps in it to undefined.
86 static void InvalidateMaps(Code* stub);
88 // Clear the inline cache to initial state.
89 static void Clear(Isolate* isolate, Address address,
90 ConstantPoolArray* constant_pool);
93 bool IsLoadStub() const {
94 return target()->is_load_stub() || target()->is_keyed_load_stub();
97 bool IsStoreStub() const {
98 return target()->is_store_stub() || target()->is_keyed_store_stub();
101 bool IsCallStub() const { return target()->is_call_stub(); }
104 template <class TypeClass>
105 static JSFunction* GetRootConstructor(TypeClass* type,
106 Context* native_context);
107 static inline Handle<Map> GetHandlerCacheHolder(HeapType* type,
108 bool receiver_is_holder,
110 CacheHolderFlag* flag);
111 static inline Handle<Map> GetICCacheHolder(HeapType* type, Isolate* isolate,
112 CacheHolderFlag* flag);
114 static bool IsCleared(Code* code) {
115 InlineCacheState state = code->ic_state();
116 return state == UNINITIALIZED || state == PREMONOMORPHIC;
119 // Utility functions to convert maps to types and back. There are two special
121 // - The heap_number_map is used as a marker which includes heap numbers as
123 // - The oddball map is only used for booleans.
124 static Handle<Map> TypeToMap(HeapType* type, Isolate* isolate);
126 static typename T::TypeHandle MapToType(Handle<Map> map,
127 typename T::Region* region);
129 static Handle<HeapType> CurrentTypeOf(Handle<Object> object,
133 // Get the call-site target; used for determining the state.
134 Handle<Code> target() const { return target_; }
136 Address fp() const { return fp_; }
137 Address pc() const { return *pc_address_; }
138 Isolate* isolate() const { return isolate_; }
140 // Get the shared function info of the caller.
141 SharedFunctionInfo* GetSharedFunctionInfo() const;
142 // Get the code object of the caller.
143 Code* GetCode() const;
144 // Get the original (non-breakpointed) code object of the caller.
145 Code* GetOriginalCode() const;
147 // Set the call-site target.
148 inline void set_target(Code* code);
149 bool is_target_set() { return target_set_; }
151 char TransitionMarkFromState(IC::State state);
152 void TraceIC(const char* type, Handle<Object> name);
153 void TraceIC(const char* type, Handle<Object> name, State old_state,
156 MaybeHandle<Object> TypeError(const char* type, Handle<Object> object,
158 MaybeHandle<Object> ReferenceError(const char* type, Handle<Name> name);
160 // Access the target code for the given IC address.
161 static inline Code* GetTargetAtAddress(Address address,
162 ConstantPoolArray* constant_pool);
163 static inline void SetTargetAtAddress(Address address, Code* target,
164 ConstantPoolArray* constant_pool);
165 static void OnTypeFeedbackChanged(Isolate* isolate, Address address,
166 State old_state, State new_state,
167 bool target_remains_ic_stub);
168 static void PostPatching(Address address, Code* target, Code* old_target);
170 // Compute the handler either by compiling or by retrieving a cached version.
171 Handle<Code> ComputeHandler(LookupIterator* lookup,
172 Handle<Object> value = Handle<Code>::null());
173 virtual Handle<Code> CompileHandler(LookupIterator* lookup,
174 Handle<Object> value,
175 CacheHolderFlag cache_holder) {
177 return Handle<Code>::null();
180 void UpdateMonomorphicIC(Handle<Code> handler, Handle<Name> name);
181 bool UpdatePolymorphicIC(Handle<Name> name, Handle<Code> code);
182 void UpdateMegamorphicCache(HeapType* type, Name* name, Code* code);
184 void CopyICToMegamorphicCache(Handle<Name> name);
185 bool IsTransitionOfMonomorphicTarget(Map* source_map, Map* target_map);
186 void PatchCache(Handle<Name> name, Handle<Code> code);
187 Code::Kind kind() const { return kind_; }
188 Code::Kind handler_kind() const {
189 if (kind_ == Code::KEYED_LOAD_IC) return Code::LOAD_IC;
190 DCHECK(kind_ == Code::LOAD_IC || kind_ == Code::STORE_IC ||
191 kind_ == Code::KEYED_STORE_IC);
194 virtual Handle<Code> megamorphic_stub() {
196 return Handle<Code>::null();
199 bool TryRemoveInvalidPrototypeDependentStub(Handle<Object> receiver,
200 Handle<String> name);
202 ExtraICState extra_ic_state() const { return extra_ic_state_; }
203 void set_extra_ic_state(ExtraICState state) { extra_ic_state_ = state; }
205 Handle<HeapType> receiver_type() { return receiver_type_; }
206 void update_receiver_type(Handle<Object> receiver) {
207 receiver_type_ = CurrentTypeOf(receiver, isolate_);
210 void TargetMaps(MapHandleList* list) {
212 for (int i = 0; i < target_maps_.length(); i++) {
213 list->Add(target_maps_.at(i));
217 void TargetTypes(TypeHandleList* list) {
219 for (int i = 0; i < target_maps_.length(); i++) {
220 list->Add(IC::MapToType<HeapType>(target_maps_.at(i), isolate_));
224 Map* FirstTargetMap() {
226 return target_maps_.length() > 0 ? *target_maps_.at(0) : NULL;
230 inline void UpdateTarget();
233 inline Code* raw_target() const;
234 inline ConstantPoolArray* constant_pool() const;
235 inline ConstantPoolArray* raw_constant_pool() const;
237 void FindTargetMaps() {
238 if (target_maps_set_) return;
239 target_maps_set_ = true;
240 if (state_ == MONOMORPHIC) {
241 Map* map = target_->FindFirstMap();
242 if (map != NULL) target_maps_.Add(handle(map));
243 } else if (state_ != UNINITIALIZED && state_ != PREMONOMORPHIC) {
244 target_->FindAllMaps(&target_maps_);
248 // Frame pointer for the frame that uses (calls) the IC.
251 // All access to the program counter of an IC structure is indirect
252 // to make the code GC safe. This feature is crucial since
253 // GetProperty and SetProperty are called and they in turn might
254 // invoke the garbage collector.
255 Address* pc_address_;
259 // The constant pool of the code which originally called the IC (which might
260 // be for the breakpointed copy of the original code).
261 Handle<ConstantPoolArray> raw_constant_pool_;
263 // The original code target that missed.
264 Handle<Code> target_;
268 Handle<HeapType> receiver_type_;
269 MaybeHandle<Code> maybe_handler_;
271 ExtraICState extra_ic_state_;
272 MapHandleList target_maps_;
273 bool target_maps_set_;
275 DISALLOW_IMPLICIT_CONSTRUCTORS(IC);
279 // An IC_Utility encapsulates IC::UtilityId. It exists mainly because you
280 // cannot make forward declarations to an enum.
283 explicit IC_Utility(IC::UtilityId id)
284 : address_(IC::AddressFromUtilityId(id)), id_(id) {}
286 Address address() const { return address_; }
288 IC::UtilityId id() const { return id_; }
296 class CallIC : public IC {
298 enum CallType { METHOD, FUNCTION };
300 class State V8_FINAL BASE_EMBEDDED {
302 explicit State(ExtraICState extra_ic_state);
304 State(int argc, CallType call_type) : argc_(argc), call_type_(call_type) {}
306 ExtraICState GetExtraICState() const;
308 static void GenerateAheadOfTime(Isolate*,
309 void (*Generate)(Isolate*, const State&));
311 int arg_count() const { return argc_; }
312 CallType call_type() const { return call_type_; }
314 bool CallAsMethod() const { return call_type_ == METHOD; }
317 class ArgcBits : public BitField<int, 0, Code::kArgumentsBits> {};
318 class CallTypeBits : public BitField<CallType, Code::kArgumentsBits, 1> {};
321 const CallType call_type_;
324 explicit CallIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {}
326 void PatchMegamorphic(Handle<Object> function, Handle<FixedArray> vector,
329 void HandleMiss(Handle<Object> receiver, Handle<Object> function,
330 Handle<FixedArray> vector, Handle<Smi> slot);
332 // Returns true if a custom handler was installed.
333 bool DoCustomHandler(Handle<Object> receiver, Handle<Object> function,
334 Handle<FixedArray> vector, Handle<Smi> slot,
337 // Code generator routines.
338 static Handle<Code> initialize_stub(Isolate* isolate, int argc,
341 static void Clear(Isolate* isolate, Address address, Code* target,
342 ConstantPoolArray* constant_pool);
345 inline IC::State FeedbackToState(Handle<FixedArray> vector,
346 Handle<Smi> slot) const;
350 OStream& operator<<(OStream& os, const CallIC::State& s);
353 class LoadIC : public IC {
355 enum ParameterIndices { kReceiverIndex, kNameIndex, kParameterCount };
356 static const Register ReceiverRegister();
357 static const Register NameRegister();
359 // With flag vector-ics, there is an additional argument. And for calls from
360 // crankshaft, yet another.
361 static const Register SlotRegister();
362 static const Register VectorRegister();
364 class State V8_FINAL BASE_EMBEDDED {
366 explicit State(ExtraICState extra_ic_state) : state_(extra_ic_state) {}
368 explicit State(ContextualMode mode)
369 : state_(ContextualModeBits::encode(mode)) {}
371 ExtraICState GetExtraICState() const { return state_; }
373 ContextualMode contextual_mode() const {
374 return ContextualModeBits::decode(state_);
378 class ContextualModeBits : public BitField<ContextualMode, 0, 1> {};
379 STATIC_ASSERT(static_cast<int>(NOT_CONTEXTUAL) == 0);
381 const ExtraICState state_;
384 static ExtraICState ComputeExtraICState(ContextualMode contextual_mode) {
385 return State(contextual_mode).GetExtraICState();
388 static ContextualMode GetContextualMode(ExtraICState state) {
389 return State(state).contextual_mode();
392 ContextualMode contextual_mode() const {
393 return GetContextualMode(extra_ic_state());
396 explicit LoadIC(FrameDepth depth, Isolate* isolate) : IC(depth, isolate) {
397 DCHECK(IsLoadStub());
400 // Returns if this IC is for contextual (no explicit receiver)
401 // access to properties.
402 bool IsUndeclaredGlobal(Handle<Object> receiver) {
403 if (receiver->IsGlobalObject()) {
404 return contextual_mode() == CONTEXTUAL;
406 DCHECK(contextual_mode() != CONTEXTUAL);
411 // Code generator routines.
412 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
413 static void GeneratePreMonomorphic(MacroAssembler* masm) {
416 static void GenerateMiss(MacroAssembler* masm);
417 static void GenerateMegamorphic(MacroAssembler* masm);
418 static void GenerateNormal(MacroAssembler* masm);
419 static void GenerateRuntimeGetProperty(MacroAssembler* masm);
421 static Handle<Code> initialize_stub(Isolate* isolate,
422 ExtraICState extra_state);
424 MUST_USE_RESULT MaybeHandle<Object> Load(Handle<Object> object,
428 inline void set_target(Code* code);
430 Handle<Code> slow_stub() const {
431 if (kind() == Code::LOAD_IC) {
432 return isolate()->builtins()->LoadIC_Slow();
434 DCHECK_EQ(Code::KEYED_LOAD_IC, kind());
435 return isolate()->builtins()->KeyedLoadIC_Slow();
439 virtual Handle<Code> megamorphic_stub();
441 // Update the inline cache and the global stub cache based on the
443 void UpdateCaches(LookupIterator* lookup);
445 virtual Handle<Code> CompileHandler(LookupIterator* lookup,
446 Handle<Object> unused,
447 CacheHolderFlag cache_holder);
450 virtual Handle<Code> pre_monomorphic_stub() const;
451 static Handle<Code> pre_monomorphic_stub(Isolate* isolate,
452 ExtraICState extra_state);
454 Handle<Code> SimpleFieldLoad(FieldIndex index);
456 static void Clear(Isolate* isolate, Address address, Code* target,
457 ConstantPoolArray* constant_pool);
463 class KeyedLoadIC : public LoadIC {
465 explicit KeyedLoadIC(FrameDepth depth, Isolate* isolate)
466 : LoadIC(depth, isolate) {
467 DCHECK(target()->is_keyed_load_stub());
470 MUST_USE_RESULT MaybeHandle<Object> Load(Handle<Object> object,
473 // Code generator routines.
474 static void GenerateMiss(MacroAssembler* masm);
475 static void GenerateRuntimeGetProperty(MacroAssembler* masm);
476 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
477 static void GeneratePreMonomorphic(MacroAssembler* masm) {
480 static void GenerateGeneric(MacroAssembler* masm);
481 static void GenerateString(MacroAssembler* masm);
482 static void GenerateIndexedInterceptor(MacroAssembler* masm);
483 static void GenerateSloppyArguments(MacroAssembler* masm);
485 // Bit mask to be tested against bit field for the cases when
486 // generic stub should go into slow case.
487 // Access check is necessary explicitly since generic stub does not perform
489 static const int kSlowCaseBitFieldMask =
490 (1 << Map::kIsAccessCheckNeeded) | (1 << Map::kHasIndexedInterceptor);
492 static Handle<Code> generic_stub(Isolate* isolate);
493 static Handle<Code> pre_monomorphic_stub(Isolate* isolate);
496 Handle<Code> LoadElementStub(Handle<JSObject> receiver);
497 virtual Handle<Code> pre_monomorphic_stub() const {
498 return pre_monomorphic_stub(isolate());
502 Handle<Code> generic_stub() const { return generic_stub(isolate()); }
503 Handle<Code> indexed_interceptor_stub() {
504 return isolate()->builtins()->KeyedLoadIC_IndexedInterceptor();
506 Handle<Code> sloppy_arguments_stub() {
507 return isolate()->builtins()->KeyedLoadIC_SloppyArguments();
509 Handle<Code> string_stub() {
510 return isolate()->builtins()->KeyedLoadIC_String();
513 static void Clear(Isolate* isolate, Address address, Code* target,
514 ConstantPoolArray* constant_pool);
520 class StoreIC : public IC {
522 class StrictModeState : public BitField<StrictMode, 1, 1> {};
523 static ExtraICState ComputeExtraICState(StrictMode flag) {
524 return StrictModeState::encode(flag);
526 static StrictMode GetStrictMode(ExtraICState state) {
527 return StrictModeState::decode(state);
530 // For convenience, a statically declared encoding of strict mode extra
532 static const ExtraICState kStrictModeState = 1 << StrictModeState::kShift;
534 enum ParameterIndices {
540 static const Register ReceiverRegister();
541 static const Register NameRegister();
542 static const Register ValueRegister();
544 StoreIC(FrameDepth depth, Isolate* isolate) : IC(depth, isolate) {
545 DCHECK(IsStoreStub());
548 StrictMode strict_mode() const {
549 return StrictModeState::decode(extra_ic_state());
552 // Code generators for stub routines. Only called once at startup.
553 static void GenerateSlow(MacroAssembler* masm);
554 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
555 static void GeneratePreMonomorphic(MacroAssembler* masm) {
558 static void GenerateMiss(MacroAssembler* masm);
559 static void GenerateMegamorphic(MacroAssembler* masm);
560 static void GenerateNormal(MacroAssembler* masm);
561 static void GenerateRuntimeSetProperty(MacroAssembler* masm,
562 StrictMode strict_mode);
564 static Handle<Code> initialize_stub(Isolate* isolate, StrictMode strict_mode);
566 MUST_USE_RESULT MaybeHandle<Object> Store(
567 Handle<Object> object, Handle<Name> name, Handle<Object> value,
568 JSReceiver::StoreFromKeyed store_mode =
569 JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED);
571 bool LookupForWrite(LookupIterator* it, Handle<Object> value,
572 JSReceiver::StoreFromKeyed store_mode);
575 virtual Handle<Code> megamorphic_stub();
578 virtual Handle<Code> generic_stub() const;
580 virtual Handle<Code> slow_stub() const {
581 return isolate()->builtins()->StoreIC_Slow();
584 virtual Handle<Code> pre_monomorphic_stub() const {
585 return pre_monomorphic_stub(isolate(), strict_mode());
588 static Handle<Code> pre_monomorphic_stub(Isolate* isolate,
589 StrictMode strict_mode);
591 // Update the inline cache and the global stub cache based on the
593 void UpdateCaches(LookupIterator* lookup, Handle<Object> value,
594 JSReceiver::StoreFromKeyed store_mode);
595 virtual Handle<Code> CompileHandler(LookupIterator* lookup,
596 Handle<Object> value,
597 CacheHolderFlag cache_holder);
600 inline void set_target(Code* code);
602 static void Clear(Isolate* isolate, Address address, Code* target,
603 ConstantPoolArray* constant_pool);
609 enum KeyedStoreCheckMap { kDontCheckMap, kCheckMap };
612 enum KeyedStoreIncrementLength { kDontIncrementLength, kIncrementLength };
615 class KeyedStoreIC : public StoreIC {
617 // ExtraICState bits (building on IC)
619 class ExtraICStateKeyedAccessStoreMode
620 : public BitField<KeyedAccessStoreMode, 2, 4> {}; // NOLINT
622 static ExtraICState ComputeExtraICState(StrictMode flag,
623 KeyedAccessStoreMode mode) {
624 return StrictModeState::encode(flag) |
625 ExtraICStateKeyedAccessStoreMode::encode(mode);
628 static KeyedAccessStoreMode GetKeyedAccessStoreMode(
629 ExtraICState extra_state) {
630 return ExtraICStateKeyedAccessStoreMode::decode(extra_state);
633 // The map register isn't part of the normal call specification, but
634 // ElementsTransitionAndStoreStub, used in polymorphic keyed store
635 // stub implementations requires it to be initialized.
636 static const Register MapRegister();
638 KeyedStoreIC(FrameDepth depth, Isolate* isolate) : StoreIC(depth, isolate) {
639 DCHECK(target()->is_keyed_store_stub());
642 MUST_USE_RESULT MaybeHandle<Object> Store(Handle<Object> object,
644 Handle<Object> value);
646 // Code generators for stub routines. Only called once at startup.
647 static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); }
648 static void GeneratePreMonomorphic(MacroAssembler* masm) {
651 static void GenerateMiss(MacroAssembler* masm);
652 static void GenerateSlow(MacroAssembler* masm);
653 static void GenerateRuntimeSetProperty(MacroAssembler* masm,
654 StrictMode strict_mode);
655 static void GenerateGeneric(MacroAssembler* masm, StrictMode strict_mode);
656 static void GenerateSloppyArguments(MacroAssembler* masm);
659 virtual Handle<Code> pre_monomorphic_stub() const {
660 return pre_monomorphic_stub(isolate(), strict_mode());
662 static Handle<Code> pre_monomorphic_stub(Isolate* isolate,
663 StrictMode strict_mode) {
664 if (strict_mode == STRICT) {
665 return isolate->builtins()->KeyedStoreIC_PreMonomorphic_Strict();
667 return isolate->builtins()->KeyedStoreIC_PreMonomorphic();
670 virtual Handle<Code> slow_stub() const {
671 return isolate()->builtins()->KeyedStoreIC_Slow();
673 virtual Handle<Code> megamorphic_stub() {
674 if (strict_mode() == STRICT) {
675 return isolate()->builtins()->KeyedStoreIC_Generic_Strict();
677 return isolate()->builtins()->KeyedStoreIC_Generic();
681 Handle<Code> StoreElementStub(Handle<JSObject> receiver,
682 KeyedAccessStoreMode store_mode);
685 inline void set_target(Code* code);
688 virtual Handle<Code> generic_stub() const {
689 if (strict_mode() == STRICT) {
690 return isolate()->builtins()->KeyedStoreIC_Generic_Strict();
692 return isolate()->builtins()->KeyedStoreIC_Generic();
696 Handle<Code> sloppy_arguments_stub() {
697 return isolate()->builtins()->KeyedStoreIC_SloppyArguments();
700 static void Clear(Isolate* isolate, Address address, Code* target,
701 ConstantPoolArray* constant_pool);
703 KeyedAccessStoreMode GetStoreMode(Handle<JSObject> receiver,
704 Handle<Object> key, Handle<Object> value);
706 Handle<Map> ComputeTransitionedMap(Handle<Map> map,
707 KeyedAccessStoreMode store_mode);
713 // Mode to overwrite BinaryExpression values.
714 enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT };
716 // Type Recording BinaryOpIC, that records the types of the inputs and outputs.
717 class BinaryOpIC : public IC {
719 class State V8_FINAL BASE_EMBEDDED {
721 State(Isolate* isolate, ExtraICState extra_ic_state);
723 State(Isolate* isolate, Token::Value op, OverwriteMode mode)
730 DCHECK_LE(FIRST_TOKEN, op);
731 DCHECK_LE(op, LAST_TOKEN);
734 InlineCacheState GetICState() const {
735 if (Max(left_kind_, right_kind_) == NONE) {
736 return ::v8::internal::UNINITIALIZED;
738 if (Max(left_kind_, right_kind_) == GENERIC) {
739 return ::v8::internal::MEGAMORPHIC;
741 if (Min(left_kind_, right_kind_) == GENERIC) {
742 return ::v8::internal::GENERIC;
744 return ::v8::internal::MONOMORPHIC;
747 ExtraICState GetExtraICState() const;
749 static void GenerateAheadOfTime(Isolate*,
750 void (*Generate)(Isolate*, const State&));
752 bool CanReuseDoubleBox() const {
753 return (result_kind_ > SMI && result_kind_ <= NUMBER) &&
754 ((mode_ == OVERWRITE_LEFT && left_kind_ > SMI &&
755 left_kind_ <= NUMBER) ||
756 (mode_ == OVERWRITE_RIGHT && right_kind_ > SMI &&
757 right_kind_ <= NUMBER));
760 // Returns true if the IC _could_ create allocation mementos.
761 bool CouldCreateAllocationMementos() const {
762 if (left_kind_ == STRING || right_kind_ == STRING) {
763 DCHECK_EQ(Token::ADD, op_);
769 // Returns true if the IC _should_ create allocation mementos.
770 bool ShouldCreateAllocationMementos() const {
771 return FLAG_allocation_site_pretenuring &&
772 CouldCreateAllocationMementos();
775 bool HasSideEffects() const {
776 return Max(left_kind_, right_kind_) == GENERIC;
779 // Returns true if the IC should enable the inline smi code (i.e. if either
780 // parameter may be a smi).
781 bool UseInlinedSmiCode() const {
782 return KindMaybeSmi(left_kind_) || KindMaybeSmi(right_kind_);
785 static const int FIRST_TOKEN = Token::BIT_OR;
786 static const int LAST_TOKEN = Token::MOD;
788 Token::Value op() const { return op_; }
789 OverwriteMode mode() const { return mode_; }
790 Maybe<int> fixed_right_arg() const { return fixed_right_arg_; }
792 Type* GetLeftType(Zone* zone) const { return KindToType(left_kind_, zone); }
793 Type* GetRightType(Zone* zone) const {
794 return KindToType(right_kind_, zone);
796 Type* GetResultType(Zone* zone) const;
798 void Update(Handle<Object> left, Handle<Object> right,
799 Handle<Object> result);
801 Isolate* isolate() const { return isolate_; }
804 friend OStream& operator<<(OStream& os, const BinaryOpIC::State& s);
806 enum Kind { NONE, SMI, INT32, NUMBER, STRING, GENERIC };
808 Kind UpdateKind(Handle<Object> object, Kind kind) const;
810 static const char* KindToString(Kind kind);
811 static Type* KindToType(Kind kind, Zone* zone);
812 static bool KindMaybeSmi(Kind kind) {
813 return (kind >= SMI && kind <= NUMBER) || kind == GENERIC;
816 // We truncate the last bit of the token.
817 STATIC_ASSERT(LAST_TOKEN - FIRST_TOKEN < (1 << 4));
818 class OpField : public BitField<int, 0, 4> {};
819 class OverwriteModeField : public BitField<OverwriteMode, 4, 2> {};
820 class ResultKindField : public BitField<Kind, 6, 3> {};
821 class LeftKindField : public BitField<Kind, 9, 3> {};
822 // When fixed right arg is set, we don't need to store the right kind.
823 // Thus the two fields can overlap.
824 class HasFixedRightArgField : public BitField<bool, 12, 1> {};
825 class FixedRightArgValueField : public BitField<int, 13, 4> {};
826 class RightKindField : public BitField<Kind, 13, 3> {};
833 Maybe<int> fixed_right_arg_;
837 explicit BinaryOpIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {}
839 static Builtins::JavaScript TokenToJSBuiltin(Token::Value op);
841 MaybeHandle<Object> Transition(Handle<AllocationSite> allocation_site,
843 Handle<Object> right) V8_WARN_UNUSED_RESULT;
847 OStream& operator<<(OStream& os, const BinaryOpIC::State& s);
850 class CompareIC : public IC {
852 // The type/state lattice is defined by the following inequations:
853 // UNINITIALIZED < ...
856 // INTERNALIZED_STRING < STRING
857 // KNOWN_OBJECT < OBJECT
864 UNIQUE_NAME, // Symbol or InternalizedString
866 KNOWN_OBJECT, // JSObject with specific map (faster check)
870 static State NewInputState(State old_state, Handle<Object> value);
872 static Type* StateToType(Zone* zone, State state,
873 Handle<Map> map = Handle<Map>());
875 static void StubInfoToType(uint32_t stub_key, Type** left_type,
876 Type** right_type, Type** overall_type,
877 Handle<Map> map, Zone* zone);
879 CompareIC(Isolate* isolate, Token::Value op)
880 : IC(EXTRA_CALL_FRAME, isolate), op_(op) {}
882 // Update the inline cache for the given operands.
883 Code* UpdateCaches(Handle<Object> x, Handle<Object> y);
886 // Factory method for getting an uninitialized compare stub.
887 static Handle<Code> GetUninitialized(Isolate* isolate, Token::Value op);
889 // Helper function for computing the condition for a compare operation.
890 static Condition ComputeCondition(Token::Value op);
892 static const char* GetStateName(State state);
895 static bool HasInlinedSmiCode(Address address);
897 State TargetState(State old_state, State old_left, State old_right,
898 bool has_inlined_smi_code, Handle<Object> x,
901 bool strict() const { return op_ == Token::EQ_STRICT; }
902 Condition GetCondition() const { return ComputeCondition(op_); }
904 static Code* GetRawUninitialized(Isolate* isolate, Token::Value op);
906 static void Clear(Isolate* isolate, Address address, Code* target,
907 ConstantPoolArray* constant_pool);
915 class CompareNilIC : public IC {
917 explicit CompareNilIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {}
919 Handle<Object> CompareNil(Handle<Object> object);
921 static Handle<Code> GetUninitialized();
923 static void Clear(Address address, Code* target,
924 ConstantPoolArray* constant_pool);
926 static Handle<Object> DoCompareNilSlow(Isolate* isolate, NilValue nil,
927 Handle<Object> object);
931 class ToBooleanIC : public IC {
933 explicit ToBooleanIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {}
935 Handle<Object> ToBoolean(Handle<Object> object);
939 // Helper for BinaryOpIC and CompareIC.
940 enum InlinedSmiCheck { ENABLE_INLINED_SMI_CHECK, DISABLE_INLINED_SMI_CHECK };
941 void PatchInlinedSmiCode(Address address, InlinedSmiCheck check);
943 DECLARE_RUNTIME_FUNCTION(KeyedLoadIC_MissFromStubFailure);
944 DECLARE_RUNTIME_FUNCTION(KeyedStoreIC_MissFromStubFailure);
945 DECLARE_RUNTIME_FUNCTION(UnaryOpIC_Miss);
946 DECLARE_RUNTIME_FUNCTION(StoreIC_MissFromStubFailure);
947 DECLARE_RUNTIME_FUNCTION(ElementsTransitionAndStoreIC_Miss);
948 DECLARE_RUNTIME_FUNCTION(BinaryOpIC_Miss);
949 DECLARE_RUNTIME_FUNCTION(BinaryOpIC_MissWithAllocationSite);
950 DECLARE_RUNTIME_FUNCTION(CompareNilIC_Miss);
951 DECLARE_RUNTIME_FUNCTION(ToBooleanIC_Miss);
953 // Support functions for callbacks handlers.
954 DECLARE_RUNTIME_FUNCTION(StoreCallbackProperty);
956 // Support functions for interceptor handlers.
957 DECLARE_RUNTIME_FUNCTION(LoadPropertyWithInterceptorOnly);
958 DECLARE_RUNTIME_FUNCTION(LoadPropertyWithInterceptor);
959 DECLARE_RUNTIME_FUNCTION(LoadElementWithInterceptor);
960 DECLARE_RUNTIME_FUNCTION(StorePropertyWithInterceptor);
962 } // namespace v8::internal