how to add some default target flags?

Hello,

I've built LLVM natively on a fpu-less (soft-float) mips32 target, and
built mesa to use it.
However llvm apparently cannot determine what machine it's running on and builds
code for a generic mips target with fpu.

Is there a way to have llc/llvm always use "-march=mipsle -mcpu=mips32
-mattr=+soft-float" as a default command line, something similar to
gcc's "--with-arch=mips32 --with-float=soft" configure switches?

Thanks!
    Manuel Lauss

Hi,

We haven't implemented host detection yet. However, I'm not sure it would help in
this case since lacking an FPU isn't always a good reason to use soft-float. This is because
soft-float binaries are incompatible with hard-float binaries (see below).
Could you tell me more about the target?

Many fpu-less targets (particularly those running linux distributions) should generate
hard-float code regardless and rely on fpu emulation in the kernel. For example, I have
an EdgeRouter Pro running Debian Jessie. This target lacks an fpu but I can't use
soft-float because that would change the calling convention and therefore break
compatibility with the libraries installed on the system.

Is there a way to have llc/llvm always use "-march=mipsle -mcpu=mips32
-mattr=+soft-float" as a default command line, something similar to
gcc's "--with-arch=mips32 --with-float=soft" configure switches?

Not that I know of. The triple is the only thing you could use in LLVM and that doesn't specify soft-float vs hard-float.

We haven't implemented host detection yet. However, I'm not sure it would help in
this case since lacking an FPU isn't always a good reason to use soft-float. This is because
soft-float binaries are incompatible with hard-float binaries (see below).
Could you tell me more about the target?

It's alchemy chips (mips32r1 le). I maintain a complete soft-float
gentoo userland for them,
and a kernel patch which kills all fpu users with SIGILL.

Many fpu-less targets (particularly those running linux distributions) should generate
hard-float code regardless and rely on fpu emulation in the kernel. For example, I have
an EdgeRouter Pro running Debian Jessie. This target lacks an fpu but I can't use
soft-float because that would change the calling convention and therefore break
compatibility with the libraries installed on the system.

the in-kernel emulator is slow, so years ago I started maintaining my
own softfloat
userland. I routinely try new things and with llvm I noticed that it
defaults to hardfloat
(i.e. when used by mesa).

Is there a way to have llc/llvm always use "-march=mipsle -mcpu=mips32
-mattr=+soft-float" as a default command line, something similar to
gcc's "--with-arch=mips32 --with-float=soft" configure switches?

Not that I know of. The triple is the only thing you could use in LLVM and that doesn't specify soft-float vs hard-float.

Well, gcc is configured as "mipsel-softfloat-linux-gnu-gcc" and that works
beautifully.

Thanks!
        Manuel

From: Manuel Lauss [mailto:manuel.lauss@gmail.com]
Sent: 03 June 2015 15:28
To: Daniel Sanders
Cc: llvmdev@dcs-maillist2.engr.illinois.edu
Subject: Re: [LLVMdev] how to add some default target flags?

> We haven't implemented host detection yet. However, I'm not sure it
would help in
> this case since lacking an FPU isn't always a good reason to use soft-float.
This is because
> soft-float binaries are incompatible with hard-float binaries (see below).
> Could you tell me more about the target?

It's alchemy chips (mips32r1 le). I maintain a complete soft-float
gentoo userland for them,
and a kernel patch which kills all fpu users with SIGILL.

Ah ok, soft-float makes sense for your situation.

The best I can think of at the moment is applying a small patch to clang so that soft-float is the default. 'llc' shouldn't be changed since it's not a user tool and changing its default behaviours will break 'make check'.

> Many fpu-less targets (particularly those running linux distributions) should
generate
> hard-float code regardless and rely on fpu emulation in the kernel. For
example, I have
> an EdgeRouter Pro running Debian Jessie. This target lacks an fpu but I can't
use
> soft-float because that would change the calling convention and therefore
break
> compatibility with the libraries installed on the system.

the in-kernel emulator is slow, so years ago I started maintaining my
own softfloat
userland. I routinely try new things and with llvm I noticed that it
defaults to hardfloat
(i.e. when used by mesa).

Yes, it's definitely slow. I have some examples of 3 minute tests that take a couple hours via emulation.
I've thought of a couple ways to significantly reduce the overhead but I lack the time to work on them.

>> Is there a way to have llc/llvm always use "-march=mipsle -mcpu=mips32
>> -mattr=+soft-float" as a default command line, something similar to
>> gcc's "--with-arch=mips32 --with-float=soft" configure switches?
>
> Not that I know of. The triple is the only thing you could use in LLVM and
that doesn't specify soft-float vs hard-float.

Well, gcc is configured as "mipsel-softfloat-linux-gnu-gcc" and that works
beautifully.

Thanks!
        Manuel

That triple is encoding ABI information in the 'vendor' field. This works for GCC (and GNU tools in general) because there's no real correlation between the triple and the behaviour of the tool. For those tools, the ./configure options are what really matters and the triple just provides overridable defaults.

I have another thread on LLVMdev that goes into more detail but LLVM's internals currently believe that GNU triples more meaningful than they actually are. It turns out that they are ambiguous, incomplete, and even misleading but LLVM uses them to make decisions in a number of places. This is a particular problem in the Mips target at the moment but other targets have encountered it too.