[LLVMdev] The most efficient way to compile to LLVM IR?

bob zhang bobzhang1988 at gmail.com
Tue Apr 16 07:09:49 PDT 2013


Thanks for your reply.
On Mon, Apr 15, 2013 at 9:15 PM, David Blaikie <dblaikie at gmail.com> wrote:

> On Mon, Apr 15, 2013 at 3:32 PM, Hongbo Zhang <bobzhang1988 at gmail.com>
> wrote:
> > Hi all,
> >    I am trying to compile my toy language to LLVM back end. (I am new to
> > LLVM, so my questions may sound naive)
> >    I am looking at some tutorials about LLVM, most are about how to use
> LLVM
> > IRBuilder, however, I find the API provided by IRBuilder is quite
> imperative
> > and verbose, and the API changes so fast that most of the tutorials are
> out
> > of dated.
> >    So I am wondering what's the benefit of emitting LLVM IR using
> IRBuilder
> > compared with designing my own abstract syntax in a high-level
> programming
> > language(e.g. Haskell or OCaml) and unparsing it to LLVM IR.
>
> To be clear you're suggesting having your frontend (say, for
> argument's sake, written in C++) parse your toy language and then emit
> a (say) Haskell representation of IR? Using some Haskell APIs you'll
> write that will emit LLVM bitcode? And then running the resulting
> Haskell program to produce your bitcode that you'll load back in to
> LLVM to optimize/compile?
>
>  Yes, that's what I am doing, in OCaml though. Functional languages are
excellent
for program transformation and manipulation. Where is the specification for
the bitcode format?
Thanks

> > Is there some
> > benefit of using IRBuilder I ignored here?
>
> It'll be more efficient to keep the IR in memory rather than to go out
> to a source file, run that file to produce bitcode, then load that
> bitcode in to LLVM.
>
> Also I'm not sure I see quite how that scheme would be less verbose.
>
> > And I have some follow-up
> > questions: 1. How stable is the IR format?
>
> There's in-built autoupgrade so that you can load old IR in newer
> versions of LLVM (any 3.* series should be compatible, I believe).
>
> > 2. Is the binary representation
> > of IR format (*.bc) stable and the same across different platforms?
>
> It's the same format, but the actual bitcode isn't retargetable, as
> such. (ie: don't expect to be able to produce bitcode that you can
> compile for different architectures)
>
> > 3. Is
> > there any previous work of building a declarative`interface instead of
> using
> > IRBuilder?
>
> Not that I know of. The frontends tend to use IRBuilder.
>
> >    Thank you in advance!
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>



-- 
Regards
-- Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130416/a820f720/attachment.html>


More information about the llvm-dev mailing list