| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library ssa.tracer; | 5 library ssa.tracer; |
| 6 | 6 |
| 7 import 'dart:async' show EventSink; | 7 import 'dart:async' show EventSink; |
| 8 | 8 |
| 9 import '../compiler.dart' show Compiler; | 9 import '../compiler.dart' show Compiler; |
| 10 import '../diagnostics/invariant.dart' show DEBUG_MODE; | 10 import '../diagnostics/invariant.dart' show DEBUG_MODE; |
| 11 import '../js_backend/js_backend.dart'; | 11 import '../js_backend/js_backend.dart'; |
| 12 import '../tracer.dart'; | 12 import '../tracer.dart'; |
| 13 import 'nodes.dart'; | 13 import 'nodes.dart'; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Outputs SSA code in a format readable by Hydra IR. | 16 * Outputs SSA code in a format readable by Hydra IR. |
| 17 * Tracing is disabled by default, see ../tracer.dart for how | 17 * Tracing is disabled by default, see ../tracer.dart for how |
| 18 * to enable it. | 18 * to enable it. |
| 19 */ | 19 */ |
| 20 class HTracer extends HGraphVisitor with TracerUtil { | 20 class HTracer extends HGraphVisitor with TracerUtil { |
| 21 Compiler compiler; | 21 Compiler compiler; |
| 22 JavaScriptItemCompilationContext context; | |
| 23 final EventSink<String> output; | 22 final EventSink<String> output; |
| 24 | 23 |
| 25 HTracer(this.output, this.compiler, this.context); | 24 HTracer(this.output, this.compiler); |
| 26 | 25 |
| 27 void traceGraph(String name, HGraph graph) { | 26 void traceGraph(String name, HGraph graph) { |
| 28 DEBUG_MODE = true; | 27 DEBUG_MODE = true; |
| 29 tag("cfg", () { | 28 tag("cfg", () { |
| 30 printProperty("name", name); | 29 printProperty("name", name); |
| 31 visitDominatorTree(graph); | 30 visitDominatorTree(graph); |
| 32 }); | 31 }); |
| 33 } | 32 } |
| 34 | 33 |
| 35 void addPredecessors(HBasicBlock block) { | 34 void addPredecessors(HBasicBlock block) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 String depends = instruction.sideEffects.dependsOnSomething() ? '?' : ''; | 68 String depends = instruction.sideEffects.dependsOnSomething() ? '?' : ''; |
| 70 addIndent(); | 69 addIndent(); |
| 71 String temporaryId = stringifier.temporaryId(instruction); | 70 String temporaryId = stringifier.temporaryId(instruction); |
| 72 String instructionString = stringifier.visit(instruction); | 71 String instructionString = stringifier.visit(instruction); |
| 73 add("$bci $uses $temporaryId $instructionString $changes $depends <|@\n"); | 72 add("$bci $uses $temporaryId $instructionString $changes $depends <|@\n"); |
| 74 } | 73 } |
| 75 } | 74 } |
| 76 | 75 |
| 77 void visitBasicBlock(HBasicBlock block) { | 76 void visitBasicBlock(HBasicBlock block) { |
| 78 HInstructionStringifier stringifier = | 77 HInstructionStringifier stringifier = |
| 79 new HInstructionStringifier(context, block, compiler); | 78 new HInstructionStringifier(block, compiler); |
| 80 assert(block.id != null); | 79 assert(block.id != null); |
| 81 tag("block", () { | 80 tag("block", () { |
| 82 printProperty("name", "B${block.id}"); | 81 printProperty("name", "B${block.id}"); |
| 83 printProperty("from_bci", -1); | 82 printProperty("from_bci", -1); |
| 84 printProperty("to_bci", -1); | 83 printProperty("to_bci", -1); |
| 85 addPredecessors(block); | 84 addPredecessors(block); |
| 86 addSuccessors(block); | 85 addSuccessors(block); |
| 87 printEmptyProperty("xhandlers"); | 86 printEmptyProperty("xhandlers"); |
| 88 printEmptyProperty("flags"); | 87 printEmptyProperty("flags"); |
| 89 if (block.dominator != null) { | 88 if (block.dominator != null) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 107 tag("HIR", () { | 106 tag("HIR", () { |
| 108 addInstructions(stringifier, block.phis); | 107 addInstructions(stringifier, block.phis); |
| 109 addInstructions(stringifier, block); | 108 addInstructions(stringifier, block); |
| 110 }); | 109 }); |
| 111 }); | 110 }); |
| 112 } | 111 } |
| 113 } | 112 } |
| 114 | 113 |
| 115 class HInstructionStringifier implements HVisitor<String> { | 114 class HInstructionStringifier implements HVisitor<String> { |
| 116 final Compiler compiler; | 115 final Compiler compiler; |
| 117 final JavaScriptItemCompilationContext context; | |
| 118 final HBasicBlock currentBlock; | 116 final HBasicBlock currentBlock; |
| 119 | 117 |
| 120 HInstructionStringifier(this.context, this.currentBlock, this.compiler); | 118 HInstructionStringifier(this.currentBlock, this.compiler); |
| 121 | 119 |
| 122 visit(HInstruction node) => '${node.accept(this)} ${node.instructionType}'; | 120 visit(HInstruction node) => '${node.accept(this)} ${node.instructionType}'; |
| 123 | 121 |
| 124 String temporaryId(HInstruction instruction) { | 122 String temporaryId(HInstruction instruction) { |
| 125 String prefix; | 123 String prefix; |
| 126 if (instruction.isNull()) { | 124 if (instruction.isNull()) { |
| 127 prefix = 'u'; | 125 prefix = 'u'; |
| 128 } else if (instruction.isConflicting()) { | 126 } else if (instruction.isConflicting()) { |
| 129 prefix = 'c'; | 127 prefix = 'c'; |
| 130 } else if (instruction.isExtendableArray(compiler)) { | 128 } else if (instruction.isExtendableArray(compiler)) { |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 } | 536 } |
| 539 | 537 |
| 540 String visitAwait(HAwait node) { | 538 String visitAwait(HAwait node) { |
| 541 return "Await: ${temporaryId(node.inputs[0])}"; | 539 return "Await: ${temporaryId(node.inputs[0])}"; |
| 542 } | 540 } |
| 543 | 541 |
| 544 String visitYield(HYield node) { | 542 String visitYield(HYield node) { |
| 545 return "Yield${node.hasStar ? "*" : ""}: ${temporaryId(node.inputs[0])}"; | 543 return "Yield${node.hasStar ? "*" : ""}: ${temporaryId(node.inputs[0])}"; |
| 546 } | 544 } |
| 547 } | 545 } |
| OLD | NEW |