From 93177be0b8b6548e27b54302c7e62a7e26750a20 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 7 Apr 2023 19:21:56 -0700 Subject: compiler: iterate on level 4-5 optimizations. * stdlib/optimize.tl (basic-blocks num-blocks): New method. * stdlib/compiler.tl (compiler optimize): At optimization level 6, instead of performing one extra pass of jump threading, dead-code elimintation and peephole optimizations, keep iterating on these until the number of basic blocks stays the same. * txr.1: Documented. --- stdlib/compiler.tl | 17 ++++++++--------- stdlib/optimize.tl | 3 +++ txr.1 | 4 +++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/stdlib/compiler.tl b/stdlib/compiler.tl index 2a8f97cd..bf6496bb 100644 --- a/stdlib/compiler.tl +++ b/stdlib/compiler.tl @@ -1723,15 +1723,14 @@ bb.(thread-jumps) bb.(elim-dead-code)) (when (>= olev 5) - bb.(calc-liveness) - bb.(peephole) - (when (>= olev 6) - bb.(link-graph) - bb.(thread-jumps)) - bb.(elim-dead-code) - (when (>= olev 6) - bb.(calc-liveness) - bb.(peephole))) + (let ((nblocks nil)) + (while* (and (>= olev 6) + (neql nblocks (set nblocks bb.(num-blocks)))) + bb.(calc-liveness) + bb.(peephole) + bb.(link-graph) + bb.(thread-jumps) + bb.(elim-dead-code)))) (cond ((>= olev 7) bb.(merge-jump-thunks) diff --git a/stdlib/optimize.tl b/stdlib/optimize.tl index ff256db7..8bf8b8c9 100644 --- a/stdlib/optimize.tl +++ b/stdlib/optimize.tl @@ -85,6 +85,9 @@ (mapdo (do set [bb.hash @1.label] @1) bb.list)) bb.(link-graph)) + (:method num-blocks (bb) + (len bb.list)) + (:method get-insns (bb) [mappend .insns bb.list]) diff --git a/txr.1 b/txr.1 index 2a5819a5..e4044901 100644 --- a/txr.1 +++ b/txr.1 @@ -87774,7 +87774,9 @@ Data flow optimizations are applied, such as elimination of dead register moves, or useless propagations of values from one register to another. More peephole optimizations are applied. .IP 6 -Another pass of the levels 4 and 5 optimizations is performed. +Additional iterations of the levels 4 and 5 optimizations are performed, +if the previous iterations have coalesced some basic blocks of the program +graph. .IP 7 Certain more rarely applicable optimizations are applied which reduce code size by merging some identical code blocks, or improving some more rarely -- cgit v1.2.3