[strong] Implement strong property access semantics
[platform/upstream/v8.git] / src / ic / ic-compiler.h
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.
4
5 #ifndef V8_IC_IC_COMPILER_H_
6 #define V8_IC_IC_COMPILER_H_
7
8 #include "src/ic/access-compiler.h"
9
10 namespace v8 {
11 namespace internal {
12
13
14 class PropertyICCompiler : public PropertyAccessCompiler {
15  public:
16   // Finds the Code object stored in the Heap::non_monomorphic_cache().
17   static Code* FindPreMonomorphic(Isolate* isolate, Code::Kind kind,
18                                   ExtraICState extra_ic_state);
19
20   // Named
21   static Handle<Code> ComputeStore(Isolate* isolate, InlineCacheState ic_state,
22                                    ExtraICState extra_state);
23
24   static Handle<Code> ComputeMonomorphic(Code::Kind kind, Handle<Name> name,
25                                          Handle<Map> map, Handle<Code> handler,
26                                          ExtraICState extra_ic_state);
27   static Handle<Code> ComputePolymorphic(Code::Kind kind, MapHandleList* maps,
28                                          CodeHandleList* handlers,
29                                          int number_of_valid_maps,
30                                          Handle<Name> name,
31                                          ExtraICState extra_ic_state);
32
33   // Keyed
34   static Handle<Code> ComputeKeyedLoadMonomorphicHandler(
35       Handle<Map> receiver_map, ExtraICState extra_ic_state);
36
37   static Handle<Code> ComputeKeyedStoreMonomorphic(
38       Handle<Map> receiver_map, LanguageMode language_mode,
39       KeyedAccessStoreMode store_mode);
40   static Handle<Code> ComputeKeyedLoadPolymorphic(MapHandleList* receiver_maps,
41                                                   LanguageMode language_mode);
42   static Handle<Code> ComputeKeyedStorePolymorphic(
43       MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode,
44       LanguageMode language_mode);
45
46   // Compare nil
47   static Handle<Code> ComputeCompareNil(Handle<Map> receiver_map,
48                                         CompareNilICStub* stub);
49
50   // Helpers
51   // TODO(verwaest): Move all uses of these helpers to the PropertyICCompiler
52   // and make the helpers private.
53   static void GenerateRuntimeSetProperty(MacroAssembler* masm,
54                                          LanguageMode language_mode);
55
56
57  private:
58   PropertyICCompiler(Isolate* isolate, Code::Kind kind,
59                      ExtraICState extra_ic_state = kNoExtraICState,
60                      CacheHolderFlag cache_holder = kCacheOnReceiver)
61       : PropertyAccessCompiler(isolate, kind, cache_holder),
62         extra_ic_state_(extra_ic_state) {}
63
64   static Handle<Code> Find(Handle<Name> name, Handle<Map> stub_holder_map,
65                            Code::Kind kind,
66                            ExtraICState extra_ic_state = kNoExtraICState,
67                            CacheHolderFlag cache_holder = kCacheOnReceiver);
68
69   Handle<Code> CompileLoadInitialize(Code::Flags flags);
70   Handle<Code> CompileStoreInitialize(Code::Flags flags);
71   Handle<Code> CompileStorePreMonomorphic(Code::Flags flags);
72   Handle<Code> CompileStoreGeneric(Code::Flags flags);
73   Handle<Code> CompileStoreMegamorphic(Code::Flags flags);
74
75   Handle<Code> CompileMonomorphic(Handle<Map> map, Handle<Code> handler,
76                                   Handle<Name> name, IcCheckType check);
77   Handle<Code> CompilePolymorphic(MapHandleList* maps, CodeHandleList* handlers,
78                                   Handle<Name> name, Code::StubType type,
79                                   IcCheckType check);
80
81   Handle<Code> CompileKeyedStoreMonomorphic(Handle<Map> receiver_map,
82                                             KeyedAccessStoreMode store_mode);
83   Handle<Code> CompileKeyedStorePolymorphic(MapHandleList* receiver_maps,
84                                             KeyedAccessStoreMode store_mode);
85   Handle<Code> CompileKeyedStorePolymorphic(MapHandleList* receiver_maps,
86                                             CodeHandleList* handler_stubs,
87                                             MapHandleList* transitioned_maps);
88
89   bool IncludesNumberMap(MapHandleList* maps);
90
91   Handle<Code> GetCode(Code::Kind kind, Code::StubType type, Handle<Name> name,
92                        InlineCacheState state = MONOMORPHIC);
93
94   Logger::LogEventsAndTags log_kind(Handle<Code> code) {
95     if (kind() == Code::LOAD_IC) {
96       return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG
97                                              : Logger::LOAD_POLYMORPHIC_IC_TAG;
98     } else if (kind() == Code::KEYED_LOAD_IC) {
99       return code->ic_state() == MONOMORPHIC
100                  ? Logger::KEYED_LOAD_IC_TAG
101                  : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG;
102     } else if (kind() == Code::STORE_IC) {
103       return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG
104                                              : Logger::STORE_POLYMORPHIC_IC_TAG;
105     } else {
106       DCHECK_EQ(Code::KEYED_STORE_IC, kind());
107       return code->ic_state() == MONOMORPHIC
108                  ? Logger::KEYED_STORE_IC_TAG
109                  : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG;
110     }
111   }
112
113   const ExtraICState extra_ic_state_;
114 };
115
116
117 }
118 }  // namespace v8::internal
119
120 #endif  // V8_IC_IC_COMPILER_H_