Developers
Resource
文档评分
Findability
Accuracy
Completeness
Readability
在线提单
论坛求助

file子命令

命令功能

file子命令支持单文件与全项目扫描两种模式。用户可通过对单个源码文件或全项目进行分析优化,定位源码文件或全项目中可向量化的代码,并提供改写建议。

命令格式

./tiancheng file [options]

参数说明

表1 参数说明

参数

参数选项

说明

-h/--help

-

可选参数,获取帮助信息。

-i

-

可选参数,指定输入的C/C++源文件。启用单文件扫描模式时必须选择该参数。

说明:

同时选择“-i”参数和“-r”参数时,“-i”参数的优先级高于“-r”参数,输入文件以“-i”参数指定的文件为准。

-o

-

必选参数,指定输出的报告文件目录。

-I

-

可选参数,指定头文件目录。

--clang-resource-dir

-

可选参数,指定Clang内置头文件(如stddef.h)所在的目录,默认为工具lib目录下的头文件目录。

说明:

该参数的默认值为:install_path/tiancheng/lib/clang/17。

--gcc-toolchain

-

可选参数,指定GCC编译器安装的目录,作为代码分析时的工具链路径。默认使用系统的GCC编译器目录。

-r

-

可选参数。启用单文件扫描模式时,该参数用于指定待分析源码文件所属项目的根目录,以支持头文件搜索,避免头文件缺失;启用全项目扫描模式时,则该参数用于指定目标工程。

--simd-target

neon/sve

可选参数,指定转换的ARM指令集,可指定为NEON或SVE指令集,默认值为neon。

  • NEON:ARM架构中的SIMD指令集,通过128位矢量寄存器实现并行数据处理,支持8/16/32/64位整数及单精度浮点运算。支持基于鲲鹏920系列和鲲鹏950处理器的服务器。
  • SVE:可伸缩矢量扩展,一种矢量长度无关的SIMD指令集,让同一份代码能在不同宽度的ARM处理器上自动获得最佳性能。支持部分基于鲲鹏920新型号和鲲鹏950处理器的服务器。
说明:

启用x86 Intel intrinsics分析功能时,“--simd-target”参数只能指定为sve。

-v

-

可选参数,启用详细输出模式,显示更多调试信息和分析过程。默认不启用。

-j

-

可选参数。在全项目分析模式下,用于指定并行工作进程的数量及上限。

说明:
  • 未通过“-j”指定时,并行度默认值为1。
  • 使用“-j”参数但未指定具体数值时,并行度默认取当前处理器并发线程数。
  • 使用“-j”参数且指定具体数值时则取其指定值。并行度下限为1,上限将取文件数量和用户设定值的最小值。

--enable-ifstmt-scan

-

可选参数,启用对if语句的扫描分析。

--enable-intel-intrinsics

-

可选参数,启用x86 Intel intrinsics分析功能,分析x86向量化指令,实现对x86向量化代码的改写。默认不启用。

--features

fma/dq/bw/vl/bf16/vnni/fp16

可选参数,指定x86指令集特性,默认值为空,支持选择多个选项,用英文逗号分隔。该参数仅在启用x86 Intel intrinsics分析功能时生效。

  • FMA:乘加融合运算,支持单指令完成乘法和加法运算,不依赖AVX512指令集,可与AVX/AVX2/AVX512指令集任意组合使用。
  • DQ:双字/四字扩展,AVX512指令集特性,支持32位和64位整数及掩码操作。
  • BW:字节和字扩展,AVX512指令集特性,支持8位和16位整数运算。
  • VL:向量长度扩展,AVX512指令集特性,支持128位和256位矢量寄存器使用AVX512指令。
  • BF16:16位脑浮点数,AVX512指令集特性,支持16位脑浮点数运算。
  • VNNI:矢量神经网络指令,AVX512指令集特性,支持低精度整数向量点积和乘加累加运算。
  • FP16:半精度浮点数,AVX512指令集特性,支持半精度浮点数向量算术运算。

--isa

sse2/avx/avx2/avx512

可选参数,指定识别的x86指令集,默认值为avx2。该参数仅在启用x86 Intel intrinsics分析功能时生效。

  • SSE2:x86架构中的SIMD指令集,通过128位矢量寄存器实现并行数据处理,支持8/16/32/64位整数及双精度浮点运算。
  • AVX:高级向量扩展,x86架构中的SIMD指令集,通过256位矢量寄存器实现并行数据处理,支持256位单精度浮点运算和双精度浮点运算。
  • AVX2:高级向量扩展,x86架构中的SIMD指令集,通过256位矢量寄存器实现并行数据处理,支持256位整数运算和浮点运算。
  • AVX512:高级向量扩展,x86架构中的SIMD指令集,通过512位矢量寄存器实现并行数据处理,支持512位整数运算和浮点运算。
说明:

若识别的指令集为AVX512指令集,则优化后的源代码需要在支持512位SVE指令集的设备上运行。

使用示例

执行以下命令,查看file命令支持的功能信息:
./tiancheng file -h

返回信息如下:

OVERVIEW: Analyze one input file or all C/C++ files under a project directory

USAGE:
  tiancheng file -i <filename> [-r <project-root>] -o <path> [options]
  tiancheng file -r <project-root> -o <path> [-j N] [options]

OPTIONS:
  -h/--help                                   Display available options
  -i <filename>                               Specify input C/C++ source file
  -o <pathname>                               Specify output report file path
  -I <pathname>                               Include the extra header files
  --clang-resource-dir=<path>                 Clang resource directory (path up to lib/clang/<version>, excluding 'include')
  --gcc-toolchain=<path>                      Path to the GCC toolchain root directory used by Clang
  -r <pathname>                               Inputfile root path. When used alone (without -i/--funcs/
                                              --flamegraph), analyze ALL C/C++ source and header files
                                              under the directory in parallel; each file is reported into
                                              a sub-directory of -o mirroring the source tree.
  --simd-target=<value>                       Convert simd type selection
    =neon                                     Convert to ARM NEON intrinsics
    =sve                                      Convert to ARM SVE intrinsics
  -v                                          Enable verbose output
  -j <N>                                      Parallel worker processes for whole-project (-r only) analysis (make-style): omit for serial; bare -j uses all CPU cores; -j N uses N.
  --enable-ifstmt-scan                        Enable scanning of if statements
  --enable-intel-intrinsics                   Enable analysis of x86 Intel intrinsics
  --features=<fma,dq,bw,vl,bf16,vnni,fp16>
                                              x86 feature flags, comma-separated
                                              Layered on top of --isa. Only effective with --enable-intel-intrinsics
    fma                                       Fused Multiply-Add: enables _mm256_fmadd_ps etc.  -> -mfma
                                              (works with avx/avx2/avx512, not AVX-512-specific)
    dq                                        Doubleword/Quadword: enables 64-bit mask ops,     -> -mavx512dq
                                              _mm512_reduce_add_ps, _mm512_mullo_epi64 etc.
    bw                                        Byte/Word: enables byte/word mask and compare ops -> -mavx512bw
    vl                                        Vector Length: enables 128/256-bit AVX-512 ops   -> -mavx512vl
    bf16                                      BFloat16: enables _mm512_dpbf16_ps etc.           -> -mavx512bf16
                                              (auto-implies dq, bw, vl)
    vnni                                      Vector Neural Net Instructions: int8 dot-product  -> -mavx512vnni
    fp16                                      FP16 arithmetic: enables _mm512_add_ph etc.       -> -mavx512fp16
  --isa=<level>                               x86 ISA level for Intel intrinsics analysis
                                              Only effective with --enable-intel-intrinsics
    =sse2                                     SSE2:    128-bit SIMD, baseline x86-64
    =avx                                      AVX:     256-bit SIMD, float only
    =avx2                                     AVX2:    AVX + 256-bit integer ops (default)
    =avx512                                   AVX-512: AVX2 + 512-bit SIMD foundation

EXAMPLES:
  Note: [option] denotes an optional argument.

  Mode 1 - Single file scan / 单文件全量扫描
    tiancheng file -i input.cpp -o ./output [-r /path/to/project]

  Mode 2 - Whole project scan / 工程目录全量扫描
    tiancheng file -r /path/to/project -o ./output [-j 8]

  Mode 3 - x86 Intel intrinsics migration / x86 Intel intrinsics 迁移分析
    # Basic usage / 基本用法:
    tiancheng file -i vec.cpp -o ./output --enable-intel-intrinsics
    # Specify ISA level / 指定 ISA:
    tiancheng file -i vec.cpp -o ./output --enable-intel-intrinsics [--isa=avx2]
    # Specify ISA level and extra features / 指定 ISA 与扩展特性:
    tiancheng file -i vec.cpp -o ./output --enable-intel-intrinsics [--isa=avx512] [--features=dq,bw]