LLVM常用命令说明

矢量化报告选项说明 gcc相关参数

-fopt-info-vec-optimized 形成优化相关的矢量化报告
-fopt-info-vec-missed

-emit-llvm

使用-S 指定只生成汇编文件,文件后缀为bc,*.bc(llvm language文件,人类可读,IR的另一种格式)

使用-c 指定只生成目标文件,*.o

-flto : link-time optimizations 控制是否开启链接时优化

-mllvm : LLVM core library LLVM核心库,此选项表示对LLVM核心库起作用;将“-mllvm option”中的“option”选项传给llvm中端

-Wl 开启该选项后,表示将后续命令传给链接器,在开启链接时优化时,该选项非常有用

-mllvm -opt-bisect-limit // 未开启链接时优化时,使用该命令定位引入问题的pass

The -opt-bisect-limit command line option can be passed directly to tools such as opt, llc and lli. The syntax is as follows:

[other options] -opt-bisect-limit=

eg:
(1)clang -O2 -mllvm -opt-bisect-limit=256 my_file.c
# When using lld, or ld64 (macOS)
(2)clang -flto -Wl,-mllvm,-opt-bisect-limit=256 my_file.o my_other_file.o
# When using Gold
(3)clang -flto -Wl,-plugin-opt,-opt-bisect-limit=256 my_file.o my_other_file.o

(4)$ opt -O2 -o test-opt.bc -opt-bisect-limit=16 test.ll

LLWM_DEBUG macro and -debug option

Basically, you can put arbitrary code into the argument of the LLVM_DEBUG macro, and it is only executed if ‘opt’ (or any other
tool) is run with the ‘-debug’ command line argument:

eg:
LLVM_DEBUG(dbgs() << “I am here!\n”);
Then you can run your pass like this:

$ opt < a.bc > /dev/null -mypass

$ opt < a.bc > /dev/null -mypass -debug
I am here!

-debug-only

解释链接 https://llvm.org/docs/ProgrammersManual.html

llc

将*.bc(位码文件IR的一种格式)或者*.ll(llvm language文件,人类可读,IR的另一种格式)文件编译成*.s(汇编语言)或者*.o(目标机器语言)文件
LLVM官方学习文档:https://llvm.org/docs/CommandGuide/llc.html

lli

lli直接执行LLVM位码格式(*.bc)的程序
LLVM官方学习文档:https://llvm.org/docs/CommandGuide/lli.html

opt

opt命令是模块化的优化器和分析器的总称;使用该命令可以执行特定的优化或者分析,
LLVM官方学习文档:https://llvm.org/docs/CommandGuide/opt.html

llvm-as

通过ll文件生成bc文件
LLVM官方学习文档:https://llvm.org/docs/CommandGuide/llvm-as.html

llvm-dis

通过bc文件生成可读的ll文件
LLVM官方学习文档:https://llvm.org/docs/CommandGuide/llvm-dis.html

FileCheck 编写测试用例规则

LLVM 官方学习文档:https://llvm.org/docs/CommandGuide/FileCheck.html#tutorial

lit LLVM测试框架

LLVM 官方学习文档:https://llvm.org/docs/CommandGuide/lit.html?spm=a2c6h.12873639.article-detail.9.6cb87a27kQbjpt

Machine IR Format Feference Manual

LLVM 官方学习文档:https://llvm.org/docs/MIRLangRef.html#introduction

LTO链接时打印IR信息的命令

-Wl,-plugin-opt=save-temps
(2)上述命令添加后,执行结果中,会出现如下文件
a.out // 生成的可执行文件
a.out.0.0.preopt.bc // 在合并之后和执行任何 LTO 优化之前合并的 IR
a.out.0.2.internalize.bc // 执行整个程序内化后的 IR
a.out.0.4.opt.bc // 优化管道后的IR
a.out.0.5.precodegen.bc // 在本地代码生成之前的IR
a.out.lto.o
a.out.resolution.txt

查看机器具体的cpu型号命令: sudo dmidecode --type processor

打印矢量化报告常用命令选项:学习地址 https://easyperf.net/blog/2017/10/30/Compiler-optimization-report

(1)clang -O3 -Rpass-analysis=loop-vectorize -Rpass=loop-vectorize -Rpass-missed=loop-vectorize
上述命令在未开启lto时使用,将打印矢量化相关的信息,形成矢量化报告
上述选项含义:-Rpass-analysis=loop-vectorize 将分析矢量化失败的原因,并打印相关信息
-Rpass=loop-vectorize 打印矢量化成功信息
-Rpass-missed=loop-vectorize 打印矢量化失败信息
(2)clang -flto=full -O3 -g -Wl,-plugin-opt,-pass-remarks=loop-vectorize -pass-remarks-missed=.
上述命令在开启lto后使用,通过-Wl选项将后续命令传给plugin-opt工具,打印矢量化报告

(3)clang -flto=full -O3 -g -Wl,-mllvm -Wl,-pass-remarks=loop-vectorize -Wl,-mllvm -Wl,-pass-remarks-missed=.
上述命令在开启lto后使用,通过-Wl选项将后续命令传给LLD 链接器,打印矢量化报告

根据pass名称搜索对应的源文件,使用grep命令

grep -nr “pass name”

-save-temps -###

上述选项,将打印整个编译的执行流程,包括前端,终端,以及从IR到汇编

llvm-reduce 裁剪大型测试用例使用

-help-hidden 选项查看clang支持的选项

生成selectionDAG 图指令(方便理解指令选择以及排查问题)

步骤1:使用命令生成dot后缀文件 https://www.cnblogs.com/Five100Miles/p/12824942.html
步骤2:使用dot命令将dot文件转换为图像文件:dot input.dot -Tpng -o output.png

将IR转换为图

1)opt -passes=dot-cfg input.ll : 以function为单位,生成对应的函数的cfg
2)dot input.dot -Tpng -o output.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值