Merge commit '58147d67806e1f54c447d7eabac35b1a5086c3a6'
[bpt/guile.git] / module / language / tree-il / optimize.scm
CommitLineData
9efc833d
AW
1;;; Tree-il optimizer
2
403d78f9 3;; Copyright (C) 2009, 2011, 2012, 2013 Free Software Foundation, Inc.
9efc833d 4
53befeb7
NJ
5;;;; This library is free software; you can redistribute it and/or
6;;;; modify it under the terms of the GNU Lesser General Public
7;;;; License as published by the Free Software Foundation; either
8;;;; version 3 of the License, or (at your option) any later version.
9;;;;
10;;;; This library 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 GNU
13;;;; Lesser General Public License for more details.
14;;;;
15;;;; You should have received a copy of the GNU Lesser General Public
16;;;; License along with this library; if not, write to the Free Software
17;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
9efc833d
AW
18
19;;; Code:
20
21(define-module (language tree-il optimize)
9efc833d 22 #:use-module (language tree-il)
55ae815b 23 #:use-module (language tree-il primitives)
b275fb26 24 #:use-module (language tree-il peval)
9068f4f5 25 #:use-module (language tree-il cse)
c21c89b1 26 #:use-module (language tree-il fix-letrec)
012492a7 27 #:use-module (language tree-il debug)
11671bba 28 #:use-module (ice-9 match)
25450a0d 29 #:export (optimize))
073bb617 30
25450a0d 31(define (optimize x env opts)
11671bba
LC
32 (let ((peval (match (memq #:partial-eval? opts)
33 ((#:partial-eval? #f _ ...)
34 ;; Disable partial evaluation.
3f2d6efc 35 (lambda (x e) x))
9068f4f5
AW
36 (_ peval)))
37 (cse (match (memq #:cse? opts)
38 ((#:cse? #f _ ...)
39 ;; Disable CSE.
40 (lambda (x) x))
41 (_ cse))))
403d78f9 42 (fix-letrec
012492a7 43 (verify-tree-il
9068f4f5
AW
44 (cse
45 (verify-tree-il
25450a0d 46 (peval (expand-primitives (resolve-primitives x env))
9068f4f5 47 env)))))))