O'Reilly logo

Getting Started with LLVM Core Libraries by Rafael Auler, Bruno Cardoso Lopes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing a custom LLVM IR generator

It is possible to use the LLVM IR generator API to programmatically build the IR for sum.ll (created at the -O0 optimization level, that is, without optimizations). In this section, you will see how to do it step by step. First, take a look at which header files are needed:

  • #include <llvm/ADT/SmallVector.h>: This is used to make the SmallVector<> template available, a data structure to aid us in building efficient vectors when the number of elements is not large. Check http://llvm.org/docs/ProgrammersManual.html for help on LLVM data structures.
  • #include <llvm/Analysis/Verifier.h>: The verifier pass is an important analysis that checks whether your LLVM module is well formed with respect to the IR rules.
  • #include ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required