Skip to content

Commit 6924fc0

Browse files
authored
[LLVM] Add Intrinsic::getDeclarationIfExists (#112428)
Add `Intrinsic::getDeclarationIfExists` to lookup an existing declaration of an intrinsic in a `Module`.
1 parent cba7b36 commit 6924fc0

24 files changed

+89
-68
lines changed

llvm/include/llvm/IR/Intrinsics.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ namespace Intrinsic {
102102
inline Function *getDeclaration(Module *M, ID id, ArrayRef<Type *> Tys = {}) {
103103
return getOrInsertDeclaration(M, id, Tys);
104104
}
105+
106+
/// Look up the Function declaration of the intrinsic \p id in the Module
107+
/// \p M and return it if it exists. Otherwise, return nullptr. This version
108+
/// supports non-overloaded intrinsics.
109+
Function *getDeclarationIfExists(const Module *M, ID id);
110+
111+
/// This version supports overloaded intrinsics.
112+
Function *getDeclarationIfExists(Module *M, ID id, ArrayRef<Type *> Tys,
113+
FunctionType *FT = nullptr);
114+
105115
/// Looks up Name in NameTable via binary search. NameTable must be sorted
106116
/// and all entries must start with "llvm.". If NameTable contains an exact
107117
/// match for Name or a prefix of Name followed by a dot, its index in

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ LazyValueInfoImpl &LazyValueInfo::getOrCreateImpl(const Module *M) {
16131613
assert(M && "getCache() called with a null Module");
16141614
const DataLayout &DL = M->getDataLayout();
16151615
Function *GuardDecl =
1616-
M->getFunction(Intrinsic::getName(Intrinsic::experimental_guard));
1616+
Intrinsic::getDeclarationIfExists(M, Intrinsic::experimental_guard);
16171617
PImpl = new LazyValueInfoImpl(AC, DL, GuardDecl);
16181618
}
16191619
return *static_cast<LazyValueInfoImpl *>(PImpl);

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11665,8 +11665,8 @@ bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB,
1166511665
}
1166611666

1166711667
// Check conditions due to any @llvm.experimental.guard intrinsics.
11668-
auto *GuardDecl = F.getParent()->getFunction(
11669-
Intrinsic::getName(Intrinsic::experimental_guard));
11668+
auto *GuardDecl = Intrinsic::getDeclarationIfExists(
11669+
F.getParent(), Intrinsic::experimental_guard);
1167011670
if (GuardDecl)
1167111671
for (const auto *GU : GuardDecl->users())
1167211672
if (const auto *Guard = dyn_cast<IntrinsicInst>(GU))
@@ -13615,8 +13615,8 @@ ScalarEvolution::ScalarEvolution(Function &F, TargetLibraryInfo &TLI,
1361513615
// ScalarEvolution to optimize based on those guards. For now we prefer to be
1361613616
// efficient in lieu of being smart in that rather obscure case.
1361713617

13618-
auto *GuardDecl = F.getParent()->getFunction(
13619-
Intrinsic::getName(Intrinsic::experimental_guard));
13618+
auto *GuardDecl = Intrinsic::getDeclarationIfExists(
13619+
F.getParent(), Intrinsic::experimental_guard);
1362013620
HasGuards = GuardDecl && !GuardDecl->use_empty();
1362113621
}
1362213622

@@ -15593,8 +15593,8 @@ ScalarEvolution::LoopGuards::collect(const Loop *L, ScalarEvolution &SE) {
1559315593
}
1559415594

1559515595
// Second, collect information from llvm.experimental.guards dominating the loop.
15596-
auto *GuardDecl = SE.F.getParent()->getFunction(
15597-
Intrinsic::getName(Intrinsic::experimental_guard));
15596+
auto *GuardDecl = Intrinsic::getDeclarationIfExists(
15597+
SE.F.getParent(), Intrinsic::experimental_guard);
1559815598
if (GuardDecl)
1559915599
for (const auto *GU : GuardDecl->users())
1560015600
if (const auto *Guard = dyn_cast<IntrinsicInst>(GU))

llvm/lib/IR/Intrinsics.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,16 @@ Function *Intrinsic::getOrInsertDeclaration(Module *M, ID id,
724724
.getCallee());
725725
}
726726

727+
Function *Intrinsic::getDeclarationIfExists(const Module *M, ID id) {
728+
return M->getFunction(getName(id));
729+
}
730+
731+
Function *Intrinsic::getDeclarationIfExists(Module *M, ID id,
732+
ArrayRef<Type *> Tys,
733+
FunctionType *FT) {
734+
return M->getFunction(getName(id, Tys, M, FT));
735+
}
736+
727737
// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
728738
#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
729739
#include "llvm/IR/IntrinsicImpl.inc"

llvm/lib/LTO/LTO.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,13 +1120,13 @@ Error LTO::checkPartiallySplit() {
11201120
if (!ThinLTO.CombinedIndex.partiallySplitLTOUnits())
11211121
return Error::success();
11221122

1123-
Function *TypeTestFunc = RegularLTO.CombinedModule->getFunction(
1124-
Intrinsic::getName(Intrinsic::type_test));
1125-
Function *TypeCheckedLoadFunc = RegularLTO.CombinedModule->getFunction(
1126-
Intrinsic::getName(Intrinsic::type_checked_load));
1127-
Function *TypeCheckedLoadRelativeFunc =
1128-
RegularLTO.CombinedModule->getFunction(
1129-
Intrinsic::getName(Intrinsic::type_checked_load_relative));
1123+
const Module *Combined = RegularLTO.CombinedModule.get();
1124+
Function *TypeTestFunc =
1125+
Intrinsic::getDeclarationIfExists(Combined, Intrinsic::type_test);
1126+
Function *TypeCheckedLoadFunc =
1127+
Intrinsic::getDeclarationIfExists(Combined, Intrinsic::type_checked_load);
1128+
Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
1129+
Combined, Intrinsic::type_checked_load_relative);
11301130

11311131
// First check if there are type tests / type checked loads in the
11321132
// merged regular LTO module IR.

llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ class PreloadKernelArgInfo {
171171
// Try to allocate SGPRs to preload implicit kernel arguments.
172172
void tryAllocImplicitArgPreloadSGPRs(uint64_t ImplicitArgsBaseOffset,
173173
IRBuilder<> &Builder) {
174-
StringRef Name = Intrinsic::getName(Intrinsic::amdgcn_implicitarg_ptr);
175-
Function *ImplicitArgPtr = F.getParent()->getFunction(Name);
174+
Function *ImplicitArgPtr = Intrinsic::getDeclarationIfExists(
175+
F.getParent(), Intrinsic::amdgcn_implicitarg_ptr);
176176
if (!ImplicitArgPtr)
177177
return;
178178

llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ class AMDGPULowerKernelAttributes : public ModulePass {
7878
Function *getBasePtrIntrinsic(Module &M, bool IsV5OrAbove) {
7979
auto IntrinsicId = IsV5OrAbove ? Intrinsic::amdgcn_implicitarg_ptr
8080
: Intrinsic::amdgcn_dispatch_ptr;
81-
StringRef Name = Intrinsic::getName(IntrinsicId);
82-
return M.getFunction(Name);
81+
return Intrinsic::getDeclarationIfExists(&M, IntrinsicId);
8382
}
8483

8584
} // end anonymous namespace

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8786,7 +8786,7 @@ SDValue SITargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
87868786

87878787
const Module *M = MF.getFunction().getParent();
87888788
const GlobalValue *GV =
8789-
M->getNamedValue(Intrinsic::getName(Intrinsic::amdgcn_groupstaticsize));
8789+
Intrinsic::getDeclarationIfExists(M, Intrinsic::amdgcn_groupstaticsize);
87908790
SDValue GA = DAG.getTargetGlobalAddress(GV, DL, MVT::i32, 0,
87918791
SIInstrInfo::MO_ABS32_LO);
87928792
return {DAG.getMachineNode(AMDGPU::S_MOV_B32, DL, MVT::i32, GA), 0};

llvm/lib/Transforms/IPO/ExpandVariadics.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ class VariadicABIInfo {
145145
// function here in the meantime to decouple from that discussion.
146146
Function *getPreexistingDeclaration(Module *M, Intrinsic::ID Id,
147147
ArrayRef<Type *> Tys = {}) {
148+
if (Tys.empty())
149+
return Intrinsic::getDeclarationIfExists(M, Id);
148150
auto *FT = Intrinsic::getType(M->getContext(), Id, Tys);
149-
return M->getFunction(Tys.empty() ? Intrinsic::getName(Id)
150-
: Intrinsic::getName(Id, Tys, M, FT));
151+
return Intrinsic::getDeclarationIfExists(M, Id, Tys, FT);
151152
}
152153

153154
class ExpandVariadics : public ModulePass {

llvm/lib/Transforms/IPO/GlobalDCE.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ void GlobalDCEPass::ScanVTableLoad(Function *Caller, Metadata *TypeId,
186186
void GlobalDCEPass::ScanTypeCheckedLoadIntrinsics(Module &M) {
187187
LLVM_DEBUG(dbgs() << "Scanning type.checked.load intrinsics\n");
188188
Function *TypeCheckedLoadFunc =
189-
M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load));
190-
Function *TypeCheckedLoadRelativeFunc =
191-
M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load_relative));
189+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_checked_load);
190+
Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
191+
&M, Intrinsic::type_checked_load_relative);
192192

193193
auto scan = [&](Function *CheckedLoadFunc) {
194194
if (!CheckedLoadFunc)

llvm/lib/Transforms/IPO/GlobalSplit.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ static bool splitGlobals(Module &M) {
174174
// llvm.type.checked.load intrinsics, which indicates that splitting globals
175175
// may be beneficial.
176176
Function *TypeTestFunc =
177-
M.getFunction(Intrinsic::getName(Intrinsic::type_test));
177+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_test);
178178
Function *TypeCheckedLoadFunc =
179-
M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load));
180-
Function *TypeCheckedLoadRelativeFunc =
181-
M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load_relative));
179+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_checked_load);
180+
Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
181+
&M, Intrinsic::type_checked_load_relative);
182182
if ((!TypeTestFunc || TypeTestFunc->use_empty()) &&
183183
(!TypeCheckedLoadFunc || TypeCheckedLoadFunc->use_empty()) &&
184184
(!TypeCheckedLoadRelativeFunc ||

llvm/lib/Transforms/IPO/LowerTypeTests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,7 @@ static void dropTypeTests(Module &M, Function &TypeTestFunc) {
19701970

19711971
bool LowerTypeTestsModule::lower() {
19721972
Function *TypeTestFunc =
1973-
M.getFunction(Intrinsic::getName(Intrinsic::type_test));
1973+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_test);
19741974

19751975
if (DropTypeTests) {
19761976
if (TypeTestFunc)
@@ -1979,7 +1979,7 @@ bool LowerTypeTestsModule::lower() {
19791979
// except for in the case where we originally were performing ThinLTO but
19801980
// decided not to in the backend.
19811981
Function *PublicTypeTestFunc =
1982-
M.getFunction(Intrinsic::getName(Intrinsic::public_type_test));
1982+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::public_type_test);
19831983
if (PublicTypeTestFunc)
19841984
dropTypeTests(M, *PublicTypeTestFunc);
19851985
if (TypeTestFunc || PublicTypeTestFunc) {
@@ -2002,7 +2002,7 @@ bool LowerTypeTestsModule::lower() {
20022002
return false;
20032003

20042004
Function *ICallBranchFunnelFunc =
2005-
M.getFunction(Intrinsic::getName(Intrinsic::icall_branch_funnel));
2005+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::icall_branch_funnel);
20062006
if ((!TypeTestFunc || TypeTestFunc->use_empty()) &&
20072007
(!ICallBranchFunnelFunc || ICallBranchFunnelFunc->use_empty()) &&
20082008
!ExportSummary && !ImportSummary)

llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,31 +123,31 @@ void promoteTypeIds(Module &M, StringRef ModuleId) {
123123
};
124124

125125
if (Function *TypeTestFunc =
126-
M.getFunction(Intrinsic::getName(Intrinsic::type_test))) {
126+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_test)) {
127127
for (const Use &U : TypeTestFunc->uses()) {
128128
auto CI = cast<CallInst>(U.getUser());
129129
ExternalizeTypeId(CI, 1);
130130
}
131131
}
132132

133133
if (Function *PublicTypeTestFunc =
134-
M.getFunction(Intrinsic::getName(Intrinsic::public_type_test))) {
134+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::public_type_test)) {
135135
for (const Use &U : PublicTypeTestFunc->uses()) {
136136
auto CI = cast<CallInst>(U.getUser());
137137
ExternalizeTypeId(CI, 1);
138138
}
139139
}
140140

141141
if (Function *TypeCheckedLoadFunc =
142-
M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load))) {
142+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_checked_load)) {
143143
for (const Use &U : TypeCheckedLoadFunc->uses()) {
144144
auto CI = cast<CallInst>(U.getUser());
145145
ExternalizeTypeId(CI, 2);
146146
}
147147
}
148148

149-
if (Function *TypeCheckedLoadRelativeFunc = M.getFunction(
150-
Intrinsic::getName(Intrinsic::type_checked_load_relative))) {
149+
if (Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
150+
&M, Intrinsic::type_checked_load_relative)) {
151151
for (const Use &U : TypeCheckedLoadRelativeFunc->uses()) {
152152
auto CI = cast<CallInst>(U.getUser());
153153
ExternalizeTypeId(CI, 2);

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ void llvm::updateVCallVisibilityInModule(
851851
void llvm::updatePublicTypeTestCalls(Module &M,
852852
bool WholeProgramVisibilityEnabledInLTO) {
853853
Function *PublicTypeTestFunc =
854-
M.getFunction(Intrinsic::getName(Intrinsic::public_type_test));
854+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::public_type_test);
855855
if (!PublicTypeTestFunc)
856856
return;
857857
if (hasWholeProgramVisibility(WholeProgramVisibilityEnabledInLTO)) {
@@ -2247,12 +2247,13 @@ bool DevirtModule::run() {
22472247
return false;
22482248

22492249
Function *TypeTestFunc =
2250-
M.getFunction(Intrinsic::getName(Intrinsic::type_test));
2250+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_test);
22512251
Function *TypeCheckedLoadFunc =
2252-
M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load));
2253-
Function *TypeCheckedLoadRelativeFunc =
2254-
M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load_relative));
2255-
Function *AssumeFunc = M.getFunction(Intrinsic::getName(Intrinsic::assume));
2252+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_checked_load);
2253+
Function *TypeCheckedLoadRelativeFunc = Intrinsic::getDeclarationIfExists(
2254+
&M, Intrinsic::type_checked_load_relative);
2255+
Function *AssumeFunc =
2256+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::assume);
22562257

22572258
// Normally if there are no users of the devirtualization intrinsics in the
22582259
// module, this pass has nothing to do. But if we are exporting, we also need

llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ computeVirtualCallSiteTypeInfoMap(Module &M, ModuleAnalysisManager &MAM,
944944
// Find out virtual calls by looking at users of llvm.type.checked.load in
945945
// that case.
946946
Function *TypeTestFunc =
947-
M.getFunction(Intrinsic::getName(Intrinsic::type_test));
947+
Intrinsic::getDeclarationIfExists(&M, Intrinsic::type_test);
948948
if (!TypeTestFunc || TypeTestFunc->use_empty())
949949
return;
950950

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -902,15 +902,15 @@ static bool needsRuntimeHookUnconditionally(const Triple &TT) {
902902
/// Check if the module contains uses of any profiling intrinsics.
903903
static bool containsProfilingIntrinsics(Module &M) {
904904
auto containsIntrinsic = [&](int ID) {
905-
if (auto *F = M.getFunction(Intrinsic::getName(ID)))
905+
if (auto *F = Intrinsic::getDeclarationIfExists(&M, ID))
906906
return !F->use_empty();
907907
return false;
908908
};
909-
return containsIntrinsic(llvm::Intrinsic::instrprof_cover) ||
910-
containsIntrinsic(llvm::Intrinsic::instrprof_increment) ||
911-
containsIntrinsic(llvm::Intrinsic::instrprof_increment_step) ||
912-
containsIntrinsic(llvm::Intrinsic::instrprof_timestamp) ||
913-
containsIntrinsic(llvm::Intrinsic::instrprof_value_profile);
909+
return containsIntrinsic(Intrinsic::instrprof_cover) ||
910+
containsIntrinsic(Intrinsic::instrprof_increment) ||
911+
containsIntrinsic(Intrinsic::instrprof_increment_step) ||
912+
containsIntrinsic(Intrinsic::instrprof_timestamp) ||
913+
containsIntrinsic(Intrinsic::instrprof_value_profile);
914914
}
915915

916916
bool InstrLowerer::lower() {

llvm/lib/Transforms/Scalar/GuardWidening.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,11 +980,11 @@ StringRef GuardWideningImpl::scoreTypeToString(WideningScore WS) {
980980
PreservedAnalyses GuardWideningPass::run(Function &F,
981981
FunctionAnalysisManager &AM) {
982982
// Avoid requesting analyses if there are no guards or widenable conditions.
983-
auto *GuardDecl = F.getParent()->getFunction(
984-
Intrinsic::getName(Intrinsic::experimental_guard));
983+
auto *GuardDecl = Intrinsic::getDeclarationIfExists(
984+
F.getParent(), Intrinsic::experimental_guard);
985985
bool HasIntrinsicGuards = GuardDecl && !GuardDecl->use_empty();
986-
auto *WCDecl = F.getParent()->getFunction(
987-
Intrinsic::getName(Intrinsic::experimental_widenable_condition));
986+
auto *WCDecl = Intrinsic::getDeclarationIfExists(
987+
F.getParent(), Intrinsic::experimental_widenable_condition);
988988
bool HasWidenableConditions = WCDecl && !WCDecl->use_empty();
989989
if (!HasIntrinsicGuards && !HasWidenableConditions)
990990
return PreservedAnalyses::all();

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ bool IndVarSimplify::simplifyAndExtend(Loop *L,
598598
LoopInfo *LI) {
599599
SmallVector<WideIVInfo, 8> WideIVs;
600600

601-
auto *GuardDecl = L->getBlocks()[0]->getModule()->getFunction(
602-
Intrinsic::getName(Intrinsic::experimental_guard));
601+
auto *GuardDecl = Intrinsic::getDeclarationIfExists(
602+
L->getBlocks()[0]->getModule(), Intrinsic::experimental_guard);
603603
bool HasGuards = GuardDecl && !GuardDecl->use_empty();
604604

605605
SmallVector<PHINode *, 8> LoopPhis;

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
296296
DTU = std::move(DTU_);
297297
BFI = BFI_;
298298
BPI = BPI_;
299-
auto *GuardDecl = F->getParent()->getFunction(
300-
Intrinsic::getName(Intrinsic::experimental_guard));
299+
auto *GuardDecl = Intrinsic::getDeclarationIfExists(
300+
F->getParent(), Intrinsic::experimental_guard);
301301
HasGuards = GuardDecl && !GuardDecl->use_empty();
302302

303303
// Reduce the number of instructions duplicated when optimizing strictly for

llvm/lib/Transforms/Scalar/LoopPredication.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,10 +1193,10 @@ bool LoopPredication::runOnLoop(Loop *Loop) {
11931193

11941194
// There is nothing to do if the module doesn't use guards
11951195
auto *GuardDecl =
1196-
M->getFunction(Intrinsic::getName(Intrinsic::experimental_guard));
1196+
Intrinsic::getDeclarationIfExists(M, Intrinsic::experimental_guard);
11971197
bool HasIntrinsicGuards = GuardDecl && !GuardDecl->use_empty();
1198-
auto *WCDecl = M->getFunction(
1199-
Intrinsic::getName(Intrinsic::experimental_widenable_condition));
1198+
auto *WCDecl = Intrinsic::getDeclarationIfExists(
1199+
M, Intrinsic::experimental_widenable_condition);
12001200
bool HasWidenableConditions =
12011201
PredicateWidenableBranchGuards && WCDecl && !WCDecl->use_empty();
12021202
if (!HasIntrinsicGuards && !HasWidenableConditions)

llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ using namespace llvm;
2727
static bool lowerGuardIntrinsic(Function &F) {
2828
// Check if we can cheaply rule out the possibility of not having any work to
2929
// do.
30-
auto *GuardDecl = F.getParent()->getFunction(
31-
Intrinsic::getName(Intrinsic::experimental_guard));
30+
auto *GuardDecl = Intrinsic::getDeclarationIfExists(
31+
F.getParent(), Intrinsic::experimental_guard);
3232
if (!GuardDecl || GuardDecl->use_empty())
3333
return false;
3434

llvm/lib/Transforms/Scalar/LowerWidenableCondition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ using namespace llvm;
2626
static bool lowerWidenableCondition(Function &F) {
2727
// Check if we can cheaply rule out the possibility of not having any work to
2828
// do.
29-
auto *WCDecl = F.getParent()->getFunction(
30-
Intrinsic::getName(Intrinsic::experimental_widenable_condition));
29+
auto *WCDecl = Intrinsic::getDeclarationIfExists(
30+
F.getParent(), Intrinsic::experimental_widenable_condition);
3131
if (!WCDecl || WCDecl->use_empty())
3232
return false;
3333

llvm/lib/Transforms/Scalar/MakeGuardsExplicit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ static void turnToExplicitForm(CallInst *Guard, Function *DeoptIntrinsic) {
5656
static bool explicifyGuards(Function &F) {
5757
// Check if we can cheaply rule out the possibility of not having any work to
5858
// do.
59-
auto *GuardDecl = F.getParent()->getFunction(
60-
Intrinsic::getName(Intrinsic::experimental_guard));
59+
auto *GuardDecl = Intrinsic::getDeclarationIfExists(
60+
F.getParent(), Intrinsic::experimental_guard);
6161
if (!GuardDecl || GuardDecl->use_empty())
6262
return false;
6363

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,8 +2920,8 @@ static bool collectUnswitchCandidates(
29202920
// Whether or not we should also collect guards in the loop.
29212921
bool CollectGuards = false;
29222922
if (UnswitchGuards) {
2923-
auto *GuardDecl = L.getHeader()->getParent()->getParent()->getFunction(
2924-
Intrinsic::getName(Intrinsic::experimental_guard));
2923+
auto *GuardDecl = Intrinsic::getDeclarationIfExists(
2924+
L.getHeader()->getParent()->getParent(), Intrinsic::experimental_guard);
29252925
if (GuardDecl && !GuardDecl->use_empty())
29262926
CollectGuards = true;
29272927
}

0 commit comments

Comments
 (0)