diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-02-27 12:19:19 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-02-27 12:19:19 -0800 |
commit | 37c3ab2c08d6546c90e3b77ba1893ec174b097a0 (patch) | |
tree | 1ecc206680d41799774a3a7fd692f2cabdbf6f62 | |
parent | 5e8fa7f8d40eed6218ae39886181eff0140059b3 (diff) | |
download | txr-37c3ab2c08d6546c90e3b77ba1893ec174b097a0.tar.gz txr-37c3ab2c08d6546c90e3b77ba1893ec174b097a0.tar.bz2 txr-37c3ab2c08d6546c90e3b77ba1893ec174b097a0.zip |
compiler: eliminate jumps to following instruction.
* share/txr/stdlib/optimize.tl (basic-blocks elim-next-jump):
New method, which detects that the basic block ends with a
(jmp label), where label is the next block in emit order.
This jmp instruction can be eliminated.
(basic-blocks elim-dead-code): Walk the reachable labels,
and call elim-next-jmp to remove useless jumps.
-rw-r--r-- | share/txr/stdlib/optimize.tl | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/share/txr/stdlib/optimize.tl b/share/txr/stdlib/optimize.tl index 81536c32..a2054ca3 100644 --- a/share/txr/stdlib/optimize.tl +++ b/share/txr/stdlib/optimize.tl @@ -390,6 +390,14 @@ (dohash (label bl bb.hash) (set bl.insns bb.(thread-jumps-block label bl.insns)))) +(defmeth basic-blocks elim-next-jump (bb bl label) + (let* ((tail (last bl.insns)) + (linsn (car tail))) + (when-match (jmp @jlabel) linsn + (let ((next bb.(next-block label))) + (when (eql [bb.hash next].?label jlabel) + (set bl.insns (butlast bl.insns))))))) + (defmeth basic-blocks elim-dead-code (bb) (dohash (label bl bb.hash) (set bl.links nil)) @@ -406,7 +414,9 @@ (add bl.label) (visit bl)) (visit bb.root))))) - (set bb.labels [keep-if (chain bb.hash visited) bb.labels]))) + (set bb.labels [keep-if (chain bb.hash visited) bb.labels]) + (each ((lb bb.labels)) + bb.(elim-next-jump [bb.hash lb] lb)))) (defun rewrite (fun list) (build |