Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2014 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/graph-replay.h" |
| 6 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 7 | #include "src/compiler/all-nodes.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 8 | #include "src/compiler/common-operator.h" |
| 9 | #include "src/compiler/graph.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 10 | #include "src/compiler/node.h" |
| 11 | #include "src/compiler/operator.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 12 | #include "src/compiler/operator-properties.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 13 | |
| 14 | namespace v8 { |
| 15 | namespace internal { |
| 16 | namespace compiler { |
| 17 | |
| 18 | #ifdef DEBUG |
| 19 | |
| 20 | void GraphReplayPrinter::PrintReplay(Graph* graph) { |
| 21 | GraphReplayPrinter replay; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 22 | PrintF(" Node* nil = graph()->NewNode(common()->Dead());\n"); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 23 | Zone zone(graph->zone()->allocator()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 24 | AllNodes nodes(&zone, graph); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 25 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 26 | // Allocate the nodes first. |
| 27 | for (Node* node : nodes.live) { |
| 28 | PrintReplayOpCreator(node->op()); |
| 29 | PrintF(" Node* n%d = graph()->NewNode(op", node->id()); |
| 30 | for (int i = 0; i < node->InputCount(); ++i) { |
| 31 | PrintF(", nil"); |
| 32 | } |
| 33 | PrintF("); USE(n%d);\n", node->id()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 34 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 35 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 36 | // Connect the nodes to their inputs. |
| 37 | for (Node* node : nodes.live) { |
| 38 | for (int i = 0; i < node->InputCount(); i++) { |
| 39 | PrintF(" n%d->ReplaceInput(%d, n%d);\n", node->id(), i, |
| 40 | node->InputAt(i)->id()); |
| 41 | } |
| 42 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | |
| 46 | void GraphReplayPrinter::PrintReplayOpCreator(const Operator* op) { |
| 47 | IrOpcode::Value opcode = static_cast<IrOpcode::Value>(op->opcode()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 48 | const char* builder = IrOpcode::IsCommonOpcode(opcode) ? "common" : "js"; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 49 | const char* mnemonic = IrOpcode::IsCommonOpcode(opcode) |
| 50 | ? IrOpcode::Mnemonic(opcode) |
| 51 | : IrOpcode::Mnemonic(opcode) + 2; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 52 | PrintF(" op = %s()->%s(", builder, mnemonic); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 53 | switch (opcode) { |
| 54 | case IrOpcode::kParameter: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 55 | PrintF("%d", ParameterIndexOf(op)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 56 | break; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 57 | case IrOpcode::kNumberConstant: |
| 58 | PrintF("%g", OpParameter<double>(op)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 59 | break; |
| 60 | case IrOpcode::kHeapConstant: |
| 61 | PrintF("unique_constant"); |
| 62 | break; |
| 63 | case IrOpcode::kPhi: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 64 | PrintF("kMachAnyTagged, %d", op->ValueInputCount()); |
| 65 | break; |
| 66 | case IrOpcode::kStateValues: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 67 | PrintF("%d", op->ValueInputCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 68 | break; |
| 69 | case IrOpcode::kEffectPhi: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 70 | PrintF("%d", op->EffectInputCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 71 | break; |
| 72 | case IrOpcode::kLoop: |
| 73 | case IrOpcode::kMerge: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 74 | PrintF("%d", op->ControlInputCount()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 75 | break; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 76 | case IrOpcode::kStart: |
| 77 | PrintF("%d", op->ValueOutputCount() - 3); |
| 78 | break; |
| 79 | case IrOpcode::kFrameState: |
| 80 | PrintF("JS_FRAME, BailoutId(-1), OutputFrameStateCombine::Ignore()"); |
| 81 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 82 | default: |
| 83 | break; |
| 84 | } |
| 85 | PrintF(");\n"); |
| 86 | } |
| 87 | |
| 88 | #endif // DEBUG |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 89 | |
| 90 | } // namespace compiler |
| 91 | } // namespace internal |
| 92 | } // namespace v8 |