[llvm-dev] RFC: New mechanism for hard register operands to inline asm

James Y Knight via llvm-dev llvm-dev at lists.llvm.org
Tue Jun 22 15:01:47 PDT 2021


On Tue, Jun 22, 2021 at 11:54 AM Anirudh Prasad via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi All,
>
> We wanted to bring up the possibility of introducing a new inline asm
> constraint for all targets. This new constraint is meant to be used as a
> replacement for the register asm construct. Part of the motivation behind
> this proposal is to come up with something that is a bit nicer and more
> obvious to use. The new inline asm constraint would be as follows:
>
> {“<register-name>”} (operand name) ...
>
> The constraint will try to tie the particular inline asm operand to a
> specific register.
>
> This is also proposed as an RFC in the GCC mailing lists (
> https://gcc.gnu.org/pipermail/gcc/2021-June/236269.html). We would
> ideally like to maintain consistency with GCC.
>

Sounds good --  if GCC also implements it. Behind the scenes, Clang
effectively already implements this proposal -- the register-asm-variables
are just a strange frontend spelling for hard register constraints. They do
nothing else, and in particular, they do NOT necessarily live in that
register other than when being passed to/from an inline asm. So, we'd be
adding a second (more obvious) spelling to do the exact same thing we
already implement. IMO it would not be worth it if this new syntax was
unique to Clang, but is if both clang and gcc implement it.

Why we believe the introduction of this new “hard register” inline asm
> constraint to be useful?
>
> 1. It is more flexible than the register asm construct since a user does
> not need to be concerned with which registers are previously mapped to
> which variable(s).
> 2. The documentation of the register asm construct (https:/ /
> gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html) specifies that
> function calls might clobber registers assigned with "register asm". Using
> this new inline asm constraint ensures that the operand is assigned to a
> particular register only in the context of the inline asm call.
>

This advantage doesn't apply to Clang, because the asm-register variables
are already assigned to the named register only in the context of an inline
asm call.

3. One register asm variable cannot be used for 2 different inline assembly
> statements if the value is expected in different hard registers.
>
> We are very interested in hearing opinions on the above proposal!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210622/bc8a0343/attachment.html>


More information about the llvm-dev mailing list