What can llvm provide when writing a new compiler?

Hi everyone.
Because there is still a little confusion about the huge document, I want to know what llvm can provide when we customize our new compiler?
For example, a normal compiler includes lexer, parser, intermediate code generator , optimizer and target code generator. According to llvm documents, it seems that llvm can provide a better intermediate code presentation. And what else can it provide?
Assuming my new lanuage is very unusual, should I write all the parts( lexer, parser, intermediate code generator , optimizer and target code generator) by myself? If so, is there any convenient method / scheme to do so? Because I heard that the biggest advantage of llvm is its flexible and quick-development for new language.

If anyone knows the answer, would you please give me a reply or recommend the chapters which can answer my questions? Thank you very much for any help or any advise.

Cloud Strife wrote:

Hi everyone.
Because there is still a little confusion about the huge document, I want to know what llvm can provide when we customize our new compiler?
For example, a normal compiler includes lexer, parser, intermediate code generator , optimizer and target code generator. According to llvm documents, it seems that llvm can provide a better intermediate code presentation. And what else can it provide?

Optimizer and target codegen. We also provide an IR file format (both binary and textual). You provide the lexer and parser, and you write the code that turns your language into LLVM IR.

Note that the codegen is capable of generating both assembly files on disk and of JITting. The optimizations are capable of doing interprocedural optimizations. Someone might want to put these pieces together in a program that ships some IR, generates some IR on the fly, and then link-time-optimizes them and JITs the result.

   Assuming my new lanuage is very unusual, should I write all the parts( lexer, parser, intermediate code generator , optimizer and target code generator) by myself? If so, is there any convenient method / scheme to do so? Because I heard that the biggest advantage of llvm is its flexible and quick-development for new language.

At some point your language has to become a sequence of operations executed in order, which can in turn be expressed in LLVM IR. Leave it to LLVM to perform your optimization and codegen.

I don't know what document you're referring to, but the LLVM IR is really quite compact. Do read it: http://llvm.org/docs/LangRef.html .

Nick

Cloud:

There are some fairly good tutorials on the LLVM site. Looking them over
would answer your question thoroughly.

shap

Hi everyone.
Because there is still a little confusion about the huge document, I want
to know what llvm can provide when we customize our new compiler?
For example, a normal compiler includes lexer, parser, intermediate code
generator , optimizer and target code generator. According to llvm
documents, it seems that llvm can provide a better intermediate code
presentation. And what else can it provide?

Codegen, codegen, codegen.

Oh, and optimizations too. :slight_smile:

   Assuming my new lanuage is very unusual, should I write all the parts(
lexer, parser, intermediate code generator , optimizer and target code
generator) by myself? If so, is there any convenient method / scheme to do
so? Because I heard that the biggest advantage of llvm is its flexible and
quick-development for new language.

If you're targeting x86, for example, you do NOT want to write your own
codegen! If you do, good luck digesting five volumes of ISA material. :slight_smile:

This is generally true for other architectures as well. Reuse, reuse, reuse.
LLVM is well-designed to allow you to do that. Take advantage of it.

Does LLVM have its shortcomings? Sure. But I can guarantee it has fewer
shortcomings than a custom codegen would have down the road. Because there's
a community working on it, itr's been forced to be designed in a flexible and
reuseable way. Development process is a significant advantage of LLVM and
open source in general, one that I think is greatly undervalued.

                                                        -Dave