| 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 interface OptimizationPhase { | 5 interface OptimizationPhase { |
| 6 String get name(); | 6 String get name(); |
| 7 void visitGraph(HGraph graph); | 7 void visitGraph(HGraph graph); |
| 8 } | 8 } |
| 9 | 9 |
| 10 class SsaOptimizerTask extends CompilerTask { | 10 class SsaOptimizerTask extends CompilerTask { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // some patterns useful for type conversion. | 35 // some patterns useful for type conversion. |
| 36 new SsaConstantFolder(backend, work, types), | 36 new SsaConstantFolder(backend, work, types), |
| 37 new SsaTypeConversionInserter(compiler), | 37 new SsaTypeConversionInserter(compiler), |
| 38 new SsaTypePropagator(compiler, types), | 38 new SsaTypePropagator(compiler, types), |
| 39 new SsaCheckInserter(backend, types), | 39 new SsaCheckInserter(backend, types), |
| 40 new SsaConstantFolder(backend, work, types), | 40 new SsaConstantFolder(backend, work, types), |
| 41 new SsaRedundantPhiEliminator(), | 41 new SsaRedundantPhiEliminator(), |
| 42 new SsaDeadPhiEliminator(), | 42 new SsaDeadPhiEliminator(), |
| 43 new SsaGlobalValueNumberer(compiler, types), | 43 new SsaGlobalValueNumberer(compiler, types), |
| 44 new SsaCodeMotion(), | 44 new SsaCodeMotion(), |
| 45 // Previous optimizations may have generated new |
| 46 // opportunities for constant folding. |
| 47 new SsaConstantFolder(backend, work, types), |
| 45 new SsaDeadCodeEliminator(types), | 48 new SsaDeadCodeEliminator(types), |
| 46 new SsaRegisterRecompilationCandidates(backend, work, types)]; | 49 new SsaRegisterRecompilationCandidates(backend, work, types)]; |
| 47 runPhases(graph, phases); | 50 runPhases(graph, phases); |
| 48 }); | 51 }); |
| 49 } | 52 } |
| 50 | 53 |
| 51 bool trySpeculativeOptimizations(WorkItem work, HGraph graph) { | 54 bool trySpeculativeOptimizations(WorkItem work, HGraph graph) { |
| 52 JavaScriptItemCompilationContext context = work.compilationContext; | 55 JavaScriptItemCompilationContext context = work.compilationContext; |
| 53 HTypeMap types = context.types; | 56 HTypeMap types = context.types; |
| 54 return measure(() { | 57 return measure(() { |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 } | 926 } |
| 924 while (instruction !== null) { | 927 while (instruction !== null) { |
| 925 HInstruction next = instruction.next; | 928 HInstruction next = instruction.next; |
| 926 int flags = instruction.getChangesFlags(); | 929 int flags = instruction.getChangesFlags(); |
| 927 assert(flags == 0 || !instruction.useGvn()); | 930 assert(flags == 0 || !instruction.useGvn()); |
| 928 values.kill(flags); | 931 values.kill(flags); |
| 929 if (instruction.useGvn()) { | 932 if (instruction.useGvn()) { |
| 930 HInstruction other = values.lookup(instruction); | 933 HInstruction other = values.lookup(instruction); |
| 931 if (other !== null) { | 934 if (other !== null) { |
| 932 assert(other.gvnEquals(instruction) && instruction.gvnEquals(other)); | 935 assert(other.gvnEquals(instruction) && instruction.gvnEquals(other)); |
| 933 block.rewrite(instruction, other); | 936 block.rewriteWithBetterUser(instruction, other); |
| 934 block.remove(instruction); | 937 block.remove(instruction); |
| 935 } else { | 938 } else { |
| 936 values.add(instruction); | 939 values.add(instruction); |
| 937 } | 940 } |
| 938 } | 941 } |
| 939 instruction = next; | 942 instruction = next; |
| 940 } | 943 } |
| 941 | 944 |
| 942 List<HBasicBlock> dominatedBlocks = block.dominatedBlocks; | 945 List<HBasicBlock> dominatedBlocks = block.dominatedBlocks; |
| 943 for (int i = 0, length = dominatedBlocks.length; i < length; i++) { | 946 for (int i = 0, length = dominatedBlocks.length; i < length; i++) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 List<HInstruction> list = instructions.toList(); | 1068 List<HInstruction> list = instructions.toList(); |
| 1066 for (HInstruction instruction in list) { | 1069 for (HInstruction instruction in list) { |
| 1067 // Move the instruction to the current block. | 1070 // Move the instruction to the current block. |
| 1068 instruction.block.detach(instruction); | 1071 instruction.block.detach(instruction); |
| 1069 block.moveAtExit(instruction); | 1072 block.moveAtExit(instruction); |
| 1070 // Go through all successors and rewrite their instruction | 1073 // Go through all successors and rewrite their instruction |
| 1071 // to the shared one. | 1074 // to the shared one. |
| 1072 for (final successor in successors) { | 1075 for (final successor in successors) { |
| 1073 HInstruction toRewrite = values[successor.id].lookup(instruction); | 1076 HInstruction toRewrite = values[successor.id].lookup(instruction); |
| 1074 if (toRewrite != instruction) { | 1077 if (toRewrite != instruction) { |
| 1075 successor.rewrite(toRewrite, instruction); | 1078 successor.rewriteWithBetterUser(toRewrite, instruction); |
| 1076 successor.remove(toRewrite); | 1079 successor.remove(toRewrite); |
| 1077 } | 1080 } |
| 1078 } | 1081 } |
| 1079 } | 1082 } |
| 1080 } | 1083 } |
| 1081 } | 1084 } |
| 1082 | 1085 |
| 1083 // Don't try to merge instructions to a dominator if we have | 1086 // Don't try to merge instructions to a dominator if we have |
| 1084 // multiple predecessors. | 1087 // multiple predecessors. |
| 1085 if (block.predecessors.length != 1) return; | 1088 if (block.predecessors.length != 1) return; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 // this type for the field is still a strong signal | 1332 // this type for the field is still a strong signal |
| 1330 // indicating the expected type of the field. | 1333 // indicating the expected type of the field. |
| 1331 types[field] = type; | 1334 types[field] = type; |
| 1332 } else { | 1335 } else { |
| 1333 // If there are no invoked setters we know the type of | 1336 // If there are no invoked setters we know the type of |
| 1334 // this field for sure. | 1337 // this field for sure. |
| 1335 field.guaranteedType = type; | 1338 field.guaranteedType = type; |
| 1336 } | 1339 } |
| 1337 } | 1340 } |
| 1338 } | 1341 } |
| OLD | NEW |