diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-07-31 07:10:27 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-07-31 07:10:27 -0700 |
commit | 58354d27c7f3f2d8f75522fe67875a2d57fcae9b (patch) | |
tree | 2a0a8b4127098a388eb4999e9d7270e50921cd8b | |
parent | ddd576f8320ba50df0ca77aaad1829e5cc18d708 (diff) | |
download | txr-58354d27c7f3f2d8f75522fe67875a2d57fcae9b.tar.gz txr-58354d27c7f3f2d8f75522fe67875a2d57fcae9b.tar.bz2 txr-58354d27c7f3f2d8f75522fe67875a2d57fcae9b.zip |
compiler: bugfix: dangling rlinks after dead code elimination
Discovered while experimenting with new optimizations.
* stdlib/optimize.tl (basic-blocks :postinit): Pass t argument
to new parameter of basic-blocks link-graph.
(basic-blocks link-graph): New parameter indicating whether
this is the first call; if false, we reset all the links.
(basic-blocks elim-dead-code): This no longer has to reset
the links before calling link-graph. But now calls link-graph
one more time after the dead code removal so that no dead
blocks appear in the graph.
-rw-r--r-- | stdlib/optimize.tl | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/stdlib/optimize.tl b/stdlib/optimize.tl index 3ca7f07c..7b8d6587 100644 --- a/stdlib/optimize.tl +++ b/stdlib/optimize.tl @@ -87,7 +87,7 @@ insns @1 label (car @1)) lparts)) (mapdo (do set [bb.hash @1.label] @1) bb.list)) - bb.(link-graph)) + bb.(link-graph t)) (:method num-blocks (bb) (len bb.list)) @@ -129,7 +129,13 @@ ,*cases)) ,list)) -(defmeth basic-blocks link-graph (bb) +(defmeth basic-blocks link-graph (bb : first-time) + (unless first-time + (each ((bl bb.list)) + (set bl.links nil + bl.next nil + bl.prev nil + bl.rlinks nil))) (each* ((bl bb.list) (nxbl (append (cdr bl) '(nil)))) (let* ((code bl.insns) @@ -600,11 +606,6 @@ (set bb.list (joinbl bb.list)))) (defmeth basic-blocks elim-dead-code (bb) - (each ((bl bb.list)) - (set bl.links nil - bl.next nil - bl.prev nil - bl.rlinks nil)) bb.(link-graph) (let* ((visited (hash :eq-based))) (labels ((visit (bl) @@ -633,7 +634,8 @@ (del [visited bl]))) (if rep (upd bb.list (keep-if visited)))))) - bb.(join-blocks)) + bb.(join-blocks) + bb.(link-graph)) (defmeth basic-blocks merge-jump-thunks (bb) (let* ((candidates (mappend [andf [chain .links len (op eql 1)] |