-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Wasm RyuJIT] Add Instruction Encoding for Local Var Declarations and Emit Local Declarations #122425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adamperlin
wants to merge
26
commits into
dotnet:main
Choose a base branch
from
adamperlin:adamperlin/wasm-arg-initialization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+241
−25
Open
[Wasm RyuJIT] Add Instruction Encoding for Local Var Declarations and Emit Local Declarations #122425
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e93e57d
Revert wasm method stub method in crossgen to allow invoking the actu…
adamperlin 4b991da
WIP add args as locals to the beginning of method epilog in Wasm codegen
adamperlin 5933e67
Multiple fixes for emitting local declarations for incoming args
adamperlin 7b8e339
jit-format
adamperlin 78b7c70
Merge branch 'main' of github.com:dotnet/runtime into adamperlin/wasm…
adamperlin 9fbfb86
Generate locals only for non-args
adamperlin 7d12af0
Update src/coreclr/jit/emit.h
adamperlin 4b91b3a
Update src/coreclr/jit/emitfmtswasm.h
adamperlin 183851f
Update src/coreclr/jit/codegencommon.cpp
adamperlin c9d3046
Update src/coreclr/jit/emitwasm.cpp
adamperlin 0482ee3
Remove incorrect noway_asserts
adamperlin dfb0627
Remove empty ifdef block
adamperlin b237c17
Apply some copilot review suggestions
adamperlin 19c9eaf
Address some review feedback
adamperlin 76a15f2
Finish addressing review feedback
adamperlin d32f695
Fix instGen placement
adamperlin f3e2f82
Add block->IsLast() guard for emitting end instruction in Wasm genFnE…
adamperlin 0820a24
Emit correct local count for current state of Wasm codegen
adamperlin 78945a3
Address some more review feedback
adamperlin 9a3c21a
Merge branch 'main' of github.com:dotnet/runtime into wasm-arg-initia…
adamperlin ddb4801
Address additional review feedback
adamperlin 704a4a7
Merge branch 'main' of github.com:dotnet/runtime into wasm-arg-initia…
adamperlin 7bb7cfc
Apply suggestion from @SingleAccretion
adamperlin 06207d5
Address additional review feedback; properly guard access to wasm-spe…
adamperlin c52da98
Address additional review feedback
adamperlin 9373181
Fix condition for `end` generation in src/coreclr/jit/codegenwasm.cpp
adamperlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,44 @@ bool emitter::emitInsIsStore(instruction ins) | |
| return false; | ||
| } | ||
|
|
||
| emitter::instrDesc* emitter::emitNewInstrLclVarDecl(emitAttr attr, cnsval_ssize_t localCount, WasmValueType type) | ||
|
||
| { | ||
| instrDescLclVarDecl* id = static_cast<instrDescLclVarDecl*>(emitAllocAnyInstr(sizeof(instrDescLclVarDecl), attr)); | ||
| id->idLclCnt(localCount); | ||
| id->idLclType(type); | ||
|
|
||
| return id; | ||
| } | ||
|
|
||
| //----------------------------------------------------------------------------------- | ||
| // emitIns_I_Ty: Emit an instruction for a local variable declaration, encoding both | ||
| // a count (immediate) and a value type. This is specifically used for local variable | ||
| // declarations that require both the number of locals and their type to be encoded. | ||
| // | ||
| void emitter::emitIns_I_Ty(instruction ins, cnsval_ssize_t imm, WasmValueType valType) | ||
| { | ||
| instrDesc* id = this->emitNewInstrLclVarDecl(EA_8BYTE, imm, valType); | ||
| insFormat fmt = this->emitInsFormat(ins); | ||
|
|
||
| id->idIns(ins); | ||
| id->idInsFmt(fmt); | ||
|
|
||
| this->dispIns(id); | ||
| this->appendToCurIG(id); | ||
adamperlin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| WasmValueType emitter::emitGetLclVarDeclType(instrDesc* id) | ||
| { | ||
| assert(id->idIsLclVarDecl()); | ||
| return static_cast<instrDescLclVarDecl*>(id)->lclType; | ||
| } | ||
|
|
||
| cnsval_ssize_t emitter::emitGetLclVarDeclCount(instrDesc* id) | ||
| { | ||
| assert(id->idIsLclVarDecl()); | ||
| return static_cast<instrDescLclVarDecl*>(id)->lclCnt; | ||
| } | ||
|
|
||
| emitter::insFormat emitter::emitInsFormat(instruction ins) | ||
| { | ||
| static_assert(IF_COUNT < 255); | ||
|
|
@@ -155,6 +193,11 @@ size_t emitter::emitSizeOfInsDsc(instrDesc* id) const | |
| return sizeof(instrDescCns); | ||
| } | ||
|
|
||
| if (id->idIsLclVarDecl()) | ||
| { | ||
| return sizeof(instrDescLclVarDecl); | ||
| } | ||
|
|
||
| return sizeof(instrDesc); | ||
| } | ||
|
|
||
|
|
@@ -181,6 +224,23 @@ unsigned emitter::SizeOfSLEB128(int64_t value) | |
| return (x * 37) >> 8; | ||
| } | ||
|
|
||
| static uint8_t getWasmValueTypeCode(WasmValueType type) | ||
adamperlin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| // clang-format off | ||
| static const uint8_t typecode_mapping[] = { | ||
| 0x00, // WasmValueType::Invalid = 0, | ||
| 0x7C, // WasmValueType::F64 = 1, | ||
| 0x7D, // WasmValueType::F32 = 2, | ||
| 0x7E, // WasmValueType::I64 = 3, | ||
| 0x7F, // WasmValueType::I32 = 4, | ||
| }; | ||
| static const int WASM_TYP_COUNT = ArrLen(typecode_mapping); | ||
| static_assert(ArrLen(typecode_mapping) == (int)WasmValueType::Count); | ||
| // clang-format on | ||
|
|
||
| return typecode_mapping[static_cast<unsigned>(type)]; | ||
| } | ||
|
|
||
| unsigned emitter::instrDesc::idCodeSize() const | ||
| { | ||
| #ifdef TARGET_WASM32 | ||
|
|
@@ -200,9 +260,18 @@ unsigned emitter::instrDesc::idCodeSize() const | |
| size += 1; | ||
| break; | ||
| case IF_LABEL: | ||
| case IF_LOCAL_CNT: | ||
| assert(!idIsCnsReloc()); | ||
| size = SizeOfULEB128(emitGetInsSC(this)); | ||
| break; | ||
| case IF_LOCAL_DECL: | ||
| { | ||
| assert(idIsLclVarDecl()); | ||
| instrDescLclVarDecl* idl = static_cast<instrDescLclVarDecl*>(const_cast<instrDesc*>(this)); | ||
| uint8_t typeCode = getWasmValueTypeCode(idl->lclType); | ||
| size = SizeOfULEB128(idl->lclCnt) + sizeof(typeCode); | ||
| break; | ||
| } | ||
| case IF_ULEB128: | ||
| size += idIsCnsReloc() ? PADDED_RELOC_SIZE : SizeOfULEB128(emitGetInsSC(this)); | ||
| break; | ||
|
|
@@ -354,6 +423,24 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) | |
| dst += emitOutputULEB128(dst, offset); | ||
| break; | ||
| } | ||
| case IF_LOCAL_CNT: | ||
| { | ||
| cnsval_ssize_t constant = emitGetInsSC(id); | ||
| dst += emitOutputULEB128(dst, (uint64_t)constant); | ||
| break; | ||
| } | ||
| case IF_LOCAL_DECL: | ||
| { | ||
| assert(id->idIsLclVarDecl()); | ||
| cnsval_ssize_t count = emitGetLclVarDeclCount(id); | ||
| uint8_t valType = getWasmValueTypeCode(emitGetLclVarDeclType(id)); | ||
| dst += emitOutputULEB128(dst, (uint64_t)count); | ||
| // TODO-WASM: currently assuming all locals are numtypes which are single byte encoded. | ||
| // vec types are also single byte encoded. If we end up using reftypes, we'll need to handle the more | ||
| // complex encoding. | ||
adamperlin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| dst += emitOutputByte(dst, valType); | ||
| break; | ||
| } | ||
| default: | ||
| NYI_WASM("emitOutputInstr"); | ||
| break; | ||
|
|
@@ -472,13 +559,22 @@ void emitter::emitDispIns( | |
|
|
||
| case IF_LABEL: | ||
| case IF_ULEB128: | ||
| case IF_LOCAL_CNT: | ||
| { | ||
| cnsval_ssize_t imm = emitGetInsSC(id); | ||
| printf(" %llu", (uint64_t)imm); | ||
| dispJumpTargetIfAny(); | ||
| } | ||
| break; | ||
|
|
||
| case IF_LOCAL_DECL: | ||
| { | ||
| cnsval_ssize_t imm = emitGetLclVarDeclCount(id); | ||
| WasmValueType valType = emitGetLclVarDeclType(id); | ||
| printf(" %llu %s", (uint64_t)imm, WasmValueTypeName(valType)); | ||
adamperlin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| break; | ||
|
|
||
| case IF_SLEB128: | ||
| { | ||
| cnsval_ssize_t imm = emitGetInsSC(id); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.