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