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

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

Issue 11364134: Merge libv1. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload due to error 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 for (HPhi phi = block.phis.first; phi != null; phi = phi.next) { 280 for (HPhi phi = block.phis.first; phi != null; phi = phi.next) {
281 environment.remove(phi, instructionId); 281 environment.remove(phi, instructionId);
282 } 282 }
283 283
284 // Save the liveInstructions of that block. 284 // Save the liveInstructions of that block.
285 environment.startId = instructionId + 1; 285 environment.startId = instructionId + 1;
286 liveInstructions[block] = environment; 286 liveInstructions[block] = environment;
287 287
288 // If the block is a loop header, we can remove the loop marker, 288 // If the block is a loop header, we can remove the loop marker,
289 // because it will just recompute the loop phis. 289 // because it will just recompute the loop phis.
290 if (block.isLoopHeader()) { 290 // We also check if this loop header has any back edges. If not,
291 // we know there is no loop marker for it.
292 if (block.isLoopHeader() && block.predecessors.length > 1) {
291 updateLoopMarker(block); 293 updateLoopMarker(block);
292 } 294 }
293 } 295 }
294 296
295 void updateLoopMarker(HBasicBlock header) { 297 void updateLoopMarker(HBasicBlock header) {
296 LiveEnvironment env = liveInstructions[header]; 298 LiveEnvironment env = liveInstructions[header];
297 int lastId = env.loopMarkers[header]; 299 int lastId = env.loopMarkers[header];
298 // Update all instructions that are liveIns in [header] to have a 300 // Update all instructions that are liveIns in [header] to have a
299 // range that covers the loop. 301 // range that covers the loop.
300 env.liveInstructions.forEach((HInstruction instruction, int id) { 302 env.liveInstructions.forEach((HInstruction instruction, int id) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 String name; 502 String name;
501 if (instruction is HCheck) { 503 if (instruction is HCheck) {
502 // Special case this instruction to use the name of its 504 // Special case this instruction to use the name of its
503 // input if it has one. 505 // input if it has one.
504 var temp = instruction; 506 var temp = instruction;
505 do { 507 do {
506 temp = temp.checkedInput; 508 temp = temp.checkedInput;
507 name = names.ownName[temp]; 509 name = names.ownName[temp];
508 } while (name == null && temp is HCheck); 510 } while (name == null && temp is HCheck);
509 if (name != null) return addAllocatedName(instruction, name); 511 if (name != null) return addAllocatedName(instruction, name);
510 } else if (instruction is HParameterValue) {
511 HParameterValue parameter = instruction;
512 name = parameterNames[parameter.sourceElement];
513 if (name == null) {
514 name = allocateWithHint(parameter.sourceElement.name.slowToString());
515 }
516 return addAllocatedName(instruction, name);
517 } 512 }
518 513
519 if (instruction.sourceElement != null) { 514 // The dom/html libraries have inline JS code that reference»
515 // parameter names directly. Long-term such code will be rejected.
516 // Now, just don't mangle the parameter name.
517 if (instruction is HParameterValue
518 && instruction.sourceElement.enclosingElement.isNative()) {
519 name = instruction.sourceElement.name.slowToString();
520 } else if (instruction.sourceElement != null) {
520 name = allocateWithHint(instruction.sourceElement.name.slowToString()); 521 name = allocateWithHint(instruction.sourceElement.name.slowToString());
521 } else { 522 } else {
522 // We could not find an element for the instruction. If the 523 // We could not find an element for the instruction. If the
523 // instruction is used by a phi, try to use the name of the phi. 524 // instruction is used by a phi, try to use the name of the phi.
524 // Otherwise, just allocate a temporary name. 525 // Otherwise, just allocate a temporary name.
525 HPhi phi = firstPhiUserWithElement(instruction); 526 HPhi phi = firstPhiUserWithElement(instruction);
526 if (phi != null) { 527 if (phi != null) {
527 name = allocateWithHint(phi.sourceElement.name.slowToString()); 528 name = allocateWithHint(phi.sourceElement.name.slowToString());
528 } else { 529 } else {
529 name = allocateTemporary(); 530 name = allocateTemporary();
530 } 531 }
531 } 532 }
532 533
533 return addAllocatedName(instruction, name); 534 return addAllocatedName(instruction, name);
534 } 535 }
535 536
536 String addAllocatedName(HInstruction instruction, String name) { 537 String addAllocatedName(HInstruction instruction, String name) {
538 if (instruction is HParameterValue) {
539 parameterNames[instruction.sourceElement] = name;
540 }
537 usedNames.add(name); 541 usedNames.add(name);
538 names.addNameUsed(name); 542 names.addNameUsed(name);
539 names.ownName[instruction] = name; 543 names.ownName[instruction] = name;
540 return name; 544 return name;
541 } 545 }
542 546
543 /** 547 /**
544 * Frees [instruction]'s name so it can be used for other instructions. 548 * Frees [instruction]'s name so it can be used for other instructions.
545 */ 549 */
546 void freeName(HInstruction instruction) { 550 void freeName(HInstruction instruction) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 block.forEachInstruction((HInstruction instruction) { 608 block.forEachInstruction((HInstruction instruction) {
605 handleInstruction(instruction, namer); 609 handleInstruction(instruction, namer);
606 }); 610 });
607 } 611 }
608 612
609 /** 613 /**
610 * Returns whether [instruction] needs a name. Instructions that 614 * Returns whether [instruction] needs a name. Instructions that
611 * have no users or that are generated at use site does not need a name. 615 * have no users or that are generated at use site does not need a name.
612 */ 616 */
613 bool needsName(HInstruction instruction) { 617 bool needsName(HInstruction instruction) {
614 if (instruction.usedBy.isEmpty) return false;
615 // TODO(ngeoffray): locals/parameters are being generated at use site, 618 // TODO(ngeoffray): locals/parameters are being generated at use site,
616 // but we need a name for them. We should probably not make 619 // but we need a name for them. We should probably not make
617 // them generate at use site to make things simpler. 620 // them generate at use site to make things simpler.
618 if (instruction is HLocalValue && instruction is !HThis) return true; 621 if (instruction is HLocalValue && instruction is !HThis) return true;
622 if (instruction.usedBy.isEmpty) return false;
619 if (generateAtUseSite.contains(instruction)) return false; 623 if (generateAtUseSite.contains(instruction)) return false;
620 // A [HCheck] instruction that has control flow needs a name only if its 624 // A [HCheck] instruction that has control flow needs a name only if its
621 // checked input needs a name (e.g. a check [HConstant] does not 625 // checked input needs a name (e.g. a check [HConstant] does not
622 // need a name). 626 // need a name).
623 if (instruction is HCheck && instruction.isControlFlow()) { 627 if (instruction is HCheck && instruction.isControlFlow()) {
624 HCheck check = instruction; 628 HCheck check = instruction;
625 return needsName(instruction.checkedInput); 629 return needsName(instruction.checkedInput);
626 } 630 }
627 return true; 631 return true;
628 } 632 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 if (!needsName(input)) { 675 if (!needsName(input)) {
672 names.addAssignment(predecessor, input, phi); 676 names.addAssignment(predecessor, input, phi);
673 } else { 677 } else {
674 names.addCopy(predecessor, input, phi); 678 names.addCopy(predecessor, input, phi);
675 } 679 }
676 } 680 }
677 681
678 namer.allocateName(phi); 682 namer.allocateName(phi);
679 } 683 }
680 } 684 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698