How to add a new target/toolchain to Clang ?

Hi all,

I have been developping a out-of-tree backend.
I would like to integrate it with clang.
Note that my backend is rather simple, generates elf32, and I do not need about linux, libary paths, …

Can someone give me a pointer to a readme, an article, or maybe a good (i.e. simple) example ?

Note :on a second step, I would like to support inline assembly in C code…

Hi all,

I have been developping a out-of-tree backend.
I would like to integrate it with clang.
Note that my backend is rather simple, generates elf32, and I do not need
about linux, libary paths, ...

Can someone give me a pointer to a readme, an article, or maybe a good
(i.e. simple) example ?

Note :on a second step, I would like to support inline assembly in C code..

Here is a simple example for adding a new toolchain:
http://reviews.llvm.org/D10700

See R600TargetInfo in lib/Basic/Targets.cpp for an example of a
simple Target that supports inline assembly.

-Tom

Thanks Tom for your help, it as indeed very easy to make the link with the linker (not sick joke).
Unfortunately, clang generates object files for target x86_64, even though I try --target --triple, --arch, …
What is the trick to tell him which target to use ?

Thanks Tom for your help, it as indeed very easy to make the link with the
linker (not sick joke).
Unfortunately, clang generates object files for target x86_64, even though
I try --target --triple, --arch, ...
What is the trick to tell him which target to use ?

The option to use is -target:

clang -target yourcpu-- in.c

You also need to teach clang to map the triple to your
TargetInfo implementation. See AllocateTarget() in lib/Basic/Targets.cpp

-Tom

Good catch.
clang is now generating asm files for my target.
Although llc works, llvm-mc is not finished yet, so it breaks.

Is there a reason clang generates asm then object files, instead of going
internaly to MCInst then object file ?
And can I force it to do so ?
I did not find the appropriate option or hook in class ToolChain ...

>
> You also need to teach clang to map the triple to your
> TargetInfo implementation. See AllocateTarget() in lib/Basic/Targets.cpp
>

Good catch.
clang is now generating asm files for my target.
Although llc works, llvm-mc is not finished yet, so it breaks.

Is there a reason clang generates asm then object files, instead of going
internaly to MCInst then object file ?
And can I force it to do so ?
I did not find the appropriate option or hook in class ToolChain ...

You can force it to use MCInst with the option -fintegrated-as. You can
also set this as the default in your ToolChain. The AMDGPU ToolChain
patch has an example of using the integrated assembler by default:
see AMDGPUToolChain::IsIntegratedAssemblerDefault().

-Tom