first cut at cross-module function inlining

Inline only trivial functions, such as `(empty? x)' -> `(null? x)',
to avoid generating too much code.

Bytecode includes a new `inline-variant' form, which records a
version of a function that is suitable for cross-module inlining.
Mostly, the variant let the run-time system to retain a copy
of the bytecode while JITting (and dropping the bytecode of)
the main variant, but it may be different from the main variant
in other ways that make it better for inlining (such a less loop
unrolling).

original commit: 779b419c03
This commit is contained in:
Matthew Flatt 2011-11-29 20:20:05 -07:00
parent 9d2461bca5
commit 52fa72bd6b
4 changed files with 23 additions and 10 deletions

View File

@ -193,7 +193,12 @@
[(struct toplevel (depth pos const? set-const?))
(list-ref/protect (glob-desc-vars globs) pos 'def-vals)]))
ids)
,(decompile-expr rhs globs stack closed))]
,(if (inline-variant? rhs)
`(begin
,(list 'quote '%%inline-variant%%)
,(decompile-expr (inline-variant-inline rhs) globs stack closed)
,(decompile-expr (inline-variant-direct rhs) globs stack closed))
(decompile-expr rhs globs stack closed)))]
[(struct def-syntaxes (ids rhs prefix max-let-depth dummy))
`(define-syntaxes ,ids
,(let-values ([(globs defns) (decompile-prefix prefix stx-ht)])

View File

@ -168,10 +168,10 @@
(define apply-values-type-num 24)
(define case-lambda-sequence-type-num 25)
(define module-type-num 26)
(define variable-type-num 34)
(define top-type-num 99)
(define prefix-type-num 112)
(define free-id-info-type-num 161)
(define inline-variants-type-num 27)
(define variable-type-num 35)
(define prefix-type-num 113)
(define free-id-info-type-num 162)
(define-syntax define-enum
(syntax-rules ()

View File

@ -329,6 +329,9 @@
(define (read-module-wrap v)
v)
(define (read-inline-variant v)
(make-inline-variant (car v) (cdr v)))
;; ----------------------------------------
;; Unmarshal dispatch for various types
@ -355,10 +358,11 @@
[(24) 'apply-values-type]
[(25) 'case-lambda-sequence-type]
[(26) 'module-type]
[(34) 'variable-type]
[(35) 'module-variable-type]
[(112) 'resolve-prefix-type]
[(161) 'free-id-info-type]
[(27) 'inline-variant-type]
[(35) 'variable-type]
[(36) 'module-variable-type]
[(113) 'resolve-prefix-type]
[(162) 'free-id-info-type]
[else (error 'int->type "unknown type: ~e" i)]))
(define type-readers
@ -378,6 +382,7 @@
(cons 'case-lambda-sequence-type read-case-lambda)
(cons 'begin0-sequence-type read-begin0)
(cons 'module-type read-module)
(cons 'inline-variant-type read-inline-variant)
(cons 'resolve-prefix-type read-resolve-prefix)
(cons 'free-id-info-type read-free-id-info)
(cons 'define-values-type read-define-values)

View File

@ -94,9 +94,12 @@
[max-let-depth exact-nonnegative-integer?]
[dummy (or/c toplevel? #f)]))
(define-form-struct (inline-variant form) ([direct expr?]
[inline expr?]))
;; Definitions (top level or within module):
(define-form-struct (def-values form) ([ids (listof (or/c toplevel? symbol?))]
[rhs (or/c expr? seq? any/c)]))
[rhs (or/c expr? seq? inline-variant? any/c)]))
(define-form-struct (def-syntaxes form) ([ids (listof (or/c toplevel? symbol?))]
[rhs (or/c expr? seq? any/c)]
[prefix prefix?]