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

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

Issue 11275189: Clean up the codegen by not re-computing parameter names. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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) 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 /** 7 /**
8 * The [LiveRange] class covers a range where an instruction is live. 8 * The [LiveRange] class covers a range where an instruction is live.
9 */ 9 */
10 class LiveRange { 10 class LiveRange {
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 String name; 502 String name;
503 if (instruction is HCheck) { 503 if (instruction is HCheck) {
504 // Special case this instruction to use the name of its 504 // Special case this instruction to use the name of its
505 // input if it has one. 505 // input if it has one.
506 var temp = instruction; 506 var temp = instruction;
507 do { 507 do {
508 temp = temp.checkedInput; 508 temp = temp.checkedInput;
509 name = names.ownName[temp]; 509 name = names.ownName[temp];
510 } while (name == null && temp is HCheck); 510 } while (name == null && temp is HCheck);
511 if (name != null) return addAllocatedName(instruction, name); 511 if (name != null) return addAllocatedName(instruction, name);
512 } else if (instruction is HParameterValue) {
513 HParameterValue parameter = instruction;
514 name = parameterNames[parameter.sourceElement];
515 if (name == null) {
516 name = allocateWithHint(parameter.sourceElement.name.slowToString());
517 }
518 return addAllocatedName(instruction, name);
519 } 512 }
520 513
521 if (instruction.sourceElement != null) { 514 if (instruction.sourceElement != null) {
522 name = allocateWithHint(instruction.sourceElement.name.slowToString()); 515 name = allocateWithHint(instruction.sourceElement.name.slowToString());
523 } else { 516 } else {
524 // We could not find an element for the instruction. If the 517 // We could not find an element for the instruction. If the
525 // instruction is used by a phi, try to use the name of the phi. 518 // instruction is used by a phi, try to use the name of the phi.
526 // Otherwise, just allocate a temporary name. 519 // Otherwise, just allocate a temporary name.
527 HPhi phi = firstPhiUserWithElement(instruction); 520 HPhi phi = firstPhiUserWithElement(instruction);
528 if (phi != null) { 521 if (phi != null) {
529 name = allocateWithHint(phi.sourceElement.name.slowToString()); 522 name = allocateWithHint(phi.sourceElement.name.slowToString());
530 } else { 523 } else {
531 name = allocateTemporary(); 524 name = allocateTemporary();
532 } 525 }
533 } 526 }
534 527
535 return addAllocatedName(instruction, name); 528 return addAllocatedName(instruction, name);
536 } 529 }
537 530
538 String addAllocatedName(HInstruction instruction, String name) { 531 String addAllocatedName(HInstruction instruction, String name) {
532 if (instruction is HParameterValue) {
533 parameterNames[instruction.sourceElement] = name;
534 }
539 usedNames.add(name); 535 usedNames.add(name);
540 names.addNameUsed(name); 536 names.addNameUsed(name);
541 names.ownName[instruction] = name; 537 names.ownName[instruction] = name;
542 return name; 538 return name;
543 } 539 }
544 540
545 /** 541 /**
546 * Frees [instruction]'s name so it can be used for other instructions. 542 * Frees [instruction]'s name so it can be used for other instructions.
547 */ 543 */
548 void freeName(HInstruction instruction) { 544 void freeName(HInstruction instruction) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 block.forEachInstruction((HInstruction instruction) { 602 block.forEachInstruction((HInstruction instruction) {
607 handleInstruction(instruction, namer); 603 handleInstruction(instruction, namer);
608 }); 604 });
609 } 605 }
610 606
611 /** 607 /**
612 * Returns whether [instruction] needs a name. Instructions that 608 * Returns whether [instruction] needs a name. Instructions that
613 * have no users or that are generated at use site does not need a name. 609 * have no users or that are generated at use site does not need a name.
614 */ 610 */
615 bool needsName(HInstruction instruction) { 611 bool needsName(HInstruction instruction) {
616 if (instruction.usedBy.isEmpty) return false;
617 // TODO(ngeoffray): locals/parameters are being generated at use site, 612 // TODO(ngeoffray): locals/parameters are being generated at use site,
618 // but we need a name for them. We should probably not make 613 // but we need a name for them. We should probably not make
619 // them generate at use site to make things simpler. 614 // them generate at use site to make things simpler.
620 if (instruction is HLocalValue && instruction is !HThis) return true; 615 if (instruction is HLocalValue && instruction is !HThis) return true;
616 if (instruction.usedBy.isEmpty) return false;
621 if (generateAtUseSite.contains(instruction)) return false; 617 if (generateAtUseSite.contains(instruction)) return false;
622 // A [HCheck] instruction that has control flow needs a name only if its 618 // A [HCheck] instruction that has control flow needs a name only if its
623 // checked input needs a name (e.g. a check [HConstant] does not 619 // checked input needs a name (e.g. a check [HConstant] does not
624 // need a name). 620 // need a name).
625 if (instruction is HCheck && instruction.isControlFlow()) { 621 if (instruction is HCheck && instruction.isControlFlow()) {
626 HCheck check = instruction; 622 HCheck check = instruction;
627 return needsName(instruction.checkedInput); 623 return needsName(instruction.checkedInput);
628 } 624 }
629 return true; 625 return true;
630 } 626 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 if (!needsName(input)) { 669 if (!needsName(input)) {
674 names.addAssignment(predecessor, input, phi); 670 names.addAssignment(predecessor, input, phi);
675 } else { 671 } else {
676 names.addCopy(predecessor, input, phi); 672 names.addCopy(predecessor, input, phi);
677 } 673 }
678 } 674 }
679 675
680 namer.allocateName(phi); 676 namer.allocateName(phi);
681 } 677 }
682 } 678 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698