[LLVMdev] Simplifying a front-end project

John McCall rjmccall at apple.com
Tue Aug 25 15:33:53 PDT 2009


Vikram S. Adve wrote:
> For the translator in step (2), I've so far had them generate LLVM IR  
> in memory using the LLVM APIs.  They find it a *lot* of work to learn  
> the LLVM APIs, which doesn't teach them much about compiler concepts  
> per se.  To simplify this project, I am considering changing the  
> project so they "print out" LLVM assembly directly instead of building  
> up the IR in memory and writing it out.
>   

I've found the LLVM API to be pretty easy to work with, at least by 
life's generally poor standards.  I don't know UIUC's program at all, 
but I would guess there are 2-3 main problems your students are having:
1.  The API is huge, and the autogenerated documentation is badly 
organized, especially for beginners.
2.  The API assumes that users are familiar with various C++ idioms, 
particularly iterators.
3.  The API assumes that users are familiar with C++.

The first point can be addressed with some "beginner's documentation" 
which highlights the important classes and their core operations.  The 
second point can be helped with a lot of directed examples;  I know 
there's some of this on the wiki already.  The third point is somewhat 
harder to solve.

> Question: Is there a convenient way to print out the LLVM assembly  
> correctly without having build the IR first?  Getting the syntax right  
> for all the types, declarations, functions, instructions, etc., is non- 
> trivial also and the less error-prone we can make it for them, the  
> better.
>   

Well, you could certainly do step 2 (the translator) by having the 
students write out LLVM assembly in text format (.ll), then assembling 
that (llvm-as) and, if required, loading the assembled bitcode.  But 
that won't really help you in step 3 unless you want them to write a 
text-to-text pass, which would be hugely painful for all but very 
specific and trivial transformations.  At some point, if they're going 
to use LLVM, they have to learn the API.

...well, unless you teach it in some other language with 
actively-maintained LLVM bindings (e.g. ocaml).

John.



More information about the llvm-dev mailing list