Commit f6e5bc16 authored by danno's avatar danno Committed by Commit bot

Clean up node iteration

- Create a first-class Edge type.
- Separate node and edge iterators
- Make iterators only responsible for iteration
- Make it possible to modify the use edge iterator while iterating.
- Add the ability to update inputs to Edges directly.

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

Cr-Commit-Position: refs/heads/master@{#25616}
parent 2ac522ab
...@@ -199,9 +199,9 @@ namespace { ...@@ -199,9 +199,9 @@ namespace {
bool CanCover(Node* value, IrOpcode::Value opcode) { bool CanCover(Node* value, IrOpcode::Value opcode) {
if (value->opcode() != opcode) return false; if (value->opcode() != opcode) return false;
bool first = true; bool first = true;
for (auto i = value->uses().begin(); i != value->uses().end(); ++i) { for (Edge const edge : value->use_edges()) {
if (NodeProperties::IsEffectEdge(i.edge())) continue; if (NodeProperties::IsEffectEdge(edge)) continue;
DCHECK(NodeProperties::IsValueEdge(i.edge())); DCHECK(NodeProperties::IsValueEdge(edge));
if (!first) return false; if (!first) return false;
first = false; first = false;
} }
...@@ -236,11 +236,9 @@ Reduction ChangeLowering::ChangeTaggedToFloat64(Node* value, Node* control) { ...@@ -236,11 +236,9 @@ Reduction ChangeLowering::ChangeTaggedToFloat64(Node* value, Node* control) {
Node* phi1 = d1.Phi(kMachFloat64, phi2, ChangeSmiToFloat64(object)); Node* phi1 = d1.Phi(kMachFloat64, phi2, ChangeSmiToFloat64(object));
Node* ephi1 = d1.EffectPhi(number, effect); Node* ephi1 = d1.EffectPhi(number, effect);
for (auto i = value->uses().begin(); i != value->uses().end();) { for (Edge edge : value->use_edges()) {
if (NodeProperties::IsEffectEdge(i.edge())) { if (NodeProperties::IsEffectEdge(edge)) {
i.UpdateToAndIncrement(ephi1); edge.UpdateTo(ephi1);
} else {
++i;
} }
} }
return Replace(phi1); return Replace(phi1);
......
...@@ -237,14 +237,13 @@ class ControlReducerImpl { ...@@ -237,14 +237,13 @@ class ControlReducerImpl {
// Remove dead->live edges. // Remove dead->live edges.
for (size_t j = 0; j < nodes.size(); j++) { for (size_t j = 0; j < nodes.size(); j++) {
Node* node = nodes[j]; Node* node = nodes[j];
for (UseIter i = node->uses().begin(); i != node->uses().end();) { for (Edge edge : node->use_edges()) {
if (!marked.IsReachableFromEnd(*i)) { Node* use = edge.from();
TRACE(("DeadLink: #%d:%s(%d) -> #%d:%s\n", (*i)->id(), if (!marked.IsReachableFromEnd(use)) {
(*i)->op()->mnemonic(), i.index(), node->id(), TRACE(("DeadLink: #%d:%s(%d) -> #%d:%s\n", use->id(),
use->op()->mnemonic(), edge.index(), node->id(),
node->op()->mnemonic())); node->op()->mnemonic()));
i.UpdateToAndIncrement(NULL); edge.UpdateTo(NULL);
} else {
++i;
} }
} }
} }
...@@ -473,18 +472,16 @@ class ControlReducerImpl { ...@@ -473,18 +472,16 @@ class ControlReducerImpl {
// Replace IfTrue and IfFalse projections from this branch. // Replace IfTrue and IfFalse projections from this branch.
Node* control = NodeProperties::GetControlInput(node); Node* control = NodeProperties::GetControlInput(node);
for (UseIter i = node->uses().begin(); i != node->uses().end();) { for (Edge edge : node->use_edges()) {
Node* to = *i; Node* use = edge.from();
if (to->opcode() == IrOpcode::kIfTrue) { if (use->opcode() == IrOpcode::kIfTrue) {
TRACE((" IfTrue: #%d:%s\n", to->id(), to->op()->mnemonic())); TRACE((" IfTrue: #%d:%s\n", use->id(), use->op()->mnemonic()));
i.UpdateToAndIncrement(NULL); edge.UpdateTo(NULL);
ReplaceNode(to, (result == kTrue) ? control : dead()); ReplaceNode(use, (result == kTrue) ? control : dead());
} else if (to->opcode() == IrOpcode::kIfFalse) { } else if (use->opcode() == IrOpcode::kIfFalse) {
TRACE((" IfFalse: #%d:%s\n", to->id(), to->op()->mnemonic())); TRACE((" IfFalse: #%d:%s\n", use->id(), use->op()->mnemonic()));
i.UpdateToAndIncrement(NULL); edge.UpdateTo(NULL);
ReplaceNode(to, (result == kTrue) ? dead() : control); ReplaceNode(use, (result == kTrue) ? dead() : control);
} else {
++i;
} }
} }
return control; return control;
......
...@@ -19,13 +19,13 @@ template <class N> ...@@ -19,13 +19,13 @@ template <class N>
class NodeInputIterationTraits { class NodeInputIterationTraits {
public: public:
typedef N Node; typedef N Node;
typedef typename N::Inputs::iterator Iterator; typedef typename N::InputEdges::iterator Iterator;
static Iterator begin(Node* node) { return node->inputs().begin(); } static Iterator begin(Node* node) { return node->input_edges().begin(); }
static Iterator end(Node* node) { return node->inputs().end(); } static Iterator end(Node* node) { return node->input_edges().end(); }
static int max_id(Graph* graph) { return graph->NodeCount(); } static int max_id(Graph* graph) { return graph->NodeCount(); }
static Node* to(Iterator iterator) { return *iterator; } static Node* to(Iterator iterator) { return (*iterator).to(); }
static Node* from(Iterator iterator) { return iterator.edge().from(); } static Node* from(Iterator iterator) { return (*iterator).from(); }
}; };
} // namespace compiler } // namespace compiler
......
...@@ -70,13 +70,13 @@ class GenericGraphVisit { ...@@ -70,13 +70,13 @@ class GenericGraphVisit {
post_order_node = Traits::from(stack.top().first); post_order_node = Traits::from(stack.top().first);
visit = true; visit = true;
} else { } else {
visitor->PreEdge(Traits::from(top.first), top.first.edge().index(), visitor->PreEdge(Traits::from(top.first), (*top.first).index(),
Traits::to(top.first)); Traits::to(top.first));
current = Traits::to(top.first); current = Traits::to(top.first);
if (!GetVisited(&visited, current->id())) break; if (!GetVisited(&visited, current->id())) break;
} }
top = stack.top(); top = stack.top();
visitor->PostEdge(Traits::from(top.first), top.first.edge().index(), visitor->PostEdge(Traits::from(top.first), (*top.first).index(),
Traits::to(top.first)); Traits::to(top.first));
++stack.top().first; ++stack.top().first;
} }
......
...@@ -228,7 +228,7 @@ class GraphVisualizer { ...@@ -228,7 +228,7 @@ class GraphVisualizer {
void PrintNode(Node* node, bool gray); void PrintNode(Node* node, bool gray);
private: private:
void PrintEdge(Node::Edge edge); void PrintEdge(Edge edge);
AllNodes all_; AllNodes all_;
std::ostream& os_; std::ostream& os_;
...@@ -285,26 +285,26 @@ void GraphVisualizer::PrintNode(Node* node, bool gray) { ...@@ -285,26 +285,26 @@ void GraphVisualizer::PrintNode(Node* node, bool gray) {
label << *node->op(); label << *node->op();
os_ << " label=\"{{#" << SafeId(node) << ":" << Escaped(label); os_ << " label=\"{{#" << SafeId(node) << ":" << Escaped(label);
InputIter i = node->inputs().begin(); auto i = node->input_edges().begin();
for (int j = node->op()->ValueInputCount(); j > 0; ++i, j--) { for (int j = node->op()->ValueInputCount(); j > 0; ++i, j--) {
os_ << "|<I" << i.index() << ">#" << SafeId(*i); os_ << "|<I" << (*i).index() << ">#" << SafeId((*i).to());
} }
for (int j = OperatorProperties::GetContextInputCount(node->op()); j > 0; for (int j = OperatorProperties::GetContextInputCount(node->op()); j > 0;
++i, j--) { ++i, j--) {
os_ << "|<I" << i.index() << ">X #" << SafeId(*i); os_ << "|<I" << (*i).index() << ">X #" << SafeId((*i).to());
} }
for (int j = OperatorProperties::GetFrameStateInputCount(node->op()); j > 0; for (int j = OperatorProperties::GetFrameStateInputCount(node->op()); j > 0;
++i, j--) { ++i, j--) {
os_ << "|<I" << i.index() << ">F #" << SafeId(*i); os_ << "|<I" << (*i).index() << ">F #" << SafeId((*i).to());
} }
for (int j = node->op()->EffectInputCount(); j > 0; ++i, j--) { for (int j = node->op()->EffectInputCount(); j > 0; ++i, j--) {
os_ << "|<I" << i.index() << ">E #" << SafeId(*i); os_ << "|<I" << (*i).index() << ">E #" << SafeId((*i).to());
} }
if (OperatorProperties::IsBasicBlockBegin(node->op()) || if (OperatorProperties::IsBasicBlockBegin(node->op()) ||
GetControlCluster(node) == NULL) { GetControlCluster(node) == NULL) {
for (int j = node->op()->ControlInputCount(); j > 0; ++i, j--) { for (int j = node->op()->ControlInputCount(); j > 0; ++i, j--) {
os_ << "|<I" << i.index() << ">C #" << SafeId(*i); os_ << "|<I" << (*i).index() << ">C #" << SafeId((*i).to());
} }
} }
os_ << "}"; os_ << "}";
...@@ -338,7 +338,7 @@ static bool IsLikelyBackEdge(Node* from, int index, Node* to) { ...@@ -338,7 +338,7 @@ static bool IsLikelyBackEdge(Node* from, int index, Node* to) {
} }
void GraphVisualizer::PrintEdge(Node::Edge edge) { void GraphVisualizer::PrintEdge(Edge edge) {
Node* from = edge.from(); Node* from = edge.from();
int index = edge.index(); int index = edge.index();
Node* to = edge.to(); Node* to = edge.to();
...@@ -382,8 +382,8 @@ void GraphVisualizer::Print() { ...@@ -382,8 +382,8 @@ void GraphVisualizer::Print() {
// With all the nodes written, add the edges. // With all the nodes written, add the edges.
for (Node* const node : all_.live) { for (Node* const node : all_.live) {
for (UseIter i = node->uses().begin(); i != node->uses().end(); ++i) { for (Edge edge : node->use_edges()) {
PrintEdge(i.edge()); PrintEdge(edge);
} }
} }
os_ << "}\n"; os_ << "}\n";
...@@ -531,7 +531,7 @@ void GraphC1Visualizer::PrintInputs(InputIter* i, int count, ...@@ -531,7 +531,7 @@ void GraphC1Visualizer::PrintInputs(InputIter* i, int count,
void GraphC1Visualizer::PrintInputs(Node* node) { void GraphC1Visualizer::PrintInputs(Node* node) {
InputIter i = node->inputs().begin(); auto i = node->inputs().begin();
PrintInputs(&i, node->op()->ValueInputCount(), " "); PrintInputs(&i, node->op()->ValueInputCount(), " ");
PrintInputs(&i, OperatorProperties::GetContextInputCount(node->op()), PrintInputs(&i, OperatorProperties::GetContextInputCount(node->op()),
" Ctx:"); " Ctx:");
......
...@@ -47,9 +47,8 @@ void InstructionSelector::SelectInstructions() { ...@@ -47,9 +47,8 @@ void InstructionSelector::SelectInstructions() {
if (phi->opcode() != IrOpcode::kPhi) continue; if (phi->opcode() != IrOpcode::kPhi) continue;
// Mark all inputs as used. // Mark all inputs as used.
Node::Inputs inputs = phi->inputs(); for (Node* const k : phi->inputs()) {
for (InputIter k = inputs.begin(); k != inputs.end(); ++k) { MarkAsUsed(k);
MarkAsUsed(*k);
} }
} }
} }
...@@ -409,11 +408,10 @@ void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer, ...@@ -409,11 +408,10 @@ void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer,
// arguments require an explicit push instruction before the call and do // arguments require an explicit push instruction before the call and do
// not appear as arguments to the call. Everything else ends up // not appear as arguments to the call. Everything else ends up
// as an InstructionOperand argument to the call. // as an InstructionOperand argument to the call.
InputIter iter(call->inputs().begin()); auto iter(call->inputs().begin());
int pushed_count = 0; int pushed_count = 0;
for (size_t index = 0; index < input_count; ++iter, ++index) { for (size_t index = 0; index < input_count; ++iter, ++index) {
DCHECK(iter != call->inputs().end()); DCHECK(iter != call->inputs().end());
DCHECK(index == static_cast<size_t>(iter.index()));
DCHECK((*iter)->op()->opcode() != IrOpcode::kFrameState); DCHECK((*iter)->op()->opcode() != IrOpcode::kFrameState);
if (index == 0) continue; // The first argument (callee) is already done. if (index == 0) continue; // The first argument (callee) is already done.
InstructionOperand* op = InstructionOperand* op =
......
...@@ -126,19 +126,17 @@ void Inlinee::UnifyReturn(JSGraph* jsgraph) { ...@@ -126,19 +126,17 @@ void Inlinee::UnifyReturn(JSGraph* jsgraph) {
NodeVector effects(jsgraph->zone()); NodeVector effects(jsgraph->zone());
// Iterate over all control flow predecessors, // Iterate over all control flow predecessors,
// which must be return statements. // which must be return statements.
InputIter iter = final_merge->inputs().begin(); for (Edge edge : final_merge->input_edges()) {
while (iter != final_merge->inputs().end()) { Node* input = edge.to();
Node* input = *iter;
switch (input->opcode()) { switch (input->opcode()) {
case IrOpcode::kReturn: case IrOpcode::kReturn:
values.push_back(NodeProperties::GetValueInput(input, 0)); values.push_back(NodeProperties::GetValueInput(input, 0));
effects.push_back(NodeProperties::GetEffectInput(input)); effects.push_back(NodeProperties::GetEffectInput(input));
iter.UpdateToAndIncrement(NodeProperties::GetControlInput(input)); edge.UpdateTo(NodeProperties::GetControlInput(input));
input->RemoveAllInputs(); input->RemoveAllInputs();
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
++iter;
break; break;
} }
} }
...@@ -167,9 +165,8 @@ class CopyVisitor : public NullNodeVisitor { ...@@ -167,9 +165,8 @@ class CopyVisitor : public NullNodeVisitor {
void Post(Node* original) { void Post(Node* original) {
NodeVector inputs(temp_zone_); NodeVector inputs(temp_zone_);
for (InputIter it = original->inputs().begin(); for (Node* const node : original->inputs()) {
it != original->inputs().end(); ++it) { inputs.push_back(GetCopy(node));
inputs.push_back(GetCopy(*it));
} }
// Reuse the operator in the copy. This assumes that op lives in a zone // Reuse the operator in the copy. This assumes that op lives in a zone
...@@ -242,35 +239,33 @@ void Inlinee::InlineAtCall(JSGraph* jsgraph, Node* call) { ...@@ -242,35 +239,33 @@ void Inlinee::InlineAtCall(JSGraph* jsgraph, Node* call) {
// context, effect, control. // context, effect, control.
int inliner_inputs = call->op()->ValueInputCount(); int inliner_inputs = call->op()->ValueInputCount();
// Iterate over all uses of the start node. // Iterate over all uses of the start node.
UseIter iter = start_->uses().begin(); for (Edge edge : start_->use_edges()) {
while (iter != start_->uses().end()) { Node* use = edge.from();
Node* use = *iter;
switch (use->opcode()) { switch (use->opcode()) {
case IrOpcode::kParameter: { case IrOpcode::kParameter: {
int index = 1 + OpParameter<int>(use->op()); int index = 1 + OpParameter<int>(use->op());
if (index < inliner_inputs && index < inlinee_context_index) { if (index < inliner_inputs && index < inlinee_context_index) {
// There is an input from the call, and the index is a value // There is an input from the call, and the index is a value
// projection but not the context, so rewire the input. // projection but not the context, so rewire the input.
NodeProperties::ReplaceWithValue(*iter, call->InputAt(index)); NodeProperties::ReplaceWithValue(use, call->InputAt(index));
} else if (index == inlinee_context_index) { } else if (index == inlinee_context_index) {
// This is the context projection, rewire it to the context from the // This is the context projection, rewire it to the context from the
// JSFunction object. // JSFunction object.
NodeProperties::ReplaceWithValue(*iter, context); NodeProperties::ReplaceWithValue(use, context);
} else if (index < inlinee_context_index) { } else if (index < inlinee_context_index) {
// Call has fewer arguments than required, fill with undefined. // Call has fewer arguments than required, fill with undefined.
NodeProperties::ReplaceWithValue(*iter, jsgraph->UndefinedConstant()); NodeProperties::ReplaceWithValue(use, jsgraph->UndefinedConstant());
} else { } else {
// We got too many arguments, discard for now. // We got too many arguments, discard for now.
// TODO(sigurds): Fix to treat arguments array correctly. // TODO(sigurds): Fix to treat arguments array correctly.
} }
++iter;
break; break;
} }
default: default:
if (NodeProperties::IsEffectEdge(iter.edge())) { if (NodeProperties::IsEffectEdge(edge)) {
iter.UpdateToAndIncrement(context); edge.UpdateTo(context);
} else if (NodeProperties::IsControlEdge(iter.edge())) { } else if (NodeProperties::IsControlEdge(edge)) {
iter.UpdateToAndIncrement(control); edge.UpdateTo(control);
} else { } else {
UNREACHABLE(); UNREACHABLE();
} }
...@@ -455,9 +450,8 @@ class JSCallRuntimeAccessor { ...@@ -455,9 +450,8 @@ class JSCallRuntimeAccessor {
NodeVector inputs(Zone* zone) const { NodeVector inputs(Zone* zone) const {
NodeVector inputs(zone); NodeVector inputs(zone);
for (InputIter it = call_->inputs().begin(); it != call_->inputs().end(); for (Node* const node : call_->inputs()) {
++it) { inputs.push_back(node);
inputs.push_back(*it);
} }
return inputs; return inputs;
} }
......
...@@ -101,7 +101,7 @@ inline int NodeProperties::GetFrameStateIndex(Node* node) { ...@@ -101,7 +101,7 @@ inline int NodeProperties::GetFrameStateIndex(Node* node) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Edge kinds. // Edge kinds.
inline bool NodeProperties::IsInputRange(Node::Edge edge, int first, int num) { inline bool NodeProperties::IsInputRange(Edge edge, int first, int num) {
// TODO(titzer): edge.index() is linear time; // TODO(titzer): edge.index() is linear time;
// edges maybe need to be marked as value/effect/control. // edges maybe need to be marked as value/effect/control.
if (num == 0) return false; if (num == 0) return false;
...@@ -109,25 +109,25 @@ inline bool NodeProperties::IsInputRange(Node::Edge edge, int first, int num) { ...@@ -109,25 +109,25 @@ inline bool NodeProperties::IsInputRange(Node::Edge edge, int first, int num) {
return first <= index && index < first + num; return first <= index && index < first + num;
} }
inline bool NodeProperties::IsValueEdge(Node::Edge edge) { inline bool NodeProperties::IsValueEdge(Edge edge) {
Node* node = edge.from(); Node* node = edge.from();
return IsInputRange(edge, FirstValueIndex(node), return IsInputRange(edge, FirstValueIndex(node),
node->op()->ValueInputCount()); node->op()->ValueInputCount());
} }
inline bool NodeProperties::IsContextEdge(Node::Edge edge) { inline bool NodeProperties::IsContextEdge(Edge edge) {
Node* node = edge.from(); Node* node = edge.from();
return IsInputRange(edge, FirstContextIndex(node), return IsInputRange(edge, FirstContextIndex(node),
OperatorProperties::GetContextInputCount(node->op())); OperatorProperties::GetContextInputCount(node->op()));
} }
inline bool NodeProperties::IsEffectEdge(Node::Edge edge) { inline bool NodeProperties::IsEffectEdge(Edge edge) {
Node* node = edge.from(); Node* node = edge.from();
return IsInputRange(edge, FirstEffectIndex(node), return IsInputRange(edge, FirstEffectIndex(node),
node->op()->EffectInputCount()); node->op()->EffectInputCount());
} }
inline bool NodeProperties::IsControlEdge(Node::Edge edge) { inline bool NodeProperties::IsControlEdge(Edge edge) {
Node* node = edge.from(); Node* node = edge.from();
return IsInputRange(edge, FirstControlIndex(node), return IsInputRange(edge, FirstControlIndex(node),
node->op()->ControlInputCount()); node->op()->ControlInputCount());
...@@ -176,13 +176,12 @@ inline void NodeProperties::ReplaceWithValue(Node* node, Node* value, ...@@ -176,13 +176,12 @@ inline void NodeProperties::ReplaceWithValue(Node* node, Node* value,
} }
// Requires distinguishing between value and effect edges. // Requires distinguishing between value and effect edges.
UseIter iter = node->uses().begin(); for (Edge edge : node->use_edges()) {
while (iter != node->uses().end()) { if (NodeProperties::IsEffectEdge(edge)) {
if (NodeProperties::IsEffectEdge(iter.edge())) {
DCHECK_NE(NULL, effect); DCHECK_NE(NULL, effect);
iter = iter.UpdateToAndIncrement(effect); edge.UpdateTo(effect);
} else { } else {
iter = iter.UpdateToAndIncrement(value); edge.UpdateTo(value);
} }
} }
} }
......
...@@ -25,10 +25,10 @@ class NodeProperties { ...@@ -25,10 +25,10 @@ class NodeProperties {
static inline int GetFrameStateIndex(Node* node); static inline int GetFrameStateIndex(Node* node);
static inline bool IsValueEdge(Node::Edge edge); static inline bool IsValueEdge(Edge edge);
static inline bool IsContextEdge(Node::Edge edge); static inline bool IsContextEdge(Edge edge);
static inline bool IsEffectEdge(Node::Edge edge); static inline bool IsEffectEdge(Edge edge);
static inline bool IsControlEdge(Node::Edge edge); static inline bool IsControlEdge(Edge edge);
static inline bool IsControl(Node* node); static inline bool IsControl(Node* node);
...@@ -56,7 +56,7 @@ class NodeProperties { ...@@ -56,7 +56,7 @@ class NodeProperties {
static inline int PastEffectIndex(Node* node); static inline int PastEffectIndex(Node* node);
static inline int PastControlIndex(Node* node); static inline int PastControlIndex(Node* node);
static inline bool IsInputRange(Node::Edge edge, int first, int count); static inline bool IsInputRange(Edge edge, int first, int count);
}; };
} // namespace compiler } // namespace compiler
......
This diff is collapsed.
...@@ -147,8 +147,8 @@ void Scheduler::UpdatePlacement(Node* node, Placement placement) { ...@@ -147,8 +147,8 @@ void Scheduler::UpdatePlacement(Node* node, Placement placement) {
// Reduce the use count of the node's inputs to potentially make them // Reduce the use count of the node's inputs to potentially make them
// schedulable. If all the uses of a node have been scheduled, then the node // schedulable. If all the uses of a node have been scheduled, then the node
// itself can be scheduled. // itself can be scheduled.
for (InputIter i = node->inputs().begin(); i != node->inputs().end(); ++i) { for (Edge const edge : node->input_edges()) {
DecrementUnscheduledUseCount(*i, i.index(), i.edge().from()); DecrementUnscheduledUseCount(edge.to(), edge.index(), edge.from());
} }
} }
data->placement_ = placement; data->placement_ = placement;
...@@ -455,9 +455,8 @@ class CFGBuilder : public ZoneObject { ...@@ -455,9 +455,8 @@ class CFGBuilder : public ZoneObject {
DCHECK(block != NULL); DCHECK(block != NULL);
// For all of the merge's control inputs, add a goto at the end to the // For all of the merge's control inputs, add a goto at the end to the
// merge's basic block. // merge's basic block.
for (InputIter j = merge->inputs().begin(); j != merge->inputs().end(); for (Node* const j : merge->inputs()) {
++j) { BasicBlock* predecessor_block = schedule_->block(j);
BasicBlock* predecessor_block = schedule_->block(*j);
TraceConnect(merge, predecessor_block, block); TraceConnect(merge, predecessor_block, block);
schedule_->AddGoto(predecessor_block, block); schedule_->AddGoto(predecessor_block, block);
} }
...@@ -1250,9 +1249,7 @@ class ScheduleLateNodeVisitor { ...@@ -1250,9 +1249,7 @@ class ScheduleLateNodeVisitor {
private: private:
void ProcessQueue(Node* root) { void ProcessQueue(Node* root) {
ZoneQueue<Node*>* queue = &(scheduler_->schedule_queue_); ZoneQueue<Node*>* queue = &(scheduler_->schedule_queue_);
for (InputIter i = root->inputs().begin(); i != root->inputs().end(); ++i) { for (Node* node : root->inputs()) {
Node* node = *i;
// Don't schedule coupled nodes on their own. // Don't schedule coupled nodes on their own.
if (scheduler_->GetPlacement(node) == Scheduler::kCoupled) { if (scheduler_->GetPlacement(node) == Scheduler::kCoupled) {
node = NodeProperties::GetControlInput(node); node = NodeProperties::GetControlInput(node);
...@@ -1325,9 +1322,8 @@ class ScheduleLateNodeVisitor { ...@@ -1325,9 +1322,8 @@ class ScheduleLateNodeVisitor {
BasicBlock* GetCommonDominatorOfUses(Node* node) { BasicBlock* GetCommonDominatorOfUses(Node* node) {
BasicBlock* block = NULL; BasicBlock* block = NULL;
Node::Uses uses = node->uses(); for (Edge edge : node->use_edges()) {
for (Node::Uses::iterator i = uses.begin(); i != uses.end(); ++i) { BasicBlock* use_block = GetBlockForUse(edge);
BasicBlock* use_block = GetBlockForUse(i.edge());
block = block == NULL ? use_block : use_block == NULL block = block == NULL ? use_block : use_block == NULL
? block ? block
: scheduler_->GetCommonDominator( : scheduler_->GetCommonDominator(
...@@ -1336,7 +1332,7 @@ class ScheduleLateNodeVisitor { ...@@ -1336,7 +1332,7 @@ class ScheduleLateNodeVisitor {
return block; return block;
} }
BasicBlock* GetBlockForUse(Node::Edge edge) { BasicBlock* GetBlockForUse(Edge edge) {
Node* use = edge.from(); Node* use = edge.from();
IrOpcode::Value opcode = use->opcode(); IrOpcode::Value opcode = use->opcode();
if (opcode == IrOpcode::kPhi || opcode == IrOpcode::kEffectPhi) { if (opcode == IrOpcode::kPhi || opcode == IrOpcode::kEffectPhi) {
......
...@@ -237,19 +237,19 @@ class RepresentationSelector { ...@@ -237,19 +237,19 @@ class RepresentationSelector {
// context, effect, and control inputs, assuming that value inputs should have // context, effect, and control inputs, assuming that value inputs should have
// {kRepTagged} representation and can observe all output values {kTypeAny}. // {kRepTagged} representation and can observe all output values {kTypeAny}.
void VisitInputs(Node* node) { void VisitInputs(Node* node) {
InputIter i = node->inputs().begin(); auto i = node->input_edges().begin();
for (int j = node->op()->ValueInputCount(); j > 0; ++i, j--) { for (int j = node->op()->ValueInputCount(); j > 0; ++i, j--) {
ProcessInput(node, i.index(), kMachAnyTagged); // Value inputs ProcessInput(node, (*i).index(), kMachAnyTagged); // Value inputs
} }
for (int j = OperatorProperties::GetContextInputCount(node->op()); j > 0; for (int j = OperatorProperties::GetContextInputCount(node->op()); j > 0;
++i, j--) { ++i, j--) {
ProcessInput(node, i.index(), kMachAnyTagged); // Context inputs ProcessInput(node, (*i).index(), kMachAnyTagged); // Context inputs
} }
for (int j = node->op()->EffectInputCount(); j > 0; ++i, j--) { for (int j = node->op()->EffectInputCount(); j > 0; ++i, j--) {
Enqueue(*i); // Effect inputs: just visit Enqueue((*i).to()); // Effect inputs: just visit
} }
for (int j = node->op()->ControlInputCount(); j > 0; ++i, j--) { for (int j = node->op()->ControlInputCount(); j > 0; ++i, j--) {
Enqueue(*i); // Control inputs: just visit Enqueue((*i).to()); // Control inputs: just visit
} }
SetOutput(node, kMachAnyTagged); SetOutput(node, kMachAnyTagged);
} }
...@@ -379,21 +379,19 @@ class RepresentationSelector { ...@@ -379,21 +379,19 @@ class RepresentationSelector {
} }
// Convert inputs to the output representation of this phi. // Convert inputs to the output representation of this phi.
Node::Inputs inputs = node->inputs(); for (Edge const edge : node->input_edges()) {
for (Node::Inputs::iterator iter(inputs.begin()); iter != inputs.end();
++iter, --values) {
// TODO(titzer): it'd be nice to have distinguished edge kinds here. // TODO(titzer): it'd be nice to have distinguished edge kinds here.
ProcessInput(node, iter.index(), values > 0 ? output_type : 0); ProcessInput(node, edge.index(), values > 0 ? output_type : 0);
values--;
} }
} else { } else {
// Propagate {use} of the phi to value inputs, and 0 to control. // Propagate {use} of the phi to value inputs, and 0 to control.
Node::Inputs inputs = node->inputs();
MachineType use_type = MachineType use_type =
static_cast<MachineType>((use & kTypeMask) | output); static_cast<MachineType>((use & kTypeMask) | output);
for (Node::Inputs::iterator iter(inputs.begin()); iter != inputs.end(); for (Edge const edge : node->input_edges()) {
++iter, --values) {
// TODO(titzer): it'd be nice to have distinguished edge kinds here. // TODO(titzer): it'd be nice to have distinguished edge kinds here.
ProcessInput(node, iter.index(), values > 0 ? use_type : 0); ProcessInput(node, edge.index(), values > 0 ? use_type : 0);
values--;
} }
} }
} }
......
...@@ -176,11 +176,11 @@ void Verifier::Visitor::Pre(Node* node) { ...@@ -176,11 +176,11 @@ void Verifier::Visitor::Pre(Node* node) {
// Verify all successors are projections if multiple value outputs exist. // Verify all successors are projections if multiple value outputs exist.
if (node->op()->ValueOutputCount() > 1) { if (node->op()->ValueOutputCount() > 1) {
Node::Uses uses = node->uses(); for (Edge edge : node->use_edges()) {
for (Node::Uses::iterator it = uses.begin(); it != uses.end(); ++it) { Node* use = edge.from();
CHECK(!NodeProperties::IsValueEdge(it.edge()) || CHECK(!NodeProperties::IsValueEdge(edge) ||
(*it)->opcode() == IrOpcode::kProjection || use->opcode() == IrOpcode::kProjection ||
(*it)->opcode() == IrOpcode::kParameter); use->opcode() == IrOpcode::kParameter);
} }
} }
......
...@@ -130,11 +130,8 @@ class ControlReducerTester : HandleAndZoneScope { ...@@ -130,11 +130,8 @@ class ControlReducerTester : HandleAndZoneScope {
} }
Node* SetSelfReferences(Node* node) { Node* SetSelfReferences(Node* node) {
Node::Inputs inputs = node->inputs(); for (Edge edge : node->input_edges()) {
for (Node::Inputs::iterator iter(inputs.begin()); iter != inputs.end(); if (edge.to() == self) node->ReplaceInput(edge.index(), node);
++iter) {
Node* input = *iter;
if (input == self) node->ReplaceInput(iter.index(), node);
} }
return node; return node;
} }
......
...@@ -92,10 +92,8 @@ TEST(NodeInputIteratorOne) { ...@@ -92,10 +92,8 @@ TEST(NodeInputIteratorOne) {
TEST(NodeUseIteratorEmpty) { TEST(NodeUseIteratorEmpty) {
GraphTester graph; GraphTester graph;
Node* n1 = graph.NewNode(&dummy_operator); Node* n1 = graph.NewNode(&dummy_operator);
Node::Uses::iterator i(n1->uses().begin());
int use_count = 0; int use_count = 0;
for (; i != n1->uses().end(); ++i) { for (Edge const edge : n1->use_edges()) {
Node::Edge edge(i.edge());
USE(edge); USE(edge);
use_count++; use_count++;
} }
...@@ -365,31 +363,31 @@ TEST(AppendInputsAndIterator) { ...@@ -365,31 +363,31 @@ TEST(AppendInputsAndIterator) {
Node* n1 = graph.NewNode(&dummy_operator, n0); Node* n1 = graph.NewNode(&dummy_operator, n0);
Node* n2 = graph.NewNode(&dummy_operator, n0, n1); Node* n2 = graph.NewNode(&dummy_operator, n0, n1);
Node::Inputs inputs(n2->inputs()); Node::InputEdges inputs(n2->input_edges());
Node::Inputs::iterator current = inputs.begin(); Node::InputEdges::iterator current = inputs.begin();
CHECK(current != inputs.end()); CHECK(current != inputs.end());
CHECK(*current == n0); CHECK((*current).to() == n0);
++current; ++current;
CHECK(current != inputs.end()); CHECK(current != inputs.end());
CHECK(*current == n1); CHECK((*current).to() == n1);
++current; ++current;
CHECK(current == inputs.end()); CHECK(current == inputs.end());
Node* n3 = graph.NewNode(&dummy_operator); Node* n3 = graph.NewNode(&dummy_operator);
n2->AppendInput(graph.zone(), n3); n2->AppendInput(graph.zone(), n3);
inputs = n2->inputs(); inputs = n2->input_edges();
current = inputs.begin(); current = inputs.begin();
CHECK(current != inputs.end()); CHECK(current != inputs.end());
CHECK(*current == n0); CHECK((*current).to() == n0);
CHECK_EQ(0, current.index()); CHECK_EQ(0, (*current).index());
++current; ++current;
CHECK(current != inputs.end()); CHECK(current != inputs.end());
CHECK(*current == n1); CHECK((*current).to() == n1);
CHECK_EQ(1, current.index()); CHECK_EQ(1, (*current).index());
++current; ++current;
CHECK(current != inputs.end()); CHECK(current != inputs.end());
CHECK(*current == n3); CHECK((*current).to() == n3);
CHECK_EQ(2, current.index()); CHECK_EQ(2, (*current).index());
++current; ++current;
CHECK(current == inputs.end()); CHECK(current == inputs.end());
} }
......
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