X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=include%2Fllvm%2FIR%2FIRBuilder.h;h=2f8c3c499295c424e18b77020d27cd235ed06ba8;hp=d46514614e48f4803ccded9178dd7b166b345641;hb=6f28d52e9d3f87875732a0f2c1f3b03ef56be2db;hpb=f3abce4a8e2e41e6b8e534b0af0b1d2d6181a114 diff --git a/include/llvm/IR/IRBuilder.h b/include/llvm/IR/IRBuilder.h index d46514614e4..2f8c3c49929 100644 --- a/include/llvm/IR/IRBuilder.h +++ b/include/llvm/IR/IRBuilder.h @@ -52,6 +52,7 @@ protected: /// \brief Common base class shared among various IRBuilders. class IRBuilderBase { DebugLoc CurDbgLocation; + protected: BasicBlock *BB; BasicBlock::iterator InsertPt; @@ -59,10 +60,14 @@ protected: MDNode *DefaultFPMathTag; FastMathFlags FMF; -public: - IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = nullptr) - : Context(context), DefaultFPMathTag(FPMathTag), FMF() { + ArrayRef DefaultOperandBundles; + +public: + IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : Context(context), DefaultFPMathTag(FPMathTag), FMF(), + DefaultOperandBundles(OpBundles) { ClearInsertionPoint(); } @@ -74,7 +79,7 @@ public: /// inserted into a block. void ClearInsertionPoint() { BB = nullptr; - InsertPt = nullptr; + InsertPt.reset(nullptr); } BasicBlock *GetInsertBlock() const { return BB; } @@ -92,8 +97,8 @@ public: /// the specified instruction. void SetInsertPoint(Instruction *I) { BB = I->getParent(); - InsertPt = I; - assert(I != BB->end() && "Can't read debug loc from end()"); + InsertPt = I->getIterator(); + assert(InsertPt != BB->end() && "Can't read debug loc from end()"); SetCurrentDebugLocation(I->getDebugLoc()); } @@ -173,10 +178,10 @@ public: void clearFastMathFlags() { FMF.clear(); } /// \brief Set the floating point math metadata to be used. - void SetDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; } + void setDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; } /// \brief Set the fast-math flags to be used with generated fp-math operators - void SetFastMathFlags(FastMathFlags NewFMF) { FMF = NewFMF; } + void setFastMathFlags(FastMathFlags NewFMF) { FMF = NewFMF; } //===--------------------------------------------------------------------===// // RAII helpers. @@ -314,10 +319,8 @@ public: } /// \brief Fetch the type representing a 128-bit integer. - IntegerType *getInt128Ty() { - return Type::getInt128Ty(Context); - } - + IntegerType *getInt128Ty() { return Type::getInt128Ty(Context); } + /// \brief Fetch the type representing an N-bit integer. IntegerType *getIntNTy(unsigned N) { return Type::getIntNTy(Context, N); @@ -427,7 +430,7 @@ public: /// \brief Create a call to Masked Load intrinsic CallInst *CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask, - Value *PassThru = 0, const Twine &Name = ""); + Value *PassThru = nullptr, const Twine &Name = ""); /// \brief Create a call to Masked Store intrinsic CallInst *CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align, @@ -446,6 +449,16 @@ public: ArrayRef GCArgs, const Twine &Name = ""); + /// \brief Create a call to the experimental.gc.statepoint intrinsic to + /// start a new statepoint sequence. + CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes, + Value *ActualCallee, uint32_t Flags, + ArrayRef CallArgs, + ArrayRef TransitionArgs, + ArrayRef DeoptArgs, + ArrayRef GCArgs, + const Twine &Name = ""); + // \brief Conveninence function for the common case when CallArgs are filled // in using makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be // .get()'ed to get the Value pointer. @@ -464,6 +477,15 @@ public: ArrayRef DeoptArgs, ArrayRef GCArgs, const Twine &Name = ""); + /// brief Create an invoke to the experimental.gc.statepoint intrinsic to + /// start a new statepoint sequence. + InvokeInst *CreateGCStatepointInvoke( + uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, + BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags, + ArrayRef InvokeArgs, ArrayRef TransitionArgs, + ArrayRef DeoptArgs, ArrayRef GCArgs, + const Twine &Name = ""); + // Conveninence function for the common case when CallArgs are filled in using // makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be .get()'ed to // get the Value *. @@ -517,39 +539,47 @@ template > class IRBuilder : public IRBuilderBase, public Inserter { T Folder; + public: IRBuilder(LLVMContext &C, const T &F, Inserter I = Inserter(), - MDNode *FPMathTag = nullptr) - : IRBuilderBase(C, FPMathTag), Inserter(std::move(I)), Folder(F) {} - - explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr) - : IRBuilderBase(C, FPMathTag), Folder() { - } - - explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr) - : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) { + MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(C, FPMathTag, OpBundles), Inserter(std::move(I)), + Folder(F) {} + + explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(C, FPMathTag, OpBundles), Folder() {} + + explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) { SetInsertPoint(TheBB); } - explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr) - : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() { + explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder() { SetInsertPoint(TheBB); } - explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr) - : IRBuilderBase(IP->getContext(), FPMathTag), Folder() { + explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(IP->getContext(), FPMathTag, OpBundles), Folder() { SetInsertPoint(IP); } - IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F, - MDNode *FPMathTag = nullptr) - : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder(F) { + IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T &F, + MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) { SetInsertPoint(TheBB, IP); } IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, - MDNode *FPMathTag = nullptr) - : IRBuilderBase(TheBB->getContext(), FPMathTag), Folder() { + MDNode *FPMathTag = nullptr, + ArrayRef OpBundles = None) + : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder() { SetInsertPoint(TheBB, IP); } @@ -672,6 +702,13 @@ public: return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args), Name); } + InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest, + BasicBlock *UnwindDest, ArrayRef Args, + ArrayRef OpBundles, + const Twine &Name = "") { + return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args, + OpBundles), Name); + } ResumeInst *CreateResume(Value *Exn) { return Insert(ResumeInst::Create(Exn)); @@ -682,29 +719,22 @@ public: return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB)); } - CleanupEndPadInst *CreateCleanupEndPad(CleanupPadInst *CleanupPad, - BasicBlock *UnwindBB = nullptr) { - return Insert(CleanupEndPadInst::Create(CleanupPad, UnwindBB)); - } - - CatchPadInst *CreateCatchPad(BasicBlock *NormalDest, BasicBlock *UnwindDest, - ArrayRef Args, const Twine &Name = "") { - return Insert(CatchPadInst::Create(NormalDest, UnwindDest, Args), Name); - } - - CatchEndPadInst *CreateCatchEndPad(BasicBlock *UnwindBB = nullptr) { - return Insert(CatchEndPadInst::Create(Context, UnwindBB)); + CatchSwitchInst *CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB, + unsigned NumHandlers, + const Twine &Name = "") { + return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers), + Name); } - TerminatePadInst *CreateTerminatePad(BasicBlock *UnwindBB = nullptr, - ArrayRef Args = {}, - const Twine &Name = "") { - return Insert(TerminatePadInst::Create(Context, UnwindBB, Args), Name); + CatchPadInst *CreateCatchPad(Value *ParentPad, ArrayRef Args, + const Twine &Name = "") { + return Insert(CatchPadInst::Create(ParentPad, Args), Name); } - CleanupPadInst *CreateCleanupPad(ArrayRef Args, + CleanupPadInst *CreateCleanupPad(Value *ParentPad, + ArrayRef Args = None, const Twine &Name = "") { - return Insert(CleanupPadInst::Create(Context, Args), Name); + return Insert(CleanupPadInst::Create(ParentPad, Args), Name); } CatchReturnInst *CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB) { @@ -739,6 +769,7 @@ private: I->setFastMathFlags(FMF); return I; } + public: Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "", bool HasNUW = false, bool HasNSW = false) { @@ -1374,11 +1405,13 @@ public: return CreateBitCast(V, DestTy, Name); } + private: // \brief Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a // compile time error, instead of converting the string to bool for the // isSigned parameter. Value *CreateIntCast(Value *, Type *, const char *) = delete; + public: Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy) @@ -1506,18 +1539,33 @@ public: } CallInst *CreateCall(Value *Callee, ArrayRef Args = None, - const Twine &Name = "") { - return Insert(CallInst::Create(Callee, Args), Name); + const Twine &Name = "", MDNode *FPMathTag = nullptr) { + PointerType *PTy = cast(Callee->getType()); + FunctionType *FTy = cast(PTy->getElementType()); + return CreateCall(FTy, Callee, Args, Name, FPMathTag); } CallInst *CreateCall(llvm::FunctionType *FTy, Value *Callee, - ArrayRef Args, const Twine &Name = "") { - return Insert(CallInst::Create(FTy, Callee, Args), Name); + ArrayRef Args, const Twine &Name = "", + MDNode *FPMathTag = nullptr) { + CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles); + if (isa(CI)) + CI = cast(AddFPMathAttributes(CI, FPMathTag, FMF)); + return Insert(CI, Name); + } + + CallInst *CreateCall(Value *Callee, ArrayRef Args, + ArrayRef OpBundles, + const Twine &Name = "", MDNode *FPMathTag = nullptr) { + CallInst *CI = CallInst::Create(Callee, Args, OpBundles); + if (isa(CI)) + CI = cast(AddFPMathAttributes(CI, FPMathTag, FMF)); + return Insert(CI, Name); } CallInst *CreateCall(Function *Callee, ArrayRef Args, - const Twine &Name = "") { - return CreateCall(Callee->getFunctionType(), Callee, Args, Name); + const Twine &Name = "", MDNode *FPMathTag = nullptr) { + return CreateCall(Callee->getFunctionType(), Callee, Args, Name, FPMathTag); } Value *CreateSelect(Value *C, Value *True, Value *False, @@ -1743,6 +1791,6 @@ public: // Create wrappers for C Binding types (see CBindingWrapping.h). DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef) -} +} // end namespace llvm -#endif +#endif // LLVM_IR_IRBUILDER_H