| 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 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 (HInstruction user in to.usedBy) { |
| 624 if (user is HCheck && identical((user as HCheck).checkedInput, to)) { | 624 if (user == from || user is! HCheck) continue; |
| 625 HCheck check = user; |
| 626 if (check.checkedInput == to) { |
| 625 better = better.prepend(user); | 627 better = better.prepend(user); |
| 626 } | 628 } |
| 627 } | 629 } |
| 628 | 630 |
| 629 if (better.isEmpty) return rewrite(from, to); | 631 if (better.isEmpty) return rewrite(from, to); |
| 630 | 632 |
| 631 L1: for (HInstruction user in from.usedBy) { | 633 L1: for (HInstruction user in from.usedBy) { |
| 632 for (HCheck check in better) { | 634 for (HCheck check in better) { |
| 633 if (check.dominates(user)) { | 635 if (check.dominates(user)) { |
| 634 user.rewriteInput(from, check); | 636 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 | 814 * A pure instruction is an instruction that does not have any side |
| 813 * effect, nor any dependency. They can be moved anywhere in the | 815 * effect, nor any dependency. They can be moved anywhere in the |
| 814 * graph. | 816 * graph. |
| 815 */ | 817 */ |
| 816 bool isPure() { | 818 bool isPure() { |
| 817 return !sideEffects.hasSideEffects() | 819 return !sideEffects.hasSideEffects() |
| 818 && !sideEffects.dependsOnSomething() | 820 && !sideEffects.dependsOnSomething() |
| 819 && !canThrow(); | 821 && !canThrow(); |
| 820 } | 822 } |
| 821 | 823 |
| 824 // Overridden by [HCheck] to return the actual non-[HCheck] |
| 825 // instruction it checks against. |
| 826 HInstruction nonCheck() => this; |
| 827 |
| 822 // Can this node throw an exception? | 828 // Can this node throw an exception? |
| 823 bool canThrow() => false; | 829 bool canThrow() => false; |
| 824 | 830 |
| 825 // Does this node potentially affect control flow. | 831 // Does this node potentially affect control flow. |
| 826 bool isControlFlow() => false; | 832 bool isControlFlow() => false; |
| 827 | 833 |
| 828 // All isFunctions work on the propagated types. | 834 // All isFunctions work on the propagated types. |
| 829 bool isArray(Compiler compiler) => | 835 bool isArray(Compiler compiler) => |
| 830 instructionType.isArray(compiler); | 836 instructionType.isArray(compiler); |
| 831 bool isReadableArray(Compiler compiler) => | 837 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. | 900 // Check that the type and the sideEffects match. |
| 895 bool hasSameType = typeEquals(other); | 901 bool hasSameType = typeEquals(other); |
| 896 assert(hasSameType == (typeCode() == other.typeCode())); | 902 assert(hasSameType == (typeCode() == other.typeCode())); |
| 897 if (!hasSameType) return false; | 903 if (!hasSameType) return false; |
| 898 if (sideEffects != other.sideEffects) return false; | 904 if (sideEffects != other.sideEffects) return false; |
| 899 // Check that the inputs match. | 905 // Check that the inputs match. |
| 900 final int inputsLength = inputs.length; | 906 final int inputsLength = inputs.length; |
| 901 final List<HInstruction> otherInputs = other.inputs; | 907 final List<HInstruction> otherInputs = other.inputs; |
| 902 if (inputsLength != otherInputs.length) return false; | 908 if (inputsLength != otherInputs.length) return false; |
| 903 for (int i = 0; i < inputsLength; i++) { | 909 for (int i = 0; i < inputsLength; i++) { |
| 904 if (!identical(inputs[i], otherInputs[i])) return false; | 910 if (!identical(inputs[i].nonCheck(), otherInputs[i].nonCheck())) { |
| 911 return false; |
| 912 } |
| 905 } | 913 } |
| 906 // Check that the data in the instruction matches. | 914 // Check that the data in the instruction matches. |
| 907 return dataEquals(other); | 915 return dataEquals(other); |
| 908 } | 916 } |
| 909 | 917 |
| 910 int gvnHashCode() { | 918 int gvnHashCode() { |
| 911 int result = typeCode(); | 919 int result = typeCode(); |
| 912 int length = inputs.length; | 920 int length = inputs.length; |
| 913 for (int i = 0; i < length; i++) { | 921 for (int i = 0; i < length; i++) { |
| 914 result = (result * 19) + (inputs[i].id) + (result >> 7); | 922 result = (result * 19) + (inputs[i].nonCheck().id) + (result >> 7); |
| 915 } | 923 } |
| 916 return result; | 924 return result; |
| 917 } | 925 } |
| 918 | 926 |
| 919 // These methods should be overwritten by instructions that | 927 // These methods should be overwritten by instructions that |
| 920 // participate in global value numbering. | 928 // participate in global value numbering. |
| 921 int typeCode() => HInstruction.UNDEFINED_TYPECODE; | 929 int typeCode() => HInstruction.UNDEFINED_TYPECODE; |
| 922 bool typeEquals(HInstruction other) => false; | 930 bool typeEquals(HInstruction other) => false; |
| 923 bool dataEquals(HInstruction other) => false; | 931 bool dataEquals(HInstruction other) => false; |
| 924 | 932 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 * instruction itself. | 1159 * instruction itself. |
| 1152 */ | 1160 */ |
| 1153 abstract class HCheck extends HInstruction { | 1161 abstract class HCheck extends HInstruction { |
| 1154 HCheck(inputs) : super(inputs) { | 1162 HCheck(inputs) : super(inputs) { |
| 1155 setUseGvn(); | 1163 setUseGvn(); |
| 1156 } | 1164 } |
| 1157 HInstruction get checkedInput => inputs[0]; | 1165 HInstruction get checkedInput => inputs[0]; |
| 1158 bool isJsStatement() => true; | 1166 bool isJsStatement() => true; |
| 1159 bool canThrow() => true; | 1167 bool canThrow() => true; |
| 1160 | 1168 |
| 1161 HInstruction unwrap() { | 1169 HInstruction nonCheck() => checkedInput.nonCheck(); |
| 1162 var checked = checkedInput; | |
| 1163 while (checked is HCheck) checked = checked.checkedInput; | |
| 1164 return checked; | |
| 1165 } | |
| 1166 } | 1170 } |
| 1167 | 1171 |
| 1168 class HBailoutTarget extends HInstruction { | 1172 class HBailoutTarget extends HInstruction { |
| 1169 final int state; | 1173 final int state; |
| 1170 bool isEnabled = true; | 1174 bool isEnabled = true; |
| 1171 // For each argument we record how many dummy (unused) arguments should | 1175 // 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 | 1176 // precede it, to make sure it lands in the correctly named parameter in the |
| 1173 // bailout function. | 1177 // bailout function. |
| 1174 List<int> padding; | 1178 List<int> padding; |
| 1175 HBailoutTarget(this.state) : super(<HInstruction>[]) { | 1179 HBailoutTarget(this.state) : super(<HInstruction>[]) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 /** | 1317 /** |
| 1314 * Returns whether this call is on an interceptor object. | 1318 * Returns whether this call is on an interceptor object. |
| 1315 */ | 1319 */ |
| 1316 bool isCallOnInterceptor(Compiler compiler) { | 1320 bool isCallOnInterceptor(Compiler compiler) { |
| 1317 return isInterceptedCall && receiver.isInterceptor(compiler); | 1321 return isInterceptedCall && receiver.isInterceptor(compiler); |
| 1318 } | 1322 } |
| 1319 | 1323 |
| 1320 int typeCode() => HInstruction.INVOKE_DYNAMIC_TYPECODE; | 1324 int typeCode() => HInstruction.INVOKE_DYNAMIC_TYPECODE; |
| 1321 bool typeEquals(other) => other is HInvokeDynamic; | 1325 bool typeEquals(other) => other is HInvokeDynamic; |
| 1322 bool dataEquals(HInvokeDynamic other) { | 1326 bool dataEquals(HInvokeDynamic other) { |
| 1323 return selector == other.selector && element == other.element; | 1327 // Use the name and the kind instead of [Selector.operator==] |
| 1328 // because we don't need to check the arity (already checked in |
| 1329 // [gvnEquals]), and the receiver types may not be in sync. |
| 1330 return selector.name == other.selector.name |
| 1331 && selector.kind == other.selector.kind; |
| 1324 } | 1332 } |
| 1325 } | 1333 } |
| 1326 | 1334 |
| 1327 class HInvokeClosure extends HInvokeDynamic { | 1335 class HInvokeClosure extends HInvokeDynamic { |
| 1328 HInvokeClosure(Selector selector, List<HInstruction> inputs) | 1336 HInvokeClosure(Selector selector, List<HInstruction> inputs) |
| 1329 : super(selector, null, inputs) { | 1337 : super(selector, null, inputs) { |
| 1330 assert(selector.isClosureCall()); | 1338 assert(selector.isClosureCall()); |
| 1331 } | 1339 } |
| 1332 accept(HVisitor visitor) => visitor.visitInvokeClosure(this); | 1340 accept(HVisitor visitor) => visitor.visitInvokeClosure(this); |
| 1333 } | 1341 } |
| (...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2675 HBasicBlock get start => expression.start; | 2683 HBasicBlock get start => expression.start; |
| 2676 HBasicBlock get end { | 2684 HBasicBlock get end { |
| 2677 // We don't create a switch block if there are no cases. | 2685 // We don't create a switch block if there are no cases. |
| 2678 assert(!statements.isEmpty); | 2686 assert(!statements.isEmpty); |
| 2679 return statements.last.end; | 2687 return statements.last.end; |
| 2680 } | 2688 } |
| 2681 | 2689 |
| 2682 bool accept(HStatementInformationVisitor visitor) => | 2690 bool accept(HStatementInformationVisitor visitor) => |
| 2683 visitor.visitSwitchInfo(this); | 2691 visitor.visitSwitchInfo(this); |
| 2684 } | 2692 } |
| OLD | NEW |