diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -691,6 +691,10 @@ MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr, MDNode *NoAliasTag = nullptr); +private: + CallInst *getReductionIntrinsic(Intrinsic::ID ID, Value *Src); + +public: /// Create a sequential vector fadd reduction intrinsic of the source vector. /// The first parameter is a scalar accumulator value. An unordered reduction /// can be created by adding the reassoc fast-math flag to the resulting @@ -2226,6 +2230,13 @@ return Insert(Phi, Name); } +private: + CallInst *createCallHelper(Function *Callee, ArrayRef Ops, + const Twine &Name = "", + Instruction *FMFSource = nullptr, + ArrayRef OpBundles = {}); + +public: CallInst *CreateCall(FunctionType *FTy, Value *Callee, ArrayRef Args = None, const Twine &Name = "", MDNode *FPMathTag = nullptr) { diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp --- a/llvm/lib/IR/IRBuilder.cpp +++ b/llvm/lib/IR/IRBuilder.cpp @@ -84,12 +84,11 @@ } } -static CallInst *createCallHelper(Function *Callee, ArrayRef Ops, - IRBuilderBase *Builder, - const Twine &Name = "", - Instruction *FMFSource = nullptr, - ArrayRef OpBundles = {}) { - CallInst *CI = Builder->CreateCall(Callee, Ops, OpBundles, Name); +CallInst * +IRBuilderBase::createCallHelper(Function *Callee, ArrayRef Ops, + const Twine &Name, Instruction *FMFSource, + ArrayRef OpBundles) { + CallInst *CI = CreateCall(Callee, Ops, OpBundles, Name); if (FMFSource) CI->copyFastMathFlags(FMFSource); return CI; @@ -102,7 +101,7 @@ Module *M = GetInsertBlock()->getParent()->getParent(); Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::vscale, {Scaling->getType()}); - CallInst *CI = createCallHelper(TheFn, {}, this, Name); + CallInst *CI = CreateCall(TheFn, {}, {}, Name); return cast(Scaling)->getSExtValue() == 1 ? CI : CreateMul(CI, Scaling); @@ -146,7 +145,7 @@ Module *M = BB->getParent()->getParent(); Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys); - CallInst *CI = createCallHelper(TheFn, Ops, this); + CallInst *CI = CreateCall(TheFn, Ops); if (Align) cast(CI)->setDestAlignment(*Align); @@ -175,7 +174,7 @@ Module *M = BB->getParent()->getParent(); Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset_inline, Tys); - CallInst *CI = createCallHelper(TheFn, Ops, this); + CallInst *CI = CreateCall(TheFn, Ops); if (DstAlign) cast(CI)->setDestAlignment(*DstAlign); @@ -204,7 +203,7 @@ Function *TheFn = Intrinsic::getDeclaration( M, Intrinsic::memset_element_unordered_atomic, Tys); - CallInst *CI = createCallHelper(TheFn, Ops, this); + CallInst *CI = CreateCall(TheFn, Ops); cast(CI)->setDestAlignment(Alignment); @@ -233,7 +232,7 @@ Module *M = BB->getParent()->getParent(); Function *TheFn = Intrinsic::getDeclaration(M, IntrID, Tys); - CallInst *CI = createCallHelper(TheFn, Ops, this); + CallInst *CI = CreateCall(TheFn, Ops); auto* MCI = cast(CI); if (DstAlign) @@ -271,7 +270,7 @@ Module *M = F->getParent(); Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy_inline, Tys); - CallInst *CI = createCallHelper(TheFn, Ops, this); + CallInst *CI = CreateCall(TheFn, Ops); auto *MCI = cast(CI); if (DstAlign) @@ -313,7 +312,7 @@ Function *TheFn = Intrinsic::getDeclaration( M, Intrinsic::memcpy_element_unordered_atomic, Tys); - CallInst *CI = createCallHelper(TheFn, Ops, this); + CallInst *CI = CreateCall(TheFn, Ops); // Set the alignment of the pointer args. auto *AMCI = cast(CI); @@ -350,7 +349,7 @@ Module *M = BB->getParent()->getParent(); Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys); - CallInst *CI = createCallHelper(TheFn, Ops, this); + CallInst *CI = CreateCall(TheFn, Ops); auto *MMI = cast(CI); if (DstAlign) @@ -388,7 +387,7 @@ Function *TheFn = Intrinsic::getDeclaration( M, Intrinsic::memmove_element_unordered_atomic, Tys); - CallInst *CI = createCallHelper(TheFn, Ops, this); + CallInst *CI = CreateCall(TheFn, Ops); // Set the alignment of the pointer args. CI->addParamAttr(0, Attribute::getWithAlignment(CI->getContext(), DstAlign)); @@ -411,13 +410,12 @@ return CI; } -static CallInst *getReductionIntrinsic(IRBuilderBase *Builder, Intrinsic::ID ID, - Value *Src) { - Module *M = Builder->GetInsertBlock()->getParent()->getParent(); +CallInst *IRBuilderBase::getReductionIntrinsic(Intrinsic::ID ID, Value *Src) { + Module *M = GetInsertBlock()->getParent()->getParent(); Value *Ops[] = {Src}; Type *Tys[] = { Src->getType() }; auto Decl = Intrinsic::getDeclaration(M, ID, Tys); - return createCallHelper(Decl, Ops, Builder); + return CreateCall(Decl, Ops); } CallInst *IRBuilderBase::CreateFAddReduce(Value *Acc, Value *Src) { @@ -425,7 +423,7 @@ Value *Ops[] = {Acc, Src}; auto Decl = Intrinsic::getDeclaration(M, Intrinsic::vector_reduce_fadd, {Src->getType()}); - return createCallHelper(Decl, Ops, this); + return CreateCall(Decl, Ops); } CallInst *IRBuilderBase::CreateFMulReduce(Value *Acc, Value *Src) { @@ -433,47 +431,47 @@ Value *Ops[] = {Acc, Src}; auto Decl = Intrinsic::getDeclaration(M, Intrinsic::vector_reduce_fmul, {Src->getType()}); - return createCallHelper(Decl, Ops, this); + return CreateCall(Decl, Ops); } CallInst *IRBuilderBase::CreateAddReduce(Value *Src) { - return getReductionIntrinsic(this, Intrinsic::vector_reduce_add, Src); + return getReductionIntrinsic(Intrinsic::vector_reduce_add, Src); } CallInst *IRBuilderBase::CreateMulReduce(Value *Src) { - return getReductionIntrinsic(this, Intrinsic::vector_reduce_mul, Src); + return getReductionIntrinsic(Intrinsic::vector_reduce_mul, Src); } CallInst *IRBuilderBase::CreateAndReduce(Value *Src) { - return getReductionIntrinsic(this, Intrinsic::vector_reduce_and, Src); + return getReductionIntrinsic(Intrinsic::vector_reduce_and, Src); } CallInst *IRBuilderBase::CreateOrReduce(Value *Src) { - return getReductionIntrinsic(this, Intrinsic::vector_reduce_or, Src); + return getReductionIntrinsic(Intrinsic::vector_reduce_or, Src); } CallInst *IRBuilderBase::CreateXorReduce(Value *Src) { - return getReductionIntrinsic(this, Intrinsic::vector_reduce_xor, Src); + return getReductionIntrinsic(Intrinsic::vector_reduce_xor, Src); } CallInst *IRBuilderBase::CreateIntMaxReduce(Value *Src, bool IsSigned) { auto ID = IsSigned ? Intrinsic::vector_reduce_smax : Intrinsic::vector_reduce_umax; - return getReductionIntrinsic(this, ID, Src); + return getReductionIntrinsic(ID, Src); } CallInst *IRBuilderBase::CreateIntMinReduce(Value *Src, bool IsSigned) { auto ID = IsSigned ? Intrinsic::vector_reduce_smin : Intrinsic::vector_reduce_umin; - return getReductionIntrinsic(this, ID, Src); + return getReductionIntrinsic(ID, Src); } CallInst *IRBuilderBase::CreateFPMaxReduce(Value *Src) { - return getReductionIntrinsic(this, Intrinsic::vector_reduce_fmax, Src); + return getReductionIntrinsic(Intrinsic::vector_reduce_fmax, Src); } CallInst *IRBuilderBase::CreateFPMinReduce(Value *Src) { - return getReductionIntrinsic(this, Intrinsic::vector_reduce_fmin, Src); + return getReductionIntrinsic(Intrinsic::vector_reduce_fmin, Src); } CallInst *IRBuilderBase::CreateLifetimeStart(Value *Ptr, ConstantInt *Size) { @@ -489,7 +487,7 @@ Module *M = BB->getParent()->getParent(); Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_start, {Ptr->getType()}); - return createCallHelper(TheFn, Ops, this); + return CreateCall(TheFn, Ops); } CallInst *IRBuilderBase::CreateLifetimeEnd(Value *Ptr, ConstantInt *Size) { @@ -505,7 +503,7 @@ Module *M = BB->getParent()->getParent(); Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_end, {Ptr->getType()}); - return createCallHelper(TheFn, Ops, this); + return CreateCall(TheFn, Ops); } CallInst *IRBuilderBase::CreateInvariantStart(Value *Ptr, ConstantInt *Size) { @@ -525,7 +523,7 @@ Module *M = BB->getParent()->getParent(); Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::invariant_start, ObjectPtr); - return createCallHelper(TheFn, Ops, this); + return CreateCall(TheFn, Ops); } CallInst * @@ -537,14 +535,14 @@ Value *Ops[] = { Cond }; Module *M = BB->getParent()->getParent(); Function *FnAssume = Intrinsic::getDeclaration(M, Intrinsic::assume); - return createCallHelper(FnAssume, Ops, this, "", nullptr, OpBundles); + return CreateCall(FnAssume, Ops, OpBundles); } Instruction *IRBuilderBase::CreateNoAliasScopeDeclaration(Value *Scope) { Module *M = BB->getModule(); auto *FnIntrinsic = Intrinsic::getDeclaration( M, Intrinsic::experimental_noalias_scope_decl, {}); - return createCallHelper(FnIntrinsic, {Scope}, this); + return CreateCall(FnIntrinsic, {Scope}); } /// Create a call to a Masked Load intrinsic. @@ -598,7 +596,7 @@ const Twine &Name) { Module *M = BB->getParent()->getParent(); Function *TheFn = Intrinsic::getDeclaration(M, Id, OverloadedTypes); - return createCallHelper(TheFn, Ops, this, Name); + return CreateCall(TheFn, Ops, {}, Name); } /// Create a call to a Masked Gather intrinsic. @@ -833,7 +831,7 @@ Function *FnGCResult = Intrinsic::getDeclaration(M, ID, Types); Value *Args[] = {Statepoint}; - return createCallHelper(FnGCResult, Args, this, Name); + return CreateCall(FnGCResult, Args, {}, Name); } CallInst *IRBuilderBase::CreateGCRelocate(Instruction *Statepoint, @@ -845,7 +843,7 @@ Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types); Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)}; - return createCallHelper(FnGCRelocate, Args, this, Name); + return CreateCall(FnGCRelocate, Args, {}, Name); } CallInst *IRBuilderBase::CreateGCGetPointerBase(Value *DerivedPtr, @@ -854,7 +852,7 @@ Type *PtrTy = DerivedPtr->getType(); Function *FnGCFindBase = Intrinsic::getDeclaration( M, Intrinsic::experimental_gc_get_pointer_base, {PtrTy, PtrTy}); - return createCallHelper(FnGCFindBase, {DerivedPtr}, this, Name); + return CreateCall(FnGCFindBase, {DerivedPtr}, {}, Name); } CallInst *IRBuilderBase::CreateGCGetPointerOffset(Value *DerivedPtr, @@ -863,7 +861,7 @@ Type *PtrTy = DerivedPtr->getType(); Function *FnGCGetOffset = Intrinsic::getDeclaration( M, Intrinsic::experimental_gc_get_pointer_offset, {PtrTy}); - return createCallHelper(FnGCGetOffset, {DerivedPtr}, this, Name); + return CreateCall(FnGCGetOffset, {DerivedPtr}, {}, Name); } CallInst *IRBuilderBase::CreateUnaryIntrinsic(Intrinsic::ID ID, Value *V, @@ -871,7 +869,7 @@ const Twine &Name) { Module *M = BB->getModule(); Function *Fn = Intrinsic::getDeclaration(M, ID, {V->getType()}); - return createCallHelper(Fn, {V}, this, Name, FMFSource); + return createCallHelper(Fn, {V}, Name, FMFSource); } CallInst *IRBuilderBase::CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, @@ -880,7 +878,7 @@ const Twine &Name) { Module *M = BB->getModule(); Function *Fn = Intrinsic::getDeclaration(M, ID, { LHS->getType() }); - return createCallHelper(Fn, {LHS, RHS}, this, Name, FMFSource); + return createCallHelper(Fn, {LHS, RHS}, Name, FMFSource); } CallInst *IRBuilderBase::CreateIntrinsic(Intrinsic::ID ID, @@ -890,7 +888,7 @@ const Twine &Name) { Module *M = BB->getModule(); Function *Fn = Intrinsic::getDeclaration(M, ID, Types); - return createCallHelper(Fn, Args, this, Name, FMFSource); + return createCallHelper(Fn, Args, Name, FMFSource); } CallInst *IRBuilderBase::CreateConstrainedFPBinOp(