1#ifndef PROTEUS_FRONTEND_LLVM_CODE_BUILDER_H
2#define PROTEUS_FRONTEND_LLVM_CODE_BUILDER_H
33 std::unique_ptr<llvm::Module> Mod,
66 llvm::BasicBlock *InsertBefore =
nullptr);
74 llvm::BasicBlock *NextBlock);
79 void createBr(llvm::BasicBlock *Dest);
81 llvm::BasicBlock *False);
106 const std::string &Name);
112 const std::vector<IRType> &ArgTys,
113 bool IsKernel =
false)
override;
129 void endIf()
override;
132 const char *File,
int Line,
LoopHints Hints = {})
override;
171 const std::string &Name =
"")
override;
199 const std::vector<IRType> &ArgTys,
200 const std::vector<IRValue *> &
Args)
override;
203 const std::vector<IRValue *> &
Args)
override;
205 const std::vector<IRValue *> &
Args)
override;
223 unsigned AddrSpace = 0)
override;
225 size_t NElem)
override;
230#if defined(PROTEUS_ENABLE_CUDA) || defined(PROTEUS_ENABLE_HIP)
232 int MinBlocksPerSM)
override;
237 std::unique_ptr<Impl> PImpl;
242 llvm::Function *unwrapFunction(
IRFunction *IRF);
247 void setInsertPoint(llvm::BasicBlock *BB);
248 void setInsertPointBegin(llvm::BasicBlock *BB);
249 llvm::BasicBlock *getInsertBlock();
303 const std::vector<IRValue *> &IdxList,
304 const std::string &Name =
"");
310 unsigned getAddressSpaceFromValue(
IRValue *PtrVal);
315#if defined(PROTEUS_ENABLE_CUDA) || defined(PROTEUS_ENABLE_HIP)
char int void ** Args
Definition CompilerInterfaceHost.cpp:23
Definition CodeBuilder.h:70
Definition IRFunction.h:9
Definition LLVMCodeBuilder.h:29
void beginWhile(std::function< IRValue *()> CondFn, const char *File, int Line) override
Definition LLVMCodeBuilder.cpp:559
IRValue * createAtomicSub(IRValue *Addr, IRValue *Val) override
Definition LLVMCodeBuilder.cpp:671
IRValue * createOr(IRValue *LHS, IRValue *RHS) override
Definition LLVMCodeBuilder.cpp:780
llvm::Type * getPointerType(unsigned AS)
Definition LLVMCodeBuilder.cpp:1031
IRValue * createArith(ArithOp Op, IRValue *LHS, IRValue *RHS, IRType Ty) override
Definition LLVMCodeBuilder.cpp:911
IRValue * loadScalar(IRValue *Slot, IRType ValueTy) override
Load the value stored directly in Slot (scalar alloca).
Definition LLVMCodeBuilder.cpp:1246
llvm::LLVMContext & getContext()
Definition LLVMCodeBuilder.cpp:260
unsigned getAddressSpace(llvm::Type *Ty)
Definition LLVMCodeBuilder.cpp:1043
IRValue * createCmp(CmpOp Op, IRValue *LHS, IRValue *RHS, IRType Ty) override
Definition LLVMCodeBuilder.cpp:943
llvm::IRBuilderBase & getIRBuilder()
Get the underlying IRBuilderBase (internal use only).
Definition LLVMCodeBuilder.cpp:244
VarAlloc allocPointer(const std::string &Name, IRType ElemTy, unsigned AddrSpace=0) override
Definition LLVMCodeBuilder.cpp:1289
void beginIf(IRValue *Cond, const char *File, int Line) override
Definition LLVMCodeBuilder.cpp:411
llvm::Module & getModule()
Definition LLVMCodeBuilder.cpp:252
llvm::BasicBlock * createBasicBlock(const std::string &Name="", llvm::BasicBlock *InsertBefore=nullptr)
Definition LLVMCodeBuilder.cpp:342
IRValue * createAtomicMin(IRValue *Addr, IRValue *Val) override
Definition LLVMCodeBuilder.cpp:691
IRFunction * addFunction(const std::string &Name, IRType RetTy, const std::vector< IRType > &ArgTys, bool IsKernel=false) override
Definition LLVMCodeBuilder.cpp:268
llvm::Type * getInt32Ty()
Definition LLVMCodeBuilder.cpp:1038
void storeScalar(IRValue *Slot, IRValue *Val) override
Store Val directly into Slot (scalar alloca).
Definition LLVMCodeBuilder.cpp:1251
void endWhile() override
Definition LLVMCodeBuilder.cpp:593
IRValue * createZExt(IRValue *V, IRType DestTy) override
Definition LLVMCodeBuilder.cpp:870
~LLVMCodeBuilder() override
VarAlloc allocArray(const std::string &Name, AddressSpace AS, IRType ElemTy, size_t NElem) override
Definition LLVMCodeBuilder.cpp:1298
void createBr(llvm::BasicBlock *Dest)
Definition LLVMCodeBuilder.cpp:804
IRValue * emitAlloca(llvm::Type *Ty, const std::string &Name, AddressSpace AS=AddressSpace::DEFAULT)
Definition LLVMCodeBuilder.cpp:1157
void eraseTerminator(llvm::BasicBlock *BB)
Definition LLVMCodeBuilder.cpp:348
IRValue * createBitCast(IRValue *V, IRType DestTy) override
Definition LLVMCodeBuilder.cpp:861
CodeBuilderKind getBackendKind() const override
Definition LLVMCodeBuilder.h:38
LLVMCodeBuilder(const LLVMCodeBuilder &)=delete
IRValue * createXor(IRValue *LHS, IRValue *RHS) override
Definition LLVMCodeBuilder.cpp:784
void createStore(IRValue *Val, IRValue *Ptr) override
Definition LLVMCodeBuilder.cpp:799
IRValue * getConstantInt(IRType Ty, uint64_t Val) override
Definition LLVMCodeBuilder.cpp:876
llvm::Type * getInt16Ty()
Definition LLVMCodeBuilder.cpp:1037
LLVMCodeBuilder(std::unique_ptr< llvm::LLVMContext > Ctx, std::unique_ptr< llvm::Module > Mod, TargetModelType TM=TargetModelType::HOST)
Construct as owner of LLVMContext and Module.
VarAlloc getElementPtr(IRValue *Base, IRType BaseTy, IRValue *Index, IRType ElemTy) override
Definition LLVMCodeBuilder.cpp:991
IRValue * createCast(IRValue *V, IRType FromTy, IRType ToTy) override
Definition LLVMCodeBuilder.cpp:979
llvm::BasicBlock * getUniqueSuccessor(llvm::BasicBlock *BB)
Definition LLVMCodeBuilder.cpp:355
void createRet(IRValue *V) override
Definition LLVMCodeBuilder.cpp:822
llvm::Type * getPointerTypeUnqual()
Definition LLVMCodeBuilder.cpp:1034
void beginFor(IRValue *IterSlot, IRType IterTy, IRValue *InitVal, IRValue *UpperBoundVal, IRValue *IncVal, bool IsSigned, const char *File, int Line, LoopHints Hints={}) override
Definition LLVMCodeBuilder.cpp:462
IRValue * emitIntrinsic(const std::string &Name, IRType RetTy, const std::vector< IRValue * > &Args) override
Lower a frontend intrinsic name to backend IR.
Definition LLVMCodeBuilder.cpp:1088
std::tuple< llvm::BasicBlock *, llvm::BasicBlock * > splitCurrentBlock()
Definition LLVMCodeBuilder.cpp:335
void endFor() override
Definition LLVMCodeBuilder.cpp:542
IRValue * createAtomicAdd(IRValue *Addr, IRValue *Val) override
Definition LLVMCodeBuilder.cpp:661
IRValue * createLoad(IRType Ty, IRValue *Ptr, const std::string &Name="") override
Definition LLVMCodeBuilder.cpp:793
std::unique_ptr< llvm::Module > takeModule()
Transfer ownership of the Module (leaves internal pointer null).
Definition LLVMCodeBuilder.cpp:308
IRValue * loadFromPointee(IRValue *Slot, IRType AllocTy, IRType ValueTy) override
Dereference the pointer stored in Slot, then load the pointee.
Definition LLVMCodeBuilder.cpp:1264
IRValue * createAnd(IRValue *LHS, IRValue *RHS) override
Definition LLVMCodeBuilder.cpp:776
std::unique_ptr< llvm::LLVMContext > takeLLVMContext()
Transfer ownership of the LLVMContext (leaves internal pointer null).
Definition LLVMCodeBuilder.cpp:304
bool isIntegerTy(llvm::Type *Ty)
Definition LLVMCodeBuilder.cpp:1055
TargetModelType getTargetModel() const override
Definition LLVMCodeBuilder.h:37
void storeToPointee(IRValue *Slot, IRType AllocTy, IRValue *Val) override
Dereference the pointer stored in Slot, then store Val to it.
Definition LLVMCodeBuilder.cpp:1272
void endFunction() override
Definition LLVMCodeBuilder.cpp:398
llvm::Type * getInt64Ty()
Definition LLVMCodeBuilder.cpp:1039
LLVMCodeBuilder & operator=(const LLVMCodeBuilder &)=delete
llvm::Function & getFunction()
Definition LLVMCodeBuilder.cpp:246
llvm::Type * getFloatTy()
Definition LLVMCodeBuilder.cpp:1040
IRValue * getConstantFP(IRType Ty, double Val) override
Definition LLVMCodeBuilder.cpp:879
IRValue * createAtomicMax(IRValue *Addr, IRValue *Val) override
Definition LLVMCodeBuilder.cpp:681
IRValue * loadAddress(IRValue *Slot, IRType AllocTy) override
Load the pointer stored in Slot (pointer alloca).
Definition LLVMCodeBuilder.cpp:1255
void storeAddress(IRValue *Slot, IRValue *Addr) override
Store Addr into Slot (pointer alloca).
Definition LLVMCodeBuilder.cpp:1260
void pushScope(const char *File, int Line, ScopeKind Kind, llvm::BasicBlock *NextBlock)
Definition LLVMCodeBuilder.cpp:364
void setInsertPointAtEntry() override
Definition LLVMCodeBuilder.cpp:322
void createRetVoid() override
Definition LLVMCodeBuilder.cpp:811
void createCondBr(IRValue *Cond, llvm::BasicBlock *True, llvm::BasicBlock *False)
Definition LLVMCodeBuilder.cpp:806
IRValue * emitArrayCreate(llvm::Type *Ty, AddressSpace AT, const std::string &Name)
Definition LLVMCodeBuilder.cpp:1170
IRValue * emitBuiltin(const std::string &Name, IRType RetTy, const std::vector< IRValue * > &Args) override
Definition LLVMCodeBuilder.cpp:1142
VarAlloc allocScalar(const std::string &Name, IRType ValueTy) override
Definition LLVMCodeBuilder.cpp:1283
void beginFunction(IRFunction *F, const char *File, int Line) override
Set F as the active function and begin IR emission.
Definition LLVMCodeBuilder.cpp:371
void endIf() override
Definition LLVMCodeBuilder.cpp:446
void clearInsertPoint() override
Definition LLVMCodeBuilder.cpp:328
IRValue * getArg(IRFunction *F, size_t Idx) override
Return the Nth argument of F as an IRValue.
Definition LLVMCodeBuilder.cpp:1308
void setFunctionName(IRFunction *F, const std::string &Name) override
Rename the function identified by F.
Definition LLVMCodeBuilder.cpp:299
IRValue * createNot(IRValue *Val) override
Definition LLVMCodeBuilder.cpp:788
bool isFloatingPointTy(llvm::Type *Ty)
Definition LLVMCodeBuilder.cpp:1056
IRValue * createCall(const std::string &FName, IRType RetTy, const std::vector< IRType > &ArgTys, const std::vector< IRValue * > &Args) override
Definition LLVMCodeBuilder.cpp:1061
Definition CompiledLibrary.h:7
Definition MemoryCache.h:27
AddressSpace
Definition AddressSpace.h:6
TargetModelType
Definition TargetModel.h:8
CodeBuilderKind
Definition CodeBuilder.h:66
ArithOp
Semantic arithmetic operation selector.
Definition CodeBuilder.h:43
CmpOp
Semantic comparison operation selector.
Definition CodeBuilder.h:46
void setLaunchBoundsForKernel(Function &F, int MaxThreadsPerSM, int MinBlocksPerSM=0)
Definition CoreLLVMCUDA.h:87
ScopeKind
Definition CodeBuilder.h:40
Definition CodeBuilder.h:21
Definition CodeBuilder.h:29