delete-block ignores already deleted blocks
authorDavid Vázquez <davazp@gmail.com>
Sat, 18 May 2013 12:57:43 +0000 (13:57 +0100)
committerDavid Vázquez <davazp@gmail.com>
Sat, 18 May 2013 12:57:43 +0000 (13:57 +0100)
experimental/compiler.lisp

index 49ed56e..858865e 100644 (file)
 (defun delete-block (block)
   (when (boundary-block-p block)
     (error "Cannot delete entry or exit basic blocks."))
-  (unless (singlep (block-succ block))
+  (unless (null (cdr (block-succ block)))
     (error "Cannot delete a basic block with multiple successors."))
-  (let ((successor (unlist (block-succ block))))
-    (replace-block block successor)
-    ;; At this point, block is unreachable, however we could have
-    ;; backreferences to it from its successors. Let's get rid of
-    ;; them.
-    (setf (block-pred successor) (remove block (block-pred successor)))
-    (setf (block-succ block) nil)))
+  ;; If the block has not successors, then it is already deleted. So
+  ;; just skip it.
+  (when (block-succ block)
+    (let ((successor (unlist (block-succ block))))
+      (replace-block block successor)
+      ;; At this point, block is unreachable, however we could have
+      ;; backreferences to it from its successors. Let's get rid of
+      ;; them.
+      (setf (block-pred successor) (remove block (block-pred successor)))
+      (setf (block-succ block) nil))))
 
 
 ;;;; Cursors