系列文章目录
LLVM系列第一章:编译LLVM源码
LLVM系列第二章:模块Module
LLVM系列第三章:函数Function
LLVM系列第四章:逻辑代码块Block
LLVM系列第五章:全局变量Global Variable
LLVM系列第六章:函数返回值Return
LLVM系列第七章:函数参数Function Arguments
LLVM系列第八章:算术运算语句Arithmetic Statement
LLVM系列第九章:控制流语句if-else
LLVM系列第十章:控制流语句if-else-phi
LLVM系列第十一章:写一个Hello World
LLVM系列第十二章:写一个简单的词法分析器Lexer
LLVM系列第十三章:写一个简单的语法分析器Parser
LLVM系列第十四章:写一个简单的语义分析器Semantic Analyzer
LLVM系列第十五章:写一个简单的中间代码生成器IR Generator
LLVM系列第十六章:写一个简单的编译器
LLVM系列第十七章:for循环
LLVM系列第十八章:写一个简单的IR处理流程Pass
LLVM系列第十九章:写一个简单的Module Pass
LLVM系列第二十章:写一个简单的Function Pass
LLVM系列第二十一章:写一个简单的Loop Pass
LLVM系列第二十二章:写一个简单的编译时函数调用统计器(Pass)
LLVM系列第二十三章:写一个简单的运行时函数调用统计器(Pass)
LLVM系列第二十四章:用Xcode编译调试LLVM源码
LLVM系列第二十五章:简单统计一下LLVM源码行数
LLVM系列第二十六章:理解LLVMContext
LLVM系列第二十七章:理解IRBuilder
LLVM系列第二十八章:写一个JIT Hello World
LLVM系列第二十九章:写一个简单的常量加法“消除”工具(Pass)
flex&bison系列
LLVM是一个著名的开源编译器项目、库、工具,在此记录下编译LLVM源码的过程,以备查阅。
我用的操作系统是macOS 11.6.4:
System Version: macOS 11.6.4 (20G417)
Kernel Version: Darwin 20.6.0
Model Name: MacBook Pro
Model Identifier: MacBookPro15,1
Processor Name: 8-Core Intel Core i9
Processor Speed: 2.3 GHz
Number of Processors: 1
Total Number of Cores: 8
Memory: 16 GB
用到的工具有Clang (Xcode)、Git、CMake以及Ninja。
关于安装Xcode, 可参考这个简易教程:
How to download Xcode DMG or XIP file? - Stack Overflow
安装后确认信息如下(示例):
% clang -v
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
对于其它工具,可借助brew (https://brew.sh) 进行安装(示例):
brew install git cmake ninja
安装后确认信息如下(示例):
% brew list --version git cmake ninja
cmake 3.22.1
git 2.32.0
ninja 1.10.2_1
使用命令如下(示例):
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout -b llvmorg-12.0.0
确认branch的信息如下(示例):
% git branch
* llvmorg-12.0.0
main
我们可使用工具CMake和Ninja来编译LLVM源代码。
使用命令如下(示例):
cd llvm-project
mkdir build
cd build
# Compile clang as well
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS=clang ../llvm
# Or, don't compile clang
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../llvm
输出log如下(示例):
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- The ASM compiler identification is Clang with GNU-like command-line
-- Found assembler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features - done
-- No build type selected, default to Debug
-- clang project is enabled
-- clang-tools-extra project is disabled
-- compiler-rt project is disabled
-- debuginfo-tests project is disabled
-- libc project is disabled
-- libclc project is disabled
-- libcxx project is disabled
-- libcxxabi project is disabled
-- libunwind project is disabled
-- lld project is disabled
-- lldb project is disabled
-- mlir project is disabled
-- openmp project is disabled
-- parallel-libs project is disabled
-- polly project is disabled
-- pstl project is disabled
-- flang project is disabled
-- Found libtool - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool
-- Looking for dlfcn.h - found
-- Looking for errno.h - found
-- Looking for fcntl.h - found
-- Looking for link.h - not found
-- Looking for malloc/malloc.h - found
-- Looking for pthread.h - found
-- Looking for signal.h - found
-- Looking for sys/ioctl.h - found
-- Looking for sys/mman.h - found
-- Looking for sys/param.h - found
-- Looking for sys/resource.h - found
-- Looking for sys/stat.h - found
-- Looking for sys/time.h - found
-- Looking for sys/types.h - found
-- Looking for sysexits.h - found
-- Looking for termios.h - found
-- Looking for unistd.h - found
-- Looking for valgrind/valgrind.h - not found
-- Looking for fenv.h - found
-- Looking for FE_ALL_EXCEPT - found
-- Looking for FE_INEXACT - found
-- Looking for mach/mach.h - found
-- Looking for histedit.h - found
-- Looking for CrashReporterClient.h - not found
-- Performing Test HAVE_CRASHREPORTER_INFO - Success
-- Looking for pthread_create in pthread - found
-- Looking for pthread_getspecific in pthread - found
-- Looking for pthread_rwlock_init in pthread - found
-- Looking for pthread_mutex_lock in pthread - found
-- Looking for dlopen in dl - found
-- Looking for clock_gettime in rt - not found
-- Looking for pfm_initialize in pfm - not found
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found ZLIB: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libz.tbd (found version "1.2.11")
-- Looking for compress2 - found
-- Found LibXml2: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libxml2.tbd (found version "2.9.4")
-- Looking for xmlReadMemory - found
-- Looking for el_init in edit - found
-- Looking for xar_open in xar - found
-- Looking for arc4random - found
-- Looking for backtrace - found
-- backtrace facility detected in default set of libraries
-- Found Backtrace: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include
-- Performing Test C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Success
-- Looking for __register_frame - found
-- Looking for __deregister_frame - found
-- Looking for _Unwind_Backtrace - found
-- Looking for getpagesize - found
-- Looking for sysconf - found
-- Looking for getrusage - found
-- Looking for setrlimit - found
-- Looking for isatty - found
-- Looking for futimens - found
-- Looking for futimes - found
-- Looking for posix_fallocate - not found
-- Looking for lseek64 - not found
-- Looking for mallctl - not found
-- Looking for mallinfo - not found
-- Looking for malloc_zone_statistics - found
-- Looking for getrlimit - found
-- Looking for posix_spawn - found
-- Looking for pread - found
-- Looking for sbrk - found
-- Looking for strerror - found
-- Looking for strerror_r - found
-- Looking for strerror_s - not found
-- Looking for setenv - found
-- Looking for dlopen - found
-- Looking for dladdr - found
-- Performing Test HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - Success
-- Performing Test HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - Failed
-- Looking for __GLIBC__ - not found
-- Looking for pthread_getname_np - found
-- Looking for pthread_setname_np - found
-- Performing Test HAVE_STD_IS_TRIVIALLY_COPYABLE - Success
-- Performing Test HAVE_CXX_ATOMICS_WITHOUT_LIB - Success
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB - Success
-- Performing Test LLVM_HAS_ATOMICS - Success
-- Performing Test SUPPORTS_VARIADIC_MACROS_FLAG - Success
-- Performing Test SUPPORTS_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS_FLAG - Success
-- Native target architecture is X86
-- Threads enabled.
-- Doxygen disabled.
-- Go bindings enabled.
-- Ninja version: 1.10.2
-- Found ld64 - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH)
-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH)
-- OCaml bindings disabled.
-- Could NOT find Python module pygments
-- Could NOT find Python module pygments.lexers.c_cpp
-- Could NOT find Python module yaml
-- LLVM host triple: x86_64-apple-darwin20.6.0
-- LLVM default target triple: x86_64-apple-darwin20.6.0
-- Performing Test C_SUPPORTS_FPIC - Success
-- Performing Test CXX_SUPPORTS_FPIC - Success
-- Building with -fPIC
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success
-- Performing Test C_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test CXX_SUPPORTS_WERROR_DATE_TIME - Success
-- Performing Test CXX_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW - Success
-- Performing Test CXX_SUPPORTS_MISSING_FIELD_INITIALIZERS_FLAG - Success
-- Performing Test C_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Success
-- Performing Test CXX_SUPPORTS_IMPLICIT_FALLTHROUGH_FLAG - Success
-- Performing Test C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Success
-- Performing Test CXX_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG - Success
-- Performing Test CXX_SUPPORTS_CLASS_MEMACCESS_FLAG - Failed
-- Performing Test CXX_SUPPORTS_NOEXCEPT_TYPE_FLAG - Success
-- Performing Test CXX_WONT_WARN_ON_FINAL_NONVIRTUALDTOR - Success
-- Performing Test C_SUPPORTS_DELETE_NON_VIRTUAL_DTOR_FLAG - Success
-- Performing Test CXX_SUPPORTS_DELETE_NON_VIRTUAL_DTOR_FLAG - Success
-- Performing Test CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG - Success
-- Performing Test CXX_WSUGGEST_OVERRIDE_ALLOWS_ONLY_FINAL - Success
-- Performing Test C_WCOMMENT_ALLOWS_LINE_WRAP - Success
-- Performing Test C_SUPPORTS_STRING_CONVERSION_FLAG - Success
-- Performing Test CXX_SUPPORTS_STRING_CONVERSION_FLAG - Success
-- Performing Test LINKER_SUPPORTS_COLOR_DIAGNOSTICS - Failed
-- Looking for os_signpost_interval_begin - found
-- Performing Test macos_signposts_usable - Success
-- Found Python3: /usr/local/Frameworks/Python.framework/Versions/3.9/bin/python3.9 (found version "3.9.6") found components: Interpreter
-- Linker detection: ld64
-- Found Git: /usr/local/bin/git (found version "2.32.0")
-- Targeting AArch64
-- Targeting AMDGPU
-- Targeting ARM
-- Targeting AVR
-- Targeting BPF
-- Targeting Hexagon
-- Targeting Lanai
-- Targeting Mips
-- Targeting MSP430
-- Targeting NVPTX
-- Targeting PowerPC
-- Targeting RISCV
-- Targeting Sparc
-- Targeting SystemZ
-- Targeting WebAssembly
-- Targeting X86
-- Targeting XCore
-- Looking for sys/resource.h - found
-- Clang version: 12.0.1
-- Performing Test CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG - Success
-- Host linker version: 711
-- Looking for include file CoreServices/CoreServices.h - found
-- Registering Bye as a pass plugin (static build: OFF)
-- Failed to find LLVM FileCheck
-- Version: 0.0.0
-- Performing Test HAVE_CXX_FLAG_STD_CXX11 - Success
-- Performing Test HAVE_CXX_FLAG_WALL - Success
-- Performing Test HAVE_CXX_FLAG_WEXTRA - Success
-- Performing Test HAVE_CXX_FLAG_WSHADOW - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC - Success
-- Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS - Success
-- Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32 - Success
-- Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL - Success
-- Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_FNO_EXCEPTIONS - Success
-- Performing Test HAVE_CXX_FLAG_WNO_SUGGEST_OVERRIDE - Success
-- Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING - Success
-- Performing Test HAVE_CXX_FLAG_WD654 - Failed
-- Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY - Success
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES -- failed to compile
-- Performing Test HAVE_CXX_FLAG_COVERAGE - Success
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/wuzhanglin/Sources/OpenSource/compiler/llvm-project/build
使用命令如下(示例):
ninja
整个编译过程大约需要30至60分钟。输出log如下(示例):
...
[164/3972] Building CXX object lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/BranchFolding.cpp.o
...
[3808/3808] Linking CXX executable bin/llvm-lto2
编译完成后,我们可以测试一下,确保一切正常(示例):
ninja check-all
整个测试过程大约需要一个小时。输出log如下(示例):
[390/704] cd .../llvm-project/clang/...al/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -m unittest discover
..............................................................................................................................
----------------------------------------------------------------------
Ran 126 tests in 21.427s
OK
[703/704] Running all regression tests
llvm-lit: .../llvm-project/llvm/utils/lit/lit/llvm/config.py:385: note: using clang: .../llvm-project/build/bin/clang
llvm-lit: .../llvm-project/llvm/utils/lit/lit/util.py:399: note: using SDKROOT: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk'
llvm-lit: .../llvm-project/build/utils/lit/tests/lit.cfg:79: warning: Setting a timeout per test not supported. Requires the Python psutil module but it could not be found. Try installing it via pip or via your operating system's package manager. Some tests will be skipped and the --timeout command line argument will not work.
FAIL: LLVM :: Bindings/Go/go.test (34351 of 69399)
******************** TEST 'LLVM :: Bindings/Go/go.test' FAILED ********************
Script:
--
: 'RUN: at line 1'; .../llvm-project/build/bin/llvm-go go=/usr/local/go/bin/go test llvm.org/llvm/bindings/go/llvm
--
Exit Code: 1
Command Output (stdout):
--
FAIL llvm.org/llvm/bindings/go/llvm [build failed]
FAIL
--
Command Output (stderr):
--
# runtime/cgo
_cgo_export.c:3:10: fatal error: 'stdlib.h' file not found
--
********************
FAIL: LLVM :: tools/lto/no-bitcode.s (69143 of 69399)
******************** TEST 'LLVM :: tools/lto/no-bitcode.s' FAILED ********************
Script:
--
: 'RUN: at line 3'; .../llvm-project/build/bin/llvm-mc -triple=arm64-apple-ios7.0.0 -filetype=obj -o .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.o
: 'RUN: at line 4'; .../llvm-project/build/bin/llvm-ar r .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.a .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.o
: 'RUN: at line 5'; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -lto_library .../llvm-project/build/test/../lib/libLTO.dylib -arch x86_64 -dylib -mllvm -O0 -o .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.dylib .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.a
--
Exit Code: 1
Command Output (stderr):
--
.../llvm-project/build/bin/llvm-ar: warning: creating .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.a
ld: warning: platform not specified
ld: warning: No platform min-version specified on command line
ld: warning: ignoring file .../llvm-project/build/test/tools/lto/Output/no-bitcode.s.tmp.a, building for -x86_64 but attempting to link with file built for iOS-arm64
ld: dynamic main executables must link with libSystem.dylib for architecture x86_64
--
********************
FAIL: LLVM :: tools/lto/opt-level.ll (69226 of 69399)
******************** TEST 'LLVM :: tools/lto/opt-level.ll' FAILED ********************
Script:
--
: 'RUN: at line 1'; .../llvm-project/build/bin/llvm-as .../llvm-project/llvm/test/tools/lto/opt-level.ll -o .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.o
: 'RUN: at line 2'; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -lto_library .../llvm-project/build/test/../lib/libLTO.dylib -arch x86_64 -dylib -mllvm -O0 -o .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.dylib .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.o
: 'RUN: at line 3'; .../llvm-project/build/bin/llvm-nm --no-llvm-bc .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.dylib | .../llvm-project/build/bin/FileCheck --allow-unused-prefixes=false --check-prefix=CHECK-O0 .../llvm-project/llvm/test/tools/lto/opt-level.ll
: 'RUN: at line 4'; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -lto_library .../llvm-project/build/test/../lib/libLTO.dylib -arch x86_64 -dylib -mllvm -O2 -o .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.dylib .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.o
: 'RUN: at line 5'; .../llvm-project/build/bin/llvm-nm --no-llvm-bc .../llvm-project/build/test/tools/lto/Output/opt-level.ll.tmp.dylib | .../llvm-project/build/bin/FileCheck --allow-unused-prefixes=false --check-prefix=CHECK-O2 .../llvm-project/llvm/test/tools/lto/opt-level.ll
--
Exit Code: 1
Command Output (stderr):
--
ld: warning: platform not specified
ld: warning: No platform min-version specified on command line
ld: dynamic main executables must link with libSystem.dylib for architecture x86_64
--
********************
FAIL: LLVM :: tools/lto/print-stats.ll (69227 of 69399)
******************** TEST 'LLVM :: tools/lto/print-stats.ll' FAILED ********************
Script:
--
: 'RUN: at line 1'; .../llvm-project/build/bin/llvm-as .../llvm-project/llvm/test/tools/lto/print-stats.ll -o .../llvm-project/build/test/tools/lto/Output/print-stats.ll.tmp.o
: 'RUN: at line 2'; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -lto_library .../llvm-project/build/test/../lib/libLTO.dylib -arch x86_64 -dylib -mllvm -stats -o .../llvm-project/build/test/tools/lto/Output/print-stats.ll.tmp.dylib .../llvm-project/build/test/tools/lto/Output/print-stats.ll.tmp.o 2>&1 | .../llvm-project/build/bin/FileCheck --allow-unused-prefixes=false --check-prefix=STATS .../llvm-project/llvm/test/tools/lto/print-stats.ll
: 'RUN: at line 3'; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -lto_library .../llvm-project/build/test/../lib/libLTO.dylib -arch x86_64 -dylib -o .../llvm-project/build/test/tools/lto/Output/print-stats.ll.tmp.dylib .../llvm-project/build/test/tools/lto/Output/print-stats.ll.tmp.o 2>&1 | .../llvm-project/build/bin/FileCheck --allow-unused-prefixes=false --check-prefix=NO_STATS .../llvm-project/llvm/test/tools/lto/print-stats.ll
--
Exit Code: 1
********************
FAIL: LLVM :: tools/lto/hide-linkonce-odr.ll (69229 of 69399)
******************** TEST 'LLVM :: tools/lto/hide-linkonce-odr.ll' FAILED ********************
Script:
--
: 'RUN: at line 1'; .../llvm-project/build/bin/llvm-as .../llvm-project/llvm/test/tools/lto/hide-linkonce-odr.ll -o .../llvm-project/build/test/tools/lto/Output/hide-linkonce-odr.ll.tmp.o
: 'RUN: at line 2'; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -lto_library .../llvm-project/build/test/../lib/libLTO.dylib -dylib -arch x86_64 -macosx_version_min 10.10.0 -o .../llvm-project/build/test/tools/lto/Output/hide-linkonce-odr.ll.tmp.dylib .../llvm-project/build/test/tools/lto/Output/hide-linkonce-odr.ll.tmp.o -save-temps -undefined dynamic_lookup -exported_symbol _c -exported_symbol _b -exported_symbol _GlobLinkonce
: 'RUN: at line 4'; .../llvm-project/build/bin/llvm-dis .../llvm-project/build/test/tools/lto/Output/hide-linkonce-odr.ll.tmp.dylib.lto.opt.bc -o - | .../llvm-project/build/bin/FileCheck --allow-unused-prefixes=false --check-prefix=IR .../llvm-project/llvm/test/tools/lto/hide-linkonce-odr.ll
: 'RUN: at line 10'; .../llvm-project/build/bin/llvm-nm .../llvm-project/build/test/tools/lto/Output/hide-linkonce-odr.ll.tmp.dylib | .../llvm-project/build/bin/FileCheck --allow-unused-prefixes=false --check-prefix=NM .../llvm-project/llvm/test/tools/lto/hide-linkonce-odr.ll
--
Exit Code: 1
Command Output (stderr):
--
ld: dynamic main executables must link with libSystem.dylib for architecture x86_64
--
********************
********************
Failed Tests (5):
LLVM :: Bindings/Go/go.test
LLVM :: tools/lto/hide-linkonce-odr.ll
LLVM :: tools/lto/no-bitcode.s
LLVM :: tools/lto/opt-level.ll
LLVM :: tools/lto/print-stats.ll
Testing Time: 4120.19s
Unsupported : 718
Passed : 68490
Expectedly Failed: 186
Failed : 5
1 warning(s) in tests
FAILED: CMakeFiles/check-all .../llvm-project/build/CMakeFiles/check-all
cd .../llvm-project/build && /usr/local/Frameworks/Python.framework/Versions/3.9/bin/python3.9 .../llvm-project/build/./bin/llvm-lit -sv --param USE_Z3_SOLVER=0 .../llvm-project/build/tools/clang/test .../llvm-project/build/utils/lit .../llvm-project/build/test
ninja: build stopped: subcommand failed.
有少量测试错误,但目前对我们使用LLVM没有影响。
我们可以简单试用一下LLVM的llc工具,进一步确保一切正常。使用命令如下(示例):
./bin/llc --version
输出log如下(示例):
LLVM (http://llvm.org/):
LLVM version 12.0.1
DEBUG build with assertions.
Default target: x86_64-apple-darwin20.6.0
Host CPU: skylake
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
ppc32le - PowerPC 32 LE
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
使用命令如下(示例):
sudo ninja install
(注意如果不用sudo
的话,可能会因为文件访问权限问题,而导致安装失败。)
这样就把LLVM安装到了/usr/local
目录下,输出log如下(示例):
[0/1] Install the project...
-- Install configuration: "Debug"
-- Installing: /usr/local/include/llvm
...
...
...
-- Installing: /usr/local/lib/cmake/llvm/./CheckLinkerFlag.cmake
我们快速地测试一下,确保安装成功。使用命令如下(示例):
which llc; llc --version
输出log如下(示例):
/usr/local/bin/llc
LLVM (http://llvm.org/):
LLVM version 12.0.1
DEBUG build with assertions.
Default target: x86_64-apple-darwin20.6.0
Host CPU: skylake
Registered Targets:
aarch64 - AArch64 (little endian)
...
...
x86-64 - 64-bit X86: EM64T and AMD64
xcore - XCore
跟上一步的log是一样的。
我们利用Git下载了LLVM的源代码,用CMake和Ninja工具编译并安装了LLVM,最后还简单地试用了一下LLVM工具库中的llc工具。