Skip to content

Commit 1232c49

Browse files
Fix bug - use correct integer ID for registers when creating pre-assigned set
1 parent 4ead605 commit 1232c49

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public Map<Integer, Integer> assignRegisters(CompiledFunction function, int numR
2121
if (function.isSSA) throw new IllegalStateException("Register allocation should be done after exiting SSA");
2222
// Remove useless copy operations
2323
InterferenceGraph g = coalesce(function, options);
24-
// Get used registers
24+
// Get used registers, indexed by reg.id
2525
Set<Integer> registers = registersInIR(function);
2626
// Create color set
2727
List<Integer> colors = new ArrayList<>(IntStream.range(0, numRegisters).boxed().toList());
@@ -59,9 +59,9 @@ private Map<Integer, Integer> preAssignArgsToColors(CompiledFunction function, S
5959
for (Instruction instruction : function.entry.instructions) {
6060
if (instruction instanceof Instruction.ArgInstruction argInstruction) {
6161
Integer color = colors.get(count);
62-
Register reg = argInstruction.arg().reg;
63-
registers.remove(reg.nonSSAId()); // Remove register from set before changing slot
64-
assignments.put(reg.nonSSAId(), color);
62+
int reg = argInstruction.arg().reg.id;
63+
registers.remove(reg); // Remove register from set before changing slot
64+
assignments.put(reg, color);
6565
count++;
6666
}
6767
else break;
@@ -142,6 +142,7 @@ private void rewriteInstructions(CompiledFunction function, Instruction deadInst
142142

143143
/**
144144
* Get the list of registers in use in the Intermediate Code
145+
* Indexed by reg.id
145146
* Chaitin: registers_in_il()
146147
*/
147148
private Set<Integer> registersInIR(CompiledFunction function) {

0 commit comments

Comments
 (0)