v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
node-cache.h
Go to the documentation of this file.
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_COMPILER_NODE_CACHE_H_
6#define V8_COMPILER_NODE_CACHE_H_
7
9#include "src/base/hashing.h"
10#include "src/base/macros.h"
12
13namespace v8 {
14namespace internal {
15
16// Forward declarations.
17class Zone;
18template <typename>
19class ZoneVector;
20
21
22namespace compiler {
23
24// Forward declarations.
25class Node;
26
27
28// A cache for nodes based on a key. Useful for implementing canonicalization of
29// nodes such as constants, parameters, etc.
30template <typename Key, typename Hash = base::hash<Key>,
31 typename Pred = std::equal_to<Key> >
32class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) NodeCache final {
33 public:
34 explicit NodeCache(Zone* zone) : map_(zone) {}
35 ~NodeCache() = default;
36 NodeCache(const NodeCache&) = delete;
37 NodeCache& operator=(const NodeCache&) = delete;
38
39 // Search for node associated with {key} and return a pointer to a memory
40 // location in this cache that stores an entry for the key. If the location
41 // returned by this method contains a non-nullptr node, the caller can use
42 // that node. Otherwise it is the responsibility of the caller to fill the
43 // entry with a new node.
44 Node** Find(Key key) { return &(map_[key]); }
45
46 // Appends all nodes from this cache to {nodes}.
47 void GetCachedNodes(ZoneVector<Node*>* nodes) {
48 for (const auto& entry : map_) {
49 if (entry.second) nodes->push_back(entry.second);
50 }
51 }
52
53 private:
55};
56
57// Various default cache types.
58using Int32NodeCache = NodeCache<int32_t>;
59using Int64NodeCache = NodeCache<int64_t>;
60
61// All we want is the numeric value of the RelocInfo::Mode enum. We typedef
62// below to avoid pulling in assembler.h
63using RelocInfoMode = char;
64using RelocInt32Key = std::pair<int32_t, RelocInfoMode>;
65using RelocInt64Key = std::pair<int64_t, RelocInfoMode>;
66using RelocInt32NodeCache = NodeCache<RelocInt32Key>;
67using RelocInt64NodeCache = NodeCache<RelocInt64Key>;
68#if V8_HOST_ARCH_32_BIT
70#else
72#endif
73
74} // namespace compiler
75} // namespace internal
76} // namespace v8
77
78#endif // V8_COMPILER_NODE_CACHE_H_
const MapRef map_
std::pair< int32_t, RelocInfoMode > RelocInt32Key
Definition node-cache.h:64
std::pair< int64_t, RelocInfoMode > RelocInt64Key
Definition node-cache.h:65
NodeCache< RelocInt64Key > RelocInt64NodeCache
Definition node-cache.h:67
NodeCache< int64_t > Int64NodeCache
Definition node-cache.h:59
Int64NodeCache IntPtrNodeCache
Definition node-cache.h:71
NodeCache< int32_t > Int32NodeCache
Definition node-cache.h:58
NodeCache< RelocInt32Key > RelocInt32NodeCache
Definition node-cache.h:66
std::unique_ptr< ValueMirror > key