summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-04-07 05:14:00 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-04-07 05:14:00 -0700
commit2cf17e97d6b433405700653e7e2c885ad5dd75de (patch)
tree8a80b3cee917cd546b9e3e351ebf7cfdbd71027d /stdlib
parent03d79d37bfbaccddbf7c83d25770a35fda95dad7 (diff)
downloadtxr-2cf17e97d6b433405700653e7e2c885ad5dd75de.tar.gz
txr-2cf17e97d6b433405700653e7e2c885ad5dd75de.tar.bz2
txr-2cf17e97d6b433405700653e7e2c885ad5dd75de.zip
compiler: optimization improvements
* stdlib/optimize.tl (basic-blocks peephole-block): Drop the code argument, and operate on bl.insns, which is stored back. Perform the renames in the rename list after the peephole pass. (basic-blocks rename): New method. (basic-blocks do-peephole-block): Implementation of peephole-block, under a new name. The local function called rename is removed; calls to it go to the new rename method. (basic-blocks peephole): Simplify code around calls to peephole-block; we no longer have to pass bl.insns to it, capture the return value and store it back into bl.insns. * stdlib/compiler.tl (*opt-level*): Initial value changes from 6 to 7. (compiler optimize): At optimization level 6, we now do another jump threading pass, and peephole, like at levels 4 and 5. The peephole optimizations at level 5 make it possible to coalesce some basic blocks in some cases, and that opens up the possibility for more reductions. The previously level 6 optimizations are moved to level 7. * txr.1: Updated documentation of optimization levels, and default value of *opt-level*. * stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/compiler.tl15
-rw-r--r--stdlib/doc-syms.tl124
-rw-r--r--stdlib/optimize.tl19
3 files changed, 85 insertions, 73 deletions
diff --git a/stdlib/compiler.tl b/stdlib/compiler.tl
index 5e5fff6b..2a8f97cd 100644
--- a/stdlib/compiler.tl
+++ b/stdlib/compiler.tl
@@ -378,8 +378,9 @@
;; 3 - lambda/combinator lifting
;; 4 - control-flow: jump-threading, dead code
;; 5 - data-flow: dead registers, useless regisers
-;; 6 - more expensive size or speed optimizations
-(defvar usr:*opt-level* 6)
+;; 6 - iterate on 4-5 optimizations.
+;; 7 - more expensive size or speed optimizations
+(defvar usr:*opt-level* 7)
(defun dedup (obj)
(cond
@@ -1724,9 +1725,15 @@
(when (>= olev 5)
bb.(calc-liveness)
bb.(peephole)
- bb.(elim-dead-code))
+ (when (>= olev 6)
+ bb.(link-graph)
+ bb.(thread-jumps))
+ bb.(elim-dead-code)
+ (when (>= olev 6)
+ bb.(calc-liveness)
+ bb.(peephole)))
(cond
- ((>= olev 6)
+ ((>= olev 7)
bb.(merge-jump-thunks)
bb.(compact-tregs)
bb.(late-peephole bb.(get-insns)))
diff --git a/stdlib/doc-syms.tl b/stdlib/doc-syms.tl
index 36df7eea..57ccce7f 100644
--- a/stdlib/doc-syms.tl
+++ b/stdlib/doc-syms.tl
@@ -4,7 +4,7 @@
("%e%" "N-03F0FA9E")
("%fun%" "N-00719365")
("%pi%" "N-03F0FA9E")
- ("*" "D-003A")
+ ("*" "D-0039")
("*args*" "N-03DEE18A")
("*args-eff*" "N-03DEE18A")
("*args-full*" "N-03DEE18A")
@@ -54,7 +54,7 @@
("*tree-fun-whitelist*" "N-025AB9C9")
("*unhandled-hook*" "N-02B4A4FB")
("+" "D-0045")
- ("-" "D-004B")
+ ("-" "D-004A")
("--" "N-0234C408")
("--rng" "N-01A056E4")
("--rng+" "N-01A056E4")
@@ -64,7 +64,7 @@
("-rng" "N-01A056E4")
("-rng+" "N-01A056E4")
("-rng-" "N-01A056E4")
- ("/" "D-004A")
+ ("/" "D-004B")
("//" "N-0054C409")
("/=" "N-003BE40C")
(":delegate" "N-037F664C")
@@ -74,18 +74,18 @@
("<" "D-0058")
("<!" "N-02B10DF9")
("<-" "N-02B10DF9")
- ("<=" "D-001E")
- ("=" "D-007A")
- (">" "D-0062")
- (">=" "D-0054")
+ ("<=" "D-0020")
+ ("=" "D-0079")
+ (">" "D-0063")
+ (">=" "D-0052")
("abort" "N-02F934F6")
("abs" "D-0017")
("abs-path-p" "N-00477B23")
- ("accept" "D-0044")
+ ("accept" "D-0043")
("acons" "N-02E9343D")
("acons-new" "N-0371BAFA")
("aconsql-new" "N-01E315BD")
- ("acos" "D-0028")
+ ("acos" "D-0026")
("acosh" "D-0042")
("add" "N-03244398")
("add*" "N-03244398")
@@ -130,8 +130,8 @@
("arraysize" "N-002129D6")
("as" "N-028B26DD")
("ash" "D-0065")
- ("asin" "D-003D")
- ("asinh" "D-0004")
+ ("asin" "D-003F")
+ ("asinh" "D-0001")
("assert" "D-0061")
("assoc" "N-00E9306D")
("assq" "N-00123702")
@@ -139,7 +139,7 @@
("at-exit-call" "N-003EEEF5")
("at-exit-do-not-call" "N-003EEEF5")
("atan" "D-0051")
- ("atan2" "D-000A")
+ ("atan2" "D-0009")
("atanh" "D-0024")
("atom" "N-0076C7BE")
("awk" "D-0059")
@@ -157,13 +157,13 @@
("bchar" "N-0008D7DC")
("bignum-len" "N-020294AB")
("bignump" "N-03E9D6E1")
- ("bind" "D-006F")
+ ("bind" "D-006D")
("bindable" "N-0222F2E3")
("bit" "D-004D")
- ("bitset" "D-0037")
+ ("bitset" "D-0038")
("blkcnt-t" "N-01153D9E")
("blksize-t" "N-01153D9E")
- ("block" "D-0071")
+ ("block" "D-006F")
("block*" "N-02F60DCE")
("bool" "D-002C")
("boundp" "N-01FBF828")
@@ -281,7 +281,7 @@
("cat-str" "N-00B6ACE3")
("cat-streams" "N-020BF082")
("cat-vec" "N-01AEB28B")
- ("catch" "D-0011")
+ ("catch" "D-000F")
("catch*" "N-0211F3D3")
("catch**" "N-0211F3D3")
("catch-frame" "N-0233BAE3")
@@ -292,7 +292,7 @@
("cdar" "N-001FA3CB")
("cdddddr" "N-001FA3CB")
("cddr" "N-001FA3CB")
- ("cdr" "D-0079")
+ ("cdr" "D-007A")
("ceil" "D-007E")
("ceil-rem" "N-02DE978F")
("ceil1" "N-02C8FF28")
@@ -341,7 +341,7 @@
("clocal" "N-01B1B5DF")
("clock-t" "N-01B6F219")
("clockid-t" "N-01153D9E")
- ("close" "D-0016")
+ ("close" "D-0015")
("close-lazy-streams" "N-00B8ACD5")
("close-stream" "N-00596930")
("closedir" "N-01FEE88A")
@@ -350,7 +350,7 @@
("cmp-str" "N-0143A273")
("cmspar" "N-01B1B5DF")
("coded-length" "N-0167F423")
- ("coll" "D-005A")
+ ("coll" "D-005B")
("collect" "D-0030")
("collect-each" "N-0105F01D")
("collect-each*" "N-0105F01D")
@@ -453,7 +453,7 @@
("data" "N-03B6EA7D")
("dec" "N-03A0AABD")
("defer-warning" "N-001106AB")
- ("defex" "D-005E")
+ ("defex" "D-005F")
("deffi" "N-00DCE51D")
("deffi-cb" "N-00C54FC8")
("deffi-cb-unsafe" "N-00C54FC8")
@@ -528,7 +528,7 @@
("dump-deferred-warnings" "N-0335651E")
("dup" "N-0387F549")
("dupfd" "N-01F91AEF")
- ("dwim" "D-001F")
+ ("dwim" "D-001E")
("e2big" "N-036B1BDB")
("eacces" "N-036B1BDB")
("each" "N-0105F01D")
@@ -658,7 +658,7 @@
("etypecase" "N-033FBE77")
("eval" "N-0286C8B8")
("eval-only" "N-030BF4F5")
- ("evenp" "D-001C")
+ ("evenp" "D-0019")
("ewouldblock" "N-036B1BDB")
("exception-subtype-map" "N-03ABFA6D")
("exception-subtype-p" "N-02E7F869")
@@ -672,7 +672,7 @@
("expand-left" "N-00E168FE")
("expand-right" "N-023B6B64")
("expand-with-free-refs" "N-0334827B")
- ("expt" "D-0077")
+ ("expt" "D-0076")
("exptmod" "D-0036")
("extproc" "N-0072FF5E")
("f" "N-003BDFA9")
@@ -737,7 +737,7 @@
("file-put-lines" "N-0041C2E5")
("file-put-string" "N-0041C2E5")
("fileno" "N-008ACF75")
- ("fill-buf" "D-0026")
+ ("fill-buf" "D-0028")
("fill-buf-adjust" "N-00D142E1")
("fill-carray" "N-00737951")
("fill-obj" "N-0039A1D1")
@@ -862,10 +862,10 @@
("gequal" "N-00A3E42D")
("get" "N-03D9F55D")
("get-buf-from-stream" "N-02954B48")
- ("get-byte" "D-0064")
- ("get-char" "D-0067")
- ("get-error" "D-0033")
- ("get-error-str" "D-0010")
+ ("get-byte" "D-0067")
+ ("get-char" "D-0064")
+ ("get-error" "D-0032")
+ ("get-error-str" "D-0011")
("get-fd" "N-011D42AB")
("get-frames" "N-010405DA")
("get-hash-userdata" "N-030B41A7")
@@ -934,7 +934,7 @@
("handle*" "N-03F7D8B5")
("handle-frame" "N-0233BAE3")
("handler-bind" "N-00A4ECC9")
- ("hash" "D-0001")
+ ("hash" "D-0003")
("hash-alist" "N-00C9B125")
("hash-begin" "N-0225209D")
("hash-construct" "N-017E6F4C")
@@ -1053,12 +1053,12 @@
("isec" "N-00DFDE76")
("isecp" "N-00DFDE76")
("isig" "N-0072FF5E")
- ("isqrt" "D-0038")
+ ("isqrt" "D-0037")
("istrip" "N-02391683")
- ("iter-begin" "D-002E")
+ ("iter-begin" "D-002D")
("iter-item" "D-0005")
- ("iter-more" "D-003E")
- ("iter-reset" "D-0020")
+ ("iter-more" "D-003D")
+ ("iter-reset" "D-001F")
("iter-step" "D-0072")
("iterable" "N-01156AE3")
("itimer-prof" "N-02B7882A")
@@ -1088,10 +1088,10 @@
("kill" "N-0386CCD5")
("krs" "N-02D33A4D")
("labels" "N-0209307D")
- ("lambda" "D-002D")
+ ("lambda" "D-002F")
("lambda-match" "N-031E43FF")
("lambda-set" "N-02FEBA97")
- ("last" "D-0043")
+ ("last" "D-0044")
("lazy-str" "N-02AFF63D")
("lazy-str-force" "N-03269DEF")
("lazy-str-force-upto" "N-0212FED6")
@@ -1143,7 +1143,7 @@
("load-for" "N-0020A085")
("load-time" "D-0048")
("loff-t" "N-01153D9E")
- ("log" "D-0047")
+ ("log" "D-0046")
("log-alert" "N-035D75EC")
("log-auth" "N-0116F48F")
("log-authpriv" "N-0116F48F")
@@ -1162,15 +1162,15 @@
("log-pid" "N-02371913")
("log-user" "N-0116F48F")
("log-warning" "N-035D75EC")
- ("log10" "D-0052")
+ ("log10" "D-0053")
("log2" "D-0075")
("logand" "D-000E")
("logcount" "D-003B")
("logior" "D-004C")
- ("lognot" "D-0012")
+ ("lognot" "D-0010")
("lognot1" "N-019541E2")
("logtest" "N-00B1548A")
- ("logtrunc" "D-0076")
+ ("logtrunc" "D-0077")
("logxor" "N-02D5AF97")
("long" "N-0235F4E4")
("long-suffix" "N-00A3183A")
@@ -1277,7 +1277,7 @@
("meq" "N-020A0042")
("meql" "N-020A0042")
("mequal" "N-020A0042")
- ("merge" "D-005B")
+ ("merge" "D-005A")
("merge-delete-package" "N-0160EA2C")
("meth" "N-02C216C3")
("method" "N-022200C1")
@@ -1324,7 +1324,7 @@
("new" "N-0230059D")
("new*" "N-021E6FDC")
("nexpand-left" "N-00E168FE")
- ("next" "D-006E")
+ ("next" "D-0070")
("next-file" "N-00839D2F")
("nf" "N-0267AE6D")
("nil" "N-015134D8")
@@ -1335,7 +1335,7 @@
("nldly" "N-03BD477F")
("nlink-t" "N-01153D9E")
("noflsh" "N-0072FF5E")
- ("none" "D-006D")
+ ("none" "D-0071")
("nor" "N-03662D87")
("norf" "N-00C18907")
("not" "D-006B")
@@ -1377,7 +1377,7 @@
("obtain*-block" "N-0102F0EB")
("obtain-block" "N-01C791D0")
("ocrnl" "N-03BD477F")
- ("oddp" "D-0039")
+ ("oddp" "D-003A")
("ofdel" "N-03BD477F")
("off-t" "N-01153D9E")
("offsetof" "N-013D0A5C")
@@ -1474,7 +1474,7 @@
("placelet" "N-0393C970")
("placelet*" "N-0393C970")
("plist-to-alist" "N-006E31B5")
- ("plusp" "D-0069")
+ ("plusp" "D-0068")
("poll" "N-0386D39D")
("poly" "N-026201AD")
("pop" "N-017F39D2")
@@ -1494,7 +1494,7 @@
("pprof" "N-018C92AB")
("pred" "N-038E636C")
("prinl" "N-02FCCE0D")
- ("print" "D-0046")
+ ("print" "D-0047")
("prn" "N-01E7F5F7")
("prod" "N-0163FFE2")
("prof" "N-004C9B10")
@@ -1525,9 +1525,9 @@
("pushhash" "N-022660B2")
("pushnew" "N-02C37AB0")
("put-buf" "D-0081")
- ("put-byte" "D-002F")
+ ("put-byte" "D-002E")
("put-carray" "N-00737951")
- ("put-char" "D-0003")
+ ("put-char" "D-0002")
("put-json" "N-009C27EF")
("put-jsonl" "N-009C27EF")
("put-jsons" "N-0124CAE6")
@@ -1538,7 +1538,7 @@
("put-strings" "N-0367B282")
("pwd" "N-0047F5F6")
("qquote" "N-01665185")
- ("qref" "D-0070")
+ ("qref" "D-006E")
("quantile" "N-0318C018")
("quip" "N-03C6D422")
("quote" "N-0163F998")
@@ -1660,12 +1660,12 @@
("rng-" "N-01A056E4")
("rot" "N-025DB962")
("rotate" "N-0166291D")
- ("round" "D-0002")
+ ("round" "D-0004")
("round-rem" "N-02DE978F")
("round1" "N-03EA1351")
("rperm" "N-0188EBDE")
("rplaca" "D-004E")
- ("rplacd" "D-0009")
+ ("rplacd" "D-000A")
("rpoly" "N-026201AD")
("rpos" "N-01F68300")
("rpos-if" "N-01F68300")
@@ -1712,7 +1712,7 @@
("seq-next" "N-02E3D643")
("seq-reset" "N-01CA6912")
("seqp" "N-03C6CAE0")
- ("set" "D-0015")
+ ("set" "D-0016")
("set-cflags" "N-02061924")
("set-hash-userdata" "N-030B40A7")
("set-iflags" "N-02061924")
@@ -1794,10 +1794,10 @@
("sig-winch" "N-0176430F")
("sig-xcpu" "N-0176430F")
("sig-xfsz" "N-0176430F")
- ("sign-extend" "D-0031")
- ("signum" "D-000F")
+ ("sign-extend" "D-0033")
+ ("signum" "D-0012")
("sin" "D-000B")
- ("sinh" "D-0068")
+ ("sinh" "D-0069")
("sixth" "N-01B0FA33")
("size-t" "N-01B6F219")
("size-vec" "N-01000634")
@@ -1864,8 +1864,8 @@
("split-str" "N-000386B4")
("split-str-set" "N-0296195B")
("spln" "N-026FC0BD")
- ("sqrt" "D-0027")
- ("square" "D-0032")
+ ("sqrt" "D-0025")
+ ("square" "D-0031")
("ssize-t" "N-01153D9E")
("sspl" "N-0296195B")
("sssucc" "N-038E636C")
@@ -1878,7 +1878,7 @@
("static-slot-p" "N-032FD510")
("static-slot-set" "N-0017D1B5")
("stdlib" "N-008E4BC2")
- ("str" "D-005F")
+ ("str" "D-005E")
("str-addr" "N-02E1B78B")
("str-buf" "N-012BF6AD")
("str-d" "N-01736060")
@@ -1967,7 +1967,7 @@
("take-until" "N-01E42C4C")
("take-while" "N-01E42C4C")
("tan" "D-003C")
- ("tanh" "D-0063")
+ ("tanh" "D-0062")
("tb" "N-02AB6E53")
("tc" "N-029B6E53")
("tcdrain" "N-01AC4760")
@@ -2000,7 +2000,7 @@
("test-set-indent-mode" "N-01A1F89C")
("tf" "N-007E0508")
("third" "N-01B0FA33")
- ("throw" "D-0053")
+ ("throw" "D-0054")
("throwf" "N-015466AD")
("time" "D-0034")
("time-fields-local" "N-00789418")
@@ -2124,7 +2124,7 @@
("unless" "N-017EFAB6")
("unquote" "N-036B313D")
("unsetenv" "N-002E0364")
- ("until" "D-0025")
+ ("until" "D-0027")
("until*" "N-01F7BF0B")
("untrace" "N-02833733")
("unuse-package" "N-024BF63F")
@@ -2198,7 +2198,7 @@
("while-match-case" "N-007220BC")
("while-true-match-case" "N-007220BC")
("whilet" "N-0154DC75")
- ("width" "D-0019")
+ ("width" "D-001C")
("width-check" "N-01A9EA49")
("window-map" "N-015AFD48")
("window-mapdo" "N-015AFD48")
@@ -2235,6 +2235,6 @@
("zarray" "N-017039ED")
("zchar" "N-0008D7DC")
("zero-fill" "N-016D3BB5")
- ("zerop" "D-003F")
+ ("zerop" "D-003E")
("zip" "N-03AA85AD")
("znew" "N-00B1FC38"))))
diff --git a/stdlib/optimize.tl b/stdlib/optimize.tl
index 8ab9e7ca..ff256db7 100644
--- a/stdlib/optimize.tl
+++ b/stdlib/optimize.tl
@@ -351,15 +351,20 @@
((equal sub list) list)
(t (set [bb.li-hash sub] li) sub))))
-(defmeth basic-blocks peephole-block (bb bl code)
+(defmeth basic-blocks rename (bb insns dst src)
+ (mapcar (op subst-preserve dst src bb [bb.li-hash @1] @1) insns))
+
+(defmeth basic-blocks peephole-block (bb bl)
+ (let ((code bb.(do-peephole-block bl bl.insns)))
+ (set bl.insns code)))
+
+(defmeth basic-blocks do-peephole-block (bb bl code)
(labels ((dead-treg (insn n)
(let ((li [bb.li-hash insn]))
(and li (not (bit li.used n)))))
(only-locally-used-treg (insn n)
(let ((li [bb.li-hash insn]))
- (and li (bit li.used n) (not (bit bl.live n)))))
- (rename (insns dst src)
- (mapcar (op subst-preserve dst src bb [bb.li-hash @1] @1) insns)))
+ (and li (bit li.used n) (not (bit bl.live n))))))
(rewrite-case insns code
;; dead t-reg
(@(require ((@(or mov getlx getv getf getfb) (t @n) . @nil) . @nil)
@@ -389,7 +394,7 @@
(not (find src rest : [chain bb.li-hash .def])))
(pushnew bl bb.rescan)
(set bb.recalc t)
- (rename rest dst src))
+ bb.(rename rest dst src))
;; wasteful moves
(((mov @reg0 @nil) (mov @reg0 @nil) . @nil)
(cdr insns))
@@ -476,7 +481,7 @@
(defmeth basic-blocks peephole (bb)
(each ((bl bb.list))
- (set bl.insns bb.(peephole-block bl bl.insns)))
+ bb.(peephole-block bl))
(whilet ((rescan (zap bb.rescan)))
(whilet ((bl (pop bb.tryjoin)))
(let ((nxbl bl.next))
@@ -490,7 +495,7 @@
(when (zap bb.recalc)
bb.(calc-liveness rescan))
(each ((bl rescan))
- (set bl.insns bb.(peephole-block bl bl.insns))))
+ bb.(peephole-block bl)))
(when bb.reelim
bb.(elim-dead-code)))