function子命令
命令功能
用户可通过对指定函数进行分析优化,快速定位可向量化的指定函数,并提供改写建议。
命令格式
./tiancheng function [options]
参数说明
参数 |
参数选项 |
说明 |
|---|---|---|
-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。
说明:
启用x86 Intel intrinsics分析功能时,“--simd-target”参数只能指定为sve。 |
-v |
- |
可选参数,启用详细输出模式,显示更多调试信息和分析过程。默认不启用。 |
--funcs |
- |
可选参数,指定函数扫描模式下被分析函数的列表。启用函数扫描模式时必须选择该参数。 |
--enable-ifstmt-scan |
- |
可选参数,启用对if语句的扫描分析。 |
--enable-intel-intrinsics |
- |
可选参数,启用x86 Intel intrinsics分析功能,分析x86向量化指令,实现对x86向量化代码的改写。默认不启用。 |
--features |
fma/dq/bw/vl/bf16/vnni/fp16 |
可选参数,指定x86指令集特性,默认值为空,支持选择多个选项,用英文逗号分隔。该参数仅在启用x86 Intel intrinsics分析功能时生效。
|
--isa |
sse2/avx/avx2/avx512 |
可选参数,指定识别的x86指令集,默认值为avx2。该参数仅在启用x86 Intel intrinsics分析功能时生效。
说明:
若识别的指令集为AVX512指令集,则优化后的源代码需要在支持512位SVE指令集的设备上运行。 |
使用示例
./tiancheng function -h
返回信息如下:
OVERVIEW: Analyze explicitly specified functions
USAGE:
tiancheng function -i <filename> [-r <project-root>] -o <path> --funcs <func1,func2> [options]
tiancheng function -r <project-root> -o <path> --funcs <func1,func2> [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
--simd-target=<value> Convert simd type selection
=neon Convert to ARM NEON intrinsics
=sve Convert to ARM SVE intrinsics
-v Enable verbose output
--funcs=<func1,func2> Comma-separated list of functions to analyze
--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 - Target functions scan (single file) / 指定函数扫描(单文件)
tiancheng function -i input.cpp -o ./output --funcs func1,func2
Mode 2 - Target functions scan (whole project) / 指定函数扫描(工程目录)
tiancheng function -o ./output -r /path/to/project --funcs func1,func2