blob: cee0c4e837c6c4706c7fb03368534deb554bbd45 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/compiler/node-cache.h"
9
10namespace v8 {
11namespace internal {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040012
13// Forward declarations.
14class ExternalReference;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000015class HeapObject;
16template <typename>
17class Handle;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040018
19
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020namespace compiler {
21
22// Bundles various caches for common nodes.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000023class CommonNodeCache final {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000024 public:
25 explicit CommonNodeCache(Zone* zone) : zone_(zone) {}
Emily Bernierd0a1eb72015-03-24 16:35:39 -040026 ~CommonNodeCache() {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027
28 Node** FindInt32Constant(int32_t value) {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040029 return int32_constants_.Find(zone(), value);
30 }
31
32 Node** FindInt64Constant(int64_t value) {
33 return int64_constants_.Find(zone(), value);
34 }
35
36 Node** FindFloat32Constant(float value) {
37 // We canonicalize float constants at the bit representation level.
38 return float32_constants_.Find(zone(), bit_cast<int32_t>(value));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000039 }
40
41 Node** FindFloat64Constant(double value) {
42 // We canonicalize double constants at the bit representation level.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040043 return float64_constants_.Find(zone(), bit_cast<int64_t>(value));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000044 }
45
Emily Bernierd0a1eb72015-03-24 16:35:39 -040046 Node** FindExternalConstant(ExternalReference value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000047
48 Node** FindNumberConstant(double value) {
49 // We canonicalize double constants at the bit representation level.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040050 return number_constants_.Find(zone(), bit_cast<int64_t>(value));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000051 }
52
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000053 Node** FindHeapConstant(Handle<HeapObject> value);
54
Ben Murdochc5610432016-08-08 18:44:38 +010055 Node** FindRelocatableInt32Constant(int32_t value) {
56 return relocatable_int32_constants_.Find(zone(), value);
57 }
58
59 Node** FindRelocatableInt64Constant(int64_t value) {
60 return relocatable_int64_constants_.Find(zone(), value);
61 }
62
Emily Bernierd0a1eb72015-03-24 16:35:39 -040063 // Return all nodes from the cache.
64 void GetCachedNodes(ZoneVector<Node*>* nodes);
65
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066 Zone* zone() const { return zone_; }
67
68 private:
69 Int32NodeCache int32_constants_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040070 Int64NodeCache int64_constants_;
71 Int32NodeCache float32_constants_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000072 Int64NodeCache float64_constants_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040073 IntPtrNodeCache external_constants_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000074 Int64NodeCache number_constants_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000075 IntPtrNodeCache heap_constants_;
Ben Murdochc5610432016-08-08 18:44:38 +010076 Int32NodeCache relocatable_int32_constants_;
77 Int64NodeCache relocatable_int64_constants_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000078 Zone* const zone_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040079
80 DISALLOW_COPY_AND_ASSIGN(CommonNodeCache);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000081};
Emily Bernierd0a1eb72015-03-24 16:35:39 -040082
83} // namespace compiler
84} // namespace internal
85} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +000086
87#endif // V8_COMPILER_COMMON_NODE_CACHE_H_