|
69 | 69 | (defmethod add-definition ((datum variable) (definition instruction)) |
70 | 70 | (set:nadjoinf (writers datum) definition)) |
71 | 71 |
|
| 72 | +(defgeneric remove-if-unused (value module)) |
| 73 | +(defmethod remove-if-unused ((value constant) module) |
| 74 | + (when (set:empty-set-p (readers value)) |
| 75 | + (set:nremovef (constants module) value) |
| 76 | + (remhash (constant-value value) (constant-table module)))) |
| 77 | +(defmethod remove-if-unused ((value function-cell) module) |
| 78 | + (when (set:empty-set-p (readers value)) |
| 79 | + (set:nremovef (constants module) value) |
| 80 | + (remhash (function-name value) (function-cell-table module)))) |
| 81 | +(defmethod remove-if-unused ((value variable-cell) module) |
| 82 | + (when (set:empty-set-p (readers value)) |
| 83 | + (set:nremovef (constants module) value) |
| 84 | + (remhash (variable-name value) (variable-cell-table module)))) |
| 85 | +(defmethod remove-if-unused ((ltv load-time-value) module) |
| 86 | + (when (set:empty-set-p (readers ltv)) |
| 87 | + (set:nremovef (constants module) ltv))) |
| 88 | +(defmethod remove-if-unused ((value function) module) |
| 89 | + (when (and (null (enclose value)) |
| 90 | + (set:empty-set-p (local-calls value))) |
| 91 | + (clean-up-function value))) |
| 92 | + |
72 | 93 | (defmethod (setf outputs) :before (new-outputs (inst instruction)) |
73 | 94 | (dolist (output (outputs inst)) |
74 | 95 | (remove-definition output inst)) |
|
144 | 165 | (unlink-instruction movant) |
145 | 166 | (insert-instruction-after movant existing)) |
146 | 167 |
|
| 168 | +;;; Remove any constants etc. that are unused. This is important to do if |
| 169 | +;;; the process of generating the module can create constants that are never |
| 170 | +;;; given a constant-reference instruction (analogously ltv-reference, etc.), |
| 171 | +;;; the deletion of which would usually clean up unused constants. |
| 172 | +;;; Verification requires unused constants to be deleted. |
| 173 | +(defun remove-unused-values (module) |
| 174 | + (set:doset (constant (constants module)) |
| 175 | + (remove-if-unused constant module))) |
| 176 | + |
147 | 177 | ;;; Remove backpointers to an instruction, etc. |
148 | 178 | (defgeneric clean-up-instruction (instruction) |
149 | 179 | (:method-combination progn) |
|
201 | 231 | (defmethod clean-up-instruction progn ((inst constant-reference)) |
202 | 232 | (let ((constant (first (inputs inst)))) |
203 | 233 | (set:nremovef (readers constant) inst) |
204 | | - (when (set:empty-set-p (readers constant)) |
205 | | - (let ((module (module (function inst)))) |
206 | | - (set:nremovef (constants module) constant) |
207 | | - (remhash (constant-value constant) (constant-table module)))))) |
| 234 | + (remove-if-unused constant (module (function inst))))) |
208 | 235 | (defmethod clean-up-instruction progn ((inst constant-fdefinition)) |
209 | 236 | (let ((constant (first (inputs inst)))) |
210 | 237 | (set:nremovef (readers constant) inst) |
211 | | - (when (set:empty-set-p (readers constant)) |
212 | | - (let ((module (module (function inst)))) |
213 | | - (set:nremovef (constants module) constant) |
214 | | - (remhash (function-name constant) (function-cell-table module)))))) |
| 238 | + (remove-if-unused constant (module (function inst))))) |
215 | 239 | (defmethod clean-up-instruction progn ((inst constant-symbol-value)) |
216 | 240 | (let ((constant (first (inputs inst)))) |
217 | 241 | (set:nremovef (readers constant) inst) |
218 | | - (when (set:empty-set-p (readers constant)) |
219 | | - (let ((module (module (function inst)))) |
220 | | - (set:nremovef (constants module) constant) |
221 | | - (remhash (variable-name constant) (variable-cell-table module)))))) |
| 242 | + (remove-if-unused constant (module (function inst))))) |
222 | 243 | (defmethod clean-up-instruction progn ((inst set-constant-symbol-value)) |
223 | 244 | (let ((constant (first (inputs inst)))) |
224 | 245 | (set:nremovef (readers constant) inst) |
225 | | - (when (set:empty-set-p (readers constant)) |
226 | | - (let ((module (module (function inst)))) |
227 | | - (set:nremovef (constants module) constant) |
228 | | - (remhash (variable-name constant) (variable-cell-table module)))))) |
| 246 | + (remove-if-unused constant (module (function inst))))) |
229 | 247 | (defmethod clean-up-instruction progn ((inst constant-bind)) |
230 | 248 | (let ((constant (first (inputs inst)))) |
231 | 249 | (set:nremovef (readers constant) inst) |
232 | | - (when (set:empty-set-p (readers constant)) |
233 | | - (let ((module (module (function inst)))) |
234 | | - (set:nremovef (constants module) constant) |
235 | | - (remhash (variable-name constant) (variable-cell-table module)))))) |
| 250 | + (remove-if-unused constant (module (function inst))))) |
236 | 251 | (defmethod clean-up-instruction progn ((inst load-time-value-reference)) |
237 | 252 | (let ((ltv (first (inputs inst)))) |
238 | 253 | (set:nremovef (readers ltv) inst) |
|
241 | 256 | (defmethod clean-up-instruction progn ((inst enclose)) |
242 | 257 | (let ((code (code inst))) |
243 | 258 | (setf (enclose code) nil) |
244 | | - (when (set:empty-set-p (local-calls code)) |
245 | | - (clean-up-function code)))) |
| 259 | + (remove-if-unused code (module code)))) |
246 | 260 | (defmethod clean-up-instruction progn ((inst abstract-local-call)) |
247 | 261 | (let* ((code (callee inst)) |
248 | 262 | (local-calls (local-calls code))) |
249 | 263 | (set:nremovef local-calls inst) |
250 | | - (when (and (null (enclose code)) |
251 | | - (set:empty-set-p local-calls)) |
252 | | - (clean-up-function code)))) |
| 264 | + (remove-if-unused code (module code)))) |
253 | 265 | (defmethod clean-up-instruction progn ((inst unwind)) |
254 | 266 | (set:nremovef (entrances (destination inst)) (iblock inst)) |
255 | 267 | (set:nremovef (unwinds (come-from inst)) inst)) |
|
0 commit comments