From ae4c925285a2f5d4d5c584168baafbabd0fe7971 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Mon, 29 Apr 2024 17:09:51 -0600 Subject: Implement optimal spilling, fix minor issue with gaps in LRA --- vaporize/RegisterAlloc.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'vaporize') diff --git a/vaporize/RegisterAlloc.java b/vaporize/RegisterAlloc.java index 100d6c4..3afdb02 100644 --- a/vaporize/RegisterAlloc.java +++ b/vaporize/RegisterAlloc.java @@ -70,10 +70,16 @@ public class RegisterAlloc { } private void spillAtInterval(LIRVar interval) { - // You can make this spill optimally (the sarkar linearscan algorithm) + this.intervals.addSpilledNum(); + LIRVar spill = this.active.last(); + if (spill.getLastUse() > interval.getLastUse()) { + interval.assignRegister(spill.getAssignedRegister()); + this.active.add(interval); + this.active.remove(spill); + interval = spill; + } MinimalLogger.severe(String.format("Ran out of free registers, had to spill %s!", interval.toString())); - this.intervals.addSpilledNum(); interval.assignRegister(String.format("local[%d]", this.spill_start++)); } -- cgit v1.2.3