summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-04-17 16:46:10 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-04-17 16:46:10 -0700
commit1d8779bc361158bd49ae6fe1d487f59fbfe7b2e3 (patch)
treeb355e8c7149feee177c2f049bdff0172eac56d1d /stdlib
parent1cd7fb50f4a68b39c6715203bc7e92808188d7c0 (diff)
downloadtxr-1d8779bc361158bd49ae6fe1d487f59fbfe7b2e3.tar.gz
txr-1d8779bc361158bd49ae6fe1d487f59fbfe7b2e3.tar.bz2
txr-1d8779bc361158bd49ae6fe1d487f59fbfe7b2e3.zip
compiler: rewrite t-regs through defining instruction.
* stdlib/optimize.tl (subst-preserve): Rename list param to insn for clarity. (careful-subst-preserve): New function. This is like subst-preserve, but used only for instructions that have destination registers. It performs a rewrite such that those destination positions are avoided. (basic-blocks rename): When the instruction has src or dst as a target, don't just stop before that insn. Do the substitution in the source operands using careful-subst-preserve.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/optimize.tl30
1 files changed, 24 insertions, 6 deletions
diff --git a/stdlib/optimize.tl b/stdlib/optimize.tl
index e78c9300..f3e2a6c6 100644
--- a/stdlib/optimize.tl
+++ b/stdlib/optimize.tl
@@ -354,10 +354,25 @@
((nequal ninsn oinsn) (append (ldiff code tail) (list ninsn)))
(t code))))
-(defun subst-preserve (x y bb li list)
- (let ((sub (subst x y list)))
+(defun subst-preserve (x y bb li insn)
+ (let ((sub (subst x y insn)))
(cond
- ((equal sub list) list)
+ ((equal sub insn) insn)
+ (t (set [bb.li-hash sub] li) sub))))
+
+(defun careful-subst-preserve (x y bb li insn)
+ (let ((sub (match-case insn
+ ((@(or apply call) @def . @refs)
+ ^(,(car insn) ,def ,*(subst x y refs)))
+ ((@(or gapply gcall) @def @fn . @refs)
+ ^(,(car insn) ,def ,fn ,*(subst x y refs)))
+ ((mov @def @x)
+ ^(mov ,def ,y))
+ ((catch @esreg @eareg . @refs)
+ ^(catch ,esreg ,eareg ,*(subst x y refs)))
+ (@else else))))
+ (cond
+ ((equal sub insn) insn)
(t (set [bb.li-hash sub] li) sub))))
(defmeth basic-blocks rename (bb insns dst src)
@@ -369,12 +384,15 @@
(li [bb.li-hash insn]))
(cond
(close (add insn))
- ((or (and vreg end)
- (mequal li.def0 dst src)
- (mequal li.def1 dst src))
+ ((and vreg end)
(add insn)
(pend insns)
(set insns nil))
+ ((or (mequal dst li.def0 li.def1)
+ (mequal src li.def0 li.def1))
+ (add (careful-subst-preserve dst src bb li insn))
+ (pend insns)
+ (set insns nil))
(t (add (subst-preserve dst src bb li insn)))))))))
(defmeth basic-blocks peephole-block (bb bl)