User: Password:
|
|
Subscribe / Log in / New account

The Design of LLVM (Dr. Dobb's)

Dr. Dobb's has a moderately detailed overview of the design of LLVM by Chris Lattner. "In particular, LLVM IR is both well specified and the only interface to the optimizer. This property means that all you need to know to write a front end for LLVM is what LLVM IR is, how it works, and the invariants it expects. Since LLVM IR has a first-class textual form, it is both possible and reasonable to build a front end that outputs LLVM IR as text, then uses UNIX pipes to send it through the optimizer sequence and code generator of your choice. It might be surprising, but this is actually a pretty novel property to LLVM and one of the major reasons for its success in a broad range of different applications. Even the widely successful and relatively well-architected GCC compiler does not have this property: its GIMPLE mid-level representation is not a self-contained representation."
(Log in to post comments)

The Design of LLVM (Dr. Dobb's)

Posted May 30, 2012 15:30 UTC (Wed) by juliank (subscriber, #45896) [Link]

I recommend the version you get when clicking the print button, instead of clicking through the three pages. Otherwise, a standard article about LLVM, not many new things to learn if you have read Chris Lattner's previous stuff on LLVM.

The Design of LLVM (Dr. Dobb's)

Posted May 30, 2012 15:43 UTC (Wed) by djc (subscriber, #56880) [Link]

It's worth to note that most of the content has already been published in the Architecture of Open Source Applications book, volume 1.

http://www.aosabook.org/en/llvm.html

The Design of LLVM (Dr. Dobb's)

Posted May 30, 2012 16:53 UTC (Wed) by juliank (subscriber, #45896) [Link]

That's a useful note, so it turns out that I have read that precise article already, and it's not just like previous ones (as I assumed before). Thanks for that.

The Design of LLVM (Dr. Dobb's)

Posted May 30, 2012 17:01 UTC (Wed) by dashesy (guest, #74652) [Link]

Thanks for the pointer. LLVM was very well written. I just started reading a few other chapters, and it is a very interesting read!

The Design of LLVM (Dr. Dobb's)

Posted May 30, 2012 18:16 UTC (Wed) by wahern (subscriber, #37304) [Link]

There's usually a gap between how an author sees his project in his mind's eye, and the project in reality. Lattner is no different. He clearly has a slightly exaggerated sense of LLVM's virtues and GCC's vices, and a diminished sense of LLVM's vices and GCC's virtues. I'm not trying to equivocate LLVM and GCC, but if you read the substance of his descriptions closely, there's less of a gap than his adjectives and qualifiers suggest.

So rather than judge the code by reading an article, judge the code by reading the code.

The Design of LLVM (Dr. Dobb's)

Posted May 30, 2012 21:52 UTC (Wed) by daglwn (guest, #65432) [Link]

This is exactly right. LLVM's use of a fully descriptive IR, ability to write that IR out to files and process it via piped commands is nothing new. This has been done in the research environment for a couple of decades, at least.

LLVM is well-designed, no doubt, and its modular nature helps tremendously when putting a project together. But it is not the first modular compiler nor the first to put compiler components into libraries.

LLVM is certainly not perfect. I would change quite a bit of the software engineering, actually. But overall, it is the most useful open source compiler tool set out there.

The Design of LLVM (Dr. Dobb's)

Posted May 31, 2012 4:00 UTC (Thu) by rsidd (subscriber, #2582) [Link]

I would change quite a bit of the software engineering, actually.

So might Lattner if he were starting from scratch. But clearly they got a lot right, and now the benefits of fundamental changes are probably not worth the pain. There is a difference between a research compiler and a compiler that is used by several production platforms and dozens of serious projects. LLVM may not be the first modular compiler but it is the first to have a real-world impact.

The Design of LLVM (Dr. Dobb's)

Posted May 31, 2012 14:31 UTC (Thu) by daglwn (guest, #65432) [Link]

> So might Lattner if he were starting from scratch.

Some, yes, but not much as he has been asked about it before.

The leadership has no problem completely replacing or removing APIs so stability is not a problem. Users simply have to bear the pain. Pain does not seem to be a concern of the project. And that's fine. I completely understand why they choose to operate that way. I wouldn't want to be locked into a set of APIs either.

Certainly they did get a lot right. As for real-world impact, I suspect that something like MSVC is pretty modular and that Microsoft uses that to its advantage in Visual Studio. Of course we can't prove that.

The Design of LLVM (Dr. Dobb's)

Posted May 31, 2012 8:09 UTC (Thu) by mlopezibanez (guest, #66088) [Link]

So what are LLVM's vices?

The criticism of GCC (and GDB, GAS and the whole GNU toolchain) in that article seems entirely fair, and Chris didn't even comment on the front ends or the development aspects.

The Design of LLVM (Dr. Dobb's)

Posted May 31, 2012 14:45 UTC (Thu) by daglwn (guest, #65432) [Link]

> So what are LLVM's vices?

I hesitate to respond because I don't want to seem like I'm dumping on LLVM. I use it every single day at work and it's a lovely thing. The community is great and the advancement is quick.

That said, here are a few things I would improve:

- Getting code merged upstream is pert near impossible. It takes forever to get code reviewed, patches are dropped all the time, etc. Many people have noted this but there doesn't seem to be a willingness to change processes to address it.

- Cathedral model of development. This is a matter of taste but I think people generally prefer the bazaar model.

- The class interfaces are WAY too extensive. Designers tend to throw everything and the kitchen sink into classes. Most of the interfaces should be freestanding functions. That would simplify the API.

- There are still scaling issues. This has been improved over the years but LLVM can still fall to its knees on very large codes.

- Refusal to use common libraries. There's a lot of NIH and reinventing of the wheel. LLVM has entire headers devoted to reproducing stuff available in Boost and the standard library. I'm not sure why that's so other than an overinflated fear of templates. There's a whole regular expression engine in there.

- Bare pointers. With today's C++ this just shouldn't happen.

The Design of LLVM (Dr. Dobb's)

Posted May 31, 2012 17:48 UTC (Thu) by hharrison (guest, #39162) [Link]

>- Getting code merged upstream is pert near impossible. It takes forever to get code reviewed, patches are dropped all the time, etc. Many people have noted this but there doesn't seem to be a willingness to change processes to address it.
>
>- Cathedral model of development. This is a matter of taste but I think people generally prefer the bazaar model.

Refusal to use anything but SVN...not sure if that's cause or effect in this case.

The Design of LLVM (Dr. Dobb's)

Posted Jun 2, 2012 13:57 UTC (Sat) by sgros (subscriber, #36440) [Link]

Isn't one of the reasons for success of LLVM also its license? I admit I have read only a part of the quoted article, but it doesn't mention license anywhere. Honestly, I think that less "restrictive" license (compared to GPL) helped a lot (primarily to involve Apple, but *BSD community too).

The Design of LLVM (Dr. Dobb's)

Posted Jun 4, 2012 1:00 UTC (Mon) by daglwn (guest, #65432) [Link]

The permissive license certainly has got a few corporate players in the mix and that's a good thing. I don't know that it has resulted in a lot of innovation or major transformation/codegen work that wouldn't have happened anyway. Certainly various organizations are holding things back and keeping then proprietary. It's really had to guess the "what ifs."

Certainly Apple would not have worked on a GPL project and this would not have hired Chris Lattner. So while it's interesting to speculate, it's impossible to know where Chris would have landed or what would have happened in the alternate universe.


Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds