Skip to content

Commit b4e9093

Browse files
committed
[NFC] Rename Intrinsic::getDeclaration to getOrInsertDeclaration
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 18952bd commit b4e9093

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});
@@ -18873,7 +18873,8 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1887318873
}
1887418874
case Builtin::BI__builtin_hlsl_wave_is_first_lane: {
1887518875
Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveIsFirstLaneIntrinsic();
18876-
return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID));
18876+
return EmitRuntimeCall(
18877+
Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID));
1887718878
}
1887818879
case Builtin::BI__builtin_hlsl_elementwise_sign: {
1887918880
Value *Op0 = EmitScalarExpr(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

0 commit comments

Comments
 (0)