| 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 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 5 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
| 6 import '../common/names.dart' show Selectors; | 6 import '../common/names.dart' show Selectors; |
| 7 import '../common/tasks.dart' show CompilerTask; | 7 import '../common/tasks.dart' show CompilerTask; |
| 8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
| 9 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
| 10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
| (...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 if (value != null) { | 916 if (value != null) { |
| 917 return _graph.addConstant(value, _closedWorld); | 917 return _graph.addConstant(value, _closedWorld); |
| 918 } | 918 } |
| 919 } | 919 } |
| 920 } | 920 } |
| 921 | 921 |
| 922 return node; | 922 return node; |
| 923 } | 923 } |
| 924 | 924 |
| 925 HInstruction visitGetLength(HGetLength node) { | 925 HInstruction visitGetLength(HGetLength node) { |
| 926 var receiver = node.receiver; | 926 dynamic receiver = node.receiver; |
| 927 if (_graph.allocatedFixedLists.contains(receiver)) { | 927 if (_graph.allocatedFixedLists.contains(receiver)) { |
| 928 // TODO(ngeoffray): checking if the second input is an integer | 928 // TODO(ngeoffray): checking if the second input is an integer |
| 929 // should not be necessary but it currently makes it easier for | 929 // should not be necessary but it currently makes it easier for |
| 930 // other optimizations to reason about a fixed length constructor | 930 // other optimizations to reason about a fixed length constructor |
| 931 // that we know takes an int. | 931 // that we know takes an int. |
| 932 if (receiver.inputs[0].isInteger(_closedWorld)) { | 932 if (receiver.inputs[0].isInteger(_closedWorld)) { |
| 933 return receiver.inputs[0]; | 933 return receiver.inputs[0]; |
| 934 } | 934 } |
| 935 } else if (receiver.isConstantList() || receiver.isConstantString()) { | 935 } else if (receiver.isConstantList() || receiver.isConstantString()) { |
| 936 return _graph.addConstantInt(receiver.constant.length, _closedWorld); | 936 return _graph.addConstantInt(receiver.constant.length, _closedWorld); |
| 937 } else { | 937 } else { |
| 938 var type = receiver.instructionType; | 938 dynamic type = receiver.instructionType; |
| 939 if (type.isContainer && type.length != null) { | 939 if (type.isContainer && type.length != null) { |
| 940 HInstruction constant = | 940 HInstruction constant = |
| 941 _graph.addConstantInt(type.length, _closedWorld); | 941 _graph.addConstantInt(type.length, _closedWorld); |
| 942 if (type.isNullable) { | 942 if (type.isNullable) { |
| 943 // If the container can be null, we update all uses of the length | 943 // If the container can be null, we update all uses of the length |
| 944 // access to use the constant instead, but keep the length access in | 944 // access to use the constant instead, but keep the length access in |
| 945 // the graph, to ensure we still have a null check. | 945 // the graph, to ensure we still have a null check. |
| 946 node.block.rewrite(node, constant); | 946 node.block.rewrite(node, constant); |
| 947 return node; | 947 return node; |
| 948 } else { | 948 } else { |
| 949 return constant; | 949 return constant; |
| 950 } | 950 } |
| 951 } | 951 } |
| 952 } | 952 } |
| 953 | 953 |
| 954 if (node.isAssignable && | 954 if (node.isAssignable && |
| 955 isFixedLength(receiver.instructionType, _closedWorld)) { | 955 isFixedLength(receiver.instructionType, _closedWorld)) { |
| 956 // The input type has changed to fixed-length so change to an unassignable | 956 // The input type has changed to fixed-length so change to an unassignable |
| 957 // HGetLength to allow more GVN optimizations. | 957 // HGetLength to allow more GVN optimizations. |
| 958 return new HGetLength(receiver, node.instructionType, | 958 return new HGetLength(receiver, node.instructionType, |
| 959 isAssignable: false); | 959 isAssignable: false); |
| 960 } | 960 } |
| 961 return node; | 961 return node; |
| 962 } | 962 } |
| 963 | 963 |
| 964 HInstruction visitIndex(HIndex node) { | 964 HInstruction visitIndex(HIndex node) { |
| 965 if (node.receiver.isConstantList() && node.index.isConstantInteger()) { | 965 if (node.receiver.isConstantList() && node.index.isConstantInteger()) { |
| 966 var instruction = node.receiver; | 966 dynamic instruction = node.receiver; |
| 967 List<ConstantValue> entries = instruction.constant.entries; | 967 List<ConstantValue> entries = instruction.constant.entries; |
| 968 instruction = node.index; | 968 instruction = node.index; |
| 969 int index = instruction.constant.primitiveValue; | 969 int index = instruction.constant.primitiveValue; |
| 970 if (index >= 0 && index < entries.length) { | 970 if (index >= 0 && index < entries.length) { |
| 971 return _graph.addConstant(entries[index], _closedWorld); | 971 return _graph.addConstant(entries[index], _closedWorld); |
| 972 } | 972 } |
| 973 } | 973 } |
| 974 return node; | 974 return node; |
| 975 } | 975 } |
| 976 | 976 |
| (...skipping 2011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2988 | 2988 |
| 2989 keyedValues.forEach((receiver, values) { | 2989 keyedValues.forEach((receiver, values) { |
| 2990 result.keyedValues[receiver] = | 2990 result.keyedValues[receiver] = |
| 2991 new Map<HInstruction, HInstruction>.from(values); | 2991 new Map<HInstruction, HInstruction>.from(values); |
| 2992 }); | 2992 }); |
| 2993 | 2993 |
| 2994 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2994 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
| 2995 return result; | 2995 return result; |
| 2996 } | 2996 } |
| 2997 } | 2997 } |
| OLD | NEW |