#ifndef V8_COMPILER_NODE_CACHE_H_
#define V8_COMPILER_NODE_CACHE_H_
#include "src/base/export-template.h"
#include "src/base/hashing.h"
#include "src/base/macros.h"
#include "src/zone/zone-containers.h"
namespace v8 {
namespace internal {
class Zone;
template <typename>
class ZoneVector;
namespace compiler {
class Node;
template <typename Key, typename Hash = base::hash<Key>,
typename Pred = std::equal_to<Key> >
class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) NodeCache final {
public:
explicit NodeCache(Zone* zone) : map_(zone) {}
~NodeCache() = default;
NodeCache(const NodeCache&) = delete;
NodeCache& operator=(const NodeCache&) = delete;
Node** Find(Key key) { return &(map_[key]); }
void GetCachedNodes(ZoneVector<Node*>* nodes) {
for (const auto& entry : map_) {
if (entry.second) nodes->push_back(entry.second);
}
}
private:
ZoneUnorderedMap<Key, Node*, Hash, Pred> map_;
};
using Int32NodeCache = NodeCache<int32_t>;
using Int64NodeCache = NodeCache<int64_t>;
using RelocInfoMode = char;
using RelocInt32Key = std::pair<int32_t, RelocInfoMode>;
using RelocInt64Key = std::pair<int64_t, RelocInfoMode>;
using RelocInt32NodeCache = NodeCache<RelocInt32Key>;
using RelocInt64NodeCache = NodeCache<RelocInt64Key>;
#if V8_HOST_ARCH_32_BIT
using IntPtrNodeCache = Int32NodeCache;
#else
using IntPtrNodeCache = Int64NodeCache;
#endif
}
}
}
#endif