Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/invoke_dynamic_specializers.dart

Issue 87783003: Add UInt32 and UInt31 types to better infer bit operations. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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.isUInt32(compiler)) return left.instructionType;
396 return super.computeTypeFromInputTypes(instruction, compiler);
397 }
398
389 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction, 399 HInstruction tryConvertToBuiltin(HInvokeDynamic instruction,
390 Compiler compiler) { 400 Compiler compiler) {
391 HInstruction left = instruction.inputs[1]; 401 HInstruction left = instruction.inputs[1];
392 HInstruction right = instruction.inputs[2]; 402 HInstruction right = instruction.inputs[2];
393 if (left.isNumber(compiler)) { 403 if (left.isNumber(compiler)) {
394 if (argumentLessThan32(right) && isPositive(left)) { 404 if (argumentLessThan32(right) && isPositive(left, compiler)) {
395 return newBuiltinVariant(instruction, compiler); 405 return newBuiltinVariant(instruction, compiler);
396 } 406 }
397 // Even if there is no builtin equivalent instruction, we know 407 // Even if there is no builtin equivalent instruction, we know
398 // the instruction does not have any side effect, and that it 408 // the instruction does not have any side effect, and that it
399 // can be GVN'ed. 409 // can be GVN'ed.
400 clearAllSideEffects(instruction); 410 clearAllSideEffects(instruction);
401 } 411 }
402 return null; 412 return null;
403 } 413 }
404 414
405 HInstruction newBuiltinVariant(HInvokeDynamic instruction, 415 HInstruction newBuiltinVariant(HInvokeDynamic instruction,
406 Compiler compiler) { 416 Compiler compiler) {
407 JavaScriptBackend backend = compiler.backend; 417 JavaScriptBackend backend = compiler.backend;
408 return new HShiftRight( 418 return new HShiftRight(
409 instruction.inputs[1], instruction.inputs[2], 419 instruction.inputs[1], instruction.inputs[2],
410 instruction.selector, backend.intType); 420 instruction.selector, computeTypeFromInputTypes(instruction, compiler));
411 } 421 }
412 422
413 BinaryOperation operation(ConstantSystem constantSystem) { 423 BinaryOperation operation(ConstantSystem constantSystem) {
414 return constantSystem.shiftRight; 424 return constantSystem.shiftRight;
415 } 425 }
416 } 426 }
417 427
418 class BitOrSpecializer extends BinaryBitOpSpecializer { 428 class BitOrSpecializer extends BinaryBitOpSpecializer {
419 const BitOrSpecializer(); 429 const BitOrSpecializer();
420 430
421 BinaryOperation operation(ConstantSystem constantSystem) { 431 BinaryOperation operation(ConstantSystem constantSystem) {
422 return constantSystem.bitOr; 432 return constantSystem.bitOr;
423 } 433 }
424 434
435 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction,
436 Compiler compiler) {
437 HInstruction left = instruction.inputs[1];
438 HInstruction right = instruction.inputs[2];
439 JavaScriptBackend backend = compiler.backend;
440 if (left.isUInt31(compiler) && right.isUInt31(compiler)) {
441 return backend.uint31Type;
442 }
443 return super.computeTypeFromInputTypes(instruction, compiler);
444 }
445
425 HInstruction newBuiltinVariant(HInvokeDynamic instruction, 446 HInstruction newBuiltinVariant(HInvokeDynamic instruction,
426 Compiler compiler) { 447 Compiler compiler) {
427 JavaScriptBackend backend = compiler.backend; 448 JavaScriptBackend backend = compiler.backend;
428 return new HBitOr( 449 return new HBitOr(
429 instruction.inputs[1], instruction.inputs[2], 450 instruction.inputs[1], instruction.inputs[2],
430 instruction.selector, backend.intType); 451 instruction.selector, computeTypeFromInputTypes(instruction, compiler));
431 } 452 }
432 } 453 }
433 454
434 class BitAndSpecializer extends BinaryBitOpSpecializer { 455 class BitAndSpecializer extends BinaryBitOpSpecializer {
435 const BitAndSpecializer(); 456 const BitAndSpecializer();
436 457
437 BinaryOperation operation(ConstantSystem constantSystem) { 458 BinaryOperation operation(ConstantSystem constantSystem) {
438 return constantSystem.bitAnd; 459 return constantSystem.bitAnd;
439 } 460 }
440 461
462 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction,
463 Compiler compiler) {
464 HInstruction left = instruction.inputs[1];
465 HInstruction right = instruction.inputs[2];
466 JavaScriptBackend backend = compiler.backend;
467 if (left.isUInt31(compiler) || right.isUInt31(compiler)) {
468 return backend.uint31Type;
469 }
470 return super.computeTypeFromInputTypes(instruction, compiler);
471 }
472
441 HInstruction newBuiltinVariant(HInvokeDynamic instruction, 473 HInstruction newBuiltinVariant(HInvokeDynamic instruction,
442 Compiler compiler) { 474 Compiler compiler) {
443 JavaScriptBackend backend = compiler.backend; 475 JavaScriptBackend backend = compiler.backend;
444 return new HBitAnd( 476 return new HBitAnd(
445 instruction.inputs[1], instruction.inputs[2], 477 instruction.inputs[1], instruction.inputs[2],
446 instruction.selector, backend.intType); 478 instruction.selector, computeTypeFromInputTypes(instruction, compiler));
447 } 479 }
448 } 480 }
449 481
450 class BitXorSpecializer extends BinaryBitOpSpecializer { 482 class BitXorSpecializer extends BinaryBitOpSpecializer {
451 const BitXorSpecializer(); 483 const BitXorSpecializer();
452 484
453 BinaryOperation operation(ConstantSystem constantSystem) { 485 BinaryOperation operation(ConstantSystem constantSystem) {
454 return constantSystem.bitXor; 486 return constantSystem.bitXor;
455 } 487 }
456 488
489 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction,
490 Compiler compiler) {
491 HInstruction left = instruction.inputs[1];
492 HInstruction right = instruction.inputs[2];
493 JavaScriptBackend backend = compiler.backend;
494 if (left.isUInt31(compiler) && right.isUInt31(compiler)) {
495 return backend.uint31Type;
496 }
497 return super.computeTypeFromInputTypes(instruction, compiler);
498 }
499
457 HInstruction newBuiltinVariant(HInvokeDynamic instruction, 500 HInstruction newBuiltinVariant(HInvokeDynamic instruction,
458 Compiler compiler) { 501 Compiler compiler) {
459 JavaScriptBackend backend = compiler.backend; 502 JavaScriptBackend backend = compiler.backend;
460 return new HBitXor( 503 return new HBitXor(
461 instruction.inputs[1], instruction.inputs[2], 504 instruction.inputs[1], instruction.inputs[2],
462 instruction.selector, backend.intType); 505 instruction.selector, computeTypeFromInputTypes(instruction, compiler));
463 } 506 }
464 } 507 }
465 508
466 abstract class RelationalSpecializer extends InvokeDynamicSpecializer { 509 abstract class RelationalSpecializer extends InvokeDynamicSpecializer {
467 const RelationalSpecializer(); 510 const RelationalSpecializer();
468 511
469 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction, 512 TypeMask computeTypeFromInputTypes(HInvokeDynamic instruction,
470 Compiler compiler) { 513 Compiler compiler) {
471 JavaScriptBackend backend = compiler.backend; 514 JavaScriptBackend backend = compiler.backend;
472 if (instruction.inputs[1].isPrimitiveOrNull(compiler)) { 515 if (instruction.inputs[1].isPrimitiveOrNull(compiler)) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 } 625 }
583 626
584 HInstruction newBuiltinVariant(HInvokeDynamic instruction, 627 HInstruction newBuiltinVariant(HInvokeDynamic instruction,
585 Compiler compiler) { 628 Compiler compiler) {
586 JavaScriptBackend backend = compiler.backend; 629 JavaScriptBackend backend = compiler.backend;
587 return new HLessEqual( 630 return new HLessEqual(
588 instruction.inputs[1], instruction.inputs[2], 631 instruction.inputs[1], instruction.inputs[2],
589 instruction.selector, backend.boolType); 632 instruction.selector, backend.boolType);
590 } 633 }
591 } 634 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/ssa/codegen.dart ('k') | sdk/lib/_internal/compiler/implementation/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698