aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Corallo2019-07-14 17:21:34 +0200
committerAndrea Corallo2020-01-01 11:33:53 +0100
commit988a5133dc86e28e4b097d2c8d64d25e37bb6c5d (patch)
treeb3654efa574d7dd0e22245c488e970330bf785a5
parent1deb54f5c9c0b4f3c594e4f4aa76b42a67643976 (diff)
downloademacs-988a5133dc86e28e4b097d2c8d64d25e37bb6c5d.tar.gz
emacs-988a5133dc86e28e4b097d2c8d64d25e37bb6c5d.zip
block to hash
-rw-r--r--lisp/emacs-lisp/comp.el39
-rw-r--r--src/comp.c17
2 files changed, 39 insertions, 17 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index e2c8fe427e3..6f4b94d308b 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -74,6 +74,13 @@ To be used when ncall-conv is nil.")
74 :documentation "If t the signature is: 74 :documentation "If t the signature is:
75(ptrdiff_t nargs, Lisp_Object *args)")) 75(ptrdiff_t nargs, Lisp_Object *args)"))
76 76
77(cl-defstruct (comp-block (:copier nil))
78 "A basic block."
79 (sp nil
80 :documentation "When non nil indicates its the sp value")
81 (closed nil :type 'boolean
82 :documentation "If the block was already closed"))
83
77(cl-defstruct (comp-func (:copier nil)) 84(cl-defstruct (comp-func (:copier nil))
78 "Internal rapresentation for a function." 85 "Internal rapresentation for a function."
79 (symbol-name nil 86 (symbol-name nil
@@ -88,8 +95,9 @@ To be used when ncall-conv is nil.")
88 :documentation "Current intermediate rappresentation") 95 :documentation "Current intermediate rappresentation")
89 (args nil :type 'comp-args) 96 (args nil :type 'comp-args)
90 (frame-size nil :type 'number) 97 (frame-size nil :type 'number)
91 (blocks () :type list 98 (blocks (make-hash-table) :type 'hash-table
92 :documentation "List of basic block") 99 :documentation "Key is the basic block symbol value is a comp-block
100structure")
93 (lap-block (make-hash-table :test #'equal) :type 'hash-table 101 (lap-block (make-hash-table :test #'equal) :type 'hash-table
94 :documentation "Key value to convert from LAP label number to 102 :documentation "Key value to convert from LAP label number to
95LIMPLE basic block") 103LIMPLE basic block")
@@ -258,26 +266,31 @@ If the calle function is known to have a return type propagate it."
258 :constant val)) 266 :constant val))
259 (comp-emit (list 'setimm (comp-slot) val))) 267 (comp-emit (list 'setimm (comp-slot) val)))
260 268
261(defun comp-emit-block (bblock) 269(defun comp-emit-block (block-name)
262 "Emit basic block BBLOCK." 270 "Emit basic block BLOCK-NAME."
263 (cl-pushnew bblock (comp-func-blocks comp-func) :test #'eq) 271 (unless (gethash block-name (comp-func-blocks comp-func))
272 (puthash block-name
273 (make-comp-block :sp (comp-sp))
274 (comp-func-blocks comp-func)))
264 ;; Every new block we are forced to wipe out all the frame. 275 ;; Every new block we are forced to wipe out all the frame.
265 ;; This will be optimized by proper flow analysis. 276 ;; This will be optimized by proper flow analysis.
266 (setf (comp-limple-frame-frame comp-frame) 277 (setf (comp-limple-frame-frame comp-frame)
267 (comp-limple-frame-new-frame (comp-func-frame-size comp-func))) 278 (comp-limple-frame-new-frame (comp-func-frame-size comp-func)))
268 ;; If we are landing here form a recorded branch adjust sp accordingly. 279 ;; If we are landing here form a recorded branch adjust sp accordingly.
269 (if-let ((new-sp (gethash bblock (comp-limple-frame-block-sp comp-frame)))) 280 (setf (comp-sp)
270 (setf (comp-sp) new-sp)) 281 (comp-block-sp (gethash block-name (comp-func-blocks comp-func))))
271 (comp-emit `(block ,bblock))) 282 (comp-emit `(block ,block-name)))
272 283
273(defmacro comp-with-fall-through-block (bb &rest body) 284(defmacro comp-with-fall-through-block (bb &rest body)
274 "Create a basic block BB that is used to fall through after executing BODY." 285 "Create a basic block BB that is used to fall through after executing BODY."
275 (declare (debug (form body)) 286 (declare (debug (form body))
276 (indent defun)) 287 (indent defun))
277 `(let ((,bb (comp-new-block-sym))) 288 `(let ((,bb (comp-new-block-sym)))
278 (push ,bb (comp-func-blocks comp-func)) 289 (puthash ,bb
279 (progn ,@body) 290 (make-comp-block :sp (comp-sp))
280 (comp-emit-block ,bb))) 291 (comp-func-blocks comp-func))
292 (progn ,@body)
293 (comp-emit-block ,bb)))
281 294
282(defun comp-stack-adjust (n) 295(defun comp-stack-adjust (n)
283 "Move sp by N." 296 "Move sp by N."
@@ -298,7 +311,7 @@ If the calle function is known to have a return type propagate it."
298 311
299(defun comp-new-block-sym () 312(defun comp-new-block-sym ()
300 "Return a symbol naming the next new basic block." 313 "Return a symbol naming the next new basic block."
301 (intern (format "bb_%s" (length (comp-func-blocks comp-func))))) 314 (intern (format "bb_%s" (hash-table-count (comp-func-blocks comp-func)))))
302 315
303(defun comp-lap-to-limple-bb (n) 316(defun comp-lap-to-limple-bb (n)
304 "Given the LAP label N return the limple basic block." 317 "Given the LAP label N return the limple basic block."
@@ -562,8 +575,6 @@ If the calle function is known to have a return type propagate it."
562 (comp-emit-block 'body) 575 (comp-emit-block 'body)
563 (mapc #'comp-limplify-lap-inst (comp-func-ir func)) 576 (mapc #'comp-limplify-lap-inst (comp-func-ir func))
564 (setf (comp-func-ir func) (reverse comp-limple)) 577 (setf (comp-func-ir func) (reverse comp-limple))
565 ;; Prologue block must be first
566 (setf (comp-func-blocks func) (reverse (comp-func-blocks func)))
567 (when comp-debug 578 (when comp-debug
568 (cl-prettyprint (comp-func-ir func))) 579 (cl-prettyprint (comp-func-ir func)))
569 func)) 580 func))
diff --git a/src/comp.c b/src/comp.c
index e407c079b63..c97fe404cad 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -212,7 +212,7 @@ retrive_block (Lisp_Object symbol)
212} 212}
213 213
214static void 214static void
215declare_block (char *block_name) 215declare_block (const char * block_name)
216{ 216{
217 gcc_jit_block *block = gcc_jit_function_new_block (comp.func, block_name); 217 gcc_jit_block *block = gcc_jit_function_new_block (comp.func, block_name);
218 Lisp_Object key = make_string (block_name, strlen (block_name)); 218 Lisp_Object key = make_string (block_name, strlen (block_name));
@@ -1977,7 +1977,7 @@ DEFUN ("comp-add-func-to-ctxt", Fcomp_add_func_to_ctxt, Scomp_add_func_to_ctxt,
1977 Lisp_Object args = FUNCALL1 (comp-func-args, func); 1977 Lisp_Object args = FUNCALL1 (comp-func-args, func);
1978 EMACS_INT frame_size = XFIXNUM (FUNCALL1 (comp-func-frame-size, func)); 1978 EMACS_INT frame_size = XFIXNUM (FUNCALL1 (comp-func-frame-size, func));
1979 EMACS_INT min_args = XFIXNUM (FUNCALL1 (comp-args-min, args)); 1979 EMACS_INT min_args = XFIXNUM (FUNCALL1 (comp-args-min, args));
1980 EMACS_INT max_args = XFIXNUM (FUNCALL1 (comp-args-max, args)); 1980 /* EMACS_INT max_args = XFIXNUM (FUNCALL1 (comp-args-max, args)); */
1981 bool ncall = !NILP (FUNCALL1 (comp-args-ncall-conv, args)); 1981 bool ncall = !NILP (FUNCALL1 (comp-args-ncall-conv, args));
1982 1982
1983 if (!ncall) 1983 if (!ncall)
@@ -2015,8 +2015,19 @@ DEFUN ("comp-add-func-to-ctxt", Fcomp_add_func_to_ctxt, Scomp_add_func_to_ctxt,
2015 2015
2016 comp.func_blocks = CALLN (Fmake_hash_table, QCtest, Qequal, QCweakness, Qt); 2016 comp.func_blocks = CALLN (Fmake_hash_table, QCtest, Qequal, QCweakness, Qt);
2017 2017
2018 /* Pre declare all basic blocks. */ 2018 /* Pre declare all basic blocks to gcc.
2019 The "entry" block must be declared as first. */
2020 declare_block ("entry");
2019 Lisp_Object blocks = FUNCALL1 (comp-func-blocks, func); 2021 Lisp_Object blocks = FUNCALL1 (comp-func-blocks, func);
2022 Lisp_Object entry_block = Fgethash (intern ("entry"), blocks, Qnil);
2023 struct Lisp_Hash_Table *ht = XHASH_TABLE (blocks);
2024 for (ptrdiff_t i = 0; i < ht->count; i++)
2025 {
2026 Lisp_Object block = HASH_VALUE (ht, i);
2027 if (!EQ (block, entry_block))
2028 declare_block ((char *) SDATA (SYMBOL_NAME (HASH_KEY (ht, i))));
2029 }
2030
2020 while (CONSP (blocks)) 2031 while (CONSP (blocks))
2021 { 2032 {
2022 char *block_name = (char *) SDATA (SYMBOL_NAME (XCAR (blocks))); 2033 char *block_name = (char *) SDATA (SYMBOL_NAME (XCAR (blocks)));