Skip to content

Commit 8ee62df

Browse files
Merge pull request #9 from CompilerProgramming/ssatest
Fix bug with swap cycles
2 parents 8304045 + 58b3f64 commit 8ee62df

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

optvm/src/main/java/com/compilerprogramming/ezlang/compiler/ExitSSA.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private void scheduleCopies(BasicBlock block, List<Integer> pushed) {
125125
addMoveAtBBEnd(block, map.get(src.id), dest);
126126
map.put(src.id, dest);
127127
/* If src is the name of a dest in copySet add item to worklist */
128-
CopyItem item = isDest(copySet, src);
128+
CopyItem item = isCycle(copySet, src);
129129
if (item != null) {
130130
workList.add(item);
131131
}
@@ -174,11 +174,14 @@ private Register addMoveToTempAtBBEnd(BasicBlock block, Register dest) {
174174
return temp;
175175
}
176176

177-
/* If src is the name of a dest in copySet return the item */
178-
private CopyItem isDest(List<CopyItem> copySet, Register src) {
179-
for (CopyItem copyItem: copySet) {
180-
if (copyItem.dest.id == src.id)
177+
/* If src is the name of a dest in copySet remove the item */
178+
private CopyItem isCycle(List<CopyItem> copySet, Register src) {
179+
for (int i = 0; i < copySet.size(); i++) {
180+
CopyItem copyItem = copySet.get(i);
181+
if (copyItem.dest.id == src.id) {
182+
copySet.remove(i);
181183
return copyItem;
184+
}
182185
}
183186
return null;
184187
}

optvm/src/test/java/com/compilerprogramming/ezlang/compiler/TestSSATransform.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,6 @@ public void testSwapProblem() {
760760
a2_6 = a2
761761
a2 = b2
762762
b2 = a2_6
763-
b2_7 = b2
764-
b2 = b2
765763
if p goto L2 else goto L1
766764
L1:
767765
""";

0 commit comments

Comments
 (0)