[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).
This commit is contained in:
Rahul Joshi 2024-10-11 05:26:03 -07:00 committed by GitHub
parent 900ea21ffb
commit fa789dffb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
137 changed files with 721 additions and 642 deletions

View File

@ -13648,7 +13648,7 @@ Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID,
Value *InfoKind = ConstantInt::get(Int64Ty, C->getSExtValue()); Value *InfoKind = ConstantInt::get(Int64Ty, C->getSExtValue());
// Built the IR for the preserve_field_info intrinsic. // Built the IR for the preserve_field_info intrinsic.
llvm::Function *FnGetFieldInfo = llvm::Intrinsic::getDeclaration( llvm::Function *FnGetFieldInfo = llvm::Intrinsic::getOrInsertDeclaration(
&CGM.getModule(), llvm::Intrinsic::bpf_preserve_field_info, &CGM.getModule(), llvm::Intrinsic::bpf_preserve_field_info,
{FieldAddr->getType()}); {FieldAddr->getType()});
return Builder.CreateCall(FnGetFieldInfo, {FieldAddr, InfoKind}); return Builder.CreateCall(FnGetFieldInfo, {FieldAddr, InfoKind});
@ -13670,10 +13670,10 @@ Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID,
llvm::Function *FnDecl; llvm::Function *FnDecl;
if (BuiltinID == BPF::BI__builtin_btf_type_id) if (BuiltinID == BPF::BI__builtin_btf_type_id)
FnDecl = llvm::Intrinsic::getDeclaration( FnDecl = llvm::Intrinsic::getOrInsertDeclaration(
&CGM.getModule(), llvm::Intrinsic::bpf_btf_type_id, {}); &CGM.getModule(), llvm::Intrinsic::bpf_btf_type_id, {});
else else
FnDecl = llvm::Intrinsic::getDeclaration( FnDecl = llvm::Intrinsic::getOrInsertDeclaration(
&CGM.getModule(), llvm::Intrinsic::bpf_preserve_type_info, {}); &CGM.getModule(), llvm::Intrinsic::bpf_preserve_type_info, {});
CallInst *Fn = Builder.CreateCall(FnDecl, {SeqNumVal, FlagValue}); CallInst *Fn = Builder.CreateCall(FnDecl, {SeqNumVal, FlagValue});
Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo); Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
@ -13708,7 +13708,7 @@ Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID,
Value *FlagValue = ConstantInt::get(Int64Ty, Flag->getSExtValue()); Value *FlagValue = ConstantInt::get(Int64Ty, Flag->getSExtValue());
Value *SeqNumVal = ConstantInt::get(Int32Ty, BuiltinSeqNum++); Value *SeqNumVal = ConstantInt::get(Int32Ty, BuiltinSeqNum++);
llvm::Function *IntrinsicFn = llvm::Intrinsic::getDeclaration( llvm::Function *IntrinsicFn = llvm::Intrinsic::getOrInsertDeclaration(
&CGM.getModule(), llvm::Intrinsic::bpf_preserve_enum_value, {}); &CGM.getModule(), llvm::Intrinsic::bpf_preserve_enum_value, {});
CallInst *Fn = CallInst *Fn =
Builder.CreateCall(IntrinsicFn, {SeqNumVal, EnumStrVal, FlagValue}); Builder.CreateCall(IntrinsicFn, {SeqNumVal, EnumStrVal, FlagValue});
@ -18895,7 +18895,8 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
} }
case Builtin::BI__builtin_hlsl_wave_is_first_lane: { case Builtin::BI__builtin_hlsl_wave_is_first_lane: {
Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveIsFirstLaneIntrinsic(); Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveIsFirstLaneIntrinsic();
return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID)); return EmitRuntimeCall(
Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID));
} }
case Builtin::BI__builtin_hlsl_elementwise_sign: { case Builtin::BI__builtin_hlsl_elementwise_sign: {
auto *Arg0 = E->getArg(0); auto *Arg0 = E->getArg(0);

View File

@ -2509,8 +2509,8 @@ void CodeGenFunction::pushRegularPartialArrayCleanup(llvm::Value *arrayBegin,
llvm::Function *CodeGenModule::getLLVMLifetimeStartFn() { llvm::Function *CodeGenModule::getLLVMLifetimeStartFn() {
if (LifetimeStartFn) if (LifetimeStartFn)
return LifetimeStartFn; return LifetimeStartFn;
LifetimeStartFn = llvm::Intrinsic::getDeclaration(&getModule(), LifetimeStartFn = llvm::Intrinsic::getOrInsertDeclaration(
llvm::Intrinsic::lifetime_start, AllocaInt8PtrTy); &getModule(), llvm::Intrinsic::lifetime_start, AllocaInt8PtrTy);
return LifetimeStartFn; return LifetimeStartFn;
} }
@ -2518,8 +2518,8 @@ llvm::Function *CodeGenModule::getLLVMLifetimeStartFn() {
llvm::Function *CodeGenModule::getLLVMLifetimeEndFn() { llvm::Function *CodeGenModule::getLLVMLifetimeEndFn() {
if (LifetimeEndFn) if (LifetimeEndFn)
return LifetimeEndFn; return LifetimeEndFn;
LifetimeEndFn = llvm::Intrinsic::getDeclaration(&getModule(), LifetimeEndFn = llvm::Intrinsic::getOrInsertDeclaration(
llvm::Intrinsic::lifetime_end, AllocaInt8PtrTy); &getModule(), llvm::Intrinsic::lifetime_end, AllocaInt8PtrTy);
return LifetimeEndFn; return LifetimeEndFn;
} }

View File

@ -1843,7 +1843,7 @@ Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF,
std::make_pair(ParentAlloca, ParentCGF.EscapedLocals.size())); std::make_pair(ParentAlloca, ParentCGF.EscapedLocals.size()));
int FrameEscapeIdx = InsertPair.first->second; int FrameEscapeIdx = InsertPair.first->second;
// call ptr @llvm.localrecover(ptr @parentFn, ptr %fp, i32 N) // call ptr @llvm.localrecover(ptr @parentFn, ptr %fp, i32 N)
llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration( llvm::Function *FrameRecoverFn = llvm::Intrinsic::getOrInsertDeclaration(
&CGM.getModule(), llvm::Intrinsic::localrecover); &CGM.getModule(), llvm::Intrinsic::localrecover);
RecoverCall = Builder.CreateCall( RecoverCall = Builder.CreateCall(
FrameRecoverFn, {ParentCGF.CurFn, ParentFP, FrameRecoverFn, {ParentCGF.CurFn, ParentFP,
@ -1942,7 +1942,7 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction &ParentCGF,
// %1 = call ptr @llvm.localrecover(@"?fin$0@0@main@@",..) // %1 = call ptr @llvm.localrecover(@"?fin$0@0@main@@",..)
// %2 = load ptr, ptr %1, align 8 // %2 = load ptr, ptr %1, align 8
// ==> %2 is the frame-pointer of outermost host function // ==> %2 is the frame-pointer of outermost host function
llvm::Function *FrameRecoverFn = llvm::Intrinsic::getDeclaration( llvm::Function *FrameRecoverFn = llvm::Intrinsic::getOrInsertDeclaration(
&CGM.getModule(), llvm::Intrinsic::localrecover); &CGM.getModule(), llvm::Intrinsic::localrecover);
ParentFP = Builder.CreateCall( ParentFP = Builder.CreateCall(
FrameRecoverFn, {ParentCGF.CurFn, ParentFP, FrameRecoverFn, {ParentCGF.CurFn, ParentFP,

View File

@ -463,7 +463,7 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
EscapeArgs.resize(EscapedLocals.size()); EscapeArgs.resize(EscapedLocals.size());
for (auto &Pair : EscapedLocals) for (auto &Pair : EscapedLocals)
EscapeArgs[Pair.second] = Pair.first; EscapeArgs[Pair.second] = Pair.first;
llvm::Function *FrameEscapeFn = llvm::Intrinsic::getDeclaration( llvm::Function *FrameEscapeFn = llvm::Intrinsic::getOrInsertDeclaration(
&CGM.getModule(), llvm::Intrinsic::localescape); &CGM.getModule(), llvm::Intrinsic::localescape);
CGBuilderTy(*this, AllocaInsertPt).CreateCall(FrameEscapeFn, EscapeArgs); CGBuilderTy(*this, AllocaInsertPt).CreateCall(FrameEscapeFn, EscapeArgs);
} }
@ -3130,7 +3130,7 @@ void CodeGenFunction::emitAlignmentAssumptionCheck(
llvm::Instruction *Assumption) { llvm::Instruction *Assumption) {
assert(isa_and_nonnull<llvm::CallInst>(Assumption) && assert(isa_and_nonnull<llvm::CallInst>(Assumption) &&
cast<llvm::CallInst>(Assumption)->getCalledOperand() == cast<llvm::CallInst>(Assumption)->getCalledOperand() ==
llvm::Intrinsic::getDeclaration( llvm::Intrinsic::getOrInsertDeclaration(
Builder.GetInsertBlock()->getParent()->getParent(), Builder.GetInsertBlock()->getParent()->getParent(),
llvm::Intrinsic::assume) && llvm::Intrinsic::assume) &&
"Assumption should be a call to llvm.assume()."); "Assumption should be a call to llvm.assume().");

View File

@ -6218,8 +6218,8 @@ void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
llvm::Function *CodeGenModule::getIntrinsic(unsigned IID, llvm::Function *CodeGenModule::getIntrinsic(unsigned IID,
ArrayRef<llvm::Type*> Tys) { ArrayRef<llvm::Type*> Tys) {
return llvm::Intrinsic::getDeclaration(&getModule(), (llvm::Intrinsic::ID)IID, return llvm::Intrinsic::getOrInsertDeclaration(&getModule(),
Tys); (llvm::Intrinsic::ID)IID, Tys);
} }
static llvm::StringMapEntry<llvm::GlobalVariable *> & static llvm::StringMapEntry<llvm::GlobalVariable *> &

View File

@ -110,8 +110,8 @@ public:
if (Ty->isFloatTy() || Ty->isDoubleTy() || Ty->isFP128Ty()) { if (Ty->isFloatTy() || Ty->isDoubleTy() || Ty->isFP128Ty()) {
llvm::Module &M = CGM.getModule(); llvm::Module &M = CGM.getModule();
auto &Ctx = M.getContext(); auto &Ctx = M.getContext();
llvm::Function *TDCFunc = llvm::Function *TDCFunc = llvm::Intrinsic::getOrInsertDeclaration(
llvm::Intrinsic::getDeclaration(&M, llvm::Intrinsic::s390_tdc, Ty); &M, llvm::Intrinsic::s390_tdc, Ty);
unsigned TDCBits = 0; unsigned TDCBits = 0;
switch (BuiltinID) { switch (BuiltinID) {
case Builtin::BI__builtin_isnan: case Builtin::BI__builtin_isnan:

View File

@ -67,8 +67,8 @@ void BrainF::header(LLVMContext& C) {
//declare void @llvm.memset.p0i8.i32(i8 *, i8, i32, i1) //declare void @llvm.memset.p0i8.i32(i8 *, i8, i32, i1)
Type *Tys[] = {PointerType::getUnqual(C), Type::getInt32Ty(C)}; Type *Tys[] = {PointerType::getUnqual(C), Type::getInt32Ty(C)};
Function *memset_func = Intrinsic::getDeclaration(module, Intrinsic::memset, Function *memset_func =
Tys); Intrinsic::getOrInsertDeclaration(module, Intrinsic::memset, Tys);
//declare i32 @getchar() //declare i32 @getchar()
getchar_func = getchar_func =

View File

@ -2807,10 +2807,10 @@ unsigned LLVMLookupIntrinsicID(const char *Name, size_t NameLen);
unsigned LLVMGetIntrinsicID(LLVMValueRef Fn); unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
/** /**
* Create or insert the declaration of an intrinsic. For overloaded intrinsics, * Get or insert the declaration of an intrinsic. For overloaded intrinsics,
* parameter types must be provided to uniquely identify an overload. * parameter types must be provided to uniquely identify an overload.
* *
* @see llvm::Intrinsic::getDeclaration() * @see llvm::Intrinsic::getOrInsertDeclaration()
*/ */
LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod, LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod,
unsigned ID, unsigned ID,

View File

@ -568,9 +568,9 @@ public:
/// \brief Declares a llvm.vp.* intrinsic in \p M that matches the parameters /// \brief Declares a llvm.vp.* intrinsic in \p M that matches the parameters
/// \p Params. Additionally, the load and gather intrinsics require /// \p Params. Additionally, the load and gather intrinsics require
/// \p ReturnType to be specified. /// \p ReturnType to be specified.
static Function *getDeclarationForParams(Module *M, Intrinsic::ID, static Function *getOrInsertDeclarationForParams(Module *M, Intrinsic::ID,
Type *ReturnType, Type *ReturnType,
ArrayRef<Value *> Params); ArrayRef<Value *> Params);
static std::optional<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID); static std::optional<unsigned> getMaskParamPos(Intrinsic::ID IntrinsicID);
static std::optional<unsigned> getVectorLengthParamPos( static std::optional<unsigned> getVectorLengthParamPos(

View File

@ -87,14 +87,15 @@ namespace Intrinsic {
/// Return the attributes for an intrinsic. /// Return the attributes for an intrinsic.
AttributeList getAttributes(LLVMContext &C, ID id); AttributeList getAttributes(LLVMContext &C, ID id);
/// Create or insert an LLVM Function declaration for an intrinsic, and return /// Look up the Function declaration of the intrinsic \p id in the Module
/// it. /// \p M. If it does not exist, add a declaration and return it. Otherwise,
/// return the existing declaration.
/// ///
/// The Tys parameter is for intrinsics with overloaded types (e.g., those /// The \p Tys parameter is for intrinsics with overloaded types (e.g., those
/// using iAny, fAny, vAny, or iPTRAny). For a declaration of an overloaded /// using iAny, fAny, vAny, or iPTRAny). For a declaration of an overloaded
/// intrinsic, Tys must provide exactly one type for each overloaded type in /// intrinsic, Tys must provide exactly one type for each overloaded type in
/// the intrinsic. /// the intrinsic.
Function *getDeclaration(Module *M, ID id, ArrayRef<Type *> Tys = {}); Function *getOrInsertDeclaration(Module *M, ID id, ArrayRef<Type *> Tys = {});
/// Looks up Name in NameTable via binary search. NameTable must be sorted /// Looks up Name in NameTable via binary search. NameTable must be sorted
/// and all entries must start with "llvm.". If NameTable contains an exact /// and all entries must start with "llvm.". If NameTable contains an exact

View File

@ -72,7 +72,7 @@ public:
B.getInt32(Columns)}; B.getInt32(Columns)};
Type *OverloadedTypes[] = {RetType, Stride->getType()}; Type *OverloadedTypes[] = {RetType, Stride->getType()};
Function *TheFn = Intrinsic::getDeclaration( Function *TheFn = Intrinsic::getOrInsertDeclaration(
getModule(), Intrinsic::matrix_column_major_load, OverloadedTypes); getModule(), Intrinsic::matrix_column_major_load, OverloadedTypes);
CallInst *Call = B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name); CallInst *Call = B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name);
@ -95,7 +95,7 @@ public:
B.getInt32(Rows), B.getInt32(Columns)}; B.getInt32(Rows), B.getInt32(Columns)};
Type *OverloadedTypes[] = {Matrix->getType(), Stride->getType()}; Type *OverloadedTypes[] = {Matrix->getType(), Stride->getType()};
Function *TheFn = Intrinsic::getDeclaration( Function *TheFn = Intrinsic::getOrInsertDeclaration(
getModule(), Intrinsic::matrix_column_major_store, OverloadedTypes); getModule(), Intrinsic::matrix_column_major_store, OverloadedTypes);
CallInst *Call = B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name); CallInst *Call = B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name);
@ -115,7 +115,7 @@ public:
Type *OverloadedTypes[] = {ReturnType}; Type *OverloadedTypes[] = {ReturnType};
Value *Ops[] = {Matrix, B.getInt32(Rows), B.getInt32(Columns)}; Value *Ops[] = {Matrix, B.getInt32(Rows), B.getInt32(Columns)};
Function *TheFn = Intrinsic::getDeclaration( Function *TheFn = Intrinsic::getOrInsertDeclaration(
getModule(), Intrinsic::matrix_transpose, OverloadedTypes); getModule(), Intrinsic::matrix_transpose, OverloadedTypes);
return B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name); return B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name);
@ -136,7 +136,7 @@ public:
B.getInt32(RHSColumns)}; B.getInt32(RHSColumns)};
Type *OverloadedTypes[] = {ReturnType, LHSType, RHSType}; Type *OverloadedTypes[] = {ReturnType, LHSType, RHSType};
Function *TheFn = Intrinsic::getDeclaration( Function *TheFn = Intrinsic::getOrInsertDeclaration(
getModule(), Intrinsic::matrix_multiply, OverloadedTypes); getModule(), Intrinsic::matrix_multiply, OverloadedTypes);
return B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name); return B.CreateCall(TheFn->getFunctionType(), TheFn, Ops, Name);
} }

View File

@ -360,7 +360,7 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
OverloadTys)) OverloadTys))
return error(Info.second, "invalid intrinsic signature"); return error(Info.second, "invalid intrinsic signature");
U.set(Intrinsic::getDeclaration(M, IID, OverloadTys)); U.set(Intrinsic::getOrInsertDeclaration(M, IID, OverloadTys));
} }
Info.first->eraseFromParent(); Info.first->eraseFromParent();

View File

@ -356,7 +356,7 @@ static void expandIToFP(Instruction *IToFP) {
Entry->getTerminator()->eraseFromParent(); Entry->getTerminator()->eraseFromParent();
Function *CTLZ = Function *CTLZ =
Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz, IntTy); Intrinsic::getOrInsertDeclaration(F->getParent(), Intrinsic::ctlz, IntTy);
ConstantInt *True = Builder.getTrue(); ConstantInt *True = Builder.getTrue();
// entry: // entry:

View File

@ -355,7 +355,7 @@ MemCmpExpansion::LoadPair MemCmpExpansion::getLoadPair(Type *LoadSizeType,
// Swap bytes if required. // Swap bytes if required.
if (BSwapSizeType) { if (BSwapSizeType) {
Function *Bswap = Intrinsic::getDeclaration( Function *Bswap = Intrinsic::getOrInsertDeclaration(
CI->getModule(), Intrinsic::bswap, BSwapSizeType); CI->getModule(), Intrinsic::bswap, BSwapSizeType);
Lhs = Builder.CreateCall(Bswap, Lhs); Lhs = Builder.CreateCall(Bswap, Lhs);
Rhs = Builder.CreateCall(Bswap, Rhs); Rhs = Builder.CreateCall(Bswap, Rhs);

View File

@ -237,7 +237,7 @@ Value *CachingVPExpander::convertEVLToMask(IRBuilder<> &Builder,
if (ElemCount.isScalable()) { if (ElemCount.isScalable()) {
auto *M = Builder.GetInsertBlock()->getModule(); auto *M = Builder.GetInsertBlock()->getModule();
Type *BoolVecTy = VectorType::get(Builder.getInt1Ty(), ElemCount); Type *BoolVecTy = VectorType::get(Builder.getInt1Ty(), ElemCount);
Function *ActiveMaskFunc = Intrinsic::getDeclaration( Function *ActiveMaskFunc = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::get_active_lane_mask, {BoolVecTy, EVLParam->getType()}); M, Intrinsic::get_active_lane_mask, {BoolVecTy, EVLParam->getType()});
// `get_active_lane_mask` performs an implicit less-than comparison. // `get_active_lane_mask` performs an implicit less-than comparison.
Value *ConstZero = Builder.getInt32(0); Value *ConstZero = Builder.getInt32(0);
@ -299,7 +299,7 @@ Value *CachingVPExpander::expandPredicationToIntCall(
case Intrinsic::umin: { case Intrinsic::umin: {
Value *Op0 = VPI.getOperand(0); Value *Op0 = VPI.getOperand(0);
Value *Op1 = VPI.getOperand(1); Value *Op1 = VPI.getOperand(1);
Function *Fn = Intrinsic::getDeclaration( Function *Fn = Intrinsic::getOrInsertDeclaration(
VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()}); VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()});
Value *NewOp = Builder.CreateCall(Fn, {Op0, Op1}, VPI.getName()); Value *NewOp = Builder.CreateCall(Fn, {Op0, Op1}, VPI.getName());
replaceOperation(*NewOp, VPI); replaceOperation(*NewOp, VPI);
@ -308,7 +308,7 @@ Value *CachingVPExpander::expandPredicationToIntCall(
case Intrinsic::bswap: case Intrinsic::bswap:
case Intrinsic::bitreverse: { case Intrinsic::bitreverse: {
Value *Op = VPI.getOperand(0); Value *Op = VPI.getOperand(0);
Function *Fn = Intrinsic::getDeclaration( Function *Fn = Intrinsic::getOrInsertDeclaration(
VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()}); VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()});
Value *NewOp = Builder.CreateCall(Fn, {Op}, VPI.getName()); Value *NewOp = Builder.CreateCall(Fn, {Op}, VPI.getName());
replaceOperation(*NewOp, VPI); replaceOperation(*NewOp, VPI);
@ -327,7 +327,7 @@ Value *CachingVPExpander::expandPredicationToFPCall(
case Intrinsic::fabs: case Intrinsic::fabs:
case Intrinsic::sqrt: { case Intrinsic::sqrt: {
Value *Op0 = VPI.getOperand(0); Value *Op0 = VPI.getOperand(0);
Function *Fn = Intrinsic::getDeclaration( Function *Fn = Intrinsic::getOrInsertDeclaration(
VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()}); VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()});
Value *NewOp = Builder.CreateCall(Fn, {Op0}, VPI.getName()); Value *NewOp = Builder.CreateCall(Fn, {Op0}, VPI.getName());
replaceOperation(*NewOp, VPI); replaceOperation(*NewOp, VPI);
@ -337,7 +337,7 @@ Value *CachingVPExpander::expandPredicationToFPCall(
case Intrinsic::minnum: { case Intrinsic::minnum: {
Value *Op0 = VPI.getOperand(0); Value *Op0 = VPI.getOperand(0);
Value *Op1 = VPI.getOperand(1); Value *Op1 = VPI.getOperand(1);
Function *Fn = Intrinsic::getDeclaration( Function *Fn = Intrinsic::getOrInsertDeclaration(
VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()}); VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()});
Value *NewOp = Builder.CreateCall(Fn, {Op0, Op1}, VPI.getName()); Value *NewOp = Builder.CreateCall(Fn, {Op0, Op1}, VPI.getName());
replaceOperation(*NewOp, VPI); replaceOperation(*NewOp, VPI);
@ -350,7 +350,7 @@ Value *CachingVPExpander::expandPredicationToFPCall(
Value *Op0 = VPI.getOperand(0); Value *Op0 = VPI.getOperand(0);
Value *Op1 = VPI.getOperand(1); Value *Op1 = VPI.getOperand(1);
Value *Op2 = VPI.getOperand(2); Value *Op2 = VPI.getOperand(2);
Function *Fn = Intrinsic::getDeclaration( Function *Fn = Intrinsic::getOrInsertDeclaration(
VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()}); VPI.getModule(), UnpredicatedIntrinsicID, {VPI.getType()});
Value *NewOp; Value *NewOp;
if (Intrinsic::isConstrainedFPIntrinsic(UnpredicatedIntrinsicID)) if (Intrinsic::isConstrainedFPIntrinsic(UnpredicatedIntrinsicID))
@ -594,7 +594,7 @@ bool CachingVPExpander::discardEVLParameter(VPIntrinsic &VPI) {
// TODO add caching // TODO add caching
auto *M = VPI.getModule(); auto *M = VPI.getModule();
Function *VScaleFunc = Function *VScaleFunc =
Intrinsic::getDeclaration(M, Intrinsic::vscale, Int32Ty); Intrinsic::getOrInsertDeclaration(M, Intrinsic::vscale, Int32Ty);
IRBuilder<> Builder(VPI.getParent(), VPI.getIterator()); IRBuilder<> Builder(VPI.getParent(), VPI.getIterator());
Value *FactorConst = Builder.getInt32(StaticElemCount.getKnownMinValue()); Value *FactorConst = Builder.getInt32(StaticElemCount.getKnownMinValue());
Value *VScale = Builder.CreateCall(VScaleFunc, {}, "vscale"); Value *VScale = Builder.CreateCall(VScaleFunc, {}, "vscale");

View File

@ -512,7 +512,7 @@ Value* HardwareLoop::InsertIterationSetup(Value *LoopCountInit) {
: Intrinsic::test_set_loop_iterations) : Intrinsic::test_set_loop_iterations)
: (UsePhi ? Intrinsic::start_loop_iterations : (UsePhi ? Intrinsic::start_loop_iterations
: Intrinsic::set_loop_iterations); : Intrinsic::set_loop_iterations);
Function *LoopIter = Intrinsic::getDeclaration(M, ID, Ty); Function *LoopIter = Intrinsic::getOrInsertDeclaration(M, ID, Ty);
Value *LoopSetup = Builder.CreateCall(LoopIter, LoopCountInit); Value *LoopSetup = Builder.CreateCall(LoopIter, LoopCountInit);
// Use the return value of the intrinsic to control the entry of the loop. // Use the return value of the intrinsic to control the entry of the loop.
@ -541,9 +541,8 @@ void HardwareLoop::InsertLoopDec() {
Attribute::StrictFP)) Attribute::StrictFP))
CondBuilder.setIsFPConstrained(true); CondBuilder.setIsFPConstrained(true);
Function *DecFunc = Function *DecFunc = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::loop_decrement, M, Intrinsic::loop_decrement, LoopDecrement->getType());
LoopDecrement->getType());
Value *Ops[] = { LoopDecrement }; Value *Ops[] = { LoopDecrement };
Value *NewCond = CondBuilder.CreateCall(DecFunc, Ops); Value *NewCond = CondBuilder.CreateCall(DecFunc, Ops);
Value *OldCond = ExitBranch->getCondition(); Value *OldCond = ExitBranch->getCondition();
@ -566,9 +565,8 @@ Instruction* HardwareLoop::InsertLoopRegDec(Value *EltsRem) {
Attribute::StrictFP)) Attribute::StrictFP))
CondBuilder.setIsFPConstrained(true); CondBuilder.setIsFPConstrained(true);
Function *DecFunc = Function *DecFunc = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::loop_decrement_reg, M, Intrinsic::loop_decrement_reg, {EltsRem->getType()});
{ EltsRem->getType() });
Value *Ops[] = { EltsRem, LoopDecrement }; Value *Ops[] = { EltsRem, LoopDecrement };
Value *Call = CondBuilder.CreateCall(DecFunc, Ops); Value *Call = CondBuilder.CreateCall(DecFunc, Ops);

View File

@ -474,7 +474,7 @@ bool IntrinsicLowering::LowerToByteSwap(CallInst *CI) {
// Okay, we can do this xform, do so now. // Okay, we can do this xform, do so now.
Module *M = CI->getModule(); Module *M = CI->getModule();
Function *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Ty); Function *Int = Intrinsic::getOrInsertDeclaration(M, Intrinsic::bswap, Ty);
Value *Op = CI->getArgOperand(0); Value *Op = CI->getArgOperand(0);
Op = CallInst::Create(Int, Op, CI->getName(), CI->getIterator()); Op = CallInst::Create(Int, Op, CI->getName(), CI->getIterator());

View File

@ -368,7 +368,8 @@ Value *SafeStack::getStackGuard(IRBuilder<> &IRB, Function &F) {
if (!StackGuardVar) { if (!StackGuardVar) {
TL.insertSSPDeclarations(*M); TL.insertSSPDeclarations(*M);
return IRB.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackguard)); return IRB.CreateCall(
Intrinsic::getOrInsertDeclaration(M, Intrinsic::stackguard));
} }
return IRB.CreateLoad(StackPtrTy, StackGuardVar, "StackGuard"); return IRB.CreateLoad(StackPtrTy, StackGuardVar, "StackGuard");

View File

@ -508,17 +508,19 @@ bool SjLjEHPrepareImpl::runOnFunction(Function &F) {
PointerType *AllocaPtrTy = M.getDataLayout().getAllocaPtrType(M.getContext()); PointerType *AllocaPtrTy = M.getDataLayout().getAllocaPtrType(M.getContext());
FrameAddrFn = FrameAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::frameaddress,
Intrinsic::getDeclaration(&M, Intrinsic::frameaddress, {AllocaPtrTy}); {AllocaPtrTy});
StackAddrFn = StackAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::stacksave,
Intrinsic::getDeclaration(&M, Intrinsic::stacksave, {AllocaPtrTy}); {AllocaPtrTy});
StackRestoreFn = StackRestoreFn = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(&M, Intrinsic::stackrestore, {AllocaPtrTy}); &M, Intrinsic::stackrestore, {AllocaPtrTy});
BuiltinSetupDispatchFn = BuiltinSetupDispatchFn =
Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch); Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_setup_dispatch);
LSDAAddrFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_lsda); LSDAAddrFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_lsda);
CallSiteFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_callsite); CallSiteFn =
FuncCtxFn = Intrinsic::getDeclaration(&M, Intrinsic::eh_sjlj_functioncontext); Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_callsite);
FuncCtxFn =
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::eh_sjlj_functioncontext);
bool Res = setupEntryBlockAndCallSites(F); bool Res = setupEntryBlockAndCallSites(F);
return Res; return Res;

View File

@ -519,7 +519,8 @@ static Value *getStackGuard(const TargetLoweringBase *TLI, Module *M,
if (SupportsSelectionDAGSP) if (SupportsSelectionDAGSP)
*SupportsSelectionDAGSP = true; *SupportsSelectionDAGSP = true;
TLI->insertSSPDeclarations(*M); TLI->insertSSPDeclarations(*M);
return B.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackguard)); return B.CreateCall(
Intrinsic::getOrInsertDeclaration(M, Intrinsic::stackguard));
} }
/// Insert code into the entry block that stores the stack guard /// Insert code into the entry block that stores the stack guard
@ -540,7 +541,7 @@ static bool CreatePrologue(Function *F, Module *M, Instruction *CheckLoc,
AI = B.CreateAlloca(PtrTy, nullptr, "StackGuardSlot"); AI = B.CreateAlloca(PtrTy, nullptr, "StackGuardSlot");
Value *GuardSlot = getStackGuard(TLI, M, B, &SupportsSelectionDAGSP); Value *GuardSlot = getStackGuard(TLI, M, B, &SupportsSelectionDAGSP);
B.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackprotector), B.CreateCall(Intrinsic::getOrInsertDeclaration(M, Intrinsic::stackprotector),
{GuardSlot, AI}); {GuardSlot, AI});
return SupportsSelectionDAGSP; return SupportsSelectionDAGSP;
} }

View File

@ -196,7 +196,7 @@ bool WasmEHPrepareImpl::prepareThrows(Function &F) {
bool Changed = false; bool Changed = false;
// wasm.throw() intinsic, which will be lowered to wasm 'throw' instruction. // wasm.throw() intinsic, which will be lowered to wasm 'throw' instruction.
ThrowF = Intrinsic::getDeclaration(&M, Intrinsic::wasm_throw); ThrowF = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::wasm_throw);
// Insert an unreachable instruction after a call to @llvm.wasm.throw and // Insert an unreachable instruction after a call to @llvm.wasm.throw and
// delete all following instructions within the BB, and delete all the dead // delete all following instructions within the BB, and delete all the dead
// children of the BB as well. // children of the BB as well.
@ -260,18 +260,21 @@ bool WasmEHPrepareImpl::prepareEHPads(Function &F) {
0, 2, "selector_gep"); 0, 2, "selector_gep");
// wasm.landingpad.index() intrinsic, which is to specify landingpad index // wasm.landingpad.index() intrinsic, which is to specify landingpad index
LPadIndexF = Intrinsic::getDeclaration(&M, Intrinsic::wasm_landingpad_index); LPadIndexF =
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::wasm_landingpad_index);
// wasm.lsda() intrinsic. Returns the address of LSDA table for the current // wasm.lsda() intrinsic. Returns the address of LSDA table for the current
// function. // function.
LSDAF = Intrinsic::getDeclaration(&M, Intrinsic::wasm_lsda); LSDAF = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::wasm_lsda);
// wasm.get.exception() and wasm.get.ehselector() intrinsics. Calls to these // wasm.get.exception() and wasm.get.ehselector() intrinsics. Calls to these
// are generated in clang. // are generated in clang.
GetExnF = Intrinsic::getDeclaration(&M, Intrinsic::wasm_get_exception); GetExnF =
GetSelectorF = Intrinsic::getDeclaration(&M, Intrinsic::wasm_get_ehselector); Intrinsic::getOrInsertDeclaration(&M, Intrinsic::wasm_get_exception);
GetSelectorF =
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::wasm_get_ehselector);
// wasm.catch() will be lowered down to wasm 'catch' instruction in // wasm.catch() will be lowered down to wasm 'catch' instruction in
// instruction selection. // instruction selection.
CatchF = Intrinsic::getDeclaration(&M, Intrinsic::wasm_catch); CatchF = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::wasm_catch);
// _Unwind_CallPersonality() wrapper function, which calls the personality // _Unwind_CallPersonality() wrapper function, which calls the personality
CallPersonalityF = M.getOrInsertFunction("_Unwind_CallPersonality", CallPersonalityF = M.getOrInsertFunction("_Unwind_CallPersonality",

View File

@ -65,7 +65,7 @@ static bool upgradePTESTIntrinsic(Function *F, Intrinsic::ID IID,
// Yes, it's old, replace it with new version. // Yes, it's old, replace it with new version.
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), IID); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), IID);
return true; return true;
} }
@ -81,7 +81,7 @@ static bool upgradeX86IntrinsicsWith8BitMask(Function *F, Intrinsic::ID IID,
// Move this function aside and map down. // Move this function aside and map down.
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), IID); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), IID);
return true; return true;
} }
@ -94,7 +94,7 @@ static bool upgradeX86MaskedFPCompare(Function *F, Intrinsic::ID IID,
return false; return false;
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), IID); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), IID);
return true; return true;
} }
@ -104,7 +104,7 @@ static bool upgradeX86BF16Intrinsic(Function *F, Intrinsic::ID IID,
return false; return false;
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), IID); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), IID);
return true; return true;
} }
@ -114,7 +114,7 @@ static bool upgradeX86BF16DPIntrinsic(Function *F, Intrinsic::ID IID,
return false; return false;
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), IID); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), IID);
return true; return true;
} }
@ -502,8 +502,8 @@ static bool upgradeX86IntrinsicFunction(Function *F, StringRef Name,
return false; return false;
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(),
Intrinsic::x86_rdtscp); Intrinsic::x86_rdtscp);
return true; return true;
} }
@ -609,14 +609,15 @@ static bool upgradeX86IntrinsicFunction(Function *F, StringRef Name,
if (ID != Intrinsic::not_intrinsic) { if (ID != Intrinsic::not_intrinsic) {
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), ID); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID);
return true; return true;
} }
return false; // No other 'x86.xop.*' return false; // No other 'x86.xop.*'
} }
if (Name == "seh.recoverfp") { if (Name == "seh.recoverfp") {
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::eh_recoverfp); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(),
Intrinsic::eh_recoverfp);
return true; return true;
} }
@ -630,15 +631,15 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
Function *&NewFn) { Function *&NewFn) {
if (Name.starts_with("rbit")) { if (Name.starts_with("rbit")) {
// '(arm|aarch64).rbit'. // '(arm|aarch64).rbit'.
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::bitreverse, NewFn = Intrinsic::getOrInsertDeclaration(
F->arg_begin()->getType()); F->getParent(), Intrinsic::bitreverse, F->arg_begin()->getType());
return true; return true;
} }
if (Name == "thread.pointer") { if (Name == "thread.pointer") {
// '(arm|aarch64).thread.pointer'. // '(arm|aarch64).thread.pointer'.
NewFn = NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(),
Intrinsic::getDeclaration(F->getParent(), Intrinsic::thread_pointer); Intrinsic::thread_pointer);
return true; return true;
} }
@ -663,7 +664,7 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
std::array<Type *, 2> Tys{ std::array<Type *, 2> Tys{
{F->getReturnType(), {F->getReturnType(),
FixedVectorType::get(Type::getBFloatTy(Ctx), OperandWidth / 16)}}; FixedVectorType::get(Type::getBFloatTy(Ctx), OperandWidth / 16)}};
NewFn = Intrinsic::getDeclaration(F->getParent(), ID, Tys); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID, Tys);
return true; return true;
} }
return false; // No other '(arm|aarch64).neon.bfdot.*'. return false; // No other '(arm|aarch64).neon.bfdot.*'.
@ -688,7 +689,7 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
: (Intrinsic::ID)Intrinsic::aarch64_neon_bfmlalt) : (Intrinsic::ID)Intrinsic::aarch64_neon_bfmlalt)
.Default(Intrinsic::not_intrinsic); .Default(Intrinsic::not_intrinsic);
if (ID != Intrinsic::not_intrinsic) { if (ID != Intrinsic::not_intrinsic) {
NewFn = Intrinsic::getDeclaration(F->getParent(), ID); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID);
return true; return true;
} }
return false; // No other '(arm|aarch64).neon.bfm*.v16i8'. return false; // No other '(arm|aarch64).neon.bfm*.v16i8'.
@ -712,8 +713,8 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
.StartsWith("vqsubu.", Intrinsic::usub_sat) .StartsWith("vqsubu.", Intrinsic::usub_sat)
.Default(Intrinsic::not_intrinsic); .Default(Intrinsic::not_intrinsic);
if (ID != Intrinsic::not_intrinsic) { if (ID != Intrinsic::not_intrinsic) {
NewFn = Intrinsic::getDeclaration(F->getParent(), ID, NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID,
F->arg_begin()->getType()); F->arg_begin()->getType());
return true; return true;
} }
@ -733,10 +734,10 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
auto fArgs = F->getFunctionType()->params(); auto fArgs = F->getFunctionType()->params();
Type *Tys[] = {fArgs[0], fArgs[1]}; Type *Tys[] = {fArgs[0], fArgs[1]};
if (Groups[1].size() == 1) if (Groups[1].size() == 1)
NewFn = Intrinsic::getDeclaration(F->getParent(), NewFn = Intrinsic::getOrInsertDeclaration(
StoreInts[fArgs.size() - 3], Tys); F->getParent(), StoreInts[fArgs.size() - 3], Tys);
else else
NewFn = Intrinsic::getDeclaration( NewFn = Intrinsic::getOrInsertDeclaration(
F->getParent(), StoreLaneInts[fArgs.size() - 5], Tys); F->getParent(), StoreLaneInts[fArgs.size() - 5], Tys);
return true; return true;
} }
@ -810,8 +811,8 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
.StartsWith("rbit", Intrinsic::bitreverse) .StartsWith("rbit", Intrinsic::bitreverse)
.Default(Intrinsic::not_intrinsic); .Default(Intrinsic::not_intrinsic);
if (ID != Intrinsic::not_intrinsic) { if (ID != Intrinsic::not_intrinsic) {
NewFn = Intrinsic::getDeclaration(F->getParent(), ID, NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID,
F->arg_begin()->getType()); F->arg_begin()->getType());
return true; return true;
} }
@ -821,8 +822,8 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
return false; // Invalid IR. return false; // Invalid IR.
VectorType *Ty = dyn_cast<VectorType>(F->getReturnType()); VectorType *Ty = dyn_cast<VectorType>(F->getReturnType());
if (Ty && Ty->getElementType()->isFloatingPointTy()) { if (Ty && Ty->getElementType()->isFloatingPointTy()) {
NewFn = Intrinsic::getDeclaration(F->getParent(), NewFn = Intrinsic::getOrInsertDeclaration(
Intrinsic::aarch64_neon_faddp, Ty); F->getParent(), Intrinsic::aarch64_neon_faddp, Ty);
return true; return true;
} }
} }
@ -840,7 +841,7 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
.Case("mlalt", Intrinsic::aarch64_sve_bfmlalt_lane_v2) .Case("mlalt", Intrinsic::aarch64_sve_bfmlalt_lane_v2)
.Default(Intrinsic::not_intrinsic); .Default(Intrinsic::not_intrinsic);
if (ID != Intrinsic::not_intrinsic) { if (ID != Intrinsic::not_intrinsic) {
NewFn = Intrinsic::getDeclaration(F->getParent(), ID); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID);
return true; return true;
} }
return false; // No other 'aarch64.sve.bf*.lane'. return false; // No other 'aarch64.sve.bf*.lane'.
@ -861,8 +862,8 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
auto Args = F->getFunctionType()->params(); auto Args = F->getFunctionType()->params();
Type *Tys[] = {F->getReturnType(), Args[1]}; Type *Tys[] = {F->getReturnType(), Args[1]};
NewFn = Intrinsic::getDeclaration(F->getParent(), NewFn = Intrinsic::getOrInsertDeclaration(
Intrinsic::aarch64_sve_faddqv, Tys); F->getParent(), Intrinsic::aarch64_sve_faddqv, Tys);
return true; return true;
} }
@ -880,8 +881,8 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
Intrinsic::aarch64_sve_ld3_sret, Intrinsic::aarch64_sve_ld3_sret,
Intrinsic::aarch64_sve_ld4_sret, Intrinsic::aarch64_sve_ld4_sret,
}; };
NewFn = Intrinsic::getDeclaration(F->getParent(), NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(),
LoadIDs[Name[0] - '2'], Ty); LoadIDs[Name[0] - '2'], Ty);
return true; return true;
} }
return false; // No other 'aarch64.sve.ld*'. return false; // No other 'aarch64.sve.ld*'.
@ -892,8 +893,8 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
if (Name.starts_with("get")) { if (Name.starts_with("get")) {
// 'aarch64.sve.tuple.get*'. // 'aarch64.sve.tuple.get*'.
Type *Tys[] = {F->getReturnType(), F->arg_begin()->getType()}; Type *Tys[] = {F->getReturnType(), F->arg_begin()->getType()};
NewFn = Intrinsic::getDeclaration(F->getParent(), NewFn = Intrinsic::getOrInsertDeclaration(
Intrinsic::vector_extract, Tys); F->getParent(), Intrinsic::vector_extract, Tys);
return true; return true;
} }
@ -901,8 +902,8 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
// 'aarch64.sve.tuple.set*'. // 'aarch64.sve.tuple.set*'.
auto Args = F->getFunctionType()->params(); auto Args = F->getFunctionType()->params();
Type *Tys[] = {Args[0], Args[2], Args[1]}; Type *Tys[] = {Args[0], Args[2], Args[1]};
NewFn = Intrinsic::getDeclaration(F->getParent(), NewFn = Intrinsic::getOrInsertDeclaration(
Intrinsic::vector_insert, Tys); F->getParent(), Intrinsic::vector_insert, Tys);
return true; return true;
} }
@ -911,8 +912,8 @@ static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F,
// 'aarch64.sve.tuple.create*'. // 'aarch64.sve.tuple.create*'.
auto Args = F->getFunctionType()->params(); auto Args = F->getFunctionType()->params();
Type *Tys[] = {F->getReturnType(), Args[1]}; Type *Tys[] = {F->getReturnType(), Args[1]};
NewFn = Intrinsic::getDeclaration(F->getParent(), NewFn = Intrinsic::getOrInsertDeclaration(
Intrinsic::vector_insert, Tys); F->getParent(), Intrinsic::vector_insert, Tys);
return true; return true;
} }
return false; // No other 'aarch64.sve.tuple.*'. return false; // No other 'aarch64.sve.tuple.*'.
@ -1026,8 +1027,8 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
if (Name.consume_front("amdgcn.")) { if (Name.consume_front("amdgcn.")) {
if (Name == "alignbit") { if (Name == "alignbit") {
// Target specific intrinsic became redundant // Target specific intrinsic became redundant
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::fshr, NewFn = Intrinsic::getOrInsertDeclaration(
{F->getReturnType()}); F->getParent(), Intrinsic::fshr, {F->getReturnType()});
return true; return true;
} }
@ -1056,9 +1057,9 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
if (Name.starts_with("ldexp.")) { if (Name.starts_with("ldexp.")) {
// Target specific intrinsic became redundant // Target specific intrinsic became redundant
NewFn = Intrinsic::getDeclaration( NewFn = Intrinsic::getOrInsertDeclaration(
F->getParent(), Intrinsic::ldexp, F->getParent(), Intrinsic::ldexp,
{F->getReturnType(), F->getArg(1)->getType()}); {F->getReturnType(), F->getArg(1)->getType()});
return true; return true;
} }
break; // No other 'amdgcn.*' break; // No other 'amdgcn.*'
@ -1074,15 +1075,16 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
.Default(Intrinsic::not_intrinsic); .Default(Intrinsic::not_intrinsic);
if (ID != Intrinsic::not_intrinsic) { if (ID != Intrinsic::not_intrinsic) {
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), ID, NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID,
F->arg_begin()->getType()); F->arg_begin()->getType());
return true; return true;
} }
} }
if (F->arg_size() == 2 && Name == "coro.end") { if (F->arg_size() == 2 && Name == "coro.end") {
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::coro_end); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(),
Intrinsic::coro_end);
return true; return true;
} }
@ -1105,7 +1107,8 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
// converted to DbgVariableRecords later. // converted to DbgVariableRecords later.
if (Name == "addr" || (Name == "value" && F->arg_size() == 4)) { if (Name == "addr" || (Name == "value" && F->arg_size() == 4)) {
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::dbg_value); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(),
Intrinsic::dbg_value);
return true; return true;
} }
break; // No other 'dbg.*'. break; // No other 'dbg.*'.
@ -1135,7 +1138,7 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
// Inserting overloads the inserted type. // Inserting overloads the inserted type.
Tys.push_back(FT->getParamType(1)); Tys.push_back(FT->getParamType(1));
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), ID, Tys); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID, Tys);
return true; return true;
} }
@ -1171,8 +1174,8 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
if (ID != Intrinsic::not_intrinsic) { if (ID != Intrinsic::not_intrinsic) {
rename(F); rename(F);
auto Args = F->getFunctionType()->params(); auto Args = F->getFunctionType()->params();
NewFn = NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID,
Intrinsic::getDeclaration(F->getParent(), ID, {Args[V2 ? 1 : 0]}); {Args[V2 ? 1 : 0]});
return true; return true;
} }
break; // No other 'expermental.vector.reduce.*'. break; // No other 'expermental.vector.reduce.*'.
@ -1182,15 +1185,16 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
if (Name.consume_front("experimental.stepvector.")) { if (Name.consume_front("experimental.stepvector.")) {
Intrinsic::ID ID = Intrinsic::stepvector; Intrinsic::ID ID = Intrinsic::stepvector;
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), ID, NewFn = Intrinsic::getOrInsertDeclaration(
F->getFunctionType()->getReturnType()); F->getParent(), ID, F->getFunctionType()->getReturnType());
return true; return true;
} }
break; // No other 'e*'. break; // No other 'e*'.
case 'f': case 'f':
if (Name.starts_with("flt.rounds")) { if (Name.starts_with("flt.rounds")) {
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::get_rounding); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(),
Intrinsic::get_rounding);
return true; return true;
} }
break; break;
@ -1200,8 +1204,8 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
auto Args = F->getFunctionType()->params(); auto Args = F->getFunctionType()->params();
Type* ObjectPtr[1] = {Args[0]}; Type* ObjectPtr[1] = {Args[0]};
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), NewFn = Intrinsic::getOrInsertDeclaration(
Intrinsic::launder_invariant_group, ObjectPtr); F->getParent(), Intrinsic::launder_invariant_group, ObjectPtr);
return true; return true;
} }
break; break;
@ -1218,7 +1222,8 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
// Get the types of dest, src, and len // Get the types of dest, src, and len
ArrayRef<Type *> ParamTypes = ArrayRef<Type *> ParamTypes =
F->getFunctionType()->params().slice(0, 3); F->getFunctionType()->params().slice(0, 3);
NewFn = Intrinsic::getDeclaration(F->getParent(), ID, ParamTypes); NewFn =
Intrinsic::getOrInsertDeclaration(F->getParent(), ID, ParamTypes);
return true; return true;
} }
} }
@ -1230,8 +1235,8 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
FT->getParamType(0), // Dest FT->getParamType(0), // Dest
FT->getParamType(2) // len FT->getParamType(2) // len
}; };
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::memset, NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(),
ParamTypes); Intrinsic::memset, ParamTypes);
return true; return true;
} }
break; break;
@ -1247,8 +1252,8 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
.Case("popc.i", Intrinsic::ctpop) .Case("popc.i", Intrinsic::ctpop)
.Default(Intrinsic::not_intrinsic); .Default(Intrinsic::not_intrinsic);
if (IID != Intrinsic::not_intrinsic) { if (IID != Intrinsic::not_intrinsic) {
NewFn = Intrinsic::getDeclaration(F->getParent(), IID, NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), IID,
{F->getReturnType()}); {F->getReturnType()});
return true; return true;
} }
} }
@ -1316,8 +1321,8 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
F->getName() != F->getName() !=
Intrinsic::getName(Intrinsic::objectsize, Tys, F->getParent())) { Intrinsic::getName(Intrinsic::objectsize, Tys, F->getParent())) {
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::objectsize, NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(),
Tys); Intrinsic::objectsize, Tys);
return true; return true;
} }
} }
@ -1326,7 +1331,7 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
case 'p': case 'p':
if (Name.starts_with("ptr.annotation.") && F->arg_size() == 4) { if (Name.starts_with("ptr.annotation.") && F->arg_size() == 4) {
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration( NewFn = Intrinsic::getOrInsertDeclaration(
F->getParent(), Intrinsic::ptr_annotation, F->getParent(), Intrinsic::ptr_annotation,
{F->arg_begin()->getType(), F->getArg(1)->getType()}); {F->arg_begin()->getType(), F->getArg(1)->getType()});
return true; return true;
@ -1345,7 +1350,7 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
if (ID != Intrinsic::not_intrinsic) { if (ID != Intrinsic::not_intrinsic) {
if (!F->getFunctionType()->getParamType(2)->isIntegerTy(32)) { if (!F->getFunctionType()->getParamType(2)->isIntegerTy(32)) {
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), ID); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID);
return true; return true;
} }
break; // No other applicable upgrades. break; // No other applicable upgrades.
@ -1359,7 +1364,7 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
if (!F->getFunctionType()->getParamType(2)->isIntegerTy(32) || if (!F->getFunctionType()->getParamType(2)->isIntegerTy(32) ||
F->getFunctionType()->getReturnType()->isIntegerTy(64)) { F->getFunctionType()->getReturnType()->isIntegerTy(64)) {
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), ID); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID);
return true; return true;
} }
break; // No other applicable upgrades. break; // No other applicable upgrades.
@ -1376,7 +1381,7 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
if (ID != Intrinsic::not_intrinsic) { if (ID != Intrinsic::not_intrinsic) {
if (F->getFunctionType()->getReturnType()->isIntegerTy(64)) { if (F->getFunctionType()->getReturnType()->isIntegerTy(64)) {
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), ID); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID);
return true; return true;
} }
break; // No other applicable upgrades. break; // No other applicable upgrades.
@ -1395,7 +1400,7 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
case 'v': { case 'v': {
if (Name == "var.annotation" && F->arg_size() == 4) { if (Name == "var.annotation" && F->arg_size() == 4) {
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration( NewFn = Intrinsic::getOrInsertDeclaration(
F->getParent(), Intrinsic::var_annotation, F->getParent(), Intrinsic::var_annotation,
{{F->arg_begin()->getType(), F->getArg(1)->getType()}}); {{F->arg_begin()->getType(), F->getArg(1)->getType()}});
return true; return true;
@ -1413,8 +1418,8 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
.Default(Intrinsic::not_intrinsic); .Default(Intrinsic::not_intrinsic);
if (ID != Intrinsic::not_intrinsic) { if (ID != Intrinsic::not_intrinsic) {
rename(F); rename(F);
NewFn = NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID,
Intrinsic::getDeclaration(F->getParent(), ID, F->getReturnType()); F->getReturnType());
return true; return true;
} }
@ -1426,7 +1431,7 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
.Default(Intrinsic::not_intrinsic); .Default(Intrinsic::not_intrinsic);
if (ID != Intrinsic::not_intrinsic) { if (ID != Intrinsic::not_intrinsic) {
rename(F); rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), ID); NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID);
return true; return true;
} }
break; // No other 'wasm.dot.i8x16.i7x16.*'. break; // No other 'wasm.dot.i8x16.i7x16.*'.
@ -1740,8 +1745,8 @@ static Value *upgradeX86VPERMT2Intrinsics(IRBuilder<> &Builder, CallBase &CI,
if (!IndexForm) if (!IndexForm)
std::swap(Args[0], Args[1]); std::swap(Args[0], Args[1]);
Value *V = Builder.CreateCall(Intrinsic::getDeclaration(CI.getModule(), IID), Value *V = Builder.CreateCall(
Args); Intrinsic::getOrInsertDeclaration(CI.getModule(), IID), Args);
Value *PassThru = ZeroMask ? ConstantAggregateZero::get(Ty) Value *PassThru = ZeroMask ? ConstantAggregateZero::get(Ty)
: Builder.CreateBitCast(CI.getArgOperand(1), : Builder.CreateBitCast(CI.getArgOperand(1),
Ty); Ty);
@ -1753,7 +1758,7 @@ static Value *upgradeX86BinaryIntrinsics(IRBuilder<> &Builder, CallBase &CI,
Type *Ty = CI.getType(); Type *Ty = CI.getType();
Value *Op0 = CI.getOperand(0); Value *Op0 = CI.getOperand(0);
Value *Op1 = CI.getOperand(1); Value *Op1 = CI.getOperand(1);
Function *Intrin = Intrinsic::getDeclaration(CI.getModule(), IID, Ty); Function *Intrin = Intrinsic::getOrInsertDeclaration(CI.getModule(), IID, Ty);
Value *Res = Builder.CreateCall(Intrin, {Op0, Op1}); Value *Res = Builder.CreateCall(Intrin, {Op0, Op1});
if (CI.arg_size() == 4) { // For masked intrinsics. if (CI.arg_size() == 4) { // For masked intrinsics.
@ -1780,7 +1785,7 @@ static Value *upgradeX86Rotate(IRBuilder<> &Builder, CallBase &CI,
} }
Intrinsic::ID IID = IsRotateRight ? Intrinsic::fshr : Intrinsic::fshl; Intrinsic::ID IID = IsRotateRight ? Intrinsic::fshr : Intrinsic::fshl;
Function *Intrin = Intrinsic::getDeclaration(CI.getModule(), IID, Ty); Function *Intrin = Intrinsic::getOrInsertDeclaration(CI.getModule(), IID, Ty);
Value *Res = Builder.CreateCall(Intrin, {Src, Src, Amt}); Value *Res = Builder.CreateCall(Intrin, {Src, Src, Amt});
if (CI.arg_size() == 4) { // For masked intrinsics. if (CI.arg_size() == 4) { // For masked intrinsics.
@ -1850,7 +1855,7 @@ static Value *upgradeX86ConcatShift(IRBuilder<> &Builder, CallBase &CI,
} }
Intrinsic::ID IID = IsShiftRight ? Intrinsic::fshr : Intrinsic::fshl; Intrinsic::ID IID = IsShiftRight ? Intrinsic::fshr : Intrinsic::fshl;
Function *Intrin = Intrinsic::getDeclaration(CI.getModule(), IID, Ty); Function *Intrin = Intrinsic::getOrInsertDeclaration(CI.getModule(), IID, Ty);
Value *Res = Builder.CreateCall(Intrin, {Op0, Op1, Amt}); Value *Res = Builder.CreateCall(Intrin, {Op0, Op1, Amt});
unsigned NumArgs = CI.arg_size(); unsigned NumArgs = CI.arg_size();
@ -1911,7 +1916,8 @@ static Value *upgradeMaskedLoad(IRBuilder<> &Builder, Value *Ptr,
static Value *upgradeAbs(IRBuilder<> &Builder, CallBase &CI) { static Value *upgradeAbs(IRBuilder<> &Builder, CallBase &CI) {
Type *Ty = CI.getType(); Type *Ty = CI.getType();
Value *Op0 = CI.getArgOperand(0); Value *Op0 = CI.getArgOperand(0);
Function *F = Intrinsic::getDeclaration(CI.getModule(), Intrinsic::abs, Ty); Function *F =
Intrinsic::getOrInsertDeclaration(CI.getModule(), Intrinsic::abs, Ty);
Value *Res = Builder.CreateCall(F, {Op0, Builder.getInt1(false)}); Value *Res = Builder.CreateCall(F, {Op0, Builder.getInt1(false)});
if (CI.arg_size() == 3) if (CI.arg_size() == 3)
Res = emitX86Select(Builder, CI.getArgOperand(2), Res, CI.getArgOperand(1)); Res = emitX86Select(Builder, CI.getArgOperand(2), Res, CI.getArgOperand(1));
@ -2004,7 +2010,7 @@ static Value *upgradeMaskedCompare(IRBuilder<> &Builder, CallBase &CI,
// Replace a masked intrinsic with an older unmasked intrinsic. // Replace a masked intrinsic with an older unmasked intrinsic.
static Value *upgradeX86MaskedShift(IRBuilder<> &Builder, CallBase &CI, static Value *upgradeX86MaskedShift(IRBuilder<> &Builder, CallBase &CI,
Intrinsic::ID IID) { Intrinsic::ID IID) {
Function *Intrin = Intrinsic::getDeclaration(CI.getModule(), IID); Function *Intrin = Intrinsic::getOrInsertDeclaration(CI.getModule(), IID);
Value *Rep = Builder.CreateCall(Intrin, Value *Rep = Builder.CreateCall(Intrin,
{ CI.getArgOperand(0), CI.getArgOperand(1) }); { CI.getArgOperand(0), CI.getArgOperand(1) });
return emitX86Select(Builder, CI.getArgOperand(3), Rep, CI.getArgOperand(2)); return emitX86Select(Builder, CI.getArgOperand(3), Rep, CI.getArgOperand(2));
@ -2263,8 +2269,8 @@ static bool upgradeAVX512MaskToSelect(StringRef Name, IRBuilder<> &Builder,
SmallVector<Value *, 4> Args(CI.args()); SmallVector<Value *, 4> Args(CI.args());
Args.pop_back(); Args.pop_back();
Args.pop_back(); Args.pop_back();
Rep = Builder.CreateCall(Intrinsic::getDeclaration(CI.getModule(), IID), Rep = Builder.CreateCall(
Args); Intrinsic::getOrInsertDeclaration(CI.getModule(), IID), Args);
unsigned NumArgs = CI.arg_size(); unsigned NumArgs = CI.arg_size();
Rep = emitX86Select(Builder, CI.getArgOperand(NumArgs - 1), Rep, Rep = emitX86Select(Builder, CI.getArgOperand(NumArgs - 1), Rep,
CI.getArgOperand(NumArgs - 2)); CI.getArgOperand(NumArgs - 2));
@ -2320,8 +2326,8 @@ static Value *upgradeNVVMIntrinsicCall(StringRef Name, CallBase *CI,
// llvm.nvvm.clz.ll returns an i32, but llvm.ctlz.i64 returns an i64. // llvm.nvvm.clz.ll returns an i32, but llvm.ctlz.i64 returns an i64.
Value *Arg = CI->getArgOperand(0); Value *Arg = CI->getArgOperand(0);
Value *Ctlz = Builder.CreateCall( Value *Ctlz = Builder.CreateCall(
Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz, Intrinsic::getOrInsertDeclaration(F->getParent(), Intrinsic::ctlz,
{Arg->getType()}), {Arg->getType()}),
{Arg, Builder.getFalse()}, "ctlz"); {Arg, Builder.getFalse()}, "ctlz");
Rep = Builder.CreateTrunc(Ctlz, Builder.getInt32Ty(), "ctlz.trunc"); Rep = Builder.CreateTrunc(Ctlz, Builder.getInt32Ty(), "ctlz.trunc");
} else if (Name == "popc.ll") { } else if (Name == "popc.ll") {
@ -2329,15 +2335,15 @@ static Value *upgradeNVVMIntrinsicCall(StringRef Name, CallBase *CI,
// i64. // i64.
Value *Arg = CI->getArgOperand(0); Value *Arg = CI->getArgOperand(0);
Value *Popc = Builder.CreateCall( Value *Popc = Builder.CreateCall(
Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctpop, Intrinsic::getOrInsertDeclaration(F->getParent(), Intrinsic::ctpop,
{Arg->getType()}), {Arg->getType()}),
Arg, "ctpop"); Arg, "ctpop");
Rep = Builder.CreateTrunc(Popc, Builder.getInt32Ty(), "ctpop.trunc"); Rep = Builder.CreateTrunc(Popc, Builder.getInt32Ty(), "ctpop.trunc");
} else if (Name == "h2f") { } else if (Name == "h2f") {
Rep = Builder.CreateCall( Rep = Builder.CreateCall(Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(F->getParent(), Intrinsic::convert_from_fp16, F->getParent(), Intrinsic::convert_from_fp16,
{Builder.getFloatTy()}), {Builder.getFloatTy()}),
CI->getArgOperand(0), "h2f"); CI->getArgOperand(0), "h2f");
} else if (Name.consume_front("bitcast.") && } else if (Name.consume_front("bitcast.") &&
(Name == "f2i" || Name == "i2f" || Name == "ll2d" || (Name == "f2i" || Name == "i2f" || Name == "ll2d" ||
Name == "d2ll")) { Name == "d2ll")) {
@ -2373,7 +2379,7 @@ static Value *upgradeNVVMIntrinsicCall(StringRef Name, CallBase *CI,
if (IID != Intrinsic::not_intrinsic && if (IID != Intrinsic::not_intrinsic &&
!F->getReturnType()->getScalarType()->isBFloatTy()) { !F->getReturnType()->getScalarType()->isBFloatTy()) {
rename(F); rename(F);
Function *NewFn = Intrinsic::getDeclaration(F->getParent(), IID); Function *NewFn = Intrinsic::getOrInsertDeclaration(F->getParent(), IID);
SmallVector<Value *, 2> Args; SmallVector<Value *, 2> Args;
for (size_t I = 0; I < NewFn->arg_size(); ++I) { for (size_t I = 0; I < NewFn->arg_size(); ++I) {
Value *Arg = CI->getArgOperand(I); Value *Arg = CI->getArgOperand(I);
@ -2480,15 +2486,15 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
} else if (Name == "sse.sqrt.ss" || Name == "sse2.sqrt.sd") { } else if (Name == "sse.sqrt.ss" || Name == "sse2.sqrt.sd") {
Value *Vec = CI->getArgOperand(0); Value *Vec = CI->getArgOperand(0);
Value *Elt0 = Builder.CreateExtractElement(Vec, (uint64_t)0); Value *Elt0 = Builder.CreateExtractElement(Vec, (uint64_t)0);
Function *Intr = Intrinsic::getDeclaration(F->getParent(), Intrinsic::sqrt, Function *Intr = Intrinsic::getOrInsertDeclaration(
Elt0->getType()); F->getParent(), Intrinsic::sqrt, Elt0->getType());
Elt0 = Builder.CreateCall(Intr, Elt0); Elt0 = Builder.CreateCall(Intr, Elt0);
Rep = Builder.CreateInsertElement(Vec, Elt0, (uint64_t)0); Rep = Builder.CreateInsertElement(Vec, Elt0, (uint64_t)0);
} else if (Name.starts_with("avx.sqrt.p") || } else if (Name.starts_with("avx.sqrt.p") ||
Name.starts_with("sse2.sqrt.p") || Name.starts_with("sse2.sqrt.p") ||
Name.starts_with("sse.sqrt.p")) { Name.starts_with("sse.sqrt.p")) {
Rep = Rep =
Builder.CreateCall(Intrinsic::getDeclaration( Builder.CreateCall(Intrinsic::getOrInsertDeclaration(
F->getParent(), Intrinsic::sqrt, CI->getType()), F->getParent(), Intrinsic::sqrt, CI->getType()),
{CI->getArgOperand(0)}); {CI->getArgOperand(0)});
} else if (Name.starts_with("avx512.mask.sqrt.p")) { } else if (Name.starts_with("avx512.mask.sqrt.p")) {
@ -2499,13 +2505,13 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
: Intrinsic::x86_avx512_sqrt_pd_512; : Intrinsic::x86_avx512_sqrt_pd_512;
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(3)}; Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(3)};
Rep = Builder.CreateCall(Intrinsic::getDeclaration(CI->getModule(), IID), Rep = Builder.CreateCall(
Args); Intrinsic::getOrInsertDeclaration(CI->getModule(), IID), Args);
} else { } else {
Rep = Builder.CreateCall(Intrinsic::getDeclaration(F->getParent(), Rep = Builder.CreateCall(
Intrinsic::sqrt, Intrinsic::getOrInsertDeclaration(F->getParent(), Intrinsic::sqrt,
CI->getType()), CI->getType()),
{CI->getArgOperand(0)}); {CI->getArgOperand(0)});
} }
Rep = Rep =
emitX86Select(Builder, CI->getArgOperand(2), Rep, CI->getArgOperand(1)); emitX86Select(Builder, CI->getArgOperand(2), Rep, CI->getArgOperand(1));
@ -2629,8 +2635,9 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
break; break;
} }
Rep = Builder.CreateCall(Intrinsic::getDeclaration(F->getParent(), IID), Rep = Builder.CreateCall(
{CI->getOperand(0), CI->getArgOperand(1)}); Intrinsic::getOrInsertDeclaration(F->getParent(), IID),
{CI->getOperand(0), CI->getArgOperand(1)});
Rep = applyX86MaskOn1BitsVec(Builder, Rep, CI->getArgOperand(2)); Rep = applyX86MaskOn1BitsVec(Builder, Rep, CI->getArgOperand(2));
} else if (Name.starts_with("avx512.mask.fpclass.p")) { } else if (Name.starts_with("avx512.mask.fpclass.p")) {
Type *OpTy = CI->getArgOperand(0)->getType(); Type *OpTy = CI->getArgOperand(0)->getType();
@ -2652,8 +2659,9 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else else
llvm_unreachable("Unexpected intrinsic"); llvm_unreachable("Unexpected intrinsic");
Rep = Builder.CreateCall(Intrinsic::getDeclaration(F->getParent(), IID), Rep = Builder.CreateCall(
{CI->getOperand(0), CI->getArgOperand(1)}); Intrinsic::getOrInsertDeclaration(F->getParent(), IID),
{CI->getOperand(0), CI->getArgOperand(1)});
Rep = applyX86MaskOn1BitsVec(Builder, Rep, CI->getArgOperand(2)); Rep = applyX86MaskOn1BitsVec(Builder, Rep, CI->getArgOperand(2));
} else if (Name.starts_with("avx512.cmp.p")) { } else if (Name.starts_with("avx512.cmp.p")) {
SmallVector<Value *, 4> Args(CI->args()); SmallVector<Value *, 4> Args(CI->args());
@ -2681,8 +2689,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
std::swap(Mask, Args.back()); std::swap(Mask, Args.back());
Args.push_back(Mask); Args.push_back(Mask);
Rep = Builder.CreateCall(Intrinsic::getDeclaration(F->getParent(), IID), Rep = Builder.CreateCall(
Args); Intrinsic::getOrInsertDeclaration(F->getParent(), IID), Args);
} else if (Name.starts_with("avx512.mask.cmp.")) { } else if (Name.starts_with("avx512.mask.cmp.")) {
// Integer compare intrinsics. // Integer compare intrinsics.
unsigned Imm = cast<ConstantInt>(CI->getArgOperand(2))->getZExtValue(); unsigned Imm = cast<ConstantInt>(CI->getArgOperand(2))->getZExtValue();
@ -2776,8 +2784,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
cast<ConstantInt>(CI->getArgOperand(3))->getZExtValue() != 4)) { cast<ConstantInt>(CI->getArgOperand(3))->getZExtValue() != 4)) {
Intrinsic::ID IID = IsUnsigned ? Intrinsic::x86_avx512_uitofp_round Intrinsic::ID IID = IsUnsigned ? Intrinsic::x86_avx512_uitofp_round
: Intrinsic::x86_avx512_sitofp_round; : Intrinsic::x86_avx512_sitofp_round;
Function *F = Function *F = Intrinsic::getOrInsertDeclaration(CI->getModule(), IID,
Intrinsic::getDeclaration(CI->getModule(), IID, {DstTy, SrcTy}); {DstTy, SrcTy});
Rep = Builder.CreateCall(F, {Rep, CI->getArgOperand(3)}); Rep = Builder.CreateCall(F, {Rep, CI->getArgOperand(3)});
} else { } else {
Rep = IsUnsigned ? Builder.CreateUIToFP(Rep, DstTy, "cvt") Rep = IsUnsigned ? Builder.CreateUIToFP(Rep, DstTy, "cvt")
@ -2819,7 +2827,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Value *MaskVec = getX86MaskVec(Builder, CI->getArgOperand(2), Value *MaskVec = getX86MaskVec(Builder, CI->getArgOperand(2),
ResultTy->getNumElements()); ResultTy->getNumElements());
Function *ELd = Intrinsic::getDeclaration( Function *ELd = Intrinsic::getOrInsertDeclaration(
F->getParent(), Intrinsic::masked_expandload, ResultTy); F->getParent(), Intrinsic::masked_expandload, ResultTy);
Rep = Builder.CreateCall(ELd, {Ptr, MaskVec, CI->getOperand(1)}); Rep = Builder.CreateCall(ELd, {Ptr, MaskVec, CI->getOperand(1)});
} else if (Name.starts_with("avx512.mask.compress.store.")) { } else if (Name.starts_with("avx512.mask.compress.store.")) {
@ -2834,7 +2842,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
getX86MaskVec(Builder, CI->getArgOperand(2), getX86MaskVec(Builder, CI->getArgOperand(2),
cast<FixedVectorType>(ResultTy)->getNumElements()); cast<FixedVectorType>(ResultTy)->getNumElements());
Function *CSt = Intrinsic::getDeclaration( Function *CSt = Intrinsic::getOrInsertDeclaration(
F->getParent(), Intrinsic::masked_compressstore, ResultTy); F->getParent(), Intrinsic::masked_compressstore, ResultTy);
Rep = Builder.CreateCall(CSt, {CI->getArgOperand(1), Ptr, MaskVec}); Rep = Builder.CreateCall(CSt, {CI->getArgOperand(1), Ptr, MaskVec});
} else if (Name.starts_with("avx512.mask.compress.") || } else if (Name.starts_with("avx512.mask.compress.") ||
@ -2847,7 +2855,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
bool IsCompress = Name[12] == 'c'; bool IsCompress = Name[12] == 'c';
Intrinsic::ID IID = IsCompress ? Intrinsic::x86_avx512_mask_compress Intrinsic::ID IID = IsCompress ? Intrinsic::x86_avx512_mask_compress
: Intrinsic::x86_avx512_mask_expand; : Intrinsic::x86_avx512_mask_expand;
Function *Intr = Intrinsic::getDeclaration(F->getParent(), IID, ResultTy); Function *Intr =
Intrinsic::getOrInsertDeclaration(F->getParent(), IID, ResultTy);
Rep = Builder.CreateCall(Intr, Rep = Builder.CreateCall(Intr,
{CI->getOperand(0), CI->getOperand(1), MaskVec}); {CI->getOperand(0), CI->getOperand(1), MaskVec});
} else if (Name.starts_with("xop.vpcom")) { } else if (Name.starts_with("xop.vpcom")) {
@ -2910,7 +2919,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
bool ZeroMask = Name[11] == 'z'; bool ZeroMask = Name[11] == 'z';
Rep = upgradeX86ConcatShift(Builder, *CI, true, ZeroMask); Rep = upgradeX86ConcatShift(Builder, *CI, true, ZeroMask);
} else if (Name == "sse42.crc32.64.8") { } else if (Name == "sse42.crc32.64.8") {
Function *CRC32 = Intrinsic::getDeclaration( Function *CRC32 = Intrinsic::getOrInsertDeclaration(
F->getParent(), Intrinsic::x86_sse42_crc32_32_8); F->getParent(), Intrinsic::x86_sse42_crc32_32_8);
Value *Trunc0 = Value *Trunc0 =
Builder.CreateTrunc(CI->getArgOperand(0), Type::getInt32Ty(C)); Builder.CreateTrunc(CI->getArgOperand(0), Type::getInt32Ty(C));
@ -3405,7 +3414,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = Intrinsic::x86_avx512_add_pd_512; IID = Intrinsic::x86_avx512_add_pd_512;
Rep = Builder.CreateCall( Rep = Builder.CreateCall(
Intrinsic::getDeclaration(F->getParent(), IID), Intrinsic::getOrInsertDeclaration(F->getParent(), IID),
{CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)}); {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)});
} else { } else {
Rep = Builder.CreateFAdd(CI->getArgOperand(0), CI->getArgOperand(1)); Rep = Builder.CreateFAdd(CI->getArgOperand(0), CI->getArgOperand(1));
@ -3421,7 +3430,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = Intrinsic::x86_avx512_div_pd_512; IID = Intrinsic::x86_avx512_div_pd_512;
Rep = Builder.CreateCall( Rep = Builder.CreateCall(
Intrinsic::getDeclaration(F->getParent(), IID), Intrinsic::getOrInsertDeclaration(F->getParent(), IID),
{CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)}); {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)});
} else { } else {
Rep = Builder.CreateFDiv(CI->getArgOperand(0), CI->getArgOperand(1)); Rep = Builder.CreateFDiv(CI->getArgOperand(0), CI->getArgOperand(1));
@ -3437,7 +3446,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = Intrinsic::x86_avx512_mul_pd_512; IID = Intrinsic::x86_avx512_mul_pd_512;
Rep = Builder.CreateCall( Rep = Builder.CreateCall(
Intrinsic::getDeclaration(F->getParent(), IID), Intrinsic::getOrInsertDeclaration(F->getParent(), IID),
{CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)}); {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)});
} else { } else {
Rep = Builder.CreateFMul(CI->getArgOperand(0), CI->getArgOperand(1)); Rep = Builder.CreateFMul(CI->getArgOperand(0), CI->getArgOperand(1));
@ -3453,7 +3462,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = Intrinsic::x86_avx512_sub_pd_512; IID = Intrinsic::x86_avx512_sub_pd_512;
Rep = Builder.CreateCall( Rep = Builder.CreateCall(
Intrinsic::getDeclaration(F->getParent(), IID), Intrinsic::getOrInsertDeclaration(F->getParent(), IID),
{CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)}); {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)});
} else { } else {
Rep = Builder.CreateFSub(CI->getArgOperand(0), CI->getArgOperand(1)); Rep = Builder.CreateFSub(CI->getArgOperand(0), CI->getArgOperand(1));
@ -3471,13 +3480,13 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Intrinsic::ID IID = MinMaxTbl[IsMin][IsDouble]; Intrinsic::ID IID = MinMaxTbl[IsMin][IsDouble];
Rep = Builder.CreateCall( Rep = Builder.CreateCall(
Intrinsic::getDeclaration(F->getParent(), IID), Intrinsic::getOrInsertDeclaration(F->getParent(), IID),
{CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)}); {CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(4)});
Rep = Rep =
emitX86Select(Builder, CI->getArgOperand(3), Rep, CI->getArgOperand(2)); emitX86Select(Builder, CI->getArgOperand(3), Rep, CI->getArgOperand(2));
} else if (Name.starts_with("avx512.mask.lzcnt.")) { } else if (Name.starts_with("avx512.mask.lzcnt.")) {
Rep = Rep =
Builder.CreateCall(Intrinsic::getDeclaration( Builder.CreateCall(Intrinsic::getOrInsertDeclaration(
F->getParent(), Intrinsic::ctlz, CI->getType()), F->getParent(), Intrinsic::ctlz, CI->getType()),
{CI->getArgOperand(0), Builder.getInt1(false)}); {CI->getArgOperand(0), Builder.getInt1(false)});
Rep = Rep =
@ -3723,10 +3732,10 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
if (NegAcc) if (NegAcc)
Ops[2] = Builder.CreateFNeg(Ops[2]); Ops[2] = Builder.CreateFNeg(Ops[2]);
Rep = Builder.CreateCall(Intrinsic::getDeclaration(CI->getModule(), Rep = Builder.CreateCall(
Intrinsic::fma, Intrinsic::getOrInsertDeclaration(CI->getModule(), Intrinsic::fma,
Ops[0]->getType()), Ops[0]->getType()),
Ops); Ops);
if (IsScalar) if (IsScalar)
Rep = Builder.CreateInsertElement(CI->getArgOperand(0), Rep, (uint64_t)0); Rep = Builder.CreateInsertElement(CI->getArgOperand(0), Rep, (uint64_t)0);
@ -3738,10 +3747,10 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Ops[1] = Builder.CreateExtractElement(Ops[1], (uint64_t)0); Ops[1] = Builder.CreateExtractElement(Ops[1], (uint64_t)0);
Ops[2] = Builder.CreateExtractElement(Ops[2], (uint64_t)0); Ops[2] = Builder.CreateExtractElement(Ops[2], (uint64_t)0);
Rep = Builder.CreateCall(Intrinsic::getDeclaration(CI->getModule(), Rep = Builder.CreateCall(
Intrinsic::fma, Intrinsic::getOrInsertDeclaration(CI->getModule(), Intrinsic::fma,
Ops[0]->getType()), Ops[0]->getType()),
Ops); Ops);
Rep = Builder.CreateInsertElement(Constant::getNullValue(CI->getType()), Rep = Builder.CreateInsertElement(Constant::getNullValue(CI->getType()),
Rep, (uint64_t)0); Rep, (uint64_t)0);
@ -3781,11 +3790,11 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = Intrinsic::x86_avx512_vfmadd_f64; IID = Intrinsic::x86_avx512_vfmadd_f64;
else else
IID = Intrinsic::x86_avx512_vfmadd_f32; IID = Intrinsic::x86_avx512_vfmadd_f32;
Function *FMA = Intrinsic::getDeclaration(CI->getModule(), IID); Function *FMA = Intrinsic::getOrInsertDeclaration(CI->getModule(), IID);
Rep = Builder.CreateCall(FMA, Ops); Rep = Builder.CreateCall(FMA, Ops);
} else { } else {
Function *FMA = Intrinsic::getDeclaration(CI->getModule(), Intrinsic::fma, Function *FMA = Intrinsic::getOrInsertDeclaration(
A->getType()); CI->getModule(), Intrinsic::fma, A->getType());
Rep = Builder.CreateCall(FMA, {A, B, C}); Rep = Builder.CreateCall(FMA, {A, B, C});
} }
@ -3837,11 +3846,12 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else else
IID = Intrinsic::x86_avx512_vfmadd_pd_512; IID = Intrinsic::x86_avx512_vfmadd_pd_512;
Rep = Builder.CreateCall(Intrinsic::getDeclaration(F->getParent(), IID), Rep = Builder.CreateCall(
{A, B, C, CI->getArgOperand(4)}); Intrinsic::getOrInsertDeclaration(F->getParent(), IID),
{A, B, C, CI->getArgOperand(4)});
} else { } else {
Function *FMA = Intrinsic::getDeclaration(CI->getModule(), Intrinsic::fma, Function *FMA = Intrinsic::getOrInsertDeclaration(
A->getType()); CI->getModule(), Intrinsic::fma, A->getType());
Rep = Builder.CreateCall(FMA, {A, B, C}); Rep = Builder.CreateCall(FMA, {A, B, C});
} }
@ -3868,8 +3878,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Value *Ops[] = {CI->getArgOperand(0), CI->getArgOperand(1), Value *Ops[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)}; CI->getArgOperand(2)};
Ops[2] = Builder.CreateFNeg(Ops[2]); Ops[2] = Builder.CreateFNeg(Ops[2]);
Rep = Rep = Builder.CreateCall(
Builder.CreateCall(Intrinsic::getDeclaration(F->getParent(), IID), Ops); Intrinsic::getOrInsertDeclaration(F->getParent(), IID), Ops);
} else if (Name.starts_with("avx512.mask.vfmaddsub.p") || } else if (Name.starts_with("avx512.mask.vfmaddsub.p") ||
Name.starts_with("avx512.mask3.vfmaddsub.p") || Name.starts_with("avx512.mask3.vfmaddsub.p") ||
Name.starts_with("avx512.maskz.vfmaddsub.p") || Name.starts_with("avx512.maskz.vfmaddsub.p") ||
@ -3892,16 +3902,16 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
if (IsSubAdd) if (IsSubAdd)
Ops[2] = Builder.CreateFNeg(Ops[2]); Ops[2] = Builder.CreateFNeg(Ops[2]);
Rep = Builder.CreateCall(Intrinsic::getDeclaration(F->getParent(), IID), Rep = Builder.CreateCall(
Ops); Intrinsic::getOrInsertDeclaration(F->getParent(), IID), Ops);
} else { } else {
int NumElts = cast<FixedVectorType>(CI->getType())->getNumElements(); int NumElts = cast<FixedVectorType>(CI->getType())->getNumElements();
Value *Ops[] = {CI->getArgOperand(0), CI->getArgOperand(1), Value *Ops[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)}; CI->getArgOperand(2)};
Function *FMA = Intrinsic::getDeclaration(CI->getModule(), Intrinsic::fma, Function *FMA = Intrinsic::getOrInsertDeclaration(
Ops[0]->getType()); CI->getModule(), Intrinsic::fma, Ops[0]->getType());
Value *Odd = Builder.CreateCall(FMA, Ops); Value *Odd = Builder.CreateCall(FMA, Ops);
Ops[2] = Builder.CreateFNeg(Ops[2]); Ops[2] = Builder.CreateFNeg(Ops[2]);
Value *Even = Builder.CreateCall(FMA, Ops); Value *Even = Builder.CreateCall(FMA, Ops);
@ -3944,8 +3954,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1), Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2), CI->getArgOperand(3)}; CI->getArgOperand(2), CI->getArgOperand(3)};
Rep = Builder.CreateCall(Intrinsic::getDeclaration(CI->getModule(), IID), Rep = Builder.CreateCall(
Args); Intrinsic::getOrInsertDeclaration(CI->getModule(), IID), Args);
Value *PassThru = ZeroMask ? ConstantAggregateZero::get(CI->getType()) Value *PassThru = ZeroMask ? ConstantAggregateZero::get(CI->getType())
: CI->getArgOperand(0); : CI->getArgOperand(0);
Rep = emitX86Select(Builder, CI->getArgOperand(4), Rep, PassThru); Rep = emitX86Select(Builder, CI->getArgOperand(4), Rep, PassThru);
@ -3972,8 +3982,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1), Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)}; CI->getArgOperand(2)};
Rep = Builder.CreateCall(Intrinsic::getDeclaration(CI->getModule(), IID), Rep = Builder.CreateCall(
Args); Intrinsic::getOrInsertDeclaration(CI->getModule(), IID), Args);
Value *PassThru = ZeroMask ? ConstantAggregateZero::get(CI->getType()) Value *PassThru = ZeroMask ? ConstantAggregateZero::get(CI->getType())
: CI->getArgOperand(0); : CI->getArgOperand(0);
Rep = emitX86Select(Builder, CI->getArgOperand(3), Rep, PassThru); Rep = emitX86Select(Builder, CI->getArgOperand(3), Rep, PassThru);
@ -4008,8 +4018,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1), Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)}; CI->getArgOperand(2)};
Rep = Builder.CreateCall(Intrinsic::getDeclaration(CI->getModule(), IID), Rep = Builder.CreateCall(
Args); Intrinsic::getOrInsertDeclaration(CI->getModule(), IID), Args);
Value *PassThru = ZeroMask ? ConstantAggregateZero::get(CI->getType()) Value *PassThru = ZeroMask ? ConstantAggregateZero::get(CI->getType())
: CI->getArgOperand(0); : CI->getArgOperand(0);
Rep = emitX86Select(Builder, CI->getArgOperand(3), Rep, PassThru); Rep = emitX86Select(Builder, CI->getArgOperand(3), Rep, PassThru);
@ -4038,8 +4048,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1), Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)}; CI->getArgOperand(2)};
Rep = Builder.CreateCall(Intrinsic::getDeclaration(CI->getModule(), IID), Rep = Builder.CreateCall(
Args); Intrinsic::getOrInsertDeclaration(CI->getModule(), IID), Args);
Value *PassThru = ZeroMask ? ConstantAggregateZero::get(CI->getType()) Value *PassThru = ZeroMask ? ConstantAggregateZero::get(CI->getType())
: CI->getArgOperand(0); : CI->getArgOperand(0);
Rep = emitX86Select(Builder, CI->getArgOperand(3), Rep, PassThru); Rep = emitX86Select(Builder, CI->getArgOperand(3), Rep, PassThru);
@ -4062,7 +4072,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1), Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)}; CI->getArgOperand(2)};
Value *NewCall = Builder.CreateCall( Value *NewCall = Builder.CreateCall(
Intrinsic::getDeclaration(CI->getModule(), IID), Args); Intrinsic::getOrInsertDeclaration(CI->getModule(), IID), Args);
// Extract the second result and store it. // Extract the second result and store it.
Value *Data = Builder.CreateExtractValue(NewCall, 1); Value *Data = Builder.CreateExtractValue(NewCall, 1);
@ -4108,7 +4118,7 @@ static Value *upgradeAArch64IntrinsicCall(StringRef Name, CallBase *CI,
Args[1] = Builder.CreateIntrinsic(Intrinsic::aarch64_sve_convert_from_svbool, Args[1] = Builder.CreateIntrinsic(Intrinsic::aarch64_sve_convert_from_svbool,
GoodPredTy, Args[1]); GoodPredTy, Args[1]);
Function *NewF = Intrinsic::getDeclaration(CI->getModule(), NewID); Function *NewF = Intrinsic::getOrInsertDeclaration(CI->getModule(), NewID);
return Builder.CreateCall(NewF, Args, CI->getName()); return Builder.CreateCall(NewF, Args, CI->getName());
} }
@ -4117,16 +4127,17 @@ static Value *upgradeARMIntrinsicCall(StringRef Name, CallBase *CI, Function *F,
if (Name == "mve.vctp64.old") { if (Name == "mve.vctp64.old") {
// Replace the old v4i1 vctp64 with a v2i1 vctp and predicate-casts to the // Replace the old v4i1 vctp64 with a v2i1 vctp and predicate-casts to the
// correct type. // correct type.
Value *VCTP = Builder.CreateCall( Value *VCTP =
Intrinsic::getDeclaration(F->getParent(), Intrinsic::arm_mve_vctp64), Builder.CreateCall(Intrinsic::getOrInsertDeclaration(
CI->getArgOperand(0), CI->getName()); F->getParent(), Intrinsic::arm_mve_vctp64),
CI->getArgOperand(0), CI->getName());
Value *C1 = Builder.CreateCall( Value *C1 = Builder.CreateCall(
Intrinsic::getDeclaration( Intrinsic::getOrInsertDeclaration(
F->getParent(), Intrinsic::arm_mve_pred_v2i, F->getParent(), Intrinsic::arm_mve_pred_v2i,
{VectorType::get(Builder.getInt1Ty(), 2, false)}), {VectorType::get(Builder.getInt1Ty(), 2, false)}),
VCTP); VCTP);
return Builder.CreateCall( return Builder.CreateCall(
Intrinsic::getDeclaration( Intrinsic::getOrInsertDeclaration(
F->getParent(), Intrinsic::arm_mve_pred_i2v, F->getParent(), Intrinsic::arm_mve_pred_i2v,
{VectorType::get(Builder.getInt1Ty(), 4, false)}), {VectorType::get(Builder.getInt1Ty(), 4, false)}),
C1); C1);
@ -4188,19 +4199,19 @@ static Value *upgradeARMIntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Type *Ty = Op->getType(); Type *Ty = Op->getType();
if (Ty->getScalarSizeInBits() == 1) { if (Ty->getScalarSizeInBits() == 1) {
Value *C1 = Builder.CreateCall( Value *C1 = Builder.CreateCall(
Intrinsic::getDeclaration( Intrinsic::getOrInsertDeclaration(
F->getParent(), Intrinsic::arm_mve_pred_v2i, F->getParent(), Intrinsic::arm_mve_pred_v2i,
{VectorType::get(Builder.getInt1Ty(), 4, false)}), {VectorType::get(Builder.getInt1Ty(), 4, false)}),
Op); Op);
Op = Builder.CreateCall( Op = Builder.CreateCall(
Intrinsic::getDeclaration(F->getParent(), Intrinsic::getOrInsertDeclaration(
Intrinsic::arm_mve_pred_i2v, {V2I1Ty}), F->getParent(), Intrinsic::arm_mve_pred_i2v, {V2I1Ty}),
C1); C1);
} }
Ops.push_back(Op); Ops.push_back(Op);
} }
Function *Fn = Intrinsic::getDeclaration(F->getParent(), ID, Tys); Function *Fn = Intrinsic::getOrInsertDeclaration(F->getParent(), ID, Tys);
return Builder.CreateCall(Fn, Ops, CI->getName()); return Builder.CreateCall(Fn, Ops, CI->getName());
} }
llvm_unreachable("Unknown function for ARM CallBase upgrade."); llvm_unreachable("Unknown function for ARM CallBase upgrade.");
@ -5088,7 +5099,8 @@ void llvm::UpgradeARCRuntime(Module &M) {
if (!Fn) if (!Fn)
return; return;
Function *NewFn = llvm::Intrinsic::getDeclaration(&M, IntrinsicFunc); Function *NewFn =
llvm::Intrinsic::getOrInsertDeclaration(&M, IntrinsicFunc);
for (User *U : make_early_inc_range(Fn->users())) { for (User *U : make_early_inc_range(Fn->users())) {
CallInst *CI = dyn_cast<CallInst>(U); CallInst *CI = dyn_cast<CallInst>(U);

View File

@ -2468,7 +2468,7 @@ LLVMValueRef LLVMGetIntrinsicDeclaration(LLVMModuleRef Mod,
size_t ParamCount) { size_t ParamCount) {
ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount); ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
auto IID = llvm_map_to_intrinsic_id(ID); auto IID = llvm_map_to_intrinsic_id(ID);
return wrap(llvm::Intrinsic::getDeclaration(unwrap(Mod), IID, Tys)); return wrap(llvm::Intrinsic::getOrInsertDeclaration(unwrap(Mod), IID, Tys));
} }
const char *LLVMIntrinsicGetName(unsigned ID, size_t *NameLength) { const char *LLVMIntrinsicGetName(unsigned ID, size_t *NameLength) {

View File

@ -991,7 +991,7 @@ DbgInstPtr DIBuilder::insertDbgAssign(Instruction *LinkedInstr, Value *Val,
LLVMContext &Ctx = LinkedInstr->getContext(); LLVMContext &Ctx = LinkedInstr->getContext();
Module *M = LinkedInstr->getModule(); Module *M = LinkedInstr->getModule();
if (!AssignFn) if (!AssignFn)
AssignFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_assign); AssignFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_assign);
std::array<Value *, 6> Args = { std::array<Value *, 6> Args = {
MetadataAsValue::get(Ctx, ValueAsMetadata::get(Val)), MetadataAsValue::get(Ctx, ValueAsMetadata::get(Val)),
@ -1060,7 +1060,7 @@ static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {
} }
static Function *getDeclareIntrin(Module &M) { static Function *getDeclareIntrin(Module &M) {
return Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); return Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_declare);
} }
DbgInstPtr DIBuilder::insertDbgValueIntrinsic( DbgInstPtr DIBuilder::insertDbgValueIntrinsic(
@ -1074,7 +1074,7 @@ DbgInstPtr DIBuilder::insertDbgValueIntrinsic(
} }
if (!ValueFn) if (!ValueFn)
ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); ValueFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_value);
return insertDbgIntrinsic(ValueFn, Val, VarInfo, Expr, DL, InsertBB, return insertDbgIntrinsic(ValueFn, Val, VarInfo, Expr, DL, InsertBB,
InsertBefore); InsertBefore);
} }
@ -1175,7 +1175,7 @@ DbgInstPtr DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL,
} }
if (!LabelFn) if (!LabelFn)
LabelFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_label); LabelFn = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::dbg_label);
Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)}; Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)};

View File

@ -413,13 +413,13 @@ DbgVariableRecord::createDebugIntrinsic(Module *M,
// Work out what sort of intrinsic we're going to produce. // Work out what sort of intrinsic we're going to produce.
switch (getType()) { switch (getType()) {
case DbgVariableRecord::LocationType::Declare: case DbgVariableRecord::LocationType::Declare:
IntrinsicFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_declare); IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_declare);
break; break;
case DbgVariableRecord::LocationType::Value: case DbgVariableRecord::LocationType::Value:
IntrinsicFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_value); IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_value);
break; break;
case DbgVariableRecord::LocationType::Assign: case DbgVariableRecord::LocationType::Assign:
IntrinsicFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_assign); IntrinsicFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_assign);
break; break;
case DbgVariableRecord::LocationType::End: case DbgVariableRecord::LocationType::End:
case DbgVariableRecord::LocationType::Any: case DbgVariableRecord::LocationType::Any:
@ -459,7 +459,7 @@ DbgVariableRecord::createDebugIntrinsic(Module *M,
DbgLabelInst * DbgLabelInst *
DbgLabelRecord::createDebugIntrinsic(Module *M, DbgLabelRecord::createDebugIntrinsic(Module *M,
Instruction *InsertBefore) const { Instruction *InsertBefore) const {
auto *LabelFn = Intrinsic::getDeclaration(M, Intrinsic::dbg_label); auto *LabelFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::dbg_label);
Value *Args[] = { Value *Args[] = {
MetadataAsValue::get(getDebugLoc()->getContext(), getLabel())}; MetadataAsValue::get(getDebugLoc()->getContext(), getLabel())};
DbgLabelInst *DbgLabel = cast<DbgLabelInst>( DbgLabelInst *DbgLabel = cast<DbgLabelInst>(

View File

@ -91,8 +91,8 @@ Value *IRBuilderBase::CreateVScale(Constant *Scaling, const Twine &Name) {
if (cast<ConstantInt>(Scaling)->isZero()) if (cast<ConstantInt>(Scaling)->isZero())
return Scaling; return Scaling;
Module *M = GetInsertBlock()->getParent()->getParent(); Module *M = GetInsertBlock()->getParent()->getParent();
Function *TheFn = Function *TheFn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::vscale,
Intrinsic::getDeclaration(M, Intrinsic::vscale, {Scaling->getType()}); {Scaling->getType()});
CallInst *CI = CreateCall(TheFn, {}, {}, Name); CallInst *CI = CreateCall(TheFn, {}, {}, Name);
return cast<ConstantInt>(Scaling)->isOne() ? CI : CreateMul(CI, Scaling); return cast<ConstantInt>(Scaling)->isOne() ? CI : CreateMul(CI, Scaling);
} }
@ -142,7 +142,8 @@ CallInst *IRBuilderBase::CreateMemSet(Value *Ptr, Value *Val, Value *Size,
Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)}; Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)};
Type *Tys[] = { Ptr->getType(), Size->getType() }; Type *Tys[] = { Ptr->getType(), Size->getType() };
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys); Function *TheFn =
Intrinsic::getOrInsertDeclaration(M, Intrinsic::memset, Tys);
CallInst *CI = CreateCall(TheFn, Ops); CallInst *CI = CreateCall(TheFn, Ops);
@ -170,7 +171,8 @@ CallInst *IRBuilderBase::CreateMemSetInline(Value *Dst, MaybeAlign DstAlign,
Value *Ops[] = {Dst, Val, Size, getInt1(IsVolatile)}; Value *Ops[] = {Dst, Val, Size, getInt1(IsVolatile)};
Type *Tys[] = {Dst->getType(), Size->getType()}; Type *Tys[] = {Dst->getType(), Size->getType()};
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset_inline, Tys); Function *TheFn =
Intrinsic::getOrInsertDeclaration(M, Intrinsic::memset_inline, Tys);
CallInst *CI = CreateCall(TheFn, Ops); CallInst *CI = CreateCall(TheFn, Ops);
@ -197,7 +199,7 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemSet(
Value *Ops[] = {Ptr, Val, Size, getInt32(ElementSize)}; Value *Ops[] = {Ptr, Val, Size, getInt32(ElementSize)};
Type *Tys[] = {Ptr->getType(), Size->getType()}; Type *Tys[] = {Ptr->getType(), Size->getType()};
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *TheFn = Intrinsic::getDeclaration( Function *TheFn = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::memset_element_unordered_atomic, Tys); M, Intrinsic::memset_element_unordered_atomic, Tys);
CallInst *CI = CreateCall(TheFn, Ops); CallInst *CI = CreateCall(TheFn, Ops);
@ -227,7 +229,7 @@ CallInst *IRBuilderBase::CreateMemTransferInst(
Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)}; Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)};
Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() }; Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *TheFn = Intrinsic::getDeclaration(M, IntrID, Tys); Function *TheFn = Intrinsic::getOrInsertDeclaration(M, IntrID, Tys);
CallInst *CI = CreateCall(TheFn, Ops); CallInst *CI = CreateCall(TheFn, Ops);
@ -265,7 +267,7 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemCpy(
Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)}; Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()}; Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *TheFn = Intrinsic::getDeclaration( Function *TheFn = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::memcpy_element_unordered_atomic, Tys); M, Intrinsic::memcpy_element_unordered_atomic, Tys);
CallInst *CI = CreateCall(TheFn, Ops); CallInst *CI = CreateCall(TheFn, Ops);
@ -381,7 +383,7 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemMove(
Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)}; Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()}; Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *TheFn = Intrinsic::getDeclaration( Function *TheFn = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::memmove_element_unordered_atomic, Tys); M, Intrinsic::memmove_element_unordered_atomic, Tys);
CallInst *CI = CreateCall(TheFn, Ops); CallInst *CI = CreateCall(TheFn, Ops);
@ -411,23 +413,23 @@ CallInst *IRBuilderBase::getReductionIntrinsic(Intrinsic::ID ID, Value *Src) {
Module *M = GetInsertBlock()->getParent()->getParent(); Module *M = GetInsertBlock()->getParent()->getParent();
Value *Ops[] = {Src}; Value *Ops[] = {Src};
Type *Tys[] = { Src->getType() }; Type *Tys[] = { Src->getType() };
auto Decl = Intrinsic::getDeclaration(M, ID, Tys); auto Decl = Intrinsic::getOrInsertDeclaration(M, ID, Tys);
return CreateCall(Decl, Ops); return CreateCall(Decl, Ops);
} }
CallInst *IRBuilderBase::CreateFAddReduce(Value *Acc, Value *Src) { CallInst *IRBuilderBase::CreateFAddReduce(Value *Acc, Value *Src) {
Module *M = GetInsertBlock()->getParent()->getParent(); Module *M = GetInsertBlock()->getParent()->getParent();
Value *Ops[] = {Acc, Src}; Value *Ops[] = {Acc, Src};
auto Decl = Intrinsic::getDeclaration(M, Intrinsic::vector_reduce_fadd, auto Decl = Intrinsic::getOrInsertDeclaration(
{Src->getType()}); M, Intrinsic::vector_reduce_fadd, {Src->getType()});
return CreateCall(Decl, Ops); return CreateCall(Decl, Ops);
} }
CallInst *IRBuilderBase::CreateFMulReduce(Value *Acc, Value *Src) { CallInst *IRBuilderBase::CreateFMulReduce(Value *Acc, Value *Src) {
Module *M = GetInsertBlock()->getParent()->getParent(); Module *M = GetInsertBlock()->getParent()->getParent();
Value *Ops[] = {Acc, Src}; Value *Ops[] = {Acc, Src};
auto Decl = Intrinsic::getDeclaration(M, Intrinsic::vector_reduce_fmul, auto Decl = Intrinsic::getOrInsertDeclaration(
{Src->getType()}); M, Intrinsic::vector_reduce_fmul, {Src->getType()});
return CreateCall(Decl, Ops); return CreateCall(Decl, Ops);
} }
@ -489,8 +491,8 @@ CallInst *IRBuilderBase::CreateLifetimeStart(Value *Ptr, ConstantInt *Size) {
"lifetime.start requires the size to be an i64"); "lifetime.start requires the size to be an i64");
Value *Ops[] = { Size, Ptr }; Value *Ops[] = { Size, Ptr };
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *TheFn = Function *TheFn = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::lifetime_start, {Ptr->getType()}); M, Intrinsic::lifetime_start, {Ptr->getType()});
return CreateCall(TheFn, Ops); return CreateCall(TheFn, Ops);
} }
@ -504,8 +506,8 @@ CallInst *IRBuilderBase::CreateLifetimeEnd(Value *Ptr, ConstantInt *Size) {
"lifetime.end requires the size to be an i64"); "lifetime.end requires the size to be an i64");
Value *Ops[] = { Size, Ptr }; Value *Ops[] = { Size, Ptr };
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *TheFn = Function *TheFn = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::lifetime_end, {Ptr->getType()}); M, Intrinsic::lifetime_end, {Ptr->getType()});
return CreateCall(TheFn, Ops); return CreateCall(TheFn, Ops);
} }
@ -523,8 +525,8 @@ CallInst *IRBuilderBase::CreateInvariantStart(Value *Ptr, ConstantInt *Size) {
// Fill in the single overloaded type: memory object type. // Fill in the single overloaded type: memory object type.
Type *ObjectPtr[1] = {Ptr->getType()}; Type *ObjectPtr[1] = {Ptr->getType()};
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *TheFn = Function *TheFn = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::invariant_start, ObjectPtr); M, Intrinsic::invariant_start, ObjectPtr);
return CreateCall(TheFn, Ops); return CreateCall(TheFn, Ops);
} }
@ -556,13 +558,13 @@ IRBuilderBase::CreateAssumption(Value *Cond,
Value *Ops[] = { Cond }; Value *Ops[] = { Cond };
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *FnAssume = Intrinsic::getDeclaration(M, Intrinsic::assume); Function *FnAssume = Intrinsic::getOrInsertDeclaration(M, Intrinsic::assume);
return CreateCall(FnAssume, Ops, OpBundles); return CreateCall(FnAssume, Ops, OpBundles);
} }
Instruction *IRBuilderBase::CreateNoAliasScopeDeclaration(Value *Scope) { Instruction *IRBuilderBase::CreateNoAliasScopeDeclaration(Value *Scope) {
Module *M = BB->getModule(); Module *M = BB->getModule();
auto *FnIntrinsic = Intrinsic::getDeclaration( auto *FnIntrinsic = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::experimental_noalias_scope_decl, {}); M, Intrinsic::experimental_noalias_scope_decl, {});
return CreateCall(FnIntrinsic, {Scope}); return CreateCall(FnIntrinsic, {Scope});
} }
@ -615,7 +617,7 @@ CallInst *IRBuilderBase::CreateMaskedIntrinsic(Intrinsic::ID Id,
ArrayRef<Type *> OverloadedTypes, ArrayRef<Type *> OverloadedTypes,
const Twine &Name) { const Twine &Name) {
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *TheFn = Intrinsic::getDeclaration(M, Id, OverloadedTypes); Function *TheFn = Intrinsic::getOrInsertDeclaration(M, Id, OverloadedTypes);
return CreateCall(TheFn, Ops, {}, Name); return CreateCall(TheFn, Ops, {}, Name);
} }
@ -765,9 +767,9 @@ static CallInst *CreateGCStatepointCallCommon(
const Twine &Name) { const Twine &Name) {
Module *M = Builder->GetInsertBlock()->getParent()->getParent(); Module *M = Builder->GetInsertBlock()->getParent()->getParent();
// Fill in the one generic type'd argument (the function is also vararg) // Fill in the one generic type'd argument (the function is also vararg)
Function *FnStatepoint = Function *FnStatepoint = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint, M, Intrinsic::experimental_gc_statepoint,
{ActualCallee.getCallee()->getType()}); {ActualCallee.getCallee()->getType()});
std::vector<Value *> Args = getStatepointArgs( std::vector<Value *> Args = getStatepointArgs(
*Builder, ID, NumPatchBytes, ActualCallee.getCallee(), Flags, CallArgs); *Builder, ID, NumPatchBytes, ActualCallee.getCallee(), Flags, CallArgs);
@ -820,9 +822,9 @@ static InvokeInst *CreateGCStatepointInvokeCommon(
const Twine &Name) { const Twine &Name) {
Module *M = Builder->GetInsertBlock()->getParent()->getParent(); Module *M = Builder->GetInsertBlock()->getParent()->getParent();
// Fill in the one generic type'd argument (the function is also vararg) // Fill in the one generic type'd argument (the function is also vararg)
Function *FnStatepoint = Function *FnStatepoint = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint, M, Intrinsic::experimental_gc_statepoint,
{ActualInvokee.getCallee()->getType()}); {ActualInvokee.getCallee()->getType()});
std::vector<Value *> Args = std::vector<Value *> Args =
getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee.getCallee(), getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee.getCallee(),
@ -875,7 +877,7 @@ CallInst *IRBuilderBase::CreateGCResult(Instruction *Statepoint,
Intrinsic::ID ID = Intrinsic::experimental_gc_result; Intrinsic::ID ID = Intrinsic::experimental_gc_result;
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Type *Types[] = {ResultType}; Type *Types[] = {ResultType};
Function *FnGCResult = Intrinsic::getDeclaration(M, ID, Types); Function *FnGCResult = Intrinsic::getOrInsertDeclaration(M, ID, Types);
Value *Args[] = {Statepoint}; Value *Args[] = {Statepoint};
return CreateCall(FnGCResult, Args, {}, Name); return CreateCall(FnGCResult, Args, {}, Name);
@ -886,8 +888,8 @@ CallInst *IRBuilderBase::CreateGCRelocate(Instruction *Statepoint,
Type *ResultType, const Twine &Name) { Type *ResultType, const Twine &Name) {
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Type *Types[] = {ResultType}; Type *Types[] = {ResultType};
Function *FnGCRelocate = Function *FnGCRelocate = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types); M, Intrinsic::experimental_gc_relocate, Types);
Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)}; Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)};
return CreateCall(FnGCRelocate, Args, {}, Name); return CreateCall(FnGCRelocate, Args, {}, Name);
@ -897,7 +899,7 @@ CallInst *IRBuilderBase::CreateGCGetPointerBase(Value *DerivedPtr,
const Twine &Name) { const Twine &Name) {
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Type *PtrTy = DerivedPtr->getType(); Type *PtrTy = DerivedPtr->getType();
Function *FnGCFindBase = Intrinsic::getDeclaration( Function *FnGCFindBase = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::experimental_gc_get_pointer_base, {PtrTy, PtrTy}); M, Intrinsic::experimental_gc_get_pointer_base, {PtrTy, PtrTy});
return CreateCall(FnGCFindBase, {DerivedPtr}, {}, Name); return CreateCall(FnGCFindBase, {DerivedPtr}, {}, Name);
} }
@ -906,7 +908,7 @@ CallInst *IRBuilderBase::CreateGCGetPointerOffset(Value *DerivedPtr,
const Twine &Name) { const Twine &Name) {
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Type *PtrTy = DerivedPtr->getType(); Type *PtrTy = DerivedPtr->getType();
Function *FnGCGetOffset = Intrinsic::getDeclaration( Function *FnGCGetOffset = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::experimental_gc_get_pointer_offset, {PtrTy}); M, Intrinsic::experimental_gc_get_pointer_offset, {PtrTy});
return CreateCall(FnGCGetOffset, {DerivedPtr}, {}, Name); return CreateCall(FnGCGetOffset, {DerivedPtr}, {}, Name);
} }
@ -915,7 +917,7 @@ CallInst *IRBuilderBase::CreateUnaryIntrinsic(Intrinsic::ID ID, Value *V,
Instruction *FMFSource, Instruction *FMFSource,
const Twine &Name) { const Twine &Name) {
Module *M = BB->getModule(); Module *M = BB->getModule();
Function *Fn = Intrinsic::getDeclaration(M, ID, {V->getType()}); Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {V->getType()});
return createCallHelper(Fn, {V}, Name, FMFSource); return createCallHelper(Fn, {V}, Name, FMFSource);
} }
@ -923,7 +925,7 @@ Value *IRBuilderBase::CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS,
Value *RHS, Instruction *FMFSource, Value *RHS, Instruction *FMFSource,
const Twine &Name) { const Twine &Name) {
Module *M = BB->getModule(); Module *M = BB->getModule();
Function *Fn = Intrinsic::getDeclaration(M, ID, { LHS->getType() }); Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, {LHS->getType()});
if (Value *V = Folder.FoldBinaryIntrinsic(ID, LHS, RHS, Fn->getReturnType(), if (Value *V = Folder.FoldBinaryIntrinsic(ID, LHS, RHS, Fn->getReturnType(),
FMFSource)) FMFSource))
return V; return V;
@ -936,7 +938,7 @@ CallInst *IRBuilderBase::CreateIntrinsic(Intrinsic::ID ID,
Instruction *FMFSource, Instruction *FMFSource,
const Twine &Name) { const Twine &Name) {
Module *M = BB->getModule(); Module *M = BB->getModule();
Function *Fn = Intrinsic::getDeclaration(M, ID, Types); Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, Types);
return createCallHelper(Fn, Args, Name, FMFSource); return createCallHelper(Fn, Args, Name, FMFSource);
} }
@ -963,7 +965,7 @@ CallInst *IRBuilderBase::CreateIntrinsic(Type *RetTy, Intrinsic::ID ID,
"Wrong types for intrinsic!"); "Wrong types for intrinsic!");
// TODO: Handle varargs intrinsics. // TODO: Handle varargs intrinsics.
Function *Fn = Intrinsic::getDeclaration(M, ID, OverloadTys); Function *Fn = Intrinsic::getOrInsertDeclaration(M, ID, OverloadTys);
return createCallHelper(Fn, Args, Name, FMFSource); return createCallHelper(Fn, Args, Name, FMFSource);
} }
@ -1120,7 +1122,7 @@ Value *IRBuilderBase::CreateLaunderInvariantGroup(Value *Ptr) {
"launder.invariant.group only applies to pointers."); "launder.invariant.group only applies to pointers.");
auto *PtrType = Ptr->getType(); auto *PtrType = Ptr->getType();
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *FnLaunderInvariantGroup = Intrinsic::getDeclaration( Function *FnLaunderInvariantGroup = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::launder_invariant_group, {PtrType}); M, Intrinsic::launder_invariant_group, {PtrType});
assert(FnLaunderInvariantGroup->getReturnType() == PtrType && assert(FnLaunderInvariantGroup->getReturnType() == PtrType &&
@ -1137,7 +1139,7 @@ Value *IRBuilderBase::CreateStripInvariantGroup(Value *Ptr) {
auto *PtrType = Ptr->getType(); auto *PtrType = Ptr->getType();
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *FnStripInvariantGroup = Intrinsic::getDeclaration( Function *FnStripInvariantGroup = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::strip_invariant_group, {PtrType}); M, Intrinsic::strip_invariant_group, {PtrType});
assert(FnStripInvariantGroup->getReturnType() == PtrType && assert(FnStripInvariantGroup->getReturnType() == PtrType &&
@ -1152,7 +1154,8 @@ Value *IRBuilderBase::CreateVectorReverse(Value *V, const Twine &Name) {
auto *Ty = cast<VectorType>(V->getType()); auto *Ty = cast<VectorType>(V->getType());
if (isa<ScalableVectorType>(Ty)) { if (isa<ScalableVectorType>(Ty)) {
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *F = Intrinsic::getDeclaration(M, Intrinsic::vector_reverse, Ty); Function *F =
Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_reverse, Ty);
return Insert(CallInst::Create(F, V), Name); return Insert(CallInst::Create(F, V), Name);
} }
// Keep the original behaviour for fixed vector // Keep the original behaviour for fixed vector
@ -1171,7 +1174,8 @@ Value *IRBuilderBase::CreateVectorSplice(Value *V1, Value *V2, int64_t Imm,
if (auto *VTy = dyn_cast<ScalableVectorType>(V1->getType())) { if (auto *VTy = dyn_cast<ScalableVectorType>(V1->getType())) {
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *F = Intrinsic::getDeclaration(M, Intrinsic::vector_splice, VTy); Function *F =
Intrinsic::getOrInsertDeclaration(M, Intrinsic::vector_splice, VTy);
Value *Ops[] = {V1, V2, getInt32(Imm)}; Value *Ops[] = {V1, V2, getInt32(Imm)};
return Insert(CallInst::Create(F, Ops), Name); return Insert(CallInst::Create(F, Ops), Name);
@ -1225,7 +1229,7 @@ Value *IRBuilderBase::CreatePreserveArrayAccessIndex(
Type *ResultType = GetElementPtrInst::getGEPReturnType(Base, IdxList); Type *ResultType = GetElementPtrInst::getGEPReturnType(Base, IdxList);
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *FnPreserveArrayAccessIndex = Intrinsic::getDeclaration( Function *FnPreserveArrayAccessIndex = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::preserve_array_access_index, {ResultType, BaseType}); M, Intrinsic::preserve_array_access_index, {ResultType, BaseType});
Value *DimV = getInt32(Dimension); Value *DimV = getInt32(Dimension);
@ -1246,7 +1250,7 @@ Value *IRBuilderBase::CreatePreserveUnionAccessIndex(
auto *BaseType = Base->getType(); auto *BaseType = Base->getType();
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *FnPreserveUnionAccessIndex = Intrinsic::getDeclaration( Function *FnPreserveUnionAccessIndex = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::preserve_union_access_index, {BaseType, BaseType}); M, Intrinsic::preserve_union_access_index, {BaseType, BaseType});
Value *DIIndex = getInt32(FieldIndex); Value *DIIndex = getInt32(FieldIndex);
@ -1271,7 +1275,7 @@ Value *IRBuilderBase::CreatePreserveStructAccessIndex(
GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex}); GetElementPtrInst::getGEPReturnType(Base, {Zero, GEPIndex});
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *FnPreserveStructAccessIndex = Intrinsic::getDeclaration( Function *FnPreserveStructAccessIndex = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::preserve_struct_access_index, {ResultType, BaseType}); M, Intrinsic::preserve_struct_access_index, {ResultType, BaseType});
Value *DIIndex = getInt32(FieldIndex); Value *DIIndex = getInt32(FieldIndex);
@ -1288,8 +1292,8 @@ Value *IRBuilderBase::CreatePreserveStructAccessIndex(
Value *IRBuilderBase::createIsFPClass(Value *FPNum, unsigned Test) { Value *IRBuilderBase::createIsFPClass(Value *FPNum, unsigned Test) {
ConstantInt *TestV = getInt32(Test); ConstantInt *TestV = getInt32(Test);
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Function *FnIsFPClass = Function *FnIsFPClass = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::is_fpclass, {FPNum->getType()}); M, Intrinsic::is_fpclass, {FPNum->getType()});
return CreateCall(FnIsFPClass, {FPNum, TestV}); return CreateCall(FnIsFPClass, {FPNum, TestV});
} }

View File

@ -629,9 +629,8 @@ bool VPIntrinsic::canIgnoreVectorLengthParam() const {
return false; return false;
} }
Function *VPIntrinsic::getDeclarationForParams(Module *M, Intrinsic::ID VPID, Function *VPIntrinsic::getOrInsertDeclarationForParams(
Type *ReturnType, Module *M, Intrinsic::ID VPID, Type *ReturnType, ArrayRef<Value *> Params) {
ArrayRef<Value *> Params) {
assert(isVPIntrinsic(VPID) && "not a VP intrinsic"); assert(isVPIntrinsic(VPID) && "not a VP intrinsic");
Function *VPFunc; Function *VPFunc;
switch (VPID) { switch (VPID) {
@ -641,7 +640,7 @@ Function *VPIntrinsic::getDeclarationForParams(Module *M, Intrinsic::ID VPID,
OverloadTy = OverloadTy =
Params[*VPReductionIntrinsic::getVectorParamPos(VPID)]->getType(); Params[*VPReductionIntrinsic::getVectorParamPos(VPID)]->getType();
VPFunc = Intrinsic::getDeclaration(M, VPID, OverloadTy); VPFunc = Intrinsic::getOrInsertDeclaration(M, VPID, OverloadTy);
break; break;
} }
case Intrinsic::vp_trunc: case Intrinsic::vp_trunc:
@ -658,43 +657,43 @@ Function *VPIntrinsic::getDeclarationForParams(Module *M, Intrinsic::ID VPID,
case Intrinsic::vp_lrint: case Intrinsic::vp_lrint:
case Intrinsic::vp_llrint: case Intrinsic::vp_llrint:
case Intrinsic::vp_cttz_elts: case Intrinsic::vp_cttz_elts:
VPFunc = VPFunc = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, VPID, {ReturnType, Params[0]->getType()}); M, VPID, {ReturnType, Params[0]->getType()});
break; break;
case Intrinsic::vp_is_fpclass: case Intrinsic::vp_is_fpclass:
VPFunc = Intrinsic::getDeclaration(M, VPID, {Params[0]->getType()}); VPFunc = Intrinsic::getOrInsertDeclaration(M, VPID, {Params[0]->getType()});
break; break;
case Intrinsic::vp_merge: case Intrinsic::vp_merge:
case Intrinsic::vp_select: case Intrinsic::vp_select:
VPFunc = Intrinsic::getDeclaration(M, VPID, {Params[1]->getType()}); VPFunc = Intrinsic::getOrInsertDeclaration(M, VPID, {Params[1]->getType()});
break; break;
case Intrinsic::vp_load: case Intrinsic::vp_load:
VPFunc = Intrinsic::getDeclaration( VPFunc = Intrinsic::getOrInsertDeclaration(
M, VPID, {ReturnType, Params[0]->getType()}); M, VPID, {ReturnType, Params[0]->getType()});
break; break;
case Intrinsic::experimental_vp_strided_load: case Intrinsic::experimental_vp_strided_load:
VPFunc = Intrinsic::getDeclaration( VPFunc = Intrinsic::getOrInsertDeclaration(
M, VPID, {ReturnType, Params[0]->getType(), Params[1]->getType()}); M, VPID, {ReturnType, Params[0]->getType(), Params[1]->getType()});
break; break;
case Intrinsic::vp_gather: case Intrinsic::vp_gather:
VPFunc = Intrinsic::getDeclaration( VPFunc = Intrinsic::getOrInsertDeclaration(
M, VPID, {ReturnType, Params[0]->getType()}); M, VPID, {ReturnType, Params[0]->getType()});
break; break;
case Intrinsic::vp_store: case Intrinsic::vp_store:
VPFunc = Intrinsic::getDeclaration( VPFunc = Intrinsic::getOrInsertDeclaration(
M, VPID, {Params[0]->getType(), Params[1]->getType()}); M, VPID, {Params[0]->getType(), Params[1]->getType()});
break; break;
case Intrinsic::experimental_vp_strided_store: case Intrinsic::experimental_vp_strided_store:
VPFunc = Intrinsic::getDeclaration( VPFunc = Intrinsic::getOrInsertDeclaration(
M, VPID, M, VPID,
{Params[0]->getType(), Params[1]->getType(), Params[2]->getType()}); {Params[0]->getType(), Params[1]->getType(), Params[2]->getType()});
break; break;
case Intrinsic::vp_scatter: case Intrinsic::vp_scatter:
VPFunc = Intrinsic::getDeclaration( VPFunc = Intrinsic::getOrInsertDeclaration(
M, VPID, {Params[0]->getType(), Params[1]->getType()}); M, VPID, {Params[0]->getType(), Params[1]->getType()});
break; break;
case Intrinsic::experimental_vp_splat: case Intrinsic::experimental_vp_splat:
VPFunc = Intrinsic::getDeclaration(M, VPID, ReturnType); VPFunc = Intrinsic::getOrInsertDeclaration(M, VPID, ReturnType);
break; break;
} }
assert(VPFunc && "Could not declare VP intrinsic"); assert(VPFunc && "Could not declare VP intrinsic");

View File

@ -713,7 +713,8 @@ Intrinsic::ID Intrinsic::lookupIntrinsicID(StringRef Name) {
#include "llvm/IR/IntrinsicImpl.inc" #include "llvm/IR/IntrinsicImpl.inc"
#undef GET_INTRINSIC_ATTRIBUTES #undef GET_INTRINSIC_ATTRIBUTES
Function *Intrinsic::getDeclaration(Module *M, ID id, ArrayRef<Type *> Tys) { Function *Intrinsic::getOrInsertDeclaration(Module *M, ID id,
ArrayRef<Type *> Tys) {
// There can never be multiple globals with the same name of different types, // There can never be multiple globals with the same name of different types,
// because intrinsics must be a specific type. // because intrinsics must be a specific type.
auto *FT = getType(M->getContext(), id, Tys); auto *FT = getType(M->getContext(), id, Tys);
@ -1078,7 +1079,7 @@ std::optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) {
// invalid and we'll get an error. // invalid and we'll get an error.
ExistingGV->setName(WantedName + ".renamed"); ExistingGV->setName(WantedName + ".renamed");
} }
return Intrinsic::getDeclaration(F->getParent(), ID, ArgTys); return Intrinsic::getOrInsertDeclaration(F->getParent(), ID, ArgTys);
}(); }();
NewDecl->setCallingConv(F->getCallingConv()); NewDecl->setCallingConv(F->getCallingConv());

View File

@ -89,21 +89,22 @@ Module::~Module() {
void Module::removeDebugIntrinsicDeclarations() { void Module::removeDebugIntrinsicDeclarations() {
auto *DeclareIntrinsicFn = auto *DeclareIntrinsicFn =
Intrinsic::getDeclaration(this, Intrinsic::dbg_declare); Intrinsic::getOrInsertDeclaration(this, Intrinsic::dbg_declare);
assert((!isMaterialized() || DeclareIntrinsicFn->hasZeroLiveUses()) && assert((!isMaterialized() || DeclareIntrinsicFn->hasZeroLiveUses()) &&
"Debug declare intrinsic should have had uses removed."); "Debug declare intrinsic should have had uses removed.");
DeclareIntrinsicFn->eraseFromParent(); DeclareIntrinsicFn->eraseFromParent();
auto *ValueIntrinsicFn = auto *ValueIntrinsicFn =
Intrinsic::getDeclaration(this, Intrinsic::dbg_value); Intrinsic::getOrInsertDeclaration(this, Intrinsic::dbg_value);
assert((!isMaterialized() || ValueIntrinsicFn->hasZeroLiveUses()) && assert((!isMaterialized() || ValueIntrinsicFn->hasZeroLiveUses()) &&
"Debug value intrinsic should have had uses removed."); "Debug value intrinsic should have had uses removed.");
ValueIntrinsicFn->eraseFromParent(); ValueIntrinsicFn->eraseFromParent();
auto *AssignIntrinsicFn = auto *AssignIntrinsicFn =
Intrinsic::getDeclaration(this, Intrinsic::dbg_assign); Intrinsic::getOrInsertDeclaration(this, Intrinsic::dbg_assign);
assert((!isMaterialized() || AssignIntrinsicFn->hasZeroLiveUses()) && assert((!isMaterialized() || AssignIntrinsicFn->hasZeroLiveUses()) &&
"Debug assign intrinsic should have had uses removed."); "Debug assign intrinsic should have had uses removed.");
AssignIntrinsicFn->eraseFromParent(); AssignIntrinsicFn->eraseFromParent();
auto *LabelntrinsicFn = Intrinsic::getDeclaration(this, Intrinsic::dbg_label); auto *LabelntrinsicFn =
Intrinsic::getOrInsertDeclaration(this, Intrinsic::dbg_label);
assert((!isMaterialized() || LabelntrinsicFn->hasZeroLiveUses()) && assert((!isMaterialized() || LabelntrinsicFn->hasZeroLiveUses()) &&
"Debug label intrinsic should have had uses removed."); "Debug label intrinsic should have had uses removed.");
LabelntrinsicFn->eraseFromParent(); LabelntrinsicFn->eraseFromParent();

View File

@ -108,8 +108,8 @@ Value *VectorBuilder::createVectorInstructionImpl(Intrinsic::ID VPID,
if (VLenPosOpt) if (VLenPosOpt)
IntrinParams[*VLenPosOpt] = &requestEVL(); IntrinParams[*VLenPosOpt] = &requestEVL();
auto *VPDecl = VPIntrinsic::getDeclarationForParams(&getModule(), VPID, auto *VPDecl = VPIntrinsic::getOrInsertDeclarationForParams(
ReturnTy, IntrinParams); &getModule(), VPID, ReturnTy, IntrinParams);
return Builder.CreateCall(VPDecl, IntrinParams, Name); return Builder.CreateCall(VPDecl, IntrinParams, Name);
} }

View File

@ -16454,8 +16454,8 @@ static void createTblForTrunc(TruncInst *TI, bool IsLittleEndian) {
Builder.CreateShuffleVector(TI->getOperand(0), ShuffleLanes), VecTy)); Builder.CreateShuffleVector(TI->getOperand(0), ShuffleLanes), VecTy));
if (Parts.size() == 4) { if (Parts.size() == 4) {
auto *F = Intrinsic::getDeclaration(TI->getModule(), auto *F = Intrinsic::getOrInsertDeclaration(
Intrinsic::aarch64_neon_tbl4, VecTy); TI->getModule(), Intrinsic::aarch64_neon_tbl4, VecTy);
Parts.push_back(ConstantVector::get(MaskConst)); Parts.push_back(ConstantVector::get(MaskConst));
Results.push_back(Builder.CreateCall(F, Parts)); Results.push_back(Builder.CreateCall(F, Parts));
Parts.clear(); Parts.clear();
@ -16484,7 +16484,7 @@ static void createTblForTrunc(TruncInst *TI, bool IsLittleEndian) {
break; break;
} }
auto *F = Intrinsic::getDeclaration(TI->getModule(), TblID, VecTy); auto *F = Intrinsic::getOrInsertDeclaration(TI->getModule(), TblID, VecTy);
Parts.push_back(ConstantVector::get(MaskConst)); Parts.push_back(ConstantVector::get(MaskConst));
Results.push_back(Builder.CreateCall(F, Parts)); Results.push_back(Builder.CreateCall(F, Parts));
} }
@ -16765,9 +16765,10 @@ static Function *getStructuredLoadFunction(Module *M, unsigned Factor,
Intrinsic::aarch64_neon_ld3, Intrinsic::aarch64_neon_ld3,
Intrinsic::aarch64_neon_ld4}; Intrinsic::aarch64_neon_ld4};
if (Scalable) if (Scalable)
return Intrinsic::getDeclaration(M, SVELoads[Factor - 2], {LDVTy}); return Intrinsic::getOrInsertDeclaration(M, SVELoads[Factor - 2], {LDVTy});
return Intrinsic::getDeclaration(M, NEONLoads[Factor - 2], {LDVTy, PtrTy}); return Intrinsic::getOrInsertDeclaration(M, NEONLoads[Factor - 2],
{LDVTy, PtrTy});
} }
static Function *getStructuredStoreFunction(Module *M, unsigned Factor, static Function *getStructuredStoreFunction(Module *M, unsigned Factor,
@ -16781,9 +16782,10 @@ static Function *getStructuredStoreFunction(Module *M, unsigned Factor,
Intrinsic::aarch64_neon_st3, Intrinsic::aarch64_neon_st3,
Intrinsic::aarch64_neon_st4}; Intrinsic::aarch64_neon_st4};
if (Scalable) if (Scalable)
return Intrinsic::getDeclaration(M, SVEStores[Factor - 2], {STVTy}); return Intrinsic::getOrInsertDeclaration(M, SVEStores[Factor - 2], {STVTy});
return Intrinsic::getDeclaration(M, NEONStores[Factor - 2], {STVTy, PtrTy}); return Intrinsic::getOrInsertDeclaration(M, NEONStores[Factor - 2],
{STVTy, PtrTy});
} }
/// Lower an interleaved load into a ldN intrinsic. /// Lower an interleaved load into a ldN intrinsic.
@ -27247,7 +27249,7 @@ Value *AArch64TargetLowering::emitLoadLinked(IRBuilderBase &Builder,
if (ValueTy->getPrimitiveSizeInBits() == 128) { if (ValueTy->getPrimitiveSizeInBits() == 128) {
Intrinsic::ID Int = Intrinsic::ID Int =
IsAcquire ? Intrinsic::aarch64_ldaxp : Intrinsic::aarch64_ldxp; IsAcquire ? Intrinsic::aarch64_ldaxp : Intrinsic::aarch64_ldxp;
Function *Ldxr = Intrinsic::getDeclaration(M, Int); Function *Ldxr = Intrinsic::getOrInsertDeclaration(M, Int);
Value *LoHi = Builder.CreateCall(Ldxr, Addr, "lohi"); Value *LoHi = Builder.CreateCall(Ldxr, Addr, "lohi");
@ -27266,7 +27268,7 @@ Value *AArch64TargetLowering::emitLoadLinked(IRBuilderBase &Builder,
Type *Tys[] = { Addr->getType() }; Type *Tys[] = { Addr->getType() };
Intrinsic::ID Int = Intrinsic::ID Int =
IsAcquire ? Intrinsic::aarch64_ldaxr : Intrinsic::aarch64_ldxr; IsAcquire ? Intrinsic::aarch64_ldaxr : Intrinsic::aarch64_ldxr;
Function *Ldxr = Intrinsic::getDeclaration(M, Int, Tys); Function *Ldxr = Intrinsic::getOrInsertDeclaration(M, Int, Tys);
const DataLayout &DL = M->getDataLayout(); const DataLayout &DL = M->getDataLayout();
IntegerType *IntEltTy = Builder.getIntNTy(DL.getTypeSizeInBits(ValueTy)); IntegerType *IntEltTy = Builder.getIntNTy(DL.getTypeSizeInBits(ValueTy));
@ -27281,7 +27283,8 @@ Value *AArch64TargetLowering::emitLoadLinked(IRBuilderBase &Builder,
void AArch64TargetLowering::emitAtomicCmpXchgNoStoreLLBalance( void AArch64TargetLowering::emitAtomicCmpXchgNoStoreLLBalance(
IRBuilderBase &Builder) const { IRBuilderBase &Builder) const {
Module *M = Builder.GetInsertBlock()->getParent()->getParent(); Module *M = Builder.GetInsertBlock()->getParent()->getParent();
Builder.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::aarch64_clrex)); Builder.CreateCall(
Intrinsic::getOrInsertDeclaration(M, Intrinsic::aarch64_clrex));
} }
Value *AArch64TargetLowering::emitStoreConditional(IRBuilderBase &Builder, Value *AArch64TargetLowering::emitStoreConditional(IRBuilderBase &Builder,
@ -27296,7 +27299,7 @@ Value *AArch64TargetLowering::emitStoreConditional(IRBuilderBase &Builder,
if (Val->getType()->getPrimitiveSizeInBits() == 128) { if (Val->getType()->getPrimitiveSizeInBits() == 128) {
Intrinsic::ID Int = Intrinsic::ID Int =
IsRelease ? Intrinsic::aarch64_stlxp : Intrinsic::aarch64_stxp; IsRelease ? Intrinsic::aarch64_stlxp : Intrinsic::aarch64_stxp;
Function *Stxr = Intrinsic::getDeclaration(M, Int); Function *Stxr = Intrinsic::getOrInsertDeclaration(M, Int);
Type *Int64Ty = Type::getInt64Ty(M->getContext()); Type *Int64Ty = Type::getInt64Ty(M->getContext());
Type *Int128Ty = Type::getInt128Ty(M->getContext()); Type *Int128Ty = Type::getInt128Ty(M->getContext());
@ -27311,7 +27314,7 @@ Value *AArch64TargetLowering::emitStoreConditional(IRBuilderBase &Builder,
Intrinsic::ID Int = Intrinsic::ID Int =
IsRelease ? Intrinsic::aarch64_stlxr : Intrinsic::aarch64_stxr; IsRelease ? Intrinsic::aarch64_stlxr : Intrinsic::aarch64_stxr;
Type *Tys[] = { Addr->getType() }; Type *Tys[] = { Addr->getType() };
Function *Stxr = Intrinsic::getDeclaration(M, Int, Tys); Function *Stxr = Intrinsic::getOrInsertDeclaration(M, Int, Tys);
const DataLayout &DL = M->getDataLayout(); const DataLayout &DL = M->getDataLayout();
IntegerType *IntValTy = Builder.getIntNTy(DL.getTypeSizeInBits(Val->getType())); IntegerType *IntValTy = Builder.getIntNTy(DL.getTypeSizeInBits(Val->getType()));
@ -27348,7 +27351,7 @@ bool AArch64TargetLowering::shouldNormalizeToSelectSequence(LLVMContext &,
static Value *UseTlsOffset(IRBuilderBase &IRB, unsigned Offset) { static Value *UseTlsOffset(IRBuilderBase &IRB, unsigned Offset) {
Module *M = IRB.GetInsertBlock()->getParent()->getParent(); Module *M = IRB.GetInsertBlock()->getParent()->getParent();
Function *ThreadPointerFunc = Function *ThreadPointerFunc =
Intrinsic::getDeclaration(M, Intrinsic::thread_pointer); Intrinsic::getOrInsertDeclaration(M, Intrinsic::thread_pointer);
return IRB.CreatePointerCast( return IRB.CreatePointerCast(
IRB.CreateConstGEP1_32(IRB.getInt8Ty(), IRB.CreateCall(ThreadPointerFunc), IRB.CreateConstGEP1_32(IRB.getInt8Ty(), IRB.CreateCall(ThreadPointerFunc),
Offset), Offset),

View File

@ -436,10 +436,10 @@ Instruction *AArch64StackTagging::collectInitializers(Instruction *StartInst,
void AArch64StackTagging::tagAlloca(AllocaInst *AI, Instruction *InsertBefore, void AArch64StackTagging::tagAlloca(AllocaInst *AI, Instruction *InsertBefore,
Value *Ptr, uint64_t Size) { Value *Ptr, uint64_t Size) {
auto SetTagZeroFunc = auto SetTagZeroFunc = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(F->getParent(), Intrinsic::aarch64_settag_zero); F->getParent(), Intrinsic::aarch64_settag_zero);
auto StgpFunc = auto StgpFunc = Intrinsic::getOrInsertDeclaration(F->getParent(),
Intrinsic::getDeclaration(F->getParent(), Intrinsic::aarch64_stgp); Intrinsic::aarch64_stgp);
InitializerBuilder IB(Size, DL, Ptr, SetTagFunc, SetTagZeroFunc, StgpFunc); InitializerBuilder IB(Size, DL, Ptr, SetTagFunc, SetTagZeroFunc, StgpFunc);
bool LittleEndian = bool LittleEndian =
@ -481,8 +481,8 @@ Instruction *AArch64StackTagging::insertBaseTaggedPointer(
assert(PrologueBB); assert(PrologueBB);
IRBuilder<> IRB(&PrologueBB->front()); IRBuilder<> IRB(&PrologueBB->front());
Function *IRG_SP = Function *IRG_SP = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(F->getParent(), Intrinsic::aarch64_irg_sp); F->getParent(), Intrinsic::aarch64_irg_sp);
Instruction *Base = Instruction *Base =
IRB.CreateCall(IRG_SP, {Constant::getNullValue(IRB.getInt64Ty())}); IRB.CreateCall(IRG_SP, {Constant::getNullValue(IRB.getInt64Ty())});
Base->setName("basetag"); Base->setName("basetag");
@ -563,8 +563,8 @@ bool AArch64StackTagging::runOnFunction(Function &Fn) {
LI = DeleteLI.get(); LI = DeleteLI.get();
} }
SetTagFunc = SetTagFunc = Intrinsic::getOrInsertDeclaration(F->getParent(),
Intrinsic::getDeclaration(F->getParent(), Intrinsic::aarch64_settag); Intrinsic::aarch64_settag);
Instruction *Base = Instruction *Base =
insertBaseTaggedPointer(*Fn.getParent(), SInfo.AllocasToInstrument, DT); insertBaseTaggedPointer(*Fn.getParent(), SInfo.AllocasToInstrument, DT);
@ -580,7 +580,7 @@ bool AArch64StackTagging::runOnFunction(Function &Fn) {
NextTag = (NextTag + 1) % 16; NextTag = (NextTag + 1) % 16;
// Replace alloca with tagp(alloca). // Replace alloca with tagp(alloca).
IRBuilder<> IRB(Info.AI->getNextNode()); IRBuilder<> IRB(Info.AI->getNextNode());
Function *TagP = Intrinsic::getDeclaration( Function *TagP = Intrinsic::getOrInsertDeclaration(
F->getParent(), Intrinsic::aarch64_tagp, {Info.AI->getType()}); F->getParent(), Intrinsic::aarch64_tagp, {Info.AI->getType()});
Instruction *TagPCall = Instruction *TagPCall =
IRB.CreateCall(TagP, {Constant::getNullValue(Info.AI->getType()), Base, IRB.CreateCall(TagP, {Constant::getNullValue(Info.AI->getType()), Base,

View File

@ -1637,7 +1637,7 @@ static std::optional<Instruction *> instCombineSVEAllActive(IntrinsicInst &II,
return std::nullopt; return std::nullopt;
auto *Mod = II.getModule(); auto *Mod = II.getModule();
auto *NewDecl = Intrinsic::getDeclaration(Mod, IID, {II.getType()}); auto *NewDecl = Intrinsic::getOrInsertDeclaration(Mod, IID, {II.getType()});
II.setCalledFunction(NewDecl); II.setCalledFunction(NewDecl);
return &II; return &II;

View File

@ -71,7 +71,7 @@ void emitTPIDR2Save(Module *M, IRBuilder<> &Builder) {
// A save to TPIDR2 should be followed by clearing TPIDR2_EL0. // A save to TPIDR2 should be followed by clearing TPIDR2_EL0.
Function *WriteIntr = Function *WriteIntr =
Intrinsic::getDeclaration(M, Intrinsic::aarch64_sme_set_tpidr2); Intrinsic::getOrInsertDeclaration(M, Intrinsic::aarch64_sme_set_tpidr2);
Builder.CreateCall(WriteIntr->getFunctionType(), WriteIntr, Builder.CreateCall(WriteIntr->getFunctionType(), WriteIntr,
Builder.getInt64(0)); Builder.getInt64(0));
} }
@ -114,7 +114,7 @@ bool SMEABI::updateNewStateFunctions(Module *M, Function *F,
// Read TPIDR2_EL0 in PreludeBB & branch to SaveBB if not 0. // Read TPIDR2_EL0 in PreludeBB & branch to SaveBB if not 0.
Builder.SetInsertPoint(PreludeBB); Builder.SetInsertPoint(PreludeBB);
Function *TPIDR2Intr = Function *TPIDR2Intr =
Intrinsic::getDeclaration(M, Intrinsic::aarch64_sme_get_tpidr2); Intrinsic::getOrInsertDeclaration(M, Intrinsic::aarch64_sme_get_tpidr2);
auto *TPIDR2 = Builder.CreateCall(TPIDR2Intr->getFunctionType(), TPIDR2Intr, auto *TPIDR2 = Builder.CreateCall(TPIDR2Intr->getFunctionType(), TPIDR2Intr,
{}, "tpidr2"); {}, "tpidr2");
auto *Cmp = Builder.CreateCmp(ICmpInst::ICMP_NE, TPIDR2, auto *Cmp = Builder.CreateCmp(ICmpInst::ICMP_NE, TPIDR2,
@ -128,20 +128,20 @@ bool SMEABI::updateNewStateFunctions(Module *M, Function *F,
// Enable pstate.za at the start of the function. // Enable pstate.za at the start of the function.
Builder.SetInsertPoint(&OrigBB->front()); Builder.SetInsertPoint(&OrigBB->front());
Function *EnableZAIntr = Function *EnableZAIntr =
Intrinsic::getDeclaration(M, Intrinsic::aarch64_sme_za_enable); Intrinsic::getOrInsertDeclaration(M, Intrinsic::aarch64_sme_za_enable);
Builder.CreateCall(EnableZAIntr->getFunctionType(), EnableZAIntr); Builder.CreateCall(EnableZAIntr->getFunctionType(), EnableZAIntr);
} }
if (FnAttrs.isNewZA()) { if (FnAttrs.isNewZA()) {
Function *ZeroIntr = Function *ZeroIntr =
Intrinsic::getDeclaration(M, Intrinsic::aarch64_sme_zero); Intrinsic::getOrInsertDeclaration(M, Intrinsic::aarch64_sme_zero);
Builder.CreateCall(ZeroIntr->getFunctionType(), ZeroIntr, Builder.CreateCall(ZeroIntr->getFunctionType(), ZeroIntr,
Builder.getInt32(0xff)); Builder.getInt32(0xff));
} }
if (FnAttrs.isNewZT0()) { if (FnAttrs.isNewZT0()) {
Function *ClearZT0Intr = Function *ClearZT0Intr =
Intrinsic::getDeclaration(M, Intrinsic::aarch64_sme_zero_zt); Intrinsic::getOrInsertDeclaration(M, Intrinsic::aarch64_sme_zero_zt);
Builder.CreateCall(ClearZT0Intr->getFunctionType(), ClearZT0Intr, Builder.CreateCall(ClearZT0Intr->getFunctionType(), ClearZT0Intr,
{Builder.getInt32(0)}); {Builder.getInt32(0)});
} }
@ -153,8 +153,8 @@ bool SMEABI::updateNewStateFunctions(Module *M, Function *F,
if (!T || !isa<ReturnInst>(T)) if (!T || !isa<ReturnInst>(T))
continue; continue;
Builder.SetInsertPoint(T); Builder.SetInsertPoint(T);
Function *DisableZAIntr = Function *DisableZAIntr = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::aarch64_sme_za_disable); M, Intrinsic::aarch64_sme_za_disable);
Builder.CreateCall(DisableZAIntr->getFunctionType(), DisableZAIntr); Builder.CreateCall(DisableZAIntr->getFunctionType(), DisableZAIntr);
} }
} }

View File

@ -407,8 +407,8 @@ Value *AMDGPUAtomicOptimizerImpl::buildReduction(IRBuilder<> &B,
Value *const Identity) const { Value *const Identity) const {
Type *AtomicTy = V->getType(); Type *AtomicTy = V->getType();
Module *M = B.GetInsertBlock()->getModule(); Module *M = B.GetInsertBlock()->getModule();
Function *UpdateDPP = Function *UpdateDPP = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::amdgcn_update_dpp, AtomicTy); M, Intrinsic::amdgcn_update_dpp, AtomicTy);
// Reduce within each row of 16 lanes. // Reduce within each row of 16 lanes.
for (unsigned Idx = 0; Idx < 4; Idx++) { for (unsigned Idx = 0; Idx < 4; Idx++) {
@ -439,8 +439,8 @@ Value *AMDGPUAtomicOptimizerImpl::buildReduction(IRBuilder<> &B,
// Pick an arbitrary lane from 0..31 and an arbitrary lane from 32..63 and // Pick an arbitrary lane from 0..31 and an arbitrary lane from 32..63 and
// combine them with a scalar operation. // combine them with a scalar operation.
Function *ReadLane = Function *ReadLane = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::amdgcn_readlane, AtomicTy); M, Intrinsic::amdgcn_readlane, AtomicTy);
Value *Lane0 = B.CreateCall(ReadLane, {V, B.getInt32(0)}); Value *Lane0 = B.CreateCall(ReadLane, {V, B.getInt32(0)});
Value *Lane32 = B.CreateCall(ReadLane, {V, B.getInt32(32)}); Value *Lane32 = B.CreateCall(ReadLane, {V, B.getInt32(32)});
return buildNonAtomicBinOp(B, Op, Lane0, Lane32); return buildNonAtomicBinOp(B, Op, Lane0, Lane32);
@ -453,8 +453,8 @@ Value *AMDGPUAtomicOptimizerImpl::buildScan(IRBuilder<> &B,
Value *Identity) const { Value *Identity) const {
Type *AtomicTy = V->getType(); Type *AtomicTy = V->getType();
Module *M = B.GetInsertBlock()->getModule(); Module *M = B.GetInsertBlock()->getModule();
Function *UpdateDPP = Function *UpdateDPP = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::amdgcn_update_dpp, AtomicTy); M, Intrinsic::amdgcn_update_dpp, AtomicTy);
for (unsigned Idx = 0; Idx < 4; Idx++) { for (unsigned Idx = 0; Idx < 4; Idx++) {
V = buildNonAtomicBinOp( V = buildNonAtomicBinOp(
@ -513,18 +513,18 @@ Value *AMDGPUAtomicOptimizerImpl::buildShiftRight(IRBuilder<> &B, Value *V,
Value *Identity) const { Value *Identity) const {
Type *AtomicTy = V->getType(); Type *AtomicTy = V->getType();
Module *M = B.GetInsertBlock()->getModule(); Module *M = B.GetInsertBlock()->getModule();
Function *UpdateDPP = Function *UpdateDPP = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::amdgcn_update_dpp, AtomicTy); M, Intrinsic::amdgcn_update_dpp, AtomicTy);
if (ST->hasDPPWavefrontShifts()) { if (ST->hasDPPWavefrontShifts()) {
// GFX9 has DPP wavefront shift operations. // GFX9 has DPP wavefront shift operations.
V = B.CreateCall(UpdateDPP, V = B.CreateCall(UpdateDPP,
{Identity, V, B.getInt32(DPP::WAVE_SHR1), B.getInt32(0xf), {Identity, V, B.getInt32(DPP::WAVE_SHR1), B.getInt32(0xf),
B.getInt32(0xf), B.getFalse()}); B.getInt32(0xf), B.getFalse()});
} else { } else {
Function *ReadLane = Function *ReadLane = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::amdgcn_readlane, AtomicTy); M, Intrinsic::amdgcn_readlane, AtomicTy);
Function *WriteLane = Function *WriteLane = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::amdgcn_writelane, AtomicTy); M, Intrinsic::amdgcn_writelane, AtomicTy);
// On GFX10 all DPP operations are confined to a single row. To get cross- // On GFX10 all DPP operations are confined to a single row. To get cross-
// row operations we have to use permlane or readlane. // row operations we have to use permlane or readlane.

View File

@ -119,8 +119,8 @@ public:
return SqrtF32; return SqrtF32;
LLVMContext &Ctx = Mod->getContext(); LLVMContext &Ctx = Mod->getContext();
SqrtF32 = Intrinsic::getDeclaration(Mod, Intrinsic::amdgcn_sqrt, SqrtF32 = Intrinsic::getOrInsertDeclaration(Mod, Intrinsic::amdgcn_sqrt,
{Type::getFloatTy(Ctx)}); {Type::getFloatTy(Ctx)});
return SqrtF32; return SqrtF32;
} }
@ -129,7 +129,7 @@ public:
return LdexpF32; return LdexpF32;
LLVMContext &Ctx = Mod->getContext(); LLVMContext &Ctx = Mod->getContext();
LdexpF32 = Intrinsic::getDeclaration( LdexpF32 = Intrinsic::getOrInsertDeclaration(
Mod, Intrinsic::ldexp, {Type::getFloatTy(Ctx), Type::getInt32Ty(Ctx)}); Mod, Intrinsic::ldexp, {Type::getFloatTy(Ctx), Type::getInt32Ty(Ctx)});
return LdexpF32; return LdexpF32;
} }
@ -577,7 +577,7 @@ bool AMDGPUCodeGenPrepareImpl::promoteUniformBitreverseToI32(
Type *I32Ty = getI32Ty(Builder, I.getType()); Type *I32Ty = getI32Ty(Builder, I.getType());
Function *I32 = Function *I32 =
Intrinsic::getDeclaration(Mod, Intrinsic::bitreverse, { I32Ty }); Intrinsic::getOrInsertDeclaration(Mod, Intrinsic::bitreverse, {I32Ty});
Value *ExtOp = Builder.CreateZExt(I.getOperand(0), I32Ty); Value *ExtOp = Builder.CreateZExt(I.getOperand(0), I32Ty);
Value *ExtRes = Builder.CreateCall(I32, { ExtOp }); Value *ExtRes = Builder.CreateCall(I32, { ExtOp });
Value *LShrOp = Value *LShrOp =
@ -1260,8 +1260,8 @@ Value *AMDGPUCodeGenPrepareImpl::expandDivRem24Impl(
Value *FB = IsSigned ? Builder.CreateSIToFP(IB,F32Ty) Value *FB = IsSigned ? Builder.CreateSIToFP(IB,F32Ty)
: Builder.CreateUIToFP(IB,F32Ty); : Builder.CreateUIToFP(IB,F32Ty);
Function *RcpDecl = Intrinsic::getDeclaration(Mod, Intrinsic::amdgcn_rcp, Function *RcpDecl = Intrinsic::getOrInsertDeclaration(
Builder.getFloatTy()); Mod, Intrinsic::amdgcn_rcp, Builder.getFloatTy());
Value *RCP = Builder.CreateCall(RcpDecl, { FB }); Value *RCP = Builder.CreateCall(RcpDecl, { FB });
Value *FQM = Builder.CreateFMul(FA, RCP); Value *FQM = Builder.CreateFMul(FA, RCP);
@ -1455,7 +1455,8 @@ Value *AMDGPUCodeGenPrepareImpl::expandDivRem32(IRBuilder<> &Builder,
// Initial estimate of inv(y). // Initial estimate of inv(y).
Value *FloatY = Builder.CreateUIToFP(Y, F32Ty); Value *FloatY = Builder.CreateUIToFP(Y, F32Ty);
Function *Rcp = Intrinsic::getDeclaration(Mod, Intrinsic::amdgcn_rcp, F32Ty); Function *Rcp =
Intrinsic::getOrInsertDeclaration(Mod, Intrinsic::amdgcn_rcp, F32Ty);
Value *RcpY = Builder.CreateCall(Rcp, {FloatY}); Value *RcpY = Builder.CreateCall(Rcp, {FloatY});
Constant *Scale = ConstantFP::get(F32Ty, llvm::bit_cast<float>(0x4F7FFFFE)); Constant *Scale = ConstantFP::get(F32Ty, llvm::bit_cast<float>(0x4F7FFFFE));
Value *ScaledY = Builder.CreateFMul(RcpY, Scale); Value *ScaledY = Builder.CreateFMul(RcpY, Scale);

View File

@ -237,7 +237,7 @@ bool optimizeSection(ArrayRef<SmallVector<IntrinsicInst *, 4>> MergeableInsts) {
else else
NewIntrinID = Intrinsic::amdgcn_image_msaa_load_2darraymsaa; NewIntrinID = Intrinsic::amdgcn_image_msaa_load_2darraymsaa;
Function *NewIntrin = Intrinsic::getDeclaration( Function *NewIntrin = Intrinsic::getOrInsertDeclaration(
IIList.front()->getModule(), NewIntrinID, OverloadTys); IIList.front()->getModule(), NewIntrinID, OverloadTys);
Args[ImageDimIntr->DMaskIndex] = Args[ImageDimIntr->DMaskIndex] =
ConstantInt::get(DMask->getType(), NewMaskVal); ConstantInt::get(DMask->getType(), NewMaskVal);

View File

@ -130,7 +130,8 @@ static std::optional<Instruction *> modifyIntrinsicCall(
// Modify arguments and types // Modify arguments and types
Func(Args, ArgTys); Func(Args, ArgTys);
Function *I = Intrinsic::getDeclaration(OldIntr.getModule(), NewIntr, ArgTys); Function *I =
Intrinsic::getOrInsertDeclaration(OldIntr.getModule(), NewIntr, ArgTys);
CallInst *NewCall = IC.Builder.CreateCall(I, Args); CallInst *NewCall = IC.Builder.CreateCall(I, Args);
NewCall->takeName(&OldIntr); NewCall->takeName(&OldIntr);
@ -502,7 +503,7 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
if (IID == Intrinsic::sqrt && !canContractSqrtToRsq(SqrtOp)) if (IID == Intrinsic::sqrt && !canContractSqrtToRsq(SqrtOp))
break; break;
Function *NewDecl = Intrinsic::getDeclaration( Function *NewDecl = Intrinsic::getOrInsertDeclaration(
SrcCI->getModule(), Intrinsic::amdgcn_rsq, {SrcCI->getType()}); SrcCI->getModule(), Intrinsic::amdgcn_rsq, {SrcCI->getType()});
InnerFMF |= FMF; InnerFMF |= FMF;
@ -527,7 +528,7 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
// f16 amdgcn.sqrt is identical to regular sqrt. // f16 amdgcn.sqrt is identical to regular sqrt.
if (IID == Intrinsic::amdgcn_sqrt && Src->getType()->isHalfTy()) { if (IID == Intrinsic::amdgcn_sqrt && Src->getType()->isHalfTy()) {
Function *NewDecl = Intrinsic::getDeclaration( Function *NewDecl = Intrinsic::getOrInsertDeclaration(
II.getModule(), Intrinsic::sqrt, {II.getType()}); II.getModule(), Intrinsic::sqrt, {II.getType()});
II.setCalledFunction(NewDecl); II.setCalledFunction(NewDecl);
return &II; return &II;
@ -614,7 +615,7 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
Value *Src1 = II.getArgOperand(1); Value *Src1 = II.getArgOperand(1);
const ConstantInt *CMask = dyn_cast<ConstantInt>(Src1); const ConstantInt *CMask = dyn_cast<ConstantInt>(Src1);
if (CMask) { if (CMask) {
II.setCalledOperand(Intrinsic::getDeclaration( II.setCalledOperand(Intrinsic::getOrInsertDeclaration(
II.getModule(), Intrinsic::is_fpclass, Src0->getType())); II.getModule(), Intrinsic::is_fpclass, Src0->getType()));
// Clamp any excess bits, as they're illegal for the generic intrinsic. // Clamp any excess bits, as they're illegal for the generic intrinsic.
@ -890,7 +891,7 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
// register (which contains the bitmask of live threads). So a // register (which contains the bitmask of live threads). So a
// comparison that always returns true is the same as a read of the // comparison that always returns true is the same as a read of the
// EXEC register. // EXEC register.
Function *NewF = Intrinsic::getDeclaration( Function *NewF = Intrinsic::getOrInsertDeclaration(
II.getModule(), Intrinsic::read_register, II.getType()); II.getModule(), Intrinsic::read_register, II.getType());
Metadata *MDArgs[] = {MDString::get(II.getContext(), "exec")}; Metadata *MDArgs[] = {MDString::get(II.getContext(), "exec")};
MDNode *MD = MDNode::get(II.getContext(), MDArgs); MDNode *MD = MDNode::get(II.getContext(), MDArgs);
@ -989,7 +990,7 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
} else if (!Ty->isFloatTy() && !Ty->isDoubleTy() && !Ty->isHalfTy()) } else if (!Ty->isFloatTy() && !Ty->isDoubleTy() && !Ty->isHalfTy())
break; break;
Function *NewF = Intrinsic::getDeclaration( Function *NewF = Intrinsic::getOrInsertDeclaration(
II.getModule(), NewIID, {II.getType(), SrcLHS->getType()}); II.getModule(), NewIID, {II.getType(), SrcLHS->getType()});
Value *Args[] = {SrcLHS, SrcRHS, Value *Args[] = {SrcLHS, SrcRHS,
ConstantInt::get(CC->getType(), SrcPred)}; ConstantInt::get(CC->getType(), SrcPred)};
@ -1205,7 +1206,7 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
// If we can prove we don't have one of the special cases then we can use a // If we can prove we don't have one of the special cases then we can use a
// normal fma instead. // normal fma instead.
if (canSimplifyLegacyMulToMul(II, Op0, Op1, IC)) { if (canSimplifyLegacyMulToMul(II, Op0, Op1, IC)) {
II.setCalledOperand(Intrinsic::getDeclaration( II.setCalledOperand(Intrinsic::getOrInsertDeclaration(
II.getModule(), Intrinsic::fma, II.getType())); II.getModule(), Intrinsic::fma, II.getType()));
return &II; return &II;
} }
@ -1401,7 +1402,7 @@ static Value *simplifyAMDGCNMemoryIntrinsicDemanded(InstCombiner &IC,
Args[0] = IC.Builder.CreateShuffleVector(II.getOperand(0), EltMask); Args[0] = IC.Builder.CreateShuffleVector(II.getOperand(0), EltMask);
} }
Function *NewIntrin = Intrinsic::getDeclaration( Function *NewIntrin = Intrinsic::getOrInsertDeclaration(
II.getModule(), II.getIntrinsicID(), OverloadTys); II.getModule(), II.getIntrinsicID(), OverloadTys);
CallInst *NewCall = IC.Builder.CreateCall(NewIntrin, Args); CallInst *NewCall = IC.Builder.CreateCall(NewIntrin, Args);
NewCall->takeName(&II); NewCall->takeName(&II);

View File

@ -1555,8 +1555,8 @@ bool AMDGPUInstructionSelector::selectGroupStaticSize(MachineInstr &I) const {
MIB.addImm(MFI->getLDSSize()); MIB.addImm(MFI->getLDSSize());
} else { } else {
Module *M = MF->getFunction().getParent(); Module *M = MF->getFunction().getParent();
const GlobalValue *GV const GlobalValue *GV =
= Intrinsic::getDeclaration(M, Intrinsic::amdgcn_groupstaticsize); Intrinsic::getOrInsertDeclaration(M, Intrinsic::amdgcn_groupstaticsize);
MIB.addGlobalAddress(GV, 0, SIInstrInfo::MO_ABS32_LO); MIB.addGlobalAddress(GV, 0, SIInstrInfo::MO_ABS32_LO);
} }

View File

@ -753,7 +753,7 @@ bool AMDGPULibCalls::fold(CallInst *CI) {
CI->setArgOperand(1, SplatArg1); CI->setArgOperand(1, SplatArg1);
} }
CI->setCalledFunction(Intrinsic::getDeclaration( CI->setCalledFunction(Intrinsic::getOrInsertDeclaration(
CI->getModule(), Intrinsic::ldexp, CI->getModule(), Intrinsic::ldexp,
{CI->getType(), CI->getArgOperand(1)->getType()})); {CI->getType(), CI->getArgOperand(1)->getType()}));
return true; return true;
@ -1034,7 +1034,8 @@ bool AMDGPULibCalls::fold_pow(FPMathOperator *FPOp, IRBuilder<> &B,
// pown/pow ---> powr(fabs(x), y) | (x & ((int)y << 31)) // pown/pow ---> powr(fabs(x), y) | (x & ((int)y << 31))
FunctionCallee ExpExpr; FunctionCallee ExpExpr;
if (ShouldUseIntrinsic) if (ShouldUseIntrinsic)
ExpExpr = Intrinsic::getDeclaration(M, Intrinsic::exp2, {FPOp->getType()}); ExpExpr = Intrinsic::getOrInsertDeclaration(M, Intrinsic::exp2,
{FPOp->getType()});
else { else {
ExpExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_EXP2, FInfo)); ExpExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_EXP2, FInfo));
if (!ExpExpr) if (!ExpExpr)
@ -1108,8 +1109,8 @@ bool AMDGPULibCalls::fold_pow(FPMathOperator *FPOp, IRBuilder<> &B,
if (needlog) { if (needlog) {
FunctionCallee LogExpr; FunctionCallee LogExpr;
if (ShouldUseIntrinsic) { if (ShouldUseIntrinsic) {
LogExpr = LogExpr = Intrinsic::getOrInsertDeclaration(M, Intrinsic::log2,
Intrinsic::getDeclaration(M, Intrinsic::log2, {FPOp->getType()}); {FPOp->getType()});
} else { } else {
LogExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_LOG2, FInfo)); LogExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_LOG2, FInfo));
if (!LogExpr) if (!LogExpr)
@ -1298,8 +1299,8 @@ void AMDGPULibCalls::replaceLibCallWithSimpleIntrinsic(IRBuilder<> &B,
} }
} }
CI->setCalledFunction( CI->setCalledFunction(Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(CI->getModule(), IntrID, {CI->getType()})); CI->getModule(), IntrID, {CI->getType()}));
} }
bool AMDGPULibCalls::tryReplaceLibcallWithSimpleIntrinsic( bool AMDGPULibCalls::tryReplaceLibcallWithSimpleIntrinsic(

View File

@ -285,8 +285,8 @@ class AMDGPULowerModuleLDS {
BasicBlock *Entry = &Func->getEntryBlock(); BasicBlock *Entry = &Func->getEntryBlock();
IRBuilder<> Builder(Entry, Entry->getFirstNonPHIIt()); IRBuilder<> Builder(Entry, Entry->getFirstNonPHIIt());
Function *Decl = Function *Decl = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(Func->getParent(), Intrinsic::donothing, {}); Func->getParent(), Intrinsic::donothing, {});
Value *UseInstance[1] = { Value *UseInstance[1] = {
Builder.CreateConstInBoundsGEP1_32(SGV->getValueType(), SGV, 0)}; Builder.CreateConstInBoundsGEP1_32(SGV->getValueType(), SGV, 0)};
@ -529,8 +529,8 @@ public:
// block to spare deduplicating it later. // block to spare deduplicating it later.
auto [It, Inserted] = tableKernelIndexCache.try_emplace(F); auto [It, Inserted] = tableKernelIndexCache.try_emplace(F);
if (Inserted) { if (Inserted) {
Function *Decl = Function *Decl = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_lds_kernel_id, {}); &M, Intrinsic::amdgcn_lds_kernel_id, {});
auto InsertAt = F->getEntryBlock().getFirstNonPHIOrDbgOrAlloca(); auto InsertAt = F->getEntryBlock().getFirstNonPHIOrDbgOrAlloca();
IRBuilder<> Builder(&*InsertAt); IRBuilder<> Builder(&*InsertAt);

View File

@ -973,10 +973,10 @@ AMDGPUPromoteAllocaImpl::getLocalSizeYZ(IRBuilder<> &Builder) {
const AMDGPUSubtarget &ST = AMDGPUSubtarget::get(TM, F); const AMDGPUSubtarget &ST = AMDGPUSubtarget::get(TM, F);
if (!IsAMDHSA) { if (!IsAMDHSA) {
Function *LocalSizeYFn = Function *LocalSizeYFn = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(Mod, Intrinsic::r600_read_local_size_y); Mod, Intrinsic::r600_read_local_size_y);
Function *LocalSizeZFn = Function *LocalSizeZFn = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(Mod, Intrinsic::r600_read_local_size_z); Mod, Intrinsic::r600_read_local_size_z);
CallInst *LocalSizeY = Builder.CreateCall(LocalSizeYFn, {}); CallInst *LocalSizeY = Builder.CreateCall(LocalSizeYFn, {});
CallInst *LocalSizeZ = Builder.CreateCall(LocalSizeZFn, {}); CallInst *LocalSizeZ = Builder.CreateCall(LocalSizeZFn, {});
@ -1022,7 +1022,7 @@ AMDGPUPromoteAllocaImpl::getLocalSizeYZ(IRBuilder<> &Builder) {
// } hsa_kernel_dispatch_packet_t // } hsa_kernel_dispatch_packet_t
// //
Function *DispatchPtrFn = Function *DispatchPtrFn =
Intrinsic::getDeclaration(Mod, Intrinsic::amdgcn_dispatch_ptr); Intrinsic::getOrInsertDeclaration(Mod, Intrinsic::amdgcn_dispatch_ptr);
CallInst *DispatchPtr = Builder.CreateCall(DispatchPtrFn, {}); CallInst *DispatchPtr = Builder.CreateCall(DispatchPtrFn, {});
DispatchPtr->addRetAttr(Attribute::NoAlias); DispatchPtr->addRetAttr(Attribute::NoAlias);
@ -1082,7 +1082,7 @@ Value *AMDGPUPromoteAllocaImpl::getWorkitemID(IRBuilder<> &Builder,
llvm_unreachable("invalid dimension"); llvm_unreachable("invalid dimension");
} }
Function *WorkitemIdFn = Intrinsic::getDeclaration(Mod, IntrID); Function *WorkitemIdFn = Intrinsic::getOrInsertDeclaration(Mod, IntrID);
CallInst *CI = Builder.CreateCall(WorkitemIdFn); CallInst *CI = Builder.CreateCall(WorkitemIdFn);
ST.makeLIDRangeMetadata(CI); ST.makeLIDRangeMetadata(CI);
F->removeFnAttr(AttrName); F->removeFnAttr(AttrName);
@ -1564,7 +1564,7 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
continue; continue;
case Intrinsic::objectsize: { case Intrinsic::objectsize: {
Value *Src = Intr->getOperand(0); Value *Src = Intr->getOperand(0);
Function *ObjectSize = Intrinsic::getDeclaration( Function *ObjectSize = Intrinsic::getOrInsertDeclaration(
Mod, Intrinsic::objectsize, Mod, Intrinsic::objectsize,
{Intr->getType(), {Intr->getType(),
PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS)}); PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS)});

View File

@ -336,8 +336,8 @@ static void markUsedByKernel(Function *Func, GlobalVariable *SGV) {
BasicBlock *Entry = &Func->getEntryBlock(); BasicBlock *Entry = &Func->getEntryBlock();
IRBuilder<> Builder(Entry, Entry->getFirstNonPHIIt()); IRBuilder<> Builder(Entry, Entry->getFirstNonPHIIt());
Function *Decl = Function *Decl = Intrinsic::getOrInsertDeclaration(Func->getParent(),
Intrinsic::getDeclaration(Func->getParent(), Intrinsic::donothing, {}); Intrinsic::donothing, {});
Value *UseInstance[1] = { Value *UseInstance[1] = {
Builder.CreateConstInBoundsGEP1_32(SGV->getValueType(), SGV, 0)}; Builder.CreateConstInBoundsGEP1_32(SGV->getValueType(), SGV, 0)};
@ -922,7 +922,8 @@ void AMDGPUSwLowerLDS::lowerKernelLDSAccesses(Function *Func,
StringRef("__asan_free_impl"), StringRef("__asan_free_impl"),
FunctionType::get(IRB.getVoidTy(), {Int64Ty, Int64Ty}, false)); FunctionType::get(IRB.getVoidTy(), {Int64Ty, Int64Ty}, false));
Value *ReturnAddr = IRB.CreateCall( Value *ReturnAddr = IRB.CreateCall(
Intrinsic::getDeclaration(&M, Intrinsic::returnaddress), IRB.getInt32(0)); Intrinsic::getOrInsertDeclaration(&M, Intrinsic::returnaddress),
IRB.getInt32(0));
Value *RAPToInt = IRB.CreatePtrToInt(ReturnAddr, Int64Ty); Value *RAPToInt = IRB.CreatePtrToInt(ReturnAddr, Int64Ty);
Value *MallocPtrToInt = IRB.CreatePtrToInt(LoadMallocPtr, Int64Ty); Value *MallocPtrToInt = IRB.CreatePtrToInt(LoadMallocPtr, Int64Ty);
IRB.CreateCall(AsanFreeFunc, {MallocPtrToInt, RAPToInt}); IRB.CreateCall(AsanFreeFunc, {MallocPtrToInt, RAPToInt});
@ -1055,8 +1056,8 @@ void AMDGPUSwLowerLDS::lowerNonKernelLDSAccesses(
SetVector<Instruction *> LDSInstructions; SetVector<Instruction *> LDSInstructions;
getLDSMemoryInstructions(Func, LDSInstructions); getLDSMemoryInstructions(Func, LDSInstructions);
Function *Decl = Function *Decl = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_lds_kernel_id, {}); &M, Intrinsic::amdgcn_lds_kernel_id, {});
auto *KernelId = IRB.CreateCall(Decl, {}); auto *KernelId = IRB.CreateCall(Decl, {});
GlobalVariable *LDSBaseTable = NKLDSParams.LDSBaseTable; GlobalVariable *LDSBaseTable = NKLDSParams.LDSBaseTable;
GlobalVariable *LDSOffsetTable = NKLDSParams.LDSOffsetTable; GlobalVariable *LDSOffsetTable = NKLDSParams.LDSOffsetTable;

View File

@ -1112,8 +1112,8 @@ Value *GCNTTIImpl::rewriteIntrinsicWithAddressSpace(IntrinsicInst *II,
if (!AMDGPU::isExtendedGlobalAddrSpace(NewAS)) if (!AMDGPU::isExtendedGlobalAddrSpace(NewAS))
return nullptr; return nullptr;
Module *M = II->getModule(); Module *M = II->getModule();
Function *NewDecl = Intrinsic::getDeclaration(M, II->getIntrinsicID(), Function *NewDecl = Intrinsic::getOrInsertDeclaration(
{DestTy, SrcTy, DestTy}); M, II->getIntrinsicID(), {DestTy, SrcTy, DestTy});
II->setArgOperand(0, NewV); II->setArgOperand(0, NewV);
II->setCalledFunction(NewDecl); II->setCalledFunction(NewDecl);
return II; return II;

View File

@ -295,8 +295,8 @@ bool AMDGPUUnifyDivergentExitNodesImpl::run(Function &F, DominatorTree *DT,
// Remove and delete the unreachable inst. // Remove and delete the unreachable inst.
UnreachableBlock->getTerminator()->eraseFromParent(); UnreachableBlock->getTerminator()->eraseFromParent();
Function *UnreachableIntrin = Function *UnreachableIntrin = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(F.getParent(), Intrinsic::amdgcn_unreachable); F.getParent(), Intrinsic::amdgcn_unreachable);
// Insert a call to an intrinsic tracking that this is an unreachable // Insert a call to an intrinsic tracking that this is an unreachable
// point, in case we want to kill the active lanes or something later. // point, in case we want to kill the active lanes or something later.

View File

@ -117,13 +117,15 @@ void SIAnnotateControlFlow::initialize(Module &M, const GCNSubtarget &ST) {
BoolUndef = PoisonValue::get(Boolean); BoolUndef = PoisonValue::get(Boolean);
IntMaskZero = ConstantInt::get(IntMask, 0); IntMaskZero = ConstantInt::get(IntMask, 0);
If = Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_if, { IntMask }); If = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::amdgcn_if, {IntMask});
Else = Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_else, Else = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::amdgcn_else,
{ IntMask, IntMask }); {IntMask, IntMask});
IfBreak = Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_if_break, IfBreak = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::amdgcn_if_break,
{ IntMask }); {IntMask});
Loop = Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_loop, { IntMask }); Loop =
EndCf = Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_end_cf, { IntMask }); Intrinsic::getOrInsertDeclaration(&M, Intrinsic::amdgcn_loop, {IntMask});
EndCf = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::amdgcn_end_cf,
{IntMask});
} }
/// Is the branch condition uniform or did the StructurizeCFG pass /// Is the branch condition uniform or did the StructurizeCFG pass

View File

@ -21149,7 +21149,7 @@ Instruction *ARMTargetLowering::makeDMB(IRBuilderBase &Builder,
// Thumb1 and pre-v6 ARM mode use a libcall instead and should never get // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get
// here. // here.
if (Subtarget->hasV6Ops() && !Subtarget->isThumb()) { if (Subtarget->hasV6Ops() && !Subtarget->isThumb()) {
Function *MCR = Intrinsic::getDeclaration(M, Intrinsic::arm_mcr); Function *MCR = Intrinsic::getOrInsertDeclaration(M, Intrinsic::arm_mcr);
Value* args[6] = {Builder.getInt32(15), Builder.getInt32(0), Value* args[6] = {Builder.getInt32(15), Builder.getInt32(0),
Builder.getInt32(0), Builder.getInt32(7), Builder.getInt32(0), Builder.getInt32(7),
Builder.getInt32(10), Builder.getInt32(5)}; Builder.getInt32(10), Builder.getInt32(5)};
@ -21160,7 +21160,7 @@ Instruction *ARMTargetLowering::makeDMB(IRBuilderBase &Builder,
llvm_unreachable("makeDMB on a target so old that it has no barriers"); llvm_unreachable("makeDMB on a target so old that it has no barriers");
} }
} else { } else {
Function *DMB = Intrinsic::getDeclaration(M, Intrinsic::arm_dmb); Function *DMB = Intrinsic::getOrInsertDeclaration(M, Intrinsic::arm_dmb);
// Only a full system barrier exists in the M-class architectures. // Only a full system barrier exists in the M-class architectures.
Domain = Subtarget->isMClass() ? ARM_MB::SY : Domain; Domain = Subtarget->isMClass() ? ARM_MB::SY : Domain;
Constant *CDomain = Builder.getInt32(Domain); Constant *CDomain = Builder.getInt32(Domain);
@ -21417,7 +21417,7 @@ Value *ARMTargetLowering::emitLoadLinked(IRBuilderBase &Builder, Type *ValueTy,
if (ValueTy->getPrimitiveSizeInBits() == 64) { if (ValueTy->getPrimitiveSizeInBits() == 64) {
Intrinsic::ID Int = Intrinsic::ID Int =
IsAcquire ? Intrinsic::arm_ldaexd : Intrinsic::arm_ldrexd; IsAcquire ? Intrinsic::arm_ldaexd : Intrinsic::arm_ldrexd;
Function *Ldrex = Intrinsic::getDeclaration(M, Int); Function *Ldrex = Intrinsic::getOrInsertDeclaration(M, Int);
Value *LoHi = Builder.CreateCall(Ldrex, Addr, "lohi"); Value *LoHi = Builder.CreateCall(Ldrex, Addr, "lohi");
@ -21433,7 +21433,7 @@ Value *ARMTargetLowering::emitLoadLinked(IRBuilderBase &Builder, Type *ValueTy,
Type *Tys[] = { Addr->getType() }; Type *Tys[] = { Addr->getType() };
Intrinsic::ID Int = IsAcquire ? Intrinsic::arm_ldaex : Intrinsic::arm_ldrex; Intrinsic::ID Int = IsAcquire ? Intrinsic::arm_ldaex : Intrinsic::arm_ldrex;
Function *Ldrex = Intrinsic::getDeclaration(M, Int, Tys); Function *Ldrex = Intrinsic::getOrInsertDeclaration(M, Int, Tys);
CallInst *CI = Builder.CreateCall(Ldrex, Addr); CallInst *CI = Builder.CreateCall(Ldrex, Addr);
CI->addParamAttr( CI->addParamAttr(
@ -21446,7 +21446,8 @@ void ARMTargetLowering::emitAtomicCmpXchgNoStoreLLBalance(
if (!Subtarget->hasV7Ops()) if (!Subtarget->hasV7Ops())
return; return;
Module *M = Builder.GetInsertBlock()->getParent()->getParent(); Module *M = Builder.GetInsertBlock()->getParent()->getParent();
Builder.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::arm_clrex)); Builder.CreateCall(
Intrinsic::getOrInsertDeclaration(M, Intrinsic::arm_clrex));
} }
Value *ARMTargetLowering::emitStoreConditional(IRBuilderBase &Builder, Value *ARMTargetLowering::emitStoreConditional(IRBuilderBase &Builder,
@ -21461,7 +21462,7 @@ Value *ARMTargetLowering::emitStoreConditional(IRBuilderBase &Builder,
if (Val->getType()->getPrimitiveSizeInBits() == 64) { if (Val->getType()->getPrimitiveSizeInBits() == 64) {
Intrinsic::ID Int = Intrinsic::ID Int =
IsRelease ? Intrinsic::arm_stlexd : Intrinsic::arm_strexd; IsRelease ? Intrinsic::arm_stlexd : Intrinsic::arm_strexd;
Function *Strex = Intrinsic::getDeclaration(M, Int); Function *Strex = Intrinsic::getOrInsertDeclaration(M, Int);
Type *Int32Ty = Type::getInt32Ty(M->getContext()); Type *Int32Ty = Type::getInt32Ty(M->getContext());
Value *Lo = Builder.CreateTrunc(Val, Int32Ty, "lo"); Value *Lo = Builder.CreateTrunc(Val, Int32Ty, "lo");
@ -21473,7 +21474,7 @@ Value *ARMTargetLowering::emitStoreConditional(IRBuilderBase &Builder,
Intrinsic::ID Int = IsRelease ? Intrinsic::arm_stlex : Intrinsic::arm_strex; Intrinsic::ID Int = IsRelease ? Intrinsic::arm_stlex : Intrinsic::arm_strex;
Type *Tys[] = { Addr->getType() }; Type *Tys[] = { Addr->getType() };
Function *Strex = Intrinsic::getDeclaration(M, Int, Tys); Function *Strex = Intrinsic::getOrInsertDeclaration(M, Int, Tys);
CallInst *CI = Builder.CreateCall( CallInst *CI = Builder.CreateCall(
Strex, {Builder.CreateZExtOrBitCast( Strex, {Builder.CreateZExtOrBitCast(
@ -21601,8 +21602,8 @@ bool ARMTargetLowering::lowerInterleavedLoad(
static const Intrinsic::ID LoadInts[3] = {Intrinsic::arm_neon_vld2, static const Intrinsic::ID LoadInts[3] = {Intrinsic::arm_neon_vld2,
Intrinsic::arm_neon_vld3, Intrinsic::arm_neon_vld3,
Intrinsic::arm_neon_vld4}; Intrinsic::arm_neon_vld4};
Function *VldnFunc = Function *VldnFunc = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(LI->getModule(), LoadInts[Factor - 2], Tys); LI->getModule(), LoadInts[Factor - 2], Tys);
SmallVector<Value *, 2> Ops; SmallVector<Value *, 2> Ops;
Ops.push_back(BaseAddr); Ops.push_back(BaseAddr);
@ -21617,7 +21618,7 @@ bool ARMTargetLowering::lowerInterleavedLoad(
Type *PtrTy = Builder.getPtrTy(LI->getPointerAddressSpace()); Type *PtrTy = Builder.getPtrTy(LI->getPointerAddressSpace());
Type *Tys[] = {VecTy, PtrTy}; Type *Tys[] = {VecTy, PtrTy};
Function *VldnFunc = Function *VldnFunc =
Intrinsic::getDeclaration(LI->getModule(), LoadInts, Tys); Intrinsic::getOrInsertDeclaration(LI->getModule(), LoadInts, Tys);
SmallVector<Value *, 2> Ops; SmallVector<Value *, 2> Ops;
Ops.push_back(BaseAddr); Ops.push_back(BaseAddr);
@ -21762,7 +21763,7 @@ bool ARMTargetLowering::lowerInterleavedStore(StoreInst *SI,
Type *PtrTy = Builder.getPtrTy(SI->getPointerAddressSpace()); Type *PtrTy = Builder.getPtrTy(SI->getPointerAddressSpace());
Type *Tys[] = {PtrTy, SubVecTy}; Type *Tys[] = {PtrTy, SubVecTy};
Function *VstNFunc = Intrinsic::getDeclaration( Function *VstNFunc = Intrinsic::getOrInsertDeclaration(
SI->getModule(), StoreInts[Factor - 2], Tys); SI->getModule(), StoreInts[Factor - 2], Tys);
SmallVector<Value *, 6> Ops; SmallVector<Value *, 6> Ops;
@ -21778,7 +21779,7 @@ bool ARMTargetLowering::lowerInterleavedStore(StoreInst *SI,
Type *PtrTy = Builder.getPtrTy(SI->getPointerAddressSpace()); Type *PtrTy = Builder.getPtrTy(SI->getPointerAddressSpace());
Type *Tys[] = {PtrTy, SubVecTy}; Type *Tys[] = {PtrTy, SubVecTy};
Function *VstNFunc = Function *VstNFunc =
Intrinsic::getDeclaration(SI->getModule(), StoreInts, Tys); Intrinsic::getOrInsertDeclaration(SI->getModule(), StoreInts, Tys);
SmallVector<Value *, 6> Ops; SmallVector<Value *, 6> Ops;
Ops.push_back(BaseAddr); Ops.push_back(BaseAddr);

View File

@ -630,13 +630,14 @@ void ARMParallelDSP::InsertParallelMACs(Reduction &R) {
Value* Args[] = { WideLd0, WideLd1, Acc }; Value* Args[] = { WideLd0, WideLd1, Acc };
Function *SMLAD = nullptr; Function *SMLAD = nullptr;
if (Exchange) if (Exchange)
SMLAD = Acc->getType()->isIntegerTy(32) ? SMLAD =
Intrinsic::getDeclaration(M, Intrinsic::arm_smladx) : Acc->getType()->isIntegerTy(32)
Intrinsic::getDeclaration(M, Intrinsic::arm_smlaldx); ? Intrinsic::getOrInsertDeclaration(M, Intrinsic::arm_smladx)
: Intrinsic::getOrInsertDeclaration(M, Intrinsic::arm_smlaldx);
else else
SMLAD = Acc->getType()->isIntegerTy(32) ? SMLAD = Acc->getType()->isIntegerTy(32)
Intrinsic::getDeclaration(M, Intrinsic::arm_smlad) : ? Intrinsic::getOrInsertDeclaration(M, Intrinsic::arm_smlad)
Intrinsic::getDeclaration(M, Intrinsic::arm_smlald); : Intrinsic::getOrInsertDeclaration(M, Intrinsic::arm_smlald);
IRBuilder<NoFolder> Builder(InsertAfter->getParent(), IRBuilder<NoFolder> Builder(InsertAfter->getParent(),
BasicBlock::iterator(InsertAfter)); BasicBlock::iterator(InsertAfter));

View File

@ -401,7 +401,7 @@ void MVETailPredication::InsertVCTPIntrinsic(IntrinsicInst *ActiveLaneMask,
case 8: VCTPID = Intrinsic::arm_mve_vctp16; break; case 8: VCTPID = Intrinsic::arm_mve_vctp16; break;
case 16: VCTPID = Intrinsic::arm_mve_vctp8; break; case 16: VCTPID = Intrinsic::arm_mve_vctp8; break;
} }
Function *VCTP = Intrinsic::getDeclaration(M, VCTPID); Function *VCTP = Intrinsic::getOrInsertDeclaration(M, VCTPID);
Value *VCTPCall = Builder.CreateCall(VCTP, Processed); Value *VCTPCall = Builder.CreateCall(VCTP, Processed);
ActiveLaneMask->replaceAllUsesWith(VCTPCall); ActiveLaneMask->replaceAllUsesWith(VCTPCall);

View File

@ -103,7 +103,7 @@ uint32_t BPFCoreSharedInfo::SeqNum;
Instruction *BPFCoreSharedInfo::insertPassThrough(Module *M, BasicBlock *BB, Instruction *BPFCoreSharedInfo::insertPassThrough(Module *M, BasicBlock *BB,
Instruction *Input, Instruction *Input,
Instruction *Before) { Instruction *Before) {
Function *Fn = Intrinsic::getDeclaration( Function *Fn = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::bpf_passthrough, {Input->getType(), Input->getType()}); M, Intrinsic::bpf_passthrough, {Input->getType(), Input->getType()});
Constant *SeqNumVal = ConstantInt::get(Type::getInt32Ty(BB->getContext()), Constant *SeqNumVal = ConstantInt::get(Type::getInt32Ty(BB->getContext()),
BPFCoreSharedInfo::SeqNum++); BPFCoreSharedInfo::SeqNum++);

View File

@ -126,7 +126,7 @@ bool BPFAdjustOptImpl::adjustICmpToBuiltin() {
Constant *Opcode = Constant *Opcode =
ConstantInt::get(Type::getInt32Ty(BB.getContext()), Op); ConstantInt::get(Type::getInt32Ty(BB.getContext()), Op);
Function *Fn = Intrinsic::getDeclaration( Function *Fn = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::bpf_compare, {Op0->getType(), ConstOp1->getType()}); M, Intrinsic::bpf_compare, {Op0->getType(), ConstOp1->getType()});
auto *NewInst = CallInst::Create(Fn, {Opcode, Op0, ConstOp1}); auto *NewInst = CallInst::Create(Fn, {Opcode, Op0, ConstOp1});
NewInst->insertBefore(&I); NewInst->insertBefore(&I);

View File

@ -163,7 +163,7 @@ static CallInst *makeIntrinsicCall(Module *M,
ArrayRef<Type *> Types, ArrayRef<Type *> Types,
ArrayRef<Value *> Args) { ArrayRef<Value *> Args) {
Function *Fn = Intrinsic::getDeclaration(M, Intrinsic, Types); Function *Fn = Intrinsic::getOrInsertDeclaration(M, Intrinsic, Types);
return CallInst::Create(Fn, Args); return CallInst::Create(Fn, Args);
} }

View File

@ -134,8 +134,8 @@ public:
/// piecemeal way - we can add the casts in to avoid updating all of the uses /// piecemeal way - we can add the casts in to avoid updating all of the uses
/// or defs, and by the end all of the casts will be redundant. /// or defs, and by the end all of the casts will be redundant.
Value *createTmpHandleCast(Value *V, Type *Ty) { Value *createTmpHandleCast(Value *V, Type *Ty) {
Function *CastFn = Intrinsic::getDeclaration(&M, Intrinsic::dx_cast_handle, Function *CastFn = Intrinsic::getOrInsertDeclaration(
{Ty, V->getType()}); &M, Intrinsic::dx_cast_handle, {Ty, V->getType()});
CallInst *Cast = OpBuilder.getIRB().CreateCall(CastFn, {V}); CallInst *Cast = OpBuilder.getIRB().CreateCall(CastFn, {V});
CleanupCasts.push_back(Cast); CleanupCasts.push_back(Cast);
return Cast; return Cast;

View File

@ -212,7 +212,7 @@ bool HexagonGenExtract::convert(Instruction *In) {
Intrinsic::ID IntId = (BW == 32) ? Intrinsic::hexagon_S2_extractu Intrinsic::ID IntId = (BW == 32) ? Intrinsic::hexagon_S2_extractu
: Intrinsic::hexagon_S2_extractup; : Intrinsic::hexagon_S2_extractup;
Module *Mod = BB->getParent()->getParent(); Module *Mod = BB->getParent()->getParent();
Function *ExtF = Intrinsic::getDeclaration(Mod, IntId); Function *ExtF = Intrinsic::getOrInsertDeclaration(Mod, IntId);
Value *NewIn = IRB.CreateCall(ExtF, {BF, IRB.getInt32(W), IRB.getInt32(SR)}); Value *NewIn = IRB.CreateCall(ExtF, {BF, IRB.getInt32(W), IRB.getInt32(SR)});
if (SL != 0) if (SL != 0)
NewIn = IRB.CreateShl(NewIn, SL, CSL->getName()); NewIn = IRB.CreateShl(NewIn, SL, CSL->getName());

View File

@ -3865,7 +3865,7 @@ Value *HexagonTargetLowering::emitLoadLinked(IRBuilderBase &Builder,
assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic loads supported"); assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic loads supported");
Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_L2_loadw_locked Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_L2_loadw_locked
: Intrinsic::hexagon_L4_loadd_locked; : Intrinsic::hexagon_L4_loadd_locked;
Function *Fn = Intrinsic::getDeclaration(M, IntID); Function *Fn = Intrinsic::getOrInsertDeclaration(M, IntID);
Value *Call = Builder.CreateCall(Fn, Addr, "larx"); Value *Call = Builder.CreateCall(Fn, Addr, "larx");
@ -3886,7 +3886,7 @@ Value *HexagonTargetLowering::emitStoreConditional(IRBuilderBase &Builder,
assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic stores supported"); assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic stores supported");
Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_S2_storew_locked Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_S2_storew_locked
: Intrinsic::hexagon_S4_stored_locked; : Intrinsic::hexagon_S4_stored_locked;
Function *Fn = Intrinsic::getDeclaration(M, IntID); Function *Fn = Intrinsic::getOrInsertDeclaration(M, IntID);
Val = Builder.CreateBitCast(Val, CastTy); Val = Builder.CreateBitCast(Val, CastTy);

View File

@ -1532,7 +1532,8 @@ Value *PolynomialMultiplyRecognize::generate(BasicBlock::iterator At,
ParsedValues &PV) { ParsedValues &PV) {
IRBuilder<> B(&*At); IRBuilder<> B(&*At);
Module *M = At->getParent()->getParent()->getParent(); Module *M = At->getParent()->getParent()->getParent();
Function *PMF = Intrinsic::getDeclaration(M, Intrinsic::hexagon_M4_pmpyw); Function *PMF =
Intrinsic::getOrInsertDeclaration(M, Intrinsic::hexagon_M4_pmpyw);
Value *P = PV.P, *Q = PV.Q, *P0 = P; Value *P = PV.P, *Q = PV.Q, *P0 = P;
unsigned IC = PV.IterCount; unsigned IC = PV.IterCount;

View File

@ -2390,8 +2390,8 @@ auto HexagonVectorCombine::vralignb(IRBuilderBase &Builder, Value *Lo,
Type *Int64Ty = Type::getInt64Ty(F.getContext()); Type *Int64Ty = Type::getInt64Ty(F.getContext());
Value *Lo64 = Builder.CreateBitCast(Lo, Int64Ty, "cst"); Value *Lo64 = Builder.CreateBitCast(Lo, Int64Ty, "cst");
Value *Hi64 = Builder.CreateBitCast(Hi, Int64Ty, "cst"); Value *Hi64 = Builder.CreateBitCast(Hi, Int64Ty, "cst");
Function *FI = Intrinsic::getDeclaration(F.getParent(), Function *FI = Intrinsic::getOrInsertDeclaration(
Intrinsic::hexagon_S2_valignrb); F.getParent(), Intrinsic::hexagon_S2_valignrb);
Value *Call = Builder.CreateCall(FI, {Hi64, Lo64, Amt}, "cup"); Value *Call = Builder.CreateCall(FI, {Hi64, Lo64, Amt}, "cup");
return Builder.CreateBitCast(Call, Lo->getType(), "cst"); return Builder.CreateBitCast(Call, Lo->getType(), "cst");
} }
@ -2587,12 +2587,13 @@ auto HexagonVectorCombine::createHvxIntrinsic(IRBuilderBase &Builder,
unsigned HwLen = HST.getVectorLength(); unsigned HwLen = HST.getVectorLength();
Intrinsic::ID TC = HwLen == 64 ? Intrinsic::hexagon_V6_pred_typecast Intrinsic::ID TC = HwLen == 64 ? Intrinsic::hexagon_V6_pred_typecast
: Intrinsic::hexagon_V6_pred_typecast_128B; : Intrinsic::hexagon_V6_pred_typecast_128B;
Function *FI = Function *FI = Intrinsic::getOrInsertDeclaration(F.getParent(), TC,
Intrinsic::getDeclaration(F.getParent(), TC, {DestTy, Val->getType()}); {DestTy, Val->getType()});
return Builder.CreateCall(FI, {Val}, "cup"); return Builder.CreateCall(FI, {Val}, "cup");
}; };
Function *IntrFn = Intrinsic::getDeclaration(F.getParent(), IntID, ArgTys); Function *IntrFn =
Intrinsic::getOrInsertDeclaration(F.getParent(), IntID, ArgTys);
FunctionType *IntrTy = IntrFn->getFunctionType(); FunctionType *IntrTy = IntrFn->getFunctionType();
SmallVector<Value *, 4> IntrArgs; SmallVector<Value *, 4> IntrArgs;

View File

@ -5808,7 +5808,7 @@ Value *LoongArchTargetLowering::emitMaskedAtomicCmpXchgIntrinsic(
Mask = Builder.CreateSExt(Mask, Builder.getInt64Ty()); Mask = Builder.CreateSExt(Mask, Builder.getInt64Ty());
Type *Tys[] = {AlignedAddr->getType()}; Type *Tys[] = {AlignedAddr->getType()};
Function *MaskedCmpXchg = Function *MaskedCmpXchg =
Intrinsic::getDeclaration(CI->getModule(), CmpXchgIntrID, Tys); Intrinsic::getOrInsertDeclaration(CI->getModule(), CmpXchgIntrID, Tys);
Value *Result = Builder.CreateCall( Value *Result = Builder.CreateCall(
MaskedCmpXchg, {AlignedAddr, CmpVal, NewVal, Mask, FailureOrdering}); MaskedCmpXchg, {AlignedAddr, CmpVal, NewVal, Mask, FailureOrdering});
Result = Builder.CreateTrunc(Result, Builder.getInt32Ty()); Result = Builder.CreateTrunc(Result, Builder.getInt32Ty());
@ -5838,7 +5838,7 @@ Value *LoongArchTargetLowering::emitMaskedAtomicRMWIntrinsic(
Value *Ordering = Value *Ordering =
Builder.getIntN(GRLen, static_cast<uint64_t>(AI->getOrdering())); Builder.getIntN(GRLen, static_cast<uint64_t>(AI->getOrdering()));
Type *Tys[] = {AlignedAddr->getType()}; Type *Tys[] = {AlignedAddr->getType()};
Function *LlwOpScwLoop = Intrinsic::getDeclaration( Function *LlwOpScwLoop = Intrinsic::getOrInsertDeclaration(
AI->getModule(), AI->getModule(),
getIntrinsicForMaskedAtomicRMWBinOp(GRLen, AI->getOperation()), Tys); getIntrinsicForMaskedAtomicRMWBinOp(GRLen, AI->getOperation()), Tys);

View File

@ -282,7 +282,7 @@ static void convertToParamAS(Use *OldUse, Value *Param, bool HasCvtaParam,
[](Value *Addr, Instruction *OriginalUser) -> Value * { [](Value *Addr, Instruction *OriginalUser) -> Value * {
PointerType *ReturnTy = PointerType *ReturnTy =
PointerType::get(OriginalUser->getContext(), ADDRESS_SPACE_GENERIC); PointerType::get(OriginalUser->getContext(), ADDRESS_SPACE_GENERIC);
Function *CvtToGen = Intrinsic::getDeclaration( Function *CvtToGen = Intrinsic::getOrInsertDeclaration(
OriginalUser->getModule(), Intrinsic::nvvm_ptr_param_to_gen, OriginalUser->getModule(), Intrinsic::nvvm_ptr_param_to_gen,
{ReturnTy, PointerType::get(OriginalUser->getContext(), {ReturnTy, PointerType::get(OriginalUser->getContext(),
ADDRESS_SPACE_PARAM)}); ADDRESS_SPACE_PARAM)});

View File

@ -360,7 +360,8 @@ static Instruction *simplifyNvvmIntrinsic(IntrinsicInst *II, InstCombiner &IC) {
// type argument, equal to that of the nvvm intrinsic's argument. // type argument, equal to that of the nvvm intrinsic's argument.
Type *Tys[] = {II->getArgOperand(0)->getType()}; Type *Tys[] = {II->getArgOperand(0)->getType()};
return CallInst::Create( return CallInst::Create(
Intrinsic::getDeclaration(II->getModule(), *Action.IID, Tys), Args); Intrinsic::getOrInsertDeclaration(II->getModule(), *Action.IID, Tys),
Args);
} }
// Simplify to target-generic binary op. // Simplify to target-generic binary op.

View File

@ -12181,7 +12181,7 @@ void PPCTargetLowering::ReplaceNodeResults(SDNode *N,
static Instruction *callIntrinsic(IRBuilderBase &Builder, Intrinsic::ID Id) { static Instruction *callIntrinsic(IRBuilderBase &Builder, Intrinsic::ID Id) {
Module *M = Builder.GetInsertBlock()->getParent()->getParent(); Module *M = Builder.GetInsertBlock()->getParent()->getParent();
Function *Func = Intrinsic::getDeclaration(M, Id); Function *Func = Intrinsic::getOrInsertDeclaration(M, Id);
return Builder.CreateCall(Func, {}); return Builder.CreateCall(Func, {});
} }
@ -12206,7 +12206,7 @@ Instruction *PPCTargetLowering::emitTrailingFence(IRBuilderBase &Builder,
// and http://www.cl.cam.ac.uk/~pes20/cppppc/ for justification. // and http://www.cl.cam.ac.uk/~pes20/cppppc/ for justification.
if (isa<LoadInst>(Inst)) if (isa<LoadInst>(Inst))
return Builder.CreateCall( return Builder.CreateCall(
Intrinsic::getDeclaration( Intrinsic::getOrInsertDeclaration(
Builder.GetInsertBlock()->getParent()->getParent(), Builder.GetInsertBlock()->getParent()->getParent(),
Intrinsic::ppc_cfence, {Inst->getType()}), Intrinsic::ppc_cfence, {Inst->getType()}),
{Inst}); {Inst});
@ -19005,7 +19005,7 @@ Value *PPCTargetLowering::emitMaskedAtomicRMWIntrinsic(
Module *M = Builder.GetInsertBlock()->getParent()->getParent(); Module *M = Builder.GetInsertBlock()->getParent()->getParent();
Type *ValTy = Incr->getType(); Type *ValTy = Incr->getType();
assert(ValTy->getPrimitiveSizeInBits() == 128); assert(ValTy->getPrimitiveSizeInBits() == 128);
Function *RMW = Intrinsic::getDeclaration( Function *RMW = Intrinsic::getOrInsertDeclaration(
M, getIntrinsicForAtomicRMWBinOp128(AI->getOperation())); M, getIntrinsicForAtomicRMWBinOp128(AI->getOperation()));
Type *Int64Ty = Type::getInt64Ty(M->getContext()); Type *Int64Ty = Type::getInt64Ty(M->getContext());
Value *IncrLo = Builder.CreateTrunc(Incr, Int64Ty, "incr_lo"); Value *IncrLo = Builder.CreateTrunc(Incr, Int64Ty, "incr_lo");
@ -19028,7 +19028,7 @@ Value *PPCTargetLowering::emitMaskedAtomicCmpXchgIntrinsic(
Type *ValTy = CmpVal->getType(); Type *ValTy = CmpVal->getType();
assert(ValTy->getPrimitiveSizeInBits() == 128); assert(ValTy->getPrimitiveSizeInBits() == 128);
Function *IntCmpXchg = Function *IntCmpXchg =
Intrinsic::getDeclaration(M, Intrinsic::ppc_cmpxchg_i128); Intrinsic::getOrInsertDeclaration(M, Intrinsic::ppc_cmpxchg_i128);
Type *Int64Ty = Type::getInt64Ty(M->getContext()); Type *Int64Ty = Type::getInt64Ty(M->getContext());
Value *CmpLo = Builder.CreateTrunc(CmpVal, Int64Ty, "cmp_lo"); Value *CmpLo = Builder.CreateTrunc(CmpVal, Int64Ty, "cmp_lo");
Value *CmpHi = Value *CmpHi =

View File

@ -123,7 +123,7 @@ bool PPCLowerMASSVEntries::handlePowSpecialCases(CallInst *CI, Function &Func,
return false; return false;
CI->setCalledFunction( CI->setCalledFunction(
Intrinsic::getDeclaration(&M, Intrinsic::pow, CI->getType())); Intrinsic::getOrInsertDeclaration(&M, Intrinsic::pow, CI->getType()));
return true; return true;
} }

View File

@ -20608,7 +20608,7 @@ Value *RISCVTargetLowering::emitMaskedAtomicRMWIntrinsic(
Value *Ordering = Value *Ordering =
Builder.getIntN(XLen, static_cast<uint64_t>(AI->getOrdering())); Builder.getIntN(XLen, static_cast<uint64_t>(AI->getOrdering()));
Type *Tys[] = {AlignedAddr->getType()}; Type *Tys[] = {AlignedAddr->getType()};
Function *LrwOpScwLoop = Intrinsic::getDeclaration( Function *LrwOpScwLoop = Intrinsic::getOrInsertDeclaration(
AI->getModule(), AI->getModule(),
getIntrinsicForMaskedAtomicRMWBinOp(XLen, AI->getOperation()), Tys); getIntrinsicForMaskedAtomicRMWBinOp(XLen, AI->getOperation()), Tys);
@ -20672,7 +20672,7 @@ Value *RISCVTargetLowering::emitMaskedAtomicCmpXchgIntrinsic(
} }
Type *Tys[] = {AlignedAddr->getType()}; Type *Tys[] = {AlignedAddr->getType()};
Function *MaskedCmpXchg = Function *MaskedCmpXchg =
Intrinsic::getDeclaration(CI->getModule(), CmpXchgIntrID, Tys); Intrinsic::getOrInsertDeclaration(CI->getModule(), CmpXchgIntrID, Tys);
Value *Result = Builder.CreateCall( Value *Result = Builder.CreateCall(
MaskedCmpXchg, {AlignedAddr, CmpVal, NewVal, Mask, Ordering}); MaskedCmpXchg, {AlignedAddr, CmpVal, NewVal, Mask, Ordering});
if (XLen == 64) if (XLen == 64)
@ -21170,7 +21170,7 @@ bool RISCVTargetLowering::preferScalarizeSplat(SDNode *N) const {
static Value *useTpOffset(IRBuilderBase &IRB, unsigned Offset) { static Value *useTpOffset(IRBuilderBase &IRB, unsigned Offset) {
Module *M = IRB.GetInsertBlock()->getModule(); Module *M = IRB.GetInsertBlock()->getModule();
Function *ThreadPointerFunc = Function *ThreadPointerFunc =
Intrinsic::getDeclaration(M, Intrinsic::thread_pointer); Intrinsic::getOrInsertDeclaration(M, Intrinsic::thread_pointer);
return IRB.CreateConstGEP1_32(IRB.getInt8Ty(), return IRB.CreateConstGEP1_32(IRB.getInt8Ty(),
IRB.CreateCall(ThreadPointerFunc), Offset); IRB.CreateCall(ThreadPointerFunc), Offset);
} }
@ -21287,9 +21287,9 @@ bool RISCVTargetLowering::lowerInterleavedLoad(
auto *XLenTy = Type::getIntNTy(LI->getContext(), Subtarget.getXLen()); auto *XLenTy = Type::getIntNTy(LI->getContext(), Subtarget.getXLen());
Function *VlsegNFunc = Function *VlsegNFunc = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(LI->getModule(), FixedVlsegIntrIds[Factor - 2], LI->getModule(), FixedVlsegIntrIds[Factor - 2],
{VTy, LI->getPointerOperandType(), XLenTy}); {VTy, LI->getPointerOperandType(), XLenTy});
Value *VL = ConstantInt::get(XLenTy, VTy->getNumElements()); Value *VL = ConstantInt::get(XLenTy, VTy->getNumElements());
@ -21341,9 +21341,9 @@ bool RISCVTargetLowering::lowerInterleavedStore(StoreInst *SI,
auto *XLenTy = Type::getIntNTy(SI->getContext(), Subtarget.getXLen()); auto *XLenTy = Type::getIntNTy(SI->getContext(), Subtarget.getXLen());
Function *VssegNFunc = Function *VssegNFunc = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(SI->getModule(), FixedVssegIntrIds[Factor - 2], SI->getModule(), FixedVssegIntrIds[Factor - 2],
{VTy, SI->getPointerOperandType(), XLenTy}); {VTy, SI->getPointerOperandType(), XLenTy});
auto Mask = SVI->getShuffleMask(); auto Mask = SVI->getShuffleMask();
SmallVector<Value *, 10> Ops; SmallVector<Value *, 10> Ops;
@ -21388,7 +21388,7 @@ bool RISCVTargetLowering::lowerDeinterleaveIntrinsicToLoad(
Type *XLenTy = Type::getIntNTy(LI->getContext(), Subtarget.getXLen()); Type *XLenTy = Type::getIntNTy(LI->getContext(), Subtarget.getXLen());
if (auto *FVTy = dyn_cast<FixedVectorType>(ResVTy)) { if (auto *FVTy = dyn_cast<FixedVectorType>(ResVTy)) {
Function *VlsegNFunc = Intrinsic::getDeclaration( Function *VlsegNFunc = Intrinsic::getOrInsertDeclaration(
LI->getModule(), FixedVlsegIntrIds[Factor - 2], LI->getModule(), FixedVlsegIntrIds[Factor - 2],
{ResVTy, LI->getPointerOperandType(), XLenTy}); {ResVTy, LI->getPointerOperandType(), XLenTy});
Value *VL = ConstantInt::get(XLenTy, FVTy->getNumElements()); Value *VL = ConstantInt::get(XLenTy, FVTy->getNumElements());
@ -21408,7 +21408,7 @@ bool RISCVTargetLowering::lowerDeinterleaveIntrinsicToLoad(
NumElts * SEW / 8), NumElts * SEW / 8),
Factor); Factor);
Function *VlsegNFunc = Intrinsic::getDeclaration( Function *VlsegNFunc = Intrinsic::getOrInsertDeclaration(
LI->getModule(), IntrIds[Factor - 2], {VecTupTy, XLenTy}); LI->getModule(), IntrIds[Factor - 2], {VecTupTy, XLenTy});
Value *VL = Constant::getAllOnesValue(XLenTy); Value *VL = Constant::getAllOnesValue(XLenTy);
@ -21418,7 +21418,7 @@ bool RISCVTargetLowering::lowerDeinterleaveIntrinsicToLoad(
SmallVector<Type *, 2> AggrTypes{Factor, ResVTy}; SmallVector<Type *, 2> AggrTypes{Factor, ResVTy};
Return = PoisonValue::get(StructType::get(LI->getContext(), AggrTypes)); Return = PoisonValue::get(StructType::get(LI->getContext(), AggrTypes));
Function *VecExtractFunc = Intrinsic::getDeclaration( Function *VecExtractFunc = Intrinsic::getOrInsertDeclaration(
LI->getModule(), Intrinsic::riscv_tuple_extract, {ResVTy, VecTupTy}); LI->getModule(), Intrinsic::riscv_tuple_extract, {ResVTy, VecTupTy});
for (unsigned i = 0; i < Factor; ++i) { for (unsigned i = 0; i < Factor; ++i) {
Value *VecExtract = Value *VecExtract =
@ -21454,7 +21454,7 @@ bool RISCVTargetLowering::lowerInterleaveIntrinsicToStore(
Type *XLenTy = Type::getIntNTy(SI->getContext(), Subtarget.getXLen()); Type *XLenTy = Type::getIntNTy(SI->getContext(), Subtarget.getXLen());
if (auto *FVTy = dyn_cast<FixedVectorType>(InVTy)) { if (auto *FVTy = dyn_cast<FixedVectorType>(InVTy)) {
Function *VssegNFunc = Intrinsic::getDeclaration( Function *VssegNFunc = Intrinsic::getOrInsertDeclaration(
SI->getModule(), FixedVssegIntrIds[Factor - 2], SI->getModule(), FixedVssegIntrIds[Factor - 2],
{InVTy, SI->getPointerOperandType(), XLenTy}); {InVTy, SI->getPointerOperandType(), XLenTy});
Value *VL = ConstantInt::get(XLenTy, FVTy->getNumElements()); Value *VL = ConstantInt::get(XLenTy, FVTy->getNumElements());
@ -21475,12 +21475,12 @@ bool RISCVTargetLowering::lowerInterleaveIntrinsicToStore(
NumElts * SEW / 8), NumElts * SEW / 8),
Factor); Factor);
Function *VssegNFunc = Intrinsic::getDeclaration( Function *VssegNFunc = Intrinsic::getOrInsertDeclaration(
SI->getModule(), IntrIds[Factor - 2], {VecTupTy, XLenTy}); SI->getModule(), IntrIds[Factor - 2], {VecTupTy, XLenTy});
Value *VL = Constant::getAllOnesValue(XLenTy); Value *VL = Constant::getAllOnesValue(XLenTy);
Function *VecInsertFunc = Intrinsic::getDeclaration( Function *VecInsertFunc = Intrinsic::getOrInsertDeclaration(
SI->getModule(), Intrinsic::riscv_tuple_insert, {VecTupTy, InVTy}); SI->getModule(), Intrinsic::riscv_tuple_insert, {VecTupTy, InVTy});
Value *StoredVal = PoisonValue::get(VecTupTy); Value *StoredVal = PoisonValue::get(VecTupTy);
for (unsigned i = 0; i < Factor; ++i) for (unsigned i = 0; i < Factor; ++i)

View File

@ -353,11 +353,11 @@ static void lowerExpectAssume(IntrinsicInst *II) {
// We need to lower this into a builtin and then the builtin into a SPIR-V // We need to lower this into a builtin and then the builtin into a SPIR-V
// instruction. // instruction.
if (II->getIntrinsicID() == Intrinsic::assume) { if (II->getIntrinsicID() == Intrinsic::assume) {
Function *F = Intrinsic::getDeclaration( Function *F = Intrinsic::getOrInsertDeclaration(
II->getModule(), Intrinsic::SPVIntrinsics::spv_assume); II->getModule(), Intrinsic::SPVIntrinsics::spv_assume);
II->setCalledFunction(F); II->setCalledFunction(F);
} else if (II->getIntrinsicID() == Intrinsic::expect) { } else if (II->getIntrinsicID() == Intrinsic::expect) {
Function *F = Intrinsic::getDeclaration( Function *F = Intrinsic::getOrInsertDeclaration(
II->getModule(), Intrinsic::SPVIntrinsics::spv_expect, II->getModule(), Intrinsic::SPVIntrinsics::spv_expect,
{II->getOperand(0)->getType()}); {II->getOperand(0)->getType()});
II->setCalledFunction(F); II->setCalledFunction(F);
@ -372,12 +372,12 @@ static bool toSpvOverloadedIntrinsic(IntrinsicInst *II, Intrinsic::ID NewID,
ArrayRef<unsigned> OpNos) { ArrayRef<unsigned> OpNos) {
Function *F = nullptr; Function *F = nullptr;
if (OpNos.empty()) { if (OpNos.empty()) {
F = Intrinsic::getDeclaration(II->getModule(), NewID); F = Intrinsic::getOrInsertDeclaration(II->getModule(), NewID);
} else { } else {
SmallVector<Type *, 4> Tys; SmallVector<Type *, 4> Tys;
for (unsigned OpNo : OpNos) for (unsigned OpNo : OpNos)
Tys.push_back(II->getOperand(OpNo)->getType()); Tys.push_back(II->getOperand(OpNo)->getType());
F = Intrinsic::getDeclaration(II->getModule(), NewID, Tys); F = Intrinsic::getOrInsertDeclaration(II->getModule(), NewID, Tys);
} }
II->setCalledFunction(F); II->setCalledFunction(F);
return true; return true;

View File

@ -366,8 +366,8 @@ bool SystemZTDCPass::runOnFunction(Function &F) {
if (!Worthy) if (!Worthy)
continue; continue;
// Call the intrinsic, compare result with 0. // Call the intrinsic, compare result with 0.
Function *TDCFunc = Function *TDCFunc = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(&M, Intrinsic::s390_tdc, V->getType()); &M, Intrinsic::s390_tdc, V->getType());
IRBuilder<> IRB(I); IRBuilder<> IRB(I);
Value *MaskVal = ConstantInt::get(Type::getInt64Ty(Ctx), Mask); Value *MaskVal = ConstantInt::get(Type::getInt64Ty(Ctx), Mask);
Instruction *TDC = IRB.CreateCall(TDCFunc, {V, MaskVal}); Instruction *TDC = IRB.CreateCall(TDCFunc, {V, MaskVal});

View File

@ -1016,7 +1016,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module &M) {
// wasm.catch() will be lowered down to wasm 'catch' instruction in // wasm.catch() will be lowered down to wasm 'catch' instruction in
// instruction selection. // instruction selection.
CatchF = Intrinsic::getDeclaration(&M, Intrinsic::wasm_catch); CatchF = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::wasm_catch);
// Type for struct __WasmLongjmpArgs // Type for struct __WasmLongjmpArgs
LongjmpArgsTy = StructType::get(Int8PtrTy, // env LongjmpArgsTy = StructType::get(Int8PtrTy, // env
Int32Ty // val Int32Ty // val

View File

@ -72,7 +72,7 @@ bool WebAssemblyLowerRefTypesIntPtrConv::runOnFunction(Function &F) {
I->replaceAllUsesWith(U); I->replaceAllUsesWith(U);
Function *TrapIntrin = Function *TrapIntrin =
Intrinsic::getDeclaration(F.getParent(), Intrinsic::debugtrap); Intrinsic::getOrInsertDeclaration(F.getParent(), Intrinsic::debugtrap);
CallInst::Create(TrapIntrin, {}, "", I->getIterator()); CallInst::Create(TrapIntrin, {}, "", I->getIterator());
worklist.insert(&*I); worklist.insert(&*I);

View File

@ -31163,12 +31163,14 @@ void X86TargetLowering::emitBitTestAtomicRMWIntrinsic(AtomicRMWInst *AI) const {
if (BitTested.second == ConstantBit || BitTested.second == NotConstantBit) { if (BitTested.second == ConstantBit || BitTested.second == NotConstantBit) {
auto *C = cast<ConstantInt>(I->getOperand(I->getOperand(0) == AI ? 1 : 0)); auto *C = cast<ConstantInt>(I->getOperand(I->getOperand(0) == AI ? 1 : 0));
BitTest = Intrinsic::getDeclaration(AI->getModule(), IID_C, AI->getType()); BitTest = Intrinsic::getOrInsertDeclaration(AI->getModule(), IID_C,
AI->getType());
unsigned Imm = llvm::countr_zero(C->getZExtValue()); unsigned Imm = llvm::countr_zero(C->getZExtValue());
Result = Builder.CreateCall(BitTest, {Addr, Builder.getInt8(Imm)}); Result = Builder.CreateCall(BitTest, {Addr, Builder.getInt8(Imm)});
} else { } else {
BitTest = Intrinsic::getDeclaration(AI->getModule(), IID_I, AI->getType()); BitTest = Intrinsic::getOrInsertDeclaration(AI->getModule(), IID_I,
AI->getType());
assert(BitTested.second == ShiftBit || BitTested.second == NotShiftBit); assert(BitTested.second == ShiftBit || BitTested.second == NotShiftBit);
@ -31328,7 +31330,7 @@ void X86TargetLowering::emitCmpArithAtomicRMWIntrinsic(
break; break;
} }
Function *CmpArith = Function *CmpArith =
Intrinsic::getDeclaration(AI->getModule(), IID, AI->getType()); Intrinsic::getOrInsertDeclaration(AI->getModule(), IID, AI->getType());
Value *Addr = Builder.CreatePointerCast(AI->getPointerOperand(), Value *Addr = Builder.CreatePointerCast(AI->getPointerOperand(),
PointerType::getUnqual(Ctx)); PointerType::getUnqual(Ctx));
Value *Call = Builder.CreateCall( Value *Call = Builder.CreateCall(
@ -31444,7 +31446,7 @@ X86TargetLowering::lowerIdempotentRMWIntoFencedLoad(AtomicRMWInst *AI) const {
return nullptr; return nullptr;
Function *MFence = Function *MFence =
llvm::Intrinsic::getDeclaration(M, Intrinsic::x86_sse2_mfence); llvm::Intrinsic::getOrInsertDeclaration(M, Intrinsic::x86_sse2_mfence);
Builder.CreateCall(MFence, {}); Builder.CreateCall(MFence, {});
// Finally we can emit the atomic load. // Finally we can emit the atomic load.

View File

@ -1876,7 +1876,8 @@ static Value *simplifyX86extrq(IntrinsicInst &II, Value *Op0,
if (II.getIntrinsicID() == Intrinsic::x86_sse4a_extrq) { if (II.getIntrinsicID() == Intrinsic::x86_sse4a_extrq) {
Value *Args[] = {Op0, CILength, CIIndex}; Value *Args[] = {Op0, CILength, CIIndex};
Module *M = II.getModule(); Module *M = II.getModule();
Function *F = Intrinsic::getDeclaration(M, Intrinsic::x86_sse4a_extrqi); Function *F =
Intrinsic::getOrInsertDeclaration(M, Intrinsic::x86_sse4a_extrqi);
return Builder.CreateCall(F, Args); return Builder.CreateCall(F, Args);
} }
} }
@ -1975,7 +1976,8 @@ static Value *simplifyX86insertq(IntrinsicInst &II, Value *Op0, Value *Op1,
Value *Args[] = {Op0, Op1, CILength, CIIndex}; Value *Args[] = {Op0, Op1, CILength, CIIndex};
Module *M = II.getModule(); Module *M = II.getModule();
Function *F = Intrinsic::getDeclaration(M, Intrinsic::x86_sse4a_insertqi); Function *F =
Intrinsic::getOrInsertDeclaration(M, Intrinsic::x86_sse4a_insertqi);
return Builder.CreateCall(F, Args); return Builder.CreateCall(F, Args);
} }

View File

@ -278,7 +278,7 @@ bool X86PartialReduction::trySADReplacement(Instruction *Op) {
IntrinsicNumElts = 16; IntrinsicNumElts = 16;
} }
Function *PSADBWFn = Intrinsic::getDeclaration(Op->getModule(), IID); Function *PSADBWFn = Intrinsic::getOrInsertDeclaration(Op->getModule(), IID);
if (NumElts < 16) { if (NumElts < 16) {
// Pad input with zeroes. // Pad input with zeroes.

View File

@ -334,7 +334,7 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
if (UseStackGuard) { if (UseStackGuard) {
Value *Val = Builder.CreateLoad(Int32Ty, Cookie); Value *Val = Builder.CreateLoad(Int32Ty, Cookie);
Value *FrameAddr = Builder.CreateCall( Value *FrameAddr = Builder.CreateCall(
Intrinsic::getDeclaration( Intrinsic::getOrInsertDeclaration(
TheModule, Intrinsic::frameaddress, TheModule, Intrinsic::frameaddress,
Builder.getPtrTy( Builder.getPtrTy(
TheModule->getDataLayout().getAllocaAddrSpace())), TheModule->getDataLayout().getAllocaAddrSpace())),
@ -370,7 +370,7 @@ void WinEHStatePass::emitExceptionRegistrationRecord(Function *F) {
Value *WinEHStatePass::emitEHLSDA(IRBuilder<> &Builder, Function *F) { Value *WinEHStatePass::emitEHLSDA(IRBuilder<> &Builder, Function *F) {
return Builder.CreateCall( return Builder.CreateCall(
Intrinsic::getDeclaration(TheModule, Intrinsic::x86_seh_lsda), F); Intrinsic::getOrInsertDeclaration(TheModule, Intrinsic::x86_seh_lsda), F);
} }
/// Generate a thunk that puts the LSDA of ParentFunc in EAX and then calls /// Generate a thunk that puts the LSDA of ParentFunc in EAX and then calls
@ -624,17 +624,17 @@ void WinEHStatePass::addStateStores(Function &F, WinEHFuncInfo &FuncInfo) {
// that it can recover the original frame pointer. // that it can recover the original frame pointer.
IRBuilder<> Builder(RegNode->getNextNode()); IRBuilder<> Builder(RegNode->getNextNode());
Value *RegNodeI8 = Builder.CreateBitCast(RegNode, Builder.getPtrTy()); Value *RegNodeI8 = Builder.CreateBitCast(RegNode, Builder.getPtrTy());
Builder.CreateCall( Builder.CreateCall(Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(TheModule, Intrinsic::x86_seh_ehregnode), TheModule, Intrinsic::x86_seh_ehregnode),
{RegNodeI8}); {RegNodeI8});
if (EHGuardNode) { if (EHGuardNode) {
IRBuilder<> Builder(EHGuardNode->getNextNode()); IRBuilder<> Builder(EHGuardNode->getNextNode());
Value *EHGuardNodeI8 = Value *EHGuardNodeI8 =
Builder.CreateBitCast(EHGuardNode, Builder.getPtrTy()); Builder.CreateBitCast(EHGuardNode, Builder.getPtrTy());
Builder.CreateCall( Builder.CreateCall(Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(TheModule, Intrinsic::x86_seh_ehguard), TheModule, Intrinsic::x86_seh_ehguard),
{EHGuardNodeI8}); {EHGuardNodeI8});
} }
// Calculate state numbers. // Calculate state numbers.

View File

@ -157,8 +157,8 @@ bool XCoreLowerThreadLocal::lowerGlobal(GlobalVariable *GV) {
for (User *U : Users) { for (User *U : Users) {
Instruction *Inst = cast<Instruction>(U); Instruction *Inst = cast<Instruction>(U);
IRBuilder<> Builder(Inst); IRBuilder<> Builder(Inst);
Function *GetID = Intrinsic::getDeclaration(GV->getParent(), Function *GetID = Intrinsic::getOrInsertDeclaration(GV->getParent(),
Intrinsic::xcore_getid); Intrinsic::xcore_getid);
Value *ThreadID = Builder.CreateCall(GetID, {}); Value *ThreadID = Builder.CreateCall(GetID, {});
Value *Addr = Builder.CreateInBoundsGEP(NewGV->getValueType(), NewGV, Value *Addr = Builder.CreateInBoundsGEP(NewGV->getValueType(), NewGV,
{Builder.getInt64(0), ThreadID}); {Builder.getInt64(0), ThreadID});

View File

@ -172,7 +172,8 @@ static bool foldGuardedFunnelShift(Instruction &I, const DominatorTree &DT) {
// %cond = phi i32 [ %fsh, %FunnelBB ], [ %ShVal0, %GuardBB ] // %cond = phi i32 [ %fsh, %FunnelBB ], [ %ShVal0, %GuardBB ]
// --> // -->
// llvm.fshl.i32(i32 %ShVal0, i32 %ShVal1, i32 %ShAmt) // llvm.fshl.i32(i32 %ShVal0, i32 %ShVal1, i32 %ShAmt)
Function *F = Intrinsic::getDeclaration(Phi.getModule(), IID, Phi.getType()); Function *F =
Intrinsic::getOrInsertDeclaration(Phi.getModule(), IID, Phi.getType());
Phi.replaceAllUsesWith(Builder.CreateCall(F, {ShVal0, ShVal1, ShAmt})); Phi.replaceAllUsesWith(Builder.CreateCall(F, {ShVal0, ShVal1, ShAmt}));
return true; return true;
} }
@ -331,7 +332,7 @@ static bool tryToRecognizePopCount(Instruction &I) {
m_SpecificInt(Mask55)))) { m_SpecificInt(Mask55)))) {
LLVM_DEBUG(dbgs() << "Recognized popcount intrinsic\n"); LLVM_DEBUG(dbgs() << "Recognized popcount intrinsic\n");
IRBuilder<> Builder(&I); IRBuilder<> Builder(&I);
Function *Func = Intrinsic::getDeclaration( Function *Func = Intrinsic::getOrInsertDeclaration(
I.getModule(), Intrinsic::ctpop, I.getType()); I.getModule(), Intrinsic::ctpop, I.getType());
I.replaceAllUsesWith(Builder.CreateCall(Func, {Root})); I.replaceAllUsesWith(Builder.CreateCall(Func, {Root}));
++NumPopCountRecognized; ++NumPopCountRecognized;
@ -398,8 +399,8 @@ static bool tryToFPToSat(Instruction &I, TargetTransformInfo &TTI) {
return false; return false;
IRBuilder<> Builder(&I); IRBuilder<> Builder(&I);
Function *Fn = Intrinsic::getDeclaration(I.getModule(), Intrinsic::fptosi_sat, Function *Fn = Intrinsic::getOrInsertDeclaration(
{SatTy, FpTy}); I.getModule(), Intrinsic::fptosi_sat, {SatTy, FpTy});
Value *Sat = Builder.CreateCall(Fn, In); Value *Sat = Builder.CreateCall(Fn, In);
I.replaceAllUsesWith(Builder.CreateSExt(Sat, IntTy)); I.replaceAllUsesWith(Builder.CreateSExt(Sat, IntTy));
return true; return true;
@ -431,7 +432,7 @@ static bool foldSqrt(CallInst *Call, LibFunc Func, TargetTransformInfo &TTI,
IRBuilderBase::FastMathFlagGuard Guard(Builder); IRBuilderBase::FastMathFlagGuard Guard(Builder);
Builder.setFastMathFlags(Call->getFastMathFlags()); Builder.setFastMathFlags(Call->getFastMathFlags());
Function *Sqrt = Intrinsic::getDeclaration(M, Intrinsic::sqrt, Ty); Function *Sqrt = Intrinsic::getOrInsertDeclaration(M, Intrinsic::sqrt, Ty);
Value *NewSqrt = Builder.CreateCall(Sqrt, Arg, "sqrt"); Value *NewSqrt = Builder.CreateCall(Sqrt, Arg, "sqrt");
Call->replaceAllUsesWith(NewSqrt); Call->replaceAllUsesWith(NewSqrt);

View File

@ -52,7 +52,8 @@ coro::LowererBase::LowererBase(Module &M)
CallInst *coro::LowererBase::makeSubFnCall(Value *Arg, int Index, CallInst *coro::LowererBase::makeSubFnCall(Value *Arg, int Index,
Instruction *InsertPt) { Instruction *InsertPt) {
auto *IndexVal = ConstantInt::get(Type::getInt8Ty(Context), Index); auto *IndexVal = ConstantInt::get(Type::getInt8Ty(Context), Index);
auto *Fn = Intrinsic::getDeclaration(&TheModule, Intrinsic::coro_subfn_addr); auto *Fn =
Intrinsic::getOrInsertDeclaration(&TheModule, Intrinsic::coro_subfn_addr);
assert(Index >= CoroSubFnInst::IndexFirst && assert(Index >= CoroSubFnInst::IndexFirst &&
Index < CoroSubFnInst::IndexLast && Index < CoroSubFnInst::IndexLast &&
@ -183,7 +184,7 @@ void coro::suppressCoroAllocs(LLVMContext &Context,
static CoroSaveInst *createCoroSave(CoroBeginInst *CoroBegin, static CoroSaveInst *createCoroSave(CoroBeginInst *CoroBegin,
CoroSuspendInst *SuspendInst) { CoroSuspendInst *SuspendInst) {
Module *M = SuspendInst->getModule(); Module *M = SuspendInst->getModule();
auto *Fn = Intrinsic::getDeclaration(M, Intrinsic::coro_save); auto *Fn = Intrinsic::getOrInsertDeclaration(M, Intrinsic::coro_save);
auto *SaveInst = cast<CoroSaveInst>( auto *SaveInst = cast<CoroSaveInst>(
CallInst::Create(Fn, CoroBegin, "", SuspendInst->getIterator())); CallInst::Create(Fn, CoroBegin, "", SuspendInst->getIterator()));
assert(!SuspendInst->getCoroSave()); assert(!SuspendInst->getCoroSave());

View File

@ -125,7 +125,8 @@ void CrossDSOCFI::buildCFICheck(Module &M) {
ConstantInt *CaseTypeId = ConstantInt::get(Type::getInt64Ty(Ctx), TypeId); ConstantInt *CaseTypeId = ConstantInt::get(Type::getInt64Ty(Ctx), TypeId);
BasicBlock *TestBB = BasicBlock::Create(Ctx, "test", F); BasicBlock *TestBB = BasicBlock::Create(Ctx, "test", F);
IRBuilder<> IRBTest(TestBB); IRBuilder<> IRBTest(TestBB);
Function *BitsetTestFn = Intrinsic::getDeclaration(&M, Intrinsic::type_test); Function *BitsetTestFn =
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::type_test);
Value *Test = IRBTest.CreateCall( Value *Test = IRBTest.CreateCall(
BitsetTestFn, {&Addr, MetadataAsValue::get( BitsetTestFn, {&Addr, MetadataAsValue::get(

View File

@ -401,7 +401,7 @@ void SampleProfileProber::instrumentOneFunc(Function &F, TargetMachine *TM) {
assert(Builder.GetInsertPoint() != BB->end() && assert(Builder.GetInsertPoint() != BB->end() &&
"Cannot get the probing point"); "Cannot get the probing point");
Function *ProbeFn = Function *ProbeFn =
llvm::Intrinsic::getDeclaration(M, Intrinsic::pseudoprobe); llvm::Intrinsic::getOrInsertDeclaration(M, Intrinsic::pseudoprobe);
Value *Args[] = {Builder.getInt64(Guid), Builder.getInt64(Index), Value *Args[] = {Builder.getInt64(Guid), Builder.getInt64(Index),
Builder.getInt32(0), Builder.getInt32(0),
Builder.getInt64(PseudoProbeFullDistributionFactor)}; Builder.getInt64(PseudoProbeFullDistributionFactor)};

View File

@ -856,7 +856,7 @@ void llvm::updatePublicTypeTestCalls(Module &M,
return; return;
if (hasWholeProgramVisibility(WholeProgramVisibilityEnabledInLTO)) { if (hasWholeProgramVisibility(WholeProgramVisibilityEnabledInLTO)) {
Function *TypeTestFunc = Function *TypeTestFunc =
Intrinsic::getDeclaration(&M, Intrinsic::type_test); Intrinsic::getOrInsertDeclaration(&M, Intrinsic::type_test);
for (Use &U : make_early_inc_range(PublicTypeTestFunc->uses())) { for (Use &U : make_early_inc_range(PublicTypeTestFunc->uses())) {
auto *CI = cast<CallInst>(U.getUser()); auto *CI = cast<CallInst>(U.getUser());
auto *NewCI = CallInst::Create( auto *NewCI = CallInst::Create(
@ -1187,7 +1187,8 @@ void DevirtModule::applySingleImplDevirt(VTableSlotInfo &SlotInfo,
Instruction *ThenTerm = Instruction *ThenTerm =
SplitBlockAndInsertIfThen(Cond, &CB, /*Unreachable=*/false); SplitBlockAndInsertIfThen(Cond, &CB, /*Unreachable=*/false);
Builder.SetInsertPoint(ThenTerm); Builder.SetInsertPoint(ThenTerm);
Function *TrapFn = Intrinsic::getDeclaration(&M, Intrinsic::debugtrap); Function *TrapFn =
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::debugtrap);
auto *CallTrap = Builder.CreateCall(TrapFn); auto *CallTrap = Builder.CreateCall(TrapFn);
CallTrap->setDebugLoc(CB.getDebugLoc()); CallTrap->setDebugLoc(CB.getDebugLoc());
} }
@ -1434,8 +1435,8 @@ void DevirtModule::tryICallBranchFunnel(
} }
BasicBlock *BB = BasicBlock::Create(M.getContext(), "", JT, nullptr); BasicBlock *BB = BasicBlock::Create(M.getContext(), "", JT, nullptr);
Function *Intr = Function *Intr = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(&M, llvm::Intrinsic::icall_branch_funnel, {}); &M, llvm::Intrinsic::icall_branch_funnel, {});
auto *CI = CallInst::Create(Intr, JTArgs, "", BB); auto *CI = CallInst::Create(Intr, JTArgs, "", BB);
CI->setTailCallKind(CallInst::TCK_MustTail); CI->setTailCallKind(CallInst::TCK_MustTail);
@ -2026,7 +2027,8 @@ void DevirtModule::scanTypeTestUsers(
} }
void DevirtModule::scanTypeCheckedLoadUsers(Function *TypeCheckedLoadFunc) { void DevirtModule::scanTypeCheckedLoadUsers(Function *TypeCheckedLoadFunc) {
Function *TypeTestFunc = Intrinsic::getDeclaration(&M, Intrinsic::type_test); Function *TypeTestFunc =
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::type_test);
for (Use &U : llvm::make_early_inc_range(TypeCheckedLoadFunc->uses())) { for (Use &U : llvm::make_early_inc_range(TypeCheckedLoadFunc->uses())) {
auto *CI = dyn_cast<CallInst>(U.getUser()); auto *CI = dyn_cast<CallInst>(U.getUser());

View File

@ -1232,7 +1232,8 @@ static Instruction *foldToUnsignedSaturatedAdd(BinaryOperator &I) {
assert(I.getOpcode() == Instruction::Add && "Expecting add instruction"); assert(I.getOpcode() == Instruction::Add && "Expecting add instruction");
Type *Ty = I.getType(); Type *Ty = I.getType();
auto getUAddSat = [&]() { auto getUAddSat = [&]() {
return Intrinsic::getDeclaration(I.getModule(), Intrinsic::uadd_sat, Ty); return Intrinsic::getOrInsertDeclaration(I.getModule(), Intrinsic::uadd_sat,
Ty);
}; };
// add (umin X, ~Y), Y --> uaddsat X, Y // add (umin X, ~Y), Y --> uaddsat X, Y
@ -2127,7 +2128,7 @@ static Instruction *foldSubOfMinMax(BinaryOperator &I,
if (match(Op0, m_c_Add(m_Specific(X), m_Specific(Y))) && if (match(Op0, m_c_Add(m_Specific(X), m_Specific(Y))) &&
(Op0->hasOneUse() || Op1->hasOneUse())) { (Op0->hasOneUse() || Op1->hasOneUse())) {
Intrinsic::ID InvID = getInverseMinMaxIntrinsic(MinMax->getIntrinsicID()); Intrinsic::ID InvID = getInverseMinMaxIntrinsic(MinMax->getIntrinsicID());
Function *F = Intrinsic::getDeclaration(I.getModule(), InvID, Ty); Function *F = Intrinsic::getOrInsertDeclaration(I.getModule(), InvID, Ty);
return CallInst::Create(F, {X, Y}); return CallInst::Create(F, {X, Y});
} }
@ -2150,7 +2151,7 @@ static Instruction *foldSubOfMinMax(BinaryOperator &I,
if (MinMax->isSigned() && match(Y, m_ZeroInt()) && if (MinMax->isSigned() && match(Y, m_ZeroInt()) &&
match(X, m_NSWSub(m_Specific(Op0), m_Value(Z)))) { match(X, m_NSWSub(m_Specific(Op0), m_Value(Z)))) {
Intrinsic::ID InvID = getInverseMinMaxIntrinsic(MinMax->getIntrinsicID()); Intrinsic::ID InvID = getInverseMinMaxIntrinsic(MinMax->getIntrinsicID());
Function *F = Intrinsic::getDeclaration(I.getModule(), InvID, Ty); Function *F = Intrinsic::getOrInsertDeclaration(I.getModule(), InvID, Ty);
return CallInst::Create(F, {Op0, Z}); return CallInst::Create(F, {Op0, Z});
} }

View File

@ -2269,7 +2269,8 @@ foldBitwiseLogicWithIntrinsics(BinaryOperator &I,
Builder.CreateBinOp(I.getOpcode(), X->getOperand(0), Y->getOperand(0)); Builder.CreateBinOp(I.getOpcode(), X->getOperand(0), Y->getOperand(0));
Value *NewOp1 = Value *NewOp1 =
Builder.CreateBinOp(I.getOpcode(), X->getOperand(1), Y->getOperand(1)); Builder.CreateBinOp(I.getOpcode(), X->getOperand(1), Y->getOperand(1));
Function *F = Intrinsic::getDeclaration(I.getModule(), IID, I.getType()); Function *F =
Intrinsic::getOrInsertDeclaration(I.getModule(), IID, I.getType());
return CallInst::Create(F, {NewOp0, NewOp1, X->getOperand(2)}); return CallInst::Create(F, {NewOp0, NewOp1, X->getOperand(2)});
} }
case Intrinsic::bswap: case Intrinsic::bswap:
@ -2280,7 +2281,8 @@ foldBitwiseLogicWithIntrinsics(BinaryOperator &I,
: ConstantInt::get(I.getType(), IID == Intrinsic::bswap : ConstantInt::get(I.getType(), IID == Intrinsic::bswap
? RHSC->byteSwap() ? RHSC->byteSwap()
: RHSC->reverseBits())); : RHSC->reverseBits()));
Function *F = Intrinsic::getDeclaration(I.getModule(), IID, I.getType()); Function *F =
Intrinsic::getOrInsertDeclaration(I.getModule(), IID, I.getType());
return CallInst::Create(F, {NewOp0}); return CallInst::Create(F, {NewOp0});
} }
default: default:
@ -3056,7 +3058,8 @@ InstCombinerImpl::convertOrOfShiftsToFunnelShift(Instruction &Or) {
static Instruction *matchFunnelShift(Instruction &Or, InstCombinerImpl &IC) { static Instruction *matchFunnelShift(Instruction &Or, InstCombinerImpl &IC) {
if (auto Opt = IC.convertOrOfShiftsToFunnelShift(Or)) { if (auto Opt = IC.convertOrOfShiftsToFunnelShift(Or)) {
auto [IID, FShiftArgs] = *Opt; auto [IID, FShiftArgs] = *Opt;
Function *F = Intrinsic::getDeclaration(Or.getModule(), IID, Or.getType()); Function *F =
Intrinsic::getOrInsertDeclaration(Or.getModule(), IID, Or.getType());
return CallInst::Create(F, FShiftArgs); return CallInst::Create(F, FShiftArgs);
} }
@ -3095,7 +3098,7 @@ static Instruction *matchOrConcat(Instruction &Or,
Value *NewUpper = Builder.CreateZExt(Hi, Ty); Value *NewUpper = Builder.CreateZExt(Hi, Ty);
NewUpper = Builder.CreateShl(NewUpper, HalfWidth); NewUpper = Builder.CreateShl(NewUpper, HalfWidth);
Value *BinOp = Builder.CreateOr(NewLower, NewUpper); Value *BinOp = Builder.CreateOr(NewLower, NewUpper);
Function *F = Intrinsic::getDeclaration(Or.getModule(), id, Ty); Function *F = Intrinsic::getOrInsertDeclaration(Or.getModule(), id, Ty);
return Builder.CreateCall(F, BinOp); return Builder.CreateCall(F, BinOp);
}; };
@ -4803,7 +4806,8 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) {
match(II->getArgOperand(1), m_One()) && match(II->getArgOperand(1), m_One()) &&
isKnownToBeAPowerOfTwo(II->getArgOperand(0), /*OrZero */ true)) { isKnownToBeAPowerOfTwo(II->getArgOperand(0), /*OrZero */ true)) {
IID = (IID == Intrinsic::ctlz) ? Intrinsic::cttz : Intrinsic::ctlz; IID = (IID == Intrinsic::ctlz) ? Intrinsic::cttz : Intrinsic::ctlz;
Function *F = Intrinsic::getDeclaration(II->getModule(), IID, Ty); Function *F =
Intrinsic::getOrInsertDeclaration(II->getModule(), IID, Ty);
return CallInst::Create(F, {II->getArgOperand(0), Builder.getTrue()}); return CallInst::Create(F, {II->getArgOperand(0), Builder.getTrue()});
} }
} }

View File

@ -488,7 +488,8 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) {
// cttz(bitreverse(x)) -> ctlz(x) // cttz(bitreverse(x)) -> ctlz(x)
if (match(Op0, m_BitReverse(m_Value(X)))) { if (match(Op0, m_BitReverse(m_Value(X)))) {
Intrinsic::ID ID = IsTZ ? Intrinsic::ctlz : Intrinsic::cttz; Intrinsic::ID ID = IsTZ ? Intrinsic::ctlz : Intrinsic::cttz;
Function *F = Intrinsic::getDeclaration(II.getModule(), ID, II.getType()); Function *F =
Intrinsic::getOrInsertDeclaration(II.getModule(), ID, II.getType());
return CallInst::Create(F, {X, II.getArgOperand(1)}); return CallInst::Create(F, {X, II.getArgOperand(1)});
} }
@ -647,7 +648,7 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) {
if (Op0->hasOneUse() && if (Op0->hasOneUse() &&
match(Op0, m_c_Or(m_Value(X), m_Neg(m_Deferred(X))))) { match(Op0, m_c_Or(m_Value(X), m_Neg(m_Deferred(X))))) {
Function *F = Function *F =
Intrinsic::getDeclaration(II.getModule(), Intrinsic::cttz, Ty); Intrinsic::getOrInsertDeclaration(II.getModule(), Intrinsic::cttz, Ty);
auto *Cttz = IC.Builder.CreateCall(F, {X, IC.Builder.getFalse()}); auto *Cttz = IC.Builder.CreateCall(F, {X, IC.Builder.getFalse()});
auto *Bw = ConstantInt::get(Ty, APInt(BitWidth, BitWidth)); auto *Bw = ConstantInt::get(Ty, APInt(BitWidth, BitWidth));
return IC.replaceInstUsesWith(II, IC.Builder.CreateSub(Bw, Cttz)); return IC.replaceInstUsesWith(II, IC.Builder.CreateSub(Bw, Cttz));
@ -657,7 +658,7 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) {
if (match(Op0, if (match(Op0,
m_c_And(m_Not(m_Value(X)), m_Add(m_Deferred(X), m_AllOnes())))) { m_c_And(m_Not(m_Value(X)), m_Add(m_Deferred(X), m_AllOnes())))) {
Function *F = Function *F =
Intrinsic::getDeclaration(II.getModule(), Intrinsic::cttz, Ty); Intrinsic::getOrInsertDeclaration(II.getModule(), Intrinsic::cttz, Ty);
return CallInst::Create(F, {X, IC.Builder.getFalse()}); return CallInst::Create(F, {X, IC.Builder.getFalse()});
} }
@ -1181,7 +1182,8 @@ Instruction *InstCombinerImpl::matchSAddSubSat(IntrinsicInst &MinMax1) {
return nullptr; return nullptr;
// Finally create and return the sat intrinsic, truncated to the new type // Finally create and return the sat intrinsic, truncated to the new type
Function *F = Intrinsic::getDeclaration(MinMax1.getModule(), IntrinsicID, NewTy); Function *F = Intrinsic::getOrInsertDeclaration(MinMax1.getModule(),
IntrinsicID, NewTy);
Value *AT = Builder.CreateTrunc(AddSub->getOperand(0), NewTy); Value *AT = Builder.CreateTrunc(AddSub->getOperand(0), NewTy);
Value *BT = Builder.CreateTrunc(AddSub->getOperand(1), NewTy); Value *BT = Builder.CreateTrunc(AddSub->getOperand(1), NewTy);
Value *Sat = Builder.CreateCall(F, {AT, BT}); Value *Sat = Builder.CreateCall(F, {AT, BT});
@ -1286,8 +1288,8 @@ reassociateMinMaxWithConstantInOperand(IntrinsicInst *II,
return nullptr; return nullptr;
// max (max X, C), Y --> max (max X, Y), C // max (max X, C), Y --> max (max X, Y), C
Function *MinMax = Function *MinMax = Intrinsic::getOrInsertDeclaration(II->getModule(),
Intrinsic::getDeclaration(II->getModule(), MinMaxID, II->getType()); MinMaxID, II->getType());
Value *NewInner = Builder.CreateBinaryIntrinsic(MinMaxID, X, Y); Value *NewInner = Builder.CreateBinaryIntrinsic(MinMaxID, X, Y);
NewInner->takeName(Inner); NewInner->takeName(Inner);
return CallInst::Create(MinMax, {NewInner, C}); return CallInst::Create(MinMax, {NewInner, C});
@ -1346,7 +1348,8 @@ static Instruction *factorizeMinMaxTree(IntrinsicInst *II) {
return nullptr; return nullptr;
Module *Mod = II->getModule(); Module *Mod = II->getModule();
Function *MinMax = Intrinsic::getDeclaration(Mod, MinMaxID, II->getType()); Function *MinMax =
Intrinsic::getOrInsertDeclaration(Mod, MinMaxID, II->getType());
return CallInst::Create(MinMax, { MinMaxOp, ThirdOp }); return CallInst::Create(MinMax, { MinMaxOp, ThirdOp });
} }
@ -1571,7 +1574,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
Type *Tys[3] = { CI.getArgOperand(0)->getType(), Type *Tys[3] = { CI.getArgOperand(0)->getType(),
CI.getArgOperand(1)->getType(), CI.getArgOperand(1)->getType(),
CI.getArgOperand(2)->getType() }; CI.getArgOperand(2)->getType() };
CI.setCalledFunction(Intrinsic::getDeclaration(M, MemCpyID, Tys)); CI.setCalledFunction(
Intrinsic::getOrInsertDeclaration(M, MemCpyID, Tys));
Changed = true; Changed = true;
} }
} }
@ -2095,7 +2099,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
Constant *LeftShiftC = ConstantExpr::getSub(WidthC, ShAmtC); Constant *LeftShiftC = ConstantExpr::getSub(WidthC, ShAmtC);
Module *Mod = II->getModule(); Module *Mod = II->getModule();
Function *Fshl = Intrinsic::getDeclaration(Mod, Intrinsic::fshl, Ty); Function *Fshl =
Intrinsic::getOrInsertDeclaration(Mod, Intrinsic::fshl, Ty);
return CallInst::Create(Fshl, { Op0, Op1, LeftShiftC }); return CallInst::Create(Fshl, { Op0, Op1, LeftShiftC });
} }
assert(IID == Intrinsic::fshl && assert(IID == Intrinsic::fshl &&
@ -2115,7 +2120,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
// fshl i16 X, X, 8 --> bswap i16 X (reduce to more-specific form) // fshl i16 X, X, 8 --> bswap i16 X (reduce to more-specific form)
if (Op0 == Op1 && BitWidth == 16 && match(ShAmtC, m_SpecificInt(8))) { if (Op0 == Op1 && BitWidth == 16 && match(ShAmtC, m_SpecificInt(8))) {
Module *Mod = II->getModule(); Module *Mod = II->getModule();
Function *Bswap = Intrinsic::getDeclaration(Mod, Intrinsic::bswap, Ty); Function *Bswap =
Intrinsic::getOrInsertDeclaration(Mod, Intrinsic::bswap, Ty);
return CallInst::Create(Bswap, { Op0 }); return CallInst::Create(Bswap, { Op0 });
} }
if (Instruction *BitOp = if (Instruction *BitOp =
@ -2824,7 +2830,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
CallArgs.push_back(II->getArgOperand(4)); CallArgs.push_back(II->getArgOperand(4));
} }
Function *NewFn = Intrinsic::getDeclaration(II->getModule(), NewIntrin); Function *NewFn =
Intrinsic::getOrInsertDeclaration(II->getModule(), NewIntrin);
return CallInst::Create(NewFn, CallArgs); return CallInst::Create(NewFn, CallArgs);
} }
case Intrinsic::arm_neon_vtbl1: case Intrinsic::arm_neon_vtbl1:

View File

@ -95,8 +95,8 @@ Value *InstCombinerImpl::EvaluateInDifferentType(Value *V, Type *Ty,
default: default:
llvm_unreachable("Unsupported call!"); llvm_unreachable("Unsupported call!");
case Intrinsic::vscale: { case Intrinsic::vscale: {
Function *Fn = Function *Fn = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(I->getModule(), Intrinsic::vscale, {Ty}); I->getModule(), Intrinsic::vscale, {Ty});
Res = CallInst::Create(Fn->getFunctionType(), Fn); Res = CallInst::Create(Fn->getFunctionType(), Fn);
break; break;
} }
@ -600,7 +600,8 @@ Instruction *InstCombinerImpl::narrowFunnelShift(TruncInst &Trunc) {
if (ShVal0 != ShVal1) if (ShVal0 != ShVal1)
Y = Builder.CreateTrunc(ShVal1, DestTy); Y = Builder.CreateTrunc(ShVal1, DestTy);
Intrinsic::ID IID = IsFshl ? Intrinsic::fshl : Intrinsic::fshr; Intrinsic::ID IID = IsFshl ? Intrinsic::fshl : Intrinsic::fshr;
Function *F = Intrinsic::getDeclaration(Trunc.getModule(), IID, DestTy); Function *F =
Intrinsic::getOrInsertDeclaration(Trunc.getModule(), IID, DestTy);
return CallInst::Create(F, {X, Y, NarrowShAmt}); return CallInst::Create(F, {X, Y, NarrowShAmt});
} }
@ -1912,8 +1913,8 @@ Instruction *InstCombinerImpl::visitFPTrunc(FPTruncInst &FPT) {
// Do unary FP operation on smaller type. // Do unary FP operation on smaller type.
// (fptrunc (fabs x)) -> (fabs (fptrunc x)) // (fptrunc (fabs x)) -> (fabs (fptrunc x))
Value *InnerTrunc = Builder.CreateFPTrunc(Src, Ty); Value *InnerTrunc = Builder.CreateFPTrunc(Src, Ty);
Function *Overload = Intrinsic::getDeclaration(FPT.getModule(), Function *Overload = Intrinsic::getOrInsertDeclaration(
II->getIntrinsicID(), Ty); FPT.getModule(), II->getIntrinsicID(), Ty);
SmallVector<OperandBundleDef, 1> OpBundles; SmallVector<OperandBundleDef, 1> OpBundles;
II->getOperandBundlesAsDefs(OpBundles); II->getOperandBundlesAsDefs(OpBundles);
CallInst *NewCI = CallInst *NewCI =
@ -2855,8 +2856,8 @@ Instruction *InstCombinerImpl::visitBitCast(BitCastInst &CI) {
if (IntrinsicNum != 0) { if (IntrinsicNum != 0) {
assert(ShufOp0->getType() == SrcTy && "Unexpected shuffle mask"); assert(ShufOp0->getType() == SrcTy && "Unexpected shuffle mask");
assert(match(ShufOp1, m_Undef()) && "Unexpected shuffle op"); assert(match(ShufOp1, m_Undef()) && "Unexpected shuffle op");
Function *BswapOrBitreverse = Function *BswapOrBitreverse = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(CI.getModule(), IntrinsicNum, DestTy); CI.getModule(), IntrinsicNum, DestTy);
Value *ScalarX = Builder.CreateBitCast(ShufOp0, DestTy); Value *ScalarX = Builder.CreateBitCast(ShufOp0, DestTy);
return CallInst::Create(BswapOrBitreverse, {ScalarX}); return CallInst::Create(BswapOrBitreverse, {ScalarX});
} }

View File

@ -1125,7 +1125,7 @@ static Instruction *processUGT_ADDCST_ADD(ICmpInst &I, Value *A, Value *B,
// use the sadd_with_overflow intrinsic to efficiently compute both the // use the sadd_with_overflow intrinsic to efficiently compute both the
// result and the overflow bit. // result and the overflow bit.
Type *NewType = IntegerType::get(OrigAdd->getContext(), NewWidth); Type *NewType = IntegerType::get(OrigAdd->getContext(), NewWidth);
Function *F = Intrinsic::getDeclaration( Function *F = Intrinsic::getOrInsertDeclaration(
I.getModule(), Intrinsic::sadd_with_overflow, NewType); I.getModule(), Intrinsic::sadd_with_overflow, NewType);
InstCombiner::BuilderTy &Builder = IC.Builder; InstCombiner::BuilderTy &Builder = IC.Builder;
@ -4790,11 +4790,11 @@ Value *InstCombinerImpl::foldMultiplicationOverflowCheck(ICmpInst &I) {
if (MulHadOtherUses) if (MulHadOtherUses)
Builder.SetInsertPoint(Mul); Builder.SetInsertPoint(Mul);
Function *F = Intrinsic::getDeclaration(I.getModule(), Function *F = Intrinsic::getOrInsertDeclaration(
Div->getOpcode() == Instruction::UDiv I.getModule(),
? Intrinsic::umul_with_overflow Div->getOpcode() == Instruction::UDiv ? Intrinsic::umul_with_overflow
: Intrinsic::smul_with_overflow, : Intrinsic::smul_with_overflow,
X->getType()); X->getType());
CallInst *Call = Builder.CreateCall(F, {X, Y}, "mul"); CallInst *Call = Builder.CreateCall(F, {X, Y}, "mul");
// If the multiplication was used elsewhere, to ensure that we don't leave // If the multiplication was used elsewhere, to ensure that we don't leave
@ -6334,7 +6334,7 @@ static Instruction *processUMulZExtIdiom(ICmpInst &I, Value *MulVal,
MulA = Builder.CreateZExt(A, MulType); MulA = Builder.CreateZExt(A, MulType);
if (WidthB < MulWidth) if (WidthB < MulWidth)
MulB = Builder.CreateZExt(B, MulType); MulB = Builder.CreateZExt(B, MulType);
Function *F = Intrinsic::getDeclaration( Function *F = Intrinsic::getOrInsertDeclaration(
I.getModule(), Intrinsic::umul_with_overflow, MulType); I.getModule(), Intrinsic::umul_with_overflow, MulType);
CallInst *Call = Builder.CreateCall(F, {MulA, MulB}, "umul"); CallInst *Call = Builder.CreateCall(F, {MulA, MulB}, "umul");
IC.addToWorklist(MulInstr); IC.addToWorklist(MulInstr);
@ -7121,8 +7121,8 @@ static Instruction *foldVectorCmp(CmpInst &Cmp,
if (auto *I = dyn_cast<Instruction>(V)) if (auto *I = dyn_cast<Instruction>(V))
I->copyIRFlags(&Cmp); I->copyIRFlags(&Cmp);
Module *M = Cmp.getModule(); Module *M = Cmp.getModule();
Function *F = Function *F = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::vector_reverse, V->getType()); M, Intrinsic::vector_reverse, V->getType());
return CallInst::Create(F, V); return CallInst::Create(F, V);
}; };

View File

@ -1148,8 +1148,8 @@ static Instruction *foldSelectCtlzToCttz(ICmpInst *ICI, Value *TrueVal,
if (!match(II->getOperand(0), m_c_And(m_Specific(X), m_Neg(m_Specific(X))))) if (!match(II->getOperand(0), m_c_And(m_Specific(X), m_Neg(m_Specific(X)))))
return nullptr; return nullptr;
Function *F = Intrinsic::getDeclaration(II->getModule(), Intrinsic::cttz, Function *F = Intrinsic::getOrInsertDeclaration(
II->getType()); II->getModule(), Intrinsic::cttz, II->getType());
return CallInst::Create(F, {X, II->getArgOperand(1)}); return CallInst::Create(F, {X, II->getArgOperand(1)});
} }
@ -2242,8 +2242,8 @@ foldOverflowingAddSubSelect(SelectInst &SI, InstCombiner::BuilderTy &Builder) {
else else
return nullptr; return nullptr;
Function *F = Function *F = Intrinsic::getOrInsertDeclaration(SI.getModule(),
Intrinsic::getDeclaration(SI.getModule(), NewIntrinsicID, SI.getType()); NewIntrinsicID, SI.getType());
return CallInst::Create(F, {X, Y}); return CallInst::Create(F, {X, Y});
} }
@ -2537,7 +2537,8 @@ static Instruction *foldSelectFunnelShift(SelectInst &Sel,
// This is a funnel/rotate that avoids shift-by-bitwidth UB in a suboptimal way. // This is a funnel/rotate that avoids shift-by-bitwidth UB in a suboptimal way.
// Convert to funnel shift intrinsic. // Convert to funnel shift intrinsic.
Intrinsic::ID IID = IsFshl ? Intrinsic::fshl : Intrinsic::fshr; Intrinsic::ID IID = IsFshl ? Intrinsic::fshl : Intrinsic::fshr;
Function *F = Intrinsic::getDeclaration(Sel.getModule(), IID, Sel.getType()); Function *F =
Intrinsic::getOrInsertDeclaration(Sel.getModule(), IID, Sel.getType());
ShAmt = Builder.CreateZExt(ShAmt, Sel.getType()); ShAmt = Builder.CreateZExt(ShAmt, Sel.getType());
return CallInst::Create(F, { SV0, SV1, ShAmt }); return CallInst::Create(F, { SV0, SV1, ShAmt });
} }
@ -2580,8 +2581,8 @@ static Instruction *foldSelectToCopysign(SelectInst &Sel,
// Canonicalize the magnitude argument as the positive constant since we do // Canonicalize the magnitude argument as the positive constant since we do
// not care about its sign. // not care about its sign.
Value *MagArg = ConstantFP::get(SelType, abs(*TC)); Value *MagArg = ConstantFP::get(SelType, abs(*TC));
Function *F = Intrinsic::getDeclaration(Sel.getModule(), Intrinsic::copysign, Function *F = Intrinsic::getOrInsertDeclaration(
Sel.getType()); Sel.getModule(), Intrinsic::copysign, Sel.getType());
return CallInst::Create(F, { MagArg, X }); return CallInst::Create(F, { MagArg, X });
} }
@ -2600,8 +2601,8 @@ Instruction *InstCombinerImpl::foldVectorSelect(SelectInst &Sel) {
if (auto *I = dyn_cast<Instruction>(V)) if (auto *I = dyn_cast<Instruction>(V))
I->copyIRFlags(&Sel); I->copyIRFlags(&Sel);
Module *M = Sel.getModule(); Module *M = Sel.getModule();
Function *F = Function *F = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::vector_reverse, V->getType()); M, Intrinsic::vector_reverse, V->getType());
return CallInst::Create(F, V); return CallInst::Create(F, V);
}; };

View File

@ -898,7 +898,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I,
Value *X; Value *X;
if (DemandedMask == 1 && VTy->getScalarSizeInBits() % 2 == 0 && if (DemandedMask == 1 && VTy->getScalarSizeInBits() % 2 == 0 &&
match(II->getArgOperand(0), m_Not(m_Value(X)))) { match(II->getArgOperand(0), m_Not(m_Value(X)))) {
Function *Ctpop = Intrinsic::getDeclaration( Function *Ctpop = Intrinsic::getOrInsertDeclaration(
II->getModule(), Intrinsic::ctpop, VTy); II->getModule(), Intrinsic::ctpop, VTy);
return InsertNewInstWith(CallInst::Create(Ctpop, {X}), I->getIterator()); return InsertNewInstWith(CallInst::Create(Ctpop, {X}), I->getIterator());
} }

View File

@ -2474,8 +2474,8 @@ static Instruction *foldShuffleOfUnaryOps(ShuffleVectorInst &Shuf,
if (IsFNeg) if (IsFNeg)
return UnaryOperator::CreateFNegFMF(NewShuf, S0); return UnaryOperator::CreateFNegFMF(NewShuf, S0);
Function *FAbs = Intrinsic::getDeclaration(Shuf.getModule(), Function *FAbs = Intrinsic::getOrInsertDeclaration(
Intrinsic::fabs, Shuf.getType()); Shuf.getModule(), Intrinsic::fabs, Shuf.getType());
CallInst *NewF = CallInst::Create(FAbs, {NewShuf}); CallInst *NewF = CallInst::Create(FAbs, {NewShuf});
NewF->setFastMathFlags(S0->getFastMathFlags()); NewF->setFastMathFlags(S0->getFastMathFlags());
return NewF; return NewF;
@ -2495,8 +2495,8 @@ static Instruction *foldShuffleOfUnaryOps(ShuffleVectorInst &Shuf,
if (IsFNeg) { if (IsFNeg) {
NewF = UnaryOperator::CreateFNeg(NewShuf); NewF = UnaryOperator::CreateFNeg(NewShuf);
} else { } else {
Function *FAbs = Intrinsic::getDeclaration(Shuf.getModule(), Function *FAbs = Intrinsic::getOrInsertDeclaration(
Intrinsic::fabs, Shuf.getType()); Shuf.getModule(), Intrinsic::fabs, Shuf.getType());
NewF = CallInst::Create(FAbs, {NewShuf}); NewF = CallInst::Create(FAbs, {NewShuf});
} }
NewF->copyIRFlags(S0); NewF->copyIRFlags(S0);

View File

@ -2084,8 +2084,8 @@ Instruction *InstCombinerImpl::foldVectorBinop(BinaryOperator &Inst) {
if (auto *BO = dyn_cast<BinaryOperator>(V)) if (auto *BO = dyn_cast<BinaryOperator>(V))
BO->copyIRFlags(&Inst); BO->copyIRFlags(&Inst);
Module *M = Inst.getModule(); Module *M = Inst.getModule();
Function *F = Function *F = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, Intrinsic::vector_reverse, V->getType()); M, Intrinsic::vector_reverse, V->getType());
return CallInst::Create(F, V); return CallInst::Create(F, V);
}; };
@ -3355,7 +3355,7 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
if (InvokeInst *II = dyn_cast<InvokeInst>(&MI)) { if (InvokeInst *II = dyn_cast<InvokeInst>(&MI)) {
// Replace invoke with a NOP intrinsic to maintain the original CFG // Replace invoke with a NOP intrinsic to maintain the original CFG
Module *M = II->getModule(); Module *M = II->getModule();
Function *F = Intrinsic::getDeclaration(M, Intrinsic::donothing); Function *F = Intrinsic::getOrInsertDeclaration(M, Intrinsic::donothing);
InvokeInst::Create(F, II->getNormalDest(), II->getUnwindDest(), {}, "", InvokeInst::Create(F, II->getNormalDest(), II->getUnwindDest(), {}, "",
II->getParent()); II->getParent());
} }

View File

@ -1109,7 +1109,7 @@ struct FunctionStackPoisoner : public InstVisitor<FunctionStackPoisoner> {
// alloca. We have a special @llvm.get.dynamic.area.offset intrinsic for // alloca. We have a special @llvm.get.dynamic.area.offset intrinsic for
// this purpose. // this purpose.
if (!isa<ReturnInst>(InstBefore)) { if (!isa<ReturnInst>(InstBefore)) {
Function *DynamicAreaOffsetFunc = Intrinsic::getDeclaration( Function *DynamicAreaOffsetFunc = Intrinsic::getOrInsertDeclaration(
InstBefore->getModule(), Intrinsic::get_dynamic_area_offset, InstBefore->getModule(), Intrinsic::get_dynamic_area_offset,
{IntptrTy}); {IntptrTy});
@ -1867,7 +1867,7 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
const ASanAccessInfo AccessInfo(IsWrite, CompileKernel, AccessSizeIndex); const ASanAccessInfo AccessInfo(IsWrite, CompileKernel, AccessSizeIndex);
Module *M = IRB.GetInsertBlock()->getParent()->getParent(); Module *M = IRB.GetInsertBlock()->getParent()->getParent();
IRB.CreateCall( IRB.CreateCall(
Intrinsic::getDeclaration(M, Intrinsic::asan_check_memaccess), Intrinsic::getOrInsertDeclaration(M, Intrinsic::asan_check_memaccess),
{IRB.CreatePointerCast(Addr, PtrTy), {IRB.CreatePointerCast(Addr, PtrTy),
ConstantInt::get(Int32Ty, AccessInfo.Packed)}); ConstantInt::get(Int32Ty, AccessInfo.Packed)});
return; return;

View File

@ -194,7 +194,7 @@ static bool addBoundsChecking(Function &F, TargetLibraryInfo &TLI,
IRB.SetInsertPoint(TrapBB); IRB.SetInsertPoint(TrapBB);
Intrinsic::ID IntrID = DebugTrapBB ? Intrinsic::ubsantrap : Intrinsic::trap; Intrinsic::ID IntrID = DebugTrapBB ? Intrinsic::ubsantrap : Intrinsic::trap;
auto *F = Intrinsic::getDeclaration(Fn->getParent(), IntrID); auto *F = Intrinsic::getOrInsertDeclaration(Fn->getParent(), IntrID);
CallInst *TrapCall; CallInst *TrapCall;
if (DebugTrapBB) { if (DebugTrapBB) {

View File

@ -1042,14 +1042,14 @@ void HWAddressSanitizer::instrumentMemAccessOutline(Value *Ptr, bool IsWrite,
if (UseFixedShadowIntrinsic) { if (UseFixedShadowIntrinsic) {
IRB.CreateCall( IRB.CreateCall(
Intrinsic::getDeclaration( Intrinsic::getOrInsertDeclaration(
M, UseShortGranules M, UseShortGranules
? Intrinsic::hwasan_check_memaccess_shortgranules_fixedshadow ? Intrinsic::hwasan_check_memaccess_shortgranules_fixedshadow
: Intrinsic::hwasan_check_memaccess_fixedshadow), : Intrinsic::hwasan_check_memaccess_fixedshadow),
{Ptr, ConstantInt::get(Int32Ty, AccessInfo), {Ptr, ConstantInt::get(Int32Ty, AccessInfo),
ConstantInt::get(Int64Ty, Mapping.offset())}); ConstantInt::get(Int64Ty, Mapping.offset())});
} else { } else {
IRB.CreateCall(Intrinsic::getDeclaration( IRB.CreateCall(Intrinsic::getOrInsertDeclaration(
M, UseShortGranules M, UseShortGranules
? Intrinsic::hwasan_check_memaccess_shortgranules ? Intrinsic::hwasan_check_memaccess_shortgranules
: Intrinsic::hwasan_check_memaccess), : Intrinsic::hwasan_check_memaccess),

View File

@ -110,7 +110,8 @@ PreservedAnalyses KCFIPass::run(Function &F, FunctionAnalysisManager &AM) {
Instruction *ThenTerm = Instruction *ThenTerm =
SplitBlockAndInsertIfThen(Test, Call, false, VeryUnlikelyWeights); SplitBlockAndInsertIfThen(Test, Call, false, VeryUnlikelyWeights);
Builder.SetInsertPoint(ThenTerm); Builder.SetInsertPoint(ThenTerm);
Builder.CreateCall(Intrinsic::getDeclaration(&M, Intrinsic::debugtrap)); Builder.CreateCall(
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::debugtrap));
++NumKCFIChecks; ++NumKCFIChecks;
} }

View File

@ -2853,7 +2853,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
Value *S2Conv = Value *S2Conv =
IRB.CreateSExt(IRB.CreateICmpNE(S2, getCleanShadow(S2)), S2->getType()); IRB.CreateSExt(IRB.CreateICmpNE(S2, getCleanShadow(S2)), S2->getType());
Value *V2 = I.getOperand(2); Value *V2 = I.getOperand(2);
Function *Intrin = Intrinsic::getDeclaration( Function *Intrin = Intrinsic::getOrInsertDeclaration(
I.getModule(), I.getIntrinsicID(), S2Conv->getType()); I.getModule(), I.getIntrinsicID(), S2Conv->getType());
Value *Shift = IRB.CreateCall(Intrin, {S0, S1, V2}); Value *Shift = IRB.CreateCall(Intrin, {S0, S1, V2});
setShadow(&I, IRB.CreateOr(Shift, S2Conv)); setShadow(&I, IRB.CreateOr(Shift, S2Conv));
@ -3057,7 +3057,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
IRBuilder<> IRB(&I); IRBuilder<> IRB(&I);
Value *Op = I.getArgOperand(0); Value *Op = I.getArgOperand(0);
Type *OpType = Op->getType(); Type *OpType = Op->getType();
Function *BswapFunc = Intrinsic::getDeclaration( Function *BswapFunc = Intrinsic::getOrInsertDeclaration(
F.getParent(), Intrinsic::bswap, ArrayRef(&OpType, 1)); F.getParent(), Intrinsic::bswap, ArrayRef(&OpType, 1));
setShadow(&I, IRB.CreateCall(BswapFunc, getShadow(Op))); setShadow(&I, IRB.CreateCall(BswapFunc, getShadow(Op)));
setOrigin(&I, getOrigin(Op)); setOrigin(&I, getOrigin(Op));
@ -3287,7 +3287,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
S2_ext = IRB.CreateBitCast(S2_ext, getMMXVectorTy(64)); S2_ext = IRB.CreateBitCast(S2_ext, getMMXVectorTy(64));
} }
Function *ShadowFn = Intrinsic::getDeclaration( Function *ShadowFn = Intrinsic::getOrInsertDeclaration(
F.getParent(), getSignedPackIntrinsic(I.getIntrinsicID())); F.getParent(), getSignedPackIntrinsic(I.getIntrinsicID()));
Value *S = Value *S =

View File

@ -919,7 +919,7 @@ void FunctionInstrumenter::instrument() {
// llvm.instrprof.cover(i8* <name>, i64 <hash>, i32 <num-counters>, // llvm.instrprof.cover(i8* <name>, i64 <hash>, i32 <num-counters>,
// i32 <index>) // i32 <index>)
Builder.CreateCall( Builder.CreateCall(
Intrinsic::getDeclaration(&M, Intrinsic::instrprof_cover), Intrinsic::getOrInsertDeclaration(&M, Intrinsic::instrprof_cover),
{NormalizedNamePtr, CFGHash, Builder.getInt32(1), Builder.getInt32(0)}); {NormalizedNamePtr, CFGHash, Builder.getInt32(1), Builder.getInt32(0)});
return; return;
} }
@ -931,7 +931,7 @@ void FunctionInstrumenter::instrument() {
if (IsCtxProf) { if (IsCtxProf) {
auto *CSIntrinsic = auto *CSIntrinsic =
Intrinsic::getDeclaration(&M, Intrinsic::instrprof_callsite); Intrinsic::getOrInsertDeclaration(&M, Intrinsic::instrprof_callsite);
// We want to count the instrumentable callsites, then instrument them. This // We want to count the instrumentable callsites, then instrument them. This
// is because the llvm.instrprof.callsite intrinsic has an argument (like // is because the llvm.instrprof.callsite intrinsic has an argument (like
// the other instrprof intrinsics) capturing the total number of // the other instrprof intrinsics) capturing the total number of
@ -972,7 +972,7 @@ void FunctionInstrumenter::instrument() {
// llvm.instrprof.timestamp(i8* <name>, i64 <hash>, i32 <num-counters>, // llvm.instrprof.timestamp(i8* <name>, i64 <hash>, i32 <num-counters>,
// i32 <index>) // i32 <index>)
Builder.CreateCall( Builder.CreateCall(
Intrinsic::getDeclaration(&M, Intrinsic::instrprof_timestamp), Intrinsic::getOrInsertDeclaration(&M, Intrinsic::instrprof_timestamp),
{NormalizedNamePtr, CFGHash, Builder.getInt32(NumCounters), {NormalizedNamePtr, CFGHash, Builder.getInt32(NumCounters),
Builder.getInt32(I)}); Builder.getInt32(I)});
I += PGOBlockCoverage ? 8 : 1; I += PGOBlockCoverage ? 8 : 1;
@ -984,12 +984,12 @@ void FunctionInstrumenter::instrument() {
"Cannot get the Instrumentation point"); "Cannot get the Instrumentation point");
// llvm.instrprof.increment(i8* <name>, i64 <hash>, i32 <num-counters>, // llvm.instrprof.increment(i8* <name>, i64 <hash>, i32 <num-counters>,
// i32 <index>) // i32 <index>)
Builder.CreateCall( Builder.CreateCall(Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(&M, PGOBlockCoverage &M, PGOBlockCoverage
? Intrinsic::instrprof_cover ? Intrinsic::instrprof_cover
: Intrinsic::instrprof_increment), : Intrinsic::instrprof_increment),
{NormalizedNamePtr, CFGHash, Builder.getInt32(NumCounters), {NormalizedNamePtr, CFGHash,
Builder.getInt32(I++)}); Builder.getInt32(NumCounters), Builder.getInt32(I++)});
} }
// Now instrument select instructions: // Now instrument select instructions:
@ -1038,7 +1038,8 @@ void FunctionInstrumenter::instrument() {
SmallVector<OperandBundleDef, 1> OpBundles; SmallVector<OperandBundleDef, 1> OpBundles;
populateEHOperandBundle(Cand, BlockColors, OpBundles); populateEHOperandBundle(Cand, BlockColors, OpBundles);
Builder.CreateCall( Builder.CreateCall(
Intrinsic::getDeclaration(&M, Intrinsic::instrprof_value_profile), Intrinsic::getOrInsertDeclaration(&M,
Intrinsic::instrprof_value_profile),
{NormalizedNamePtr, Builder.getInt64(FuncInfo.FunctionHash), {NormalizedNamePtr, Builder.getInt64(FuncInfo.FunctionHash),
ToProfile, Builder.getInt32(Kind), Builder.getInt32(SiteIndex++)}, ToProfile, Builder.getInt32(Kind), Builder.getInt32(SiteIndex++)},
OpBundles); OpBundles);
@ -1726,7 +1727,7 @@ void SelectInstVisitor::instrumentOneSelectInst(SelectInst &SI) {
ConstantExpr::getPointerBitCastOrAddrSpaceCast( ConstantExpr::getPointerBitCastOrAddrSpaceCast(
FuncNameVar, PointerType::get(M->getContext(), 0)); FuncNameVar, PointerType::get(M->getContext(), 0));
Builder.CreateCall( Builder.CreateCall(
Intrinsic::getDeclaration(M, Intrinsic::instrprof_increment_step), Intrinsic::getOrInsertDeclaration(M, Intrinsic::instrprof_increment_step),
{NormalizedFuncNameVarPtr, Builder.getInt64(FuncHash), {NormalizedFuncNameVarPtr, Builder.getInt64(FuncHash),
Builder.getInt32(TotalNumCtrs), Builder.getInt32(*CurCtrIdx), Step}); Builder.getInt32(TotalNumCtrs), Builder.getInt32(*CurCtrIdx), Step});
++(*CurCtrIdx); ++(*CurCtrIdx);

View File

@ -999,7 +999,7 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
if (Options.StackDepth && IsEntryBB && !IsLeafFunc) { if (Options.StackDepth && IsEntryBB && !IsLeafFunc) {
// Check stack depth. If it's the deepest so far, record it. // Check stack depth. If it's the deepest so far, record it.
Module *M = F.getParent(); Module *M = F.getParent();
Function *GetFrameAddr = Intrinsic::getDeclaration( Function *GetFrameAddr = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::frameaddress, M, Intrinsic::frameaddress,
IRB.getPtrTy(M->getDataLayout().getAllocaAddrSpace())); IRB.getPtrTy(M->getDataLayout().getAllocaAddrSpace()));
auto FrameAddrPtr = auto FrameAddrPtr =

View File

@ -571,9 +571,10 @@ bool ThreadSanitizer::sanitizeFunction(Function &F,
// Instrument function entry/exit points if there were instrumented accesses. // Instrument function entry/exit points if there were instrumented accesses.
if ((Res || HasCalls) && ClInstrumentFuncEntryExit) { if ((Res || HasCalls) && ClInstrumentFuncEntryExit) {
InstrumentationIRBuilder IRB(F.getEntryBlock().getFirstNonPHI()); InstrumentationIRBuilder IRB(F.getEntryBlock().getFirstNonPHI());
Value *ReturnAddress = IRB.CreateCall( Value *ReturnAddress =
Intrinsic::getDeclaration(F.getParent(), Intrinsic::returnaddress), IRB.CreateCall(Intrinsic::getOrInsertDeclaration(
IRB.getInt32(0)); F.getParent(), Intrinsic::returnaddress),
IRB.getInt32(0));
IRB.CreateCall(TsanFuncEntry, ReturnAddress); IRB.CreateCall(TsanFuncEntry, ReturnAddress);
EscapeEnumerator EE(F, "tsan_cleanup", ClHandleCxxExceptions); EscapeEnumerator EE(F, "tsan_cleanup", ClHandleCxxExceptions);

View File

@ -139,7 +139,7 @@ private:
if (Decl) if (Decl)
return Decl; return Decl;
return Decl = Intrinsic::getDeclaration(TheModule, IntID); return Decl = Intrinsic::getOrInsertDeclaration(TheModule, IntID);
} }
}; };

View File

@ -380,7 +380,8 @@ bool InferAddressSpacesImpl::rewriteIntrinsicOperands(IntrinsicInst *II,
case Intrinsic::masked_load: { case Intrinsic::masked_load: {
Type *DestTy = II->getType(); Type *DestTy = II->getType();
Type *SrcTy = NewV->getType(); Type *SrcTy = NewV->getType();
Function *NewDecl = Intrinsic::getDeclaration(M, IID, {DestTy, SrcTy}); Function *NewDecl =
Intrinsic::getOrInsertDeclaration(M, IID, {DestTy, SrcTy});
II->setArgOperand(0, NewV); II->setArgOperand(0, NewV);
II->setCalledFunction(NewDecl); II->setCalledFunction(NewDecl);
return true; return true;
@ -391,7 +392,8 @@ bool InferAddressSpacesImpl::rewriteIntrinsicOperands(IntrinsicInst *II,
case Intrinsic::masked_gather: { case Intrinsic::masked_gather: {
Type *RetTy = II->getType(); Type *RetTy = II->getType();
Type *NewPtrTy = NewV->getType(); Type *NewPtrTy = NewV->getType();
Function *NewDecl = Intrinsic::getDeclaration(M, IID, {RetTy, NewPtrTy}); Function *NewDecl =
Intrinsic::getOrInsertDeclaration(M, IID, {RetTy, NewPtrTy});
II->setArgOperand(0, NewV); II->setArgOperand(0, NewV);
II->setCalledFunction(NewDecl); II->setCalledFunction(NewDecl);
return true; return true;
@ -400,16 +402,16 @@ bool InferAddressSpacesImpl::rewriteIntrinsicOperands(IntrinsicInst *II,
case Intrinsic::masked_scatter: { case Intrinsic::masked_scatter: {
Type *ValueTy = II->getOperand(0)->getType(); Type *ValueTy = II->getOperand(0)->getType();
Type *NewPtrTy = NewV->getType(); Type *NewPtrTy = NewV->getType();
Function *NewDecl = Function *NewDecl = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, II->getIntrinsicID(), {ValueTy, NewPtrTy}); M, II->getIntrinsicID(), {ValueTy, NewPtrTy});
II->setArgOperand(1, NewV); II->setArgOperand(1, NewV);
II->setCalledFunction(NewDecl); II->setCalledFunction(NewDecl);
return true; return true;
} }
case Intrinsic::prefetch: case Intrinsic::prefetch:
case Intrinsic::is_constant: { case Intrinsic::is_constant: {
Function *NewDecl = Function *NewDecl = Intrinsic::getOrInsertDeclaration(
Intrinsic::getDeclaration(M, II->getIntrinsicID(), {NewV->getType()}); M, II->getIntrinsicID(), {NewV->getType()});
II->setArgOperand(0, NewV); II->setArgOperand(0, NewV);
II->setCalledFunction(NewDecl); II->setCalledFunction(NewDecl);
return true; return true;

View File

@ -405,7 +405,7 @@ bool LoopDataPrefetch::runOnLoop(Loop *L) {
IRBuilder<> Builder(P.InsertPt); IRBuilder<> Builder(P.InsertPt);
Module *M = BB->getParent()->getParent(); Module *M = BB->getParent()->getParent();
Type *I32 = Type::getInt32Ty(BB->getContext()); Type *I32 = Type::getInt32Ty(BB->getContext());
Function *PrefetchFunc = Intrinsic::getDeclaration( Function *PrefetchFunc = Intrinsic::getOrInsertDeclaration(
M, Intrinsic::prefetch, PrefPtrValue->getType()); M, Intrinsic::prefetch, PrefPtrValue->getType());
Builder.CreateCall( Builder.CreateCall(
PrefetchFunc, PrefetchFunc,

View File

@ -978,8 +978,8 @@ static bool FlattenLoopPair(FlattenInfo &FI, DominatorTree *DT, LoopInfo *LI,
assert(match(Br->getCondition(), m_Zero()) && assert(match(Br->getCondition(), m_Zero()) &&
"Expected branch condition to be false"); "Expected branch condition to be false");
IRBuilder<> Builder(Br); IRBuilder<> Builder(Br);
Function *F = Intrinsic::getDeclaration(M, Intrinsic::umul_with_overflow, Function *F = Intrinsic::getOrInsertDeclaration(
FI.OuterTripCount->getType()); M, Intrinsic::umul_with_overflow, FI.OuterTripCount->getType());
Value *Call = Builder.CreateCall(F, {FI.OuterTripCount, FI.InnerTripCount}, Value *Call = Builder.CreateCall(F, {FI.OuterTripCount, FI.InnerTripCount},
"flatten.mul"); "flatten.mul");
FI.NewTripCount = Builder.CreateExtractValue(Call, 0, "flatten.tripcount"); FI.NewTripCount = Builder.CreateExtractValue(Call, 0, "flatten.tripcount");

View File

@ -2122,7 +2122,7 @@ static CallInst *createPopcntIntrinsic(IRBuilder<> &IRBuilder, Value *Val,
Type *Tys[] = {Val->getType()}; Type *Tys[] = {Val->getType()};
Module *M = IRBuilder.GetInsertBlock()->getParent()->getParent(); Module *M = IRBuilder.GetInsertBlock()->getParent()->getParent();
Function *Func = Intrinsic::getDeclaration(M, Intrinsic::ctpop, Tys); Function *Func = Intrinsic::getOrInsertDeclaration(M, Intrinsic::ctpop, Tys);
CallInst *CI = IRBuilder.CreateCall(Func, Ops); CallInst *CI = IRBuilder.CreateCall(Func, Ops);
CI->setDebugLoc(DL); CI->setDebugLoc(DL);
@ -2136,7 +2136,7 @@ static CallInst *createFFSIntrinsic(IRBuilder<> &IRBuilder, Value *Val,
Type *Tys[] = {Val->getType()}; Type *Tys[] = {Val->getType()};
Module *M = IRBuilder.GetInsertBlock()->getParent()->getParent(); Module *M = IRBuilder.GetInsertBlock()->getParent()->getParent();
Function *Func = Intrinsic::getDeclaration(M, IID, Tys); Function *Func = Intrinsic::getOrInsertDeclaration(M, IID, Tys);
CallInst *CI = IRBuilder.CreateCall(Func, Ops); CallInst *CI = IRBuilder.CreateCall(Func, Ops);
CI->setDebugLoc(DL); CI->setDebugLoc(DL);

View File

@ -44,7 +44,7 @@ static bool lowerGuardIntrinsic(Function &F) {
if (ToLower.empty()) if (ToLower.empty())
return false; return false;
auto *DeoptIntrinsic = Intrinsic::getDeclaration( auto *DeoptIntrinsic = Intrinsic::getOrInsertDeclaration(
F.getParent(), Intrinsic::experimental_deoptimize, {F.getReturnType()}); F.getParent(), Intrinsic::experimental_deoptimize, {F.getReturnType()});
DeoptIntrinsic->setCallingConv(GuardDecl->getCallingConv()); DeoptIntrinsic->setCallingConv(GuardDecl->getCallingConv());

Some files were not shown because too many files have changed in this diff Show More