Emitting a simple arithmetic statement in a basic block

A basic block consists of a list of instructions. For example, an instruction can be a simple statement performing tasks based on some simple arithmetic instruction. We will see how the LLVM API can be used to emit arithmetic instructions.

For example, if we want to multiply first argument a with integer value 16, we will create a constant integer value 16 with the following API:

Value *constant = Builder.getInt32(16);

We already have a from the function argument list:

Value *Arg1 = fooFunc->arg_begin();

LLVM provides a rich list of API's to create binary operations. You can go through the include/llvm/IR/IRBuild.h file for more details on the APIs.

Value *createArith(IRBuilder<> &Builder, ...

Get LLVM Essentials now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.