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 7 #include "src/compiler/all-nodes.h" 8 #include "src/compiler/common-operator.h" 9 #include "src/compiler/graph.h" 10 #include "src/compiler/node.h" 11 #include "src/compiler/operator.h" 12 #include "src/compiler/operator-properties.h" 13 14 namespace v8 { 15 namespace internal { 16 namespace compiler { 17 18 #ifdef DEBUG 19 20 void GraphReplayPrinter::PrintReplay(Graph* graph) { 21 GraphReplayPrinter replay; 22 PrintF(" Node* nil = graph()->NewNode(common()->Dead());\n"); 23 Zone zone(graph->zone()->allocator(), ZONE_NAME); 24 AllNodes nodes(&zone, graph); 25 26 // Allocate the nodes first. 27 for (Node* node : nodes.reachable) { 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()); 34 } 35 36 // Connect the nodes to their inputs. 37 for (Node* node : nodes.reachable) { 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 } 43 } 44 45 46 void GraphReplayPrinter::PrintReplayOpCreator(const Operator* op) { 47 IrOpcode::Value opcode = static_cast<IrOpcode::Value>(op->opcode()); 48 const char* builder = IrOpcode::IsCommonOpcode(opcode) ? "common" : "js"; 49 const char* mnemonic = IrOpcode::IsCommonOpcode(opcode) 50 ? IrOpcode::Mnemonic(opcode) 51 : IrOpcode::Mnemonic(opcode) + 2; 52 PrintF(" op = %s()->%s(", builder, mnemonic); 53 switch (opcode) { 54 case IrOpcode::kParameter: 55 PrintF("%d", ParameterIndexOf(op)); 56 break; 57 case IrOpcode::kNumberConstant: 58 PrintF("%g", OpParameter<double>(op)); 59 break; 60 case IrOpcode::kHeapConstant: 61 PrintF("unique_constant"); 62 break; 63 case IrOpcode::kPhi: 64 PrintF("kMachAnyTagged, %d", op->ValueInputCount()); 65 break; 66 case IrOpcode::kStateValues: 67 PrintF("%d", op->ValueInputCount()); 68 break; 69 case IrOpcode::kEffectPhi: 70 PrintF("%d", op->EffectInputCount()); 71 break; 72 case IrOpcode::kLoop: 73 case IrOpcode::kMerge: 74 PrintF("%d", op->ControlInputCount()); 75 break; 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; 82 default: 83 break; 84 } 85 PrintF(");\n"); 86 } 87 88 #endif // DEBUG 89 90 } // namespace compiler 91 } // namespace internal 92 } // namespace v8 93