Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

code examples for learning LLVM backend programming

I am learning programming LLVM backends.

Currently I am interested in analysis passes, later program transformations. (I assume as I will be more fluent with analysis then will be time for program transformations).

Could you recommend resources for learning ? (I know LLVM Programmers manual and Dragon Book ;) ).

By resources I mean not only tutorials, books, but especially small well-written projects. I'd like to read code examples, compile them and play with them (hack a little bit) to learn more about practical implementation.

Those codes does not have to be restricted to analysis part. The topic is LLVM backend programming in general, while analysis and program transformations are most interesting.

like image 770
Grzegorz Wierzowiecki Avatar asked Jan 08 '12 10:01

Grzegorz Wierzowiecki


People also ask

What is LLVM backend?

The backend of LLVM features a target-independent code generator that may create output for several types of target CPUs — including X86, PowerPC, ARM, and SPARC. The backend may also be used to generate code targeted at SPUs of the Cell processor or GPUs to support the execution of compute kernels.

Is LLVM written in C++?

LLVM is written in C++ and is designed for compile-time, link-time, run-time, and "idle-time" optimization.

Is C++ an LLVM?

LLVM itself is written in C++. LLVM's APIs are available in C and C++ incarnations.

Is LLVM IR a programming language?

LLVM IR is a low-level intermediate representation used by the LLVM compiler framework. You can think of LLVM IR as a platform-independent assembly language with an infinite number of function local registers.


2 Answers

All LLVM transformations are organized as self-contained passes inside lib/Transforms dir, You can read its sources and run any arbitrary pass on your code using opt tool.

Also, there is nice tutorial on how to write your own pass and use it as loadable module without recompiling whole LLVM.

So there is pretty wide playground already.

like image 98
arrowd Avatar answered Sep 22 '22 09:09

arrowd


As someone that did what you want to do 3 years ago: LLVM codebase has the best examples. Maybe a good place to start is dominator analysis, as it is well described in compiler books.

Check how it is done in LLVM: http://llvm.org/doxygen/Dominators_8h_source.html

Other place to look might be instruction scheduling.

like image 34
mentatkgs Avatar answered Sep 23 '22 09:09

mentatkgs