common-node-cache.h 3.05 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
 public:
25 26 27 28 29 30 31 32 33 34 35 36
  explicit CommonNodeCache(Zone* zone)
      : int32_constants_(zone),
        int64_constants_(zone),
        tagged_index_constants_(zone),
        float32_constants_(zone),
        float64_constants_(zone),
        external_constants_(zone),
        pointer_constants_(zone),
        number_constants_(zone),
        heap_constants_(zone),
        relocatable_int32_constants_(zone),
        relocatable_int64_constants_(zone) {}
37
  ~CommonNodeCache() = default;
38

39 40 41
  CommonNodeCache(const CommonNodeCache&) = delete;
  CommonNodeCache& operator=(const CommonNodeCache&) = delete;

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 55
  Node** FindFloat32Constant(float value) {
    // We canonicalize float constants at the bit representation level.
56
    return float32_constants_.Find(bit_cast<int32_t>(value));
57 58
  }

59 60
  Node** FindFloat64Constant(double value) {
    // 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 71
  Node** FindNumberConstant(double value) {
    // We canonicalize double constants at the bit representation level.
72
    return number_constants_.Find(bit_cast<int64_t>(value));
73 74
  }

75 76
  Node** FindHeapConstant(Handle<HeapObject> value);

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 86
  // Return all nodes from the cache.
  void GetCachedNodes(ZoneVector<Node*>* nodes);
87 88 89

 private:
  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 99
  RelocInt32NodeCache relocatable_int32_constants_;
  RelocInt64NodeCache relocatable_int64_constants_;
100
};
101 102 103 104

}  // namespace compiler
}  // namespace internal
}  // namespace v8
105 106

#endif  // V8_COMPILER_COMMON_NODE_CACHE_H_