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 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1348 ? HType.INDEXABLE_PRIMITIVE | 1348 ? HType.INDEXABLE_PRIMITIVE |
1349 : HType.MUTABLE_ARRAY; | 1349 : HType.MUTABLE_ARRAY; |
1350 } | 1350 } |
1351 // The index should be an int when the receiver is a string or array. | 1351 // The index should be an int when the receiver is a string or array. |
1352 // However it turns out that inserting an integer check in the optimized | 1352 // However it turns out that inserting an integer check in the optimized |
1353 // version is cheaper than having another bailout case. This is true, | 1353 // version is cheaper than having another bailout case. This is true, |
1354 // because the integer check will simply throw if it fails. | 1354 // because the integer check will simply throw if it fails. |
1355 return HType.UNKNOWN; | 1355 return HType.UNKNOWN; |
1356 } else if (selector.kind == SelectorKind.OPERATOR) { | 1356 } else if (selector.kind == SelectorKind.OPERATOR) { |
1357 HType propagatedType = types[this]; | 1357 HType propagatedType = types[this]; |
1358 if (selector.name == const SourceString('-') && input == inputs[1]) { | 1358 if (selector.name == const SourceString('unary-') && input == inputs[1]) { |
1359 // If the outgoing type should be a number (integer, double or both) we | 1359 // If the outgoing type should be a number (integer, double or both) we |
1360 // want the outgoing type to be the input too. | 1360 // want the outgoing type to be the input too. |
1361 // If we don't know the outgoing type we try to make it a number. | 1361 // If we don't know the outgoing type we try to make it a number. |
1362 if (propagatedType.isNumber()) return propagatedType; | 1362 if (propagatedType.isNumber()) return propagatedType; |
1363 if (propagatedType.isUnknown()) return HType.NUMBER; | 1363 if (propagatedType.isUnknown()) return HType.NUMBER; |
1364 } else if (selector.name == const SourceString('~') | 1364 } else if (selector.name == const SourceString('~') |
1365 && input == inputs[1]) { | 1365 && input == inputs[1]) { |
1366 if (propagatedType.isUnknown() || propagatedType.isNumber()) { | 1366 if (propagatedType.isUnknown() || propagatedType.isNumber()) { |
1367 return HType.INTEGER; | 1367 return HType.INTEGER; |
1368 } | 1368 } |
1369 } | 1369 } |
1370 return HType.UNKNOWN; | 1370 return HType.UNKNOWN; |
1371 } | 1371 } |
1372 return HType.UNKNOWN; | 1372 return HType.UNKNOWN; |
1373 } | 1373 } |
1374 | 1374 |
1375 HType computeTypeFromInputTypes(HTypeMap types, Compiler compiler) { | 1375 HType computeTypeFromInputTypes(HTypeMap types, Compiler compiler) { |
1376 // TODO(ngeoffray): Move this logic into a different class that | 1376 // TODO(ngeoffray): Move this logic into a different class that |
1377 // will know what type it has for a given selector. | 1377 // will know what type it has for a given selector. |
1378 if (!isInterceptorCall) return HType.UNKNOWN; | 1378 if (!isInterceptorCall) return HType.UNKNOWN; |
1379 | 1379 |
1380 if (selector.kind == SelectorKind.OPERATOR) { | 1380 if (selector.kind == SelectorKind.OPERATOR) { |
1381 if (selector.name == const SourceString('-')) { | 1381 if (selector.name == const SourceString('unary-')) { |
1382 HType operandType = types[inputs[1]]; | 1382 HType operandType = types[inputs[1]]; |
1383 if (operandType.isNumber()) return operandType; | 1383 if (operandType.isNumber()) return operandType; |
1384 } else if (selector.name == const SourceString('~')) { | 1384 } else if (selector.name == const SourceString('~')) { |
1385 // All bitwise operations on primitive types either produce an | 1385 // All bitwise operations on primitive types either produce an |
1386 // integer or throw an error. | 1386 // integer or throw an error. |
1387 if (inputs[1].isPrimitive(types)) return HType.INTEGER; | 1387 if (inputs[1].isPrimitive(types)) return HType.INTEGER; |
1388 } | 1388 } |
1389 } | 1389 } |
1390 return HType.UNKNOWN; | 1390 return HType.UNKNOWN; |
1391 } | 1391 } |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2396 : super(<HInstruction>[receiver]); | 2396 : super(<HInstruction>[receiver]); |
2397 String toString() => 'interceptor on $interceptedClasses'; | 2397 String toString() => 'interceptor on $interceptedClasses'; |
2398 accept(HVisitor visitor) => visitor.visitInterceptor(this); | 2398 accept(HVisitor visitor) => visitor.visitInterceptor(this); |
2399 HInstruction get receiver => inputs[0]; | 2399 HInstruction get receiver => inputs[0]; |
2400 | 2400 |
2401 void prepareGvn(HTypeMap types) { | 2401 void prepareGvn(HTypeMap types) { |
2402 clearAllSideEffects(); | 2402 clearAllSideEffects(); |
2403 setUseGvn(); | 2403 setUseGvn(); |
2404 } | 2404 } |
2405 | 2405 |
2406 HType computeDesiredTypeForInput(HInstruction input, | |
2407 HTypeMap types, | |
2408 Compiler compiler) { | |
ngeoffray
2013/01/15 10:32:27
This was the main reason for the unit test to fail
| |
2409 if (interceptedClasses.length != 1) return HType.UNKNOWN; | |
2410 // If the only class being intercepted is of type number, we | |
2411 // make this interceptor call say it wants that class as input. | |
2412 Element interceptor = interceptedClasses.toList()[0]; | |
2413 JavaScriptBackend backend = compiler.backend; | |
2414 if (interceptor == backend.jsNumberClass) { | |
2415 return HType.NUMBER; | |
2416 } else if (interceptor == backend.jsIntClass) { | |
2417 return HType.INTEGER; | |
2418 } else if (interceptor == backend.jsDoubleClass) { | |
2419 return HType.DOUBLE; | |
2420 } | |
2421 return HType.UNKNOWN; | |
2422 } | |
2423 | |
2406 int typeCode() => HInstruction.INTERCEPTOR_TYPECODE; | 2424 int typeCode() => HInstruction.INTERCEPTOR_TYPECODE; |
2407 bool typeEquals(other) => other is HInterceptor; | 2425 bool typeEquals(other) => other is HInterceptor; |
2408 bool dataEquals(HInterceptor other) { | 2426 bool dataEquals(HInterceptor other) { |
2409 return interceptedClasses == other.interceptedClasses | 2427 return interceptedClasses == other.interceptedClasses |
2410 || (interceptedClasses.length == other.interceptedClasses.length | 2428 || (interceptedClasses.length == other.interceptedClasses.length |
2411 && interceptedClasses.containsAll(other.interceptedClasses)); | 2429 && interceptedClasses.containsAll(other.interceptedClasses)); |
2412 } | 2430 } |
2413 } | 2431 } |
2414 | 2432 |
2415 /** An [HLazyStatic] is a static that is initialized lazily at first read. */ | 2433 /** An [HLazyStatic] is a static that is initialized lazily at first read. */ |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2915 HBasicBlock get start => expression.start; | 2933 HBasicBlock get start => expression.start; |
2916 HBasicBlock get end { | 2934 HBasicBlock get end { |
2917 // We don't create a switch block if there are no cases. | 2935 // We don't create a switch block if there are no cases. |
2918 assert(!statements.isEmpty); | 2936 assert(!statements.isEmpty); |
2919 return statements.last.end; | 2937 return statements.last.end; |
2920 } | 2938 } |
2921 | 2939 |
2922 bool accept(HStatementInformationVisitor visitor) => | 2940 bool accept(HStatementInformationVisitor visitor) => |
2923 visitor.visitSwitchInfo(this); | 2941 visitor.visitSwitchInfo(this); |
2924 } | 2942 } |
OLD | NEW |