LLVM - Run Own Pass automatically with clang

邮差的信 提交于 2019-12-01 01:19:10

问题


I wrote a few own passes for llvm, in order to use them with clang.

I integrated them in llvm (not dynamically loaded). They are even listed in the Optimizations available: section when I type:

opt --help-hidden

I want to run one of own my passes now automatically as the last one when I call clang:

clang ./hello.bc -o ./hello

or even with c-code:

clang ./hello.c -o ./hello

When I run my pass with opt manually, the modified ByteCode is generated and written to a new .bc file:

opt -my-pass < ./hello.bc > ./hello_optimized.bc

When I compile the modified .bc with clang, normal clang Optimizations are run again, which destroy the optimizations of my manual executed pass:

clang -O0 -m32 ./hello_optimized.bc -o ./hello_optimized

My Question is:

  • How can I run my own written pass automatically with clang as the last pass of all?
  • Another possible solution is deactivating all passes completely, or at least the dead code/function elimination of clang/opt. How could I do this?

回答1:


The proper way to do this would be to make clang add your pass to the pass manager it builds. See clang/lib/CodeGen/BackendUtil.cpp:void EmitAssemblyHelper::CreatePasses() for how it's handled for the sanitizers.




回答2:


You can run your own pass with clang directly with -Xclang.

clang++ -Xclang -load -Xclang ./libmypass.so input.cpp

Source



来源:https://stackoverflow.com/questions/23130821/llvm-run-own-pass-automatically-with-clang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!