add a brain-dead inliner
authorAndy Wingo <wingo@pobox.com>
Wed, 5 Aug 2009 14:17:20 +0000 (16:17 +0200)
committerAndy Wingo <wingo@pobox.com>
Wed, 5 Aug 2009 14:17:20 +0000 (16:17 +0200)
* module/Makefile.am (TREE_IL_LANG_SOURCES):
* module/language/tree-il/inline.scm: Add a brain-dead inliner, to
  inline ((lambda () x)) => x.

* module/language/tree-il/optimize.scm (optimize!): Invoke the inliner.

module/Makefile.am
module/language/tree-il/inline.scm [new file with mode: 0644]
module/language/tree-il/optimize.scm

index 2971fc6..b6bd341 100644 (file)
@@ -77,6 +77,7 @@ SCHEME_LANG_SOURCES =                                         \
 TREE_IL_LANG_SOURCES =                                         \
   language/tree-il/primitives.scm                              \
   language/tree-il/optimize.scm                                 \
+  language/tree-il/inline.scm                                   \
   language/tree-il/analyze.scm                                 \
   language/tree-il/compile-glil.scm                            \
   language/tree-il/spec.scm
diff --git a/module/language/tree-il/inline.scm b/module/language/tree-il/inline.scm
new file mode 100644 (file)
index 0000000..10ec51c
--- /dev/null
@@ -0,0 +1,44 @@
+;;; a simple inliner
+
+;; Copyright (C) 2009 Free Software Foundation, Inc.
+
+;; This library is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU Lesser General Public
+;; License as published by the Free Software Foundation; either
+;; version 2.1 of the License, or (at your option) any later version.
+;; 
+;; This library is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; Lesser General Public License for more details.
+;; 
+;; You should have received a copy of the GNU Lesser General Public
+;; License along with this library; if not, write to the Free Software
+;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+(define-module (language tree-il inline)
+  #:use-module (system base syntax)
+  #:use-module (language tree-il)
+  #:export (inline!))
+
+;; Possible optimizations:
+;; * constant folding, propagation
+;; * procedure inlining
+;;   * always when single call site
+;;   * always for "trivial" procs
+;;   * otherwise who knows
+;; * dead code elimination
+;; * degenerate case optimizations
+;; * "fixing letrec"
+
+;; This is a completely brain-dead optimization pass whose sole claim to
+;; fame is ((lambda () x)) => x.
+(define (inline! x)
+  (post-order!
+   (lambda (x)
+     (record-case x
+       ((<application> proc args)
+        (and (lambda? proc) (null? args)
+             (lambda-body proc)))
+       (else #f)))
+   x))
index ac16a9e..9820f94 100644 (file)
 (define-module (language tree-il optimize)
   #:use-module (language tree-il)
   #:use-module (language tree-il primitives)
+  #:use-module (language tree-il inline)
   #:export (optimize!))
 
 (define (env-module e)
   (if e (car e) (current-module)))
 
 (define (optimize! x env opts)
-  (expand-primitives! (resolve-primitives! x (env-module env))))
-
-;; Possible optimizations:
-;; * constant folding, propagation
-;; * procedure inlining
-;;   * always when single call site
-;;   * always for "trivial" procs
-;;   * otherwise who knows
-;; * dead code elimination
-;; * degenerate case optimizations
-;; * "fixing letrec"
+  (inline!
+   (expand-primitives! 
+    (resolve-primitives! x (env-module env)))))