Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save no-defun-allowed/778599c5b95407fe21baff7445443ad6 to your computer and use it in GitHub Desktop.
Save no-defun-allowed/778599c5b95407fe21baff7445443ad6 to your computer and use it in GitHub Desktop.
Remove redundant assignments and locations in Cleavir IR
;;; 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