14 ms·
LLVM for Grad Students
- asb 11y agoThis is (in my humble opinion) a fantastic introduction, and relevant to a much wider audience than the title implies. If you want to keep up to date with LLVM developments, you might also be interested in my LLVM Weekly newsletter (http://llvmweekly.org/ http://llvmweekly.org/). I try to highlight interesting commits, mailing list discussions, and blog posts (tips and submissions always welcome!).
- jnordwick 11y agoNot just for grad students! I wish I would have seen this a week ago. LLVM passes are surprisingly readable too.
- amelius 11y agoHow difficult would it be to add a garbage collector to a language that you have written a compiler for?
- cfallin 11y agoIf you want an imprecise (conservative) garbage collector, the GC and the compiler are almost disjoint. The GC only needs to know where the heap and stack are, and be able to capture register values at GC time. In other words, it's a runtime-library issue, not a compiler issue. (See the Boehm GC for an example that works with a stock C compiler.) If you want a precise garbage collector, you need type information to know which heap and stack slots and registers are pointers. This is much harder because your compiler needs to emit metadata for each struct and then keep stack frame info or somesuch at the GC safe points so the runtime knows what the thread's roots are. Most of the precise GCs I know of are in JIT'd or interpreted languages where you have this type info anyway... AOT-compiled Lisp is the one counterexample I can think of, but usually Lisps solve this in a different way by using tagged pointers (so you know if any heap slot is a pointer by e.g. its LSB).
- ufo 11y agoWhat about all the ML-family functional languages? JIT compilation is a fairly recent innovation and I don't think its accurate to say that garbage collection is restricted to JIT compilers.
- cfallin 11y agoI never said precise GC (or even GC in general -- see Boehm GC which I cited) is restricted to JIT! Only that this is perhaps the most common case, because type info still exists at runtime. As I mentioned, the compiler can emit the necessary metadata for AOT cases. And I forgot to mention ML and Haskell and friends, sorry.
- slrz 11y agoGo also has a precise garbage collector, by the way.
- kragen 11y agoAOT-compiled Lisp generally retains the type info you need at runtime in one way or another. A precise garbage collector for a normal-ish implementation of C, assembly, or Forth is potentially very difficult, though.
- mafribe 11y agoMost of the precise GCs I know of are in JIT'd or interpreted languages GC is orthogonal to JITing. OCaml and Haskell are two examples of languages with non-JIT AOT compilers (ocamlopt and ghc, respectively) that do precise GC. I'm sure there are plenty of others.
- cfallin 11y agoYep, you're right, it is. And I totally forgot about those compiled functional languages. Thanks! I mentioned JITs and interpreters because those are the obvious cases where type information still exists at runtime, but the compiler can emit that metadata too (as I mentioned).
- _delirium 11y agoRelevant docs: http://llvm.org/docs/GarbageCollection.html http://llvm.org/docs/GarbageCollection.html
- maximilianburke 11y agoOne of my work projects involved building a .NET runtime with LLVM. It evolved from conservative garbage collection through to an advanced precise collector supporting a multithreaded runtime. The conservative collector required no support from the runtime as they operate by treating every word-sized value on the stack and heap as a potential reference. All you need for a conservative collector is to be able to know where your stack starts and ends, where your heap begins and ends, and where your globals are. We went through a couple designs for precise collectors and they all used the same meta-information. A precise collector needs to know what is a reference and what is not so your compiler needs to emit stack maps (tables of offsets where, given your PC in a function, all the live objects are), global root information, as well as object layout information. Sometimes this becomes more complex. Object layout information included both location of references within type instances as well as whether or not an object is an array. Arrays of value types require both. .NET also has a type of reference, a managed pointer, which can be used to refer to the middle of an object, such as a pointer to a value type in the middle of an array, which contributes to the parent object's liveliness information. To sum up, conservative garbage collection can be easy to add. Precise garbage collection much less so. Language specifics can throw a big wrench into things.
- deanstag 11y agoFor the past year, i had two projects which required me to work with LLVM. Because of the scarcity of articles/documentation, i found it really hard to get into it. The API Docs and a few articles by Eli Bendersky(thank you so much!!! ) was all i found useful. But once i got past the basic hurdles, the llvm project code was so well written, i felt a certain pleasure working with it.
- david-given 11y agoI've used LLVM a few times to generate code, and it's pretty easy to use (and moderately stable between revisions). e.g. http://cowlark.com/calculon http://cowlark.com/calculon is a function evaluation language I wrote as a sort of cheap shader language for a ray tracer; the whole thing is 4000 lines of C++ header. I have also attempted to port LLVM to new CPU architectures. This is a totally different deal --- it's poorly documented, very hard to make progress with, and peculiarly unfinished. (e.g. the pattern matcher language, which is excellent, is weirdly unable to match certain types of pattern, which requires you to write big chunks of C++ which manually look for particular DAG patterns and convert them into other patterns.) Debugging is a pain; get a pattern wrong and it'll just hang as the pattern matcher state machine goes insane, or else produce weird, contorted and incomprehensible error messages. I would say that it's probably about as painful as gcc, although the pain points are in a very different place. And LLVM actually has people and momentum behind it, while the gcc mailing lists are dead quiet. I'm currently investigating libfirm, which is the open source C compiler nobody's ever heard of. It looks really rather nice, and builds in less time than LLVM takes to run its configure script...
- lorenzhs 11y agolibFirm is a very interesting project, I know some of the people who are working on it (we're in the same building). What they're doing is quite cool.
- mtweak 11y agoIf you're really interested in this stuff and looking for an opportunity, we're looking for talented LLVM developers for our Austin location. http://www.bitfusion.io/jobs.php http://www.bitfusion.io/jobs.php Mazhar Memon, Bitfusion.io
- olorundaglory 11y agoGREETINGS TO EVERYONE OF YOU THAT IS READING THIS, ADVERTISEMENT HAS BEEN ADVERTISE IN ALL OVER THE NATION AND WEBSITE E.G TOKUNBO WEBSITE,NTA NEWS, AIT NEWS, OSRC, ITV, FM STATION, NEWSPAPER ETC, We deal in all cars, you can also make a request for the vehicle you want to purchase and also your budget for any vehicle, we shall call you back to inform you about it. we have these cars for sale right now. WE HAVE DIRECT TOKUNBO CARS VERY CLEAN AND BRAND NEW CARS FOR SALE AT A CHEAPER PRICES. These cars were seized by government officials at border and the time duration given to the owners to claim their cars has elapse so they are been sold in a give away price. All you need do is to call on 554 OR CALL MRS olorunda glory on 08067834923 OR EMAIL US ON Nigeriacustomauctionservice@yahoo.com WE HAVE THOSE VEHICLE FOR SALE NOW: TOYOTA HIGH LANDER 2003 - 2012 (N500,000) HONDA CRV 2000 - 2009 (N550,000) TOYOTA COROLLA 2003 - 2006 (N300,000) TOYOTA MATRIX 2005 - 2010 (N450,000) TOYOTA ALVALLON 2004 (N500,000) Acura MDX N500,000 Acura TL N400,000 Acura ZDX N700,000 Audi A4 N550,000 Audi A6 N400,000 BMW 3-Series N650,000 BMW 5- Series N450,000 BMW X5 N750,000 BMW X6 N550,000 Ford Escape N600,000 Ford Explorer N500,000 Honda Accord N350,000 Honda City N250,000 Honda Civic N300,000 Honda Crosstour N1,200,000 Honda CR-V N550,000 Honda Odyssey N650,000 Honda Pilot N850,000 Hyundai Accent N550,000 Hyundai Elantra N350,000 Infiniti FX35 N650,000 Infiniti FX45 N700,000 Infiniti QX4 N800,000 Isuzu Trooper N550,000 Jaguar S-Type N300,000 Jeep Liberty N700,000 Kia Sorento N550,000 Land Rover Discovery N800,000 Land Rover Freelander N1,000,000 Land Rover LR3 N850,000 Land Rover LR4 N750,000 Land Rover Range Rover N1,000,000 Land Rover N1500,000 Range Rover Sport N2000,000 Land Rover Vogue N1,000,000 Lexus GS N800,000 Lexus GX460 N600,000 Lexus GX470 N500,000 Lexus LX 570 N450,000 Lexus RX 300 N550,000 Lexus RX 330 N500,000 Lexus RX 350 N600,000 Mazda 6 N300,000 Mazda 626 N400,000 Mazda MPV N450,000 Mazda Tribute N500,000 Mercedes-Benz C-Class N400,000 Mercedes-Benz E-Class N500,000 Mercedes-Benz G-Class N300,000 Mercedes-Benz GLK N200,000 Mercedes-Benz ML N200,000 Mitsubishi Endeavour N350,000 Nissan Altima N300,000 Nissan Armada N550,000 Nissan Maxima N250,000 Nissan Murano N500,000 Nissan Pathfinder N500,000 Nissan Primera N250,000 Nissan Quest N500,000 Nissan Sentra N450,000 Nissan Xterra N400,000 Peugeot 406 N300,000 Peugeot 407 N200,000 Peugeot 607 N300,000 Toyota 4Runner N450,000 Toyota Avalon N500,000 Toyota Avensis N550,000 Toyota Camry N450,000 Toyota Camry 2.2 N350,000 Toyota Corolla N300,000 Toyota FJ Cruiser N650,000 Toyota Hiace N550,000 Toyota Highlander N550,000 Toyota HiLux N1,500,000 Toyota Matrix N370,000 Toyota Prado N900,000 Toyota Rav4 N450,000 Toyota Sequoia N650,000 Toyota Sienna N600,000 Toyota Tacoma N600,000 Toyota Tundra N1,500,000 Toyota Venza N750,000 Toyota Yaris N450,000 Volkswagen Beetle N200,000 Volkswagen Golf N250,000 Volkswagen Jetta N200,000 Volkswagen Passat N250,000 Volkswagen Touareg N300,000 NISSAN XTERA 2002 (N400,000) HONDA ACCORD 2003 (N350,000) HONDA ACCORD 2004 (N450,000) HONDA ACCORD 2009 (Nd50,000) TOYOTA COROLLA 2012 (650,000) TINY LIGHT TOYOTA CAMRY (N400,000)Call MRS olorunda glory 08067834923 Nigeria Custom Market; AUTHORIZED CAR SIGN BY THE FEDERAL REPUBLIC OF NIGERIA.😢
- fish2000 11y agoThis is indeed a great intro article. For those interested in seeing examples of LLVM hacking in action, I would recommend reading the source for Halide – https://github.com/halide/Halide https://github.com/halide/Halide – which is an image-processing DSL implemented in C++ and piggybacking on LLVM. I myself learned a lot about LLVM this way.
- dadrian 11y agoThis would have been great during my grad school compilers class.
- felixangell 11y agoA nice introduction, I'm currently working on a compiler which uses LLVM for code generation... it was very difficult to get into at first. Especially since I was using C (now Go), so I would have to work through 2/3 layers of language and documentation. (Was just C to C++, now it's Go, to C, to C++). If you're interested in learning more about LLVM, there are some good open source projects that use it. If you aren't using C++, people have also ported the kaleidoscope tutorial project to Haskell, Rust, C, etc... Additionally, a lot of bigger compilers like Rust, and Clang use it - Swift also uses LLVM, and should be open source soon?
- slimsag 11y agoBecause I'm curious, could we have a link to your Go project if it's open-source? :)
- andars 11y agohttps://github.com/ark-lang/ark https://github.com/ark-lang/ark
- felixangell 11y agoThat's the one :)
- kd0amg 11y agoWorking with the OCaml bindings feels similar. A lot of the functions are explained as wrapping some particular function from the C++ code, which is itself only explained in the docs with a link to its source implementation.
- johntyree 11y ago> LLVM is nicely written: its architecture is way more modular than other compilers. Part of the reason for this niceness comes from its original implementor, who is one of us. What on earth is that supposd to mean?
- valgaze 11y agoThis isn't germane to the main topic but this paper they cite about using a compiler pass to verify OS security ("Protecting Applications from Hostile Operating Systems") is pretty darn interesting: http://sva.cs.illinois.edu/pubs/VirtualGhost-ASPLOS-2014.pdf http://sva.cs.illinois.edu/pubs/VirtualGhost-ASPLOS-2014.pdf
- regehr 11y agoAdrian might have mentioned an important drawback of using LLVM: active effort is required to keep up with it. Many an LLVM-based research project has gotten stuck on 2.9 or 3.2 at which point it starts becoming less and less relevant. It's not that big of a deal, but active effort is required. The amount of effort depends on how many and which APIs your project uses; for a small/medium project perhaps a couple of hours every couple of weeks.
- samps 11y agoGreat point, John. Can I have a comments section on my site where only you are allowed to comment?
- regehr 11y agoSure :).
- mattgrice 11y agoThis seems like a strange observation. Active effort is required to keep up with any compiler framework, except the ones that aren't going anywhere. LLVM and Clang at least attempt to provide fixed interfaces for interfacing. In contrast The GCC maintainers are actively hostile towards that idea. Honestly, keeping up seems like less of a concern for research projects. Most projects will be abandoned after providing grist for a few papers. The most useful and practical will get integrated back into LLVM. The ones that are not yet practical but of ongoing interest will have multiple groups working on them. A good example of this is Polly.
- regehr 11y agoMany people have observed the LLVM appears to move unusually quickly. This is good except when it's bad.
- sklogic 11y agoI found that sticking to llvm-c interface makes things a bit better.
- tmostak 11y agoThis is a great intro into the subject. We use LLVM to at MapD (http://mapd.com http://mapd.com) to compile SQL queries to CPU and GPU machine code - it has given us a major boost over an interpreter based approach. For more see here - http://devblogs.nvidia.com/parallelforall/mapd-massive-throughput-database-queries-llvm-gpus/ http://devblogs.nvidia.com/parallelforall/mapd-massive-throu.... If you have a background in LLVM or compilers in general and are interested in tackling problems like this please reach out at jobs@mapd.com.
- gct 11y agoAre you guys entertaining remote developers?
- raincom 11y agoDaytona(http://www.research.att.com/projects/Daytona/index.html http://www.research.att.com/projects/Daytona/index.html ), mainly developed by Rick Greer in 1990's, does the same thing. They have implemented superset of SQL; and this SQL is compiled into machine code. Daytona in those days used to parse call records for AT&T. They were processing Terabytes of data when the average laptop had a 20GB hard drive. Rick wrote a paper titled "Daytona And The Fourth-Generation Language Cymbal". You should contact Rick, if you guys need to pick his mind. He is very down to earth man. And he is retired, lives in Morristown, NJ area.
- shepardrtc 11y agoThat link is down, but I found a whitepaper on it: http://web2.research.att.com/export/sites/att_labs/projects/Daytona/AllAboutDaytona.pdf http://web2.research.att.com/export/sites/att_labs/projects/...
- noreasonw 11y agoLong time ago I read a post by Mathew Flatt about LLVM and gcc and how mini optimization and selling points were important not able to find the post, but it was a interesting read.
- PSeitz 11y ago"backed by the largest company on Earth." Wal-Mart?
- _delirium 11y agoBy market cap (or enterprise value), Apple's the largest public company now, worth about $700b, which is about 2x as much as the next biggest (Exxon, Microsoft, etc.). Although Saudi Aramco is probably the world's most valuable company if non-publicly-traded companies are included.
- altctr 11y agoFIXIN I JUST HATE YOU ALLLLLL YOU DONT KNOW ME I PROMISE I WILL MAKE SURE I BECOME YOUR NIGHTMARE BYE
- altctr 11y agoPLEASE KILL TOBIAS STEINER HE OWES ME 28 000 euros because of my webiste sold for 6 mil to atlasean mike from berlin. I am DJ. LG NAMASTE