[LLVMdev] experimenting with partial evaluation

NAKAMURA Takumi geek4civic at gmail.com
Sat Jun 12 04:16:37 PDT 2010


Good evening, Pierre.


Here is an example to you. attached. run with -disable-lazy-comilation.
It is *as-is* for Win32 but might be applicable to *-linux-elf more smartly.
It does get llvm::Function* by function ptr(not name!),
and clone a specialized function,
and execute specialized one
in the same context as parent lli.


> - In a running program, can I get pointers to the llvm Module that
> contains the code currently being executed ?
>     Using this I could do a module->getFunction() to get the Function,
> clone
> it, tweak it, JIT it and I'd be happy.

AFAIK, current version of lli does not support.
I let lli to export current llvm::Module* and llvm::ExecutionEngine*.

Current llvm::Module const* could be gotten from llvm::Function const*,
but you must need not Module const* but writable one.
(or, clone a module to optimize)


> - When I JIT something how can I link it to my running program so it can
> call functions and access globals ?

 - to export some symbols in lli and llvm/lib. It would be difficult in Win32.
   I believe it possible to work with ELF.

 - to build llvm with shared object. Some APIs might be neede to
   your application. lli should resolve symbols when he reads *.bc.


> - How should I compile my program so I can do all that ? (I guess I
> shouldn't compile it to x86-64 native but bitcode instead, but what
> options ?..)

I guess you will need a special version of lli.


mata ne, Takumi
-------------- next part --------------
fib(2)=1
GV:0x309e20
FN:0x309e20
RAW:0xb40070
a0=0x311868
Ffib8=0x31f1d8<_Z3fibi1>

define internal i32 @_Z3fibi1() nounwind readnone {
entry:
  %0 = icmp sgt i32 2, 2                          ; <i1> [#uses=1]
  br i1 %0, label %entry.bb_crit_edge, label %entry.bb2_crit_edge

entry.bb2_crit_edge:                              ; preds = %entry
  br label %bb2

entry.bb_crit_edge:                               ; preds = %entry
  br label %bb

bb:                                               ; preds = %bb, %entry.bb_crit_edge
  %lsr.iv = phi i32 [ %lsr.iv.next, %bb ], [ 2, %entry.bb_crit_edge ] ; <i32> [#uses=2]
  %accumulator.tr1 = phi i32 [ %2, %bb ], [ 1, %entry.bb_crit_edge ] ; <i32> [#uses=1]
  %tmp1 = add i32 %lsr.iv, -1                     ; <i32> [#uses=1]
  %1 = tail call i32 @_Z3fibi(i32 %tmp1) nounwind ; <i32> [#uses=1]
  %2 = add nsw i32 %1, %accumulator.tr1           ; <i32> [#uses=2]
  %lsr.iv.next = add i32 %lsr.iv, -2              ; <i32> [#uses=2]
  %3 = icmp sgt i32 %lsr.iv.next, 2               ; <i1> [#uses=1]
  br i1 %3, label %bb, label %bb.bb2_crit_edge

bb.bb2_crit_edge:                                 ; preds = %bb
  br label %bb2

bb2:                                              ; preds = %bb.bb2_crit_edge, %entry.bb2_crit_edge
  %accumulator.tr.lcssa = phi i32 [ 1, %entry.bb2_crit_edge ], [ %2, %bb.bb2_crit_edge ] ; <i32> [#uses=1]
  ret i32 %accumulator.tr.lcssa
}

Specialized:fnaddr=0xb40720

define internal i32 @_Z3fibi1() nounwind readnone {
entry:
  br i1 false, label %bb, label %bb2

bb:                                               ; preds = %entry, %bb
  br i1 false, label %bb, label %bb2

bb2:                                              ; preds = %bb, %entry
  ret i32 1
}

Specialized fib(2)=1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: j.cpp
Type: application/octet-stream
Size: 1409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100612/2cb41244/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lli.diff
Type: application/octet-stream
Size: 3057 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100612/2cb41244/attachment-0001.obj>


More information about the llvm-dev mailing list