mvr initialization should now optimize away the common case

This commit is contained in:
Danny Yoo 2011-09-16 16:22:26 -04:00
parent f2c3dc3fe1
commit 0991a0d74b
4 changed files with 37 additions and 17 deletions

View File

@ -298,18 +298,24 @@
(: assemble-label (Label Blockht -> String))
(define (assemble-label a-label Blockht)
(let ([chunks
(regexp-split #rx"[^a-zA-Z0-9]+"
(symbol->string (Label-name a-label)))])
(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))))])))
[(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))))])]))

View File

@ -139,10 +139,23 @@ EOF
[(symbol? stmt)
(next)]
[(LinkedLabel? stmt)
;; Setting up multiple-value-return
(fprintf op "~a.mvr=~a;\n"
(assemble-label (make-Label (LinkedLabel-label stmt)) blockht)
(assemble-label (make-Label (LinkedLabel-linked-to stmt)) blockht))
;; Setting up multiple-value-return.
;; Optimization: in the most common case (expecting only one), we optimize away
;; the assignment, because there's a distinguished instruction, and it's implied
;; that if .mvr is missing, that the block only expects one.
(define linked-to-block (hash-ref blockht (LinkedLabel-linked-to stmt)))
(cond
[(block-looks-like-context-expected-values? linked-to-block)
=> (lambda (expected)
(cond
[(= expected 1)
(void)]
[else
(fprintf op "~a.mvr=RT.si_context_expected(~a);\n" expected)]))]
[else
(fprintf op "~a.mvr=~a;\n"
(assemble-label (make-Label (LinkedLabel-label stmt)) blockht)
(assemble-label (make-Label (LinkedLabel-linked-to stmt)) blockht))])
(next)]
[(DebugPrint? stmt)
(next)]

View File

@ -72,12 +72,12 @@
return MACHINE.c.pop().label(MACHINE);
} else if (returnArgs.length === 0) {
MACHINE.a = 0;
return MACHINE.c.pop().label.mvr(MACHINE);
return (MACHINE.c.pop().label.mvr || plt.runtime.si_context_expected_1)(MACHINE);
} else {
MACHINE.a = returnArgs.length;
MACHINE.v = returnArgs.shift();
MACHINE.e.push.apply(MACHINE.e, returnArgs.reverse());
return MACHINE.c.pop().label.mvr(MACHINE);
return (MACHINE.c.pop().label.mvr || plt.runtime.si_context_expected_1)(MACHINE);
}
};

View File

@ -817,6 +817,7 @@
exports['getTracedCalleeKey'] = getTracedCalleeKey;
exports['si_context_expected'] = si_context_expected;
exports['si_context_expected_1'] = si_context_expected_1;
exports['checkClosureAndArity'] = checkClosureAndArity;