Joos1W Compiler Framework
All Classes Functions Typedefs Pages
tir::IRBuilder Class Reference

Public Member Functions

 IRBuilder (Context &ctx)
 
void setInsertPoint (BasicBlock::iterator it)
 Set the insertion point to the given basic block. This will insert new instructions after the given instruction iterator. More...
 
void setInsertPoint (Instruction *instr)
 Set the insertion point to the given instruction. This will insert new instructions after the given instruction. More...
 
void setInsertPoint (BasicBlock *bb)
 Set the insertion point to the beginning of the given basic block. More...
 
BasicBlockcurrentBlock ()
 
BasicBlockcreateBasicBlock (Function *parent)
 Create a new basic block within the given function. This does not change the insertion point, unlike the other create functions. More...
 
InstructioncreateBinaryInstr (Instruction::BinOp op, Value *lhs, Value *rhs)
 Create a binary instruction with the given operation and left-hand and right-hand operands (as values). More...
 
InstructioncreateCallInstr (Value *callee, utils::range_ref< Value * > args)
 Create a call instruction with the given callee and arguments. More...
 
InstructioncreateLoadInstr (Type *type, Value *ptr)
 Create a load instruction with the given type and pointer. The type is the type of the value to load and will dictate the size of the load operation. The ptr is the pointer to load from. More...
 
InstructioncreateStoreInstr (Value *val, Value *ptr)
 Create a store instruction with the given value and pointer. The value is the value to store and the ptr is the pointer to store to. More...
 
InstructioncreateReturnInstr (Value *val)
 Create a return instruction with the given value. More...
 
InstructioncreateReturnInstr ()
 Create a return instruction with no value (void). More...
 
InstructioncreateBranchInstr (BasicBlock *target)
 Creates an unconditional branch instruction to the given target basic block. More...
 
InstructioncreateBranchInstr (Value *cond, BasicBlock *true_target, BasicBlock *false_target)
 Create a conditional branch instruction with the given condition and true and false target basic blocks. More...
 
InstructioncreateCmpInstr (CmpInst::Predicate pred, Value *lhs, Value *rhs)
 Create a comparison instruction with the given predicate and left-hand and right-hand operands. More...
 
InstructioncreateICastInstr (ICastInst::CastOp op, Value *val, Type *destTy)
 Create the generic trunc/zext/sext instruction with the given operation, value, and destination type. More...
 
InstructioncreateGEPInstr (Value *ptr, StructType *t, utils::range_ref< Value * > indices)
 

Detailed Description

Definition at line 10 of file IRBuilder.h.

Member Function Documentation

◆ createBasicBlock()

BasicBlock* tir::IRBuilder::createBasicBlock ( Function parent)
inline

Create a new basic block within the given function. This does not change the insertion point, unlike the other create functions.

Parameters
parentThe parent function of the basic block
Returns
BasicBlock* The new (empty) basic block

Definition at line 51 of file IRBuilder.h.

51  {
52  return BasicBlock::Create(ctx_, parent);
53  }

◆ createBinaryInstr()

Instruction* tir::IRBuilder::createBinaryInstr ( Instruction::BinOp  op,
Value lhs,
Value rhs 
)
inline

Create a binary instruction with the given operation and left-hand and right-hand operands (as values).

Parameters
opThe binary operation to perform
lhsThe LHS value
rhsThe RHS value
Returns
BinaryInst* A pointer to the instruction

Definition at line 64 of file IRBuilder.h.

64  {
65  return insert(BinaryInst::Create(ctx_, op, lhs, rhs));
66  }

◆ createBranchInstr() [1/2]

Instruction* tir::IRBuilder::createBranchInstr ( BasicBlock target)
inline

Creates an unconditional branch instruction to the given target basic block.

Parameters
targetThe target basic block
Returns
BranchInst* A pointer to the instruction

Definition at line 130 of file IRBuilder.h.

130  {
131  return createBranchInstr(Constant::CreateBool(ctx_, true), target, target);
132  }
Instruction * createBranchInstr(BasicBlock *target)
Creates an unconditional branch instruction to the given target basic block.
Definition: IRBuilder.h:130

◆ createBranchInstr() [2/2]

Instruction* tir::IRBuilder::createBranchInstr ( Value cond,
BasicBlock true_target,
BasicBlock false_target 
)
inline

Create a conditional branch instruction with the given condition and true and false target basic blocks.

Parameters
condThe condition to branch on
true_targetThe target basic block if the condition is true
false_targetThe target basic block if the condition is false
Returns
BranchInst* A pointer to the instruction

Definition at line 143 of file IRBuilder.h.

144  {
145  return insert(BranchInst::Create(ctx_, cond, true_target, false_target));
146  }

◆ createCallInstr()

Instruction* tir::IRBuilder::createCallInstr ( Value callee,
utils::range_ref< Value * >  args 
)
inline

Create a call instruction with the given callee and arguments.

Parameters
calleeThe function to call
argsThe arguments to pass to the function
Returns
CallInst* A pointer to the instruction

Definition at line 75 of file IRBuilder.h.

75  {
76  return insert(CallInst::Create(ctx_, callee, args));
77  }

◆ createCmpInstr()

Instruction* tir::IRBuilder::createCmpInstr ( CmpInst::Predicate  pred,
Value lhs,
Value rhs 
)
inline

Create a comparison instruction with the given predicate and left-hand and right-hand operands.

Parameters
predThe comparison predicate
lhsThe LHS value
rhsThe RHS value
Returns
CmpInst* A pointer to the instruction

Definition at line 157 of file IRBuilder.h.

157  {
158  return insert(CmpInst::Create(ctx_, pred, lhs, rhs));
159  }

◆ createICastInstr()

Instruction* tir::IRBuilder::createICastInstr ( ICastInst::CastOp  op,
Value val,
Type destTy 
)
inline

Create the generic trunc/zext/sext instruction with the given operation, value, and destination type.

Parameters
opThe cast operation to perform
valThe value to cast
destTyThe destination type
Returns
Instruction* The created instruction

Definition at line 170 of file IRBuilder.h.

170  {
171  return insert(ICastInst::Create(ctx_, op, val, destTy));
172  }

◆ createLoadInstr()

Instruction* tir::IRBuilder::createLoadInstr ( Type type,
Value ptr 
)
inline

Create a load instruction with the given type and pointer. The type is the type of the value to load and will dictate the size of the load operation. The ptr is the pointer to load from.

Parameters
typeThe type of the value to load
ptrThe pointer to load from
Returns
LoadInst* A pointer to the instruction

Definition at line 88 of file IRBuilder.h.

88  {
89  return insert(LoadInst::Create(ctx_, type, ptr));
90  }

◆ createReturnInstr() [1/2]

Instruction* tir::IRBuilder::createReturnInstr ( )
inline

Create a return instruction with no value (void).

Returns
ReturnInst* A pointer to the instruction

Definition at line 119 of file IRBuilder.h.

119  {
120  return insert(ReturnInst::Create(ctx_, nullptr));
121  }

◆ createReturnInstr() [2/2]

Instruction* tir::IRBuilder::createReturnInstr ( Value val)
inline

Create a return instruction with the given value.

Parameters
valThe value to return
Returns
ReturnInst* A pointer to the instruction

Definition at line 110 of file IRBuilder.h.

110  {
111  return insert(ReturnInst::Create(ctx_, val));
112  }

◆ createStoreInstr()

Instruction* tir::IRBuilder::createStoreInstr ( Value val,
Value ptr 
)
inline

Create a store instruction with the given value and pointer. The value is the value to store and the ptr is the pointer to store to.

Parameters
valThe value to store
ptrThe pointer to store to
Returns
StoreInst* A pointer to the instruction

Definition at line 100 of file IRBuilder.h.

100  {
101  return insert(StoreInst::Create(ctx_, val, ptr));
102  }

◆ setInsertPoint() [1/3]

void tir::IRBuilder::setInsertPoint ( BasicBlock bb)
inline

Set the insertion point to the beginning of the given basic block.

Parameters
bbThe basic block to set the insertion point to

Definition at line 35 of file IRBuilder.h.

35  {
36  insertPoint_ = bb->begin();
37  }

◆ setInsertPoint() [2/3]

void tir::IRBuilder::setInsertPoint ( BasicBlock::iterator  it)
inline

Set the insertion point to the given basic block. This will insert new instructions after the given instruction iterator.

Parameters
itThe iterator to set the insertion point to

Definition at line 20 of file IRBuilder.h.

20 { insertPoint_ = it; }

◆ setInsertPoint() [3/3]

void tir::IRBuilder::setInsertPoint ( Instruction instr)
inline

Set the insertion point to the given instruction. This will insert new instructions after the given instruction.

Parameters
instrThe instruction to set the insertion point to

Definition at line 28 of file IRBuilder.h.

28 { setInsertPoint(instr->iter()); }
void setInsertPoint(BasicBlock::iterator it)
Set the insertion point to the given basic block. This will insert new instructions after the given i...
Definition: IRBuilder.h:20

The documentation for this class was generated from the following file: