Chromium Code Reviews| 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 HVisitor<R> { | 7 abstract class HVisitor<R> { |
| 8 R visitAdd(HAdd node); | 8 R visitAdd(HAdd node); |
| 9 R visitBailoutTarget(HBailoutTarget node); | 9 R visitBailoutTarget(HBailoutTarget node); |
| 10 R visitBitAnd(HBitAnd node); | 10 R visitBitAnd(HBitAnd node); |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 from.usedBy.clear(); | 613 from.usedBy.clear(); |
| 614 } | 614 } |
| 615 | 615 |
| 616 /** | 616 /** |
| 617 * Rewrites all uses of the [from] instruction to using either the | 617 * Rewrites all uses of the [from] instruction to using either the |
| 618 * [to] instruction, or a [HCheck] instruction that has better type | 618 * [to] instruction, or a [HCheck] instruction that has better type |
| 619 * information on [to], and that dominates the user. | 619 * information on [to], and that dominates the user. |
| 620 */ | 620 */ |
| 621 void rewriteWithBetterUser(HInstruction from, HInstruction to) { | 621 void rewriteWithBetterUser(HInstruction from, HInstruction to) { |
| 622 Link<HCheck> better = const Link<HCheck>(); | 622 Link<HCheck> better = const Link<HCheck>(); |
| 623 for (HInstruction user in to.usedBy) { | 623 for (var user in to.usedBy) { |
| 624 if (user is HCheck && identical((user as HCheck).checkedInput, to)) { | 624 if (user != from && user is HCheck && user.checkedInput == to) { |
|
karlklose
2013/06/12 13:12:38
I would prefer:
for (HInstruction user in to.usedB
ngeoffray
2013/06/12 13:55:09
Done.
| |
| 625 better = better.prepend(user); | 625 better = better.prepend(user); |
| 626 } | 626 } |
| 627 } | 627 } |
| 628 | 628 |
| 629 if (better.isEmpty) return rewrite(from, to); | 629 if (better.isEmpty) return rewrite(from, to); |
| 630 | 630 |
| 631 L1: for (HInstruction user in from.usedBy) { | 631 L1: for (HInstruction user in from.usedBy) { |
| 632 for (HCheck check in better) { | 632 for (HCheck check in better) { |
| 633 if (check.dominates(user)) { | 633 if (check.dominates(user)) { |
| 634 user.rewriteInput(from, check); | 634 user.rewriteInput(from, check); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 812 * A pure instruction is an instruction that does not have any side | 812 * A pure instruction is an instruction that does not have any side |
| 813 * effect, nor any dependency. They can be moved anywhere in the | 813 * effect, nor any dependency. They can be moved anywhere in the |
| 814 * graph. | 814 * graph. |
| 815 */ | 815 */ |
| 816 bool isPure() { | 816 bool isPure() { |
| 817 return !sideEffects.hasSideEffects() | 817 return !sideEffects.hasSideEffects() |
| 818 && !sideEffects.dependsOnSomething() | 818 && !sideEffects.dependsOnSomething() |
| 819 && !canThrow(); | 819 && !canThrow(); |
| 820 } | 820 } |
| 821 | 821 |
| 822 // Overridden by [HCheck] to return the actual non-[HCheck] | |
| 823 // instruction it checks against. | |
| 824 HInstruction nonCheck() => this; | |
| 825 | |
| 822 // Can this node throw an exception? | 826 // Can this node throw an exception? |
| 823 bool canThrow() => false; | 827 bool canThrow() => false; |
| 824 | 828 |
| 825 // Does this node potentially affect control flow. | 829 // Does this node potentially affect control flow. |
| 826 bool isControlFlow() => false; | 830 bool isControlFlow() => false; |
| 827 | 831 |
| 828 // All isFunctions work on the propagated types. | 832 // All isFunctions work on the propagated types. |
| 829 bool isArray(Compiler compiler) => | 833 bool isArray(Compiler compiler) => |
| 830 instructionType.isArray(compiler); | 834 instructionType.isArray(compiler); |
| 831 bool isReadableArray(Compiler compiler) => | 835 bool isReadableArray(Compiler compiler) => |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 // Check that the type and the sideEffects match. | 898 // Check that the type and the sideEffects match. |
| 895 bool hasSameType = typeEquals(other); | 899 bool hasSameType = typeEquals(other); |
| 896 assert(hasSameType == (typeCode() == other.typeCode())); | 900 assert(hasSameType == (typeCode() == other.typeCode())); |
| 897 if (!hasSameType) return false; | 901 if (!hasSameType) return false; |
| 898 if (sideEffects != other.sideEffects) return false; | 902 if (sideEffects != other.sideEffects) return false; |
| 899 // Check that the inputs match. | 903 // Check that the inputs match. |
| 900 final int inputsLength = inputs.length; | 904 final int inputsLength = inputs.length; |
| 901 final List<HInstruction> otherInputs = other.inputs; | 905 final List<HInstruction> otherInputs = other.inputs; |
| 902 if (inputsLength != otherInputs.length) return false; | 906 if (inputsLength != otherInputs.length) return false; |
| 903 for (int i = 0; i < inputsLength; i++) { | 907 for (int i = 0; i < inputsLength; i++) { |
| 904 if (!identical(inputs[i], otherInputs[i])) return false; | 908 if (!identical(inputs[i].nonCheck(), otherInputs[i].nonCheck())) { |
| 909 return false; | |
| 910 } | |
| 905 } | 911 } |
| 906 // Check that the data in the instruction matches. | 912 // Check that the data in the instruction matches. |
| 907 return dataEquals(other); | 913 return dataEquals(other); |
| 908 } | 914 } |
| 909 | 915 |
| 910 int gvnHashCode() { | 916 int gvnHashCode() { |
| 911 int result = typeCode(); | 917 int result = typeCode(); |
| 912 int length = inputs.length; | 918 int length = inputs.length; |
| 913 for (int i = 0; i < length; i++) { | 919 for (int i = 0; i < length; i++) { |
| 914 result = (result * 19) + (inputs[i].id) + (result >> 7); | 920 result = (result * 19) + (inputs[i].nonCheck().id) + (result >> 7); |
| 915 } | 921 } |
| 916 return result; | 922 return result; |
| 917 } | 923 } |
| 918 | 924 |
| 919 // These methods should be overwritten by instructions that | 925 // These methods should be overwritten by instructions that |
| 920 // participate in global value numbering. | 926 // participate in global value numbering. |
| 921 int typeCode() => HInstruction.UNDEFINED_TYPECODE; | 927 int typeCode() => HInstruction.UNDEFINED_TYPECODE; |
| 922 bool typeEquals(HInstruction other) => false; | 928 bool typeEquals(HInstruction other) => false; |
| 923 bool dataEquals(HInstruction other) => false; | 929 bool dataEquals(HInstruction other) => false; |
| 924 | 930 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1151 * instruction itself. | 1157 * instruction itself. |
| 1152 */ | 1158 */ |
| 1153 abstract class HCheck extends HInstruction { | 1159 abstract class HCheck extends HInstruction { |
| 1154 HCheck(inputs) : super(inputs) { | 1160 HCheck(inputs) : super(inputs) { |
| 1155 setUseGvn(); | 1161 setUseGvn(); |
| 1156 } | 1162 } |
| 1157 HInstruction get checkedInput => inputs[0]; | 1163 HInstruction get checkedInput => inputs[0]; |
| 1158 bool isJsStatement() => true; | 1164 bool isJsStatement() => true; |
| 1159 bool canThrow() => true; | 1165 bool canThrow() => true; |
| 1160 | 1166 |
| 1161 HInstruction unwrap() { | 1167 HInstruction nonCheck() => checkedInput.nonCheck(); |
| 1162 var checked = checkedInput; | |
| 1163 while (checked is HCheck) checked = checked.checkedInput; | |
| 1164 return checked; | |
| 1165 } | |
| 1166 } | 1168 } |
| 1167 | 1169 |
| 1168 class HBailoutTarget extends HInstruction { | 1170 class HBailoutTarget extends HInstruction { |
| 1169 final int state; | 1171 final int state; |
| 1170 bool isEnabled = true; | 1172 bool isEnabled = true; |
| 1171 // For each argument we record how many dummy (unused) arguments should | 1173 // For each argument we record how many dummy (unused) arguments should |
| 1172 // precede it, to make sure it lands in the correctly named parameter in the | 1174 // precede it, to make sure it lands in the correctly named parameter in the |
| 1173 // bailout function. | 1175 // bailout function. |
| 1174 List<int> padding; | 1176 List<int> padding; |
| 1175 HBailoutTarget(this.state) : super(<HInstruction>[]) { | 1177 HBailoutTarget(this.state) : super(<HInstruction>[]) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1313 /** | 1315 /** |
| 1314 * Returns whether this call is on an interceptor object. | 1316 * Returns whether this call is on an interceptor object. |
| 1315 */ | 1317 */ |
| 1316 bool isCallOnInterceptor(Compiler compiler) { | 1318 bool isCallOnInterceptor(Compiler compiler) { |
| 1317 return isInterceptedCall && receiver.isInterceptor(compiler); | 1319 return isInterceptedCall && receiver.isInterceptor(compiler); |
| 1318 } | 1320 } |
| 1319 | 1321 |
| 1320 int typeCode() => HInstruction.INVOKE_DYNAMIC_TYPECODE; | 1322 int typeCode() => HInstruction.INVOKE_DYNAMIC_TYPECODE; |
| 1321 bool typeEquals(other) => other is HInvokeDynamic; | 1323 bool typeEquals(other) => other is HInvokeDynamic; |
| 1322 bool dataEquals(HInvokeDynamic other) { | 1324 bool dataEquals(HInvokeDynamic other) { |
| 1323 return selector == other.selector && element == other.element; | 1325 return selector.name == other.selector.name; |
|
Johnni Winther
2013/06/12 11:06:08
Why not [: selector == other.selector :] ?
ngeoffray
2013/06/12 13:55:09
Because if we end up here, we know the receiver is
| |
| 1324 } | 1326 } |
| 1325 } | 1327 } |
| 1326 | 1328 |
| 1327 class HInvokeClosure extends HInvokeDynamic { | 1329 class HInvokeClosure extends HInvokeDynamic { |
| 1328 HInvokeClosure(Selector selector, List<HInstruction> inputs) | 1330 HInvokeClosure(Selector selector, List<HInstruction> inputs) |
| 1329 : super(selector, null, inputs) { | 1331 : super(selector, null, inputs) { |
| 1330 assert(selector.isClosureCall()); | 1332 assert(selector.isClosureCall()); |
| 1331 } | 1333 } |
| 1332 accept(HVisitor visitor) => visitor.visitInvokeClosure(this); | 1334 accept(HVisitor visitor) => visitor.visitInvokeClosure(this); |
| 1333 } | 1335 } |
| (...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2675 HBasicBlock get start => expression.start; | 2677 HBasicBlock get start => expression.start; |
| 2676 HBasicBlock get end { | 2678 HBasicBlock get end { |
| 2677 // We don't create a switch block if there are no cases. | 2679 // We don't create a switch block if there are no cases. |
| 2678 assert(!statements.isEmpty); | 2680 assert(!statements.isEmpty); |
| 2679 return statements.last.end; | 2681 return statements.last.end; |
| 2680 } | 2682 } |
| 2681 | 2683 |
| 2682 bool accept(HStatementInformationVisitor visitor) => | 2684 bool accept(HStatementInformationVisitor visitor) => |
| 2683 visitor.visitSwitchInfo(this); | 2685 visitor.visitSwitchInfo(this); |
| 2684 } | 2686 } |
| OLD | NEW |