Shan Shan - 2 months ago 12
C Question

how to compile a program using LLVM for different target architecture?

I want to compile the basic program hello.c to native x86 architecture using LLVM / Clang to generate the intermediate and assembly.
I used the following commands :

clang -O3 -emit-llvm hello.c -c -o hello.bc
llc hello.bc -o hello.s


It works perfectly. How do I generate the code for other architecture say SPARC 32 bit? Are there any flags used in clang to specify the architecture?

Answer

You can run llc --version to get a list of supported targets. From my machine:

$ llc --version
LLVM (http://llvm.org/):
  LLVM version 3.2svn
  Optimized build with assertions.
  Built Aug 30 2012 (23:29:11).
  Default target: mipsel-sde-elf
  Host CPU: corei7-avx

  Registered Targets:
    arm      - ARM
    cellspu  - STI CBEA Cell SPU [experimental]
    cpp      - C++ backend
    hexagon  - Hexagon
    mblaze   - MBlaze
    mips     - Mips
    mips64   - Mips64 [experimental]
    mips64el - Mips64el [experimental]
    mipsel   - Mipsel
    msp430   - MSP430 [experimental]
    nvptx    - NVIDIA PTX 32-bit
    nvptx64  - NVIDIA PTX 64-bit
    ppc32    - PowerPC 32
    ppc64    - PowerPC 64
    sparc    - Sparc
    sparcv9  - Sparc V9
    thumb    - Thumb
    x86      - 32-bit X86: Pentium-Pro and above
    x86-64   - 64-bit X86: EM64T and AMD64
    xcore    - XCore

In your case, you want llc -march=sparc, probably.