[llvm] 9436a85 - [IRBuilder] Make createCallHelper a member function. NFC.
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 29 13:23:41 PDT 2022
Author: Jay Foad
Date: 2022-07-29T21:17:26+01:00
New Revision: 9436a85eb62525062fc538ced4199bc49e72ab33
URL: https://github.com/llvm/llvm-project/commit/9436a85eb62525062fc538ced4199bc49e72ab33
DIFF: https://github.com/llvm/llvm-project/commit/9436a85eb62525062fc538ced4199bc49e72ab33.diff
LOG: [IRBuilder] Make createCallHelper a member function. NFC.
This just avoids explicitly passing in 'this' as an argument in a bunch
of places.
Differential Revision: https://reviews.llvm.org/D130752
Added:
Modified:
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/IR/IRBuilder.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 0d3ffba955a33..6e559bb8f7f33 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -691,6 +691,10 @@ class IRBuilderBase {
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 @@ class IRBuilderBase {
return Insert(Phi, Name);
}
+private:
+ CallInst *createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
+ const Twine &Name = "",
+ Instruction *FMFSource = nullptr,
+ ArrayRef<OperandBundleDef> OpBundles = {});
+
+public:
CallInst *CreateCall(FunctionType *FTy, Value *Callee,
ArrayRef<Value *> Args = None, const Twine &Name = "",
MDNode *FPMathTag = nullptr) {
diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp
index d0c622fe2389f..137d6eaa57427 100644
--- a/llvm/lib/IR/IRBuilder.cpp
+++ b/llvm/lib/IR/IRBuilder.cpp
@@ -84,12 +84,11 @@ void IRBuilderBase::SetInstDebugLocation(Instruction *I) const {
}
}
-static CallInst *createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
- IRBuilderBase *Builder,
- const Twine &Name = "",
- Instruction *FMFSource = nullptr,
- ArrayRef<OperandBundleDef> OpBundles = {}) {
- CallInst *CI = Builder->CreateCall(Callee, Ops, OpBundles, Name);
+CallInst *
+IRBuilderBase::createCallHelper(Function *Callee, ArrayRef<Value *> Ops,
+ const Twine &Name, Instruction *FMFSource,
+ ArrayRef<OperandBundleDef> OpBundles) {
+ CallInst *CI = CreateCall(Callee, Ops, OpBundles, Name);
if (FMFSource)
CI->copyFastMathFlags(FMFSource);
return CI;
@@ -102,7 +101,7 @@ Value *IRBuilderBase::CreateVScale(Constant *Scaling, const Twine &Name) {
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<ConstantInt>(Scaling)->getSExtValue() == 1
? CI
: CreateMul(CI, Scaling);
@@ -146,7 +145,7 @@ CallInst *IRBuilderBase::CreateMemSet(Value *Ptr, Value *Val, Value *Size,
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<MemSetInst>(CI)->setDestAlignment(*Align);
@@ -175,7 +174,7 @@ CallInst *IRBuilderBase::CreateMemSetInline(Value *Dst, MaybeAlign DstAlign,
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<MemSetInlineInst>(CI)->setDestAlignment(*DstAlign);
@@ -204,7 +203,7 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemSet(
Function *TheFn = Intrinsic::getDeclaration(
M, Intrinsic::memset_element_unordered_atomic, Tys);
- CallInst *CI = createCallHelper(TheFn, Ops, this);
+ CallInst *CI = CreateCall(TheFn, Ops);
cast<AtomicMemSetInst>(CI)->setDestAlignment(Alignment);
@@ -233,7 +232,7 @@ CallInst *IRBuilderBase::CreateMemTransferInst(
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<MemTransferInst>(CI);
if (DstAlign)
@@ -271,7 +270,7 @@ CallInst *IRBuilderBase::CreateMemCpyInline(
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<MemCpyInlineInst>(CI);
if (DstAlign)
@@ -313,7 +312,7 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemCpy(
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<AtomicMemCpyInst>(CI);
@@ -350,7 +349,7 @@ CallInst *IRBuilderBase::CreateMemMove(Value *Dst, MaybeAlign DstAlign,
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<MemMoveInst>(CI);
if (DstAlign)
@@ -388,7 +387,7 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemMove(
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 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemMove(
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 @@ CallInst *IRBuilderBase::CreateFAddReduce(Value *Acc, Value *Src) {
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 @@ CallInst *IRBuilderBase::CreateFMulReduce(Value *Acc, Value *Src) {
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 @@ CallInst *IRBuilderBase::CreateLifetimeStart(Value *Ptr, ConstantInt *Size) {
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 @@ CallInst *IRBuilderBase::CreateLifetimeEnd(Value *Ptr, ConstantInt *Size) {
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 @@ CallInst *IRBuilderBase::CreateInvariantStart(Value *Ptr, ConstantInt *Size) {
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 @@ IRBuilderBase::CreateAssumption(Value *Cond,
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 @@ CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
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 @@ CallInst *IRBuilderBase::CreateGCResult(Instruction *Statepoint,
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 @@ CallInst *IRBuilderBase::CreateGCRelocate(Instruction *Statepoint,
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 @@ CallInst *IRBuilderBase::CreateGCGetPointerBase(Value *DerivedPtr,
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 @@ CallInst *IRBuilderBase::CreateGCGetPointerOffset(Value *DerivedPtr,
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 @@ CallInst *IRBuilderBase::CreateUnaryIntrinsic(Intrinsic::ID ID, Value *V,
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 @@ CallInst *IRBuilderBase::CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS,
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 @@ CallInst *IRBuilderBase::CreateIntrinsic(Intrinsic::ID ID,
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(
More information about the llvm-commits
mailing list