ORiordan, Martin via llvm-dev
2017-Dec-12 13:30 UTC
[llvm-dev] File/module scope inline assembly
I am trying to support an experimental DSL that uses non-C identifiers, but I
want to write the implementation of the runtime support libraries for this DSL
in C. The compiler is built using the LLVM v5.0.0 release branch.
To do this I thought I could simply write:
int foo() { return 42; } // The C implementation
asm(".alias nonCname foo"); // Make the non-C name be a synonym for
the C implementation
If I compile with '-S -emit-llvm', the LL file contains:
module asm ".alias nonCname foo"
define i32 @foo() local_unnamed_addr #0 {
ret i32 42
}
That is, the inline-assembly precedes the function definition. The resulting
assembly code for the target also has the '.alias nonCname foo' before
the definition for the function 'foo'. When I edit the LL file to place
the inline-assembly after the function definition, it makes no difference to the
emitted assembly code for the target, it is still placed first.
Our assembler requires that the symbol being aliased has been defined before the
'.alias' directive; but I can't get LLVM to do this, and it
aggregates all file-scoped (or module-scoped) inline assembly before the code
generated for the functions and data.
Since the semantics of inline-assembly are very murky, I don't know if this
is a bug or by-design.
Is there anyway of writing C code that will preserve the relative ordering of
file-scoped function, data and inline-assembly definitions?
Thanks,
MartinO
--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263
This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20171212/263e9f37/attachment.html>
David Blaikie via llvm-dev
2017-Dec-12 18:36 UTC
[llvm-dev] File/module scope inline assembly
This is roughly by design in LLVM - though other compilers have other designs. LLVM does not preserve the relative ordering of inline assembly and other IR (functions, globals, etc). "Is there anyway of writing C code that will preserve the relative ordering of file-scoped function, data and inline-assembly definitions?" - using an LLVM-based compiler, basically: no. Sorry :/ On Tue, Dec 12, 2017 at 5:30 AM ORiordan, Martin via llvm-dev < llvm-dev at lists.llvm.org> wrote:> I am trying to support an experimental DSL that uses non-C identifiers, > but I want to write the implementation of the runtime support libraries for > this DSL in C. The compiler is built using the LLVM v5.0.0 release branch. > > > > To do this I thought I could simply write: > > > > int foo() { return 42; } // The C implementation > > asm(".alias nonCname foo"); // Make the non-C name be a synonym for the C > implementation > > > > If I compile with ‘-S –emit-llvm’, the LL file contains: > > > > module asm ".alias nonCname foo" > > define i32 @foo() local_unnamed_addr #0 { > > ret i32 42 > > } > > > > That is, the inline-assembly precedes the function definition. The > resulting assembly code for the target also has the ‘.alias nonCname foo’ > before the definition for the function ‘foo’. When I edit the LL file to > place the inline-assembly after the function definition, it makes no > difference to the emitted assembly code for the target, it is still placed > first. > > > > Our assembler requires that the symbol being aliased has been defined > before the ‘.alias’ directive; but I can’t get LLVM to do this, and it > aggregates all file-scoped (or module-scoped) inline assembly before the > code generated for the functions and data. > > > > Since the semantics of inline-assembly are very murky, I don’t know if > this is a bug or by-design. > > > > Is there anyway of writing C code that will preserve the relative ordering > of file-scoped function, data and inline-assembly definitions? > > > > Thanks, > > > > MartinO > > > > > > -------------------------------------------------------------- > Intel Research and Development Ireland Limited > Registered in Ireland > Registered Office: Collinstown Industrial Park, Leixlip, County Kildare > Registered Number: 308263 > > This e-mail and any attachments may contain confidential material for the > sole use of the intended recipient(s). Any review or distribution by others > is strictly prohibited. If you are not the intended recipient, please > contact the sender and delete all copies. > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171212/e7805b55/attachment.html>
Matthias Braun via llvm-dev
2017-Dec-12 19:50 UTC
[llvm-dev] File/module scope inline assembly
gcc/clang have a syntax for that which works fine for me:
$ cat t.c
void thumb_up(void) asm("👍");
void thumb_up(void) {
}
$ clang -O3 -S t.c -o -
...
.globl "👍"
.p2align 4, 0x90
"👍": ## @"\01\F0\9F\91\8D"
...
- Matthias
> On Dec 12, 2017, at 5:30 AM, ORiordan, Martin via llvm-dev <llvm-dev at
lists.llvm.org> wrote:
>
> I am trying to support an experimental DSL that uses non-C identifiers, but
I want to write the implementation of the runtime support libraries for this DSL
in C. The compiler is built using the LLVM v5.0.0 release branch.
>
> To do this I thought I could simply write:
>
> int foo() { return 42; } // The C implementation
> asm(".alias nonCname foo"); // Make the non-C name be a synonym
for the C implementation
>
> If I compile with ‘-S –emit-llvm’, the LL file contains:
>
> module asm ".alias nonCname foo"
> define i32 @foo() local_unnamed_addr #0 {
> ret i32 42
> }
>
> That is, the inline-assembly precedes the function definition. The
resulting assembly code for the target also has the ‘.alias nonCname foo’ before
the definition for the function ‘foo’. When I edit the LL file to place the
inline-assembly after the function definition, it makes no difference to the
emitted assembly code for the target, it is still placed first.
>
> Our assembler requires that the symbol being aliased has been defined
before the ‘.alias’ directive; but I can’t get LLVM to do this, and it
aggregates all file-scoped (or module-scoped) inline assembly before the code
generated for the functions and data.
>
> Since the semantics of inline-assembly are very murky, I don’t know if this
is a bug or by-design.
>
> Is there anyway of writing C code that will preserve the relative ordering
of file-scoped function, data and inline-assembly definitions?
>
> Thanks,
>
> MartinO
>
>
> --------------------------------------------------------------
> Intel Research and Development Ireland Limited
> Registered in Ireland
> Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
> Registered Number: 308263
>
> This e-mail and any attachments may contain confidential material for the
sole use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
<http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20171212/a9d471aa/attachment.html>
Martin J. O'Riordan via llvm-dev
2017-Dec-12 20:50 UTC
[llvm-dev] File/module scope inline assembly
Hi Matthias,
That trick didn’t work for me, but it got me thinking, and the following “does”
work for me:
int foo() {
asm(".alias nonCname foo");
return 42;
}
and our assembler is quite happy to accept the output with the desired outcome
:)
Thanks for the pointer,
MartinO
From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Matthias
Braun via llvm-dev
Sent: 12 December 2017 19:50
To: ORiordan, Martin <martin.oriordan at intel.com>
Cc: llvm-dev <llvm-dev at lists.llvm.org>
Subject: Re: [llvm-dev] File/module scope inline assembly
gcc/clang have a syntax for that which works fine for me:
$ cat t.c
void thumb_up(void) asm("👍");
void thumb_up(void) {
}
$ clang -O3 -S t.c -o -
...
.globl "👍"
.p2align 4, 0x90
"👍": ## @"\01\F0\9F\91\8D"
...
- Matthias
On Dec 12, 2017, at 5:30 AM, ORiordan, Martin via llvm-dev <llvm-dev at
lists.llvm.org <mailto:llvm-dev at lists.llvm.org> > wrote:
I am trying to support an experimental DSL that uses non-C identifiers, but I
want to write the implementation of the runtime support libraries for this DSL
in C. The compiler is built using the LLVM v5.0.0 release branch.
To do this I thought I could simply write:
int foo() { return 42; } // The C implementation
asm(".alias nonCname foo"); // Make the non-C name be a synonym for
the C implementation
If I compile with ‘-S –emit-llvm’, the LL file contains:
module asm ".alias nonCname foo"
define i32 @foo() local_unnamed_addr #0 {
ret i32 42
}
That is, the inline-assembly precedes the function definition. The resulting
assembly code for the target also has the ‘.alias nonCname foo’ before the
definition for the function ‘foo’. When I edit the LL file to place the
inline-assembly after the function definition, it makes no difference to the
emitted assembly code for the target, it is still placed first.
Our assembler requires that the symbol being aliased has been defined before the
‘.alias’ directive; but I can’t get LLVM to do this, and it aggregates all
file-scoped (or module-scoped) inline assembly before the code generated for the
functions and data.
Since the semantics of inline-assembly are very murky, I don’t know if this is a
bug or by-design.
Is there anyway of writing C code that will preserve the relative ordering of
file-scoped function, data and inline-assembly definitions?
Thanks,
MartinO
--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263
This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
_______________________________________________
LLVM Developers mailing list
<mailto:llvm-dev at lists.llvm.org> llvm-dev at lists.llvm.org
<http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20171212/d15aa037/attachment.html>