aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Corallo2020-09-27 23:43:35 +0200
committerAndrea Corallo2020-10-10 20:25:57 +0200
commit4b924ef87d69d56ef78604fbcb50399578f83f5a (patch)
tree93a626850f69d00ea15e6fc84d74d9b49e1a447a
parent96f59a9faf375409a0301a54fcb46fc2325a9cc2 (diff)
downloademacs-4b924ef87d69d56ef78604fbcb50399578f83f5a.tar.gz
emacs-4b924ef87d69d56ef78604fbcb50399578f83f5a.zip
* As edges are indexed store them in an hash table
* lisp/emacs-lisp/comp.el (comp-edge): Update doc for 'number' slot. (comp-func): Rename 'edges' slot into 'edges-h'. (comp-log-edges): Update logic for edges in an hash table. (comp-clean-ssa, comp-compute-edges): Likewise.
-rw-r--r--lisp/emacs-lisp/comp.el42
1 files changed, 20 insertions, 22 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index be29f84cd32..b4a86fc83ec 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -336,7 +336,7 @@ into it.")
336 (dst nil :type comp-block) 336 (dst nil :type comp-block)
337 (number nil :type number 337 (number nil :type number
338 :documentation "The index number corresponding to this edge in the 338 :documentation "The index number corresponding to this edge in the
339 edge vector.")) 339 edge hash."))
340 340
341(defun comp-block-preds (basic-block) 341(defun comp-block-preds (basic-block)
342 "Given BASIC-BLOCK return the list of its predecessors." 342 "Given BASIC-BLOCK return the list of its predecessors."
@@ -371,8 +371,8 @@ CFG is mutated by a pass.")
371 :documentation "Basic block name -> basic block.") 371 :documentation "Basic block name -> basic block.")
372 (lap-block (make-hash-table :test #'equal) :type hash-table 372 (lap-block (make-hash-table :test #'equal) :type hash-table
373 :documentation "LAP lable -> LIMPLE basic block name.") 373 :documentation "LAP lable -> LIMPLE basic block name.")
374 (edges () :type list 374 (edges-h (make-hash-table) :type hash-table
375 :documentation "List of edges connecting basic blocks.") 375 :documentation "Hash edge-num -> edge connecting basic two blocks.")
376 (block-cnt-gen (funcall #'comp-gen-counter) :type function 376 (block-cnt-gen (funcall #'comp-gen-counter) :type function
377 :documentation "Generates block numbers.") 377 :documentation "Generates block numbers.")
378 (edge-cnt-gen (funcall #'comp-gen-counter) :type function 378 (edge-cnt-gen (funcall #'comp-gen-counter) :type function
@@ -555,16 +555,16 @@ VERBOSITY is a number between 0 and 3."
555 555
556(defun comp-log-edges (func) 556(defun comp-log-edges (func)
557 "Log edges in FUNC." 557 "Log edges in FUNC."
558 (let ((edges (comp-func-edges func))) 558 (let ((edges (comp-func-edges-h func)))
559 (comp-log (format "\nEdges in function: %s\n" 559 (comp-log (format "\nEdges in function: %s\n"
560 (comp-func-name func)) 560 (comp-func-name func))
561 2) 561 2)
562 (mapc (lambda (e) 562 (maphash (lambda (_ e)
563 (comp-log (format "n: %d src: %s dst: %s\n" 563 (comp-log (format "n: %d src: %s dst: %s\n"
564 (comp-edge-number e) 564 (comp-edge-number e)
565 (comp-block-name (comp-edge-src e)) 565 (comp-block-name (comp-edge-src e))
566 (comp-block-name (comp-edge-dst e))) 566 (comp-block-name (comp-edge-dst e)))
567 2)) 567 2))
568 edges))) 568 edges)))
569 569
570 570
@@ -1693,7 +1693,7 @@ into the C code forwarding the compilation unit."
1693 1693
1694(defun comp-clean-ssa (f) 1694(defun comp-clean-ssa (f)
1695 "Clean-up SSA for funtion F." 1695 "Clean-up SSA for funtion F."
1696 (setf (comp-func-edges f) ()) 1696 (setf (comp-func-edges-h f) (make-hash-table))
1697 (cl-loop 1697 (cl-loop
1698 for b being each hash-value of (comp-func-blocks f) 1698 for b being each hash-value of (comp-func-blocks f)
1699 do (setf (comp-block-in-edges b) () 1699 do (setf (comp-block-in-edges b) ()
@@ -1709,12 +1709,12 @@ into the C code forwarding the compilation unit."
1709 1709
1710(defun comp-compute-edges () 1710(defun comp-compute-edges ()
1711 "Compute the basic block edges for the current function." 1711 "Compute the basic block edges for the current function."
1712 (cl-flet ((edge-add (&rest args) 1712 (cl-flet ((edge-add (&rest args &aux (n (funcall
1713 (push 1713 (comp-func-edge-cnt-gen comp-func))))
1714 (apply #'make--comp-edge 1714 (puthash
1715 :number (funcall (comp-func-edge-cnt-gen comp-func)) 1715 n
1716 args) 1716 (apply #'make--comp-edge :number n args)
1717 (comp-func-edges comp-func)))) 1717 (comp-func-edges-h comp-func))))
1718 1718
1719 (cl-loop with blocks = (comp-func-blocks comp-func) 1719 (cl-loop with blocks = (comp-func-blocks comp-func)
1720 for bb being each hash-value of blocks 1720 for bb being each hash-value of blocks
@@ -1738,18 +1738,16 @@ into the C code forwarding the compilation unit."
1738 (list "block does not end with a branch" 1738 (list "block does not end with a branch"
1739 bb 1739 bb
1740 (comp-func-name comp-func))))) 1740 (comp-func-name comp-func)))))
1741 finally
1742 (setf (comp-func-edges comp-func)
1743 (nreverse (comp-func-edges comp-func)))
1744 ;; Update edge refs into blocks. 1741 ;; Update edge refs into blocks.
1742 finally
1745 (cl-loop 1743 (cl-loop
1746 for edge in (comp-func-edges comp-func) 1744 for edge being the hash-value in (comp-func-edges-h comp-func)
1747 do 1745 do
1748 (push edge 1746 (push edge
1749 (comp-block-out-edges (comp-edge-src edge))) 1747 (comp-block-out-edges (comp-edge-src edge)))
1750 (push edge 1748 (push edge
1751 (comp-block-in-edges (comp-edge-dst edge)))) 1749 (comp-block-in-edges (comp-edge-dst edge))))
1752 (comp-log-edges comp-func)))) 1750 (comp-log-edges comp-func))))
1753 1751
1754(defun comp-collect-rev-post-order (basic-block) 1752(defun comp-collect-rev-post-order (basic-block)
1755 "Walk BASIC-BLOCK children and return their name in reversed post-order." 1753 "Walk BASIC-BLOCK children and return their name in reversed post-order."