From f8f5892d9826d626f21705c92a4ea26204c570c8 Mon Sep 17 00:00:00 2001 From: John Lorentzson Date: Tue, 1 Jul 2025 20:38:42 +0200 Subject: [PATCH] Somewhat clunky optimization for reusing temporary variable slots --- .../backend/value-allocator.lisp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/wip-duuqnd/user-side-compiler/backend/value-allocator.lisp b/wip-duuqnd/user-side-compiler/backend/value-allocator.lisp index 501ee30..e89c62b 100644 --- a/wip-duuqnd/user-side-compiler/backend/value-allocator.lisp +++ b/wip-duuqnd/user-side-compiler/backend/value-allocator.lisp @@ -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)))))))))