1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-09 21:40:33 +02:00

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).
This commit is contained in:
Andy Wingo 2014-01-10 20:42:50 +01:00
parent 8a2d420f74
commit ad4f6be137

View file

@ -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))