Skip to content

[RyuJit/WASW] Insert temporaries when needed in the stackifier#125146

Open
SingleAccretion wants to merge 1 commit intodotnet:mainfrom
SingleAccretion:WasmJit-StkTmp
Open

[RyuJit/WASW] Insert temporaries when needed in the stackifier#125146
SingleAccretion wants to merge 1 commit intodotnet:mainfrom
SingleAccretion:WasmJit-StkTmp

Conversation

@SingleAccretion
Copy link
Contributor

@SingleAccretion SingleAccretion commented Mar 3, 2026

To do this we need to maintain some more state, so convert the stackifier into a full walk over all blocks so that we can encapsulate this state better.

Depends on #125073.

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 3, 2026
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 3, 2026
@SingleAccretion SingleAccretion force-pushed the WasmJit-StkTmp branch 3 times, most recently from 8488681 to d962722 Compare March 3, 2026 20:34
@am11 am11 added the arch-wasm WebAssembly architecture label Mar 3, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

To do this we need to maintain some more state, so convert the
stackifier into a full walk over all blocks so that we can
encapsulate this state better.
@SingleAccretion
Copy link
Contributor Author

@dotnet/jit-contrib

@kg
Copy link
Member

kg commented Mar 4, 2026

LGTM, thanks! Will defer the green check to Andy.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

Looks good overall; just left some questions on implementation details.

lclNum = m_compiler->lvaGrabTemp(true DEBUGARG("Stackifier temporary"));
LclVarDsc* varDsc = m_compiler->lvaGetDesc(lclNum);
varDsc->lvType = genActualType(type);
assert(lclNum >= m_minimumTempLclNum);
Copy link
Member

Choose a reason for hiding this comment

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

Seems a bit odd to me to defer creating a Temporary here and append it to the m_unusedTemps.

void ReleaseTemporariesDefinedBy(GenTree* node)
{
assert(IsDataFlowRoot(node)); // We rely on the node not moving after this call.
if (!node->OperIs(GT_STORE_LCL_VAR))
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this check. Can't we see reordering under other top level node types?

}

unsigned index = static_cast<unsigned>(ActualTypeToWasmValueType(node->TypeGet()));
Temporary* local = Remove(&m_unusedTemps[index]);
Copy link
Member

Choose a reason for hiding this comment

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

If we didn't defer above we could assert here instead of allocating a new temporary.

ArrayStack<GenTree**> m_stack;
unsigned m_minimumTempLclNum;
Temporary* m_availableTemps[static_cast<unsigned>(WasmValueType::Count)] = {};
Temporary* m_unusedTemps[static_cast<unsigned>(WasmValueType::Count)] = {};
Copy link
Member

Choose a reason for hiding this comment

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

Naming: m_inUseTemps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants