Debian Codegraph @

src/how-to-optimize-arg-checks.tex

raw
1
2 Step1: Optimize direct calls:
3
4 Suppose we have a case-lambda as follows
5
6 (case-lambda
7 [<formals_0> <code_0>]
8 [<formals_1> <code_1>]
9 ...
10 [<formals_n> <code_n>])
11
12 First, generate labels for every clause as well as a label for top
13
14 (case-lambda <label>
15 [<formals_0> <label_0> <code0_>]
16 [<formals_1> <label_1> <code1_>]
17 ...
18 [<formals_n> <label_n> <coden_>])
19
20 Now everywhere there is a call to a closure bound variable:
21 (funcall x args ...)
22 We match on the labels of x:
23 * If a matching label is found, we transform the call to
24 (dircall <label_i> x args ...)
25 * If no matching label is found, we transform the call to
26 (dircall <label> x args ...)
27 If we match on a case with ". rest" formals, we emit a call
28 to "list" on the rest arguments because the label will be
29 inside the code (after the rest-args are constructed).
30
31
32 Step2: Eliminate passing arg-counts:
33
34 All direct calls to inner labels do not require passing an argument
35 count since it will not be used by the procedure.
36
37
38
39 Step3: Eliminate useless case-lambda cases. (not important)
40
41 For every label generated, determine whether it is actually used or
42 not.
43
44 We assume the main label unused until we find:
45 * A reference to it in a closure that's not a dircall operator.
46 * A reference to it as the target label to a dircall.
47
48 We assume an inner label unused until we find:
49 * A direct call to it.
50 * The main label used.
51
52 If a case-lambda has unused clauses, they can be eliminated.
53
54 If a case-lambda has an unused main label, the dispatch can be
55 eliminated.
56
57
58