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 part of ssa; | 5 part of ssa; |
6 | 6 |
7 abstract class OptimizationPhase { | 7 abstract class OptimizationPhase { |
8 String get name; | 8 String get name; |
9 void visitGraph(HGraph graph); | 9 void visitGraph(HGraph graph); |
10 } | 10 } |
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1236 return instruction is HGoto | 1236 return instruction is HGoto |
1237 || instruction.inputs[0].isConstantTrue(); | 1237 || instruction.inputs[0].isConstantTrue(); |
1238 } | 1238 } |
1239 bool firstInstructionInLoop = block == loopHeader | 1239 bool firstInstructionInLoop = block == loopHeader |
1240 // Compensate for lack of code motion. | 1240 // Compensate for lack of code motion. |
1241 || (blockChangesFlags[loopHeader.id] == 0 | 1241 || (blockChangesFlags[loopHeader.id] == 0 |
1242 && isLoopAlwaysTaken() | 1242 && isLoopAlwaysTaken() |
1243 && loopHeader.successors[0] == block); | 1243 && loopHeader.successors[0] == block); |
1244 while (instruction != null) { | 1244 while (instruction != null) { |
1245 HInstruction next = instruction.next; | 1245 HInstruction next = instruction.next; |
1246 if (instruction.useGvn() | 1246 if (instruction.useGvn() && instruction.isMovable |
1247 && (!instruction.canThrow() || firstInstructionInLoop) | 1247 && (!instruction.canThrow() || firstInstructionInLoop) |
1248 && !instruction.sideEffects.dependsOn(dependsFlags)) { | 1248 && !instruction.sideEffects.dependsOn(dependsFlags)) { |
1249 bool loopInvariantInputs = true; | 1249 bool loopInvariantInputs = true; |
1250 List<HInstruction> inputs = instruction.inputs; | 1250 List<HInstruction> inputs = instruction.inputs; |
1251 for (int i = 0, length = inputs.length; i < length; i++) { | 1251 for (int i = 0, length = inputs.length; i < length; i++) { |
1252 if (isInputDefinedAfterDominator(inputs[i], preheader)) { | 1252 if (isInputDefinedAfterDominator(inputs[i], preheader)) { |
1253 loopInvariantInputs = false; | 1253 loopInvariantInputs = false; |
1254 break; | 1254 break; |
1255 } | 1255 } |
1256 } | 1256 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1458 // which instructions can be moved to a dominator block. | 1458 // which instructions can be moved to a dominator block. |
1459 ValueSet set_ = values[block.id]; | 1459 ValueSet set_ = values[block.id]; |
1460 HInstruction instruction = block.first; | 1460 HInstruction instruction = block.first; |
1461 int flags = 0; | 1461 int flags = 0; |
1462 while (instruction != null) { | 1462 while (instruction != null) { |
1463 int dependsFlags = SideEffects.computeDependsOnFlags(flags); | 1463 int dependsFlags = SideEffects.computeDependsOnFlags(flags); |
1464 flags |= instruction.sideEffects.getChangesFlags(); | 1464 flags |= instruction.sideEffects.getChangesFlags(); |
1465 | 1465 |
1466 HInstruction current = instruction; | 1466 HInstruction current = instruction; |
1467 instruction = instruction.next; | 1467 instruction = instruction.next; |
1468 | 1468 if (!current.useGvn() || !current.isMovable) continue; |
1469 // TODO(ngeoffray): this check is needed because we currently do | |
1470 // not have flags to express 'Gvn'able', but not movable. | |
1471 if (current is HCheck) continue; | |
1472 if (!current.useGvn()) continue; | |
1473 if (current.sideEffects.dependsOn(dependsFlags)) continue; | 1469 if (current.sideEffects.dependsOn(dependsFlags)) continue; |
1474 | 1470 |
1475 bool canBeMoved = true; | 1471 bool canBeMoved = true; |
1476 for (final HInstruction input in current.inputs) { | 1472 for (final HInstruction input in current.inputs) { |
1477 if (input.block == block) { | 1473 if (input.block == block) { |
1478 canBeMoved = false; | 1474 canBeMoved = false; |
1479 break; | 1475 break; |
1480 } | 1476 } |
1481 } | 1477 } |
1482 if (!canBeMoved) continue; | 1478 if (!canBeMoved) continue; |
(...skipping 14 matching lines...) Expand all Loading... | |
1497 final String name = "SsaTypeconversionInserter"; | 1493 final String name = "SsaTypeconversionInserter"; |
1498 final Compiler compiler; | 1494 final Compiler compiler; |
1499 | 1495 |
1500 SsaTypeConversionInserter(this.compiler); | 1496 SsaTypeConversionInserter(this.compiler); |
1501 | 1497 |
1502 void visitGraph(HGraph graph) { | 1498 void visitGraph(HGraph graph) { |
1503 visitDominatorTree(graph); | 1499 visitDominatorTree(graph); |
1504 } | 1500 } |
1505 | 1501 |
1506 // Update users of [input] that are dominated by [:dominator.first:] | 1502 // Update users of [input] that are dominated by [:dominator.first:] |
1507 // to use [newInput] instead. | 1503 // to use [newInput] instead. As the type information depends on the |
1504 // control flow, we mark the inserted [HTypeKnown] nodes as non-movable. | |
1508 void changeUsesDominatedBy(HBasicBlock dominator, | 1505 void changeUsesDominatedBy(HBasicBlock dominator, |
floitsch
2014/03/20 16:07:25
Nit: we should change the name. It's not just chan
herhut
2014/03/20 16:25:11
It is now called [insertTypePropagationForDominate
| |
1509 HInstruction input, | 1506 HInstruction input, |
1510 TypeMask convertedType) { | 1507 TypeMask convertedType) { |
1511 Setlet<HInstruction> dominatedUsers = input.dominatedUsers(dominator.first); | 1508 Setlet<HInstruction> dominatedUsers = input.dominatedUsers(dominator.first); |
1512 if (dominatedUsers.isEmpty) return; | 1509 if (dominatedUsers.isEmpty) return; |
1513 | 1510 |
1514 HTypeKnown newInput = new HTypeKnown(convertedType, input); | 1511 HTypeKnown newInput = new HTypeKnown.pinned(convertedType, input); |
1515 dominator.addBefore(dominator.first, newInput); | 1512 dominator.addBefore(dominator.first, newInput); |
1516 dominatedUsers.forEach((HInstruction user) { | 1513 dominatedUsers.forEach((HInstruction user) { |
1517 user.changeUse(input, newInput); | 1514 user.changeUse(input, newInput); |
1518 }); | 1515 }); |
1519 } | 1516 } |
1520 | 1517 |
1521 void visitIs(HIs instruction) { | 1518 void visitIs(HIs instruction) { |
1522 DartType type = instruction.typeExpression; | 1519 DartType type = instruction.typeExpression; |
1523 Element element = type.element; | 1520 Element element = type.element; |
1524 if (!instruction.isRawCheck) { | 1521 if (!instruction.isRawCheck) { |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2031 | 2028 |
2032 keyedValues.forEach((receiver, values) { | 2029 keyedValues.forEach((receiver, values) { |
2033 result.keyedValues[receiver] = | 2030 result.keyedValues[receiver] = |
2034 new Map<HInstruction, HInstruction>.from(values); | 2031 new Map<HInstruction, HInstruction>.from(values); |
2035 }); | 2032 }); |
2036 | 2033 |
2037 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2034 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
2038 return result; | 2035 return result; |
2039 } | 2036 } |
2040 } | 2037 } |
OLD | NEW |