Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/compiler/node-cache.h" |
| 9 | |
| 10 | namespace v8 { |
| 11 | namespace internal { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 12 | |
| 13 | // Forward declarations. |
| 14 | class ExternalReference; |
| 15 | |
| 16 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 17 | namespace compiler { |
| 18 | |
| 19 | // Bundles various caches for common nodes. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 20 | class CommonNodeCache FINAL { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 21 | public: |
| 22 | explicit CommonNodeCache(Zone* zone) : zone_(zone) {} |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 23 | ~CommonNodeCache() {} |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 24 | |
| 25 | Node** FindInt32Constant(int32_t value) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 26 | return int32_constants_.Find(zone(), value); |
| 27 | } |
| 28 | |
| 29 | Node** FindInt64Constant(int64_t value) { |
| 30 | return int64_constants_.Find(zone(), value); |
| 31 | } |
| 32 | |
| 33 | Node** FindFloat32Constant(float value) { |
| 34 | // We canonicalize float constants at the bit representation level. |
| 35 | return float32_constants_.Find(zone(), bit_cast<int32_t>(value)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | Node** FindFloat64Constant(double value) { |
| 39 | // We canonicalize double constants at the bit representation level. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 40 | return float64_constants_.Find(zone(), bit_cast<int64_t>(value)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 43 | Node** FindExternalConstant(ExternalReference value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 44 | |
| 45 | Node** FindNumberConstant(double value) { |
| 46 | // We canonicalize double constants at the bit representation level. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 47 | return number_constants_.Find(zone(), bit_cast<int64_t>(value)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 50 | // Return all nodes from the cache. |
| 51 | void GetCachedNodes(ZoneVector<Node*>* nodes); |
| 52 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 53 | Zone* zone() const { return zone_; } |
| 54 | |
| 55 | private: |
| 56 | Int32NodeCache int32_constants_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 57 | Int64NodeCache int64_constants_; |
| 58 | Int32NodeCache float32_constants_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 59 | Int64NodeCache float64_constants_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 60 | IntPtrNodeCache external_constants_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 61 | Int64NodeCache number_constants_; |
| 62 | Zone* zone_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 63 | |
| 64 | DISALLOW_COPY_AND_ASSIGN(CommonNodeCache); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 65 | }; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 66 | |
| 67 | } // namespace compiler |
| 68 | } // namespace internal |
| 69 | } // namespace v8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 70 | |
| 71 | #endif // V8_COMPILER_COMMON_NODE_CACHE_H_ |