OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_NODE_CACHE_H_ | 5 #ifndef V8_COMPILER_NODE_CACHE_H_ |
6 #define V8_COMPILER_NODE_CACHE_H_ | 6 #define V8_COMPILER_NODE_CACHE_H_ |
7 | 7 |
8 #include "src/base/macros.h" | 8 #include "src/v8.h" |
| 9 |
| 10 #include "src/compiler/node.h" |
9 | 11 |
10 namespace v8 { | 12 namespace v8 { |
11 namespace internal { | 13 namespace internal { |
12 | |
13 // Forward declarations. | |
14 class Zone; | |
15 | |
16 namespace compiler { | 14 namespace compiler { |
17 | 15 |
18 // Forward declarations. | |
19 class Node; | |
20 | |
21 // A cache for nodes based on a key. Useful for implementing canonicalization of | 16 // A cache for nodes based on a key. Useful for implementing canonicalization of |
22 // nodes such as constants, parameters, etc. | 17 // nodes such as constants, parameters, etc. |
23 template <typename Key> | 18 template <typename Key> |
24 class NodeCache { | 19 class NodeCache { |
25 public: | 20 public: |
26 explicit NodeCache(int max = 256) : entries_(NULL), size_(0), max_(max) {} | 21 explicit NodeCache(int max = 256) : entries_(NULL), size_(0), max_(max) {} |
27 | 22 |
28 // Search for node associated with {key} and return a pointer to a memory | 23 // Search for node associated with {key} and return a pointer to a memory |
29 // location in this cache that stores an entry for the key. If the location | 24 // location in this cache that stores an entry for the key. If the location |
30 // returned by this method contains a non-NULL node, the caller can use that | 25 // returned by this method contains a non-NULL node, the caller can use that |
31 // node. Otherwise it is the responsibility of the caller to fill the entry | 26 // node. Otherwise it is the responsibility of the caller to fill the entry |
32 // with a new node. | 27 // with a new node. |
33 // Note that a previous cache entry may be overwritten if the cache becomes | 28 // Note that a previous cache entry may be overwritten if the cache becomes |
34 // too full or encounters too many hash collisions. | 29 // too full or encounters too many hash collisions. |
35 Node** Find(Zone* zone, Key key); | 30 Node** Find(Zone* zone, Key key); |
36 | 31 |
37 private: | 32 private: |
38 struct Entry { | 33 struct Entry { |
39 Key key_; | 34 Key key_; |
40 Node* value_; | 35 Node* value_; |
41 }; | 36 }; |
42 | 37 |
43 Entry* entries_; // lazily-allocated hash entries. | 38 Entry* entries_; // lazily-allocated hash entries. |
44 int size_; | 39 int32_t size_; |
45 int max_; | 40 int32_t max_; |
46 | 41 |
47 bool Resize(Zone* zone); | 42 bool Resize(Zone* zone); |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(NodeCache); | |
50 }; | 43 }; |
51 | 44 |
52 // Various default cache types. | 45 // Various default cache types. |
| 46 typedef NodeCache<int64_t> Int64NodeCache; |
53 typedef NodeCache<int32_t> Int32NodeCache; | 47 typedef NodeCache<int32_t> Int32NodeCache; |
54 typedef NodeCache<int64_t> Int64NodeCache; | 48 typedef NodeCache<void*> PtrNodeCache; |
55 typedef NodeCache<intptr_t> IntPtrNodeCache; | 49 } |
56 | 50 } |
57 } // namespace compiler | 51 } // namespace v8::internal::compiler |
58 } // namespace internal | |
59 } // namespace v8 | |
60 | 52 |
61 #endif // V8_COMPILER_NODE_CACHE_H_ | 53 #endif // V8_COMPILER_NODE_CACHE_H_ |
OLD | NEW |