Proteus
Programmable JIT compilation and optimization for C/C++ using LLVM
Loading...
Searching...
No Matches
Public Member Functions | List of all members
proteus::CodeBuilder Class Referenceabstract

#include <CodeBuilder.h>

Inheritance diagram for proteus::CodeBuilder:
Inheritance graph
[legend]

Public Member Functions

virtual ~CodeBuilder ()=default
 
virtual TargetModelType getTargetModel () const =0
 
virtual CodeBuilderKind getBackendKind () const =0
 
virtual IRFunctionaddFunction (const std::string &Name, IRType RetTy, const std::vector< IRType > &ArgTys, bool IsKernel=false)=0
 
virtual void setFunctionName (IRFunction *F, const std::string &Name)=0
 Rename the function identified by F.
 
virtual IRValuegetArg (IRFunction *F, size_t Idx)=0
 Return the Nth argument of F as an IRValue.
 
virtual void beginFunction (IRFunction *F, const char *File, int Line)=0
 Set F as the active function and begin IR emission.
 
virtual void endFunction ()=0
 
virtual void setInsertPointAtEntry ()=0
 
virtual void clearInsertPoint ()=0
 
virtual void beginIf (IRValue *Cond, const char *File, int Line)=0
 
virtual void endIf ()=0
 
virtual void beginFor (IRValue *IterSlot, IRType IterTy, IRValue *InitVal, IRValue *UpperBoundVal, IRValue *IncVal, bool IsSigned, const char *File, int Line, LoopHints Hints={})=0
 
virtual void endFor ()=0
 
virtual void beginWhile (std::function< IRValue *()> CondFn, const char *File, int Line)=0
 
virtual void endWhile ()=0
 
virtual void createRetVoid ()=0
 
virtual void createRet (IRValue *V)=0
 
virtual IRValuecreateArith (ArithOp Op, IRValue *LHS, IRValue *RHS, IRType Ty)=0
 
virtual IRValuecreateAtomicAdd (IRValue *Addr, IRValue *Val)=0
 
virtual IRValuecreateAtomicSub (IRValue *Addr, IRValue *Val)=0
 
virtual IRValuecreateAtomicMax (IRValue *Addr, IRValue *Val)=0
 
virtual IRValuecreateAtomicMin (IRValue *Addr, IRValue *Val)=0
 
virtual IRValuecreateCmp (CmpOp Op, IRValue *LHS, IRValue *RHS, IRType Ty)=0
 
virtual IRValuecreateAnd (IRValue *LHS, IRValue *RHS)=0
 
virtual IRValuecreateOr (IRValue *LHS, IRValue *RHS)=0
 
virtual IRValuecreateXor (IRValue *LHS, IRValue *RHS)=0
 
virtual IRValuecreateNot (IRValue *Val)=0
 
virtual IRValuecreateLoad (IRType Ty, IRValue *Ptr, const std::string &Name="")=0
 
virtual void createStore (IRValue *Val, IRValue *Ptr)=0
 
virtual IRValuecreateCast (IRValue *V, IRType FromTy, IRType ToTy)=0
 
virtual IRValuecreateBitCast (IRValue *V, IRType DestTy)=0
 
virtual IRValuecreateZExt (IRValue *V, IRType DestTy)=0
 
virtual IRValuegetConstantInt (IRType Ty, uint64_t Val)=0
 
virtual IRValuegetConstantFP (IRType Ty, double Val)=0
 
virtual VarAlloc getElementPtr (IRValue *Base, IRType BaseTy, IRValue *Index, IRType ElemTy)=0
 
virtual VarAlloc getElementPtr (IRValue *Base, IRType BaseTy, size_t Index, IRType ElemTy)=0
 
virtual IRValuecreateCall (const std::string &FName, IRType RetTy, const std::vector< IRType > &ArgTys, const std::vector< IRValue * > &Args)=0
 
virtual IRValuecreateCall (const std::string &FName, IRType RetTy)=0
 
virtual IRValueemitIntrinsic (const std::string &Name, IRType RetTy, const std::vector< IRValue * > &Args)=0
 Lower a frontend intrinsic name to backend IR.
 
virtual IRValueemitBuiltin (const std::string &Name, IRType RetTy, const std::vector< IRValue * > &Args)=0
 
virtual IRValueloadScalar (IRValue *Slot, IRType ValueTy)=0
 Load the value stored directly in Slot (scalar alloca).
 
virtual void storeScalar (IRValue *Slot, IRValue *Val)=0
 Store Val directly into Slot (scalar alloca).
 
virtual IRValueloadAddress (IRValue *Slot, IRType AllocTy)=0
 Load the pointer stored in Slot (pointer alloca).
 
virtual void storeAddress (IRValue *Slot, IRValue *Addr)=0
 Store Addr into Slot (pointer alloca).
 
virtual IRValueloadFromPointee (IRValue *Slot, IRType AllocTy, IRType ValueTy)=0
 Dereference the pointer stored in Slot, then load the pointee.
 
virtual void storeToPointee (IRValue *Slot, IRType AllocTy, IRValue *Val)=0
 Dereference the pointer stored in Slot, then store Val to it.
 
virtual VarAlloc allocScalar (const std::string &Name, IRType ValueTy)=0
 
virtual VarAlloc allocPointer (const std::string &Name, IRType ElemTy, unsigned AddrSpace=0)=0
 
virtual VarAlloc allocArray (const std::string &Name, AddressSpace AS, IRType ElemTy, size_t NElem)=0
 

Detailed Description

Abstract code-builder interface. The frontend (Var.h, Func.h, LoopNest.h) depends only on this class.

Constructor & Destructor Documentation

◆ ~CodeBuilder()

virtual proteus::CodeBuilder::~CodeBuilder ( )
virtualdefault

Member Function Documentation

◆ addFunction()

virtual IRFunction * proteus::CodeBuilder::addFunction ( const std::string &  Name,
IRType  RetTy,
const std::vector< IRType > &  ArgTys,
bool  IsKernel = false 
)
pure virtual

Create a function with the given name and signature. Kernel intent is explicit so backends can select the correct IR container up front. Returns an opaque IRFunction handle owned by this builder.

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ allocArray()

virtual VarAlloc proteus::CodeBuilder::allocArray ( const std::string &  Name,
AddressSpace  AS,
IRType  ElemTy,
size_t  NElem 
)
pure virtual

◆ allocPointer()

virtual VarAlloc proteus::CodeBuilder::allocPointer ( const std::string &  Name,
IRType  ElemTy,
unsigned  AddrSpace = 0 
)
pure virtual

◆ allocScalar()

virtual VarAlloc proteus::CodeBuilder::allocScalar ( const std::string &  Name,
IRType  ValueTy 
)
pure virtual

◆ beginFor()

virtual void proteus::CodeBuilder::beginFor ( IRValue IterSlot,
IRType  IterTy,
IRValue InitVal,
IRValue UpperBoundVal,
IRValue IncVal,
bool  IsSigned,
const char *  File,
int  Line,
LoopHints  Hints = {} 
)
pure virtual

IterSlot : alloca holding the loop iterator. IterTy : value type of the iterator (must be an integer type). InitVal : initial value to store into IterSlot. UpperBoundVal : exclusive upper bound for the loop condition. IncVal : increment added to the iterator on each iteration. IsSigned : true → ICmpSLT, false → ICmpULT.

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ beginFunction()

virtual void proteus::CodeBuilder::beginFunction ( IRFunction F,
const char *  File,
int  Line 
)
pure virtual

Set F as the active function and begin IR emission.

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ beginIf()

virtual void proteus::CodeBuilder::beginIf ( IRValue Cond,
const char *  File,
int  Line 
)
pure virtual

◆ beginWhile()

virtual void proteus::CodeBuilder::beginWhile ( std::function< IRValue *()>  CondFn,
const char *  File,
int  Line 
)
pure virtual

CondFn : callable that emits the condition IR at the current insert point and returns the resulting i1 Value (true → continue loop).

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ clearInsertPoint()

virtual void proteus::CodeBuilder::clearInsertPoint ( )
pure virtual

◆ createAnd()

virtual IRValue * proteus::CodeBuilder::createAnd ( IRValue LHS,
IRValue RHS 
)
pure virtual

◆ createArith()

virtual IRValue * proteus::CodeBuilder::createArith ( ArithOp  Op,
IRValue LHS,
IRValue RHS,
IRType  Ty 
)
pure virtual

◆ createAtomicAdd()

virtual IRValue * proteus::CodeBuilder::createAtomicAdd ( IRValue Addr,
IRValue Val 
)
pure virtual

◆ createAtomicMax()

virtual IRValue * proteus::CodeBuilder::createAtomicMax ( IRValue Addr,
IRValue Val 
)
pure virtual

◆ createAtomicMin()

virtual IRValue * proteus::CodeBuilder::createAtomicMin ( IRValue Addr,
IRValue Val 
)
pure virtual

◆ createAtomicSub()

virtual IRValue * proteus::CodeBuilder::createAtomicSub ( IRValue Addr,
IRValue Val 
)
pure virtual

◆ createBitCast()

virtual IRValue * proteus::CodeBuilder::createBitCast ( IRValue V,
IRType  DestTy 
)
pure virtual

◆ createCall() [1/2]

virtual IRValue * proteus::CodeBuilder::createCall ( const std::string &  FName,
IRType  RetTy 
)
pure virtual

◆ createCall() [2/2]

virtual IRValue * proteus::CodeBuilder::createCall ( const std::string &  FName,
IRType  RetTy,
const std::vector< IRType > &  ArgTys,
const std::vector< IRValue * > &  Args 
)
pure virtual

◆ createCast()

virtual IRValue * proteus::CodeBuilder::createCast ( IRValue V,
IRType  FromTy,
IRType  ToTy 
)
pure virtual

◆ createCmp()

virtual IRValue * proteus::CodeBuilder::createCmp ( CmpOp  Op,
IRValue LHS,
IRValue RHS,
IRType  Ty 
)
pure virtual

◆ createLoad()

virtual IRValue * proteus::CodeBuilder::createLoad ( IRType  Ty,
IRValue Ptr,
const std::string &  Name = "" 
)
pure virtual

◆ createNot()

virtual IRValue * proteus::CodeBuilder::createNot ( IRValue Val)
pure virtual

◆ createOr()

virtual IRValue * proteus::CodeBuilder::createOr ( IRValue LHS,
IRValue RHS 
)
pure virtual

◆ createRet()

virtual void proteus::CodeBuilder::createRet ( IRValue V)
pure virtual

◆ createRetVoid()

virtual void proteus::CodeBuilder::createRetVoid ( )
pure virtual

◆ createStore()

virtual void proteus::CodeBuilder::createStore ( IRValue Val,
IRValue Ptr 
)
pure virtual

◆ createXor()

virtual IRValue * proteus::CodeBuilder::createXor ( IRValue LHS,
IRValue RHS 
)
pure virtual

◆ createZExt()

virtual IRValue * proteus::CodeBuilder::createZExt ( IRValue V,
IRType  DestTy 
)
pure virtual

◆ emitBuiltin()

virtual IRValue * proteus::CodeBuilder::emitBuiltin ( const std::string &  Name,
IRType  RetTy,
const std::vector< IRValue * > &  Args 
)
pure virtual

Lower a frontend GPU builtin name to backend IR. Returns nullptr for void builtins (e.g. syncThreads).

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ emitIntrinsic()

virtual IRValue * proteus::CodeBuilder::emitIntrinsic ( const std::string &  Name,
IRType  RetTy,
const std::vector< IRValue * > &  Args 
)
pure virtual

Lower a frontend intrinsic name to backend IR.

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ endFor()

virtual void proteus::CodeBuilder::endFor ( )
pure virtual

◆ endFunction()

virtual void proteus::CodeBuilder::endFunction ( )
pure virtual

◆ endIf()

virtual void proteus::CodeBuilder::endIf ( )
pure virtual

◆ endWhile()

virtual void proteus::CodeBuilder::endWhile ( )
pure virtual

◆ getArg()

virtual IRValue * proteus::CodeBuilder::getArg ( IRFunction F,
size_t  Idx 
)
pure virtual

Return the Nth argument of F as an IRValue.

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ getBackendKind()

virtual CodeBuilderKind proteus::CodeBuilder::getBackendKind ( ) const
pure virtual

◆ getConstantFP()

virtual IRValue * proteus::CodeBuilder::getConstantFP ( IRType  Ty,
double  Val 
)
pure virtual

◆ getConstantInt()

virtual IRValue * proteus::CodeBuilder::getConstantInt ( IRType  Ty,
uint64_t  Val 
)
pure virtual

◆ getElementPtr() [1/2]

virtual VarAlloc proteus::CodeBuilder::getElementPtr ( IRValue Base,
IRType  BaseTy,
IRValue Index,
IRType  ElemTy 
)
pure virtual

◆ getElementPtr() [2/2]

virtual VarAlloc proteus::CodeBuilder::getElementPtr ( IRValue Base,
IRType  BaseTy,
size_t  Index,
IRType  ElemTy 
)
pure virtual

◆ getTargetModel()

virtual TargetModelType proteus::CodeBuilder::getTargetModel ( ) const
pure virtual

◆ loadAddress()

virtual IRValue * proteus::CodeBuilder::loadAddress ( IRValue Slot,
IRType  AllocTy 
)
pure virtual

Load the pointer stored in Slot (pointer alloca).

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ loadFromPointee()

virtual IRValue * proteus::CodeBuilder::loadFromPointee ( IRValue Slot,
IRType  AllocTy,
IRType  ValueTy 
)
pure virtual

Dereference the pointer stored in Slot, then load the pointee.

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ loadScalar()

virtual IRValue * proteus::CodeBuilder::loadScalar ( IRValue Slot,
IRType  ValueTy 
)
pure virtual

Load the value stored directly in Slot (scalar alloca).

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ setFunctionName()

virtual void proteus::CodeBuilder::setFunctionName ( IRFunction F,
const std::string &  Name 
)
pure virtual

Rename the function identified by F.

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ setInsertPointAtEntry()

virtual void proteus::CodeBuilder::setInsertPointAtEntry ( )
pure virtual

◆ storeAddress()

virtual void proteus::CodeBuilder::storeAddress ( IRValue Slot,
IRValue Addr 
)
pure virtual

Store Addr into Slot (pointer alloca).

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ storeScalar()

virtual void proteus::CodeBuilder::storeScalar ( IRValue Slot,
IRValue Val 
)
pure virtual

Store Val directly into Slot (scalar alloca).

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.

◆ storeToPointee()

virtual void proteus::CodeBuilder::storeToPointee ( IRValue Slot,
IRType  AllocTy,
IRValue Val 
)
pure virtual

Dereference the pointer stored in Slot, then store Val to it.

Implemented in proteus::LLVMCodeBuilder, and proteus::MLIRCodeBuilder.


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