1 // Copyright 2015 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.
5 #ifndef V8_COMPILER_STATE_VALUES_UTILS_H_
6 #define V8_COMPILER_STATE_VALUES_UTILS_H_
8 #include "src/compiler/js-graph.h"
17 class StateValuesCache {
19 explicit StateValuesCache(JSGraph* js_graph);
21 Node* GetNodeForValues(Node** values, size_t count);
24 static const size_t kMaxInputCount = 8;
29 explicit NodeKey(Node* node) : node(node) {}
32 struct StateValuesKey : public NodeKey {
33 // ValueArray - array of nodes ({node} has to be nullptr).
37 StateValuesKey(size_t count, Node** values)
38 : NodeKey(nullptr), count(count), values(values) {}
41 class ValueArrayIterator;
43 static bool AreKeysEqual(void* key1, void* key2);
44 static bool IsKeysEqualToNode(StateValuesKey* key, Node* node);
45 static bool AreValueKeysEqual(StateValuesKey* key1, StateValuesKey* key2);
47 Node* BuildTree(ValueArrayIterator* it, size_t max_height);
48 NodeVector* GetWorkingSpace(size_t level);
49 Node* GetEmptyStateValues();
50 Node* GetValuesNodeFromCache(Node** nodes, size_t count);
52 Graph* graph() { return js_graph_->graph(); }
53 CommonOperatorBuilder* common() { return js_graph_->common(); }
55 Zone* zone() { return graph()->zone(); }
58 ZoneHashMap hash_map_;
59 ZoneVector<NodeVector*> working_space_; // One working space per level.
60 Node* empty_state_values_;
63 class StateValuesAccess {
68 TypedNode(Node* node, MachineType type) : node(node), type(type) {}
73 // Bare minimum of operators needed for range iteration.
74 bool operator!=(iterator& other);
75 iterator& operator++();
76 TypedNode operator*();
79 friend class StateValuesAccess;
81 iterator() : current_depth_(-1) {}
82 explicit iterator(Node* node);
93 explicit StatePos(Node* node) : node(node), index(0) {}
98 void Push(Node* node);
101 static const int kMaxInlineDepth = 8;
102 StatePos stack_[kMaxInlineDepth];
106 explicit StateValuesAccess(Node* node) : node_(node) {}
109 iterator begin() { return iterator(node_); }
110 iterator end() { return iterator(); }
116 } // namespace compiler
117 } // namespace internal
120 #endif // V8_COMPILER_STATE_VALUES_UTILS_H_