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_COMMON_NODE_CACHE_H_
6#define V8_COMPILER_COMMON_NODE_CACHE_H_
7
8#include "src/compiler/node-cache.h"
9
10namespace v8 {
11namespace internal {
12
13// Forward declarations.
14class ExternalReference;
15class HeapObject;
16template <typename>
17class Handle;
18
19
20namespace compiler {
21
22// Bundles various caches for common nodes.
23class CommonNodeCache final {
24 public:
25  explicit CommonNodeCache(Zone* zone)
26      : int32_constants_(zone),
27        int64_constants_(zone),
28        tagged_index_constants_(zone),
29        float32_constants_(zone),
30        float64_constants_(zone),
31        external_constants_(zone),
32        pointer_constants_(zone),
33        number_constants_(zone),
34        heap_constants_(zone),
35        relocatable_int32_constants_(zone),
36        relocatable_int64_constants_(zone) {}
37  ~CommonNodeCache() = default;
38
39  CommonNodeCache(const CommonNodeCache&) = delete;
40  CommonNodeCache& operator=(const CommonNodeCache&) = delete;
41
42  Node** FindInt32Constant(int32_t value) {
43    return int32_constants_.Find(value);
44  }
45
46  Node** FindInt64Constant(int64_t value) {
47    return int64_constants_.Find(value);
48  }
49
50  Node** FindTaggedIndexConstant(int32_t value) {
51    return tagged_index_constants_.Find(value);
52  }
53
54  Node** FindFloat32Constant(float value) {
55    // We canonicalize float constants at the bit representation level.
56    return float32_constants_.Find(bit_cast<int32_t>(value));
57  }
58
59  Node** FindFloat64Constant(double value) {
60    // We canonicalize double constants at the bit representation level.
61    return float64_constants_.Find(bit_cast<int64_t>(value));
62  }
63
64  Node** FindExternalConstant(ExternalReference value);
65
66  Node** FindPointerConstant(intptr_t value) {
67    return pointer_constants_.Find(value);
68  }
69
70  Node** FindNumberConstant(double value) {
71    // We canonicalize double constants at the bit representation level.
72    return number_constants_.Find(bit_cast<int64_t>(value));
73  }
74
75  Node** FindHeapConstant(Handle<HeapObject> value);
76
77  Node** FindRelocatableInt32Constant(int32_t value, RelocInfoMode rmode) {
78    return relocatable_int32_constants_.Find(std::make_pair(value, rmode));
79  }
80
81  Node** FindRelocatableInt64Constant(int64_t value, RelocInfoMode rmode) {
82    return relocatable_int64_constants_.Find(std::make_pair(value, rmode));
83  }
84
85  // Return all nodes from the cache.
86  void GetCachedNodes(ZoneVector<Node*>* nodes);
87
88 private:
89  Int32NodeCache int32_constants_;
90  Int64NodeCache int64_constants_;
91  Int32NodeCache tagged_index_constants_;
92  Int32NodeCache float32_constants_;
93  Int64NodeCache float64_constants_;
94  IntPtrNodeCache external_constants_;
95  IntPtrNodeCache pointer_constants_;
96  Int64NodeCache number_constants_;
97  IntPtrNodeCache heap_constants_;
98  RelocInt32NodeCache relocatable_int32_constants_;
99  RelocInt64NodeCache relocatable_int64_constants_;
100};
101
102}  // namespace compiler
103}  // namespace internal
104}  // namespace v8
105
106#endif  // V8_COMPILER_COMMON_NODE_CACHE_H_
107