Commit 76178f1d authored by titzer's avatar titzer Committed by Commit bot

[turbofan] Avoid repeatedly revisiting inputs in GraphReducer.

R=mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/753073009

Cr-Commit-Position: refs/heads/master@{#25551}
parent 34702e9d
......@@ -99,11 +99,22 @@ Reduction GraphReducer::Reduce(Node* const node) {
void GraphReducer::ReduceTop() {
Node* const node = Top();
NodeState& entry = stack_.top();
Node* node = entry.node;
DCHECK(state_[node->id()] == State::kOnStack);
if (node->IsDead()) return Pop(); // Node was killed while on stack.
// Recurse on an input if necessary.
for (auto const input : node->inputs()) {
int start = entry.input_index < node->InputCount() ? entry.input_index : 0;
for (int i = start; i < node->InputCount(); i++) {
Node* input = node->InputAt(i);
entry.input_index = i + 1;
if (input != node && Recurse(input)) return;
}
for (int i = 0; i < start; i++) {
Node* input = node->InputAt(i);
entry.input_index = i + 1;
if (input != node && Recurse(input)) return;
}
......@@ -153,7 +164,7 @@ void GraphReducer::ReduceTop() {
void GraphReducer::Pop() {
Node* const node = Top();
Node* const node = stack_.top().node;
state_[node->id()] = State::kVisited;
stack_.pop();
}
......@@ -165,18 +176,7 @@ void GraphReducer::Push(Node* const node) {
DCHECK(id < state_.size());
DCHECK(state_[id] != State::kOnStack);
state_[id] = State::kOnStack;
stack_.push(node);
}
Node* GraphReducer::Top() const {
DCHECK(!stack_.empty());
Node* const node = stack_.top();
size_t const id = static_cast<size_t>(node->id());
DCHECK(id < state_.size());
DCHECK(state_[id] == State::kOnStack);
USE(id);
return node;
stack_.push({node, 0});
}
......
......@@ -68,6 +68,10 @@ class GraphReducer FINAL {
private:
enum class State : uint8_t;
struct NodeState {
Node* node;
int input_index;
};
// Reduce a single node.
Reduction Reduce(Node* const);
......@@ -77,7 +81,6 @@ class GraphReducer FINAL {
// Node stack operations.
void Pop();
void Push(Node* const);
Node* Top() const;
// Revisit queue operations.
bool Recurse(Node* const);
......@@ -86,7 +89,7 @@ class GraphReducer FINAL {
Graph* graph_;
ZoneVector<Reducer*> reducers_;
ZoneStack<Node*> revisit_;
ZoneStack<Node*> stack_;
ZoneStack<NodeState> stack_;
ZoneDeque<State> state_;
DISALLOW_COPY_AND_ASSIGN(GraphReducer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment