Ignore:
Timestamp:
08/07/10 11:53:23 (13 years ago)
Author:
ehuelsmann
Message:

Eliminate optimize-2: Partially, it duplicated DELETE-UNREACHABLE-CODE.
The other part moves to OPTIMIZE-3.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/generic-class-file/abcl/src/org/armedbear/lisp/compiler-pass2.lisp

    r12870 r12871  
    919919
    920920
    921 
    922 (defun optimize-2 ()
    923   (let* ((code (coerce *code* 'vector))
    924          (length (length code))
    925          (changed nil))
    926     (declare (type (unsigned-byte 16) length))
    927     ;; Since we're looking at this instruction and the next one, we can stop
    928     ;; one before the end.
    929     (dotimes (i (1- length))
    930       (declare (type (unsigned-byte 16) i))
    931       (let ((instruction (aref code i)))
    932         (when (and instruction (= (instruction-opcode instruction) 167)) ; GOTO
    933           (do* ((j (1+ i) (1+ j))
    934                 (next-instruction (aref code j) (aref code j)))
    935                ((>= j length))
    936             (declare (type (unsigned-byte 16) j))
    937             (when next-instruction
    938               (cond ((= (instruction-opcode next-instruction) 167) ; GOTO
    939                      (cond ((= j (1+ i))
    940                             ;; Two GOTOs in a row: the second instruction is
    941                             ;; unreachable.
    942                             (setf (aref code j) nil)
    943                             (setf changed t))
    944                            ((eq (car (instruction-args next-instruction))
    945                                 (car (instruction-args instruction)))
    946                             ;; We've reached another GOTO to the same destination.
    947                             ;; We don't need the first GOTO; we can just fall
    948                             ;; through to the second one.
    949                             (setf (aref code i) nil)
    950                             (setf changed t)))
    951                      (return))
    952                     ((= (instruction-opcode next-instruction) 202) ; LABEL
    953                      (when (eq (car (instruction-args instruction))
    954                                (car (instruction-args next-instruction)))
    955                        ;; GOTO next instruction; we don't need this one.
    956                        (setf (aref code i) nil)
    957                        (setf changed t)
    958                        (return)))
    959                     (t
    960                      ;; Not a GOTO or a label.
    961                      (return))))))))
    962     (when changed
    963       (setf *code* (delete nil code))
    964       t)))
    965 
    966921;; CLEAR-VALUES CLEAR-VALUES => CLEAR-VALUES
    967922;; GETSTATIC POP => nothing
     
    972927      (declare (type (unsigned-byte 16) i))
    973928      (let* ((this-instruction (aref code i))
    974              (this-opcode (and this-instruction (instruction-opcode this-instruction)))
     929             (this-opcode (and this-instruction
     930                               (instruction-opcode this-instruction)))
    975931             (next-instruction (aref code (1+ i)))
    976              (next-opcode (and next-instruction (instruction-opcode next-instruction))))
     932             (next-opcode (and next-instruction
     933                               (instruction-opcode next-instruction))))
    977934        (case this-opcode
    978935          (205 ; CLEAR-VALUES
     
    984941             (setf (aref code i) nil)
    985942             (setf (aref code (1+ i)) nil)
     943             (setf changed t)))
     944          (167 ; GOTO
     945           (when (and (eql next-opcode 202)  ; LABEL
     946                      (eq (car (instruction-args this-instruction))
     947                          (car (instruction-args next-instruction))))
     948             (setf (aref code i) nil)
     949             ;;(setf (aref code (1+ i)) nil)
    986950             (setf changed t))))))
    987951    (when changed
     
    1008972                                 (mapcar #'handler-to *handlers*)
    1009973                                 (mapcar #'handler-code *handlers*))))
    1010         (setf changed-p (or (optimize-2) changed-p))
    1011974        (if changed-p
    1012975            (setf *code* (optimize-jumps *code*))
Note: See TracChangeset for help on using the changeset viewer.