使用带有内置过程的LLVM opt

使用带有内置过程的LLVM opt,llvm,Llvm,我已经用我的玩具转换过程成功地运行了llvm opt,但没有看到如何使用内置转换过程的“opt” 我有一个空的hi.c文件 int main(){ } 例如,如果我想使用-instcount pass opt -instcount hi.c 给我一个奇怪的错误 opt: hi.c:1:1: error: expected top-level entity int main(){ ^ 使用opt-instcount hi.bc也不起作用 WARNING: You're attempting

我已经用我的玩具转换过程成功地运行了llvm opt,但没有看到如何使用内置转换过程的“opt”

我有一个空的hi.c文件

int main(){
}
例如,如果我想使用-instcount pass

opt -instcount hi.c
给我一个奇怪的错误

opt: hi.c:1:1: error: expected top-level entity
int main(){
^
使用opt-instcount hi.bc也不起作用

WARNING: You're attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f' option.
如果使用opt
-inst count-f hi.bc
,则输出是一个混乱的位码

问题:我们应该如何将“opt”与内置转换过程(来自上面链接的转换过程)一起使用?谢谢你的想法“选择帮助”说

opt[选项]


但是我上面的例子'opt-instcount hi.bc'并没有像预期的那样工作(见上文)。

首先:
opt
只在位码/可读LLVM IR文件上工作。因此,传递
.c
文件将永远不会起作用。 您必须首先使用clang编译.c文件:

clang -emit-llvm in.c -o input.bc
您遇到的警告基本上说明了一切:

警告:您正在尝试打印位代码文件。这是 不可取,因为这可能会导致显示问题。如果你真的想 亲身体验LLVM位代码,您可以使用“-f”强制输出 选择权

opt的输出可能是修改过的位代码文件,由于您不支持输出文件,它将把它打印到stdout。这就是为什么你会得到“凌乱”的比特码

要按应有的方式使用opt,可以使用/dev/null删除输出:

opt -inst-count input.bc -o /dev/null
或支持输出文件

opt -inst-count input.bc -o output.bc
或者将输出作为可读的LLVM IR打印到标准输出

opt -inst-count input.bc -S
或者将输出作为可读的LLVM IR文件打印到磁盘

opt -inst-count input.bc -S -o output.ll