|
18 | 18 | //
|
19 | 19 | // 1. Create the new secondary module.
|
20 | 20 | //
|
21 |
| -// 2. Export globals, tags, tables, and memories from the primary module and |
22 |
| -// import them in the secondary module. |
23 |
| -// |
24 |
| -// 3. Move the deferred functions from the primary to the secondary module. |
| 21 | +// 2. Move the deferred functions from the primary to the secondary module. |
25 | 22 | //
|
26 |
| -// 4. For any secondary function exported from the primary module, export in |
| 23 | +// 3. For any secondary function exported from the primary module, export in |
27 | 24 | // its place a trampoline function that makes an indirect call to its
|
28 | 25 | // placeholder function (and eventually to the original secondary
|
29 | 26 | // function), allocating a new table slot for the placeholder if necessary.
|
30 | 27 | //
|
| 28 | +// 4. Replace all references to secondary functions in the primary module's |
| 29 | +// table segments with references to imported placeholder functions. |
| 30 | +// |
31 | 31 | // 5. Rewrite direct calls from primary functions to secondary functions to be
|
32 | 32 | // indirect calls to their placeholder functions (and eventually to their
|
33 | 33 | // original secondary functions), allocating new table slots for the
|
|
37 | 37 | // export the primary function if it is not already exported and import it
|
38 | 38 | // into the secondary module.
|
39 | 39 | //
|
40 |
| -// 7. Replace all references to secondary functions in the primary module's |
41 |
| -// table segments with references to imported placeholder functions. |
42 |
| -// |
43 |
| -// 8. Create new active table segments in the secondary module that will |
| 40 | +// 7. Create new active table segments in the secondary module that will |
44 | 41 | // replace all the placeholder function references in the table with
|
45 | 42 | // references to their corresponding secondary functions upon
|
46 | 43 | // instantiation.
|
47 | 44 | //
|
| 45 | +// 8. Export globals, tags, tables, and memories from the primary module and |
| 46 | +// import them in the secondary module. |
| 47 | +// |
| 48 | +// 9. Run RemoveUnusedModuleElements pass on the secondary module in order to |
| 49 | +// remove unused imports. |
| 50 | +// |
48 | 51 | // Functions can be used or referenced three ways in a WebAssembly module: they
|
49 |
| -// can be exported, called, or placed in a table. The above procedure introduces |
50 |
| -// a layer of indirection to each of those mechanisms that removes all |
51 |
| -// references to secondary functions from the primary module but restores the |
52 |
| -// original program's semantics once the secondary module is instantiated. As |
53 |
| -// more mechanisms that reference functions are added in the future, such as |
54 |
| -// ref.func instructions, they will have to be modified to use a similar layer |
55 |
| -// of indirection. |
| 52 | +// can be exported, called, or referenced with ref.func. The above procedure |
| 53 | +// introduces a layer of indirection to each of those mechanisms that removes |
| 54 | +// all references to secondary functions from the primary module but restores |
| 55 | +// the original program's semantics once the secondary module is instantiated. |
56 | 56 | //
|
57 | 57 | // The code as currently written makes a couple assumptions about the module
|
58 | 58 | // that is being split:
|
|
64 | 64 | //
|
65 | 65 | // 2. It assumes that either all table segment offsets are constants or there
|
66 | 66 | // is exactly one segment that may have a non-constant offset. It also
|
67 |
| -// assumes that all segments are active segments (although Binaryen does |
68 |
| -// not yet support passive table segments anyway). |
| 67 | +// assumes that all segments are active segments. |
69 | 68 |
|
70 | 69 | #include "ir/module-splitting.h"
|
71 | 70 | #include "asmjs/shared-constants.h"
|
72 | 71 | #include "ir/export-utils.h"
|
73 |
| -#include "ir/manipulation.h" |
74 | 72 | #include "ir/module-utils.h"
|
75 | 73 | #include "ir/names.h"
|
76 | 74 | #include "pass.h"
|
|
0 commit comments