[LLVMdev] opt usage?

Reid Spencer rspencer at reidspencer.com
Fri Oct 13 12:31:32 PDT 2006

Hi Brian,

On Fri, 2006-10-13 at 11:40 -0700, Lewis, Brian T wrote:
> I’m new to the LLVM, so please forgive what might be a silly
> question. 
No problem :)
> I’d like to use the opt bytecode-to-bytecode optimizer, but when I try
> running it to do, for example, dead code elimination (-dce) or global
> common subexpression elimination (-gcse), nothing much seems to
> happen:
>             opt –gcse –dce –o bar-opt.bc bar.bc
>             llvm2cpp -o bar-opt.cpp bar-opt.bc
>             diff bar.bc bar-opt.bc

Why do you want to diff the bytecode files? Did you mean to diff
the .cpp files? The above commands don't create a cpp file from the
original bytecode (bar.bc).
>             40c40
> < Module* mod = new Module(“bar.bc”);
> ---
> < Module* mod = new Module(“bar-opt.bc”);

The DCE is for dead code elimination. It really depends on what your
input bytecode looks like. Perhaps there was no dead code to eliminate.
> Other optimizations seem to have similar effect.

That is strange, but again, it depends on what the input bytecode is.
Can you send it to me so I can see what you're trying to optimize?

>  Are the optimizations listed in the “opt –help” output only available
> if some library is loaded? 

No, they should be available all the time.  If they weren't available,
you'd get an error message of some sort.

> If so, where are these opt plugin libraries stored? 

While you can load optimization transforms using the --load option, the
standard optimizations that LLVM provides are all linked into opt
directly, they are not plugins.

> If not, how do you use opt? 

Just the way you've been using it :)  I think this is mostly just a case
that your input doesn't have anything to optimize for your test case. To
get something to happen, try this:

opt -mem2reg -reg2mem -stats -time-passes bar.bc -o bar-opt.bc

This will run an SSA transform of memory to SSA registers and then back
again from registers to memory. If there's any code at all in bar.bc,
the stats printed should be non-zero.

> Thanks.

You're very welcome, and welcome to LLVM.
>    Brian


More information about the llvm-dev mailing list