2021年1月7日木曜日

bugpointを使ってみたよ

前回、前々回とC-Reduceを使って、ここまで削れました。

$ ls -l test2.cc*
-rw-r--r-- 1 jam jam 1180 Dec 27 10:41 test2.cc
$ clang -O3 -fvectorize ... -S -emit-llvm test2.cc
$ ls -l test2.ll
-rw-r--r-- 1 jam jam 8500 Dec 27 11:04 test2.ll
$ wc test2.ll
136 981 8500 test2.ll

しかし、ビットコードで見るとまだ大きいので、これをbugpointで削ります。

$ cp test2.ll test3.ll
$ bugpoint --compile-custom --compile-command=./test3.sh test3.ll
...
Emitted bitcode to 'bugpoint-reduced-simplified.bc'
$ llvm-dis bugpoint-reduced-simplified.bc -o test3-reduced.ll
$ ls -l test3*.ll
-rw-r--r-- 1 jam jam 893 Dec 27 11:40 test3-reduced.ll
-rw-r--r-- 1 jam jam 8500 Dec 27 11:10 test3.ll
$ wc test3*.ll
24 100 893 test3-reduced.ll
136 981 8500 test3.ll
160 1081 9393 total

これでデバッグが本当に楽になります。何故俺はこれまでC-Reduceとbugpointを使っていなかったのか・・・。

ちなみに、test3.shは以下の通りです。C-Reduceと違い、bugpointのスクリプトは探索対象の場合0以外を返すため、!は必要ありません。

$ cat test3.sh
#!/bin/bash
llc -mtriple XX "$@"