Book Image

Getting started with LLVM core libraries

Book Image

Getting started with LLVM core libraries

Overview of this book

Table of Contents (17 chapters)
Getting Started with LLVM Core Libraries
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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 <llvm/IR/BasicBlock.h>: This is the header file that declares the BasicBlock class, an important IR entity that we already presented.

  • #include <llvm/IR/CallingConv.h>: This header file defines the set of ABI rules...