Skip to content

[LLVM] Add Intrinsic::getDeclarationIfExists #112428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions llvm/include/llvm/IR/Intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/LazyValueInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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))
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/IR/Intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 7 additions & 7 deletions llvm/lib/LTO/LTO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/SIISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/IPO/ExpandVariadics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/IPO/GlobalDCE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/IPO/GlobalSplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/IPO/LowerTypeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,31 @@ 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);
}
}

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);
}
}

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);
Expand Down
13 changes: 7 additions & 6 deletions llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Scalar/GuardWidening.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/JumpThreading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Scalar/LoopPredication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/LowerWidenableCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/MakeGuardsExplicit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading