Value

The LLVM value class is the base class of all the following classes. See LLVM Value Class for more information. Here, we document some of their most useful member functions for our Tiger Compiler.

BasicBlock:

See LLVM Basic Block Representation.

// Creates a new BasicBlock. If the Parent parameter is specified, the basic block is automatically inserted at either the end of
// the function (if InsertBefore is 0), or before the specified basic block.
static BasicBlock *Create (LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr);

Function:

This file contains the declaration of the Function class, which represents a single function/procedure in LLVM. A function consists of a list of basic blocks, a list of arguments, and a symbol table.

// Creates a new function and attaches it to a module.
static Function *Create (FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr);

ConstantInt:

This class represents both boolean and integral constants.

// Return a ConstantInt with the specified value for the specified type.
static ConstantInt *getSigned (IntegerType *Ty, int64_t V);

ConstantPointerNull:

A constant pointer value that points to null.

// Returns object of the specified type.
ConstantPointerNull * ConstantPointerNull::get(PointerType *T);

AllocaInst:

An instruction to allocate memory on the stack.

CallInst:

This class represents a function call, abstracting a target machine’s calling convention.

// Generate the IR for a call to malloc.
static Instruction *CreateMalloc (Instruction *InsertBefore, Type *IntPtrTy, Type *AllocTy, Value *AllocSize,Value
                                  Value *ArraySize=nullptr, Function *MallocF=nullptr, const Twine &Name="");

ConstantExpr:

A constant value that is initialized with an expression using other constant values.

static Constant *getTruncOrBitCast (Constant *C, Type *Ty);

For more information on this method, check out the ‘trunc’ and ‘bitcast’ instructions.

// Computes the (alloc) size of a type (in address-units, not bits) in a target independent way (the return type is an i64).
Constant *ConstantExpr::getSizeOf(Type *Ty)