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

Code before:
    regNumber reg = AllocateTemporaryRegister(genActualType(type));
    m_codeGen->internalRegisters.Add(node, reg);
    return reg;
}

//------------------------------------------------------------------------
// ResolveReferences: Translate virtual registers to physical ones (WASM locals).
//
// And fill-in the references collected earlier.
//
void WasmRegAlloc::ResolveReferences()
{
    // Finish the allocation by allocating temporary registers to virtual registers.
    struct TemporaryRegBank
    {
        regNumber* Regs;
        unsigned   Count;
    };
    TemporaryRegBank temporaryRegMap[static_cast<unsigned>(WasmValueType::Count)];
    for (WasmValueType type = WasmValueType::First; type < WasmValueType::Count; ++type)
    {
        TemporaryRegStack& temporaryRegs          = m_temporaryRegs[static_cast<unsigned>(type)];
        TemporaryRegBank&  allocatedTemporaryRegs = temporaryRegMap[static_cast<unsigned>(type)];
        // If temporaryRegs.Count != 0 that means CollectReferences failed to CollectReference one or more multiply-used
        // nodes.
        assert(temporaryRegs.Count == 0);

        allocatedTemporaryRegs.Count = temporaryRegs.MaxCount;
        if (allocatedTemporaryRegs.Count == 0)
        {
            continue;
        }

        allocatedTemporaryRegs.Regs = new (m_compiler->getAllocator(CMK_LSRA)) regNumber[allocatedTemporaryRegs.Count];
        for (unsigned i = 0; i < allocatedTemporaryRegs.Count; i++)
        {
            allocatedTemporaryRegs.Regs[i] = AllocateVirtualRegister(type);
        }
    }

    struct PhysicalRegBank
    {
        unsigned DeclaredCount;
        unsigned IndexBase;
        unsigned Index;
    };

    PhysicalRegBank virtToPhysRegMap[static_cast<unsigned>(WasmValueType::Count)];
    for (WasmValueType type = WasmValueType::First; type < WasmValueType::Count; ++type)
    {
        VirtualRegStack& virtRegs = m_virtualRegs[static_cast<unsigned>(type)];

Review comment (suggestion):
```suggestion
assert((temporaryRegs.Count == 0) && "Some temporary regs were not consumed/released");
```

Code after:
    return reg;
}

//------------------------------------------------------------------------
// ResolveReferences: Translate virtual registers to physical ones (WASM locals).
//
// And fill-in the references collected earlier.
//
void WasmRegAlloc::ResolveReferences()
{
    // Finish the allocation by allocating temporary registers to virtual registers.
    struct TemporaryRegBank
    {
        regNumber* Regs;
        unsigned   Count;
    };
    TemporaryRegBank temporaryRegMap[static_cast<unsigned>(WasmValueType::Count)];
    for (WasmValueType type = WasmValueType::First; type < WasmValueType::Count; ++type)
    {
        TemporaryRegStack& temporaryRegs          = m_temporaryRegs[static_cast<unsigned>(type)];
        TemporaryRegBank&  allocatedTemporaryRegs = temporaryRegMap[static_cast<unsigned>(type)];
        assert((temporaryRegs.Count == 0) && "Some temporary regs were not consumed/released");

        allocatedTemporaryRegs.Count = temporaryRegs.MaxCount;
        if (allocatedTemporaryRegs.Count == 0)
        {
            continue;
        }

        allocatedTemporaryRegs.Regs = new (m_compiler->getAllocator(CMK_LSRA)) regNumber[allocatedTemporaryRegs.Count];
        for (unsigned i = 0; i < allocatedTemporaryRegs.Count; i++)
        {
            allocatedTemporaryRegs.Regs[i] = AllocateVirtualRegister(type);
        }
    }

    struct PhysicalRegBank
    {
        unsigned DeclaredCount;
        unsigned IndexBase;
        unsigned Index;
    };

    PhysicalRegBank virtToPhysRegMap[static_cast<unsigned>(WasmValueType::Count)];
    for (WasmValueType type = WasmValueType::First; type < WasmValueType::Count; ++type)
    {
        VirtualRegStack& virtRegs = m_virtualRegs[static_cast<unsigned>(type)];
        PhysicalRegBank& physRegs = virtToPhysRegMap[static_cast<unsigned>(type)];
        physRegs.DeclaredCount    = virtRegs.Count();
    }