[wasm] Int64Lowering: changing to DFS.
R=titzer@chromium.org Review URL: https://codereview.chromium.org/1798993002 Cr-Commit-Position: refs/heads/master@{#34767}
This commit is contained in:
parent
8d7399f9f8
commit
c4c34eba30
@ -24,7 +24,7 @@ Int64Lowering::Int64Lowering(Graph* graph, MachineOperatorBuilder* machine,
|
|||||||
graph_(graph),
|
graph_(graph),
|
||||||
machine_(machine),
|
machine_(machine),
|
||||||
common_(common),
|
common_(common),
|
||||||
state_(graph, 4),
|
state_(graph, 3),
|
||||||
stack_(zone),
|
stack_(zone),
|
||||||
replacements_(zone->NewArray<Replacement>(graph->NodeCount())),
|
replacements_(zone->NewArray<Replacement>(graph->NodeCount())),
|
||||||
signature_(signature) {
|
signature_(signature) {
|
||||||
@ -35,25 +35,23 @@ void Int64Lowering::LowerGraph() {
|
|||||||
if (!machine()->Is32()) {
|
if (!machine()->Is32()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
stack_.push(graph()->end());
|
stack_.push({graph()->end(), 0});
|
||||||
state_.Set(graph()->end(), State::kOnStack);
|
state_.Set(graph()->end(), State::kOnStack);
|
||||||
|
|
||||||
while (!stack_.empty()) {
|
while (!stack_.empty()) {
|
||||||
Node* top = stack_.top();
|
NodeState& top = stack_.top();
|
||||||
if (state_.Get(top) == State::kInputsPushed) {
|
if (top.input_index == top.node->InputCount()) {
|
||||||
|
// All inputs of top have already been lowered, now lower top.
|
||||||
stack_.pop();
|
stack_.pop();
|
||||||
state_.Set(top, State::kVisited);
|
state_.Set(top.node, State::kVisited);
|
||||||
// All inputs of top have already been reduced, now reduce top.
|
LowerNode(top.node);
|
||||||
LowerNode(top);
|
|
||||||
} else {
|
} else {
|
||||||
// Push all children onto the stack.
|
// Push the next input onto the stack.
|
||||||
for (Node* input : top->inputs()) {
|
Node* input = top.node->InputAt(top.input_index++);
|
||||||
if (state_.Get(input) == State::kUnvisited) {
|
if (state_.Get(input) == State::kUnvisited) {
|
||||||
stack_.push(input);
|
stack_.push({input, 0});
|
||||||
state_.Set(input, State::kOnStack);
|
state_.Set(input, State::kOnStack);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
state_.Set(top, State::kInputsPushed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class Int64Lowering {
|
|||||||
void LowerGraph();
|
void LowerGraph();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class State : uint8_t { kUnvisited, kOnStack, kInputsPushed, kVisited };
|
enum class State : uint8_t { kUnvisited, kOnStack, kVisited };
|
||||||
|
|
||||||
struct Replacement {
|
struct Replacement {
|
||||||
Node* low;
|
Node* low;
|
||||||
@ -48,12 +48,17 @@ class Int64Lowering {
|
|||||||
bool HasReplacementHigh(Node* node);
|
bool HasReplacementHigh(Node* node);
|
||||||
Node* GetReplacementHigh(Node* node);
|
Node* GetReplacementHigh(Node* node);
|
||||||
|
|
||||||
|
struct NodeState {
|
||||||
|
Node* node;
|
||||||
|
int input_index;
|
||||||
|
};
|
||||||
|
|
||||||
Zone* zone_;
|
Zone* zone_;
|
||||||
Graph* const graph_;
|
Graph* const graph_;
|
||||||
MachineOperatorBuilder* machine_;
|
MachineOperatorBuilder* machine_;
|
||||||
CommonOperatorBuilder* common_;
|
CommonOperatorBuilder* common_;
|
||||||
NodeMarker<State> state_;
|
NodeMarker<State> state_;
|
||||||
ZoneStack<Node*> stack_;
|
ZoneStack<NodeState> stack_;
|
||||||
Replacement* replacements_;
|
Replacement* replacements_;
|
||||||
Signature<MachineRepresentation>* signature_;
|
Signature<MachineRepresentation>* signature_;
|
||||||
};
|
};
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FOREACH_I64_OPERATOR(V) \
|
#define FOREACH_I64_OPERATOR(V) \
|
||||||
V(DepthFirst, false) \
|
V(DepthFirst, true) \
|
||||||
V(I64Const, true) \
|
V(I64Const, true) \
|
||||||
V(I64Return, true) \
|
V(I64Return, true) \
|
||||||
V(I64Param, true) \
|
V(I64Param, true) \
|
||||||
|
@ -494,6 +494,24 @@ TEST_F(Int64LoweringTest, I64UConvertI32_2) {
|
|||||||
// kExprI64Clz:
|
// kExprI64Clz:
|
||||||
// kExprI64Ctz:
|
// kExprI64Ctz:
|
||||||
// kExprI64Popcnt:
|
// kExprI64Popcnt:
|
||||||
|
|
||||||
|
TEST_F(Int64LoweringTest, Dfs) {
|
||||||
|
Node* common = Int64Constant(value(0));
|
||||||
|
LowerGraph(graph()->NewNode(machine()->Word64And(), common,
|
||||||
|
graph()->NewNode(machine()->Word64And(), common,
|
||||||
|
Int64Constant(value(1)))),
|
||||||
|
MachineRepresentation::kWord64);
|
||||||
|
|
||||||
|
EXPECT_THAT(
|
||||||
|
graph()->end()->InputAt(1),
|
||||||
|
IsReturn2(IsWord32And(IsInt32Constant(low_word_value(0)),
|
||||||
|
IsWord32And(IsInt32Constant(low_word_value(0)),
|
||||||
|
IsInt32Constant(low_word_value(1)))),
|
||||||
|
IsWord32And(IsInt32Constant(high_word_value(0)),
|
||||||
|
IsWord32And(IsInt32Constant(high_word_value(0)),
|
||||||
|
IsInt32Constant(high_word_value(1)))),
|
||||||
|
start(), start()));
|
||||||
|
}
|
||||||
} // namespace compiler
|
} // namespace compiler
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace v8
|
} // namespace v8
|
||||||
|
Loading…
Reference in New Issue
Block a user