• 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 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   // Keyed
25   static Handle<Code> ComputeKeyedLoadMonomorphicHandler(
26       Handle<Map> receiver_map, ExtraICState extra_ic_state);
27 
28   static Handle<Code> ComputeKeyedStoreMonomorphicHandler(
29       Handle<Map> receiver_map, LanguageMode language_mode,
30       KeyedAccessStoreMode store_mode);
31   static void ComputeKeyedStorePolymorphicHandlers(
32       MapHandleList* receiver_maps, MapHandleList* transitioned_maps,
33       CodeHandleList* handlers, KeyedAccessStoreMode store_mode,
34       LanguageMode language_mode);
35 
36   // Compare nil
37   static Handle<Code> ComputeCompareNil(Handle<Map> receiver_map,
38                                         CompareNilICStub* stub);
39 
40   // Helpers
41   // TODO(verwaest): Move all uses of these helpers to the PropertyICCompiler
42   // and make the helpers private.
43   static void GenerateRuntimeSetProperty(MacroAssembler* masm,
44                                          LanguageMode language_mode);
45 
46 
47  private:
48   PropertyICCompiler(Isolate* isolate, Code::Kind kind,
49                      ExtraICState extra_ic_state = kNoExtraICState,
50                      CacheHolderFlag cache_holder = kCacheOnReceiver)
PropertyAccessCompiler(isolate,kind,cache_holder)51       : PropertyAccessCompiler(isolate, kind, cache_holder),
52         extra_ic_state_(extra_ic_state) {}
53 
54   static Handle<Code> Find(Handle<Name> name, Handle<Map> stub_holder_map,
55                            Code::Kind kind,
56                            ExtraICState extra_ic_state = kNoExtraICState,
57                            CacheHolderFlag cache_holder = kCacheOnReceiver);
58 
59   Handle<Code> CompileLoadInitialize(Code::Flags flags);
60   Handle<Code> CompileStoreInitialize(Code::Flags flags);
61   Handle<Code> CompileStorePreMonomorphic(Code::Flags flags);
62   Handle<Code> CompileStoreGeneric(Code::Flags flags);
63   Handle<Code> CompileStoreMegamorphic(Code::Flags flags);
64 
65   Handle<Code> CompileKeyedStoreMonomorphicHandler(
66       Handle<Map> receiver_map, KeyedAccessStoreMode store_mode);
67   Handle<Code> CompileKeyedStoreMonomorphic(Handle<Map> receiver_map,
68                                             KeyedAccessStoreMode store_mode);
69   void CompileKeyedStorePolymorphicHandlers(MapHandleList* receiver_maps,
70                                             MapHandleList* transitioned_maps,
71                                             CodeHandleList* handlers,
72                                             KeyedAccessStoreMode store_mode);
73 
74   bool IncludesNumberMap(MapHandleList* maps);
75 
76   Handle<Code> GetCode(Code::Kind kind, Code::StubType type, Handle<Name> name,
77                        InlineCacheState state = MONOMORPHIC);
78 
log_kind(Handle<Code> code)79   Logger::LogEventsAndTags log_kind(Handle<Code> code) {
80     if (kind() == Code::LOAD_IC) {
81       return code->ic_state() == MONOMORPHIC ? Logger::LOAD_IC_TAG
82                                              : Logger::LOAD_POLYMORPHIC_IC_TAG;
83     } else if (kind() == Code::KEYED_LOAD_IC) {
84       return code->ic_state() == MONOMORPHIC
85                  ? Logger::KEYED_LOAD_IC_TAG
86                  : Logger::KEYED_LOAD_POLYMORPHIC_IC_TAG;
87     } else if (kind() == Code::STORE_IC) {
88       return code->ic_state() == MONOMORPHIC ? Logger::STORE_IC_TAG
89                                              : Logger::STORE_POLYMORPHIC_IC_TAG;
90     } else {
91       DCHECK_EQ(Code::KEYED_STORE_IC, kind());
92       return code->ic_state() == MONOMORPHIC
93                  ? Logger::KEYED_STORE_IC_TAG
94                  : Logger::KEYED_STORE_POLYMORPHIC_IC_TAG;
95     }
96   }
97 
98   const ExtraICState extra_ic_state_;
99 };
100 
101 
102 }  // namespace internal
103 }  // namespace v8
104 
105 #endif  // V8_IC_IC_COMPILER_H_
106