Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame^] | 1 | // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/compiler/node.h" |
| 6 | |
| 7 | #include "src/compiler/generic-node-inl.h" |
| 8 | |
| 9 | namespace v8 { |
| 10 | namespace internal { |
| 11 | namespace compiler { |
| 12 | |
| 13 | void Node::Kill() { |
| 14 | DCHECK_NOT_NULL(op()); |
| 15 | RemoveAllInputs(); |
| 16 | DCHECK(uses().empty()); |
| 17 | } |
| 18 | |
| 19 | |
| 20 | void Node::CollectProjections(NodeVector* projections) { |
| 21 | for (size_t i = 0; i < projections->size(); i++) { |
| 22 | (*projections)[i] = NULL; |
| 23 | } |
| 24 | for (UseIter i = uses().begin(); i != uses().end(); ++i) { |
| 25 | if ((*i)->opcode() != IrOpcode::kProjection) continue; |
| 26 | size_t index = OpParameter<size_t>(*i); |
| 27 | DCHECK_LT(index, projections->size()); |
| 28 | DCHECK_EQ(NULL, (*projections)[index]); |
| 29 | (*projections)[index] = *i; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | |
| 34 | Node* Node::FindProjection(size_t projection_index) { |
| 35 | for (UseIter i = uses().begin(); i != uses().end(); ++i) { |
| 36 | if ((*i)->opcode() == IrOpcode::kProjection && |
| 37 | OpParameter<size_t>(*i) == projection_index) { |
| 38 | return *i; |
| 39 | } |
| 40 | } |
| 41 | return NULL; |
| 42 | } |
| 43 | |
| 44 | |
| 45 | OStream& operator<<(OStream& os, const Operator& op) { return op.PrintTo(os); } |
| 46 | |
| 47 | |
| 48 | OStream& operator<<(OStream& os, const Node& n) { |
| 49 | os << n.id() << ": " << *n.op(); |
| 50 | if (n.op()->InputCount() != 0) { |
| 51 | os << "("; |
| 52 | for (int i = 0; i < n.op()->InputCount(); ++i) { |
| 53 | if (i != 0) os << ", "; |
| 54 | os << n.InputAt(i)->id(); |
| 55 | } |
| 56 | os << ")"; |
| 57 | } |
| 58 | return os; |
| 59 | } |
| 60 | |
| 61 | } // namespace compiler |
| 62 | } // namespace internal |
| 63 | } // namespace v8 |