[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
src/compiler
test
@ -24,7 +24,7 @@ Int64Lowering::Int64Lowering(Graph* graph, MachineOperatorBuilder* machine,
|
||||
graph_(graph),
|
||||
machine_(machine),
|
||||
common_(common),
|
||||
state_(graph, 4),
|
||||
state_(graph, 3),
|
||||
stack_(zone),
|
||||
replacements_(zone->NewArray<Replacement>(graph->NodeCount())),
|
||||
signature_(signature) {
|
||||
@ -35,25 +35,23 @@ void Int64Lowering::LowerGraph() {
|
||||
if (!machine()->Is32()) {
|
||||
return;
|
||||
}
|
||||
stack_.push(graph()->end());
|
||||
stack_.push({graph()->end(), 0});
|
||||
state_.Set(graph()->end(), State::kOnStack);
|
||||
|
||||
while (!stack_.empty()) {
|
||||
Node* top = stack_.top();
|
||||
if (state_.Get(top) == State::kInputsPushed) {
|
||||
NodeState& top = stack_.top();
|
||||
if (top.input_index == top.node->InputCount()) {
|
||||
// All inputs of top have already been lowered, now lower top.
|
||||
stack_.pop();
|
||||
state_.Set(top, State::kVisited);
|
||||
// All inputs of top have already been reduced, now reduce top.
|
||||
LowerNode(top);
|
||||
state_.Set(top.node, State::kVisited);
|
||||
LowerNode(top.node);
|
||||
} else {
|
||||
// Push all children onto the stack.
|
||||
for (Node* input : top->inputs()) {
|
||||
if (state_.Get(input) == State::kUnvisited) {
|
||||
stack_.push(input);
|
||||
state_.Set(input, State::kOnStack);
|
||||
}
|
||||
// Push the next input onto the stack.
|
||||
Node* input = top.node->InputAt(top.input_index++);
|
||||
if (state_.Get(input) == State::kUnvisited) {
|
||||
stack_.push({input, 0});
|
||||
state_.Set(input, State::kOnStack);
|
||||
}
|
||||
state_.Set(top, State::kInputsPushed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class Int64Lowering {
|
||||
void LowerGraph();
|
||||
|
||||
private:
|
||||
enum class State : uint8_t { kUnvisited, kOnStack, kInputsPushed, kVisited };
|
||||
enum class State : uint8_t { kUnvisited, kOnStack, kVisited };
|
||||
|
||||
struct Replacement {
|
||||
Node* low;
|
||||
@ -48,12 +48,17 @@ class Int64Lowering {
|
||||
bool HasReplacementHigh(Node* node);
|
||||
Node* GetReplacementHigh(Node* node);
|
||||
|
||||
struct NodeState {
|
||||
Node* node;
|
||||
int input_index;
|
||||
};
|
||||
|
||||
Zone* zone_;
|
||||
Graph* const graph_;
|
||||
MachineOperatorBuilder* machine_;
|
||||
CommonOperatorBuilder* common_;
|
||||
NodeMarker<State> state_;
|
||||
ZoneStack<Node*> stack_;
|
||||
ZoneStack<NodeState> stack_;
|
||||
Replacement* replacements_;
|
||||
Signature<MachineRepresentation>* signature_;
|
||||
};
|
||||
|
@ -30,7 +30,7 @@
|
||||
#endif
|
||||
|
||||
#define FOREACH_I64_OPERATOR(V) \
|
||||
V(DepthFirst, false) \
|
||||
V(DepthFirst, true) \
|
||||
V(I64Const, true) \
|
||||
V(I64Return, true) \
|
||||
V(I64Param, true) \
|
||||
|
@ -494,6 +494,24 @@ TEST_F(Int64LoweringTest, I64UConvertI32_2) {
|
||||
// kExprI64Clz:
|
||||
// kExprI64Ctz:
|
||||
// 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 internal
|
||||
} // namespace v8
|
||||
|
Loading…
Reference in New Issue
Block a user