| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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('tracer'); | 5 #library('tracer'); |
| 6 | 6 |
| 7 #import('dart:io'); | 7 #import('dart:io'); |
| 8 #import('ssa.dart'); | 8 #import('ssa.dart'); |
| 9 #import('../leg.dart'); | 9 #import('../leg.dart'); |
| 10 | 10 |
| 11 final bool GENERATE_SSA_TRACE = false; | 11 final bool GENERATE_SSA_TRACE = false; |
| 12 final String SSA_TRACE_FILTER = null; | 12 final String SSA_TRACE_FILTER = null; |
| 13 | 13 |
| 14 class HTracer extends HGraphVisitor implements Tracer { | 14 class HTracer extends HGraphVisitor implements Tracer { |
| 15 JavaScriptItemCompilationContext context; |
| 15 int indent = 0; | 16 int indent = 0; |
| 16 final RandomAccessFile output; | 17 final RandomAccessFile output; |
| 17 final bool enabled = GENERATE_SSA_TRACE; | 18 final bool enabled = GENERATE_SSA_TRACE; |
| 18 bool traceActive = false; | 19 bool traceActive = false; |
| 19 | 20 |
| 20 HTracer([String path = "dart.cfg"]) | 21 HTracer([String path = "dart.cfg"]) |
| 21 : output = GENERATE_SSA_TRACE ? new File(path).openSync(FileMode.WRITE) | 22 : output = GENERATE_SSA_TRACE ? new File(path).openSync(FileMode.WRITE) |
| 22 : null; | 23 : null; |
| 23 | 24 |
| 24 void close() { | 25 void close() { |
| 25 if (enabled) output.closeSync(); | 26 if (enabled) output.closeSync(); |
| 26 } | 27 } |
| 27 | 28 |
| 28 void traceCompilation(String methodName) { | 29 void traceCompilation(String methodName, |
| 30 JavaScriptItemCompilationContext compilationContext) { |
| 29 if (!enabled) return; | 31 if (!enabled) return; |
| 32 this.context = compilationContext; |
| 30 traceActive = | 33 traceActive = |
| 31 SSA_TRACE_FILTER == null || methodName.contains(SSA_TRACE_FILTER); | 34 SSA_TRACE_FILTER == null || methodName.contains(SSA_TRACE_FILTER); |
| 32 if (!traceActive) return; | 35 if (!traceActive) return; |
| 33 tag("compilation", () { | 36 tag("compilation", () { |
| 34 printProperty("name", methodName); | 37 printProperty("name", methodName); |
| 35 printProperty("method", methodName); | 38 printProperty("method", methodName); |
| 36 printProperty("date", new Date.now().millisecondsSinceEpoch); | 39 printProperty("date", new Date.now().millisecondsSinceEpoch); |
| 37 }); | 40 }); |
| 38 } | 41 } |
| 39 | 42 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 66 add("successors"); | 69 add("successors"); |
| 67 for (HBasicBlock successor in block.successors) { | 70 for (HBasicBlock successor in block.successors) { |
| 68 add(' "B${successor.id}"'); | 71 add(' "B${successor.id}"'); |
| 69 } | 72 } |
| 70 add("\n"); | 73 add("\n"); |
| 71 } | 74 } |
| 72 } | 75 } |
| 73 | 76 |
| 74 void addInstructions(HInstructionStringifier stringifier, | 77 void addInstructions(HInstructionStringifier stringifier, |
| 75 HInstructionList list) { | 78 HInstructionList list) { |
| 79 HTypeMap types = context.types; |
| 76 for (HInstruction instruction = list.first; | 80 for (HInstruction instruction = list.first; |
| 77 instruction !== null; | 81 instruction !== null; |
| 78 instruction = instruction.next) { | 82 instruction = instruction.next) { |
| 79 int bci = 0; | 83 int bci = 0; |
| 80 int uses = instruction.usedBy.length; | 84 int uses = instruction.usedBy.length; |
| 81 String changes = instruction.hasSideEffects() ? '!' : ' '; | 85 String changes = instruction.hasSideEffects(types) ? '!' : ' '; |
| 82 String depends = instruction.dependsOnSomething() ? '?' : ''; | 86 String depends = instruction.dependsOnSomething() ? '?' : ''; |
| 83 addIndent(); | 87 addIndent(); |
| 84 String temporaryId = stringifier.temporaryId(instruction); | 88 String temporaryId = stringifier.temporaryId(instruction); |
| 85 String instructionString = stringifier.visit(instruction); | 89 String instructionString = stringifier.visit(instruction); |
| 86 add("$bci $uses $temporaryId $instructionString $changes $depends <|@\n"); | 90 add("$bci $uses $temporaryId $instructionString $changes $depends <|@\n"); |
| 87 } | 91 } |
| 88 } | 92 } |
| 89 | 93 |
| 90 void visitBasicBlock(HBasicBlock block) { | 94 void visitBasicBlock(HBasicBlock block) { |
| 91 HInstructionStringifier stringifier = new HInstructionStringifier(block); | 95 HInstructionStringifier stringifier = |
| 96 new HInstructionStringifier(context, block); |
| 92 assert(block.id !== null); | 97 assert(block.id !== null); |
| 93 tag("block", () { | 98 tag("block", () { |
| 94 printProperty("name", "B${block.id}"); | 99 printProperty("name", "B${block.id}"); |
| 95 printProperty("from_bci", -1); | 100 printProperty("from_bci", -1); |
| 96 printProperty("to_bci", -1); | 101 printProperty("to_bci", -1); |
| 97 addPredecessors(block); | 102 addPredecessors(block); |
| 98 addSuccessors(block); | 103 addSuccessors(block); |
| 99 printEmptyProperty("xhandlers"); | 104 printEmptyProperty("xhandlers"); |
| 100 printEmptyProperty("flags"); | 105 printEmptyProperty("flags"); |
| 101 if (block.dominator !== null) { | 106 if (block.dominator !== null) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 159 } |
| 155 | 160 |
| 156 void addIndent() { | 161 void addIndent() { |
| 157 for (int i = 0; i < indent; i++) { | 162 for (int i = 0; i < indent; i++) { |
| 158 add(" "); | 163 add(" "); |
| 159 } | 164 } |
| 160 } | 165 } |
| 161 } | 166 } |
| 162 | 167 |
| 163 class HInstructionStringifier implements HVisitor<String> { | 168 class HInstructionStringifier implements HVisitor<String> { |
| 169 JavaScriptItemCompilationContext context; |
| 164 HBasicBlock currentBlock; | 170 HBasicBlock currentBlock; |
| 165 | 171 |
| 166 HInstructionStringifier(this.currentBlock); | 172 HInstructionStringifier(this.context, this.currentBlock); |
| 167 | 173 |
| 168 visit(HInstruction node) => node.accept(this); | 174 visit(HInstruction node) => node.accept(this); |
| 169 | 175 |
| 170 String temporaryId(HInstruction instruction) { | 176 String temporaryId(HInstruction instruction) { |
| 171 String prefix; | 177 String prefix; |
| 172 HType type = instruction.propagatedType; | 178 HType type = context.types[instruction]; |
| 173 if (!type.isPrimitive()) { | 179 if (!type.isPrimitive()) { |
| 174 prefix = 'U'; | 180 prefix = 'U'; |
| 175 } else { | 181 } else { |
| 176 if (type == HType.MUTABLE_ARRAY) { | 182 if (type == HType.MUTABLE_ARRAY) { |
| 177 prefix = 'm'; | 183 prefix = 'm'; |
| 178 } else if (type == HType.READABLE_ARRAY) { | 184 } else if (type == HType.READABLE_ARRAY) { |
| 179 prefix = 'a'; | 185 prefix = 'a'; |
| 180 } else if (type == HType.EXTENDABLE_ARRAY) { | 186 } else if (type == HType.EXTENDABLE_ARRAY) { |
| 181 prefix = 'e'; | 187 prefix = 'e'; |
| 182 } else if (type == HType.BOOLEAN) { | 188 } else if (type == HType.BOOLEAN) { |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 return "TypeGuard($on): $guardedId is $type bailout: $bailoutId " | 510 return "TypeGuard($on): $guardedId is $type bailout: $bailoutId " |
| 505 "env: $envBuffer"; | 511 "env: $envBuffer"; |
| 506 } | 512 } |
| 507 | 513 |
| 508 String visitIs(HIs node) { | 514 String visitIs(HIs node) { |
| 509 String type = node.typeExpression.toString(); | 515 String type = node.typeExpression.toString(); |
| 510 return "TypeTest: ${temporaryId(node.expression)} is $type"; | 516 return "TypeTest: ${temporaryId(node.expression)} is $type"; |
| 511 } | 517 } |
| 512 | 518 |
| 513 String visitTypeConversion(HTypeConversion node) { | 519 String visitTypeConversion(HTypeConversion node) { |
| 514 String type = node.propagatedType.toString(); | 520 return "TypeConversion: ${temporaryId(node.inputs[0])} to ${node.type}"; |
| 515 return "TypeConversion: ${temporaryId(node.inputs[0])} to $type"; | |
| 516 } | 521 } |
| 517 } | 522 } |
| OLD | NEW |