[llvm-dev] RFC: Adding IR Transformation examples/tutorial code to llvm-project

Florian Hahn via llvm-dev llvm-dev at lists.llvm.org
Thu Oct 24 16:46:12 PDT 2019


Hi,

I’d like to propose adding a new example directory (llvm/examples/IRTransforms) as a new home for example code used by various tutorials. After talking to a few people at the Developers meeting, it became clear to me that it would be valuable to have the code examples for various tutorials in-tree to keep them from bit-rotting and make it very easy to build them.

I’d suggest adding new IR pass examples to llvm/examples/IRTransforms. The passes in that directory will be built as an ExamplesIRTransforms library, which exposes initializeExampleIRTransforms to initialise the passes. Additionally, if LLVM_BUILD_EXAMPLES=On, we add a  -DBUILD_EXAMPLES define, which is then used in opt to make the example passes available if LLVM_BUILD_EXAMPLES=On. I think that allows for relatively friction-less integration of the example passes into `opt`.

I’ve put up a patch doing exactly that: https://reviews.llvm.org/D69416 and added a few reviewers, but please join in if you have any thoughts!

Please let me know if you have any concerns or suggestions to improve the CMake setup & co.


As initial example, it contains the code we used for the IR transformations in the 'Getting Started With LLVM: Basics’ tutorial.

I think there were other tutorials with examples that would be great to have there, like 'Writing Loop Optimizations in LLVM’.

As a second step, to make those examples even more valuable, it would be great to provide an accompanying text version of the tutorials. But I would suggest we start with adding the code, which we already have.

Cheers,
Florian


More information about the llvm-dev mailing list