AlexandreFressange via llvm-dev
2015-Nov-14 21:09 UTC
[llvm-dev] llvm, new language and inline assembly.
Hello, I am creating a very small language which needs inline assembly, with llvm as a compiler framework. On x86, I am interested in the "out","in","mfence","lfence".. and other specific sse operations. How may I tell llvm about them in my language? -> I read that "module asm" should be my companion but I am not sure how it works (the doc about it, is only a few lines of not so complete information. What is the syntax when the final register the value comes from or goes in doesn't matter? so no explicit %%rax or %%rdx but rather something like %%r?x; here the question mark let the compiler to choose the best register for the value); I need the same functionalities as "asm" in C but in my language basically. Thanks -- Alex
Tim Northover via llvm-dev
2015-Nov-15 02:57 UTC
[llvm-dev] llvm, new language and inline assembly.
On 14 November 2015 at 13:09, AlexandreFressange via llvm-dev <llvm-dev at lists.llvm.org> wrote:> -> I read that "module asm" should be my companion but I am not sure how it works (the doc about it, is only a few lines of not so complete information.The documentation is unfortunately lacking. But you almost certainly don't want module-level inline asm; you probably want a "%res = call TYPE asm ..." type thing instead.> What is the syntax when the final register the value comes from or goes in doesn't matter? so no explicit %%rax or %%rdx but rather something like %%r?x; here the question mark let the compiler to choose the best register for the value);Our inline asm is based heavily on GCC style syntax. The main change is that a "%N" or "%[whatever]" argument to reference an in/out value becomes $N. Operand modifiers are written "${N:mod}" rather than "%modN". The best way to get familiar with it is probably to write what you want in GCC asm and run "clang -S -o- -emit-llvm" to see what IR gets produced. Cheers. Tim.
AlexandreFressange via llvm-dev
2015-Nov-15 06:52 UTC
[llvm-dev] llvm, new language and inline assembly.
Will do that Tim, Thanks a lot :) -- Alex 15.11.2015, 03:57, "Tim Northover" <t.p.northover at gmail.com>:> On 14 November 2015 at 13:09, AlexandreFressange via llvm-dev > <llvm-dev at lists.llvm.org> wrote: >> -> I read that "module asm" should be my companion but I am not sure how it works (the doc about it, is only a few lines of not so complete information. > > The documentation is unfortunately lacking. But you almost certainly > don't want module-level inline asm; you probably want a "%res = call > TYPE asm ..." type thing instead. > >> What is the syntax when the final register the value comes from or goes in doesn't matter? so no explicit %%rax or %%rdx but rather something like %%r?x; here the question mark let the compiler to choose the best register for the value); > > Our inline asm is based heavily on GCC style syntax. The main change > is that a "%N" or "%[whatever]" argument to reference an in/out value > becomes $N. Operand modifiers are written "${N:mod}" rather than > "%modN". > > The best way to get familiar with it is probably to write what you > want in GCC asm and run "clang -S -o- -emit-llvm" to see what IR gets > produced. > > Cheers. > > Tim.