llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-amdgpu Author: Rahul Joshi (jurahul) <details> <summary>Changes</summary> Rename the function to reflect its correct behavior and to be consistent with `Module::getOrInsertFunction`. This is also in preparation of adding a new `Intrinsic::getDeclaration` that will have behavior similar to `Module::getFunction` (i.e, just lookup, no creation). --- Patch is 245.25 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/111752.diff 137 Files Affected: - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+6-5) - (modified) clang/lib/CodeGen/CGDecl.cpp (+4-4) - (modified) clang/lib/CodeGen/CGException.cpp (+2-2) - (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+2-2) - (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2-2) - (modified) clang/lib/CodeGen/Targets/SystemZ.cpp (+2-2) - (modified) llvm/examples/BrainF/BrainF.cpp (+2-2) - (modified) llvm/include/llvm-c/Core.h (+2-2) - (modified) llvm/include/llvm/IR/IntrinsicInst.h (+3-3) - (modified) llvm/include/llvm/IR/Intrinsics.h (+5-4) - (modified) llvm/include/llvm/IR/MatrixBuilder.h (+4-4) - (modified) llvm/lib/AsmParser/LLParser.cpp (+1-1) - (modified) llvm/lib/CodeGen/ExpandLargeFpConvert.cpp (+1-1) - (modified) llvm/lib/CodeGen/ExpandMemCmp.cpp (+1-1) - (modified) llvm/lib/CodeGen/ExpandVectorPredication.cpp (+7-7) - (modified) llvm/lib/CodeGen/HardwareLoops.cpp (+5-7) - (modified) llvm/lib/CodeGen/IntrinsicLowering.cpp (+1-1) - (modified) llvm/lib/CodeGen/SafeStack.cpp (+2-1) - (modified) llvm/lib/CodeGen/SjLjEHPrepare.cpp (+12-10) - (modified) llvm/lib/CodeGen/StackProtector.cpp (+3-2) - (modified) llvm/lib/CodeGen/WasmEHPrepare.cpp (+9-6) - (modified) llvm/lib/IR/AutoUpgrade.cpp (+165-153) - (modified) llvm/lib/IR/Core.cpp (+1-1) - (modified) llvm/lib/IR/DIBuilder.cpp (+4-4) - (modified) llvm/lib/IR/DebugProgramInstruction.cpp (+4-4) - (modified) llvm/lib/IR/IRBuilder.cpp (+50-46) - (modified) llvm/lib/IR/IntrinsicInst.cpp (+14-15) - (modified) llvm/lib/IR/Intrinsics.cpp (+3-2) - (modified) llvm/lib/IR/Module.cpp (+5-4) - (modified) llvm/lib/IR/VectorBuilder.cpp (+2-2) - (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+16-13) - (modified) llvm/lib/Target/AArch64/AArch64StackTagging.cpp (+9-9) - (modified) llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp (+1-1) - (modified) llvm/lib/Target/AArch64/SMEABIPass.cpp (+7-7) - (modified) llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp (+12-12) - (modified) llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp (+8-7) - (modified) llvm/lib/Target/AMDGPU/AMDGPUImageIntrinsicOptimizer.cpp (+1-1) - (modified) llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp (+9-8) - (modified) llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp (+2-2) - (modified) llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp (+7-6) - (modified) llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp (+4-4) - (modified) llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp (+7-7) - (modified) llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp (+6-5) - (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp (+2-2) - (modified) llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp (+2-2) - (modified) llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp (+9-7) - (modified) llvm/lib/Target/ARM/ARMISelLowering.cpp (+13-12) - (modified) llvm/lib/Target/ARM/ARMParallelDSP.cpp (+7-6) - (modified) llvm/lib/Target/ARM/MVETailPredication.cpp (+1-1) - (modified) llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp (+1-1) - (modified) llvm/lib/Target/BPF/BPFAdjustOpt.cpp (+1-1) - (modified) llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp (+1-1) - (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+2-2) - (modified) llvm/lib/Target/Hexagon/HexagonGenExtract.cpp (+1-1) - (modified) llvm/lib/Target/Hexagon/HexagonISelLowering.cpp (+2-2) - (modified) llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp (+2-1) - (modified) llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp (+6-5) - (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp (+2-2) - (modified) llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp (+1-1) - (modified) llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp (+2-1) - (modified) llvm/lib/Target/PowerPC/PPCISelLowering.cpp (+4-4) - (modified) llvm/lib/Target/PowerPC/PPCLowerMASSVEntries.cpp (+1-1) - (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+15-15) - (modified) llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp (+4-4) - (modified) llvm/lib/Target/SystemZ/SystemZTDC.cpp (+2-2) - (modified) llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp (+1-1) - (modified) llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp (+1-1) - (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+6-4) - (modified) llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp (+4-2) - (modified) llvm/lib/Target/X86/X86PartialReduction.cpp (+1-1) - (modified) llvm/lib/Target/X86/X86WinEHState.cpp (+8-8) - (modified) llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp (+2-2) - (modified) llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp (+6-5) - (modified) llvm/lib/Transforms/Coroutines/Coroutines.cpp (+3-2) - (modified) llvm/lib/Transforms/IPO/CrossDSOCFI.cpp (+2-1) - (modified) llvm/lib/Transforms/IPO/SampleProfileProbe.cpp (+1-1) - (modified) llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp (+7-5) - (modified) llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp (+4-3) - (modified) llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (+9-5) - (modified) llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp (+18-11) - (modified) llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp (+8-7) - (modified) llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp (+9-9) - (modified) llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp (+10-9) - (modified) llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp (+1-1) - (modified) llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (+4-4) - (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+3-3) - (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+2-2) - (modified) llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp (+1-1) - (modified) llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp (+2-2) - (modified) llvm/lib/Transforms/Instrumentation/KCFI.cpp (+2-1) - (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+3-3) - (modified) llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (+12-11) - (modified) llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp (+1-1) - (modified) llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp (+4-3) - (modified) llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h (+1-1) - (modified) llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp (+8-6) - (modified) llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp (+1-1) - (modified) llvm/lib/Transforms/Scalar/LoopFlatten.cpp (+2-2) - (modified) llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp (+2-2) - (modified) llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp (+1-1) - (modified) llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp (+1-1) - (modified) llvm/lib/Transforms/Scalar/MakeGuardsExplicit.cpp (+1-1) - (modified) llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp (+2-2) - (modified) llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (+2-2) - (modified) llvm/lib/Transforms/Scalar/Scalarizer.cpp (+3-2) - (modified) llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp (+2-1) - (modified) llvm/lib/Transforms/Utils/CloneFunction.cpp (+2-2) - (modified) llvm/lib/Transforms/Utils/CodeExtractor.cpp (+2-1) - (modified) llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp (+1-1) - (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+4-3) - (modified) llvm/lib/Transforms/Utils/IntegerDivision.cpp (+2-2) - (modified) llvm/lib/Transforms/Utils/Local.cpp (+2-1) - (modified) llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp (+2-2) - (modified) llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp (+3-3) - (modified) llvm/lib/Transforms/Utils/PredicateInfo.cpp (+2-2) - (modified) llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp (+1-1) - (modified) llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp (+1-1) - (modified) llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp (+2-2) - (modified) llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp (+1-1) - (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+1-1) - (modified) llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp (+1-1) - (modified) llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp (+1-1) - (modified) llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp (+2-1) - (modified) llvm/unittests/Analysis/MemorySSATest.cpp (+1-1) - (modified) llvm/unittests/Analysis/ValueTrackingTest.cpp (+2-2) - (modified) llvm/unittests/IR/BasicBlockTest.cpp (+5-3) - (modified) llvm/unittests/IR/DebugInfoTest.cpp (+2-1) - (modified) llvm/unittests/IR/IRBuilderTest.cpp (+3-2) - (modified) llvm/unittests/IR/IntrinsicsTest.cpp (+1-1) - (modified) llvm/unittests/IR/PatternMatch.cpp (+1-1) - (modified) llvm/unittests/IR/VPIntrinsicTest.cpp (+2-2) - (modified) llvm/unittests/Transforms/Vectorize/VPlanTest.cpp (+2-1) - (modified) mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td (+3-3) - (modified) mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp (+3-2) - (modified) mlir/lib/Target/LLVMIR/ModuleTranslation.cpp (+4-3) - (modified) polly/lib/CodeGen/IslExprBuilder.cpp (+6-6) - (modified) polly/lib/CodeGen/PerfMonitor.cpp (+1-1) ``````````diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 57705f2d2d0423..7efa59cf16c185 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -13648,7 +13648,7 @@ Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID, Value *InfoKind = ConstantInt::get(Int64Ty, C->getSExtValue()); // Built the IR for the preserve_field_info intrinsic. - llvm::Function *FnGetFieldInfo = llvm::Intrinsic::getDeclaration( + llvm::Function *FnGetFieldInfo = llvm::Intrinsic::getOrInsertDeclaration( &CGM.getModule(), llvm::Intrinsic::bpf_preserve_field_info, {FieldAddr->getType()}); return Builder.CreateCall(FnGetFieldInfo, {FieldAddr, InfoKind}); @@ -13670,10 +13670,10 @@ Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID, llvm::Function *FnDecl; if (BuiltinID == BPF::BI__builtin_btf_type_id) - FnDecl = llvm::Intrinsic::getDeclaration( + FnDecl = llvm::Intrinsic::getOrInsertDeclaration( &CGM.getModule(), llvm::Intrinsic::bpf_btf_type_id, {}); else - FnDecl = llvm::Intrinsic::getDeclaration( + FnDecl = llvm::Intrinsic::getOrInsertDeclaration( &CGM.getModule(), llvm::Intrinsic::bpf_preserve_type_info, {}); CallInst *Fn = Builder.CreateCall(FnDecl, {SeqNumVal, FlagValue}); Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo); @@ -13708,7 +13708,7 @@ Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID, Value *FlagValue = ConstantInt::get(Int64Ty, Flag->getSExtValue()); Value *SeqNumVal = ConstantInt::get(Int32Ty, BuiltinSeqNum++); - llvm::Function *IntrinsicFn = llvm::Intrinsic::getDeclaration( + llvm::Function *IntrinsicFn = llvm::Intrinsic::getOrInsertDeclaration( &CGM.getModule(), llvm::Intrinsic::bpf_preserve_enum_value, {}); CallInst *Fn = Builder.CreateCall(IntrinsicFn, {SeqNumVal, EnumStrVal, FlagValue}); @@ -18873,7 +18873,8 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: { } case Builtin::BI__builtin_hlsl_wave_is_first_lane: { Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveIsFirstLaneIntrinsic(); - return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID)); + return EmitRuntimeCall( + Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID)); } case Builtin::BI__builtin_hlsl_elementwise_sign: { Value *Op0 = EmitScalarExpr(E->getArg(0)); diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 563f728e29d781..30af9268b30e2e 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -2509,8 +2509,8 @@ void CodeGenFunction::pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Function *CodeGenModule::getLLVMLifetimeStartFn() { if (LifetimeStartFn) return LifetimeStartFn; - LifetimeStartFn = llvm::Intrinsic::getDeclaration(&getModule(), - llvm::Intrinsic::lifetime_start, AllocaInt8PtrTy); + LifetimeStartFn = llvm::Intrinsic::getOrInsertDeclaration( + &getModule(), llvm::Intrinsic::lifetime_start, AllocaInt8PtrTy); return LifetimeStartFn; } @@ -2518,8 +2518,8 @@ llvm::Function *CodeGenModule::getLLVMLifetimeStartFn() { llvm::Function *CodeGenModule::getLLVMLifetimeEndFn() { if (LifetimeEndFn) return LifetimeEndFn; - LifetimeEndFn = llvm::Intrinsic::getDeclaration(&getModule(), - llvm::Intrinsic::lifetime_end, AllocaInt8PtrTy); + LifetimeEndFn = llvm::Intrinsic::getOrInsertDeclaration( + &getModule(), llvm::Intrinsic::lifetime_end, AllocaInt8PtrTy); return LifetimeEndFn; } diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp index bb2ed237ee9f35..44a45413dbc45a 100644 --- a/clang/lib/CodeGen/CGException.cpp +++ b/clang/lib/CodeGen/CGException.cpp @@ -1843,7 +1843,7 @@ Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF, std::make_pair(ParentAlloca, ParentCGF.EscapedLocals.size())); int FrameEscapeIdx = InsertPair.first->second; // call ptr @llvm.localrecover(ptr @parentFn, ptr %fp, i32 N) - llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration( + llvm::Function *FrameRecoverFn = llvm::Intrinsic::getOrInsertDeclaration( &CGM.getModule(), llvm::Intrinsic::localrecover); RecoverCall = Builder.CreateCall( FrameRecoverFn, {ParentCGF.CurFn, ParentFP, @@ -1942,7 +1942,7 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF, // %1 = call ptr @llvm.localrecover(@"?fin$0@0@main@@",..) // %2 = load ptr, ptr %1, align 8 // ==> %2 is the frame-pointer of outermost host function - llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration( + llvm::Function *FrameRecoverFn = llvm::Intrinsic::getOrInsertDeclaration( &CGM.getModule(), llvm::Intrinsic::localrecover); ParentFP = Builder.CreateCall( FrameRecoverFn, {ParentCGF.CurFn, ParentFP, diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index e1fd9b72b8d7b2..f3023c7a20c405 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -463,7 +463,7 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) { EscapeArgs.resize(EscapedLocals.size()); for (auto &Pair : EscapedLocals) EscapeArgs[Pair.second] = Pair.first; - llvm::Function *FrameEscapeFn = llvm::Intrinsic::getDeclaration( + llvm::Function *FrameEscapeFn = llvm::Intrinsic::getOrInsertDeclaration( &CGM.getModule(), llvm::Intrinsic::localescape); CGBuilderTy(*this, AllocaInsertPt).CreateCall(FrameEscapeFn, EscapeArgs); } @@ -3130,7 +3130,7 @@ void CodeGenFunction::emitAlignmentAssumptionCheck( llvm::Instruction *Assumption) { assert(isa_and_nonnull<llvm::CallInst>(Assumption) && cast<llvm::CallInst>(Assumption)->getCalledOperand() == - llvm::Intrinsic::getDeclaration( + llvm::Intrinsic::getOrInsertDeclaration( Builder.GetInsertBlock()->getParent()->getParent(), llvm::Intrinsic::assume) && "Assumption should be a call to llvm.assume()."); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 5ba098144a74e7..7a7dea4668ad09 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -6218,8 +6218,8 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) { llvm::Function *CodeGenModule::getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys) { - return llvm::Intrinsic::getDeclaration(&getModule(), (llvm::Intrinsic::ID)IID, - Tys); + return llvm::Intrinsic::getOrInsertDeclaration(&getModule(), + (llvm::Intrinsic::ID)IID, Tys); } static llvm::StringMapEntry<llvm::GlobalVariable *> & diff --git a/clang/lib/CodeGen/Targets/SystemZ.cpp b/clang/lib/CodeGen/Targets/SystemZ.cpp index 56129622f48dbd..23c96fa5cf98cb 100644 --- a/clang/lib/CodeGen/Targets/SystemZ.cpp +++ b/clang/lib/CodeGen/Targets/SystemZ.cpp @@ -110,8 +110,8 @@ class SystemZTargetCodeGenInfo : public TargetCodeGenInfo { if (Ty->isFloatTy() || Ty->isDoubleTy() || Ty->isFP128Ty()) { llvm::Module &M = CGM.getModule(); auto &Ctx = M.getContext(); - llvm::Function *TDCFunc = - llvm::Intrinsic::getDeclaration(&M, llvm::Intrinsic::s390_tdc, Ty); + llvm::Function *TDCFunc = llvm::Intrinsic::getOrInsertDeclaration( + &M, llvm::Intrinsic::s390_tdc, Ty); unsigned TDCBits = 0; switch (BuiltinID) { case Builtin::BI__builtin_isnan: diff --git a/llvm/examples/BrainF/BrainF.cpp b/llvm/examples/BrainF/BrainF.cpp index ac01961735e137..e62cc7bd591a3f 100644 --- a/llvm/examples/BrainF/BrainF.cpp +++ b/llvm/examples/BrainF/BrainF.cpp @@ -67,8 +67,8 @@ void BrainF::header(LLVMContext& C) { //declare void @llvm.memset.p0i8.i32(i8 *, i8, i32, i1) Type *Tys[] = {PointerType::getUnqual(C), Type::getInt32Ty(C)}; - Function *memset_func = Intrinsic::getDeclaration(module, Intrinsic::memset, - Tys); + Function *memset_func = + Intrinsic::getOrInsertDeclaration(module, Intrinsic::memset, Tys); //declare i32 @getchar() getchar_func = diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h index 28dc270ca368d2..55649d89a6b8f4 100644 --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -2807,10 +2807,10 @@ unsigned LLVMLookupIntrinsicID(const char *Name, size_t NameLen); unsigned LLVMGetIntrinsicID(LLVMValueRef Fn); /** - * Create or insert the declaration of an intrinsic. For overloaded intrinsics, + * Get or insert the declaration of an intrinsic. For overloaded intrinsics, * parameter types must be provided to uniquely identify an overload. * - * @see llvm::Intrinsic::getDeclaration() + * @see llvm::Intrinsic::getOrInsertDeclaration() */ LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod, unsigned ID, diff --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h index 4458126ffa759d..920eed01374c83 100644 --- a/llvm/include/llvm/IR/IntrinsicInst.h +++ b/llvm/include/llvm/IR/IntrinsicInst.h @@ -568,9 +568,9 @@ class VPIntrinsic : public IntrinsicInst { /// \brief Declares a llvm.vp.* intrinsic in \p M that matches the parameters /// \p Params. Additionally, the load and gather intrinsics require /// \p ReturnType to be specified. - static Function *getDeclarationForParams(Module *M, Intrinsic::ID, - Type *ReturnType, - ArrayRef<Value *> Params); + static Function *getOrInsertDeclarationForParams(Module *M, Intrinsic::ID, + Type *ReturnType, + ArrayRef<Value *> Params); static std::optional<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID); static std::optional<unsigned> getVectorLengthParamPos( diff --git a/llvm/include/llvm/IR/Intrinsics.h b/llvm/include/llvm/IR/Intrinsics.h index b251036247c5c0..8c37925732a83a 100644 --- a/llvm/include/llvm/IR/Intrinsics.h +++ b/llvm/include/llvm/IR/Intrinsics.h @@ -87,14 +87,15 @@ namespace Intrinsic { /// Return the attributes for an intrinsic. AttributeList getAttributes(LLVMContext &C, ID id); - /// Create or insert an LLVM Function declaration for an intrinsic, and return - /// it. + /// Look up the Function declaration of the intrinsic \p id in the Module + /// \p M. If it does not exist, add a declaration and return it. Otherwise, + /// return the existing declaration. /// - /// The Tys parameter is for intrinsics with overloaded types (e.g., those + /// The \p Tys parameter is for intrinsics with overloaded types (e.g., those /// using iAny, fAny, vAny, or iPTRAny). For a declaration of an overloaded /// intrinsic, Tys must provide exactly one type for each overloaded type in /// the intrinsic. - Function *getDeclaration(Module *M, ID id, ArrayRef<Type *> Tys = {}); + Function *getOrInsertDeclaration(Module *M, ID id, ArrayRef<Type *> Tys = {}); /// Looks up Name in NameTable via binary search. NameTable must be sorted /// and all entries must start with "llvm.". If NameTable contains an exact diff --git a/llvm/include/llvm/IR/MatrixBuilder.h b/llvm/include/llvm/IR/MatrixBuilder.h index dbf2cfb7c5e966..3a04ca87f2b558 100644 --- a/llvm/include/llvm/IR/MatrixBuilder.h +++ b/llvm/include/llvm/IR/MatrixBuilder.h @@ -72,7 +72,7 @@ class MatrixBuilder { B.getInt32(Columns)}; Type *OverloadedTypes[] = {RetType, Stride->getType()}; - Function *TheFn = Intrinsic::getDeclaration( + Function *TheFn = Intrinsic::getOrInsertDeclaration( getModule(), Intrinsic::matrix_column_major_load, OverloadedTypes); CallInst *Call = B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name); @@ -95,7 +95,7 @@ class MatrixBuilder { B.getInt32(Rows), B.getInt32(Columns)}; Type *OverloadedTypes[] = {Matrix->getType(), Stride->getType()}; - Function *TheFn = Intrinsic::getDeclaration( + Function *TheFn = Intrinsic::getOrInsertDeclaration( getModule(), Intrinsic::matrix_column_major_store, OverloadedTypes); CallInst *Call = B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name); @@ -115,7 +115,7 @@ class MatrixBuilder { Type *OverloadedTypes[] = {ReturnType}; Value *Ops[] = {Matrix, B.getInt32(Rows), B.getInt32(Columns)}; - Function *TheFn = Intrinsic::getDeclaration( + Function *TheFn = Intrinsic::getOrInsertDeclaration( getModule(), Intrinsic::matrix_transpose, OverloadedTypes); return B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name); @@ -136,7 +136,7 @@ class MatrixBuilder { B.getInt32(RHSColumns)}; Type *OverloadedTypes[] = {ReturnType, LHSType, RHSType}; - Function *TheFn = Intrinsic::getDeclaration( + Function *TheFn = Intrinsic::getOrInsertDeclaration( getModule(), Intrinsic::matrix_multiply, OverloadedTypes); return B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name); } diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 9f2ef2e6a9311e..54eb18bafc03f8 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -360,7 +360,7 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) { OverloadTys)) return error(Info.second, "invalid intrinsic signature"); - U.set(Intrinsic::getDeclaration(M, IID, OverloadTys)); + U.set(Intrinsic::getOrInsertDeclaration(M, IID, OverloadTys)); } Info.first->eraseFromParent(); diff --git a/llvm/lib/CodeGen/ExpandLargeFpConvert.cpp b/llvm/lib/CodeGen/ExpandLargeFpConvert.cpp index 11f123aa5bed85..0a3d0cf8ec9300 100644 --- a/llvm/lib/CodeGen/ExpandLargeFpConvert.cpp +++ b/llvm/lib/CodeGen/ExpandLargeFpConvert.cpp @@ -356,7 +356,7 @@ static void expandIToFP(Instruction *IToFP) { Entry->getTerminator()->eraseFromParent(); Function *CTLZ = - Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz, IntTy); + Intrinsic::getOrInsertDeclaration(F->getParent(), Intrinsic::ctlz, IntTy); ConstantInt *True = Builder.getTrue(); // entry: diff --git a/llvm/lib/CodeGen/ExpandMemCmp.cpp b/llvm/lib/CodeGen/ExpandMemCmp.cpp index 04222d5b4afd4c..6d626de0b4e635 100644 --- a/llvm/lib/CodeGen/ExpandMemCmp.cpp +++ b/llvm/lib/CodeGen/ExpandMemCmp.cpp @@ -355,7 +355,7 @@ MemCmpExpansion::LoadPair MemCmpExpansion::getLoadPair(Type *LoadSizeType, // Swap bytes if required. if (BSwapSizeType) { - Function *Bswap = Intrinsic::getDeclaration( + Function *Bswap = Intrinsic::getOrInsertDeclaration( CI->getModule(), Intrinsic::bswap, BSwapSizeType); Lhs = Builder.CreateCall(Bswap, Lhs); Rhs = Builder.CreateCall(Bswap, Rhs); diff --git a/llvm/lib/CodeGen/ExpandVectorPredication.cpp b/llvm/lib/CodeGen/ExpandVectorPredication.cpp index ffe879ff049648..32ba3e91822ddb 100644 --- a/llvm/lib/CodeGen/ExpandVectorPredication.cpp +++ b/llvm/lib/CodeGen/ExpandVectorPredication.cpp @@ -237,7 +237,7 @@ Value *CachingVPExpander::convertEVLToMask(IRBuilder<> &Builder, if (ElemCount.isScalable()) { auto *M = Builder.GetInsertBlock()->getModule(); Type *BoolVecTy = VectorType::get(Builder.getInt1Ty(), ElemCount); - Function *ActiveMaskFunc = Intrinsic::getDeclaration( + Function *ActiveMaskFunc = Intrinsic::getOrInsertDeclaration( M, Intrinsic::get_active_lane_mask, {BoolVecTy, EVLParam->getType()}); // `get_active_lane_mask` performs an implicit less-than comparison. Value *ConstZero = Builder.getInt32(0); @@ -299,7 +299,7 @@ Value *CachingVPExpander::expandPredicationToIntCall( case Intrinsic::umin: { Value *Op0 = VPI.getOperand(0); Value *Op1 = VPI.getOperand(1); - Function *Fn = Intrinsic::getDeclaration( + Function *Fn = Intrinsic::getOrInsertDeclaration( VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()}); Value *NewOp = Builder.CreateCall(Fn, {Op0, Op1}, VPI.getName()); replaceOperation(*NewOp, VPI); @@ -308,7 +308,7 @@ Value *CachingVPExpander::expandPredicationToIntCall( case Intrinsic::bswap: case Intrinsic::bitreverse: { Value *Op = VPI.getOperand(0); - Function *Fn = Intrinsic::getDeclaration( + Function *Fn = Intrinsic::getOrInsertDeclaration( VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()}); Value *NewOp = Builder.CreateCall(Fn, {Op}, VPI.getName()); replaceOperation(*NewOp, VPI); @@ -327,7 +327,7 @@ Value *CachingVPExpander::expandPredicationToFPCall( case Intrinsic::fabs: case Intrinsic::sqrt: { Value *Op0 = VPI.getOperand(0); - Function *Fn = Intrinsic::getDeclaration( + Function *Fn = Intrinsic::getOrInsertDeclaration( VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()}); Value *NewOp = Builder.CreateCall(Fn, {Op0}, VPI.getName()); replaceOperation(*NewOp, VPI); @@ -337,7 +337,7 @@ Value *CachingVPExpander::expandPredicationToFPCall( case Intrinsic::minnum: { Value *Op0 = VPI.getOperand(0); Value *Op1 = VPI.getOperand(1); - Function *Fn = Intrinsic::getDeclaration( + Function *Fn = Intrinsic::getOrInsertDeclaration( VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()}); Value *NewOp = Builder.CreateCall(Fn, {Op0, Op1}, VPI.getName()); replaceOperation(*NewOp, VPI); @@ -350,7 +350,7 @@ Value *CachingVPExpander::expandPredicationToFPCall( Value *Op0 = VPI.getOperand(0); Value *Op1 = VPI.getOperand(1); Value *Op2 = VPI.getOperand(2); - Function *Fn = Intrinsic::getDeclaration( + Function *Fn = Intrinsic::getOrInsertDeclaration( VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()}); Value *NewOp; if (Intrinsic::isConstrainedFPIntrinsic(UnpredicatedIntrinsicID)) @@ -594,7 +594,7 @@ bool CachingVPExpander::discardEVLParameter(VPIntrinsic &VPI) { // TODO add caching auto *M = VPI.getModule(); Function *VScaleFunc = - Intrinsic::getDeclaration(M, Intrinsic::vscale, Int32Ty); + Intrinsic::getOrInsertDeclaration(M, Intrinsic::vscale, Int32Ty); IRBuilder<> Builder(VPI.getParent(), VPI.getIterator()); Value *FactorConst = Builder.getInt32(StaticElemCount.getKnownMinValue()); Value *VScale = Builder.CreateCall(VScaleFunc, {}, "vscale"); diff --git a/llvm/lib/CodeGen/HardwareLoops.cpp b/llvm/lib/CodeGen/HardwareLoops.cpp index 9205eabcf5684e..c8a63304a3b63b 100644 --- a/llvm/lib/CodeGen/HardwareLoops.cpp +++ b/llvm/lib/CodeGen/HardwareLoops.cpp @@ -512,7 +512,7 @@ Value* HardwareLoop::InsertIterationSetup(Value *LoopCountInit) { : Intrinsic::test_set_loop_iterations) : (UsePhi ? Intrinsic::start_loop_iterations : Intrinsic::set_loop_iterations); - Function *LoopIter = Intrinsic::getDeclaration(M, ID, Ty); + Function *LoopIter = Intrinsic::getOrInsertDeclaration(M, ID, Ty); Value *LoopSetup = Builder.CreateCall(LoopIter, LoopCountInit); // Use the return value of the intrinsic to control the entry of the loop. @@ -541,9 +541,8 @@ void HardwareLoop::InsertLoopDec() { Attribute::StrictFP)) CondBuilder.setIsFPConstrained(true); - Function *DecFunc = - Intrinsic::getDeclaration(M, Intrinsic::loop_decrement, - LoopDecrement->getType()); + Function *DecFunc = Intrinsic::getOrInsertDeclaration( + M, Intrinsic::loop_decrement, LoopDecrement->getType()); Value *Ops[] = { LoopDecrement }; Value *NewCond = CondBuilder.CreateCall(DecFunc, Ops); Value *OldCond = ExitBranch->getCondition(); @@ -566,9 +565,8 @@ Instruction* HardwareLoop::InsertLoopRegDec(Value *EltsRem) { Attribute::StrictFP)) CondBuilder.setIsFPConstrained(true); - Function *DecFunc = - Intrinsic::getDeclaration(M, Intrinsic::loop_decrement_reg, - { EltsRem->getType() }); + Function *DecFunc = Intrinsic:... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/111752 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits