Some Tips for Me

Hello everyone,
I want to develop projects with LLVM, so I am new in LLVM (not new in programming and computer architecture). Is there anybody to help me to make a roadmap to learn LLVM? How can I find resources, and from where? I do not have enough information to start to learn LLVM.
Thanks.

1 Like

I’ll give it a try. First of all, welcome!

I’d say the first question to answer is: What are you interested in? Compilers ? Linkers ? Debuggers ?
LLVM is an umbrella with all kinds of projects.

Assuming that you’re interested in compilers, as I guess most people, are you interested in front-end, middle-end or back-end ?

If you don’t have a general knowledge of compilers, let me make a (probably bad) attempt at explaining them really fast:

  • Front-end: It takes your e.g., C code, understands its structure and semantics and outputs some intermediate representation of the code. This is passed to the “middle-end”
  • Middle-end: It does “target-independent” optimizations i.e., (theoretically) they don’t depend on whether you’re compiling for x86, arm etc. Things like loop-unrolling, inlining etc.
  • Back-end: It does target-dependent optimizations (e.g., instruction selection; what instructions of the ISA am I going to use?) and then outputs assembly.

Some initial resources overlap between these, but at least the distinction between front-end and the other two is important.

Best,
Stefanos

1 Like

First, thank you for your reply and your kind welcome. :] I want to explain myself simply. I am interested in compilers (as I understand from your reply). I am aware of this distinction anymore, thanks.
My professor at my college told about LLVM like that “The developers use it to translate source code to machine language(or assembly I don’t know) with machine independency. You write some program and LLVM makes it executable in various of machines.”, and he gave an example about Apple. He did not provide enough information to me because he is not interested in a lot.

Please, stay in touch with me.

Thanks.

Ok, I think I get it. It seems that it’s not clear how LLVM (or most modern compilers) achieves that on the high-level. The best place to learn that would be a lecture but unfortunately I can’t find one that addresses this hugely important point. So, I’ll give a quick try myself.

Imagine that you have a C compiler which translates your code to x86 assembly. Then, you write a couple of optimizations that act on x86 assembly i.e., you take C, you generate some dumb x86 asm at first and then you just hammer on that asm over and over to optimize it. Note here that a lot of your optimizations actually have nothing to do with your target. For example, here:

for (int i = 0; i < n; ++i) {
v = 1 + 2;
A[i] = v;
}

The architecture really doesn’t matter on the fact that v is loop-invariant. i.e., we can compute it once outside the loop and then just use it. So, you have written a bunch of optimizations in x86 assembly when in fact the concepts are more high-level and independent of the target.

Ok, now imagine that you want your compiler to also generate MIPS. Your only option is basically to make some kind of translator from x86 to MIPS. As you add targets, you would have to do that for every target. But here’s the most important problem.

You don’t have any freedom on how x86 assembly is designed :slight_smile: Combine that with the fact that a lot of your optimizations have nothing to do with x86 asm specifically whatsoever. So, why don’t you design an “assembly” (or more precisely called intermediate representation or IR) the way you want it ? i.e. the way it serves your optimizations / transformations the best ?

Then, translate that (one version of code) to x86, MIPS etc. This is an immensely important point IMHO.

This is one reason target-independent IRs were introduced. The middle-end of LLVM acts on LLVM IR, an IR designed to serve target-independent optimizations the best way possible. Then, that gets translated to x86, MIPS etc (by the back-end).

Hopefully that made sense, please let me know if it didn’t.

Alright, now again I’m not sure whether you’re more interested again in the front-end, middle-end or back-end. To phrase them in terms of IR, now that it’s (hopefully) more understood. The front-end takes e.g., C code and generates some trivial, completely unoptimized LLVM IR. The middle-end takes this IR and tries to apply target-independent optimizations to it. When it’s done, it gives that (in a different form but anyway) to the back-end which does target-dependent optimizations (because such exist too) and finally generates assemmbly.

Best,
Stefanos

1 Like

It made sense completely and absolutely. What a clear expression!

I associated your explanation and my professor’s sayings and I came to a conclusion that I am more interested in back-end ( or middle-end, I am not sure. I will try to explain what I want to learn). My professor told that while they were developing a micro-processor with their own instruction set, one of his students tried to use LLVM to translate some type of code to assemmbly using their instruction set.

I have some problems while I am explaining because people who are interested in this case are very little in my country and I do not have enough source to learn developing with LLVM, also I do not know how I look for. Nobody can guide me. Do you suggest any sources?

Also, could you tell about yourself? What is your interest within LLVM?

Thanks,
Ä°rem

Alright so… I tried to reply posting some links to the LLVM conference youtube talks. But my posts were taken down by Discourse and they sent me a message that it is considered spam or promotion…
Let repeat as it wasn’t funny enough the first time: It considered spam or promotion sending LLVM talks to the LLVM discourse. Yeah I guess why not :stuck_out_tongue:

Anyway, here’s my message again. I’m going to have the titles only. I hope that you can just type them on youtube and you should find the videos.

It made sense completely and absolutely. What a clear expression!

Glad it made sense :slight_smile: Thanks, btw

So, from what I can understand, you have a custom instruction set and you want to say translate
C to this ISA. Now, note that the choice of the source language is important. If you want to translate some language that LLVM does not have a front-end for, then you need a front-end for LLVM (i.e., something that translates your language to LLVM IR) and that’s a completely different story.

Anyway, that’s probably not the case though, so what you’re interested in is something that takes
LLVM IR (after LLVM has done any target-independent optimizations [1] it could) and translate to your ISA. And there unfortunately I can’t help :confused: Because, I have very little experience with the
back-end.

But let me try to propose some sources anyway. First, even if you’re interested in the back-end, you’re probably not going to be able to work with LLVM without a fundamental knowledge of the middle-end (both because you’ll have to interact with it and because a lot of ideas have been tranferred to the back-end).

(Here come the titles)

  1. 2019 LLVM Developers’ Meeting: E. Christopher & J. Doerfert “Introduction to LLVM”
  2. 2019 EuroLLVM Developers’ Meeting: V. Bridgers & F. Piovezan “LLVM IR Tutorial - Phis, GEPs …”
  3. LLVM Basics: 2019 LLVM Developers’ Meeting: J. Paquette & F. Hahn “Getting Started With LLVM: Basics”

Back-end specific stuff (I have not watched those from start to finish):

  1. 2014 LLVM Developers’ Meeting: “Building an LLVM Backend ”
  2. 2009 LLVM Developers’ Meeting: “Tutorial: Building backend in 24 hours” (that’s good but old)
  3. 2017 LLVM Developers’ Meeting: M. Braun “Welcome to the back-end: The LLVM machine representation” (essential if you’re going to do anything with LLVM back-end)

And some things that you might find interesting:

  1. 2018 LLVM Developers’ Meeting: M. Braun “Register Allocation: More than Coloring”
  2. 2019 LLVM Developers’ Meeting: M. Arsenault “Address Spaces in LLVM”

Above all, you definitely want to seek further help from the community. e.g., in the discord channel and/or the mailing list.

Also, could you tell about yourself? What is your interest within LLVM?

I am working mostly on the middle-end and the last couple of months, I have been working downstream. Hopefully some of the things will make it to upstream :slight_smile: My main interest is loop optimizations.
But maybe the important thing, related to me, for our discussion is that I was what I’d call a super-beginner recently (about a year ago). So, I know how it feels to be lost in LLVM.

[1] Btw, I keep saying target-independent. They’re not really, but I want to avoid confusion.

2 Likes

I achieved the videos, thanks. :smiley: I am sorry to cause this “flagged” problem.

I feel very lucky because I come across with you, so I have basic information what I will look for anymore. Thanks for trying to understand me and spending your time.

I cannot gain the access to join the channel, LLVM Community Code of Conduct — LLVM 12 documentation this link does not available now. (Edit: it was my fault, the link is not broken)

Finally, again thanks for your help. I hope one day, I use this platform to disscuss not for learning tips (Iike this post :d ).

Take care of yourself,
Ä°rem

1 Like

I feel very lucky because I come across with you, so I have basic information what I will look for anymore. Thanks for trying to understand me and spending your time.

No problem, good luck!

I cannot gain the access to join the channel

The Discord channel? Hmm… I’m not sure about that. Maybe you can try asking on the mailing list.

Finally, again thanks for your help. I hope one day, I use this platform to disscuss not for learning tips (Iike this post :d ).

Sure, welcome to LLVM :slight_smile: (asking for tips is totally ok btw, AFAIK, everybody needs that and people
are usually happy to help)

Kind regards,
Stefanos

1 Like

Hey!
I’m Rishik ,new to this community. I have followed the thread till the end
I have few questions

  1. How do i get started with front end here (I have prior knowledge about compilers)
  2. How can i contribute to frontend
    I saw you as Middle end person but any suggestion would be greatful to get started
    Thanks

Hi Rishik,

I think a good first step would be this video 2019 LLVM Develope
This will give you an overview of Clang.
Then, you can watch this: 2019 LLVM Developers’ Meeting: C. Bieneman & K. Barton “How to Contribute to LLVM ” - YouTube
because it’ll give you some useful guidelines for contributing in LLVM projects in general.

Now, to actually contribute, I would do these:

  1. Find bugs tagged with “beginner” bugs for “clang”. I didn’t have much luck with this when I was starting out but it’s worth at least taking a look
  2. Other than that, I would join cfe-dev and LLVM’s Discord and I would simply ask people what can I do. I think people will be willing to provide concrete things.

Hope this helps,
Stefanos

1 Like