OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 7 /** |
8 * [InvokeDynamicSpecializer] and its subclasses are helpers to | 8 * [InvokeDynamicSpecializer] and its subclasses are helpers to |
9 * optimize intercepted dynamic calls. It knows what input types | 9 * optimize intercepted dynamic calls. It knows what input types |
10 * would be beneficial for performance, and how to change a invoke | 10 * would be beneficial for performance, and how to change a invoke |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 UnaryOperation operation(ConstantSystem constantSystem) { | 128 UnaryOperation operation(ConstantSystem constantSystem) { |
129 return constantSystem.bitNot; | 129 return constantSystem.bitNot; |
130 } | 130 } |
131 | 131 |
132 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, | 132 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, |
133 Compiler compiler) { | 133 Compiler compiler) { |
134 // All bitwise operations on primitive types either produce an | 134 // All bitwise operations on primitive types either produce an |
135 // integer or throw an error. | 135 // integer or throw an error. |
136 JavaScriptBackend backend = compiler.backend; | 136 JavaScriptBackend backend = compiler.backend; |
137 if (instruction.inputs[1].isPrimitiveOrNull(compiler)) { | 137 if (instruction.inputs[1].isPrimitiveOrNull(compiler)) { |
138 return backend.intType; | 138 return backend.uint32Type; |
139 } | 139 } |
140 return super.computeTypeFromInputTypes(instruction, compiler); | 140 return super.computeTypeFromInputTypes(instruction, compiler); |
141 } | 141 } |
142 | 142 |
143 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, | 143 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, |
144 Compiler compiler) { | 144 Compiler compiler) { |
145 JavaScriptBackend backend = compiler.backend; | 145 JavaScriptBackend backend = compiler.backend; |
146 HInstruction input = instruction.inputs[1]; | 146 HInstruction input = instruction.inputs[1]; |
147 if (input.isNumber(compiler)) { | 147 if (input.isNumber(compiler)) { |
148 return new HBitNot(input, instruction.selector, backend.intType); | 148 return new HBitNot(input, instruction.selector, |
149 computeTypeFromInputTypes(instruction, compiler)); | |
149 } | 150 } |
150 return null; | 151 return null; |
151 } | 152 } |
152 } | 153 } |
153 | 154 |
154 class UnaryNegateSpecializer extends InvokeDynamicSpecializer { | 155 class UnaryNegateSpecializer extends InvokeDynamicSpecializer { |
155 const UnaryNegateSpecializer(); | 156 const UnaryNegateSpecializer(); |
156 | 157 |
157 UnaryOperation operation(ConstantSystem constantSystem) { | 158 UnaryOperation operation(ConstantSystem constantSystem) { |
158 return constantSystem.negate; | 159 return constantSystem.negate; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 abstract class BinaryBitOpSpecializer extends BinaryArithmeticSpecializer { | 325 abstract class BinaryBitOpSpecializer extends BinaryArithmeticSpecializer { |
325 const BinaryBitOpSpecializer(); | 326 const BinaryBitOpSpecializer(); |
326 | 327 |
327 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, | 328 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, |
328 Compiler compiler) { | 329 Compiler compiler) { |
329 // All bitwise operations on primitive types either produce an | 330 // All bitwise operations on primitive types either produce an |
330 // integer or throw an error. | 331 // integer or throw an error. |
331 HInstruction left = instruction.inputs[1]; | 332 HInstruction left = instruction.inputs[1]; |
332 JavaScriptBackend backend = compiler.backend; | 333 JavaScriptBackend backend = compiler.backend; |
333 if (left.isPrimitiveOrNull(compiler)) { | 334 if (left.isPrimitiveOrNull(compiler)) { |
334 return backend.intType; | 335 return backend.uint32Type; |
335 } | 336 } |
336 return super.computeTypeFromInputTypes(instruction, compiler); | 337 return super.computeTypeFromInputTypes(instruction, compiler); |
337 } | 338 } |
338 | 339 |
339 bool argumentLessThan32(HInstruction instruction) { | 340 bool argumentLessThan32(HInstruction instruction) { |
340 if (!instruction.isConstantInteger()) return false; | 341 if (!instruction.isConstantInteger()) return false; |
341 HConstant rightConstant = instruction; | 342 HConstant rightConstant = instruction; |
342 IntConstant intConstant = rightConstant.constant; | 343 IntConstant intConstant = rightConstant.constant; |
343 int count = intConstant.value; | 344 int count = intConstant.value; |
344 return count >= 0 && count <= 31; | 345 return count >= 0 && count <= 31; |
345 } | 346 } |
346 | 347 |
347 bool isPositive(HInstruction instruction) { | 348 bool isPositive(HInstruction instruction, Compiler compiler) { |
348 // TODO: We should use the value range analysis. Currently, ranges | 349 // TODO: We should use the value range analysis. Currently, ranges |
349 // are discarded just after the analysis. | 350 // are discarded just after the analysis. |
350 return instruction is HBinaryBitOp; | 351 return instruction.isUInt32(compiler); |
351 } | 352 } |
352 } | 353 } |
353 | 354 |
354 class ShiftLeftSpecializer extends BinaryBitOpSpecializer { | 355 class ShiftLeftSpecializer extends BinaryBitOpSpecializer { |
355 const ShiftLeftSpecializer(); | 356 const ShiftLeftSpecializer(); |
356 | 357 |
357 BinaryOperation operation(ConstantSystem constantSystem) { | 358 BinaryOperation operation(ConstantSystem constantSystem) { |
358 return constantSystem.shiftLeft; | 359 return constantSystem.shiftLeft; |
359 } | 360 } |
360 | 361 |
(...skipping 11 matching lines...) Expand all Loading... | |
372 clearAllSideEffects(instruction); | 373 clearAllSideEffects(instruction); |
373 } | 374 } |
374 return null; | 375 return null; |
375 } | 376 } |
376 | 377 |
377 HInstruction newBuiltinVariant(HInvokeDynamic instruction, | 378 HInstruction newBuiltinVariant(HInvokeDynamic instruction, |
378 Compiler compiler) { | 379 Compiler compiler) { |
379 JavaScriptBackend backend = compiler.backend; | 380 JavaScriptBackend backend = compiler.backend; |
380 return new HShiftLeft( | 381 return new HShiftLeft( |
381 instruction.inputs[1], instruction.inputs[2], | 382 instruction.inputs[1], instruction.inputs[2], |
382 instruction.selector, backend.intType); | 383 instruction.selector, computeTypeFromInputTypes(instruction, compiler)); |
383 } | 384 } |
384 } | 385 } |
385 | 386 |
386 class ShiftRightSpecializer extends BinaryBitOpSpecializer { | 387 class ShiftRightSpecializer extends BinaryBitOpSpecializer { |
387 const ShiftRightSpecializer(); | 388 const ShiftRightSpecializer(); |
388 | 389 |
390 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, | |
391 Compiler compiler) { | |
392 HInstruction left = instruction.inputs[1]; | |
393 HInstruction right = instruction.inputs[2]; | |
394 JavaScriptBackend backend = compiler.backend; | |
395 if (left.isUInt31(compiler) && right.isUInt31(compiler)) { | |
kasperl
2013/11/26 14:58:40
Isn't it enough if right is positive?
ngeoffray
2013/11/26 15:19:12
You mean left, right? :-) Done.
| |
396 return backend.uint31Type; | |
397 } | |
398 return super.computeTypeFromInputTypes(instruction, compiler); | |
399 } | |
400 | |
389 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, | 401 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, |
390 Compiler compiler) { | 402 Compiler compiler) { |
391 HInstruction left = instruction.inputs[1]; | 403 HInstruction left = instruction.inputs[1]; |
392 HInstruction right = instruction.inputs[2]; | 404 HInstruction right = instruction.inputs[2]; |
393 if (left.isNumber(compiler)) { | 405 if (left.isNumber(compiler)) { |
394 if (argumentLessThan32(right) && isPositive(left)) { | 406 if (argumentLessThan32(right) && isPositive(left, compiler)) { |
395 return newBuiltinVariant(instruction, compiler); | 407 return newBuiltinVariant(instruction, compiler); |
396 } | 408 } |
397 // Even if there is no builtin equivalent instruction, we know | 409 // Even if there is no builtin equivalent instruction, we know |
398 // the instruction does not have any side effect, and that it | 410 // the instruction does not have any side effect, and that it |
399 // can be GVN'ed. | 411 // can be GVN'ed. |
400 clearAllSideEffects(instruction); | 412 clearAllSideEffects(instruction); |
401 } | 413 } |
402 return null; | 414 return null; |
403 } | 415 } |
404 | 416 |
405 HInstruction newBuiltinVariant(HInvokeDynamic instruction, | 417 HInstruction newBuiltinVariant(HInvokeDynamic instruction, |
406 Compiler compiler) { | 418 Compiler compiler) { |
407 JavaScriptBackend backend = compiler.backend; | 419 JavaScriptBackend backend = compiler.backend; |
408 return new HShiftRight( | 420 return new HShiftRight( |
409 instruction.inputs[1], instruction.inputs[2], | 421 instruction.inputs[1], instruction.inputs[2], |
410 instruction.selector, backend.intType); | 422 instruction.selector, computeTypeFromInputTypes(instruction, compiler)); |
411 } | 423 } |
412 | 424 |
413 BinaryOperation operation(ConstantSystem constantSystem) { | 425 BinaryOperation operation(ConstantSystem constantSystem) { |
414 return constantSystem.shiftRight; | 426 return constantSystem.shiftRight; |
415 } | 427 } |
416 } | 428 } |
417 | 429 |
418 class BitOrSpecializer extends BinaryBitOpSpecializer { | 430 class BitOrSpecializer extends BinaryBitOpSpecializer { |
419 const BitOrSpecializer(); | 431 const BitOrSpecializer(); |
420 | 432 |
421 BinaryOperation operation(ConstantSystem constantSystem) { | 433 BinaryOperation operation(ConstantSystem constantSystem) { |
422 return constantSystem.bitOr; | 434 return constantSystem.bitOr; |
423 } | 435 } |
424 | 436 |
437 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, | |
438 Compiler compiler) { | |
439 HInstruction left = instruction.inputs[1]; | |
440 HInstruction right = instruction.inputs[2]; | |
441 JavaScriptBackend backend = compiler.backend; | |
442 if (left.isUInt31(compiler) && right.isUInt31(compiler)) { | |
443 return backend.uint31Type; | |
444 } | |
445 return super.computeTypeFromInputTypes(instruction, compiler); | |
446 } | |
447 | |
425 HInstruction newBuiltinVariant(HInvokeDynamic instruction, | 448 HInstruction newBuiltinVariant(HInvokeDynamic instruction, |
426 Compiler compiler) { | 449 Compiler compiler) { |
427 JavaScriptBackend backend = compiler.backend; | 450 JavaScriptBackend backend = compiler.backend; |
428 return new HBitOr( | 451 return new HBitOr( |
429 instruction.inputs[1], instruction.inputs[2], | 452 instruction.inputs[1], instruction.inputs[2], |
430 instruction.selector, backend.intType); | 453 instruction.selector, computeTypeFromInputTypes(instruction, compiler)); |
431 } | 454 } |
432 } | 455 } |
433 | 456 |
434 class BitAndSpecializer extends BinaryBitOpSpecializer { | 457 class BitAndSpecializer extends BinaryBitOpSpecializer { |
435 const BitAndSpecializer(); | 458 const BitAndSpecializer(); |
436 | 459 |
437 BinaryOperation operation(ConstantSystem constantSystem) { | 460 BinaryOperation operation(ConstantSystem constantSystem) { |
438 return constantSystem.bitAnd; | 461 return constantSystem.bitAnd; |
439 } | 462 } |
440 | 463 |
464 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, | |
465 Compiler compiler) { | |
466 HInstruction left = instruction.inputs[1]; | |
467 HInstruction right = instruction.inputs[2]; | |
468 JavaScriptBackend backend = compiler.backend; | |
469 if (left.isUInt31(compiler) || right.isUInt31(compiler)) { | |
470 return backend.uint31Type; | |
471 } | |
472 return super.computeTypeFromInputTypes(instruction, compiler); | |
473 } | |
474 | |
441 HInstruction newBuiltinVariant(HInvokeDynamic instruction, | 475 HInstruction newBuiltinVariant(HInvokeDynamic instruction, |
442 Compiler compiler) { | 476 Compiler compiler) { |
443 JavaScriptBackend backend = compiler.backend; | 477 JavaScriptBackend backend = compiler.backend; |
444 return new HBitAnd( | 478 return new HBitAnd( |
445 instruction.inputs[1], instruction.inputs[2], | 479 instruction.inputs[1], instruction.inputs[2], |
446 instruction.selector, backend.intType); | 480 instruction.selector, computeTypeFromInputTypes(instruction, compiler)); |
447 } | 481 } |
448 } | 482 } |
449 | 483 |
450 class BitXorSpecializer extends BinaryBitOpSpecializer { | 484 class BitXorSpecializer extends BinaryBitOpSpecializer { |
451 const BitXorSpecializer(); | 485 const BitXorSpecializer(); |
452 | 486 |
453 BinaryOperation operation(ConstantSystem constantSystem) { | 487 BinaryOperation operation(ConstantSystem constantSystem) { |
454 return constantSystem.bitXor; | 488 return constantSystem.bitXor; |
455 } | 489 } |
456 | 490 |
491 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, | |
492 Compiler compiler) { | |
493 HInstruction left = instruction.inputs[1]; | |
494 HInstruction right = instruction.inputs[2]; | |
495 JavaScriptBackend backend = compiler.backend; | |
496 if (left.isUInt31(compiler) && right.isUInt31(compiler)) { | |
497 return backend.uint31Type; | |
498 } | |
499 return super.computeTypeFromInputTypes(instruction, compiler); | |
500 } | |
501 | |
457 HInstruction newBuiltinVariant(HInvokeDynamic instruction, | 502 HInstruction newBuiltinVariant(HInvokeDynamic instruction, |
458 Compiler compiler) { | 503 Compiler compiler) { |
459 JavaScriptBackend backend = compiler.backend; | 504 JavaScriptBackend backend = compiler.backend; |
460 return new HBitXor( | 505 return new HBitXor( |
461 instruction.inputs[1], instruction.inputs[2], | 506 instruction.inputs[1], instruction.inputs[2], |
462 instruction.selector, backend.intType); | 507 instruction.selector, computeTypeFromInputTypes(instruction, compiler)); |
463 } | 508 } |
464 } | 509 } |
465 | 510 |
466 abstract class RelationalSpecializer extends InvokeDynamicSpecializer { | 511 abstract class RelationalSpecializer extends InvokeDynamicSpecializer { |
467 const RelationalSpecializer(); | 512 const RelationalSpecializer(); |
468 | 513 |
469 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, | 514 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, |
470 Compiler compiler) { | 515 Compiler compiler) { |
471 JavaScriptBackend backend = compiler.backend; | 516 JavaScriptBackend backend = compiler.backend; |
472 if (instruction.inputs[1].isPrimitiveOrNull(compiler)) { | 517 if (instruction.inputs[1].isPrimitiveOrNull(compiler)) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 } | 627 } |
583 | 628 |
584 HInstruction newBuiltinVariant(HInvokeDynamic instruction, | 629 HInstruction newBuiltinVariant(HInvokeDynamic instruction, |
585 Compiler compiler) { | 630 Compiler compiler) { |
586 JavaScriptBackend backend = compiler.backend; | 631 JavaScriptBackend backend = compiler.backend; |
587 return new HLessEqual( | 632 return new HLessEqual( |
588 instruction.inputs[1], instruction.inputs[2], | 633 instruction.inputs[1], instruction.inputs[2], |
589 instruction.selector, backend.boolType); | 634 instruction.selector, backend.boolType); |
590 } | 635 } |
591 } | 636 } |
OLD | NEW |