Changeset 7941


Ignore:
Timestamp:
Dec 26, 2007, 7:50:53 AM (12 years ago)
Author:
gb
Message:

Try to avoid jumping/branching to jumps. (NB: this requires some
changes to vinsn attributes, so that :JUMP is only used for absolute
pc-relative unconditional branches; that may not yet be true on PPC.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/working-0711/ccl/compiler/vinsn.lisp

    r6474 r7941  
    578578           (insert-dll-node-after lab current))))
    579579      (:branch
    580         (unless (eq prevtype :jump)
    581           (let* ((lab
    582                   (if (eq prevtype :label)
    583                     (dll-node-succ current)
    584                     (aref *backend-labels* (backend-get-next-label))))
    585                  (jump (select-vinsn "JUMP" *backend-vinsns* (list lab))))
    586             (unless (eq prevtype :label)
    587               (insert-dll-node-after lab current))
    588             (insert-dll-node-after jump current))))
     580       (unless (eq prevtype :jump)
     581         (let* ((lab
     582                 (if (eq prevtype :label)
     583                   (dll-node-succ current)
     584                   (aref *backend-labels* (backend-get-next-label))))
     585                (jump (select-vinsn "JUMP" *backend-vinsns* (list lab))))
     586           (unless (eq prevtype :label)
     587             (insert-dll-node-after lab current))
     588           (insert-dll-node-after jump current))))
    589589      ((nil)
    590590       (if (eq prevtype :label)
    591591         (let* ((lab (dll-node-succ current)))
    592592           (when (vinsn-label-p lab)
    593            (insert-dll-node-after
    594             (select-vinsn "JUMP" *backend-vinsns* (list lab))
     593             (insert-dll-node-after
     594              (select-vinsn "JUMP" *backend-vinsns* (list lab))
    595595              current))))))))
    596596
     
    647647  (dll-node-pred (svref (vinsn-variable-parts v) 0)))
    648648
     649(defun replace-label-refs (vinsn old-label new-label)
     650  (let ((vp (vinsn-variable-parts vinsn)))
     651    (dotimes (i (length vp))
     652      (when (eq (svref vp i) old-label)
     653        (setf (svref vp i) new-label)))))
     654 
     655;;; Try to remove jumps/branches to jumps.
     656(defun maximize-jumps (header)
     657  (do* ((prev nil next)
     658        (next (dll-header-first header) (dll-node-succ next)))
     659       ((eq next header))
     660    (when (and (vinsn-attribute-p next :jump)
     661               (vinsn-label-p  prev))
     662      (let* ((target (svref (vinsn-variable-parts next) 0)))
     663        (unless (eq target prev)
     664          (dolist (ref (vinsn-label-refs prev) (setf (vinsn-label-refs prev) nil))
     665            (replace-label-refs ref prev target)
     666            (push ref (vinsn-label-refs target))))))))
    649667
    650668(defun optimize-vinsns (header)
     
    669687            (setq repeat t)
    670688            (return)))))
     689    (maximize-jumps header)
    671690    (delete-unreferenced-labels labels)
    672691    (normalize-vinsns header)
Note: See TracChangeset for help on using the changeset viewer.