[LLVMdev] LLVM-OCaml Bindings Tutorial (2.6-2.7)
jon at ffconsultancy.com
Wed Feb 17 22:42:59 PST 2010
On Wednesday 17 February 2010 17:31:56 Jianzhou Zhao wrote:
> On Tue, Feb 16, 2010 at 2:47 AM, Jon Harrop <jon at ffconsultancy.com> wrote:
> > I've written a VM in OCaml built upon LLVM using LLVM's OCaml bindings:
> > http://www.ffconsultancy.com/ocaml/hlvm/
> HLVM is an interesting project to support multi-language programming
> in a higher level. In this project, have you designed a compiler
> optimization pass with OCaml bindings?
HLVM is designed as a completely separate layer on top of LLVM with loose
bindings. LLVM code never calls back into HLVM, so no LLVM compiler passes
are written in OCaml. However, HLVM is compiling its own declarative
intermediate representation down to LLVM IR and, therefore, implements its
own internal compiler optimization passes that act upon HLVM's own IR and are
written entirely in OCaml. This is, of course, far simpler and safer than
trying to write LLVM passes in OCaml.
> I looked into the OCaml bindings codes.
> It provides some OCaml interfaces to call an existing LLVM pass, such
> as constant propagation, simplification of CFG, but it has not wrapped
> enough interfaces to design a pass in OCaml from sketch yet. For example,
> to implement a simple constant propagation (which is defined in
> lib/Transforms/scalar in C++)
> in OCaml, we need some functions in lib/Analysis which have not been
> ported into OCaml. Was there any difficult to port those C++ code into
> How does LLVM team expect users to use these OCaml bindings?
> Is the implementation of a pass in OCaml an expected requirement? or
> this bindings are only used to drive the LLVM compilations from OCaml.
I believe the OCaml bindings are only intended to let OCaml programs drive
LLVM by conveying IR to it.
For me, the quality of LLVM's code gen is extremely important but its
optimization passes are irrelevant. HLVM generates very efficient LLVM IR
directly so LLVM's optimization passes rarely provide significant performance
improvements. Any productive optimizations that HLVM might do cannot be
expressed as LLVM passes because they would require higher-level information
that has been removed by that stage.
Dr Jon Harrop, Flying Frog Consultancy Ltd.
More information about the llvm-dev