118

現在、私は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など)のように、すべてに個別のバイナリを用意する必要があります。http ://git.savannah.gnu.org/cgit/libtool.git/tree/doc/PLATFORMS

clangの世界では、これは1つのバイナリのみです(いくつかのフォーラムで読んだように)。しかし、サポートされているターゲットのリストを取得するにはどうすればよいですか?また、ターゲットがディストリビューション(linux / windows / macos / whatever)でサポートされていない場合、より多くのプラットフォームをサポートするターゲットを取得するにはどうすればよいですか?

I SVNの最新のclangが次のようになっている場合:

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

ほとんどのプラットフォームを入手できますか?Clangはすぐにクロスコンパイルを念頭に置いて構築されていないようですが、llvmベースなので、理論的には非常にクロスフレンドリーなはずですか?ありがとう!

4

11 に答える 11

68

私の知る限り、特定のclangバイナリがサポートするアーキテクチャを一覧表示するコマンドラインオプションはなく、その上で実行stringsしても実際には役に立ちません。Clangは本質的にCからLLVMへのトランスレーターであり、実際のマシンコードを生成するための要点を処理するのはLLVM自体であるため、Clangが基盤となるアーキテクチャーにあまり注意を払っていないことはまったく驚くべきことではありません。

他の人がすでに述べたように、あなたはそれがllcどのアーキテクチャをサポートしているかを尋ねることができます。これは、これらのLLVMコンポーネントがインストールされていない可能性があるだけでなく、検索パスとパッケージングシステムの変動により、ユーザーllcclangバイナリが同じバージョンのLLVMに対応していない可能性があるため、それほど役に立ちません。

ただし、議論のために、LLVMとClangの両方を自分でコンパイルした、またはLLVMバイナリを十分に受け入れて満足しているとしましょう。

  • llc --versionサポートされているすべてのアーキテクチャのリストが表示されます。デフォルトでは、すべてのアーキテクチャをサポートするようにコンパイルされています。ARMなどの単一のアーキテクチャと考えると、通常のARM、Thumb、AArch64などのLLVMアーキテクチャがいくつかある場合があります。実行モードが異なれば命令のエンコーディングとセマンティクスも大きく異なるため、これは主に実装の便宜のためです。
  • リストされているアーキテクチャごとに、llc -march=ARCH -mattr=help「使用可能なCPU」と「使用可能な機能」がリストされます。CPUは通常、デフォルトの機能コレクションを設定するための便利な方法です。

しかし、今は悪いニュースです。llvm::Tripleアーキテクチャ固有のバックエンドにはトリプル文字列をオブジェクトに解析するオプションがあるため(include / llvm / ADT / Triple.hで定義) 、ダンプできるClangまたはLLVMのトリプルの便利なテーブルはありません。言い換えれば、利用可能なすべてのトリプルをダンプするには、停止性問題を解く必要があります。たとえば、llvm::ARM_MC::ParseARMTriple(...)文字列を解析する特殊なケースを参照してください"generic"

ただし、最終的には、「トリプル」はほとんどの場合、ClangをGCCのドロップイン代替品にするための下位互換性機能であるため、ClangまたはLLVMを新しいプラットフォームに移植する場合を除いて、通常はあまり注意を払う必要はありません。またはアーキテクチャ。llc -march=arm -mattr=help代わりに、さまざまなARM機能の膨大な配列の出力と混乱が調査に役立つことがわかるでしょう。

あなたの研究で頑張ってください!

于 2016-01-28T12:46:05.417 に答える
38

私はClang3.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に関するsthがあります。

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);
}
于 2013-09-02T15:12:25.453 に答える
23
于 2016-11-30T14:00:42.970 に答える
16

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 commitClang11ドキュメント

于 2020-06-30T05:04:38.050 に答える
14
于 2016-08-24T05:00:41.203 に答える
7

また、試してみてください

> 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.
  ...
于 2014-01-28T15:43:03.563 に答える
3

すべてのトリプルがリストされるわけではありませんが、

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

少なくともすべてのCPUを一覧表示します。

于 2013-06-20T04:27:51.503 に答える
3

clang -march=dont-know empty.c

エラー:不明なターゲットCPU'not-know'

注:有効なターゲット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

于 2020-11-18T05:58:07.963 に答える
2

ソースからLLVMまたはClangを構築するためにサポートされているターゲット(の値)に関心がある場合は、ソース配布-DLLVM_TARGETS_TO_BUILDのフォルダー内のサブディレクトリーのリストを探してください。llvm/lib/Target9.0.1の時点で、次のものがあります。

AArch64
AMDGPU
ARC
ARM
AVR
BPF
Hexagon
Lanai
MSP430
Mips
NVPTX
PowerPC
RISCV
Sparc
SystemZ
WebAssembly
X86
于 2020-02-29T18:07:56.230 に答える
0

最初のもの(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

一般に、最初のパラメーターを除くパラメーターは、正しい場合にのみ有効になります(3つの処理プロセスの後、間違ったパラメーターを賢く作成する可能性があります)。たとえば、「windows」はコードに影響します。

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

このメソッドは、コンパイルされた結果に影響を与えるためにClang / LLVMの他のコードによって使用され、パラメーターが「windows」の場合にのみtrueを返し、「foo」などの他のものの場合はfalseを返します。

于 2021-04-03T08:37:04.673 に答える
0

特定のx86CPUファミリーアーキテクチャに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が必要です。

于 2021-10-23T05:17:39.193 に答える