abrown opened PR #10632 from abrown:asm-operands-post-fixed to bytecodealliance:main:
This PR changes the paradigm for how a user (like
regalloc2) will interact with the operands of an assembler instruction. Instead of using a visitor pattern, calling functions for each of the operands, this approach builds up a list of operands that expose&mutreferences to the underlying operands of the instruction.While this does have the advantage of being a bit more straightforward, the motivation for this is more subtle: some instructions have special register constraints that the visitor pattern does not handle. E.g., when switching
AluConstOpto use the new assembler, I noticed that the calls it makes to the register allocator are quite different than the visitor expects:AluConstOpboils down toxor %r*, %r*and expects us a completely different call toregalloc2: a singlereg_def(). We would need to build a completely different visitor implementation for this.Also, this refactoring makes it possible for users of the assembler to examine and modify any operands to any instruction. This should be useful regardless of the
AluConstOpmotivation.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
abrown requested cfallin for a review on PR #10632.
abrown requested wasmtime-compiler-reviewers for a review on PR #10632.
abrown submitted PR review.
abrown created PR review comment:
We _could_ use a
smallvecwith a threshold of 4 and be a bit more efficient but I thought, for now, this was fine.
cfallin commented on PR #10632:
Hmm -- I have some serious concerns with this approach, and in particular, constructing a
Vecof operands for each instruction during each visitor pass. We've worked hard to reduce allocations during compilation, and to operate on data in-place as much as possible; I would expect this to have a pretty nontrivial impact on all that, especially in the fullness of time when the migration of all instructions to the new assembler is complete. Basically: the "mutate in place" was hard-won, let's not give it up.I suspect/hope there is an easier way to address the "differing constraints for some instructions" problem. In the xor case, we could adopt the approach we took with XMM zeroing, namely to have an "uninitialized value" virtual def instruction that assembles to nothing and then always emit that prior to (and only in the case of) an xor-zeroing idiom. What do you think?
abrown closed without merge PR #10632.
abrown commented on PR #10632:
The now-merged #10648 takes a different approach to this problem.
Last updated: Dec 06 2025 at 07:03 UTC