summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-03-10 08:09:08 -0800
committerKaz Kylheku <kaz@kylheku.com>2021-03-10 08:09:08 -0800
commit631dc14534aef3fa17feb3864aedaa9a4292e796 (patch)
treeaae7c0c3ed91d40784f1c98699e322a0123fdc6c
parentbb526b11ed93a0853eecac8bb5d0588bec61e837 (diff)
downloadtxr-631dc14534aef3fa17feb3864aedaa9a4292e796.tar.gz
txr-631dc14534aef3fa17feb3864aedaa9a4292e796.tar.bz2
txr-631dc14534aef3fa17feb3864aedaa9a4292e796.zip
compiler: eliminate unused closures.
In this patch, we optimize away closures that are not used. Unused closures that have been hoisted to the top level are not affected. We look for close instructions which produce a dead treg, and rewrite these to jmp instructions to the same label. When this happend, we set a flag for a dead code elimination pass to be done again, to actually remove the now unreachable closure code. * share/txr/stdlib/optimize.tl (struct basic-blocks): New slot, reelim, indicating that dead code elimination is to be done again after peephole since the control flow graph has changed. (basic-blocks peephole-block): New pattern for eliminating a dead register, targeting the close instruction. (basic-blocks peephole): After peephole, check whether the reelim flag has been set and do elim-dead-code again.
-rw-r--r--share/txr/stdlib/optimize.tl11
1 files changed, 10 insertions, 1 deletions
diff --git a/share/txr/stdlib/optimize.tl b/share/txr/stdlib/optimize.tl
index 8f166a6f..109dc9b3 100644
--- a/share/txr/stdlib/optimize.tl
+++ b/share/txr/stdlib/optimize.tl
@@ -57,6 +57,7 @@
list
rescan
recalc
+ reelim
(:static start (gensym "start-"))
(:static jump-ops '(jmp if ifq ifql close swtch ret abscsr
uwprot catch block jend))
@@ -359,6 +360,12 @@
(pushnew bl bb.rescan)
(set bb.recalc t)
(cdr insns))
+ (@(require ((close (t @n) @nil @nil @jlabel . @nil) . @nil)
+ (dead-treg (car insns) n))
+ (pushnew bl bb.rescan)
+ (set bb.recalc t
+ bb.reelim t)
+ ^((jmp ,jlabel) ,*(cdr insns)))
(@(require ((@(or gcall gapply) (t @n) @idx . @nil) . @nil)
(dead-treg (car insns) n)
[%const-foldable% [bb.symvec idx]])
@@ -436,7 +443,9 @@
bb.(calc-liveness rescan)
(set bb.recalc nil))
(each ((bl rescan))
- (set bl.insns bb.(peephole-block bl bl.insns)))))
+ (set bl.insns bb.(peephole-block bl bl.insns))))
+ (when bb.reelim
+ bb.(elim-dead-code)))
(defmeth basic-blocks thread-jumps (bb)
(each ((bl bb.list))