1a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org// Copyright 2014 the V8 project authors. All rights reserved.
2a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org// Use of this source code is governed by a BSD-style license that can be
3a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org// found in the LICENSE file.
4a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
5a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org#ifndef V8_IC_IC_COMPILER_H_
6a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org#define V8_IC_IC_COMPILER_H_
7a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
8a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org#include "src/ic/access-compiler.h"
9a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
10a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.orgnamespace v8 {
11a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.orgnamespace internal {
12a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
13a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
14a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.orgenum IcCheckType { ELEMENT, PROPERTY };
15a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
16a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
17a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.orgclass PropertyICCompiler : public PropertyAccessCompiler {
18a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org public:
19a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  // Finds the Code object stored in the Heap::non_monomorphic_cache().
20a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  static Code* FindPreMonomorphic(Isolate* isolate, Code::Kind kind,
21a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                  ExtraICState extra_ic_state);
22a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
23a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  // Named
24a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  static Handle<Code> ComputeLoad(Isolate* isolate, InlineCacheState ic_state,
25a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                  ExtraICState extra_state);
26a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  static Handle<Code> ComputeStore(Isolate* isolate, InlineCacheState ic_state,
27a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                   ExtraICState extra_state);
28a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
29a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  static Handle<Code> ComputeMonomorphic(Code::Kind kind, Handle<Name> name,
30a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                         Handle<HeapType> type,
31a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                         Handle<Code> handler,
32a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                         ExtraICState extra_ic_state);
33a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  static Handle<Code> ComputePolymorphic(Code::Kind kind, TypeHandleList* types,
34a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                         CodeHandleList* handlers,
35a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                         int number_of_valid_maps,
36a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                         Handle<Name> name,
37a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                         ExtraICState extra_ic_state);
38a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
39a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  // Keyed
40a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  static Handle<Code> ComputeKeyedLoadMonomorphic(Handle<Map> receiver_map);
41a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
42a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  static Handle<Code> ComputeKeyedStoreMonomorphic(
43a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org      Handle<Map> receiver_map, StrictMode strict_mode,
44a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org      KeyedAccessStoreMode store_mode);
45a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  static Handle<Code> ComputeKeyedLoadPolymorphic(MapHandleList* receiver_maps);
46a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  static Handle<Code> ComputeKeyedStorePolymorphic(
47a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org      MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode,
48a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org      StrictMode strict_mode);
49a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
50a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  // Compare nil
51a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  static Handle<Code> ComputeCompareNil(Handle<Map> receiver_map,
52a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                        CompareNilICStub* stub);
53a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
54a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  // Helpers
55a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  // TODO(verwaest): Move all uses of these helpers to the PropertyICCompiler
56a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  // and make the helpers private.
57a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  static void GenerateRuntimeSetProperty(MacroAssembler* masm,
58a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                         StrictMode strict_mode);
59a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
60a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
61a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org private:
62a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  PropertyICCompiler(Isolate* isolate, Code::Kind kind,
63a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                     ExtraICState extra_ic_state = kNoExtraICState,
64a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                     CacheHolderFlag cache_holder = kCacheOnReceiver)
65a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org      : PropertyAccessCompiler(isolate, kind, cache_holder),
66a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org        extra_ic_state_(extra_ic_state) {}
67a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
68a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  static Handle<Code> Find(Handle<Name> name, Handle<Map> stub_holder_map,
69a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                           Code::Kind kind,
70a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                           ExtraICState extra_ic_state = kNoExtraICState,
71a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                           CacheHolderFlag cache_holder = kCacheOnReceiver);
72a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
73a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Handle<Code> CompileLoadInitialize(Code::Flags flags);
74a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Handle<Code> CompileLoadPreMonomorphic(Code::Flags flags);
75a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Handle<Code> CompileStoreInitialize(Code::Flags flags);
76a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Handle<Code> CompileStorePreMonomorphic(Code::Flags flags);
77a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Handle<Code> CompileStoreGeneric(Code::Flags flags);
78a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Handle<Code> CompileStoreMegamorphic(Code::Flags flags);
79a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
80a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Handle<Code> CompileMonomorphic(Handle<HeapType> type, Handle<Code> handler,
81a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                  Handle<Name> name, IcCheckType check);
82a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Handle<Code> CompilePolymorphic(TypeHandleList* types,
83a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                  CodeHandleList* handlers, Handle<Name> name,
84a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                  Code::StubType type, IcCheckType check);
85a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
86a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Handle<Code> CompileKeyedStoreMonomorphic(Handle<Map> receiver_map,
87a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                            KeyedAccessStoreMode store_mode);
88a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Handle<Code> CompileKeyedStorePolymorphic(MapHandleList* receiver_maps,
89a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                            KeyedAccessStoreMode store_mode);
90a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Handle<Code> CompileKeyedStorePolymorphic(MapHandleList* receiver_maps,
91a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                            CodeHandleList* handler_stubs,
92a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                            MapHandleList* transitioned_maps);
93a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
94a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  bool IncludesNumberType(TypeHandleList* types);
95a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
96a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Handle<Code> GetCode(Code::Kind kind, Code::StubType type, Handle<Name> name,
97a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                       InlineCacheState state = MONOMORPHIC);
98a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
99a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  Logger::LogEventsAndTags log_kind(Handle<Code> code) {
100a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org    if (kind() == Code::LOAD_IC) {
101a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org      return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG
102a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                             : Logger::LOAD_POLYMORPHIC_IC_TAG;
103a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org    } else if (kind() == Code::KEYED_LOAD_IC) {
104a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org      return code->ic_state() == MONOMORPHIC
105a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                 ? Logger::KEYED_LOAD_IC_TAG
106a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                 : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG;
107a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org    } else if (kind() == Code::STORE_IC) {
108a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org      return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG
109a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                                             : Logger::STORE_POLYMORPHIC_IC_TAG;
110a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org    } else {
111a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org      DCHECK_EQ(Code::KEYED_STORE_IC, kind());
112a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org      return code->ic_state() == MONOMORPHIC
113a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                 ? Logger::KEYED_STORE_IC_TAG
114a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org                 : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG;
115a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org    }
116a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  }
117a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
118a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org  const ExtraICState extra_ic_state_;
119a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org};
120a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
121a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
122a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org}
123a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org}  // namespace v8::internal
124a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org
125a8702c210b949f35c64d8e4aa01bb6d525086c85machenbach@chromium.org#endif  // V8_IC_IC_COMPILER_H_
126