[LLVMdev] How to print machine code of JIT IR

Clemens Hammacher hammacher at cs.uni-saarland.de
Fri Dec 21 05:21:47 PST 2012

Hi Chia Lun Liu,

On 12/21/12 7:47 AM, ChiaLun wrote:
>    I am using LLVM 3.1, and wants to print the machine code of JIT IR
> I try the following method
> EngineBuilder builder(&ctx.getModule());
>   builder.setEngineKind(EngineKind::JIT);
> 	*
>     TargetMachine * tm = builder.selectTarget();
>     tm->Options.PrintMachineCode = true;*
>      engine = builder.create();

Try builder.create(tm).

selectTarget() returns a new object, so setting options on that has no 
effect on the ExecutionEngine which is built by the create() call.
In fact, EngineBuilder.create() just creates passes a newly created 
>   ExecutionEngine *create() {
>     return create(selectTarget());
>   }

> Another question is that I am not sure when JIT would dump machine code.

It actually dumps it several times during code emission, after running 
different passes on it. Code emission happens on the first call to the 
functions, thus lazily (or just in time).


More information about the llvm-dev mailing list