multiple value return optimizations

This commit is contained in:
Danny Yoo 2011-09-16 17:04:15 -04:00
parent 0991a0d74b
commit b8cfd43a50
3 changed files with 33 additions and 28 deletions

View File

@ -19,6 +19,7 @@
assemble-prefix-reference
assemble-whole-prefix-reference
assemble-reg
munge-label-name
assemble-label
assemble-listof-assembled-values
assemble-default-continuation-prompt-tag
@ -295,27 +296,26 @@
"M.a"])))
(: munge-label-name (Label -> String))
(define (munge-label-name a-label)
(define chunks
(regexp-split #rx"[^a-zA-Z0-9]+"
(symbol->string (Label-name a-label))))
(cond
[(empty? chunks)
(error "impossible: empty label ~s" a-label)]
[(empty? (rest chunks))
(string-append "_" (first chunks))]
[else
(string-append "_"
(first chunks)
(apply string-append (map string-titlecase (rest chunks))))]))
(: assemble-label (Label Blockht -> String))
(define (assemble-label a-label Blockht)
(define a-block (hash-ref Blockht (Label-name a-label)))
(cond
[(block-looks-like-context-expected-values? a-block)
=> (lambda (expected)
(format "RT.si_context_expected(~a)" expected))]
[else
(define chunks
(regexp-split #rx"[^a-zA-Z0-9]+"
(symbol->string (Label-name a-label))))
(cond
[(empty? chunks)
(error "impossible: empty label ~s" a-label)]
[(empty? (rest chunks))
(string-append "_" (first chunks))]
[else
(string-append "_"
(first chunks)
(apply string-append (map string-titlecase (rest chunks))))])]))
(munge-label-name a-label))
@ -333,7 +333,7 @@
(: assemble-control-stack-label/multiple-value-return (ControlStackLabel/MultipleValueReturn -> String))
(define (assemble-control-stack-label/multiple-value-return a-csl)
"M.c[M.c.length-1].label.mvr")
"(M.c[M.c.length-1].label.mvr||RT.si_context_expected_1)")

View File

@ -151,10 +151,12 @@ EOF
[(= expected 1)
(void)]
[else
(fprintf op "~a.mvr=RT.si_context_expected(~a);\n" expected)]))]
(fprintf op "~a.mvr=RT.si_context_expected(~a);\n"
(munge-label-name (make-Label (LinkedLabel-label stmt)))
expected)]))]
[else
(fprintf op "~a.mvr=~a;\n"
(assemble-label (make-Label (LinkedLabel-label stmt)) blockht)
(munge-label-name (make-Label (LinkedLabel-label stmt)))
(assemble-label (make-Label (LinkedLabel-linked-to stmt)) blockht))])
(next)]
[(DebugPrint? stmt)
@ -197,11 +199,14 @@ EOF
[(block-looks-like-context-expected-values? a-basic-block)
=>
(lambda (expected)
(fprintf op "~a=RT.si_context_expected(~a);\n"
(assemble-label (make-Label (BasicBlock-name a-basic-block))
blockht)
expected)
'ok)]
(cond
[(= expected 1)
'ok]
[else
(fprintf op "~a=RT.si_context_expected(~a);\n"
(munge-label-name (make-Label (BasicBlock-name a-basic-block)))
expected)
'ok]))]
[else
(default-assemble-basic-block a-basic-block blockht entry-points function-entry-and-exit-names op)]))

View File

@ -675,7 +675,8 @@
// Superinstructions to try to reduce code size.
var si_context_expected = function(n) {
if (n === 1) { return si_context_expected_1; }
return function(M) { raiseContextExpectedValuesError(M, n); }
var f = function(M) { raiseContextExpectedValuesError(M, n); };
return f;
};
var si_context_expected_1 = function(M) { raiseContextExpectedValuesError(M, 1); }
@ -686,7 +687,6 @@
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////