5#ifndef V8_COMPILER_CONTROL_PATH_STATE_H_
6#define V8_COMPILER_CONTROL_PATH_STATE_H_
30template <
typename NodeState, NodeUniqueness node_uniqueness>
34 std::is_member_function_pointer<
decltype(&NodeState::IsSet)>
::value,
35 "{NodeState} needs an {IsSet} method");
37 std::is_member_object_pointer<
decltype(&NodeState::node)>
::value,
38 "{NodeState} needs to hold a pointer to the {Node*} owner of the state");
60 return blocks_ == other.blocks_;
63 return blocks_ != other.blocks_;
69 size_t depth(
size_t depth_if_multiple_instances) {
75 bool BlocksAndStatesInvariant();
86template <
typename NodeState, NodeUniqueness node_uniqueness>
106 Node* additional_node, NodeState additional_state,
bool in_new_block);
124template <
typename NodeState, NodeUniqueness node_uniqueness>
128 for (
size_t depth =
blocks_.Size(); depth > 0; depth--) {
129 NodeState state = states_.Get({
node, depth});
130 if (state.IsSet())
return state;
135template <
typename NodeState, NodeUniqueness node_uniqueness>
137 Zone* zone,
Node* node, NodeState state,
139 NodeState previous_state = LookupState(node);
141 : previous_state == state) {
152 blocks_.PushFront(prev_front, zone);
157template <
typename NodeState, NodeUniqueness node_uniqueness>
159 Zone* zone,
Node* node, NodeState state) {
161 NodeState previous_state = LookupState(node);
163 : previous_state != state) {
167 blocks_.PushFront(new_block, zone);
171template <
typename NodeState, NodeUniqueness node_uniqueness>
174 while (other.blocks_.Size() >
blocks_.Size()) other.blocks_.DropFront();
175 while (
blocks_.Size() > other.blocks_.Size()) {
176 for (NodeState state :
blocks_.Front()) {
177 states_.Set({state.node, depth(
blocks_.Size())}, {});
181 while (
blocks_ != other.blocks_) {
182 for (NodeState state :
blocks_.Front()) {
183 states_.Set({state.node, depth(
blocks_.Size())}, {});
186 other.blocks_.DropFront();
192template <
typename NodeState, NodeUniqueness node_uniqueness>
195 size_t current_depth =
blocks_.Size();
197 std::unordered_set<Node*> seen_this_block;
198 for (NodeState state : block) {
200 if (seen_this_block.count(state.node) == 0) {
201 if (states_copy.Get({state.node, depth(current_depth)}) != state) {
204 states_copy.Set({state.node, depth(current_depth)}, {});
205 seen_this_block.emplace(state.node);
213 return states_copy.begin() == states_copy.end();
217template <
typename NodeState, NodeUniqueness node_uniqueness>
218Reduction AdvancedReducerWithControlPathState<
219 NodeState, node_uniqueness>::TakeStatesFromFirstControl(
Node* node) {
223 if (!reduced_.Get(input))
return NoChange();
224 return UpdateStates(node, node_states_.Get(input));
227template <
typename NodeState, NodeUniqueness node_uniqueness>
232 bool reduced_changed = reduced_.Set(state_owner,
true);
233 bool node_states_changed = node_states_.Set(state_owner, new_state);
234 if (reduced_changed || node_states_changed) {
235 return Changed(state_owner);
240template <
typename NodeState, NodeUniqueness node_uniqueness>
244 Node* additional_node, NodeState additional_state,
bool in_new_block) {
245 if (in_new_block || prev_states.
IsEmpty()) {
249 node_states_.Get(state_owner);
250 prev_states.
AddState(
zone_, additional_node, additional_state, original);
252 return UpdateStates(state_owner, prev_states);
#define SLOW_DCHECK(condition)
Reduction UpdateStates(Node *state_owner, ControlPathState< NodeState, node_uniqueness > new_state)
AdvancedReducerWithControlPathState(Editor *editor, Zone *zone, TFGraph *graph)
bool IsReduced(Node *node)
NodeAuxData< bool > reduced_
ControlPathState< NodeState, node_uniqueness > GetState(Node *node)
Reduction UpdateStates(Node *state_owner, ControlPathState< NodeState, node_uniqueness > prev_states, Node *additional_node, NodeState additional_state, bool in_new_block)
NodeAuxData< ControlPathState< NodeState, node_uniqueness >, ZoneConstruct< ControlPathState< NodeState, node_uniqueness > > > node_states_
Reduction TakeStatesFromFirstControl(Node *node)
bool operator==(const ControlPathState &other) const
ControlPathState(Zone *zone)
bool operator!=(const ControlPathState &other) const
void ResetToCommonAncestor(ControlPathState other)
NodeState LookupState(Node *node) const
size_t depth(size_t depth_if_multiple_instances)
FunctionalList< FunctionalList< NodeState > > blocks_
void AddState(Zone *zone, Node *node, NodeState state, ControlPathState hint)
void AddStateInNewBlock(Zone *zone, Node *node, NodeState state)
PersistentMap< NodeWithPathDepth, NodeState > states_
std::pair< Node *, size_t > NodeWithPathDepth
void PushFront(A a, Zone *zone)
static Node * GetControlInput(Node *node, int index=0)
LiftoffAssembler::CacheState state
T ZoneConstruct(Zone *zone)
std::vector< std::vector< ValueType > > blocks_