23
23
#include " clang/Basic/Diagnostic.h"
24
24
#include " clang/CodeGen/CGFunctionInfo.h"
25
25
#include " llvm/ADT/STLExtras.h"
26
- #include " llvm/Analysis/ObjCARCUtil.h"
27
26
#include " llvm/BinaryFormat/MachO.h"
28
27
#include " llvm/IR/DataLayout.h"
29
28
#include " llvm/IR/InlineAsm.h"
@@ -2079,15 +2078,6 @@ void CodeGenFunction::EmitARCIntrinsicUse(ArrayRef<llvm::Value*> values) {
2079
2078
EmitNounwindRuntimeCall (fn, values);
2080
2079
}
2081
2080
2082
- // / Emit a call to "clang.arc.noop.use", which consumes the result of a call
2083
- // / that has operand bundle "clang.arc.rv".
2084
- void CodeGenFunction::EmitARCNoopIntrinsicUse (ArrayRef<llvm::Value *> values) {
2085
- llvm::Function *&fn = CGM.getObjCEntrypoints ().clang_arc_noop_use ;
2086
- if (!fn)
2087
- fn = CGM.getIntrinsic (llvm::Intrinsic::objc_clang_arc_noop_use);
2088
- EmitNounwindRuntimeCall (fn, values);
2089
- }
2090
-
2091
2081
static void setARCRuntimeFunctionLinkage (CodeGenModule &CGM, llvm::Value *RTF) {
2092
2082
if (auto *F = dyn_cast<llvm::Function>(RTF)) {
2093
2083
// If the target runtime doesn't naturally support ARC, emit weak
@@ -2314,11 +2304,10 @@ static void emitAutoreleasedReturnValueMarker(CodeGenFunction &CGF) {
2314
2304
// with this marker yet, so leave a breadcrumb for the ARC
2315
2305
// optimizer to pick up.
2316
2306
} else {
2317
- const char *retainRVMarkerKey = llvm::objcarc::getRVMarkerModuleFlagStr () ;
2318
- if (!CGF.CGM .getModule ().getModuleFlag (retainRVMarkerKey )) {
2307
+ const char *markerKey = " clang.arc.retainAutoreleasedReturnValueMarker " ;
2308
+ if (!CGF.CGM .getModule ().getModuleFlag (markerKey )) {
2319
2309
auto *str = llvm::MDString::get (CGF.getLLVMContext (), assembly);
2320
- CGF.CGM .getModule ().addModuleFlag (llvm::Module::Error,
2321
- retainRVMarkerKey, str);
2310
+ CGF.CGM .getModule ().addModuleFlag (llvm::Module::Error, markerKey, str);
2322
2311
}
2323
2312
}
2324
2313
}
@@ -2328,54 +2317,22 @@ static void emitAutoreleasedReturnValueMarker(CodeGenFunction &CGF) {
2328
2317
CGF.Builder .CreateCall (marker, None, CGF.getBundlesForFunclet (marker));
2329
2318
}
2330
2319
2331
- static llvm::Value *emitOptimizedARCReturnCall (llvm::Value *value,
2332
- bool IsRetainRV,
2333
- CodeGenFunction &CGF) {
2334
- emitAutoreleasedReturnValueMarker (CGF);
2335
-
2336
- // Add operand bundle "clang.arc.rv" to the call instead of emitting retainRV
2337
- // or claimRV calls in the IR. We currently do this only when the optimization
2338
- // level isn't -O0 since global-isel, which is currently run at -O0, doesn't
2339
- // know about the operand bundle.
2340
-
2341
- // FIXME: Do this when the target isn't aarch64.
2342
- if (CGF.CGM .getCodeGenOpts ().OptimizationLevel > 0 &&
2343
- CGF.CGM .getTarget ().getTriple ().isAArch64 ()) {
2344
- llvm::Value *bundleArgs[] = {llvm::ConstantInt::get (
2345
- CGF.Int64Ty , llvm::objcarc::getRVOperandBundleEnum (IsRetainRV))};
2346
- SmallVector<llvm::OperandBundleDef, 1 > bundles;
2347
- bundles.emplace_back (" clang.arc.rv" , bundleArgs);
2348
- auto *oldCall = cast<llvm::CallBase>(value);
2349
- llvm::CallBase *newCall = llvm::CallBase::Create (oldCall, bundles, oldCall);
2350
- newCall->copyMetadata (*oldCall);
2351
- oldCall->replaceAllUsesWith (newCall);
2352
- oldCall->eraseFromParent ();
2353
- CGF.EmitARCNoopIntrinsicUse (newCall);
2354
- return newCall;
2355
- }
2356
-
2357
- bool isNoTail =
2358
- CGF.CGM .getTargetCodeGenInfo ().markARCOptimizedReturnCallsAsNoTail ();
2359
- llvm::CallInst::TailCallKind tailKind =
2360
- isNoTail ? llvm::CallInst::TCK_NoTail : llvm::CallInst::TCK_None;
2361
- ObjCEntrypoints &EPs = CGF.CGM .getObjCEntrypoints ();
2362
- llvm::Function *&EP = IsRetainRV
2363
- ? EPs.objc_retainAutoreleasedReturnValue
2364
- : EPs.objc_unsafeClaimAutoreleasedReturnValue ;
2365
- llvm::Intrinsic::ID IID =
2366
- IsRetainRV ? llvm::Intrinsic::objc_retainAutoreleasedReturnValue
2367
- : llvm::Intrinsic::objc_unsafeClaimAutoreleasedReturnValue;
2368
- return emitARCValueOperation (CGF, value, nullptr , EP, IID, tailKind);
2369
- }
2370
-
2371
2320
// / Retain the given object which is the result of a function call.
2372
2321
// / call i8* \@objc_retainAutoreleasedReturnValue(i8* %value)
2373
2322
// /
2374
2323
// / Yes, this function name is one character away from a different
2375
2324
// / call with completely different semantics.
2376
2325
llvm::Value *
2377
2326
CodeGenFunction::EmitARCRetainAutoreleasedReturnValue (llvm::Value *value) {
2378
- return emitOptimizedARCReturnCall (value, true , *this );
2327
+ emitAutoreleasedReturnValueMarker (*this );
2328
+ llvm::CallInst::TailCallKind tailKind =
2329
+ CGM.getTargetCodeGenInfo ().markARCOptimizedReturnCallsAsNoTail ()
2330
+ ? llvm::CallInst::TCK_NoTail
2331
+ : llvm::CallInst::TCK_None;
2332
+ return emitARCValueOperation (
2333
+ *this , value, nullptr ,
2334
+ CGM.getObjCEntrypoints ().objc_retainAutoreleasedReturnValue ,
2335
+ llvm::Intrinsic::objc_retainAutoreleasedReturnValue, tailKind);
2379
2336
}
2380
2337
2381
2338
// / Claim a possibly-autoreleased return value at +0. This is only
@@ -2387,7 +2344,15 @@ CodeGenFunction::EmitARCRetainAutoreleasedReturnValue(llvm::Value *value) {
2387
2344
// / call i8* \@objc_unsafeClaimAutoreleasedReturnValue(i8* %value)
2388
2345
llvm::Value *
2389
2346
CodeGenFunction::EmitARCUnsafeClaimAutoreleasedReturnValue (llvm::Value *value) {
2390
- return emitOptimizedARCReturnCall (value, false , *this );
2347
+ emitAutoreleasedReturnValueMarker (*this );
2348
+ llvm::CallInst::TailCallKind tailKind =
2349
+ CGM.getTargetCodeGenInfo ().markARCOptimizedReturnCallsAsNoTail ()
2350
+ ? llvm::CallInst::TCK_NoTail
2351
+ : llvm::CallInst::TCK_None;
2352
+ return emitARCValueOperation (
2353
+ *this , value, nullptr ,
2354
+ CGM.getObjCEntrypoints ().objc_unsafeClaimAutoreleasedReturnValue ,
2355
+ llvm::Intrinsic::objc_unsafeClaimAutoreleasedReturnValue, tailKind);
2391
2356
}
2392
2357
2393
2358
// / Release the given object.
0 commit comments