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 theSmallVector<>
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 <llvm/IR/BasicBlock.h>
: This is the header file that declares theBasicBlock
class, an important IR entity that we already presented.#include <llvm/IR/CallingConv.h>
: This header file defines the set of ABI rules used...