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 class ICUtility : public AllStatic {
19 // Clear the inline cache to initial state.
20 static void Clear(Isolate* isolate, Address address,
21 ConstantPoolArray* constant_pool);
25 class CallICState FINAL BASE_EMBEDDED {
27 explicit CallICState(ExtraICState extra_ic_state);
29 enum CallType { METHOD, FUNCTION };
31 CallICState(int argc, CallType call_type)
32 : argc_(argc), call_type_(call_type) {}
34 ExtraICState GetExtraICState() const;
36 static void GenerateAheadOfTime(Isolate*,
37 void (*Generate)(Isolate*,
40 int arg_count() const { return argc_; }
41 CallType call_type() const { return call_type_; }
43 bool CallAsMethod() const { return call_type_ == METHOD; }
46 class ArgcBits : public BitField<int, 0, Code::kArgumentsBits> {};
47 class CallTypeBits : public BitField<CallType, Code::kArgumentsBits, 1> {};
50 const CallType call_type_;
54 std::ostream& operator<<(std::ostream& os, const CallICState& s);
57 class BinaryOpICState FINAL BASE_EMBEDDED {
59 BinaryOpICState(Isolate* isolate, ExtraICState extra_ic_state);
61 BinaryOpICState(Isolate* isolate, Token::Value op)
67 DCHECK_LE(FIRST_TOKEN, op);
68 DCHECK_LE(op, LAST_TOKEN);
71 InlineCacheState GetICState() const {
72 if (Max(left_kind_, right_kind_) == NONE) {
73 return ::v8::internal::UNINITIALIZED;
75 if (Max(left_kind_, right_kind_) == GENERIC) {
76 return ::v8::internal::MEGAMORPHIC;
78 if (Min(left_kind_, right_kind_) == GENERIC) {
79 return ::v8::internal::GENERIC;
81 return ::v8::internal::MONOMORPHIC;
84 ExtraICState GetExtraICState() const;
86 static void GenerateAheadOfTime(Isolate*,
87 void (*Generate)(Isolate*,
88 const BinaryOpICState&));
90 // Returns true if the IC _could_ create allocation mementos.
91 bool CouldCreateAllocationMementos() const {
92 if (left_kind_ == STRING || right_kind_ == STRING) {
93 DCHECK_EQ(Token::ADD, op_);
99 // Returns true if the IC _should_ create allocation mementos.
100 bool ShouldCreateAllocationMementos() const {
101 return FLAG_allocation_site_pretenuring && CouldCreateAllocationMementos();
104 bool HasSideEffects() const {
105 return Max(left_kind_, right_kind_) == GENERIC;
108 // Returns true if the IC should enable the inline smi code (i.e. if either
109 // parameter may be a smi).
110 bool UseInlinedSmiCode() const {
111 return KindMaybeSmi(left_kind_) || KindMaybeSmi(right_kind_);
114 static const int FIRST_TOKEN = Token::BIT_OR;
115 static const int LAST_TOKEN = Token::MOD;
117 Token::Value op() const { return op_; }
118 Maybe<int> fixed_right_arg() const { return fixed_right_arg_; }
120 Type* GetLeftType(Zone* zone) const { return KindToType(left_kind_, zone); }
121 Type* GetRightType(Zone* zone) const { return KindToType(right_kind_, zone); }
122 Type* GetResultType(Zone* zone) const;
124 void Update(Handle<Object> left, Handle<Object> right, Handle<Object> result);
126 Isolate* isolate() const { return isolate_; }
129 friend std::ostream& operator<<(std::ostream& os, const BinaryOpICState& s);
131 enum Kind { NONE, SMI, INT32, NUMBER, STRING, GENERIC };
133 Kind UpdateKind(Handle<Object> object, Kind kind) const;
135 static const char* KindToString(Kind kind);
136 static Type* KindToType(Kind kind, Zone* zone);
137 static bool KindMaybeSmi(Kind kind) {
138 return (kind >= SMI && kind <= NUMBER) || kind == GENERIC;
141 // We truncate the last bit of the token.
142 STATIC_ASSERT(LAST_TOKEN - FIRST_TOKEN < (1 << 4));
143 class OpField : public BitField<int, 0, 4> {};
144 class ResultKindField : public BitField<Kind, 4, 3> {};
145 class LeftKindField : public BitField<Kind, 7, 3> {};
146 // When fixed right arg is set, we don't need to store the right kind.
147 // Thus the two fields can overlap.
148 class HasFixedRightArgField : public BitField<bool, 10, 1> {};
149 class FixedRightArgValueField : public BitField<int, 11, 4> {};
150 class RightKindField : public BitField<Kind, 11, 3> {};
156 Maybe<int> fixed_right_arg_;
161 std::ostream& operator<<(std::ostream& os, const BinaryOpICState& s);
164 class CompareICState {
166 // The type/state lattice is defined by the following inequations:
167 // UNINITIALIZED < ...
170 // INTERNALIZED_STRING < STRING
171 // KNOWN_OBJECT < OBJECT
178 UNIQUE_NAME, // Symbol or InternalizedString
180 KNOWN_OBJECT, // JSObject with specific map (faster check)
184 static Type* StateToType(Zone* zone, State state,
185 Handle<Map> map = Handle<Map>());
187 static State NewInputState(State old_state, Handle<Object> value);
189 static const char* GetStateName(CompareICState::State state);
191 static State TargetState(State old_state, State old_left, State old_right,
192 Token::Value op, bool has_inlined_smi_code,
193 Handle<Object> x, Handle<Object> y);
197 class LoadICState FINAL BASE_EMBEDDED {
199 explicit LoadICState(ExtraICState extra_ic_state) : state_(extra_ic_state) {}
201 explicit LoadICState(ContextualMode mode)
202 : state_(ContextualModeBits::encode(mode)) {}
204 ExtraICState GetExtraICState() const { return state_; }
206 ContextualMode contextual_mode() const {
207 return ContextualModeBits::decode(state_);
210 static ContextualMode GetContextualMode(ExtraICState state) {
211 return LoadICState(state).contextual_mode();
215 class ContextualModeBits : public BitField<ContextualMode, 0, 1> {};
216 STATIC_ASSERT(static_cast<int>(NOT_CONTEXTUAL) == 0);
218 const ExtraICState state_;
223 #endif // V8_IC_STATE_H_