From a8a844da1c68f84f73ae09dd2f610cf70151c58e Mon Sep 17 00:00:00 2001 From: bmeurer Date: Fri, 19 Jun 2015 07:02:28 -0700 Subject: [PATCH] [turbofan] Preserve Bounds when cloning nodes in the scheduler. R=jarin@chromium.org Review URL: https://codereview.chromium.org/1196613003 Cr-Commit-Position: refs/heads/master@{#29149} --- src/compiler/graph.cc | 8 ++++++++ src/compiler/graph.h | 3 +++ src/compiler/node.cc | 13 ++++++++++++- src/compiler/node.h | 5 +++-- src/compiler/scheduler.cc | 4 +--- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/compiler/graph.cc b/src/compiler/graph.cc index 327fb5853c..00074b5513 100644 --- a/src/compiler/graph.cc +++ b/src/compiler/graph.cc @@ -51,6 +51,14 @@ Node* Graph::NewNode(const Operator* op, int input_count, Node** inputs, } +Node* Graph::CloneNode(const Node* node) { + DCHECK_NOT_NULL(node); + Node* const clone = Node::Clone(zone(), NextNodeId(), node); + Decorate(clone); + return clone; +} + + NodeId Graph::NextNodeId() { NodeId const id = next_node_id_; CHECK(!base::bits::UnsignedAddOverflow32(id, 1, &next_node_id_)); diff --git a/src/compiler/graph.h b/src/compiler/graph.h index 44258feeb2..cb073b312a 100644 --- a/src/compiler/graph.h +++ b/src/compiler/graph.h @@ -80,6 +80,9 @@ class Graph : public ZoneObject { return NewNode(op, arraysize(nodes), nodes); } + // Clone the {node}, and assign a new node id to the copy. + Node* CloneNode(const Node* node); + template inline void VisitNodeInputsFromEnd(Visitor* visitor); diff --git a/src/compiler/node.cc b/src/compiler/node.cc index f38fb95441..e92dccc739 100644 --- a/src/compiler/node.cc +++ b/src/compiler/node.cc @@ -50,7 +50,7 @@ void Node::OutOfLineInputs::ExtractFrom(Use* old_use_ptr, Node** old_input_ptr, Node* Node::New(Zone* zone, NodeId id, const Operator* op, int input_count, - Node** inputs, bool has_extensible_inputs) { + Node* const* inputs, bool has_extensible_inputs) { Node** input_ptr; Use* use_ptr; Node* node; @@ -106,6 +106,17 @@ Node* Node::New(Zone* zone, NodeId id, const Operator* op, int input_count, } +Node* Node::Clone(Zone* zone, NodeId id, const Node* node) { + int const input_count = node->InputCount(); + Node* const* const inputs = node->has_inline_inputs() + ? node->inputs_.inline_ + : node->inputs_.outline_->inputs_; + Node* const clone = New(zone, id, node->op(), input_count, inputs, false); + clone->set_bounds(node->bounds()); + return clone; +} + + void Node::Kill() { DCHECK_NOT_NULL(op()); NullAllInputs(); diff --git a/src/compiler/node.h b/src/compiler/node.h index 08b775c1ff..6557635a2e 100644 --- a/src/compiler/node.h +++ b/src/compiler/node.h @@ -42,7 +42,8 @@ typedef uint32_t NodeId; class Node final { public: static Node* New(Zone* zone, NodeId id, const Operator* op, int input_count, - Node** inputs, bool has_extensible_inputs); + Node* const* inputs, bool has_extensible_inputs); + static Node* Clone(Zone* zone, NodeId id, const Node* node); bool IsDead() const { return InputCount() > 0 && !InputAt(0); } void Kill(); @@ -284,7 +285,7 @@ class Node final { void* operator new(size_t, void* location) { return location; } // Only NodeProperties should manipulate the bounds. - Bounds bounds() { return bounds_; } + Bounds bounds() const { return bounds_; } void set_bounds(Bounds b) { bounds_ = b; } // Only NodeMarkers should manipulate the marks on nodes. diff --git a/src/compiler/scheduler.cc b/src/compiler/scheduler.cc index 862969e752..aa9a7cfdb2 100644 --- a/src/compiler/scheduler.cc +++ b/src/compiler/scheduler.cc @@ -1580,13 +1580,11 @@ class ScheduleLateNodeVisitor { Node* CloneNode(Node* node) { int const input_count = node->InputCount(); - Node** const inputs = scheduler_->zone_->NewArray(input_count); for (int index = 0; index < input_count; ++index) { Node* const input = node->InputAt(index); scheduler_->IncrementUnscheduledUseCount(input, index, node); - inputs[index] = input; } - Node* copy = scheduler_->graph_->NewNode(node->op(), input_count, inputs); + Node* const copy = scheduler_->graph_->CloneNode(node); TRACE(("clone #%d:%s -> #%d\n"), node->id(), node->op()->mnemonic(), copy->id()); scheduler_->node_data_.resize(copy->id() + 1,