V8 Project
ic-state.h
Go to the documentation of this file.
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.
4 
5 #ifndef V8_IC_STATE_H_
6 #define V8_IC_STATE_H_
7 
8 #include "src/macro-assembler.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 
14 const int kMaxKeyedPolymorphism = 4;
15 
16 
17 class ICUtility : public AllStatic {
18  public:
19  // Clear the inline cache to initial state.
20  static void Clear(Isolate* isolate, Address address,
21  ConstantPoolArray* constant_pool);
22 };
23 
24 
25 class CallICState FINAL BASE_EMBEDDED {
26  public:
27  explicit CallICState(ExtraICState extra_ic_state);
28 
29  enum CallType { METHOD, FUNCTION };
30 
31  CallICState(int argc, CallType call_type)
32  : argc_(argc), call_type_(call_type) {}
33 
35 
37  void (*Generate)(Isolate*,
38  const CallICState&));
39 
40  int arg_count() const { return argc_; }
41  CallType call_type() const { return call_type_; }
42 
43  bool CallAsMethod() const { return call_type_ == METHOD; }
44 
45  private:
46  class ArgcBits : public BitField<int, 0, Code::kArgumentsBits> {};
47  class CallTypeBits : public BitField<CallType, Code::kArgumentsBits, 1> {};
48 
49  const int argc_;
51 };
52 
53 
54 OStream& operator<<(OStream& os, const CallICState& s);
55 
56 
57 // Mode to overwrite BinaryExpression values.
59 
60 class BinaryOpICState FINAL BASE_EMBEDDED {
61  public:
62  BinaryOpICState(Isolate* isolate, ExtraICState extra_ic_state);
63 
65  : op_(op),
66  mode_(mode),
67  left_kind_(NONE),
68  right_kind_(NONE),
69  result_kind_(NONE),
70  isolate_(isolate) {
71  DCHECK_LE(FIRST_TOKEN, op);
72  DCHECK_LE(op, LAST_TOKEN);
73  }
74 
76  if (Max(left_kind_, right_kind_) == NONE) {
78  }
79  if (Max(left_kind_, right_kind_) == GENERIC) {
81  }
82  if (Min(left_kind_, right_kind_) == GENERIC) {
84  }
86  }
87 
89 
91  void (*Generate)(Isolate*,
92  const BinaryOpICState&));
93 
94  bool CanReuseDoubleBox() const {
95  return (result_kind_ > SMI && result_kind_ <= NUMBER) &&
96  ((mode_ == OVERWRITE_LEFT && left_kind_ > SMI &&
97  left_kind_ <= NUMBER) ||
98  (mode_ == OVERWRITE_RIGHT && right_kind_ > SMI &&
99  right_kind_ <= NUMBER));
100  }
101 
102  // Returns true if the IC _could_ create allocation mementos.
104  if (left_kind_ == STRING || right_kind_ == STRING) {
105  DCHECK_EQ(Token::ADD, op_);
106  return true;
107  }
108  return false;
109  }
110 
111  // Returns true if the IC _should_ create allocation mementos.
113  return FLAG_allocation_site_pretenuring && CouldCreateAllocationMementos();
114  }
115 
116  bool HasSideEffects() const {
117  return Max(left_kind_, right_kind_) == GENERIC;
118  }
119 
120  // Returns true if the IC should enable the inline smi code (i.e. if either
121  // parameter may be a smi).
122  bool UseInlinedSmiCode() const {
123  return KindMaybeSmi(left_kind_) || KindMaybeSmi(right_kind_);
124  }
125 
126  static const int FIRST_TOKEN = Token::BIT_OR;
127  static const int LAST_TOKEN = Token::MOD;
128 
129  Token::Value op() const { return op_; }
130  OverwriteMode mode() const { return mode_; }
131  Maybe<int> fixed_right_arg() const { return fixed_right_arg_; }
132 
133  Type* GetLeftType(Zone* zone) const { return KindToType(left_kind_, zone); }
134  Type* GetRightType(Zone* zone) const { return KindToType(right_kind_, zone); }
135  Type* GetResultType(Zone* zone) const;
136 
138 
139  Isolate* isolate() const { return isolate_; }
140 
141  private:
142  friend OStream& operator<<(OStream& os, const BinaryOpICState& s);
143 
144  enum Kind { NONE, SMI, INT32, NUMBER, STRING, GENERIC };
145 
146  Kind UpdateKind(Handle<Object> object, Kind kind) const;
147 
148  static const char* KindToString(Kind kind);
149  static Type* KindToType(Kind kind, Zone* zone);
150  static bool KindMaybeSmi(Kind kind) {
151  return (kind >= SMI && kind <= NUMBER) || kind == GENERIC;
152  }
153 
154  // We truncate the last bit of the token.
155  STATIC_ASSERT(LAST_TOKEN - FIRST_TOKEN < (1 << 4));
156  class OpField : public BitField<int, 0, 4> {};
157  class OverwriteModeField : public BitField<OverwriteMode, 4, 2> {};
158  class ResultKindField : public BitField<Kind, 6, 3> {};
159  class LeftKindField : public BitField<Kind, 9, 3> {};
160  // When fixed right arg is set, we don't need to store the right kind.
161  // Thus the two fields can overlap.
162  class HasFixedRightArgField : public BitField<bool, 12, 1> {};
163  class FixedRightArgValueField : public BitField<int, 13, 4> {};
164  class RightKindField : public BitField<Kind, 13, 3> {};
165 
172  Isolate* isolate_;
173 };
174 
175 
176 OStream& operator<<(OStream& os, const BinaryOpICState& s);
177 
178 
180  public:
181  // The type/state lattice is defined by the following inequations:
182  // UNINITIALIZED < ...
183  // ... < GENERIC
184  // SMI < NUMBER
185  // INTERNALIZED_STRING < STRING
186  // KNOWN_OBJECT < OBJECT
187  enum State {
193  UNIQUE_NAME, // Symbol or InternalizedString
194  OBJECT, // JSObject
195  KNOWN_OBJECT, // JSObject with specific map (faster check)
196  GENERIC
197  };
198 
199  static Type* StateToType(Zone* zone, State state,
201 
202  static State NewInputState(State old_state, Handle<Object> value);
203 
204  static const char* GetStateName(CompareICState::State state);
205 
206  static State TargetState(State old_state, State old_left, State old_right,
207  Token::Value op, bool has_inlined_smi_code,
209 };
210 
211 
212 class LoadICState FINAL BASE_EMBEDDED {
213  public:
214  explicit LoadICState(ExtraICState extra_ic_state) : state_(extra_ic_state) {}
215 
217  : state_(ContextualModeBits::encode(mode)) {}
218 
219  ExtraICState GetExtraICState() const { return state_; }
220 
222  return ContextualModeBits::decode(state_);
223  }
224 
226  return LoadICState(state).contextual_mode();
227  }
228 
229  private:
230  class ContextualModeBits : public BitField<ContextualMode, 0, 1> {};
231  STATIC_ASSERT(static_cast<int>(NOT_CONTEXTUAL) == 0);
232 
234 };
235 }
236 }
237 
238 #endif // V8_IC_STATE_H_
#define BASE_EMBEDDED
Definition: allocation.h:45
LoadICState(ExtraICState extra_ic_state)
Definition: ic-state.h:214
void Update(Handle< Object > left, Handle< Object > right, Handle< Object > result)
static void GenerateAheadOfTime(Isolate *, void(*Generate)(Isolate *, const CallICState &))
Type * GetResultType(Zone *zone) const
Isolate * isolate() const
Definition: ic-state.h:139
static bool KindMaybeSmi(Kind kind)
Definition: ic-state.h:150
STATIC_ASSERT(static_cast< int >(NOT_CONTEXTUAL)==0)
ContextualMode contextual_mode() const
Definition: ic-state.h:221
Token::Value op() const
Definition: ic-state.h:129
bool CanReuseDoubleBox() const
Definition: ic-state.h:94
BinaryOpICState(Isolate *isolate, Token::Value op, OverwriteMode mode)
Definition: ic-state.h:64
LoadICState(ContextualMode mode)
Definition: ic-state.h:216
STATIC_ASSERT(LAST_TOKEN - FIRST_TOKEN<(1<< 4))
bool CouldCreateAllocationMementos() const
Definition: ic-state.h:103
const ExtraICState state_
Definition: ic-state.h:233
bool HasSideEffects() const
Definition: ic-state.h:116
Maybe< int > fixed_right_arg() const
Definition: ic-state.h:131
static Type * KindToType(Kind kind, Zone *zone)
Type * GetLeftType(Zone *zone) const
Definition: ic-state.h:133
InlineCacheState GetICState() const
Definition: ic-state.h:75
static void GenerateAheadOfTime(Isolate *, void(*Generate)(Isolate *, const BinaryOpICState &))
CallType call_type() const
Definition: ic-state.h:41
BinaryOpICState(Isolate *isolate, ExtraICState extra_ic_state)
ExtraICState GetExtraICState() const
CallICState(int argc, CallType call_type)
Definition: ic-state.h:31
Maybe< int > fixed_right_arg_
Definition: ic-state.h:171
bool ShouldCreateAllocationMementos() const
Definition: ic-state.h:112
bool UseInlinedSmiCode() const
Definition: ic-state.h:122
static const char * KindToString(Kind kind)
OverwriteMode mode() const
Definition: ic-state.h:130
Kind UpdateKind(Handle< Object > object, Kind kind) const
const CallType call_type_
Definition: ic-state.h:50
CallICState(ExtraICState extra_ic_state)
static ContextualMode GetContextualMode(ExtraICState state)
Definition: ic-state.h:225
Type * GetRightType(Zone *zone) const
Definition: ic-state.h:134
bool CallAsMethod() const
Definition: ic-state.h:43
static const char * GetStateName(CompareICState::State state)
Definition: ic-state.cc:457
static Type * StateToType(Zone *zone, State state, Handle< Map > map=Handle< Map >())
Definition: ic-state.cc:483
static State NewInputState(State old_state, Handle< Object > value)
Definition: ic-state.cc:509
static State TargetState(State old_state, State old_left, State old_right, Token::Value op, bool has_inlined_smi_code, Handle< Object > x, Handle< Object > y)
Definition: ic-state.cc:552
Source to read snapshot and builtins files from.
Definition: lithium-arm.h:372
static void Clear(Isolate *isolate, Address address, ConstantPoolArray *constant_pool)
Definition: ic-state.cc:13
#define FINAL
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_BOOL(enable_always_align_csp
#define DCHECK_LE(v1, v2)
Definition: logging.h:210
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
static LifetimePosition Min(LifetimePosition a, LifetimePosition b)
@ NO_OVERWRITE
Definition: ic-state.h:58
@ OVERWRITE_RIGHT
Definition: ic-state.h:58
@ OVERWRITE_LEFT
Definition: ic-state.h:58
OStream & operator<<(OStream &os, const BasicBlockProfiler &p)
static LifetimePosition Max(LifetimePosition a, LifetimePosition b)
byte * Address
Definition: globals.h:101
@ NOT_CONTEXTUAL
Definition: objects.h:174
const int kMaxKeyedPolymorphism
Definition: ic-state.h:14
@ UNINITIALIZED
Definition: globals.h:446
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
@ NONE
@ STRING