3 ;; Copyright (C) 2009 Free Software Foundation, Inc.
5 ;; This program is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program; see the file COPYING. If not, write to
17 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 ;; Boston, MA 02111-1307, USA.
22 (define-module (language tree-il optimize)
23 #:use-module (system base syntax)
24 #:use-module (language tree-il)
25 #:export (resolve-primitives!))
27 ;; Possible optimizations:
28 ;; * constant folding, propagation
29 ;; * procedure inlining
30 ;; * always when single call site
31 ;; * always for "trivial" procs
32 ;; * otherwise who knows
33 ;; * dead code elimination
34 ;; * degenerate case optimizations
37 (define *interesting-primitive-names*
39 call-with-values @call-with-values
40 call-with-current-continuation @call-with-current-continuation
42 ;; compile-time-environment
45 + * - / 1- 1+ quotient remainder modulo
47 pair? null? list? acons cons cons*
54 caaar caadr cadar caddr cdaar cdadr cddar cdddr
56 caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr
57 cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr))
59 (define *interesting-primitive-vars*
60 (let ((h (make-hash-table)))
62 (hashq-set! h (module-variable the-root-module x) x))
63 *interesting-primitive-names*)
66 (define (resolve-primitives! x mod)
70 ((<toplevel-ref> src name)
71 (and (hashq-ref *interesting-primitive-vars*
72 (module-variable mod name))
73 (make-primitive-ref src name)))
74 ((<module-ref> mod name public?)
75 (let ((m (if public? (resolve-interface mod) (resolve-module mod))))
76 (and m (hashq-ref *interesting-primitive-vars*
77 (module-variable m name))
78 (make-primitive-ref src name))))