Uh oh!
There was an error while loading. Please reload this page.
Move handling of WASM Function section entries to dependency graph - #132543
Move handling of WASM Function section entries to dependency graph#132543jtschuster wants to merge 2 commits into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
71cecf8 to
1142e0cCompare1142e0c to
0d32d2aCompareThere was a problem hiding this comment.
Pull request overview
This PR refactors WebAssembly WebCIL emission so that WASM Function section entries are represented as dependency-graph ObjectNodes, aligning the Function section with the existing object-node model used elsewhere. It also moves the three WebCIL “spec” helper functions into the dependency graph and introduces a new relocation to encode the final emitted function count directly into fillWebcilTable, with accompanying ReadyToRun tests validating section alignment and minimal encodings.
Changes:
- Model WASM Function-section entries as dependency-graph nodes (
WasmFunctionEntryNode) and make allINodeWithTypeSignaturedepend on the corresponding Function-section entry node(s), including funclets. - Move WebCIL default stub methods (
getWebcilSize,fillWebcilTable,getWebcilPayload) into the dependency graph and root them for WASM R2R builds; add aWASM_FUNCTION_COUNT_SLEBreloc forfillWebcilTable. - Update WebCIL relocation resolution to support shrinking/resolving Function-section relocs and add tests that validate Function/Code section consistency and the
fillWebcilTablebody.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/Common/Compiler/ObjectWriter/WebCilObjectWriter.cs | Adds Function-section relocation shrinking/resolution path and new reloc handling for function-count. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs | Stops directly emitting Function-section entries/signature indices; Function section becomes externally counted. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/WasmInstructions.cs | Adds WASM_FUNCTION_COUNT_SLEB relocation support and helper for emitting it. |
| src/coreclr/tools/Common/Compiler/ObjectWriter/Wasm/WasmSection.cs | Removes WasmFunctionSection (Function section now uses externally-counted vector section). |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/WasmFunctionEntryNode.cs | New node type representing a WASM Function-section entry tied to a code node + signature. |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_Wasm/WebcilDefaultMethodNode.cs | Adds dependency-graph nodes for WebCIL spec methods and a symbol node for function-count relocs. |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/SortableDependencyNode.cs | Adds sort order entry for WebCIL default methods to ensure they come first. |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs | Introduces WASM_FUNCTION_COUNT_SLEB and wires it into size/read/write helpers. |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/ObjectNode.cs | Adds automatic WASM Function-section entry dependencies for INodeWithTypeSignature nodes (and funclets). |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/NodeFactory.Wasm.cs | Adds node cache for WasmFunctionEntryNode. |
| src/coreclr/tools/Common/Compiler/DependencyAnalysis/INodeWithTypeSignature.cs | Centralizes signature→WasmFuncType derivation via an extension method. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj | Includes new dependency-analysis source files in the R2R project. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs | Adds WasmFunctionCount symbol and roots WebCIL default method nodes for WASM builds; initializes new caches. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCasesRunner/WasmR2RAssert.cs | Adds assertions verifying Function section matches Code section and fillWebcilTable uses the defined function count. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/Webcil/WasmWebcilModule.cs | Adds a throwing method to exercise EH/funclet-related emission scenarios. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.cs | Hooks new WASM WebCIL structural assertions into the test suite. |
| src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj | Includes WasmFunctionEntryNode.cs in the compiler project. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs | Initializes the new wasm function-entry node cache and adds WasmTypeNode(WasmFuncType) helper. |
| } | ||
| static WasmFunctionBody GetWebcilSize = new WasmFunctionBody( | ||
| new WasmFuncType(new([WasmValueType.I32]), new([])), // (func (destPtr i32) (result)) |
| foreach (SymbolicRelocation reloc in relocs) | ||
| { | ||
| Debug.Assert(sourceStream.Position != reloc.Offset, | ||
| $"Unexpected data in the WASM Function section between offsets {sourceStream.Position} and {reloc.Offset}."); | ||
0d32d2a to
59d5420CompareThere was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 18 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/coreclr/tools/Common/Compiler/ObjectWriter/WebCilObjectWriter.cs:878
- The assertion that validates the Function section contains only relocation placeholders is inverted: it currently asserts
sourceStream.Position != reloc.Offset, which will fail in debug builds when the stream position correctly matches the relocation offset (i.e., when there is no data between relocs).
foreach (SymbolicRelocation reloc in relocs)
{
Debug.Assert(sourceStream.Position != reloc.Offset,
$"Unexpected data in the WASM Function section between offsets {sourceStream.Position} and {reloc.Offset}.");
59d5420 to
988cb84Compare- Create WasmFunctionEntryNode to represent an entry in the Function section. - These emit relocations to the index of the wasm type / signature index for the method. - They use the represented method as the key for sorting to ensure the order of the function section matches the order of the method code nodes in the code section. - These are rooted as dependencies of all ObjectNodes that implement INodeWithTypeSignature. Funclets also get their own and fit into the sorting to ensure they are placed in order. - Create WebcilDefaultMethodNode to represent a webcil spec method that must be exported. - These are implemented as assembly stubs. - They are emitted in the Ordered phase to ensure they are emitted first, and sort properly between themselves. - fillWebcilTable requires a const for the method count of the module, so a new reloc WASM_FUNCTION_COUNT_SLEB is added. - The three methods are rooted in crossgen wasm compilations. - Tests validate that the WASM_FUNCTION_COUNT_SLEB relocation is accurate. - Validated crossgen test modules with wasm-validate. - ILCompiler also has these changes, but full wasm modules are not yet emitted, so this is untested.
- Override equals in NodeCache key to avoid boxing. - Make WasmFunctionEntryNode._methodCodeNode an ObjectNode and avoid emitting when _methodCodeNode is not emitted or is folded. - Shrink Function section relocations and add test validating they are shrunk.
988cb84 to
3823269Compare
This PR adds ObjectNodes representing the entries in the Function section of WASM modules. They are dependencies of all INodeWithTypeSignature, and entries are also created for each function of INodeWithFunclets. The ordering of entries in the Function section kept aligned with the code nodes by sorting the FunctionEntryNodes by their
_methodCodeNode, then by their funclet index. The ObjectData for the nodes is a single reloc to the index of theWasmTypeNode.Since the webcil functions
getWebcilSize,fillWebcilTable, andgetWebcilPayloadare inserted as stubs in the ObjectWriter, they had to be moved to the dependency graph as well. I made them a new subclass ofAssemblyStubNodeand added them as roots when compiling a webcil module. They sort themselves ahead of all other method nodes.fillWebcilTablerequired knowing the size of the table as a constant, so a new reloc type was created,WASM_FUNCTON_COUNT_SLEBthat represents the number of entries in the Code and Function sections of the module, and a new Node was created to be the target of this reloc,WasmFunctionCountNode.The relocs for the section are shrunk thanks to the work done in #132029.
In the end, this makes the Function section fit into the dependency graph ObjectNode model, but likely is less performant. The existing system for emitting the Function section isn't particularly convoluted or confusing, so I'm not sure this is really a net positive, but the work is done, so I thought I'd create the PR for discussion.