@@ -2108,6 +2108,13 @@ static void setARCRuntimeFunctionLinkage(CodeGenModule &CGM,
2108
2108
setARCRuntimeFunctionLinkage (CGM, RTF.getCallee ());
2109
2109
}
2110
2110
2111
+ static llvm::Function *getARCIntrinsic (llvm::Intrinsic::ID IntID,
2112
+ CodeGenModule &CGM) {
2113
+ llvm::Function *fn = CGM.getIntrinsic (IntID);
2114
+ setARCRuntimeFunctionLinkage (CGM, fn);
2115
+ return fn;
2116
+ }
2117
+
2111
2118
// / Perform an operation having the signature
2112
2119
// / i8* (i8*)
2113
2120
// / where a null input causes a no-op and returns null.
@@ -2118,10 +2125,8 @@ static llvm::Value *emitARCValueOperation(
2118
2125
if (isa<llvm::ConstantPointerNull>(value))
2119
2126
return value;
2120
2127
2121
- if (!fn) {
2122
- fn = CGF.CGM .getIntrinsic (IntID);
2123
- setARCRuntimeFunctionLinkage (CGF.CGM , fn);
2124
- }
2128
+ if (!fn)
2129
+ fn = getARCIntrinsic (IntID, CGF.CGM );
2125
2130
2126
2131
// Cast the argument to 'id'.
2127
2132
llvm::Type *origType = returnType ? returnType : value->getType ();
@@ -2140,10 +2145,8 @@ static llvm::Value *emitARCValueOperation(
2140
2145
static llvm::Value *emitARCLoadOperation (CodeGenFunction &CGF, Address addr,
2141
2146
llvm::Function *&fn,
2142
2147
llvm::Intrinsic::ID IntID) {
2143
- if (!fn) {
2144
- fn = CGF.CGM .getIntrinsic (IntID);
2145
- setARCRuntimeFunctionLinkage (CGF.CGM , fn);
2146
- }
2148
+ if (!fn)
2149
+ fn = getARCIntrinsic (IntID, CGF.CGM );
2147
2150
2148
2151
// Cast the argument to 'id*'.
2149
2152
llvm::Type *origType = addr.getElementType ();
@@ -2168,10 +2171,8 @@ static llvm::Value *emitARCStoreOperation(CodeGenFunction &CGF, Address addr,
2168
2171
bool ignored) {
2169
2172
assert (addr.getElementType () == value->getType ());
2170
2173
2171
- if (!fn) {
2172
- fn = CGF.CGM .getIntrinsic (IntID);
2173
- setARCRuntimeFunctionLinkage (CGF.CGM , fn);
2174
- }
2174
+ if (!fn)
2175
+ fn = getARCIntrinsic (IntID, CGF.CGM );
2175
2176
2176
2177
llvm::Type *origType = value->getType ();
2177
2178
@@ -2193,10 +2194,8 @@ static void emitARCCopyOperation(CodeGenFunction &CGF, Address dst, Address src,
2193
2194
llvm::Intrinsic::ID IntID) {
2194
2195
assert (dst.getType () == src.getType ());
2195
2196
2196
- if (!fn) {
2197
- fn = CGF.CGM .getIntrinsic (IntID);
2198
- setARCRuntimeFunctionLinkage (CGF.CGM , fn);
2199
- }
2197
+ if (!fn)
2198
+ fn = getARCIntrinsic (IntID, CGF.CGM );
2200
2199
2201
2200
llvm::Value *args[] = {
2202
2201
CGF.Builder .CreateBitCast (dst.getPointer (), CGF.Int8PtrPtrTy ),
@@ -2340,13 +2339,19 @@ static llvm::Value *emitOptimizedARCReturnCall(llvm::Value *value,
2340
2339
// retainRV or claimRV calls in the IR. We currently do this only when the
2341
2340
// optimization level isn't -O0 since global-isel, which is currently run at
2342
2341
// -O0, doesn't know about the operand bundle.
2342
+ ObjCEntrypoints &EPs = CGF.CGM .getObjCEntrypoints ();
2343
+ llvm::Function *&EP = IsRetainRV
2344
+ ? EPs.objc_retainAutoreleasedReturnValue
2345
+ : EPs.objc_unsafeClaimAutoreleasedReturnValue ;
2346
+ llvm::Intrinsic::ID IID =
2347
+ IsRetainRV ? llvm::Intrinsic::objc_retainAutoreleasedReturnValue
2348
+ : llvm::Intrinsic::objc_unsafeClaimAutoreleasedReturnValue;
2349
+ EP = getARCIntrinsic (IID, CGF.CGM );
2343
2350
2344
2351
// FIXME: Do this when the target isn't aarch64.
2345
2352
if (CGF.CGM .getCodeGenOpts ().OptimizationLevel > 0 &&
2346
2353
CGF.CGM .getTarget ().getTriple ().isAArch64 ()) {
2347
- llvm::Value *bundleArgs[] = {llvm::ConstantInt::get (
2348
- CGF.Int64Ty ,
2349
- llvm::objcarc::getAttachedCallOperandBundleEnum (IsRetainRV))};
2354
+ llvm::Value *bundleArgs[] = {EP};
2350
2355
llvm::OperandBundleDef OB (" clang.arc.attachedcall" , bundleArgs);
2351
2356
auto *oldCall = cast<llvm::CallBase>(value);
2352
2357
llvm::CallBase *newCall = llvm::CallBase::addOperandBundle (
@@ -2362,13 +2367,6 @@ static llvm::Value *emitOptimizedARCReturnCall(llvm::Value *value,
2362
2367
CGF.CGM .getTargetCodeGenInfo ().markARCOptimizedReturnCallsAsNoTail ();
2363
2368
llvm::CallInst::TailCallKind tailKind =
2364
2369
isNoTail ? llvm::CallInst::TCK_NoTail : llvm::CallInst::TCK_None;
2365
- ObjCEntrypoints &EPs = CGF.CGM .getObjCEntrypoints ();
2366
- llvm::Function *&EP = IsRetainRV
2367
- ? EPs.objc_retainAutoreleasedReturnValue
2368
- : EPs.objc_unsafeClaimAutoreleasedReturnValue ;
2369
- llvm::Intrinsic::ID IID =
2370
- IsRetainRV ? llvm::Intrinsic::objc_retainAutoreleasedReturnValue
2371
- : llvm::Intrinsic::objc_unsafeClaimAutoreleasedReturnValue;
2372
2370
return emitARCValueOperation (CGF, value, nullptr , EP, IID, tailKind);
2373
2371
}
2374
2372
@@ -2401,10 +2399,8 @@ void CodeGenFunction::EmitARCRelease(llvm::Value *value,
2401
2399
if (isa<llvm::ConstantPointerNull>(value)) return ;
2402
2400
2403
2401
llvm::Function *&fn = CGM.getObjCEntrypoints ().objc_release ;
2404
- if (!fn) {
2405
- fn = CGM.getIntrinsic (llvm::Intrinsic::objc_release);
2406
- setARCRuntimeFunctionLinkage (CGM, fn);
2407
- }
2402
+ if (!fn)
2403
+ fn = getARCIntrinsic (llvm::Intrinsic::objc_release, CGM);
2408
2404
2409
2405
// Cast the argument to 'id'.
2410
2406
value = Builder.CreateBitCast (value, Int8PtrTy);
@@ -2447,10 +2443,8 @@ llvm::Value *CodeGenFunction::EmitARCStoreStrongCall(Address addr,
2447
2443
assert (addr.getElementType () == value->getType ());
2448
2444
2449
2445
llvm::Function *&fn = CGM.getObjCEntrypoints ().objc_storeStrong ;
2450
- if (!fn) {
2451
- fn = CGM.getIntrinsic (llvm::Intrinsic::objc_storeStrong);
2452
- setARCRuntimeFunctionLinkage (CGM, fn);
2453
- }
2446
+ if (!fn)
2447
+ fn = getARCIntrinsic (llvm::Intrinsic::objc_storeStrong, CGM);
2454
2448
2455
2449
llvm::Value *args[] = {
2456
2450
Builder.CreateBitCast (addr.getPointer (), Int8PtrPtrTy),
@@ -2603,10 +2597,8 @@ void CodeGenFunction::EmitARCInitWeak(Address addr, llvm::Value *value) {
2603
2597
// / Essentially objc_storeWeak(addr, nil).
2604
2598
void CodeGenFunction::EmitARCDestroyWeak (Address addr) {
2605
2599
llvm::Function *&fn = CGM.getObjCEntrypoints ().objc_destroyWeak ;
2606
- if (!fn) {
2607
- fn = CGM.getIntrinsic (llvm::Intrinsic::objc_destroyWeak);
2608
- setARCRuntimeFunctionLinkage (CGM, fn);
2609
- }
2600
+ if (!fn)
2601
+ fn = getARCIntrinsic (llvm::Intrinsic::objc_destroyWeak, CGM);
2610
2602
2611
2603
// Cast the argument to 'id*'.
2612
2604
addr = Builder.CreateBitCast (addr, Int8PtrPtrTy);
@@ -2651,10 +2643,8 @@ void CodeGenFunction::emitARCMoveAssignWeak(QualType Ty, Address DstAddr,
2651
2643
// / call i8* \@objc_autoreleasePoolPush(void)
2652
2644
llvm::Value *CodeGenFunction::EmitObjCAutoreleasePoolPush () {
2653
2645
llvm::Function *&fn = CGM.getObjCEntrypoints ().objc_autoreleasePoolPush ;
2654
- if (!fn) {
2655
- fn = CGM.getIntrinsic (llvm::Intrinsic::objc_autoreleasePoolPush);
2656
- setARCRuntimeFunctionLinkage (CGM, fn);
2657
- }
2646
+ if (!fn)
2647
+ fn = getARCIntrinsic (llvm::Intrinsic::objc_autoreleasePoolPush, CGM);
2658
2648
2659
2649
return EmitNounwindRuntimeCall (fn);
2660
2650
}
@@ -2679,10 +2669,8 @@ void CodeGenFunction::EmitObjCAutoreleasePoolPop(llvm::Value *value) {
2679
2669
EmitRuntimeCallOrInvoke (fn, value);
2680
2670
} else {
2681
2671
llvm::FunctionCallee &fn = CGM.getObjCEntrypoints ().objc_autoreleasePoolPop ;
2682
- if (!fn) {
2683
- fn = CGM.getIntrinsic (llvm::Intrinsic::objc_autoreleasePoolPop);
2684
- setARCRuntimeFunctionLinkage (CGM, fn);
2685
- }
2672
+ if (!fn)
2673
+ fn = getARCIntrinsic (llvm::Intrinsic::objc_autoreleasePoolPop, CGM);
2686
2674
2687
2675
EmitRuntimeCall (fn, value);
2688
2676
}
0 commit comments