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

Side by Side Diff: lib/compiler/implementation/ssa/nodes.dart

Issue 10696120: Fix very subtle bug in HNode.changeUse. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months 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
« no previous file with comments | « no previous file | tests/language/partial_min_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 interface HVisitor<R> { 5 interface HVisitor<R> {
6 R visitAdd(HAdd node); 6 R visitAdd(HAdd node);
7 R visitBitAnd(HBitAnd node); 7 R visitBitAnd(HBitAnd node);
8 R visitBitNot(HBitNot node); 8 R visitBitNot(HBitNot node);
9 R visitBitOr(HBitOr node); 9 R visitBitOr(HBitOr node);
10 R visitBitXor(HBitXor node); 10 R visitBitXor(HBitXor node);
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 // Change all uses of [oldInput] by [this] to [newInput]. Also 924 // Change all uses of [oldInput] by [this] to [newInput]. Also
925 // updates the [usedBy] of [oldInput] and [newInput]. 925 // updates the [usedBy] of [oldInput] and [newInput].
926 void changeUse(HInstruction oldInput, HInstruction newInput) { 926 void changeUse(HInstruction oldInput, HInstruction newInput) {
927 for (int i = 0; i < inputs.length; i++) { 927 for (int i = 0; i < inputs.length; i++) {
928 if (inputs[i] === oldInput) { 928 if (inputs[i] === oldInput) {
929 inputs[i] = newInput; 929 inputs[i] = newInput;
930 newInput.usedBy.add(this); 930 newInput.usedBy.add(this);
931 } 931 }
932 } 932 }
933 List<HInstruction> oldInputUsers = oldInput.usedBy; 933 List<HInstruction> oldInputUsers = oldInput.usedBy;
934 for (int i = 0; i < oldInputUsers.length; i++) { 934 int i = 0;
935 while (i < oldInputUsers.length) {
935 if (oldInputUsers[i] == this) { 936 if (oldInputUsers[i] == this) {
936 oldInputUsers[i] = oldInputUsers[oldInput.usedBy.length - 1]; 937 oldInputUsers[i] = oldInputUsers[oldInput.usedBy.length - 1];
937 oldInputUsers.length = oldInputUsers.length - 1; 938 oldInputUsers.length = oldInputUsers.length - 1;
Lasse Reichstein Nielsen 2012/07/06 11:22:16 Use 'oldInputUsers.length -= 1' here, or even 'old
floitsch 2012/07/06 15:20:33 done.
939 } else {
940 i++;
938 } 941 }
939 } 942 }
940 } 943 }
941 944
942 // Compute the set of users of this instruction that is dominated by 945 // Compute the set of users of this instruction that is dominated by
943 // [other]. 946 // [other].
944 Set<HInstruction> dominatedUsers(HInstruction other) { 947 Set<HInstruction> dominatedUsers(HInstruction other) {
945 // Keep track of all instructions that we have to deal with later 948 // Keep track of all instructions that we have to deal with later
946 // and count the number of them that are in the current block. 949 // and count the number of them that are in the current block.
947 Set<HInstruction> users = new Set<HInstruction>(); 950 Set<HInstruction> users = new Set<HInstruction>();
948 int usersInCurrentBlock = 0; 951 int usersInCurrentBlock = 0;
949 952
950 // Run through all the users and see if they are dominated or 953 // Run through all the users and see if they are dominated or
951 // potentially dominated by [other]. 954 // potentially dominated by [other].
952 HBasicBlock block = other.block; 955 HBasicBlock otherBlock = other.block;
953 for (int i = 0, length = usedBy.length; i < length; i++) { 956 for (int i = 0, length = usedBy.length; i < length; i++) {
954 HInstruction current = usedBy[i]; 957 HInstruction current = usedBy[i];
955 if (current !== other && block.dominates(current.block)) { 958 if (current !== other && otherBlock.dominates(current.block)) {
956 if (current.block === block) usersInCurrentBlock++; 959 if (current.block === otherBlock) usersInCurrentBlock++;
957 users.add(current); 960 users.add(current);
958 } 961 }
959 } 962 }
960 963
961 // Run through all the instructions before [other] and remove them 964 // Run through all the instructions before [other] and remove them
962 // from the users set. 965 // from the users set.
963 if (usersInCurrentBlock > 0) { 966 if (usersInCurrentBlock > 0) {
964 HInstruction current = block.first; 967 HInstruction current = otherBlock.first;
965 while (current !== other) { 968 while (current !== other) {
966 if (users.contains(current)) { 969 if (users.contains(current)) {
967 users.remove(current); 970 users.remove(current);
968 if (--usersInCurrentBlock == 0) break; 971 if (--usersInCurrentBlock == 0) break;
969 } 972 }
970 current = current.next; 973 current = current.next;
971 } 974 }
972 } 975 }
973 976
974 return users; 977 return users;
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after
2659 HBasicBlock get start() => expression.start; 2662 HBasicBlock get start() => expression.start;
2660 HBasicBlock get end() { 2663 HBasicBlock get end() {
2661 // We don't create a switch block if there are no cases. 2664 // We don't create a switch block if there are no cases.
2662 assert(!statements.isEmpty()); 2665 assert(!statements.isEmpty());
2663 return statements.last().end; 2666 return statements.last().end;
2664 } 2667 }
2665 2668
2666 bool accept(HStatementInformationVisitor visitor) => 2669 bool accept(HStatementInformationVisitor visitor) =>
2667 visitor.visitSwitchInfo(this); 2670 visitor.visitSwitchInfo(this);
2668 } 2671 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/partial_min_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698