blob: cb775e96f3538f56fabc7f54e57a4f5144a7dc13 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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 Murdoch4a90d5f2016-03-22 12:00:34 +00007#include "src/compiler/all-nodes.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/compiler/common-operator.h"
9#include "src/compiler/graph.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010#include "src/compiler/node.h"
11#include "src/compiler/operator.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040012#include "src/compiler/operator-properties.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000013
14namespace v8 {
15namespace internal {
16namespace compiler {
17
18#ifdef DEBUG
19
20void GraphReplayPrinter::PrintReplay(Graph* graph) {
21 GraphReplayPrinter replay;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000022 PrintF(" Node* nil = graph()->NewNode(common()->Dead());\n");
Ben Murdochda12d292016-06-02 14:46:10 +010023 Zone zone(graph->zone()->allocator());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000024 AllNodes nodes(&zone, graph);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000025
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026 // 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 Murdochb8a8cc12014-11-26 15:28:44 +000034 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000035
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000036 // 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 Murdochb8a8cc12014-11-26 15:28:44 +000043}
44
45
46void GraphReplayPrinter::PrintReplayOpCreator(const Operator* op) {
47 IrOpcode::Value opcode = static_cast<IrOpcode::Value>(op->opcode());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000048 const char* builder = IrOpcode::IsCommonOpcode(opcode) ? "common" : "js";
Ben Murdochb8a8cc12014-11-26 15:28:44 +000049 const char* mnemonic = IrOpcode::IsCommonOpcode(opcode)
50 ? IrOpcode::Mnemonic(opcode)
51 : IrOpcode::Mnemonic(opcode) + 2;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000052 PrintF(" op = %s()->%s(", builder, mnemonic);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000053 switch (opcode) {
54 case IrOpcode::kParameter:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000055 PrintF("%d", ParameterIndexOf(op));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000057 case IrOpcode::kNumberConstant:
58 PrintF("%g", OpParameter<double>(op));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059 break;
60 case IrOpcode::kHeapConstant:
61 PrintF("unique_constant");
62 break;
63 case IrOpcode::kPhi:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000064 PrintF("kMachAnyTagged, %d", op->ValueInputCount());
65 break;
66 case IrOpcode::kStateValues:
Emily Bernierd0a1eb72015-03-24 16:35:39 -040067 PrintF("%d", op->ValueInputCount());
Ben Murdochb8a8cc12014-11-26 15:28:44 +000068 break;
69 case IrOpcode::kEffectPhi:
Emily Bernierd0a1eb72015-03-24 16:35:39 -040070 PrintF("%d", op->EffectInputCount());
Ben Murdochb8a8cc12014-11-26 15:28:44 +000071 break;
72 case IrOpcode::kLoop:
73 case IrOpcode::kMerge:
Emily Bernierd0a1eb72015-03-24 16:35:39 -040074 PrintF("%d", op->ControlInputCount());
Ben Murdochb8a8cc12014-11-26 15:28:44 +000075 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000076 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 Murdochb8a8cc12014-11-26 15:28:44 +000082 default:
83 break;
84 }
85 PrintF(");\n");
86}
87
88#endif // DEBUG
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000089
90} // namespace compiler
91} // namespace internal
92} // namespace v8