common-node-cache.h 2.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_COMPILER_COMMON_NODE_CACHE_H_
#define V8_COMPILER_COMMON_NODE_CACHE_H_

#include "src/compiler/node-cache.h"

namespace v8 {
namespace internal {
12 13 14

// Forward declarations.
class ExternalReference;
15 16 17
class HeapObject;
template <typename>
class Handle;
18 19


20 21 22
namespace compiler {

// Bundles various caches for common nodes.
23
class CommonNodeCache final {
24 25
 public:
  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 34 35 36 37 38
    return int64_constants_.Find(zone(), value);
  }

  Node** FindFloat32Constant(float value) {
    // We canonicalize float constants at the bit representation level.
    return float32_constants_.Find(zone(), bit_cast<int32_t>(value));
39 40
  }

41 42
  Node** FindFloat64Constant(double value) {
    // 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 49 50 51
  Node** FindPointerConstant(intptr_t value) {
    return pointer_constants_.Find(zone(), value);
  }

52 53
  Node** FindNumberConstant(double value) {
    // We canonicalize double constants at the bit representation level.
54
    return number_constants_.Find(zone(), bit_cast<int64_t>(value));
55 56
  }

57 58
  Node** FindHeapConstant(Handle<HeapObject> value);

59 60 61
  Node** FindRelocatableInt32Constant(int32_t value, RelocInfoMode rmode) {
    return relocatable_int32_constants_.Find(zone(),
                                             std::make_pair(value, rmode));
62 63
  }

64 65 66
  Node** FindRelocatableInt64Constant(int64_t value, RelocInfoMode rmode) {
    return relocatable_int64_constants_.Find(zone(),
                                             std::make_pair(value, rmode));
67 68
  }

69 70
  // Return all nodes from the cache.
  void GetCachedNodes(ZoneVector<Node*>* nodes);
71

72
  Zone* zone() const { return zone_; }
73

74 75
 private:
  Int32NodeCache int32_constants_;
76
  Int64NodeCache int64_constants_;
77
  Int32NodeCache float32_constants_;
78
  Int64NodeCache float64_constants_;
79
  IntPtrNodeCache external_constants_;
80
  IntPtrNodeCache pointer_constants_;
81
  Int64NodeCache number_constants_;
82
  IntPtrNodeCache heap_constants_;
83 84
  RelocInt32NodeCache relocatable_int32_constants_;
  RelocInt64NodeCache relocatable_int64_constants_;
85
  Zone* const zone_;
86 87

  DISALLOW_COPY_AND_ASSIGN(CommonNodeCache);
88
};
89 90 91 92

}  // namespace compiler
}  // namespace internal
}  // namespace v8
93 94

#endif  // V8_COMPILER_COMMON_NODE_CACHE_H_