v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
state-values-utils.h
Go to the documentation of this file.
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.
4
5#ifndef V8_COMPILER_STATE_VALUES_UTILS_H_
6#define V8_COMPILER_STATE_VALUES_UTILS_H_
7
8#include <array>
9
13
14namespace v8 {
15namespace internal {
16
17class BitVector;
18
19namespace compiler {
20
21class TFGraph;
22class BytecodeLivenessState;
23
25 public:
26 explicit StateValuesCache(JSGraph* js_graph);
27
28 Node* GetNodeForValues(Node** values, size_t count,
29 const BytecodeLivenessState* liveness = nullptr);
30
31 private:
32 static const size_t kMaxInputCount = 8;
33 using WorkingBuffer = std::array<Node*, kMaxInputCount>;
34
35 struct NodeKey {
37
38 explicit NodeKey(Node* node) : node(node) {}
39 };
40
41 struct StateValuesKey : public NodeKey {
42 // ValueArray - array of nodes ({node} has to be nullptr).
43 size_t count;
46
48 : NodeKey(nullptr), count(count), mask(mask), values(values) {}
49 };
50
51 static bool AreKeysEqual(void* key1, void* key2);
52 static bool IsKeysEqualToNode(StateValuesKey* key, Node* node);
53 static bool AreValueKeysEqual(StateValuesKey* key1, StateValuesKey* key2);
54
55 // Fills {node_buffer}, starting from {node_count}, with {values}, starting
56 // at {values_idx}, sparsely encoding according to {liveness}. {node_count} is
57 // updated with the new number of inputs in {node_buffer}, and a bitmask of
58 // the sparse encoding is returned.
59 SparseInputMask::BitMaskType FillBufferWithValues(
60 WorkingBuffer* node_buffer, size_t* node_count, size_t* values_idx,
61 Node** values, size_t count, const BytecodeLivenessState* liveness);
62
63 Node* BuildTree(size_t* values_idx, Node** values, size_t count,
64 const BytecodeLivenessState* liveness, size_t level);
65
66 WorkingBuffer* GetWorkingSpace(size_t level);
67 Node* GetEmptyStateValues();
68 Node* GetValuesNodeFromCache(Node** nodes, size_t count,
70
71 TFGraph* graph() { return js_graph_->graph(); }
72 CommonOperatorBuilder* common() { return js_graph_->common(); }
73
74 Zone* zone() { return graph()->zone(); }
75
78 ZoneVector<WorkingBuffer> working_space_; // One working space per level.
80};
81
83 public:
84 struct TypedNode {
87 TypedNode(Node* node, MachineType type) : node(node), type(type) {}
88 };
89
91 public:
92 bool operator!=(iterator const& other) const;
94 TypedNode operator*();
95
96 Node* node();
97 bool done() const { return current_depth_ < 0; }
98
99 // Returns the number of empty nodes that were skipped over.
100 size_t AdvanceTillNotEmpty();
101
102 private:
103 friend class StateValuesAccess;
104
105 iterator() : current_depth_(-1) {}
106 explicit iterator(Node* node);
107
109 void Advance();
110 void EnsureValid();
111
113 void Push(Node* node);
114 void Pop();
115
116 static const int kMaxInlineDepth = 8;
117 SparseInputMask::InputIterator stack_[kMaxInlineDepth];
119 };
120
121 explicit StateValuesAccess(Node* node) : node_(node) {}
122
123 size_t size() const;
124 iterator begin() const { return iterator(node_); }
126 return ++begin(); // Skip the receiver.
127 }
129 iterator it = begin_without_receiver();
130 while (n_skips > 0 && !it.done()) {
131 ++it;
132 --n_skips;
133 }
134 return it;
135 }
136 iterator end() const { return iterator(); }
137
138 private:
140};
141
142} // namespace compiler
143} // namespace internal
144} // namespace v8
145
146#endif // V8_COMPILER_STATE_VALUES_UTILS_H_
TFGraph * graph
ZoneVector< WorkingBuffer > working_space_
std::array< Node *, kMaxInputCount > WorkingBuffer
Node * node
uint32_t const mask
Node::Uses::const_iterator begin(const Node::Uses &uses)
Definition node.h:708
bool operator!=(ExternalReference lhs, ExternalReference rhs)
V8_INLINE Builtin operator++(Builtin &builtin)
Definition builtins.h:80
Node * node_
#define V8_EXPORT_PRIVATE
Definition macros.h:460
StateValuesKey(size_t count, SparseInputMask mask, Node **values)
std::unique_ptr< ValueMirror > key
wasm::ValueType type