[cfe-dev] [llvm-dev] Writing built-ins for instructions returning multiple operands
mats petersson via cfe-dev
cfe-dev at lists.llvm.org
Wed Sep 9 03:31:52 PDT 2015
Kind of depends on what you actually get back.
For example, if I take the RDTSC instruction on x86, it returns a 64-bit
value, but it's in two registers, EAX and EDX as 32-bit values. The natural
thing in that case is to let the builtin form a 64-bit value [either in EAX
and EDX in the 32-bit compiler, as that happens to be the way 64-bit values
are returned, or as a single 64-bit value by shifting/oring the two
register values into one 64-bit return value].
However, if we have, say, an instruction that returns two distinct values
(div that also gives the remainder, as a simple example), you will either
have to return a (small) struct, or pass in a pointer to be filled in by
the function [the latter is not ideal from an optimisation perspective, as
the optimiser has a harder time knowing if the output is aliased with
On 9 September 2015 at 10:53, Martin J. O'Riordan via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> I have written many builtins for our SHAVE processor which bind directly
> to our instructions, and making instructions that are not easily selectable
> by the compiler available to the programmer.
> The majority of these are straight-forward enough, taking a small number
> pf input operands and returning a single result; for example ‘int
> __builtin_shave_mul(int, int)’ might map onto a simple multiple
> instruction that takes two input integer operands in registers, and returns
> a single integer result in another register.
> However, I have a small number instructions that have two output operands,
> each in a separate register. I would like to provide access to these
> instructions using the builtins approach. This is easy enough to express
> in LLVM IR, but I have not been able to figure out how this can be
> presented in a C or C++ binding.
> Is there a pattern for doing this kind of thing that I haven’t discovered,
> or is it simply something that cannot be expressed using the C binding to
> the builtins?
> MartinO (Movidius Ltd.)
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev