源码编译llvm
下载源码
yeqiang@yeqiang-MS-7B23:~/Downloads/src$ git clone --depth=1 -b 7cbf1a2 https://github.com/llvm/llvm-project
正克隆到 'llvm-project'...
warning: 不能发现要克隆的远程分支 7cbf1a2。
fatal: 远程分支 7cbf1a2 在上游 origin 未发现
yeqiang@yeqiang-MS-7B23:~/Downloads/src$ git clone --depth=1 -b llvmorg-16.0.6 https://github.com/llvm/llvm-project
正克隆到 'llvm-project'...
remote: Enumerating objects: 132947, done.
remote: Counting objects: 100% (132947/132947), done.
remote: Compressing objects: 100% (107072/107072), done.
remote: Total 132947 (delta 28313), reused 67422 (delta 21784), pack-reused 0
接收对象中: 100% (132947/132947), 187.34 MiB | 961.00 KiB/s, 完成.
处理 delta 中: 100% (28313/28313), 完成.
注意:正在切换到 '7cbf1a2591520c2491aa35339f227775f4d3adf6'。
您正处于分离头指针状态。您可以查看、做试验性的修改及提交,并且您可以在切换
回一个分支时,丢弃在此状态下所做的提交而不对分支造成影响。
如果您想要通过创建分支来保留在此状态下所做的提交,您可以通过在 switch 命令
中添加参数 -c 来实现(现在或稍后)。例如:
git switch -c <新分支名>
或者撤销此操作:
git switch -
通过将配置变量 advice.detachedHead 设置为 false 来关闭此建议
正在更新文件: 100% (126307/126307), 完成.
编译安装llvm
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project$ mkdir build
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project$ cd build/
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project/build$ cmake ../llvm -DCMAKE_BUILD_TYPE=Release
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project/build$ make -j4
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project/build$ sudo make install
编译安装clang
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project$ mkdir build-clang
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project$ cd build-clang/
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project/build-clang$ cmake ../clang
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project/build-clang$ make -j6
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project/build-clang$ sudo make install
编译安装openmp
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project$ mkdir build-openmp
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project$ cd build-openmp/
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project/build-openmp$ cmake ../openmp/
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project/build-openmp$ make -j6
yeqiang@yeqiang-MS-7B23:~/Downloads/src/llvm-project/build-openmp$ sudo make install
x86_64 编译intrate,intspeed
gcc-llvm-intrate-intspeed.patch 内容
*** Example-gcc-linux-x86.cfg Fri May 4 20:53:19 2018
--- gcc-llvm.cfg Wed Jul 26 15:43:37 2023
*************** default:
*** 145,153 ****
preENV_LD_LIBRARY_PATH = %{gcc_dir}/lib64/:%{gcc_dir}/lib/:/lib64
#preENV_LD_LIBRARY_PATH = %{gcc_dir}/lib64/:%{gcc_dir}/lib/:/lib64:%{ENV_LD_LIBRARY_PATH}
SPECLANG = %{gcc_dir}/bin/
! CC = $(SPECLANG)gcc -std=c99 %{model}
! CXX = $(SPECLANG)g++ -std=c++03 %{model}
! FC = $(SPECLANG)gfortran %{model}
# How to say "Show me your version, please"
CC_VERSION_OPTION = -v
CXX_VERSION_OPTION = -v
--- 145,153 ----
preENV_LD_LIBRARY_PATH = %{gcc_dir}/lib64/:%{gcc_dir}/lib/:/lib64
#preENV_LD_LIBRARY_PATH = %{gcc_dir}/lib64/:%{gcc_dir}/lib/:/lib64:%{ENV_LD_LIBRARY_PATH}
SPECLANG = %{gcc_dir}/bin/
! CC = /usr/local/bin/clang %{model}
! CXX = /usr/local/bin/clang++ %{model}
! FC = gfortran %{model}
# How to say "Show me your version, please"
CC_VERSION_OPTION = -v
CXX_VERSION_OPTION = -v
*************** default: # data model appl
*** 184,193 ****
--- 184,201 ----
%endif
PORTABILITY = -DSPEC_%{os}_%{suffix}
+ # lex.expryy.cc:816:2: error: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
+ 520.omnetpp_r:
+ CXXPORTABILITY = -Wno-error=register
+
521.wrf_r,621.wrf_s: #lang='F,C'
CPORTABILITY = -DSPEC_CASE_FLAG
FPORTABILITY = -fconvert=big-endian
+ # process *** Error building 525.x264_r base
+ 525.x264_r:
+ CPORTABILITY = -fcommon
+
523.xalancbmk_r,623.xalancbmk_s: #lang='CXX'
PORTABILITY = -DSPEC_%{os}
*************** default: # data model appl
*** 197,206 ****
--- 205,232 ----
527.cam4_r,627.cam4_s: #lang='F,C'
PORTABILITY = -DSPEC_CASE_FLAG
+ # *** Error building 620.omnetpp_s base
+ 620.omnetpp_s:
+ CXXPORTABILITY = -Wno-error=register
+
+ # *** Error building 625.x264_s base, /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x22
+ 625.x264_s:
+ PORTABILITY = -fcommon
+
628.pop2_s: #lang='F,C'
CPORTABILITY = -DSPEC_CASE_FLAG
FPORTABILITY = -fconvert=big-endian
+ # Build errors for fprate: 521.wrf_r(base; CE), 527.cam4_r(base; CE) Error: Type mismatch between actual argument
+ 521.wrf_r:
+ FPORTABILITY = -fallow-argument-mismatch
+ 527.cam4_r:
+ FPORTABILITY = -fallow-argument-mismatch
+ # 526.blender_r(base; CE) error: call to undeclared function 'kill'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
+ # error: unknown type name 'mode_t'; did you mean '__mode_t'
+ 526.blender_r:
+ PORTABILITY = -Wno-error,-Wno-sign-conversion -Wno-sign-conversion -Wno-constant-conversion-Wno-implicit-function-declaration -Wno-int-conversion
+
#-------- Tuning Flags common to Base and Peak --------------------------------
*************** default: # data model appl
*** 234,240 ****
# switches here. See also 'About the -fno switches' below.
#
default=base: # flags for all base
! OPTIMIZE = -g -O3 -march=native -fno-unsafe-math-optimizations -fno-tree-loop-vectorize
intrate,intspeed=base: # flags for integer base
EXTRA_COPTIMIZE = -fno-strict-aliasing -fgnu89-inline
--- 260,266 ----
# switches here. See also 'About the -fno switches' below.
#
default=base: # flags for all base
! OPTIMIZE = -g -O3 -march=native -fno-unsafe-math-optimizations
intrate,intspeed=base: # flags for integer base
EXTRA_COPTIMIZE = -fno-strict-aliasing -fgnu89-inline
打补丁,编译
cd /opt/cpu2017/
cd config
cp Example-gcc-linux-x86.cfg gcc-llvm.cfg
patch -p0 < ../gcc-llvm-intrate-intspeed.patch
cd /opt/cpu2017
runcpu -c gcc-llvm.cfg --action build intrate intspeed
编译成功日志
root@yeqiang-MS-7B23:/opt/cpu2017/config# cd /opt/cpu2017/
root@yeqiang-MS-7B23:/opt/cpu2017# source shrc
root@yeqiang-MS-7B23:/opt/cpu2017# runcpu -c gcc-llvm.cfg --action build intrate intspeed
SPEC CPU(r) 2017 Benchmark Suites
Copyright 1995-2017 Standard Performance Evaluation Corporation (SPEC)
runcpu v5825
Using 'linux-x86_64' tools
Reading file manifests... read 32272 entries from 2 files in 0.08s (403885 files/s)
Loading runcpu modules.................
Locating benchmarks...found 47 benchmarks in 53 benchsets.
Reading config file '/opt/cpu2017/config/gcc-llvm.cfg'
2 configurations selected:
Action Benchmarks
------ ----------------------------------------------------------------------
build intrate
build intspeed
-------------------------------------------------------------------------------
Setting up environment for running intrate...
Starting runcpu for intrate...
Running "specperl /opt/cpu2017/bin/sysinfo" to gather system information.
sysinfo: r5974 of 2018-05-19 (9bcde8f2999c33d61f64985e45859ea9)
sysinfo: Getting system information for Linux...
sysinfo: ...getting CPU info
sysinfo: ...getting info from numactl
sysinfo: ...getting memory info
sysinfo: ...getting OS info
sysinfo: ...getting CPU vulnerability status from the kernel
sysinfo: ...getting disk info
sysinfo: ...trying to get DIMM info from dmidecode
Retrieving flags file (/opt/cpu2017/config/flags/gcc.xml)...
Benchmarks selected: 500.perlbench_r, 502.gcc_r, 505.mcf_r, 520.omnetpp_r, 523.xalancbmk_r, 525.x264_r, 531.deepsjeng_r, 541.leela_r, 548.exchange2_r, 557.xz_r, 999.specrand_ir
Compiling Binaries
Building 500.perlbench_r base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 15:45:24]
Building 502.gcc_r base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 15:46:03]
Building 505.mcf_r base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 15:50:02]
Building 520.omnetpp_r base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 15:50:04]
Building 523.xalancbmk_r base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 15:55:30]
Building 525.x264_r base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:07:21]
Building 531.deepsjeng_r base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:07:46]
Building 541.leela_r base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:07:55]
Building 548.exchange2_r base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:08:38]
Building 557.xz_r base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:08:47]
Building 999.specrand_ir base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:08:53]
Build successes for intrate: 500.perlbench_r(base), 502.gcc_r(base), 505.mcf_r(base), 520.omnetpp_r(base), 523.xalancbmk_r(base), 525.x264_r(base), 531.deepsjeng_r(base), 541.leela_r(base), 548.exchange2_r(base), 557.xz_r(base), 999.specrand_ir(base)
Build errors for intrate: None
Build Complete
-------------------------------------------------------------------------------
Setting up environment for running intspeed...
Starting runcpu for intspeed...
Running "specperl /opt/cpu2017/bin/sysinfo" to gather system information.
sysinfo: r5974 of 2018-05-19 (9bcde8f2999c33d61f64985e45859ea9)
sysinfo: Getting system information for Linux...
sysinfo: ...getting CPU info
sysinfo: ...getting info from numactl
sysinfo: ...getting memory info
sysinfo: ...getting OS info
sysinfo: ...getting CPU vulnerability status from the kernel
sysinfo: ...getting disk info
sysinfo: ...trying to get DIMM info from dmidecode
Retrieving flags file (/opt/cpu2017/config/flags/gcc.xml)...
Benchmarks selected: 600.perlbench_s, 602.gcc_s, 605.mcf_s, 620.omnetpp_s, 623.xalancbmk_s, 625.x264_s, 631.deepsjeng_s, 641.leela_s, 648.exchange2_s, 657.xz_s, 998.specrand_is
Compiling Binaries
Building 600.perlbench_s base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:08:55]
Building 602.gcc_s base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:09:35]
Building 605.mcf_s base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:13:38]
Building 620.omnetpp_s base mytest-m64: (build_base_mytest-m64.0001) [2023-07-26 16:13:40]
Building 623.xalancbmk_s base mytest-m64: (build_base_mytest-m64.0001) [2023-07-26 16:19:12]
Building 625.x264_s base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:30:56]
Building 631.deepsjeng_s base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:31:20]
Building 641.leela_s base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:31:29]
Building 648.exchange2_s base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:32:11]
Building 657.xz_s base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:32:20]
Building 998.specrand_is base mytest-m64: (build_base_mytest-m64.0000) [2023-07-26 16:32:26]
Build successes for intspeed: 600.perlbench_s(base), 602.gcc_s(base), 605.mcf_s(base), 620.omnetpp_s(base), 623.xalancbmk_s(base), 625.x264_s(base), 631.deepsjeng_s(base), 641.leela_s(base), 648.exchange2_s(base), 657.xz_s(base), 998.specrand_is(base)
Build errors for intspeed: None
Build Complete
The log for this run is in /opt/cpu2017/result/CPU2017.031.log
runcpu finished at 2023-07-26 16:32:28; 2825 total seconds elapsed
故障处理
*** Error building 600.perlbench_s base /usr/bin/ld: cannot find -lomp: No such file or directory
安装openmp,其中有日志
-- Installing: /usr/local/lib/libomp.so