• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 enum IcCheckType { ELEMENT, PROPERTY };
15 
16 
17 class PropertyICCompiler : public PropertyAccessCompiler {
18  public:
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);
22 
23   // Named
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);
28 
29   static Handle<Code> ComputeMonomorphic(Code::Kind kind, Handle<Name> name,
30                                          Handle<HeapType> type,
31                                          Handle<Code> handler,
32                                          ExtraICState extra_ic_state);
33   static Handle<Code> ComputePolymorphic(Code::Kind kind, TypeHandleList* types,
34                                          CodeHandleList* handlers,
35                                          int number_of_valid_maps,
36                                          Handle<Name> name,
37                                          ExtraICState extra_ic_state);
38 
39   // Keyed
40   static Handle<Code> ComputeKeyedLoadMonomorphic(Handle<Map> receiver_map);
41 
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);
49 
50   // Compare nil
51   static Handle<Code> ComputeCompareNil(Handle<Map> receiver_map,
52                                         CompareNilICStub* stub);
53 
54   // Helpers
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);
59 
60 
61  private:
62   PropertyICCompiler(Isolate* isolate, Code::Kind kind,
63                      ExtraICState extra_ic_state = kNoExtraICState,
64                      CacheHolderFlag cache_holder = kCacheOnReceiver)
PropertyAccessCompiler(isolate,kind,cache_holder)65       : PropertyAccessCompiler(isolate, kind, cache_holder),
66         extra_ic_state_(extra_ic_state) {}
67 
68   static Handle<Code> Find(Handle<Name> name, Handle<Map> stub_holder_map,
69                            Code::Kind kind,
70                            ExtraICState extra_ic_state = kNoExtraICState,
71                            CacheHolderFlag cache_holder = kCacheOnReceiver);
72 
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);
79 
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);
85 
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);
93 
94   bool IncludesNumberType(TypeHandleList* types);
95 
96   Handle<Code> GetCode(Code::Kind kind, Code::StubType type, Handle<Name> name,
97                        InlineCacheState state = MONOMORPHIC);
98 
log_kind(Handle<Code> code)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;
110     } else {
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;
115     }
116   }
117 
118   const ExtraICState extra_ic_state_;
119 };
120 
121 
122 }
123 }  // namespace v8::internal
124 
125 #endif  // V8_IC_IC_COMPILER_H_
126