[llvm] [LLVM] Add `Intrinsic::getDeclarationIfExists` (PR #112428)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 15 13:06:03 PDT 2024
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/112428
Add `Intrinsic::getDeclarationIfExists` to lookup an existing declaration of an intrinsic in a `Module`.
>From 8938da062e6b0b13af81d7ac85a3949802ddc2e6 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Tue, 15 Oct 2024 13:00:18 -0700
Subject: [PATCH] [LLVM] Add `Intrinsic::getDeclarationIfExists`
Add `Intrinsic::getDeclarationIfExists` to lookup an existing
declaration of an intrinsic in a `Module`.
---
llvm/include/llvm/IR/Intrinsics.h | 10 ++++++++++
llvm/lib/Analysis/LazyValueInfo.cpp | 2 +-
llvm/lib/Analysis/ScalarEvolution.cpp | 12 ++++++------
llvm/lib/IR/Intrinsics.cpp | 10 ++++++++++
llvm/lib/LTO/LTO.cpp | 14 +++++++-------
.../Target/AMDGPU/AMDGPULowerKernelArguments.cpp | 4 ++--
.../Target/AMDGPU/AMDGPULowerKernelAttributes.cpp | 3 +--
llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 2 +-
llvm/lib/Transforms/IPO/ExpandVariadics.cpp | 5 +++--
llvm/lib/Transforms/IPO/GlobalDCE.cpp | 6 +++---
llvm/lib/Transforms/IPO/GlobalSplit.cpp | 8 ++++----
llvm/lib/Transforms/IPO/LowerTypeTests.cpp | 6 +++---
llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp | 10 +++++-----
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp | 13 +++++++------
.../Instrumentation/IndirectCallPromotion.cpp | 2 +-
.../Transforms/Instrumentation/InstrProfiling.cpp | 12 ++++++------
llvm/lib/Transforms/Scalar/GuardWidening.cpp | 8 ++++----
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 4 ++--
llvm/lib/Transforms/Scalar/JumpThreading.cpp | 4 ++--
llvm/lib/Transforms/Scalar/LoopPredication.cpp | 6 +++---
llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp | 4 ++--
.../Transforms/Scalar/LowerWidenableCondition.cpp | 4 ++--
llvm/lib/Transforms/Scalar/MakeGuardsExplicit.cpp | 4 ++--
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp | 4 ++--
24 files changed, 89 insertions(+), 68 deletions(-)
diff --git a/llvm/include/llvm/IR/Intrinsics.h b/llvm/include/llvm/IR/Intrinsics.h
index 49f4fe4c5c3d7f..e893295e3272b9 100644
--- a/llvm/include/llvm/IR/Intrinsics.h
+++ b/llvm/include/llvm/IR/Intrinsics.h
@@ -102,6 +102,16 @@ namespace Intrinsic {
inline Function *getDeclaration(Module *M, ID id, ArrayRef<Type *> Tys = {}) {
return getOrInsertDeclaration(M, id, Tys);
}
+
+ /// Look up the Function declaration of the intrinsic \p id in the Module
+ /// \p M and return it if it exists. Otherwise, return nullptr. This version
+ /// supports non-overloaded intrinsics.
+ Function *getDeclarationIfExists(const Module *M, ID id);
+
+ /// This version supports overloaded intrinsics.
+ Function *getDeclarationIfExists(Module *M, ID id, ArrayRef<Type *> Tys,
+ FunctionType *FT = nullptr);
+
/// Looks up Name in NameTable via binary search. NameTable must be sorted
/// and all entries must start with "llvm.". If NameTable contains an exact
/// match for Name or a prefix of Name followed by a dot, its index in
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index 30dc4ae30dbfa5..10ad4708596cb3 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1613,7 +1613,7 @@ LazyValueInfoImpl &LazyValueInfo::getOrCreateImpl(const Module *M) {
assert(M && "getCache() called with a null Module");
const DataLayout &DL = M->getDataLayout();
Function *GuardDecl =
- M->getFunction(Intrinsic::getName(Intrinsic::experimental_guard));
+ Intrinsic::getDeclarationIfExists(M, Intrinsic::experimental_guard);
PImpl = new LazyValueInfoImpl(AC, DL, GuardDecl);
}
return *static_cast<LazyValueInfoImpl *>(PImpl);
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 97ea405a5267ae..a3ba8e03781910 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -11665,8 +11665,8 @@ bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB,
}
// Check conditions due to any @llvm.experimental.guard intrinsics.
- auto *GuardDecl = F.getParent()->getFunction(
- Intrinsic::getName(Intrinsic::experimental_guard));
+ auto *GuardDecl = Intrinsic::getDeclarationIfExists(
+ F.getParent(), Intrinsic::experimental_guard);
if (GuardDecl)
for (const auto *GU : GuardDecl->users())
if (const auto *Guard = dyn_cast<IntrinsicInst>(GU))
@@ -13615,8 +13615,8 @@ ScalarEvolution::ScalarEvolution(Function &F, TargetLibraryInfo &TLI,
// ScalarEvolution to optimize based on those guards. For now we prefer to be
// efficient in lieu of being smart in that rather obscure case.
- auto *GuardDecl = F.getParent()->getFunction(
- Intrinsic::getName(Intrinsic::experimental_guard));
+ auto *GuardDecl = Intrinsic::getDeclarationIfExists(
+ F.getParent(), Intrinsic::experimental_guard);
HasGuards = GuardDecl && !GuardDecl->use_empty();
}
@@ -15593,8 +15593,8 @@ ScalarEvolution::LoopGuards::collect(const Loop *L, ScalarEvolution &SE) {
}
// Second, collect information from llvm.experimental.guards dominating the loop.
- auto *GuardDecl = SE.F.getParent()->getFunction(
- Intrinsic::getName(Intrinsic::experimental_guard));
+ auto *GuardDecl = Intrinsic::getDeclarationIfExists(
+ SE.F.getParent(), Intrinsic::experimental_guard);
if (GuardDecl)
for (const auto *GU : GuardDecl->users())
if (const auto *Guard = dyn_cast<IntrinsicInst>(GU))
diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
index ff8b4b7a020c2f..1b92daf15b463e 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -724,6 +724,16 @@ Function *Intrinsic::getOrInsertDeclaration(Module *M, ID id,
.getCallee());
}
+Function *Intrinsic::getDeclarationIfExists(const Module *M, ID id) {
+ return M->getFunction(getName(id));
+}
+
+Function *Intrinsic::getDeclarationIfExists(Module *M, ID id,
+ ArrayRef<Type *> Tys,
+ FunctionType *FT) {
+ return M->getFunction(getName(id, Tys, M, FT));
+}
+
// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
#include "llvm/IR/IntrinsicImpl.inc"
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 90c4e2c3cd131c..0f53c608512171 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1120,13 +1120,13 @@ Error LTO::checkPartiallySplit() {
if (!ThinLTO.CombinedIndex.partiallySplitLTOUnits())
return Error::success();
- Function *TypeTestFunc = RegularLTO.CombinedModule->getFunction(
- Intrinsic::getName(Intrinsic::type_test));
- Function *TypeCheckedLoadFunc = RegularLTO.CombinedModule->getFunction(
- Intrinsic::getName(Intrinsic::type_checked_load));
- Function *TypeCheckedLoadRelativeFunc =
- RegularLTO.CombinedModule->getFunction(
- Intrinsic::getName(Intrinsic::type_checked_load_relative));
+ const Module *Combined = RegularLTO.CombinedModule.get();
+ Function *TypeTestFunc =
+ Intrinsic::getDeclarationIfExists(Combined, Intrinsic::type_test);
+ Function *TypeCheckedLoadFunc =
+ Intrinsic::getDeclarationIfExists(Combined, Intrinsic::type_checked_load);
+ Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
+ Combined, Intrinsic::type_checked_load_relative);
// First check if there are type tests / type checked loads in the
// merged regular LTO module IR.
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp
index d16c96f88e7b1e..6573176492b7f3 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp
@@ -171,8 +171,8 @@ class PreloadKernelArgInfo {
// Try to allocate SGPRs to preload implicit kernel arguments.
void tryAllocImplicitArgPreloadSGPRs(uint64_t ImplicitArgsBaseOffset,
IRBuilder<> &Builder) {
- StringRef Name = Intrinsic::getName(Intrinsic::amdgcn_implicitarg_ptr);
- Function *ImplicitArgPtr = F.getParent()->getFunction(Name);
+ Function *ImplicitArgPtr = Intrinsic::getDeclarationIfExists(
+ F.getParent(), Intrinsic::amdgcn_implicitarg_ptr);
if (!ImplicitArgPtr)
return;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
index 7d66d07c9d0fb7..1bb5e794da7dd6 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
@@ -78,8 +78,7 @@ class AMDGPULowerKernelAttributes : public ModulePass {
Function *getBasePtrIntrinsic(Module &M, bool IsV5OrAbove) {
auto IntrinsicId = IsV5OrAbove ? Intrinsic::amdgcn_implicitarg_ptr
: Intrinsic::amdgcn_dispatch_ptr;
- StringRef Name = Intrinsic::getName(IntrinsicId);
- return M.getFunction(Name);
+ return Intrinsic::getDeclarationIfExists(&M, IntrinsicId);
}
} // end anonymous namespace
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 8c197f23149612..de9173e923ab5c 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -8786,7 +8786,7 @@ SDValue SITargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
const Module *M = MF.getFunction().getParent();
const GlobalValue *GV =
- M->getNamedValue(Intrinsic::getName(Intrinsic::amdgcn_groupstaticsize));
+ Intrinsic::getDeclarationIfExists(M, Intrinsic::amdgcn_groupstaticsize);
SDValue GA = DAG.getTargetGlobalAddress(GV, DL, MVT::i32, 0,
SIInstrInfo::MO_ABS32_LO);
return {DAG.getMachineNode(AMDGPU::S_MOV_B32, DL, MVT::i32, GA), 0};
diff --git a/llvm/lib/Transforms/IPO/ExpandVariadics.cpp b/llvm/lib/Transforms/IPO/ExpandVariadics.cpp
index a7a01ca1055dd3..3121659edadd81 100644
--- a/llvm/lib/Transforms/IPO/ExpandVariadics.cpp
+++ b/llvm/lib/Transforms/IPO/ExpandVariadics.cpp
@@ -145,9 +145,10 @@ class VariadicABIInfo {
// function here in the meantime to decouple from that discussion.
Function *getPreexistingDeclaration(Module *M, Intrinsic::ID Id,
ArrayRef<Type *> Tys = {}) {
+ if (Tys.empty())
+ return Intrinsic::getDeclarationIfExists(M, Id);
auto *FT = Intrinsic::getType(M->getContext(), Id, Tys);
- return M->getFunction(Tys.empty() ? Intrinsic::getName(Id)
- : Intrinsic::getName(Id, Tys, M, FT));
+ return Intrinsic::getDeclarationIfExists(M, Id, Tys, FT);
}
class ExpandVariadics : public ModulePass {
diff --git a/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
index e36d524d7667ab..eca36fb31cea0e 100644
--- a/llvm/lib/Transforms/IPO/GlobalDCE.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
@@ -186,9 +186,9 @@ void GlobalDCEPass::ScanVTableLoad(Function *Caller, Metadata *TypeId,
void GlobalDCEPass::ScanTypeCheckedLoadIntrinsics(Module &M) {
LLVM_DEBUG(dbgs() << "Scanning type.checked.load intrinsics\n");
Function *TypeCheckedLoadFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load));
- Function *TypeCheckedLoadRelativeFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load_relative));
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_checked_load);
+ Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
+ &M, Intrinsic::type_checked_load_relative);
auto scan = [&](Function *CheckedLoadFunc) {
if (!CheckedLoadFunc)
diff --git a/llvm/lib/Transforms/IPO/GlobalSplit.cpp b/llvm/lib/Transforms/IPO/GlobalSplit.cpp
index fd49b745fd750e..320fd893935f84 100644
--- a/llvm/lib/Transforms/IPO/GlobalSplit.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalSplit.cpp
@@ -174,11 +174,11 @@ static bool splitGlobals(Module &M) {
// llvm.type.checked.load intrinsics, which indicates that splitting globals
// may be beneficial.
Function *TypeTestFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::type_test));
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_test);
Function *TypeCheckedLoadFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load));
- Function *TypeCheckedLoadRelativeFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load_relative));
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_checked_load);
+ Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
+ &M, Intrinsic::type_checked_load_relative);
if ((!TypeTestFunc || TypeTestFunc->use_empty()) &&
(!TypeCheckedLoadFunc || TypeCheckedLoadFunc->use_empty()) &&
(!TypeCheckedLoadRelativeFunc ||
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 519a4e9314a26b..3fcfc6a876776d 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -1970,7 +1970,7 @@ static void dropTypeTests(Module &M, Function &TypeTestFunc) {
bool LowerTypeTestsModule::lower() {
Function *TypeTestFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::type_test));
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_test);
if (DropTypeTests) {
if (TypeTestFunc)
@@ -1979,7 +1979,7 @@ bool LowerTypeTestsModule::lower() {
// except for in the case where we originally were performing ThinLTO but
// decided not to in the backend.
Function *PublicTypeTestFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::public_type_test));
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::public_type_test);
if (PublicTypeTestFunc)
dropTypeTests(M, *PublicTypeTestFunc);
if (TypeTestFunc || PublicTypeTestFunc) {
@@ -2002,7 +2002,7 @@ bool LowerTypeTestsModule::lower() {
return false;
Function *ICallBranchFunnelFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::icall_branch_funnel));
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::icall_branch_funnel);
if ((!TypeTestFunc || TypeTestFunc->use_empty()) &&
(!ICallBranchFunnelFunc || ICallBranchFunnelFunc->use_empty()) &&
!ExportSummary && !ImportSummary)
diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
index 9bf29c46938eba..cd0e412bdf353b 100644
--- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -123,7 +123,7 @@ void promoteTypeIds(Module &M, StringRef ModuleId) {
};
if (Function *TypeTestFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::type_test))) {
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_test)) {
for (const Use &U : TypeTestFunc->uses()) {
auto CI = cast<CallInst>(U.getUser());
ExternalizeTypeId(CI, 1);
@@ -131,7 +131,7 @@ void promoteTypeIds(Module &M, StringRef ModuleId) {
}
if (Function *PublicTypeTestFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::public_type_test))) {
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::public_type_test)) {
for (const Use &U : PublicTypeTestFunc->uses()) {
auto CI = cast<CallInst>(U.getUser());
ExternalizeTypeId(CI, 1);
@@ -139,15 +139,15 @@ void promoteTypeIds(Module &M, StringRef ModuleId) {
}
if (Function *TypeCheckedLoadFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load))) {
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_checked_load)) {
for (const Use &U : TypeCheckedLoadFunc->uses()) {
auto CI = cast<CallInst>(U.getUser());
ExternalizeTypeId(CI, 2);
}
}
- if (Function *TypeCheckedLoadRelativeFunc = M.getFunction(
- Intrinsic::getName(Intrinsic::type_checked_load_relative))) {
+ if (Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
+ &M, Intrinsic::type_checked_load_relative)) {
for (const Use &U : TypeCheckedLoadRelativeFunc->uses()) {
auto CI = cast<CallInst>(U.getUser());
ExternalizeTypeId(CI, 2);
diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
index 59f986b4ca2664..45d32218f362c5 100644
--- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -851,7 +851,7 @@ void llvm::updateVCallVisibilityInModule(
void llvm::updatePublicTypeTestCalls(Module &M,
bool WholeProgramVisibilityEnabledInLTO) {
Function *PublicTypeTestFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::public_type_test));
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::public_type_test);
if (!PublicTypeTestFunc)
return;
if (hasWholeProgramVisibility(WholeProgramVisibilityEnabledInLTO)) {
@@ -2247,12 +2247,13 @@ bool DevirtModule::run() {
return false;
Function *TypeTestFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::type_test));
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_test);
Function *TypeCheckedLoadFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load));
- Function *TypeCheckedLoadRelativeFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load_relative));
- Function *AssumeFunc = M.getFunction(Intrinsic::getName(Intrinsic::assume));
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_checked_load);
+ Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
+ &M, Intrinsic::type_checked_load_relative);
+ Function *AssumeFunc =
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::assume);
// Normally if there are no users of the devirtualization intrinsics in the
// module, this pass has nothing to do. But if we are exporting, we also need
diff --git a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
index 86637109d94083..43b8d5e6a8ce5b 100644
--- a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
+++ b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
@@ -944,7 +944,7 @@ computeVirtualCallSiteTypeInfoMap(Module &M, ModuleAnalysisManager &MAM,
// Find out virtual calls by looking at users of llvm.type.checked.load in
// that case.
Function *TypeTestFunc =
- M.getFunction(Intrinsic::getName(Intrinsic::type_test));
+ Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_test);
if (!TypeTestFunc || TypeTestFunc->use_empty())
return;
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index 929c787442057a..d7d809dfdd5f65 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -902,15 +902,15 @@ static bool needsRuntimeHookUnconditionally(const Triple &TT) {
/// Check if the module contains uses of any profiling intrinsics.
static bool containsProfilingIntrinsics(Module &M) {
auto containsIntrinsic = [&](int ID) {
- if (auto *F = M.getFunction(Intrinsic::getName(ID)))
+ if (auto *F = Intrinsic::getDeclarationIfExists(&M, ID))
return !F->use_empty();
return false;
};
- return containsIntrinsic(llvm::Intrinsic::instrprof_cover) ||
- containsIntrinsic(llvm::Intrinsic::instrprof_increment) ||
- containsIntrinsic(llvm::Intrinsic::instrprof_increment_step) ||
- containsIntrinsic(llvm::Intrinsic::instrprof_timestamp) ||
- containsIntrinsic(llvm::Intrinsic::instrprof_value_profile);
+ return containsIntrinsic(Intrinsic::instrprof_cover) ||
+ containsIntrinsic(Intrinsic::instrprof_increment) ||
+ containsIntrinsic(Intrinsic::instrprof_increment_step) ||
+ containsIntrinsic(Intrinsic::instrprof_timestamp) ||
+ containsIntrinsic(Intrinsic::instrprof_value_profile);
}
bool InstrLowerer::lower() {
diff --git a/llvm/lib/Transforms/Scalar/GuardWidening.cpp b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
index e7ff2a14469c5e..7fa9f42809091f 100644
--- a/llvm/lib/Transforms/Scalar/GuardWidening.cpp
+++ b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
@@ -980,11 +980,11 @@ StringRef GuardWideningImpl::scoreTypeToString(WideningScore WS) {
PreservedAnalyses GuardWideningPass::run(Function &F,
FunctionAnalysisManager &AM) {
// Avoid requesting analyses if there are no guards or widenable conditions.
- auto *GuardDecl = F.getParent()->getFunction(
- Intrinsic::getName(Intrinsic::experimental_guard));
+ auto *GuardDecl = Intrinsic::getDeclarationIfExists(
+ F.getParent(), Intrinsic::experimental_guard);
bool HasIntrinsicGuards = GuardDecl && !GuardDecl->use_empty();
- auto *WCDecl = F.getParent()->getFunction(
- Intrinsic::getName(Intrinsic::experimental_widenable_condition));
+ auto *WCDecl = Intrinsic::getDeclarationIfExists(
+ F.getParent(), Intrinsic::experimental_widenable_condition);
bool HasWidenableConditions = WCDecl && !WCDecl->use_empty();
if (!HasIntrinsicGuards && !HasWidenableConditions)
return PreservedAnalyses::all();
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index 2668305e9c8447..ad68fc1f21e2c2 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -598,8 +598,8 @@ bool IndVarSimplify::simplifyAndExtend(Loop *L,
LoopInfo *LI) {
SmallVector<WideIVInfo, 8> WideIVs;
- auto *GuardDecl = L->getBlocks()[0]->getModule()->getFunction(
- Intrinsic::getName(Intrinsic::experimental_guard));
+ auto *GuardDecl = Intrinsic::getDeclarationIfExists(
+ L->getBlocks()[0]->getModule(), Intrinsic::experimental_guard);
bool HasGuards = GuardDecl && !GuardDecl->use_empty();
SmallVector<PHINode *, 8> LoopPhis;
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 7a0b661a07799a..11fdc39464dfb6 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -296,8 +296,8 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
DTU = std::move(DTU_);
BFI = BFI_;
BPI = BPI_;
- auto *GuardDecl = F->getParent()->getFunction(
- Intrinsic::getName(Intrinsic::experimental_guard));
+ auto *GuardDecl = Intrinsic::getDeclarationIfExists(
+ F->getParent(), Intrinsic::experimental_guard);
HasGuards = GuardDecl && !GuardDecl->use_empty();
// Reduce the number of instructions duplicated when optimizing strictly for
diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
index 209b083a4e91a3..31694ad1fa508a 100644
--- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
@@ -1193,10 +1193,10 @@ bool LoopPredication::runOnLoop(Loop *Loop) {
// There is nothing to do if the module doesn't use guards
auto *GuardDecl =
- M->getFunction(Intrinsic::getName(Intrinsic::experimental_guard));
+ Intrinsic::getDeclarationIfExists(M, Intrinsic::experimental_guard);
bool HasIntrinsicGuards = GuardDecl && !GuardDecl->use_empty();
- auto *WCDecl = M->getFunction(
- Intrinsic::getName(Intrinsic::experimental_widenable_condition));
+ auto *WCDecl = Intrinsic::getDeclarationIfExists(
+ M, Intrinsic::experimental_widenable_condition);
bool HasWidenableConditions =
PredicateWidenableBranchGuards && WCDecl && !WCDecl->use_empty();
if (!HasIntrinsicGuards && !HasWidenableConditions)
diff --git a/llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp b/llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp
index ce35349376c483..5f3e612e73b661 100644
--- a/llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp
@@ -27,8 +27,8 @@ using namespace llvm;
static bool lowerGuardIntrinsic(Function &F) {
// Check if we can cheaply rule out the possibility of not having any work to
// do.
- auto *GuardDecl = F.getParent()->getFunction(
- Intrinsic::getName(Intrinsic::experimental_guard));
+ auto *GuardDecl = Intrinsic::getDeclarationIfExists(
+ F.getParent(), Intrinsic::experimental_guard);
if (!GuardDecl || GuardDecl->use_empty())
return false;
diff --git a/llvm/lib/Transforms/Scalar/LowerWidenableCondition.cpp b/llvm/lib/Transforms/Scalar/LowerWidenableCondition.cpp
index 3c977b816a0506..ea2b419b17a59c 100644
--- a/llvm/lib/Transforms/Scalar/LowerWidenableCondition.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerWidenableCondition.cpp
@@ -26,8 +26,8 @@ using namespace llvm;
static bool lowerWidenableCondition(Function &F) {
// Check if we can cheaply rule out the possibility of not having any work to
// do.
- auto *WCDecl = F.getParent()->getFunction(
- Intrinsic::getName(Intrinsic::experimental_widenable_condition));
+ auto *WCDecl = Intrinsic::getDeclarationIfExists(
+ F.getParent(), Intrinsic::experimental_widenable_condition);
if (!WCDecl || WCDecl->use_empty())
return false;
diff --git a/llvm/lib/Transforms/Scalar/MakeGuardsExplicit.cpp b/llvm/lib/Transforms/Scalar/MakeGuardsExplicit.cpp
index b9f88ba4e0780e..948466c675e974 100644
--- a/llvm/lib/Transforms/Scalar/MakeGuardsExplicit.cpp
+++ b/llvm/lib/Transforms/Scalar/MakeGuardsExplicit.cpp
@@ -56,8 +56,8 @@ static void turnToExplicitForm(CallInst *Guard, Function *DeoptIntrinsic) {
static bool explicifyGuards(Function &F) {
// Check if we can cheaply rule out the possibility of not having any work to
// do.
- auto *GuardDecl = F.getParent()->getFunction(
- Intrinsic::getName(Intrinsic::experimental_guard));
+ auto *GuardDecl = Intrinsic::getDeclarationIfExists(
+ F.getParent(), Intrinsic::experimental_guard);
if (!GuardDecl || GuardDecl->use_empty())
return false;
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index f3f5ffb6b61b47..aa3cbc5e4bddc2 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -2920,8 +2920,8 @@ static bool collectUnswitchCandidates(
// Whether or not we should also collect guards in the loop.
bool CollectGuards = false;
if (UnswitchGuards) {
- auto *GuardDecl = L.getHeader()->getParent()->getParent()->getFunction(
- Intrinsic::getName(Intrinsic::experimental_guard));
+ auto *GuardDecl = Intrinsic::getDeclarationIfExists(
+ L.getHeader()->getParent()->getParent(), Intrinsic::experimental_guard);
if (GuardDecl && !GuardDecl->use_empty())
CollectGuards = true;
}
More information about the llvm-commits
mailing list