Writing into a memory location

LLVM uses the store instruction to write into a memory location. There are two arguments to the store instruction: a value to store and an address at which to store it. The store instruction has no return value. Let's say that we want to write a data to the second element of the vector of two integers. The store instruction looks like store i32 3, i32* %a1. To emit the store instruction, we can use the following API provided by LLVM:

void getStore(IRBuilder<> &Builder, Value *Address, Value *V) {
  Builder.CreateStore(V, Address);
}

For example, we will multiply the second element of the <2 x i32> vector by 16 and store it back at the same location.

Consider the following code:

#include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" ...

Get LLVM Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.