【问题标题】:clang: how to list supported target architectures?clang:如何列出支持的目标架构?
【发布时间】:2013-02-08 19:44:04
【问题描述】:

目前我对 ARM 感兴趣,特别是 iphone/android 目标。但我只是想了解更多关于 clang 的信息,因为感觉它会在未来几年发挥重要作用。

我试过了

clang -cc1 --help|grep -i list
clang -cc1 --help|grep arch|grep -v search
clang -cc1 --help|grep target

 -triple <value>         Specify target triple (e.g. i686-apple-darwin9)

我知道 clang 有 -triplet 参数,但是如何列出它的所有可能值? 我发现 clang 在交叉编译方面与 gcc 非常不同,在 GCC 世界中,您应该为所有内容使用单独的二进制文件,例如 PLATFORM_make 或 PLATFORM_ld (i*86-pc-cygwin i*86-*-linux-gnu 等。@ 987654321@)

在 clang 世界中,它只有一个二进制文件(正如我在一些论坛上看到的那样)。但是我如何获得支持的目标列表呢?如果我的目标在我的发行版(linux/windows/macos/whatever)上不支持,我怎样才能获得支持更多平台的目标?

如果我的 SVN 最新的 clang 是这样的:

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

我会得到大多数平台吗? 看起来 Clang 并没有立即考虑交叉编译,但是由于它是基于 llvm 的,所以理论上应该是非常交叉友好的?谢谢!

【问题讨论】:

  • 不是一个完整的答案,但 llc --version 会给你目标
  • 我认为您必须查看源代码才能看到三元组。据我了解,clang 的默认构建将包括对交叉编译的基本支持。基本支持仅将代码转换为目标文件(只要集成汇编器支持三元组,否则您将不得不采用 .s 文件)。您必须提供头文件、库、链接器(无论如何,直到 lld 工作)等。
  • 虽然默认安装只有 clang 和 clang++ 可执行文件,但与其他平台一样,您可以使用名称中编码的三元组和四元组创建它们的副本或硬链接。 clang++ 和 clang 实际上只是彼此的副本,它检查可执行文件的名称以查看如何处理输入。

标签: clang llvm


【解决方案1】:

据我所知,没有命令行选项可以列出给定的clang 二进制文件支持哪些架构,甚至在其上运行strings 也无济于事。 Clang 本质上只是一个 C 到 LLVM 的翻译器,而 LLVM 本身负责处理生成实际机器代码的细节,所以 Clang 不太关注底层架构也就不足为奇了。

正如其他人已经指出的那样,您可以询问llc 它支持哪些架构。这并不是很有帮助,不仅因为这些 LLVM 组件可能未安装,而且由于搜索路径和打包系统的变幻莫测,您的 llcclang 二进制文件可能与同一版本的 LLVM 不对应。

但是,为了争论,假设您自己编译了 LLVM 和 Clang,或者您很乐意接受您的 LLVM 二进制文件足够好:

  • llc --version 将列出它支持的所有架构。默认情况下,它被编译为支持所有架构。您可能认为像 ARM 这样的单一架构可能有多个 LLVM 架构,例如常规 ARM、Thumb 和 AArch64。这主要是为了实现方便,因为不同的执行模式有非常不同的指令编码和语义。
  • 对于列出的每个体系结构,llc -march=ARCH -mattr=help 将列出“可用 CPU”和“可用功能”。 CPU 通常只是设置默认功能集合的一种便捷方式。

但现在是坏消息。在 Clang 或 LLVM 中没有可以转储的方便的三元组表,因为特定于体系结构的后端可以选择将三元组字符串解析为 llvm::Triple 对象(在 include/llvm/ADT/Triple.h 中定义)。换句话说,转储所有可用的三元组需要解决停机问题。例如,请参阅 llvm::ARM_MC::ParseARMTriple(...) 解析字符串 "generic" 的特殊情况。

但最终,“三元组”主要是一种向后兼容功能,使 Clang 成为 GCC 的直接替代品,因此您通常不需要过多关注它,除非您将 Clang 或 LLVM 移植到一个新的平台或架构。相反,您可能会发现llc -march=arm -mattr=help 的输出结果令人难以置信,大量不同的 ARM 功能在您的调查中更有用。

祝你研究顺利!

【讨论】:

    【解决方案2】:

    我正在使用 Clang 3.3,我认为获得答案的最佳方法是阅读源代码。 在 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
      };
    

    在 clang/lib/Driver/ToolChains.cpp 中,有关于 arm 的东西。

    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);
    }
    

    【讨论】:

    【解决方案3】:

    你可以做的一个提示:如果你想找到一个特定的目标三元组,是在那个系统上安装 llvm 然后做一个

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

    或者:

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

    那么你就知道在交叉编译时如何定位它了。

    显然那里有“很多”目标,这里有一个列表,请随意添加,社区 wiki 风格:

    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
    i686-pc-windows-gnu # MSVC
    x86_64-pc-windows-gnu # MSVC 64-BIT
    

    这就是docs 列表的内容(显然现在是四倍 [或五倍?] 而不是三倍):

    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.
    

    您甚至可以在此范围之外微调指定目标 cpu,尽管它使用基于三元组的目标 cpu 的合理默认值。

    有时将目标“解析”到同一件事,因此要查看目标实际上被视为什么:

     $ clang -target x86_64-w64-mingw32 -v 2>&1 | grep Target
     Target: x86_64-w64-windows-gnu
    

    【讨论】:

    • 什么时候说mingw32 是否意味着它不适用于MinGW64?有什么东西是 MSVC 兼容的吗?
    • @Royi stackoverflow.com/q/39871656/32453 可能有用,祝你好运!
    • 怎么有win32却没有win64?
    • 我认为 i686-w64-mingw32 是 32 位的,但针对的是“mingw w64”工具链。它也有自己的 32 位版本。去图...
    【解决方案4】:

    从 Clang 11(主干)开始,可以使用新添加的 -print-targets 标志轻松打印支持的目标架构列表:

    $ clang-11 -print-targets
      Registered Targets:
        aarch64    - AArch64 (little endian)
        aarch64_32 - AArch64 (little endian ILP32)
        aarch64_be - AArch64 (big endian)
        amdgcn     - AMD GCN GPUs
        arm        - ARM
        arm64      - ARM64 (little endian)
        arm64_32   - ARM64 (little endian ILP32)
        armeb      - ARM (big endian)
        avr        - Atmel AVR Microcontroller
        bpf        - BPF (host endian)
        bpfeb      - BPF (big endian)
        bpfel      - BPF (little endian)
        hexagon    - Hexagon
        lanai      - Lanai
        mips       - MIPS (32-bit big endian)
        mips64     - MIPS (64-bit big endian)
        mips64el   - MIPS (64-bit little endian)
        mipsel     - MIPS (32-bit little endian)
        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
        riscv32    - 32-bit RISC-V
        riscv64    - 64-bit RISC-V
        sparc      - Sparc
        sparcel    - Sparc LE
        sparcv9    - Sparc V9
        systemz    - SystemZ
        thumb      - Thumb
        thumbeb    - Thumb (big endian)
        wasm32     - WebAssembly 32-bit
        wasm64     - WebAssembly 64-bit
        x86        - 32-bit X86: Pentium-Pro and above
        x86-64     - 64-bit X86: EM64T and AMD64
        xcore      - XCore
    

    参考:LLVM PRLLVM commitClang 11 documentation

    【讨论】:

      【解决方案5】:

      根据 Jonathan Roelofs 在本次演讲中的说法“Which targets does Clang support?”

      $ 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
      

      Clang 的未来版本可能会提供以下功能。它们被列为“建议的”,但至少在 v 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 
      

      【讨论】:

      • 看起来它不适用于较新的 Clang 版本。
      【解决方案6】:

      也试试

      > 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.
        ...
      

      【讨论】:

      • clang 可用并不意味着 llc 可用。
      • 似乎 llc 通常与 clang 一起安装,但是...如果不是从您的包管理器中安装它,您可以安装它,并且它应该排队,我猜...但是这个列表出现如果您想针对特定的 cpu,不一定是 OP 想要的不同的“三重”架构......
      • 要列出其他架构的选项,您可以使用-mtriple 选项,如llc -mtriple=arm -mattr=help
      • llc: 错误: : 错误: 无法获取“未知”的目标,请参阅--version 和--triple。
      • 使用$ llc --version
      【解决方案7】:

      它不会列出所有的三元组,但是

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

      至少会列出所有的 CPU。

      【讨论】:

      • 这将仅列出可应用于当前(默认)目标的选项。
      • llc: 错误: : 错误: 无法获取“未知”的目标,请参阅--version 和--triple。
      【解决方案8】:

      如果您对从源代码构建 LLVM 或 Clang 支持哪些目标感兴趣(-DLLVM_TARGETS_TO_BUILD 的值),请在源代码分发中的 llvm/lib/Target 文件夹中查找子目录列表。从 9.0.1 开始,有:

      AArch64
      AMDGPU
      ARC
      ARM
      AVR
      BPF
      Hexagon
      Lanai
      MSP430
      Mips
      NVPTX
      PowerPC
      RISCV
      Sparc
      SystemZ
      WebAssembly
      X86
      

      【讨论】:

        【解决方案9】:

        clang -march=dont-know empty.c

        错误:未知目标 CPU '不知道'

        注意:有效的目标 CPU 值为:nocona、core2、penryn、bonnell、atom、silvermont、slm、goldmont、goldmont-plus、tremont、nehalem、corei7、westmere、sandybridge、corei7-avx、ivybridge、core-avx -i、haswell、core-avx2、broadwell、skylake、skylake-avx512、skx、cascadelake、cooperlake、cannonlake、icelake-client、icelake-server、tigerlake、knl、knm、k8、athlon64、athlon-fx、opteron、k8 -sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona,​​ btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, x86-64

        【讨论】:

          【解决方案10】:

          只有第一个(CPU架构)需要准确,其他参数都经过智能复杂的处理,可以使用“clang++ ... --verbose ...”查看处理结果,例如:

          Command Line Input      After triple processing
          x86_64                  x86_64
          x86_64-foo              x86_64-foo
          x86_64-windows          x86_64-unknown-windows-msvc19.28.29335
          x86_64-windows-bar      x86_64-unknown-windows-msvc19.28.29335
          x86_64-foo-windows-bar  x86_64-foo-windows-msvc19.28.29335
          x86_64-foo-bar-foobar   x86_64-foo-bar-foobar
          

          一般除第一个参数外,只有在正确时才会生效(经过三重处理,可能会巧妙地将错误的一个正确正确),例如“windows”会影响代码:

          /// Tests whether the OS is Windows.
          bool isOSWindows() const {
              return getOS() == Triple::Win32;
          }
          

          这个方法被Clang/LLVM中的其他代码用来影响编译结果,它只在参数为“windows”时返回true,如果是“foo”之类的任何其他东西,则返回false。

          【讨论】:

            【解决方案11】:

            对于那些最终到这里来看看他们的特定 x86 CPU 系列架构是否有 llvm/clang 优化目标的人(例如:zen3、zen1、skylake、penryn 等)

            您可以查看下面的列表或运行以下命令:

            $ llc -march=x86 -mattr=help
            Available CPUs for this target:
            
              alderlake      - Select the alderlake processor.
              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.
              barcelona      - Select the barcelona processor.
              bdver1         - Select the bdver1 processor.
              bdver2         - Select the bdver2 processor.
              bdver3         - Select the bdver3 processor.
              bdver4         - Select the bdver4 processor.
              bonnell        - Select the bonnell processor.
              broadwell      - Select the broadwell processor.
              btver1         - Select the btver1 processor.
              btver2         - Select the btver2 processor.
              c3             - Select the c3 processor.
              c3-2           - Select the c3-2 processor.
              cannonlake     - Select the cannonlake processor.
              cascadelake    - Select the cascadelake processor.
              cooperlake     - Select the cooperlake processor.
              core-avx-i     - Select the core-avx-i processor.
              core-avx2      - Select the core-avx2 processor.
              core2          - Select the core2 processor.
              corei7         - Select the corei7 processor.
              corei7-avx     - Select the corei7-avx processor.
              generic        - Select the generic processor.
              geode          - Select the geode processor.
              goldmont       - Select the goldmont processor.
              goldmont-plus  - Select the goldmont-plus processor.
              haswell        - Select the haswell processor.
              i386           - Select the i386 processor.
              i486           - Select the i486 processor.
              i586           - Select the i586 processor.
              i686           - Select the i686 processor.
              icelake-client - Select the icelake-client processor.
              icelake-server - Select the icelake-server processor.
              ivybridge      - Select the ivybridge processor.
              k6             - Select the k6 processor.
              k6-2           - Select the k6-2 processor.
              k6-3           - Select the k6-3 processor.
              k8             - Select the k8 processor.
              k8-sse3        - Select the k8-sse3 processor.
              knl            - Select the knl processor.
              knm            - Select the knm processor.
              lakemont       - Select the lakemont processor.
              nehalem        - Select the nehalem processor.
              nocona         - Select the nocona processor.
              opteron        - Select the opteron processor.
              opteron-sse3   - Select the opteron-sse3 processor.
              penryn         - Select the penryn processor.
              pentium        - Select the pentium processor.
              pentium-m      - Select the pentium-m processor.
              pentium-mmx    - Select the pentium-mmx processor.
              pentium2       - Select the pentium2 processor.
              pentium3       - Select the pentium3 processor.
              pentium3m      - Select the pentium3m processor.
              pentium4       - Select the pentium4 processor.
              pentium4m      - Select the pentium4m processor.
              pentiumpro     - Select the pentiumpro processor.
              prescott       - Select the prescott processor.
              rocketlake     - Select the rocketlake processor.
              sandybridge    - Select the sandybridge processor.
              sapphirerapids - Select the sapphirerapids processor.
              silvermont     - Select the silvermont processor.
              skx            - Select the skx processor.
              skylake        - Select the skylake processor.
              skylake-avx512 - Select the skylake-avx512 processor.
              slm            - Select the slm processor.
              tigerlake      - Select the tigerlake processor.
              tremont        - Select the tremont processor.
              westmere       - Select the westmere processor.
              winchip-c6     - Select the winchip-c6 processor.
              winchip2       - Select the winchip2 processor.
              x86-64         - Select the x86-64 processor.
              x86-64-v2      - Select the x86-64-v2 processor.
              x86-64-v3      - Select the x86-64-v3 processor.
              x86-64-v4      - Select the x86-64-v4 processor.
              yonah          - Select the yonah processor.
              znver1         - Select the znver1 processor.
              znver2         - Select the znver2 processor.
              znver3         - Select the znver3 processor.
            

            以上列表是 llvm-13 的最新列表

            要运行上述程序,您至少需要安装 llvm,并且要获得与上述相同的结果,您至少需要 llvm-13。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2012-12-06
              • 2013-05-01
              • 2014-01-02
              • 1970-01-01
              • 2013-12-10
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多