Is it possible to run a gcc optimization pass on any code and in the end obtain llvm IR? I want to use dead store elimination available in gcc. I am aware that llvm also has this pass but it is not as advanced as in gcc.
I don't have experience with it and I haven't tried, but I think the following command-line should work in DragonEgg version 3.0 and above:
-fplugin=./dragonegg.so -O0 -fdse -fplugin-arg-dragonegg-enable-gcc-optzns -fplugin-arg-dragonegg-llvm-ir-optimize=2 -fplugin-arg-dragonegg-emit-ir -S
-fplugin=./dragonegg.so
enables DragonEgg-O0
turns off all GCC optimization passes-fdse
turns on GCC dead store elimination-fplugin-arg-dragonegg-enable-gcc-optzns
enables GCC optimizations in DragonEgg-fplugin-arg-dragonegg-llvm-ir-optimize=2
forces LLVM to optimize to -O2
instead of following the GCC optimization level-fplugin-arg-dragonegg-emit-ir
generates LLVM IR instead of asm, which according to the question is what you want here-S
because you kinda need it when you use -fplugin-arg-dragonegg-emit-ir
And this should work on any GCC tree pass.
If you need more fine-grained control than this, you can tweak DragonEgg: the correct place to edit is the plugin_init
function in Backend.cpp - you can see precisely how it sets up the passes to run there.