[wasm-split] Do not split out the start function#8711
Conversation
aheejin
left a comment
There was a problem hiding this comment.
Thanks! Can you handle it in multiSplitModule too?
|
Ok, I think I managed to do that. The first commit runs into a crash where the table is not present yet. I fixed that in the last commit by reordering operations: shareImportableItems needs the other code to run first so it can see which tables etc. need to be used. The change to the existing test seems valid to me - now it is using the more accurate table definition from the primary module (which is larger). However, I'm not very familiar with this code, so PTAL carefully! |
| indirectReferencesToSecondaryFunctions(); | ||
| indirectCallsToSecondaryFunctions(); | ||
| exportImportCalledPrimaryFunctions(); | ||
| shareImportableItems(); |
There was a problem hiding this comment.
This is what I meant by this:
The first commit runs into a crash where the table is not present yet. I fixed that in the last commit by reordering operations: shareImportableItems needs the other code to run first so it can see which tables etc. need to be used.
That is the table needs to be created at the right time. I think...
There was a problem hiding this comment.
I don't see why that would be related to this change 🤔
There was a problem hiding this comment.
I don't either... Can you give an example?
That order change was the gist of #8688, so without breaking a lot of new assumptions, it is not easy to flip...
There was a problem hiding this comment.
For an example, run the multi-split test in this PR. (That is, take all of this PR but the part in question. The test crashes because it doesn't find the table. Reordering makes the table exist - but I have no high-level understanding of the flow here 😄 so maybe it is the wrong fix)
| // The start function must always be kept in the primary module. | ||
| if (func->imported() || !configSecondaryFuncs.contains(func->name) || | ||
| segmentReferrers.contains(func->name)) { | ||
| segmentReferrers.contains(func->name) || func->name == primary.start) { |
There was a problem hiding this comment.
Can we just do something like
if (primary.start)
primaryFuncs.insert(primary.start)at the start of the function, rather than in this loop?
There was a problem hiding this comment.
We also need the if's else not to happen, though. That is, we need to add it in the primary and not in the secondary. If the loop body is not modified, it will add it to the second.
|
Looks like there are a bunch of tests that do not use the auto-updater, so I will need to update them manually. I did one in the last commit. I'll wait on the others to see if this fix is even the right one. |
|
The fix looks right to me, but changing the order of splitting steps shouldn't be necessary. |
I didn't use And AI is fairly good at updating those expectations 😀 I often give prompts like "Don't change whether each test uses update_lit_checks.py or not, and update expectations for tests in test/lit/wasm-split" But I also don't see why this PR should change existing tests' expectations, who don't have |
| if (function->name == wasm.start) { | ||
| if (!options.quiet) { | ||
| std::cerr << "warning: cannot split out start function " << func | ||
| << "\n"; | ||
| } | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Can't you do the same thing in multiSplitModule after this line?
binaryen/src/tools/wasm-split/wasm-split.cpp
Line 437 in b5b9ebd
Then we don't need to do anything in module-splitting.cpp.
Also while you're at it you can add this there too, to be consistent with splitModule:
binaryen/src/tools/wasm-split/wasm-split.cpp
Lines 286 to 298 in b5b9ebd
Like imports, automatically keep it in the primary module.