1#ifndef PROTEUS_FRONTEND_LLVM_CODE_BUILDER_H
2#define PROTEUS_FRONTEND_LLVM_CODE_BUILDER_H
33 std::unique_ptr<llvm::Module> Mod,
63 llvm::BasicBlock *InsertBefore =
nullptr);
71 llvm::BasicBlock *NextBlock);
76 void createBr(llvm::BasicBlock *Dest);
78 llvm::BasicBlock *False);
103 const std::string &Name);
109 const std::vector<IRType> &ArgTys)
override;
125 void endIf()
override;
128 const char *File,
int Line,
LoopHints Hints = {})
override;
167 const std::string &Name =
"")
override;
195 const std::vector<IRType> &ArgTys,
196 const std::vector<IRValue *> &
Args)
override;
215 unsigned AddrSpace = 0)
override;
217 size_t NElem)
override;
222#if defined(PROTEUS_ENABLE_CUDA) || defined(PROTEUS_ENABLE_HIP)
225 int MinBlocksPerSM)
override;
230 std::unique_ptr<Impl> PImpl;
235 llvm::Function *unwrapFunction(
IRFunction *IRF);
240 void setInsertPoint(llvm::BasicBlock *BB);
241 void setInsertPointBegin(llvm::BasicBlock *BB);
242 llvm::BasicBlock *getInsertBlock();
296 const std::vector<IRValue *> &IdxList,
297 const std::string &Name =
"");
303 unsigned getAddressSpaceFromValue(
IRValue *PtrVal);
char int void ** Args
Definition CompilerInterfaceHost.cpp:22
Definition CodeBuilder.h:66
Definition IRFunction.h:9
Definition LLVMCodeBuilder.h:29
void beginWhile(std::function< IRValue *()> CondFn, const char *File, int Line) override
Definition LLVMCodeBuilder.cpp:383
IRValue * createAtomicSub(IRValue *Addr, IRValue *Val) override
Definition LLVMCodeBuilder.cpp:491
IRValue * createOr(IRValue *LHS, IRValue *RHS) override
Definition LLVMCodeBuilder.cpp:600
IRValue * createArith(ArithOp Op, IRValue *LHS, IRValue *RHS, IRType Ty) override
Definition LLVMCodeBuilder.cpp:731
IRValue * loadScalar(IRValue *Slot, IRType ValueTy) override
Load the value stored directly in Slot (scalar alloca).
Definition LLVMCodeBuilder.cpp:996
llvm::LLVMContext & getContext()
Definition LLVMCodeBuilder.cpp:107
unsigned getAddressSpace(llvm::Type *Ty)
Definition LLVMCodeBuilder.cpp:863
IRValue * createCmp(CmpOp Op, IRValue *LHS, IRValue *RHS, IRType Ty) override
Definition LLVMCodeBuilder.cpp:763
llvm::IRBuilderBase & getIRBuilder()
Get the underlying IRBuilderBase (internal use only).
Definition LLVMCodeBuilder.cpp:91
VarAlloc allocPointer(const std::string &Name, IRType ElemTy, unsigned AddrSpace=0) override
Definition LLVMCodeBuilder.cpp:1039
void beginIf(IRValue *Cond, const char *File, int Line) override
Definition LLVMCodeBuilder.cpp:245
IRFunction * addFunction(const std::string &Name, IRType RetTy, const std::vector< IRType > &ArgTys) override
Definition LLVMCodeBuilder.cpp:115
llvm::Module & getModule()
Definition LLVMCodeBuilder.cpp:99
llvm::BasicBlock * createBasicBlock(const std::string &Name="", llvm::BasicBlock *InsertBefore=nullptr)
Definition LLVMCodeBuilder.cpp:178
IRValue * createAtomicMin(IRValue *Addr, IRValue *Val) override
Definition LLVMCodeBuilder.cpp:511
llvm::Type * getInt32Ty()
Definition LLVMCodeBuilder.cpp:858
void storeScalar(IRValue *Slot, IRValue *Val) override
Store Val directly into Slot (scalar alloca).
Definition LLVMCodeBuilder.cpp:1001
void endWhile() override
Definition LLVMCodeBuilder.cpp:413
IRValue * createZExt(IRValue *V, IRType DestTy) override
Definition LLVMCodeBuilder.cpp:690
~LLVMCodeBuilder() override
VarAlloc allocArray(const std::string &Name, AddressSpace AS, IRType ElemTy, size_t NElem) override
Definition LLVMCodeBuilder.cpp:1048
void createBr(llvm::BasicBlock *Dest)
Definition LLVMCodeBuilder.cpp:624
IRValue * emitAlloca(llvm::Type *Ty, const std::string &Name, AddressSpace AS=AddressSpace::DEFAULT)
Definition LLVMCodeBuilder.cpp:909
void eraseTerminator(llvm::BasicBlock *BB)
Definition LLVMCodeBuilder.cpp:184
IRValue * createBitCast(IRValue *V, IRType DestTy) override
Definition LLVMCodeBuilder.cpp:681
LLVMCodeBuilder(const LLVMCodeBuilder &)=delete
IRValue * createXor(IRValue *LHS, IRValue *RHS) override
Definition LLVMCodeBuilder.cpp:604
void createStore(IRValue *Val, IRValue *Ptr) override
Definition LLVMCodeBuilder.cpp:619
IRValue * getConstantInt(IRType Ty, uint64_t Val) override
Definition LLVMCodeBuilder.cpp:696
llvm::Type * getInt16Ty()
Definition LLVMCodeBuilder.cpp:857
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:811
IRValue * createCast(IRValue *V, IRType FromTy, IRType ToTy) override
Definition LLVMCodeBuilder.cpp:799
llvm::BasicBlock * getUniqueSuccessor(llvm::BasicBlock *BB)
Definition LLVMCodeBuilder.cpp:191
void createRet(IRValue *V) override
Definition LLVMCodeBuilder.cpp:642
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:290
std::tuple< llvm::BasicBlock *, llvm::BasicBlock * > splitCurrentBlock()
Definition LLVMCodeBuilder.cpp:171
void endFor() override
Definition LLVMCodeBuilder.cpp:366
IRValue * createAtomicAdd(IRValue *Addr, IRValue *Val) override
Definition LLVMCodeBuilder.cpp:481
IRValue * createLoad(IRType Ty, IRValue *Ptr, const std::string &Name="") override
Definition LLVMCodeBuilder.cpp:613
std::unique_ptr< llvm::Module > takeModule()
Transfer ownership of the Module (leaves internal pointer null).
Definition LLVMCodeBuilder.cpp:144
IRValue * loadFromPointee(IRValue *Slot, IRType AllocTy, IRType ValueTy) override
Dereference the pointer stored in Slot, then load the pointee.
Definition LLVMCodeBuilder.cpp:1014
IRValue * createAnd(IRValue *LHS, IRValue *RHS) override
Definition LLVMCodeBuilder.cpp:596
std::unique_ptr< llvm::LLVMContext > takeLLVMContext()
Transfer ownership of the LLVMContext (leaves internal pointer null).
Definition LLVMCodeBuilder.cpp:140
bool isIntegerTy(llvm::Type *Ty)
Definition LLVMCodeBuilder.cpp:875
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:1022
void endFunction() override
Definition LLVMCodeBuilder.cpp:232
llvm::Type * getInt64Ty()
Definition LLVMCodeBuilder.cpp:859
LLVMCodeBuilder & operator=(const LLVMCodeBuilder &)=delete
llvm::Type * getPointerType(llvm::Type *ElemTy, unsigned AS)
Definition LLVMCodeBuilder.cpp:851
llvm::Function & getFunction()
Definition LLVMCodeBuilder.cpp:93
llvm::Type * getFloatTy()
Definition LLVMCodeBuilder.cpp:860
IRValue * getConstantFP(IRType Ty, double Val) override
Definition LLVMCodeBuilder.cpp:699
IRValue * createAtomicMax(IRValue *Addr, IRValue *Val) override
Definition LLVMCodeBuilder.cpp:501
IRValue * loadAddress(IRValue *Slot, IRType AllocTy) override
Load the pointer stored in Slot (pointer alloca).
Definition LLVMCodeBuilder.cpp:1005
void storeAddress(IRValue *Slot, IRValue *Addr) override
Store Addr into Slot (pointer alloca).
Definition LLVMCodeBuilder.cpp:1010
void pushScope(const char *File, int Line, ScopeKind Kind, llvm::BasicBlock *NextBlock)
Definition LLVMCodeBuilder.cpp:200
void setInsertPointAtEntry() override
Definition LLVMCodeBuilder.cpp:158
void createRetVoid() override
Definition LLVMCodeBuilder.cpp:631
void createCondBr(IRValue *Cond, llvm::BasicBlock *True, llvm::BasicBlock *False)
Definition LLVMCodeBuilder.cpp:626
llvm::Type * getPointerTypeUnqual(llvm::Type *ElemTy)
Definition LLVMCodeBuilder.cpp:854
IRValue * emitArrayCreate(llvm::Type *Ty, AddressSpace AT, const std::string &Name)
Definition LLVMCodeBuilder.cpp:922
VarAlloc allocScalar(const std::string &Name, IRType ValueTy) override
Definition LLVMCodeBuilder.cpp:1033
void beginFunction(IRFunction *F, const char *File, int Line) override
Set F as the active function and begin IR emission.
Definition LLVMCodeBuilder.cpp:207
void endIf() override
Definition LLVMCodeBuilder.cpp:274
void clearInsertPoint() override
Definition LLVMCodeBuilder.cpp:164
IRValue * getArg(IRFunction *F, size_t Idx) override
Return the Nth argument of F as an IRValue.
Definition LLVMCodeBuilder.cpp:1058
void setFunctionName(IRFunction *F, const std::string &Name) override
Rename the function identified by F.
Definition LLVMCodeBuilder.cpp:135
IRValue * createNot(IRValue *Val) override
Definition LLVMCodeBuilder.cpp:608
bool isFloatingPointTy(llvm::Type *Ty)
Definition LLVMCodeBuilder.cpp:876
IRValue * createCall(const std::string &FName, IRType RetTy, const std::vector< IRType > &ArgTys, const std::vector< IRValue * > &Args) override
Definition LLVMCodeBuilder.cpp:881
Definition CompiledLibrary.h:7
Definition MemoryCache.h:26
AddressSpace
Definition AddressSpace.h:6
TargetModelType
Definition TargetModel.h:8
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