From ad4f6be137a3a2fabcbba54f1419a26f41626881 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 10 Jan 2014 20:42:50 +0100 Subject: [PATCH] Shuffle the first return value from truncating calls * module/language/cps/slot-allocation.scm (allocate-slots): For truncating calls, shuffle the first return value (if any). Avoids frame size growth due to sparse locals, pegged where they were left by procedure call returns. With this patch, eval with $ktrunc nodes goes from 31 locals to 18 (similar to the size before adding $ktrunc nodes). --- module/language/cps/slot-allocation.scm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/module/language/cps/slot-allocation.scm b/module/language/cps/slot-allocation.scm index 32cbf84d4..5e92a6a23 100644 --- a/module/language/cps/slot-allocation.scm +++ b/module/language/cps/slot-allocation.scm @@ -497,8 +497,17 @@ are comparable with eqv?. A tmp slot may be used." (result-vars (vector-ref defv (cfa-k-idx cfa kargs))) (value-slots (map (cut + proc-slot 1 <>) (iota (length result-vars)))) - (result-live (fold allocate! - post-live result-vars value-slots)) + ;; Shuffle the first result down to the lowest slot, and + ;; leave any remaining results where they are. This + ;; strikes a balance between avoiding shuffling, + ;; especially for unused extra values, and avoiding + ;; frame size growth due to sparse locals. + (result-live (match (cons result-vars value-slots) + ((() . ()) post-live) + (((var . vars) . (slot . slots)) + (fold allocate! + (allocate! var #f post-live) + vars slots)))) (result-slots (map (cut vector-ref slots <>) result-vars)) ;; Filter out unused results. (value-slots (filter-map (lambda (val result) (and result val))