Repository: dotnet/runtime
File: src/coreclr/jit/codegenwasm.cpp (C++)

Code before:
//
// Arguments:
//    node - The emitted node
//
void CodeGen::WasmProduceReg(GenTree* node)
{
    assert(!genIsRegCandidateLocal(node)); // Candidate liveness is handled in "genConsumeReg".
    if (genIsValidReg(node->GetRegNum()))
    {
        GetEmitter()->emitIns_I(INS_local_tee, emitActualTypeSize(node), WasmRegToIndex(node->GetRegNum()));
    }
    genProduceReg(node);
    if (node->IsUnusedValue())
    {
        GetEmitter()->emitIns(INS_drop);
    }
}

//------------------------------------------------------------------------
// GetMultiUseOperandReg: Get the register of a multi-use operand.
//
// If the operand is a candidate, we use that candidate's current register.
// Otherwise it must have been allocated into a temporary register initialized
// in 'WasmProduceReg'. To do this, call treeNode->SetMultiplyUsed() during
// lowering or other pre-regalloc phases, and ensure that regalloc is updated to
// call CollectReferences on the node(s) that need to be used multiple times.
//
// Arguments:
//    operand - The operand node
//
// Return Value:
//    The register to use for 'operand'.
//
regNumber CodeGen::GetMultiUseOperandReg(GenTree* operand)
{
    if (genIsRegCandidateLocal(operand))
    {
        LclVarDsc* varDsc = m_compiler->lvaGetDesc(operand->AsLclVar());
        assert(varDsc->lvIsInReg());
        return varDsc->GetRegNum();
    }

    regNumber reg = operand->GetRegNum();
    assert(genIsValidReg(reg));
    return reg;
}

//------------------------------------------------------------------------
// genCodeForTreeNode: codegen for a particular tree node
//
// Arguments:

Review comment (suggestion):
```suggestion
// in 'WasmProduceReg'. To do this, call treeNode->SetMultiplyUsed() during
// lowering and ensure that regalloc is updated to call 'ConsumeTemporaryRegForOperand'
// on the node(s) that need to be used multiple times.
```

Code after:
//
// Arguments:
//    node - The emitted node
//
void CodeGen::WasmProduceReg(GenTree* node)
{
    assert(!genIsRegCandidateLocal(node)); // Candidate liveness is handled in "genConsumeReg".
    if (genIsValidReg(node->GetRegNum()))
    {
        GetEmitter()->emitIns_I(INS_local_tee, emitActualTypeSize(node), WasmRegToIndex(node->GetRegNum()));
    }
    genProduceReg(node);
    if (node->IsUnusedValue())
    {
        GetEmitter()->emitIns(INS_drop);
    }
}

//------------------------------------------------------------------------
// GetMultiUseOperandReg: Get the register of a multi-use operand.
//
// If the operand is a candidate, we use that candidate's current register.
// Otherwise it must have been allocated into a temporary register initialized
// in 'WasmProduceReg'. To do this, call treeNode->SetMultiplyUsed() during
// lowering and ensure that regalloc is updated to call 'ConsumeTemporaryRegForOperand'
// on the node(s) that need to be used multiple times.
//
// Arguments:
//    operand - The operand node
//
// Return Value:
//    The register to use for 'operand'.
//
regNumber CodeGen::GetMultiUseOperandReg(GenTree* operand)
{
    if (genIsRegCandidateLocal(operand))
    {
        LclVarDsc* varDsc = m_compiler->lvaGetDesc(operand->AsLclVar());
        assert(varDsc->lvIsInReg());
        return varDsc->GetRegNum();
    }

    regNumber reg = operand->GetRegNum();
    assert(genIsValidReg(reg));
    return reg;
}

//------------------------------------------------------------------------
// genCodeForTreeNode: codegen for a particular tree node
//
// Arguments: