Somewhat clunky optimization for reusing temporary variable slots

This commit is contained in:
John Lorentzson 2025-07-01 20:38:42 +02:00
parent 3f470688a4
commit f8f5892d98

View file

@ -58,4 +58,22 @@
:test-not #'eql :key #'strategy)))
(loop :for allocation :in (append named temporary)
:do (setf (varvec-index allocation) (incf counter))))
allocations))
(remove-if #'null allocations :key (lambda (a) (users (data a))))))
(defun optim-reuse-temporary-slots (start-iblock allocations)
(let ((free '()))
(do-iblocks (iblock start-iblock)
(do-instructions (inst iblock)
(let ((ending (find inst allocations
:key (alexandria:compose #'last-use
#'data)))
(beginning (find (output inst) allocations :key #'data)))
(cond ((and ending
(eql (strategy ending) :temporary-variable)
(not (null (varvec-index ending))))
(pushnew (varvec-index ending) free))
((and beginning
(eql (strategy beginning) :temporary-variable)
(not (null (varvec-index beginning)))
(not (null free)))
(setf (varvec-index beginning) (pop free)))))))))