1 // Copyright 2014 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_IC_IC_COMPILER_H_
6 #define V8_IC_IC_COMPILER_H_
8 #include "src/ic/access-compiler.h"
14 enum IcCheckType { ELEMENT, PROPERTY };
17 class PropertyICCompiler : public PropertyAccessCompiler {
19 // Finds the Code object stored in the Heap::non_monomorphic_cache().
20 static Code* FindPreMonomorphic(Isolate* isolate, Code::Kind kind,
21 ExtraICState extra_ic_state);
24 static Handle<Code> ComputeLoad(Isolate* isolate, InlineCacheState ic_state,
25 ExtraICState extra_state);
26 static Handle<Code> ComputeStore(Isolate* isolate, InlineCacheState ic_state,
27 ExtraICState extra_state);
29 static Handle<Code> ComputeMonomorphic(Code::Kind kind, Handle<Name> name,
30 Handle<HeapType> type,
32 ExtraICState extra_ic_state);
33 static Handle<Code> ComputePolymorphic(Code::Kind kind, TypeHandleList* types,
34 CodeHandleList* handlers,
35 int number_of_valid_maps,
37 ExtraICState extra_ic_state);
40 static Handle<Code> ComputeKeyedLoadMonomorphic(Handle<Map> receiver_map);
42 static Handle<Code> ComputeKeyedStoreMonomorphic(
43 Handle<Map> receiver_map, StrictMode strict_mode,
44 KeyedAccessStoreMode store_mode);
45 static Handle<Code> ComputeKeyedLoadPolymorphic(MapHandleList* receiver_maps);
46 static Handle<Code> ComputeKeyedStorePolymorphic(
47 MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode,
48 StrictMode strict_mode);
51 static Handle<Code> ComputeCompareNil(Handle<Map> receiver_map,
52 CompareNilICStub* stub);
55 // TODO(verwaest): Move all uses of these helpers to the PropertyICCompiler
56 // and make the helpers private.
57 static void GenerateRuntimeSetProperty(MacroAssembler* masm,
58 StrictMode strict_mode);
62 PropertyICCompiler(Isolate* isolate, Code::Kind kind,
63 ExtraICState extra_ic_state = kNoExtraICState,
64 CacheHolderFlag cache_holder = kCacheOnReceiver)
65 : PropertyAccessCompiler(isolate, kind, cache_holder),
66 extra_ic_state_(extra_ic_state) {}
68 static Handle<Code> Find(Handle<Name> name, Handle<Map> stub_holder_map,
70 ExtraICState extra_ic_state = kNoExtraICState,
71 CacheHolderFlag cache_holder = kCacheOnReceiver);
73 Handle<Code> CompileLoadInitialize(Code::Flags flags);
74 Handle<Code> CompileLoadPreMonomorphic(Code::Flags flags);
75 Handle<Code> CompileStoreInitialize(Code::Flags flags);
76 Handle<Code> CompileStorePreMonomorphic(Code::Flags flags);
77 Handle<Code> CompileStoreGeneric(Code::Flags flags);
78 Handle<Code> CompileStoreMegamorphic(Code::Flags flags);
80 Handle<Code> CompileMonomorphic(Handle<HeapType> type, Handle<Code> handler,
81 Handle<Name> name, IcCheckType check);
82 Handle<Code> CompilePolymorphic(TypeHandleList* types,
83 CodeHandleList* handlers, Handle<Name> name,
84 Code::StubType type, IcCheckType check);
86 Handle<Code> CompileKeyedStoreMonomorphic(Handle<Map> receiver_map,
87 KeyedAccessStoreMode store_mode);
88 Handle<Code> CompileKeyedStorePolymorphic(MapHandleList* receiver_maps,
89 KeyedAccessStoreMode store_mode);
90 Handle<Code> CompileKeyedStorePolymorphic(MapHandleList* receiver_maps,
91 CodeHandleList* handler_stubs,
92 MapHandleList* transitioned_maps);
94 bool IncludesNumberType(TypeHandleList* types);
96 Handle<Code> GetCode(Code::Kind kind, Code::StubType type, Handle<Name> name,
97 InlineCacheState state = MONOMORPHIC);
99 Logger::LogEventsAndTags log_kind(Handle<Code> code) {
100 if (kind() == Code::LOAD_IC) {
101 return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG
102 : Logger::LOAD_POLYMORPHIC_IC_TAG;
103 } else if (kind() == Code::KEYED_LOAD_IC) {
104 return code->ic_state() == MONOMORPHIC
105 ? Logger::KEYED_LOAD_IC_TAG
106 : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG;
107 } else if (kind() == Code::STORE_IC) {
108 return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG
109 : Logger::STORE_POLYMORPHIC_IC_TAG;
111 DCHECK_EQ(Code::KEYED_STORE_IC, kind());
112 return code->ic_state() == MONOMORPHIC
113 ? Logger::KEYED_STORE_IC_TAG
114 : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG;
118 const ExtraICState extra_ic_state_;
123 } // namespace v8::internal
125 #endif // V8_IC_IC_COMPILER_H_