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.
5 #ifndef V8_COMPILER_NODE_CACHE_H_
6 #define V8_COMPILER_NODE_CACHE_H_
10 #include "src/compiler/node.h"
16 // A cache for nodes based on a key. Useful for implementing canonicalization of
17 // nodes such as constants, parameters, etc.
18 template <typename Key>
21 explicit NodeCache(int max = 256) : entries_(NULL), size_(0), max_(max) {}
23 // Search for node associated with {key} and return a pointer to a memory
24 // location in this cache that stores an entry for the key. If the location
25 // returned by this method contains a non-NULL node, the caller can use that
26 // node. Otherwise it is the responsibility of the caller to fill the entry
28 // Note that a previous cache entry may be overwritten if the cache becomes
29 // too full or encounters too many hash collisions.
30 Node** Find(Zone* zone, Key key);
38 Entry* entries_; // lazily-allocated hash entries.
42 bool Resize(Zone* zone);
45 // Various default cache types.
46 typedef NodeCache<int64_t> Int64NodeCache;
47 typedef NodeCache<int32_t> Int32NodeCache;
48 typedef NodeCache<void*> PtrNodeCache;
51 } // namespace v8::internal::compiler
53 #endif // V8_COMPILER_NODE_CACHE_H_