bugpoint
LLVM bugpoint tool: design and usage¶
https://llvm.org/docs/Bugpoint.html
在分析benchmark codegen的时候,常常需要一个小一点的IR来产生想要的pattern,bugpoint提供了--compile-custom功能可以完成这个任务1。
使用一个例子来说明bugpoint的这一用法。
最近的wyvern对leela_r产生了这样的pattern
这里有个明显的redundant copy。perf是了解这段代码所在的函数的,所以我们也知道源代码文件。通过spec的编译log,我们也知道编译命令,从而我们可以得到相应的FastBoard.ll。 1 用llvm-extract把目标函数抽取出来成为一个独立的IR文件¶
为了加快bugpoint的reduce速度,我们可以先用llvm-extract把目标函数抽取出来成为一个独立的IR文件。
llvm-extract -S --func=<target_func_name> FastBoard.ll -o output.ll
llvm-extract -S --func=_ZN3pov12Ray_In_BoundEPNS_10Ray_StructEPNS_13Object_StructE objects.ll -o objects.narrow.ll
2 写感兴趣的CHECK脚本¶
接下来是编写check脚本。check脚本会被bugpoint调用,输入为bugpoint提供的LLVM IR文件,通过返回码向bugpoint反馈信息2。
对于这个例子,在The command should exit with a failure exit code if the file is "interesting" and should exit with a success exit code (i.e. 0) otherwise (this is the same as if it crashed on "interesting" inputs).
output.ll中加上 check.sh脚本为 cat check.sh
或者
可以先试下llc < output.ll | FileCheck output.ll能否通过,即能否得到自己想到的Pattern。
3 调用bugpoint narrow down case¶
最后调用bugpoint
4 得到simplify.bc¶
bugpoint执行完后,你将得到下述文件
bugpoint-reduced-blocks.bc bugpoint-reduced-simplified.bc bugpoint.reference.out-358a0f0
bugpoint-reduced-conditionals.bc bugpoint-reduced-simplified.s check.sh
bugpoint-reduced-instructions.bc bugpoint-reduced-simplifycfg.bc output.ll
bugpoint-reduced-named-md.bc bugpoint.reference.out-22be82e output.s
得到所需要的ll文件
利用check.sh中的命令行来检验是否得到了所需要的ll文件。
Example¶
从~/llvm/llvm/test/CodeGen/PowerPC/bdzlr.ll中提取能用于测试ppc-early-retpass的从BCC->BCCLR的小case。
- 修改bdnzlr.ll
bdzlr.ll的最后加上CHECK: BCCLR
- 得到
before-early-ret.mir,简单是否有所需要的BCCLR
llc -verify-machineinstrs bdzlr.ll -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 -mattr=-crbits -stop-after=ppc-early-ret -o before-early-ret.mir
- cat check.sh
#!/bin/bash
! $(llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 -mattr=-crbits -stop-after=ppc-early-ret < "$@" | FileCheck "$@")
- 调用bugpoint
- get the simplified ll