Skip to content

[Wasm RyuJit] Add partial constant emitting support to codegenwasm.cpp #122161

@kg

Description

@kg

The WebAssembly RyuJIT backend in codegenwasm.cpp and emitwasm.cpp needs to be updated as follows:

  1. Add a definition for CodeGen::genSetRegToConst which switches on tree->gtOper() and has cases for GT_CNS_INT and GT_CNS_DBL. The case for GT_CNS_INT should use AsIntCon()->IconValue() to store the integer constant into a ssize_t constant. The case for GT_CNS_DBL should use AsDblCon()->DconValue() to store the double constant into a double constant.
  2. Declare a new member function in emitwasm.h called emitEncodeLEB64 with the signature size_t emitter:emitEncodeLEB64(uint8_t *destination, const void *source, bool valueIsSigned).
  3. Define emitEncodeLeb64 in emitwasm.cpp and make its body a NYI_WASM.
  4. Declare a new member function in emitwasm.h called emitIns_R_F with the signature void emitter::emitIns_R_F(instruction ins, emitAttr attr, regNumber reg, double immDbl).
  5. Define emitIns_R_F in emitwasm.cpp and make its body a NYI_WASM.
  6. Update genSetRegToConst's GT_CNS_INT case to use emitEncodeLEB64 to measure the size of the integer constant like so: emitAttr encodedSize = (emitAttr)GetEmitter()->emitEncodeLEB64(nullptr, &constant, true);
  7. Update genSetRegToConst's GT_CNS_DBL case to determine the size of the floating-point constant based on targetType, like so: emitAttr encodedSize = (targetType == TYP_FLOAT) ? EA_4BYTE : EA_8BYTE;
  8. Update genSetRegToConst's GT_CNS_INT case to call emitIns_R_I with appropriate arguments, like so: GetEmitter()->emitIns_R_I((targetType == TYP_INT) ? INS_i32_const : INS_i64_const, encodedSize, targetReg, constant);.
  9. Update genSetRegToConst's GT_CNS_DBL case to call emitIns_R_F with appropriate arguments, like so: GetEmitter()->emitIns_R_F((targetType == TYP_FLOAT) ? INS_f32_const : INS_f64_const, encodedSize, targetReg, constant);.
  10. Update CodeGen::genCodeForTreeNode to add cases for GT_CNS_INT and GT_CNS_DBL that call the new genSetRegToConst member function. The targetReg is treeNode->GetRegNum() and the targetType is treeNode->TypeGet(). After calling genSetRegToConst, call genProduceReg(treeNode).

Metadata

Metadata

Assignees

Labels

arch-wasmWebAssembly architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions