Home | History | Annotate | Download | only in compiler
      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 
     10 namespace v8 {
     11 namespace internal {
     12 
     13 // Forward declarations.
     14 class ExternalReference;
     15 class HeapObject;
     16 template <typename>
     17 class Handle;
     18 
     19 
     20 namespace compiler {
     21 
     22 // Bundles various caches for common nodes.
     23 class CommonNodeCache final {
     24  public:
     25   explicit CommonNodeCache(Zone* zone) : zone_(zone) {}
     26   ~CommonNodeCache() {}
     27 
     28   Node** FindInt32Constant(int32_t value) {
     29     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));
     39   }
     40 
     41   Node** FindFloat64Constant(double value) {
     42     // We canonicalize double constants at the bit representation level.
     43     return float64_constants_.Find(zone(), bit_cast<int64_t>(value));
     44   }
     45 
     46   Node** FindExternalConstant(ExternalReference value);
     47 
     48   Node** FindNumberConstant(double value) {
     49     // We canonicalize double constants at the bit representation level.
     50     return number_constants_.Find(zone(), bit_cast<int64_t>(value));
     51   }
     52 
     53   Node** FindHeapConstant(Handle<HeapObject> value);
     54 
     55   // Return all nodes from the cache.
     56   void GetCachedNodes(ZoneVector<Node*>* nodes);
     57 
     58   Zone* zone() const { return zone_; }
     59 
     60  private:
     61   Int32NodeCache int32_constants_;
     62   Int64NodeCache int64_constants_;
     63   Int32NodeCache float32_constants_;
     64   Int64NodeCache float64_constants_;
     65   IntPtrNodeCache external_constants_;
     66   Int64NodeCache number_constants_;
     67   IntPtrNodeCache heap_constants_;
     68   Zone* const zone_;
     69 
     70   DISALLOW_COPY_AND_ASSIGN(CommonNodeCache);
     71 };
     72 
     73 }  // namespace compiler
     74 }  // namespace internal
     75 }  // namespace v8
     76 
     77 #endif  // V8_COMPILER_COMMON_NODE_CACHE_H_
     78