Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 Dec 9, 2025
4b991da
WIP add args as locals to the beginning of method epilog in Wasm codegen
adamperlin Dec 10, 2025
5933e67
Multiple fixes for emitting local declarations for incoming args
adamperlin Dec 11, 2025
7b8e339
jit-format
adamperlin Dec 11, 2025
78b7c70
Merge branch 'main' of github.com:dotnet/runtime into adamperlin/wasm…
adamperlin Dec 11, 2025
9fbfb86
Generate locals only for non-args
adamperlin Dec 11, 2025
7d12af0
Update src/coreclr/jit/emit.h
adamperlin Dec 11, 2025
4b91b3a
Update src/coreclr/jit/emitfmtswasm.h
adamperlin Dec 11, 2025
183851f
Update src/coreclr/jit/codegencommon.cpp
adamperlin Dec 11, 2025
c9d3046
Update src/coreclr/jit/emitwasm.cpp
adamperlin Dec 11, 2025
0482ee3
Remove incorrect noway_asserts
adamperlin Dec 11, 2025
dfb0627
Remove empty ifdef block
adamperlin Dec 11, 2025
b237c17
Apply some copilot review suggestions
adamperlin Dec 11, 2025
19c9eaf
Address some review feedback
adamperlin Dec 12, 2025
76a15f2
Finish addressing review feedback
adamperlin Dec 12, 2025
d32f695
Fix instGen placement
adamperlin Dec 12, 2025
f3e2f82
Add block->IsLast() guard for emitting end instruction in Wasm genFnE…
adamperlin Dec 13, 2025
0820a24
Emit correct local count for current state of Wasm codegen
adamperlin Dec 13, 2025
78945a3
Address some more review feedback
adamperlin Dec 16, 2025
9a3c21a
Merge branch 'main' of github.com:dotnet/runtime into wasm-arg-initia…
adamperlin Dec 16, 2025
ddb4801
Address additional review feedback
adamperlin Dec 17, 2025
704a4a7
Merge branch 'main' of github.com:dotnet/runtime into wasm-arg-initia…
adamperlin Dec 17, 2025
7bb7cfc
Apply suggestion from @SingleAccretion
adamperlin Dec 17, 2025
06207d5
Address additional review feedback; properly guard access to wasm-spe…
adamperlin Dec 17, 2025
c52da98
Address additional review feedback
adamperlin Dec 17, 2025
9373181
Fix condition for `end` generation in src/coreclr/jit/codegenwasm.cpp
adamperlin Dec 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address some review feedback
  • Loading branch information
adamperlin committed Dec 12, 2025
commit 19c9eaf65fd2f8e2460ca72ebe47ffb4bd4bc4c7
20 changes: 4 additions & 16 deletions src/coreclr/jit/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,6 @@ class emitter
BasicBlock* idTargetBlock; // Target block for branches
};

#if defined(TARGET_WASM)
#include "wasmtypesdef.h"
#endif

#ifdef TARGET_ARM
unsigned insEncodeSetFlags(insFlags sf);

Expand Down Expand Up @@ -896,9 +892,6 @@ class emitter
unsigned _idLclFPBase : 1; // access a local on stack - SP based offset
insOpts _idInsOpt : 3; // options for Load/Store instructions
#endif
#ifdef TARGET_WASM
unsigned _idLclDecl : 1; // is this a local declaration?
#endif

////////////////////////////////////////////////////////////////////////
// Space taken up to here:
Expand Down Expand Up @@ -926,7 +919,7 @@ class emitter
#elif defined(TARGET_AMD64)
#define ID_EXTRA_BITFIELD_BITS (20)
#elif defined(TARGET_WASM)
#define ID_EXTRA_BITFIELD_BITS (-3)
#define ID_EXTRA_BITFIELD_BITS (-4)
#else
#error Unsupported or unset target architecture
#endif
Expand Down Expand Up @@ -1306,12 +1299,7 @@ class emitter
#ifdef TARGET_WASM
bool idIsLclVarDecl() const
{
return (_idLclDecl != 0);
}

void idSetIsLclVarDecl(bool isDecl)
{
_idLclDecl = isDecl ? 1 : 0;
return _idInsFmt == IF_LOCAL_DECL
}
#endif

Expand Down Expand Up @@ -2359,9 +2347,9 @@ class emitter
{
instrDescLclVarDecl() = delete;
cnsval_ssize_t lclCnt;
instWasmValueType lclType;
WasmValueType lclType;

void idLclType(instWasmValueType type)
void idLclType(WasmValueType type)
{
lclType = type;
}
Expand Down
25 changes: 22 additions & 3 deletions src/coreclr/jit/emitwasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool emitter::emitInsIsStore(instruction ins)
return false;
}

emitter::instrDesc* emitter::emitNewInstrLclVarDecl(emitAttr attr, cnsval_ssize_t localCount, instWasmValueType type)
emitter::instrDesc* emitter::emitNewInstrLclVarDecl(emitAttr attr, cnsval_ssize_t localCount, WasmValueType type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These new functions are missing function headers (C&P template in `conventions.txt).

{
instrDescLclVarDecl* id = static_cast<instrDescLclVarDecl*>(emitAllocAnyInstr(sizeof(instrDescLclVarDecl), attr));
id->idSetIsLclVarDecl(true);
Expand All @@ -131,7 +131,7 @@ emitter::instrDesc* emitter::emitNewInstrLclVarDecl(emitAttr attr, cnsval_ssize_
// 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, emitter::instWasmValueType valType)
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);
Expand Down Expand Up @@ -225,6 +225,24 @@ unsigned emitter::SizeOfSLEB128(int64_t value)
return (x * 37) >> 8;
}

uint8_t getWasmValueTypeCode(WasmValueType type)
{
// clang-format off
static const WasmValueType typecode_mapping[] = {
0x00, // WasmValueType::Invalid = 0,
0x7C, // WasmValueType::F64 = 1,
0x7D, // WasmValueType::F32 = 2,
0x7E, // WasmValueType::I64 = 3,
0x7F, // WasmValueType::I32 = 4,
};

static_assert(ArrLen(mapping) == TYP_COUNT);
// clang-format on

assert(0 <= type && type < WasmValueType::Count);
return typecode_mapping[static_cast<unsigned>(type)];
}

unsigned emitter::instrDesc::idCodeSize() const
{
#ifdef TARGET_WASM32
Expand Down Expand Up @@ -252,7 +270,8 @@ unsigned emitter::instrDesc::idCodeSize() const
{
assert(idIsLclVarDecl());
instrDescLclVarDecl* idl = static_cast<instrDescLclVarDecl*>(const_cast<instrDesc*>(this));
size = SizeOfULEB128(idl->lclCnt) + sizeof(emitter::instWasmValueType);
uint8_t typeCode = getWasmValueTypeCode(idl->lclType);
size = SizeOfULEB128(idl->lclCnt) + sizeof(typeCode);
break;
}
case IF_ULEB128:
Expand Down
4 changes: 1 addition & 3 deletions src/coreclr/jit/emitwasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
/* Debug-only routines to display instructions */
/************************************************************************/

#include "wasmtypesdef.h"

#if defined(DEBUG) || defined(LATE_DISASM)
void getInsSveExecutionCharacteristics(instrDesc* id, insExecutionCharacteristics& result);
#endif // defined(DEBUG) || defined(LATE_DISASM)
Expand All @@ -20,7 +18,7 @@ void emitDispInst(instruction ins);
public:
void emitIns(instruction ins);
void emitIns_I(instruction ins, emitAttr attr, cnsval_ssize_t imm);
void emitIns_I_Ty(instruction ins, cnsval_ssize_t imm, instWasmValueType valType);
void emitIns_I_Ty(instruction ins, cnsval_ssize_t imm, WasmValueType valType);
void emitIns_J(instruction ins, emitAttr attr, cnsval_ssize_t imm, BasicBlock* tgtBlock);
void emitIns_S(instruction ins, emitAttr attr, int varx, int offs);
void emitIns_R(instruction ins, emitAttr attr, regNumber reg);
Expand Down