Clang: how is the list of supported target architectures?

I'm currently interested in ARM in general and, in particular, the goals of iphone / android. But I just want to learn more about clang, as it feels that it will play an important role in the coming years.

I tried

clang -cc1 --help|grep -i list clang -cc1 --help|grep arch|grep -v search clang -cc1 --help|grep target -triple <value> Specify target triple (eg i686-apple-darwin9) 

I know that clang has the -triplet option, but how can I list all the possible values ​​for it? I found that clang is very different from gcc in terms of cross-compiling, in the GCC world you have to have separate binary code for everything, e.g. PLATFORM_make or PLATFORM_ld (i * 86-pc-cygwin i * 86 - * - linux-gnu etc. .d. http://git.savannah.gnu.org/cgit/libtool.git/tree/doc/PLATFORMS )

in the clang world, this is only one binary (as I read on some forums). But how do I get a list of supported goals? And if my target is not supported on my distribution (linux / windows / macos / whatever), how can I get one that supports more platforms?

if i svn the last clang like this:

 svn co http://llvm.org/svn/llvm-project/cfe/trunk clang 

Will I get most platforms? It seems that Clang was not built with cross-compilation right away, but since it is based on llvm, it should be very cross-friendly in theory? thank!

+56
clang llvm
Feb 23 '13 at 3:58
source share
6 answers

I am using Clang 3.3, I think the best way to get the answer is to read the source code. at llvm / ADT / Triple.h ( http://llvm.org/doxygen/Triple_8h_source.html ):

  enum ArchType { UnknownArch, arm, // ARM: arm, armv.*, xscale aarch64, // AArch64: aarch64 hexagon, // Hexagon: hexagon mips, // MIPS: mips, mipsallegrex mipsel, // MIPSEL: mipsel, mipsallegrexel mips64, // MIPS64: mips64 mips64el,// MIPS64EL: mips64el msp430, // MSP430: msp430 ppc, // PPC: powerpc ppc64, // PPC64: powerpc64, ppu r600, // R600: AMD GPUs HD2XXX - HD6XXX sparc, // Sparc: sparc sparcv9, // Sparcv9: Sparcv9 systemz, // SystemZ: s390x tce, // TCE (http://tce.cs.tut.fi/): tce thumb, // Thumb: thumb, thumbv.* x86, // X86: i[3-9]86 x86_64, // X86-64: amd64, x86_64 xcore, // XCore: xcore mblaze, // MBlaze: mblaze nvptx, // NVPTX: 32-bit nvptx64, // NVPTX: 64-bit le32, // le32: generic little-endian 32-bit CPU (PNaCl / Emscripten) amdil, // amdil: amd IL spir, // SPIR: standard portable IR for OpenCL 32-bit version spir64 // SPIR: standard portable IR for OpenCL 64-bit version }; 

and in clang / lib / Driver / ToolChains.cpp there is a link to the hand.

 static const char *GetArmArchForMArch(StringRef Value) { return llvm::StringSwitch<const char*>(Value) .Case("armv6k", "armv6") .Case("armv6m", "armv6m") .Case("armv5tej", "armv5") .Case("xscale", "xscale") .Case("armv4t", "armv4t") .Case("armv7", "armv7") .Cases("armv7a", "armv7-a", "armv7") .Cases("armv7r", "armv7-r", "armv7") .Cases("armv7em", "armv7e-m", "armv7em") .Cases("armv7f", "armv7-f", "armv7f") .Cases("armv7k", "armv7-k", "armv7k") .Cases("armv7m", "armv7-m", "armv7m") .Cases("armv7s", "armv7-s", "armv7s") .Default(0); } static const char *GetArmArchForMCpu(StringRef Value) { return llvm::StringSwitch<const char *>(Value) .Cases("arm9e", "arm946e-s", "arm966e-s", "arm968e-s", "arm926ej-s","armv5") .Cases("arm10e", "arm10tdmi", "armv5") .Cases("arm1020t", "arm1020e", "arm1022e", "arm1026ej-s", "armv5") .Case("xscale", "xscale") .Cases("arm1136j-s", "arm1136jf-s", "arm1176jz-s", "arm1176jzf-s", "armv6") .Case("cortex-m0", "armv6m") .Cases("cortex-a8", "cortex-r4", "cortex-a9", "cortex-a15", "armv7") .Case("cortex-a9-mp", "armv7f") .Case("cortex-m3", "armv7m") .Case("cortex-m4", "armv7em") .Case("swift", "armv7s") .Default(0); } 
+23
02 Sep '13 at 15:12
source share

As far as I can tell, there is no command line option to list the architectures that the given clang binary supports, and even running strings on it really doesn't help. Clang is, in fact, just a C LLVM translator, and it is LLVM itself that deals with the serious creation of actual machine code, so it is not surprising that Clang does not pay much attention to the underlying architecture.

As already noted, you can ask llc which architectures it supports. This is not all that is useful, not only because these LLVM components cannot be installed, but due to the vagaries of the search paths and packaging systems, your llc and clang binaries may not match the same version of LLVM.

However, for the sake of argument, let's say that you compiled both LLVM and Clang yourself, or that you are otherwise happy to accept your LLVM binaries as good enough:

  • llc --version will provide a list of all supported architectures. By default, it is compiled to support all architectures. What you can consider as a single architecture, such as ARM, can have several LLVM architectures, such as regular ARM, Thumb, and AArch64. This is mainly for ease of implementation, since different execution modes have very different command encodings and semantics.
  • For each architecture listed in the architecture list, llc -march=ARCH -mattr=help will list available processors and available functions. CPUs are usually a convenient way to set a default feature set.

But now for the bad news. Clang or LLVM does not have a table of convenient tables that can be reset, because for architecture-specific backends, you can split the triple row into the llvm::Triple object (defined in include / llvm / ADT / Triple.h ). In other words, to reset all available triples, a solution to the stop problem is required. See, for example, llvm::ARM_MC::ParseARMTriple(...) which special cases parse the "generic" string.

Ultimately, however, the “triple” is basically a backward compatibility feature that makes Clang a replacement for GCC, so you don’t have to pay much attention to this unless you port Clang or LLVM to a new platform or architecture. Instead, you will probably find the results llv -march=arm -mattr=help and stun a huge array of different ARM functions to be more useful in your research.

Good luck with your research!

+12
Jan 28 '16 at 12:46 on
source share

According to Jonathan Roelofs in this conversation, "What are the goals Clang supports?" :

 $ llc --version LLVM (http://llvm.org/): LLVM version 3.6.0 Optimized build with assertions. Built Apr 2 2015 (01:25:22). Default target: x86_64-apple-darwin12.6.0 Host CPU: corei7-avx Registered Targets: aarch64 - AArch64 (little endian) aarch64_be - AArch64 (big endian) amdgcn - AMD GCN GPUs arm - ARM arm64 - ARM64 (little endian) armeb - ARM (big endian) cpp - C++ backend hexagon - Hexagon 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 ppc64le - PowerPC 64 LE r600 - AMD GPUs HD2XXX-HD6XXX sparc - Sparc sparcv9 - Sparc V9 systemz - SystemZ thumb - Thumb thumbeb - Thumb (big endian) x86 - 32-bit X86: Pentium-Pro and above x86-64 - 64-bit X86: EM64T and AMD64 xcore - XCore 

Future versions of Clang may provide the following. They are listed as “proposed”, although not yet available at least from version 3.9.0:

 $ clang -target <target_from_list_above> --print-multi-libs $ clang -print-supported-archs $ clang -march x86 -print-supported-systems $ clang -march x86 -print-available-systems 
+7
Aug 24 '16 at 5:00
source share

Also try

 > llc -mattr=help Available CPUs for this target: amdfam10 - Select the amdfam10 processor. athlon - Select the athlon processor. athlon-4 - Select the athlon-4 processor. athlon-fx - Select the athlon-fx processor. athlon-mp - Select the athlon-mp processor. athlon-tbird - Select the athlon-tbird processor. athlon-xp - Select the athlon-xp processor. athlon64 - Select the athlon64 processor. athlon64-sse3 - Select the athlon64-sse3 processor. atom - Select the atom processor. ... Available features for this target: 16bit-mode - 16-bit mode (i8086). 32bit-mode - 32-bit mode (80386). 3dnow - Enable 3DNow! instructions. 3dnowa - Enable 3DNow! Athlon instructions. 64bit - Support 64-bit instructions. 64bit-mode - 64-bit mode (x86_64). adx - Support ADX instructions. ... 
+5
Jan 28 '14 at 15:43
source share

One hint you can do: if you are trying to find a specific triple of goals, you need to install llvm on this system, then do

 $ llc --version | grep Default Default target: x86_64-apple-darwin16.1.0 

or alternatively:

 $ llvm-config --host-target x86_64-apple-darwin16.0.0 or $ clang -v 2>&1 | grep Target Target: x86_64-apple-darwin16.1.0 

Then you know how to target cross-compiling.

There seems to be a “party" of goals, here is a list, feel free to add a wiki community style to it:

 arm-none-eabi armv7a-none-eabi arm-linux-gnueabihf arm-none-linux-gnueabi i386-pc-linux-gnu x86_64-apple-darwin10 i686-w64-windows-gnu # same as i686-w64-mingw32 x86_64-pc-linux-gnu # from ubuntu 64 bit x86_64-unknown-windows-cygnus # cygwin 64-bit x86_64-w64-windows-gnu # same as x86_64-w64-mingw32 

Here it’s all the same docs (apparently, this is a four [or five-fold?] Instead of a three these days):

 The triple has the general format <arch><sub>-<vendor>-<sys>-<abi>, where: arch = x86, arm, thumb, mips, etc. sub = for ex. on ARM: v5, v6m, v7a, v7m, etc. vendor = pc, apple, nvidia, ibm, etc. sys = none, linux, win32, darwin, cuda, etc. abi = eabi, gnu, android, macho, elf, etc. 

and you can even fine-tune the target processor outside of this, although it uses a reasonable default value for the triple-based target processor.

Sometimes goals "allow" the same thing, therefore, to see which goal they actually belong to:

  $ clang -target x86_64-w64-mingw32 -v 2>&1 | grep Target Target: x86_64-w64-windows-gnu 
+5
Nov 30 '16 at 2:00
source share

He will not list all triples, but

 llvm-as < /dev/null | llc -mcpu=help 

at least list all processors.

+1
Jun 20 '13 at 4:27
source share



All Articles