Skip to content

Commit fa789df

Browse files
authored
[NFC] Rename Intrinsic::getDeclaration to getOrInsertDeclaration (#111752)
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).
1 parent 900ea21 commit fa789df

File tree

137 files changed

+721
-642
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+721
-642
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13648,7 +13648,7 @@ Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID,
1364813648
Value *InfoKind = ConstantInt::get(Int64Ty, C->getSExtValue());
1364913649

1365013650
// Built the IR for the preserve_field_info intrinsic.
13651-
llvm::Function *FnGetFieldInfo = llvm::Intrinsic::getDeclaration(
13651+
llvm::Function *FnGetFieldInfo = llvm::Intrinsic::getOrInsertDeclaration(
1365213652
&CGM.getModule(), llvm::Intrinsic::bpf_preserve_field_info,
1365313653
{FieldAddr->getType()});
1365413654
return Builder.CreateCall(FnGetFieldInfo, {FieldAddr, InfoKind});
@@ -13670,10 +13670,10 @@ Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID,
1367013670

1367113671
llvm::Function *FnDecl;
1367213672
if (BuiltinID == BPF::BI__builtin_btf_type_id)
13673-
FnDecl = llvm::Intrinsic::getDeclaration(
13673+
FnDecl = llvm::Intrinsic::getOrInsertDeclaration(
1367413674
&CGM.getModule(), llvm::Intrinsic::bpf_btf_type_id, {});
1367513675
else
13676-
FnDecl = llvm::Intrinsic::getDeclaration(
13676+
FnDecl = llvm::Intrinsic::getOrInsertDeclaration(
1367713677
&CGM.getModule(), llvm::Intrinsic::bpf_preserve_type_info, {});
1367813678
CallInst *Fn = Builder.CreateCall(FnDecl, {SeqNumVal, FlagValue});
1367913679
Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
@@ -13708,7 +13708,7 @@ Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID,
1370813708
Value *FlagValue = ConstantInt::get(Int64Ty, Flag->getSExtValue());
1370913709
Value *SeqNumVal = ConstantInt::get(Int32Ty, BuiltinSeqNum++);
1371013710

13711-
llvm::Function *IntrinsicFn = llvm::Intrinsic::getDeclaration(
13711+
llvm::Function *IntrinsicFn = llvm::Intrinsic::getOrInsertDeclaration(
1371213712
&CGM.getModule(), llvm::Intrinsic::bpf_preserve_enum_value, {});
1371313713
CallInst *Fn =
1371413714
Builder.CreateCall(IntrinsicFn, {SeqNumVal, EnumStrVal, FlagValue});
@@ -18895,7 +18895,8 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1889518895
}
1889618896
case Builtin::BI__builtin_hlsl_wave_is_first_lane: {
1889718897
Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveIsFirstLaneIntrinsic();
18898-
return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID));
18898+
return EmitRuntimeCall(
18899+
Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID));
1889918900
}
1890018901
case Builtin::BI__builtin_hlsl_elementwise_sign: {
1890118902
auto *Arg0 = E->getArg(0);

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,17 +2509,17 @@ void CodeGenFunction::pushRegularPartialArrayCleanup(llvm::Value *arrayBegin,
25092509
llvm::Function *CodeGenModule::getLLVMLifetimeStartFn() {
25102510
if (LifetimeStartFn)
25112511
return LifetimeStartFn;
2512-
LifetimeStartFn = llvm::Intrinsic::getDeclaration(&getModule(),
2513-
llvm::Intrinsic::lifetime_start, AllocaInt8PtrTy);
2512+
LifetimeStartFn = llvm::Intrinsic::getOrInsertDeclaration(
2513+
&getModule(), llvm::Intrinsic::lifetime_start, AllocaInt8PtrTy);
25142514
return LifetimeStartFn;
25152515
}
25162516

25172517
/// Lazily declare the @llvm.lifetime.end intrinsic.
25182518
llvm::Function *CodeGenModule::getLLVMLifetimeEndFn() {
25192519
if (LifetimeEndFn)
25202520
return LifetimeEndFn;
2521-
LifetimeEndFn = llvm::Intrinsic::getDeclaration(&getModule(),
2522-
llvm::Intrinsic::lifetime_end, AllocaInt8PtrTy);
2521+
LifetimeEndFn = llvm::Intrinsic::getOrInsertDeclaration(
2522+
&getModule(), llvm::Intrinsic::lifetime_end, AllocaInt8PtrTy);
25232523
return LifetimeEndFn;
25242524
}
25252525

clang/lib/CodeGen/CGException.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF,
18431843
std::make_pair(ParentAlloca, ParentCGF.EscapedLocals.size()));
18441844
int FrameEscapeIdx = InsertPair.first->second;
18451845
// call ptr @llvm.localrecover(ptr @parentFn, ptr %fp, i32 N)
1846-
llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration(
1846+
llvm::Function *FrameRecoverFn = llvm::Intrinsic::getOrInsertDeclaration(
18471847
&CGM.getModule(), llvm::Intrinsic::localrecover);
18481848
RecoverCall = Builder.CreateCall(
18491849
FrameRecoverFn, {ParentCGF.CurFn, ParentFP,
@@ -1942,7 +1942,7 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF,
19421942
// %1 = call ptr @llvm.localrecover(@"?fin$0@0@main@@",..)
19431943
// %2 = load ptr, ptr %1, align 8
19441944
// ==> %2 is the frame-pointer of outermost host function
1945-
llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration(
1945+
llvm::Function *FrameRecoverFn = llvm::Intrinsic::getOrInsertDeclaration(
19461946
&CGM.getModule(), llvm::Intrinsic::localrecover);
19471947
ParentFP = Builder.CreateCall(
19481948
FrameRecoverFn, {ParentCGF.CurFn, ParentFP,

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
463463
EscapeArgs.resize(EscapedLocals.size());
464464
for (auto &Pair : EscapedLocals)
465465
EscapeArgs[Pair.second] = Pair.first;
466-
llvm::Function *FrameEscapeFn = llvm::Intrinsic::getDeclaration(
466+
llvm::Function *FrameEscapeFn = llvm::Intrinsic::getOrInsertDeclaration(
467467
&CGM.getModule(), llvm::Intrinsic::localescape);
468468
CGBuilderTy(*this, AllocaInsertPt).CreateCall(FrameEscapeFn, EscapeArgs);
469469
}
@@ -3130,7 +3130,7 @@ void CodeGenFunction::emitAlignmentAssumptionCheck(
31303130
llvm::Instruction *Assumption) {
31313131
assert(isa_and_nonnull<llvm::CallInst>(Assumption) &&
31323132
cast<llvm::CallInst>(Assumption)->getCalledOperand() ==
3133-
llvm::Intrinsic::getDeclaration(
3133+
llvm::Intrinsic::getOrInsertDeclaration(
31343134
Builder.GetInsertBlock()->getParent()->getParent(),
31353135
llvm::Intrinsic::assume) &&
31363136
"Assumption should be a call to llvm.assume().");

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6218,8 +6218,8 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
62186218

62196219
llvm::Function *CodeGenModule::getIntrinsic(unsigned IID,
62206220
ArrayRef<llvm::Type*> Tys) {
6221-
return llvm::Intrinsic::getDeclaration(&getModule(), (llvm::Intrinsic::ID)IID,
6222-
Tys);
6221+
return llvm::Intrinsic::getOrInsertDeclaration(&getModule(),
6222+
(llvm::Intrinsic::ID)IID, Tys);
62236223
}
62246224

62256225
static llvm::StringMapEntry<llvm::GlobalVariable *> &

clang/lib/CodeGen/Targets/SystemZ.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class SystemZTargetCodeGenInfo : public TargetCodeGenInfo {
110110
if (Ty->isFloatTy() || Ty->isDoubleTy() || Ty->isFP128Ty()) {
111111
llvm::Module &M = CGM.getModule();
112112
auto &Ctx = M.getContext();
113-
llvm::Function *TDCFunc =
114-
llvm::Intrinsic::getDeclaration(&M, llvm::Intrinsic::s390_tdc, Ty);
113+
llvm::Function *TDCFunc = llvm::Intrinsic::getOrInsertDeclaration(
114+
&M, llvm::Intrinsic::s390_tdc, Ty);
115115
unsigned TDCBits = 0;
116116
switch (BuiltinID) {
117117
case Builtin::BI__builtin_isnan:

llvm/examples/BrainF/BrainF.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ void BrainF::header(LLVMContext& C) {
6767

6868
//declare void @llvm.memset.p0i8.i32(i8 *, i8, i32, i1)
6969
Type *Tys[] = {PointerType::getUnqual(C), Type::getInt32Ty(C)};
70-
Function *memset_func = Intrinsic::getDeclaration(module, Intrinsic::memset,
71-
Tys);
70+
Function *memset_func =
71+
Intrinsic::getOrInsertDeclaration(module, Intrinsic::memset, Tys);
7272

7373
//declare i32 @getchar()
7474
getchar_func =

llvm/include/llvm-c/Core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,10 +2807,10 @@ unsigned LLVMLookupIntrinsicID(const char *Name, size_t NameLen);
28072807
unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
28082808

28092809
/**
2810-
* Create or insert the declaration of an intrinsic. For overloaded intrinsics,
2810+
* Get or insert the declaration of an intrinsic. For overloaded intrinsics,
28112811
* parameter types must be provided to uniquely identify an overload.
28122812
*
2813-
* @see llvm::Intrinsic::getDeclaration()
2813+
* @see llvm::Intrinsic::getOrInsertDeclaration()
28142814
*/
28152815
LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod,
28162816
unsigned ID,

llvm/include/llvm/IR/IntrinsicInst.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,9 @@ class VPIntrinsic : public IntrinsicInst {
568568
/// \brief Declares a llvm.vp.* intrinsic in \p M that matches the parameters
569569
/// \p Params. Additionally, the load and gather intrinsics require
570570
/// \p ReturnType to be specified.
571-
static Function *getDeclarationForParams(Module *M, Intrinsic::ID,
572-
Type *ReturnType,
573-
ArrayRef<Value *> Params);
571+
static Function *getOrInsertDeclarationForParams(Module *M, Intrinsic::ID,
572+
Type *ReturnType,
573+
ArrayRef<Value *> Params);
574574

575575
static std::optional<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID);
576576
static std::optional<unsigned> getVectorLengthParamPos(

llvm/include/llvm/IR/Intrinsics.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,15 @@ namespace Intrinsic {
8787
/// Return the attributes for an intrinsic.
8888
AttributeList getAttributes(LLVMContext &C, ID id);
8989

90-
/// Create or insert an LLVM Function declaration for an intrinsic, and return
91-
/// it.
90+
/// Look up the Function declaration of the intrinsic \p id in the Module
91+
/// \p M. If it does not exist, add a declaration and return it. Otherwise,
92+
/// return the existing declaration.
9293
///
93-
/// The Tys parameter is for intrinsics with overloaded types (e.g., those
94+
/// The \p Tys parameter is for intrinsics with overloaded types (e.g., those
9495
/// using iAny, fAny, vAny, or iPTRAny). For a declaration of an overloaded
9596
/// intrinsic, Tys must provide exactly one type for each overloaded type in
9697
/// the intrinsic.
97-
Function *getDeclaration(Module *M, ID id, ArrayRef<Type *> Tys = {});
98+
Function *getOrInsertDeclaration(Module *M, ID id, ArrayRef<Type *> Tys = {});
9899

99100
/// Looks up Name in NameTable via binary search. NameTable must be sorted
100101
/// and all entries must start with "llvm.". If NameTable contains an exact

llvm/include/llvm/IR/MatrixBuilder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class MatrixBuilder {
7272
B.getInt32(Columns)};
7373
Type *OverloadedTypes[] = {RetType, Stride->getType()};
7474

75-
Function *TheFn = Intrinsic::getDeclaration(
75+
Function *TheFn = Intrinsic::getOrInsertDeclaration(
7676
getModule(), Intrinsic::matrix_column_major_load, OverloadedTypes);
7777

7878
CallInst *Call = B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name);
@@ -95,7 +95,7 @@ class MatrixBuilder {
9595
B.getInt32(Rows), B.getInt32(Columns)};
9696
Type *OverloadedTypes[] = {Matrix->getType(), Stride->getType()};
9797

98-
Function *TheFn = Intrinsic::getDeclaration(
98+
Function *TheFn = Intrinsic::getOrInsertDeclaration(
9999
getModule(), Intrinsic::matrix_column_major_store, OverloadedTypes);
100100

101101
CallInst *Call = B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name);
@@ -115,7 +115,7 @@ class MatrixBuilder {
115115

116116
Type *OverloadedTypes[] = {ReturnType};
117117
Value *Ops[] = {Matrix, B.getInt32(Rows), B.getInt32(Columns)};
118-
Function *TheFn = Intrinsic::getDeclaration(
118+
Function *TheFn = Intrinsic::getOrInsertDeclaration(
119119
getModule(), Intrinsic::matrix_transpose, OverloadedTypes);
120120

121121
return B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name);
@@ -136,7 +136,7 @@ class MatrixBuilder {
136136
B.getInt32(RHSColumns)};
137137
Type *OverloadedTypes[] = {ReturnType, LHSType, RHSType};
138138

139-
Function *TheFn = Intrinsic::getDeclaration(
139+
Function *TheFn = Intrinsic::getOrInsertDeclaration(
140140
getModule(), Intrinsic::matrix_multiply, OverloadedTypes);
141141
return B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name);
142142
}

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
360360
OverloadTys))
361361
return error(Info.second, "invalid intrinsic signature");
362362

363-
U.set(Intrinsic::getDeclaration(M, IID, OverloadTys));
363+
U.set(Intrinsic::getOrInsertDeclaration(M, IID, OverloadTys));
364364
}
365365

366366
Info.first->eraseFromParent();

llvm/lib/CodeGen/ExpandLargeFpConvert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static void expandIToFP(Instruction *IToFP) {
356356
Entry->getTerminator()->eraseFromParent();
357357

358358
Function *CTLZ =
359-
Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz, IntTy);
359+
Intrinsic::getOrInsertDeclaration(F->getParent(), Intrinsic::ctlz, IntTy);
360360
ConstantInt *True = Builder.getTrue();
361361

362362
// entry:

llvm/lib/CodeGen/ExpandMemCmp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ MemCmpExpansion::LoadPair MemCmpExpansion::getLoadPair(Type *LoadSizeType,
355355

356356
// Swap bytes if required.
357357
if (BSwapSizeType) {
358-
Function *Bswap = Intrinsic::getDeclaration(
358+
Function *Bswap = Intrinsic::getOrInsertDeclaration(
359359
CI->getModule(), Intrinsic::bswap, BSwapSizeType);
360360
Lhs = Builder.CreateCall(Bswap, Lhs);
361361
Rhs = Builder.CreateCall(Bswap, Rhs);

llvm/lib/CodeGen/ExpandVectorPredication.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ Value *CachingVPExpander::convertEVLToMask(IRBuilder<> &Builder,
237237
if (ElemCount.isScalable()) {
238238
auto *M = Builder.GetInsertBlock()->getModule();
239239
Type *BoolVecTy = VectorType::get(Builder.getInt1Ty(), ElemCount);
240-
Function *ActiveMaskFunc = Intrinsic::getDeclaration(
240+
Function *ActiveMaskFunc = Intrinsic::getOrInsertDeclaration(
241241
M, Intrinsic::get_active_lane_mask, {BoolVecTy, EVLParam->getType()});
242242
// `get_active_lane_mask` performs an implicit less-than comparison.
243243
Value *ConstZero = Builder.getInt32(0);
@@ -299,7 +299,7 @@ Value *CachingVPExpander::expandPredicationToIntCall(
299299
case Intrinsic::umin: {
300300
Value *Op0 = VPI.getOperand(0);
301301
Value *Op1 = VPI.getOperand(1);
302-
Function *Fn = Intrinsic::getDeclaration(
302+
Function *Fn = Intrinsic::getOrInsertDeclaration(
303303
VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()});
304304
Value *NewOp = Builder.CreateCall(Fn, {Op0, Op1}, VPI.getName());
305305
replaceOperation(*NewOp, VPI);
@@ -308,7 +308,7 @@ Value *CachingVPExpander::expandPredicationToIntCall(
308308
case Intrinsic::bswap:
309309
case Intrinsic::bitreverse: {
310310
Value *Op = VPI.getOperand(0);
311-
Function *Fn = Intrinsic::getDeclaration(
311+
Function *Fn = Intrinsic::getOrInsertDeclaration(
312312
VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()});
313313
Value *NewOp = Builder.CreateCall(Fn, {Op}, VPI.getName());
314314
replaceOperation(*NewOp, VPI);
@@ -327,7 +327,7 @@ Value *CachingVPExpander::expandPredicationToFPCall(
327327
case Intrinsic::fabs:
328328
case Intrinsic::sqrt: {
329329
Value *Op0 = VPI.getOperand(0);
330-
Function *Fn = Intrinsic::getDeclaration(
330+
Function *Fn = Intrinsic::getOrInsertDeclaration(
331331
VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()});
332332
Value *NewOp = Builder.CreateCall(Fn, {Op0}, VPI.getName());
333333
replaceOperation(*NewOp, VPI);
@@ -337,7 +337,7 @@ Value *CachingVPExpander::expandPredicationToFPCall(
337337
case Intrinsic::minnum: {
338338
Value *Op0 = VPI.getOperand(0);
339339
Value *Op1 = VPI.getOperand(1);
340-
Function *Fn = Intrinsic::getDeclaration(
340+
Function *Fn = Intrinsic::getOrInsertDeclaration(
341341
VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()});
342342
Value *NewOp = Builder.CreateCall(Fn, {Op0, Op1}, VPI.getName());
343343
replaceOperation(*NewOp, VPI);
@@ -350,7 +350,7 @@ Value *CachingVPExpander::expandPredicationToFPCall(
350350
Value *Op0 = VPI.getOperand(0);
351351
Value *Op1 = VPI.getOperand(1);
352352
Value *Op2 = VPI.getOperand(2);
353-
Function *Fn = Intrinsic::getDeclaration(
353+
Function *Fn = Intrinsic::getOrInsertDeclaration(
354354
VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()});
355355
Value *NewOp;
356356
if (Intrinsic::isConstrainedFPIntrinsic(UnpredicatedIntrinsicID))
@@ -594,7 +594,7 @@ bool CachingVPExpander::discardEVLParameter(VPIntrinsic &VPI) {
594594
// TODO add caching
595595
auto *M = VPI.getModule();
596596
Function *VScaleFunc =
597-
Intrinsic::getDeclaration(M, Intrinsic::vscale, Int32Ty);
597+
Intrinsic::getOrInsertDeclaration(M, Intrinsic::vscale, Int32Ty);
598598
IRBuilder<> Builder(VPI.getParent(), VPI.getIterator());
599599
Value *FactorConst = Builder.getInt32(StaticElemCount.getKnownMinValue());
600600
Value *VScale = Builder.CreateCall(VScaleFunc, {}, "vscale");

llvm/lib/CodeGen/HardwareLoops.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ Value* HardwareLoop::InsertIterationSetup(Value *LoopCountInit) {
512512
: Intrinsic::test_set_loop_iterations)
513513
: (UsePhi ? Intrinsic::start_loop_iterations
514514
: Intrinsic::set_loop_iterations);
515-
Function *LoopIter = Intrinsic::getDeclaration(M, ID, Ty);
515+
Function *LoopIter = Intrinsic::getOrInsertDeclaration(M, ID, Ty);
516516
Value *LoopSetup = Builder.CreateCall(LoopIter, LoopCountInit);
517517

518518
// Use the return value of the intrinsic to control the entry of the loop.
@@ -541,9 +541,8 @@ void HardwareLoop::InsertLoopDec() {
541541
Attribute::StrictFP))
542542
CondBuilder.setIsFPConstrained(true);
543543

544-
Function *DecFunc =
545-
Intrinsic::getDeclaration(M, Intrinsic::loop_decrement,
546-
LoopDecrement->getType());
544+
Function *DecFunc = Intrinsic::getOrInsertDeclaration(
545+
M, Intrinsic::loop_decrement, LoopDecrement->getType());
547546
Value *Ops[] = { LoopDecrement };
548547
Value *NewCond = CondBuilder.CreateCall(DecFunc, Ops);
549548
Value *OldCond = ExitBranch->getCondition();
@@ -566,9 +565,8 @@ Instruction* HardwareLoop::InsertLoopRegDec(Value *EltsRem) {
566565
Attribute::StrictFP))
567566
CondBuilder.setIsFPConstrained(true);
568567

569-
Function *DecFunc =
570-
Intrinsic::getDeclaration(M, Intrinsic::loop_decrement_reg,
571-
{ EltsRem->getType() });
568+
Function *DecFunc = Intrinsic::getOrInsertDeclaration(
569+
M, Intrinsic::loop_decrement_reg, {EltsRem->getType()});
572570
Value *Ops[] = { EltsRem, LoopDecrement };
573571
Value *Call = CondBuilder.CreateCall(DecFunc, Ops);
574572

llvm/lib/CodeGen/IntrinsicLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ bool IntrinsicLowering::LowerToByteSwap(CallInst *CI) {
474474

475475
// Okay, we can do this xform, do so now.
476476
Module *M = CI->getModule();
477-
Function *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Ty);
477+
Function *Int = Intrinsic::getOrInsertDeclaration(M, Intrinsic::bswap, Ty);
478478

479479
Value *Op = CI->getArgOperand(0);
480480
Op = CallInst::Create(Int, Op, CI->getName(), CI->getIterator());

llvm/lib/CodeGen/SafeStack.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ Value *SafeStack::getStackGuard(IRBuilder<> &IRB, Function &F) {
368368

369369
if (!StackGuardVar) {
370370
TL.insertSSPDeclarations(*M);
371-
return IRB.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackguard));
371+
return IRB.CreateCall(
372+
Intrinsic::getOrInsertDeclaration(M, Intrinsic::stackguard));
372373
}
373374

374375
return IRB.CreateLoad(StackPtrTy, StackGuardVar, "StackGuard");

llvm/lib/CodeGen/SjLjEHPrepare.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -508,17 +508,19 @@ bool SjLjEHPrepareImpl::runOnFunction(Function &F) {
508508

509509
PointerType *AllocaPtrTy = M.getDataLayout().getAllocaPtrType(M.getContext());
510510

511-
FrameAddrFn =
512-
Intrinsic::getDeclaration(&M, Intrinsic::frameaddress, {AllocaPtrTy});
513-
StackAddrFn =
514-
Intrinsic::getDeclaration(&M, Intrinsic::stacksave, {AllocaPtrTy});
515-
StackRestoreFn =
516-
Intrinsic::getDeclaration(&M, Intrinsic::stackrestore, {AllocaPtrTy});
511+
FrameAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::frameaddress,
512+
{AllocaPtrTy});
513+
StackAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::stacksave,
514+
{AllocaPtrTy});
515+
StackRestoreFn = Intrinsic::getOrInsertDeclaration(
516+
&M, Intrinsic::stackrestore, {AllocaPtrTy});
517517
BuiltinSetupDispatchFn =
518-
Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch);
519-
LSDAAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_lsda);
520-
CallSiteFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_callsite);
521-
FuncCtxFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_functioncontext);
518+
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch);
519+
LSDAAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_lsda);
520+
CallSiteFn =
521+
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_callsite);
522+
FuncCtxFn =
523+
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_functioncontext);
522524

523525
bool Res = setupEntryBlockAndCallSites(F);
524526
return Res;

0 commit comments

Comments
 (0)