Created
June 18, 2021 07:28
-
-
Save no-defun-allowed/778599c5b95407fe21baff7445443ad6 to your computer and use it in GitHub Desktop.
Remove redundant assignments and locations in Cleavir IR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; Remove any assignment instructions and locations which appear to | |
;;; be redundant. We define a "redundant" assignment to be one which | |
;;; assigns from a lexical location to another, either with only one | |
;;; defining instruction; i.e. the assignment does not cause any | |
;;; visible effect. | |
(defun remove-redundant-assignments (enter-instruction) | |
(cleavir-ir:map-instructions-arbitrary-order | |
(lambda (instruction) | |
(when (typep instruction 'cleavir-ir:assignment-instruction) | |
(destructuring-bind (input) | |
(cleavir-ir:inputs instruction) | |
(destructuring-bind (output) | |
(cleavir-ir:outputs instruction) | |
(when (and | |
(typep input 'cleavir-ir:lexical-location) | |
(alexandria:length= | |
1 | |
(cleavir-ir:defining-instructions input) | |
(cleavir-ir:defining-instructions output))) | |
(cleavir-ir:replace-datum input output) | |
(cleavir-ir:delete-instruction instruction)))))) | |
enter-instruction)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment