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/functional.h" | 8 #include "src/base/functional.h" |
9 #include "src/base/macros.h" | 9 #include "src/base/macros.h" |
10 #include "src/compiler/node.h" | |
Benedikt Meurer
2014/10/15 12:06:39
Don't add the include here. Just forward declare Z
| |
10 | 11 |
11 namespace v8 { | 12 namespace v8 { |
12 namespace internal { | 13 namespace internal { |
13 | |
14 // Forward declarations. | |
15 class Zone; | |
16 | |
17 | |
18 namespace compiler { | 14 namespace compiler { |
19 | 15 |
20 // Forward declarations. | |
21 class Node; | |
22 | |
23 | |
24 // 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 |
25 // nodes such as constants, parameters, etc. | 17 // nodes such as constants, parameters, etc. |
26 template <typename Key, typename Hash = base::hash<Key>, | 18 template <typename Key, typename Hash = base::hash<Key>, |
27 typename Pred = std::equal_to<Key> > | 19 typename Pred = std::equal_to<Key> > |
28 class NodeCache FINAL { | 20 class NodeCache FINAL { |
29 public: | 21 public: |
30 explicit NodeCache(size_t max = 256) | 22 explicit NodeCache(size_t max = 256) |
31 : entries_(nullptr), size_(0), max_(max) {} | 23 : entries_(nullptr), size_(0), max_(max) {} |
32 | 24 |
33 // Search for node associated with {key} and return a pointer to a memory | 25 // Search for node associated with {key} and return a pointer to a memory |
34 // location in this cache that stores an entry for the key. If the location | 26 // location in this cache that stores an entry for the key. If the location |
35 // returned by this method contains a non-NULL node, the caller can use that | 27 // returned by this method contains a non-NULL node, the caller can use that |
36 // node. Otherwise it is the responsibility of the caller to fill the entry | 28 // node. Otherwise it is the responsibility of the caller to fill the entry |
37 // with a new node. | 29 // with a new node. |
38 // Note that a previous cache entry may be overwritten if the cache becomes | 30 // Note that a previous cache entry may be overwritten if the cache becomes |
39 // too full or encounters too many hash collisions. | 31 // too full or encounters too many hash collisions. |
40 Node** Find(Zone* zone, Key key); | 32 Node** Find(Zone* zone, Key key); |
41 | 33 |
34 void GetCachedNodes(NodeVector* nodes); | |
35 | |
42 private: | 36 private: |
43 enum { kInitialSize = 16u, kLinearProbe = 5u }; | 37 enum { kInitialSize = 16u, kLinearProbe = 5u }; |
44 | 38 |
45 struct Entry; | 39 struct Entry; |
46 | 40 |
47 Entry* entries_; // lazily-allocated hash entries. | 41 Entry* entries_; // lazily-allocated hash entries. |
48 size_t size_; | 42 size_t size_; |
49 size_t max_; | 43 size_t max_; |
50 Hash hash_; | 44 Hash hash_; |
51 Pred pred_; | 45 Pred pred_; |
52 | 46 |
53 bool Resize(Zone* zone); | 47 bool Resize(Zone* zone); |
54 }; | 48 }; |
55 | 49 |
56 // Various default cache types. | 50 // Various default cache types. |
57 typedef NodeCache<int64_t> Int64NodeCache; | 51 typedef NodeCache<int64_t> Int64NodeCache; |
58 typedef NodeCache<int32_t> Int32NodeCache; | 52 typedef NodeCache<int32_t> Int32NodeCache; |
59 typedef NodeCache<void*> PtrNodeCache; | 53 typedef NodeCache<void*> PtrNodeCache; |
60 | 54 |
61 } // namespace compiler | 55 } // namespace compiler |
62 } // namespace internal | 56 } // namespace internal |
63 } // namespace v8 | 57 } // namespace v8 |
64 | 58 |
65 #endif // V8_COMPILER_NODE_CACHE_H_ | 59 #endif // V8_COMPILER_NODE_CACHE_H_ |
OLD | NEW |