Skip to content

Commit de1966e

Browse files
committedFeb 9, 2021
Revert "[ObjC][ARC] Use operand bundle 'clang.arc.rv' instead of explicitly"
This reverts commit 4a64d8f. Makes clang crash when buildling trivial iOS programs, see comment after https://reviews.llvm.org/D92808#2551401
1 parent 2309392 commit de1966e

34 files changed

+121
-1081
lines changed
 

‎clang/lib/CodeGen/CGObjC.cpp

+21-56
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "clang/Basic/Diagnostic.h"
2424
#include "clang/CodeGen/CGFunctionInfo.h"
2525
#include "llvm/ADT/STLExtras.h"
26-
#include "llvm/Analysis/ObjCARCUtil.h"
2726
#include "llvm/BinaryFormat/MachO.h"
2827
#include "llvm/IR/DataLayout.h"
2928
#include "llvm/IR/InlineAsm.h"
@@ -2079,15 +2078,6 @@ void CodeGenFunction::EmitARCIntrinsicUse(ArrayRef<llvm::Value*> values) {
20792078
EmitNounwindRuntimeCall(fn, values);
20802079
}
20812080

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-
20912081
static void setARCRuntimeFunctionLinkage(CodeGenModule &CGM, llvm::Value *RTF) {
20922082
if (auto *F = dyn_cast<llvm::Function>(RTF)) {
20932083
// If the target runtime doesn't naturally support ARC, emit weak
@@ -2314,11 +2304,10 @@ static void emitAutoreleasedReturnValueMarker(CodeGenFunction &CGF) {
23142304
// with this marker yet, so leave a breadcrumb for the ARC
23152305
// optimizer to pick up.
23162306
} 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)) {
23192309
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);
23222311
}
23232312
}
23242313
}
@@ -2328,54 +2317,22 @@ static void emitAutoreleasedReturnValueMarker(CodeGenFunction &CGF) {
23282317
CGF.Builder.CreateCall(marker, None, CGF.getBundlesForFunclet(marker));
23292318
}
23302319

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-
23712320
/// Retain the given object which is the result of a function call.
23722321
/// call i8* \@objc_retainAutoreleasedReturnValue(i8* %value)
23732322
///
23742323
/// Yes, this function name is one character away from a different
23752324
/// call with completely different semantics.
23762325
llvm::Value *
23772326
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);
23792336
}
23802337

23812338
/// Claim a possibly-autoreleased return value at +0. This is only
@@ -2387,7 +2344,15 @@ CodeGenFunction::EmitARCRetainAutoreleasedReturnValue(llvm::Value *value) {
23872344
/// call i8* \@objc_unsafeClaimAutoreleasedReturnValue(i8* %value)
23882345
llvm::Value *
23892346
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);
23912356
}
23922357

23932358
/// Release the given object.

‎clang/lib/CodeGen/CodeGenFunction.h

-2
Original file line numberDiff line numberDiff line change
@@ -4202,8 +4202,6 @@ class CodeGenFunction : public CodeGenTypeCache {
42024202

42034203
void EmitARCIntrinsicUse(ArrayRef<llvm::Value*> values);
42044204

4205-
void EmitARCNoopIntrinsicUse(ArrayRef<llvm::Value *> values);
4206-
42074205
static Destroyer destroyARCStrongImprecise;
42084206
static Destroyer destroyARCStrongPrecise;
42094207
static Destroyer destroyARCWeak;

‎clang/lib/CodeGen/CodeGenModule.h

-3
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,6 @@ struct ObjCEntrypoints {
210210

211211
/// void clang.arc.use(...);
212212
llvm::Function *clang_arc_use;
213-
214-
/// void clang.arc.noop.use(...);
215-
llvm::Function *clang_arc_noop_use;
216213
};
217214

218215
/// This class records statistics on instrumentation based profiling.

‎clang/test/CodeGenObjC/arc-rv-attr.m

-177
This file was deleted.

‎clang/test/CodeGenObjC/arc-unsafeclaim.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
// Make sure it works on x86-32.
55
// RUN: %clang_cc1 -triple i386-apple-darwin11 -fobjc-runtime=macosx-fragile-10.11 -fobjc-arc -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-UNOPTIMIZED -check-prefix=CHECK-MARKED -check-prefix=CALL
66

7-
// Make sure it works on ARM64.
7+
// Make sure it works on ARM.
88
// RUN: %clang_cc1 -triple arm64-apple-ios9 -fobjc-runtime=ios-9.0 -fobjc-arc -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-UNOPTIMIZED -check-prefix=CHECK-MARKED -check-prefix=CALL
9+
// RUN: %clang_cc1 -triple arm64-apple-ios9 -fobjc-runtime=ios-9.0 -fobjc-arc -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-OPTIMIZED -check-prefix=CALL
910

10-
// Make sure it works on ARM.
11+
// Make sure it works on ARM64.
1112
// RUN: %clang_cc1 -triple armv7-apple-ios9 -fobjc-runtime=ios-9.0 -fobjc-arc -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-UNOPTIMIZED -check-prefix=CHECK-MARKED -check-prefix=CALL
1213
// RUN: %clang_cc1 -triple armv7-apple-ios9 -fobjc-runtime=ios-9.0 -fobjc-arc -O -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-OPTIMIZED -check-prefix=CALL
1314

‎llvm/docs/LangRef.rst

-12
Original file line numberDiff line numberDiff line change
@@ -2325,18 +2325,6 @@ When lowered, any relocated value will be recorded in the corresponding
23252325
:ref:`stackmap entry <statepoint-stackmap-format>`. See the intrinsic description
23262326
for further details.
23272327

2328-
ObjC ARC RetainRV/ClaimRV Operand Bundles
2329-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2330-
2331-
A ``"clang.arc.rv"`` operand bundle on a call indicates the call is implicitly
2332-
followed by a marker instruction and a call to an ObjC runtime function that
2333-
uses the result of the call. If the argument passed to the operand bundle is 0,
2334-
``@objc_retainAutoreleasedReturnValue`` is called. If 1 is passed,
2335-
``@objc_unsafeClaimAutoreleasedReturnValue`` is called.
2336-
2337-
The operand bundle is needed to ensure the call is immediately followed by the
2338-
marker instruction or the ObjC runtime call in the final output.
2339-
23402328
.. _moduleasm:
23412329

23422330
Module-Level Inline Assembly

‎llvm/include/llvm/Analysis/ObjCARCUtil.h

-48
This file was deleted.

0 commit comments

Comments
 (0)