Skip to content

Commit 5bb8e9d

Browse files
authored
Revert "[ObjCARC][Contract] Optimize bundled RetainRV to ClaimRV" (#139780)
Reverts #139762 for breaking bots
1 parent 649b799 commit 5bb8e9d

File tree

6 files changed

+3
-124
lines changed

6 files changed

+3
-124
lines changed

llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ enum class ARCRuntimeEntryPointKind {
4242
Autorelease,
4343
StoreStrong,
4444
RetainRV,
45-
ClaimRV,
4645
UnsafeClaimRV,
4746
RetainAutorelease,
4847
RetainAutoreleaseRV,
@@ -63,7 +62,6 @@ class ARCRuntimeEntryPoints {
6362
Autorelease = nullptr;
6463
StoreStrong = nullptr;
6564
RetainRV = nullptr;
66-
ClaimRV = nullptr;
6765
UnsafeClaimRV = nullptr;
6866
RetainAutorelease = nullptr;
6967
RetainAutoreleaseRV = nullptr;
@@ -89,9 +87,6 @@ class ARCRuntimeEntryPoints {
8987
case ARCRuntimeEntryPointKind::RetainRV:
9088
return getIntrinsicEntryPoint(RetainRV,
9189
Intrinsic::objc_retainAutoreleasedReturnValue);
92-
case ARCRuntimeEntryPointKind::ClaimRV:
93-
return getIntrinsicEntryPoint(
94-
ClaimRV, Intrinsic::objc_claimAutoreleasedReturnValue);
9590
case ARCRuntimeEntryPointKind::UnsafeClaimRV:
9691
return getIntrinsicEntryPoint(
9792
UnsafeClaimRV, Intrinsic::objc_unsafeClaimAutoreleasedReturnValue);
@@ -131,9 +126,6 @@ class ARCRuntimeEntryPoints {
131126
/// Declaration for objc_retainAutoreleasedReturnValue().
132127
Function *RetainRV = nullptr;
133128

134-
/// Declaration for objc_claimAutoreleasedReturnValue().
135-
Function *ClaimRV = nullptr;
136-
137129
/// Declaration for objc_unsafeClaimAutoreleasedReturnValue().
138130
Function *UnsafeClaimRV = nullptr;
139131

llvm/lib/Transforms/ObjCARC/ObjCARC.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -101,37 +101,8 @@ BundledRetainClaimRVs::~BundledRetainClaimRVs() {
101101
// can't be tail calls.
102102
if (auto *CI = dyn_cast<CallInst>(CB))
103103
CI->setTailCallKind(CallInst::TCK_NoTail);
104-
105-
// We can also do one final optimization: modify the bundle in the
106-
// annotated call, to change the bundle operand from
107-
// objc_retainAutoreleasedReturnValue
108-
// to:
109-
// objc_claimAutoreleasedReturnValue
110-
// allowing the marker to be omitted from the bundle expansion later.
111-
//
112-
// Note that, confusingly, ClaimRV is semantically equivalent to RetainRV,
113-
// and only differs in that it doesn't require the marker.
114-
// The bundle provides the guarantee that we're emitting the ClaimRV call
115-
// adjacent to the original call, and providing that guarantee is the
116-
// only difference between ClaimRV and RetainRV.
117-
//
118-
// UnsafeClaimRV has a different RC contract entirely.
119-
120-
// Find the clang.arc.attachedcall bundle, and rewrite its operand.
121-
if (UseClaimRV) {
122-
for (auto OBI : CB->bundle_op_infos()) {
123-
auto OBU = CB->operandBundleFromBundleOpInfo(OBI);
124-
if (OBU.getTagID() == LLVMContext::OB_clang_arc_attachedcall &&
125-
OBU.Inputs[0] == EP.get(ARCRuntimeEntryPointKind::RetainRV)) {
126-
CB->setOperand(OBI.Begin,
127-
EP.get(ARCRuntimeEntryPointKind::ClaimRV));
128-
break;
129-
}
130-
}
131-
}
132104
}
133105

134-
// Erase the RV call we emitted earlier: it's already in the bundle.
135106
EraseInstruction(P.first);
136107
}
137108

llvm/lib/Transforms/ObjCARC/ObjCARC.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_OBJCARC_H
2323
#define LLVM_LIB_TRANSFORMS_OBJCARC_OBJCARC_H
2424

25-
#include "ARCRuntimeEntryPoints.h"
2625
#include "llvm/Analysis/ObjCARCAnalysisUtils.h"
2726
#include "llvm/Analysis/ObjCARCUtil.h"
2827
#include "llvm/IR/EHPersonalities.h"
@@ -105,9 +104,7 @@ CallInst *createCallInstWithColors(
105104

106105
class BundledRetainClaimRVs {
107106
public:
108-
BundledRetainClaimRVs(ARCRuntimeEntryPoints &EP, bool ContractPass,
109-
bool UseClaimRV)
110-
: EP(EP), ContractPass(ContractPass), UseClaimRV(UseClaimRV) {}
107+
BundledRetainClaimRVs(bool ContractPass) : ContractPass(ContractPass) {}
111108
~BundledRetainClaimRVs();
112109

113110
/// Insert a retainRV/claimRV call to the normal destination blocks of invokes
@@ -158,9 +155,7 @@ class BundledRetainClaimRVs {
158155
/// A map of inserted retainRV/claimRV calls to annotated calls/invokes.
159156
DenseMap<CallInst *, CallBase *> RVCalls;
160157

161-
ARCRuntimeEntryPoints &EP;
162158
bool ContractPass;
163-
bool UseClaimRV;
164159
};
165160

166161
} // end namespace objcarc

llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "llvm/InitializePasses.h"
4343
#include "llvm/Support/Debug.h"
4444
#include "llvm/Support/raw_ostream.h"
45-
#include "llvm/TargetParser/Triple.h"
4645
#include "llvm/Transforms/ObjCARC.h"
4746

4847
using namespace llvm;
@@ -53,11 +52,6 @@ using namespace llvm::objcarc;
5352
STATISTIC(NumPeeps, "Number of calls peephole-optimized");
5453
STATISTIC(NumStoreStrongs, "Number objc_storeStrong calls formed");
5554

56-
static cl::opt<cl::boolOrDefault> UseObjCClaimRV(
57-
"arc-contract-use-objc-claim-rv",
58-
cl::desc(
59-
"Enable generation of calls to objc_claimAutoreleasedReturnValue"));
60-
6155
//===----------------------------------------------------------------------===//
6256
// Declarations
6357
//===----------------------------------------------------------------------===//
@@ -80,9 +74,6 @@ class ObjCARCContract {
8074
/// A flag indicating whether this optimization pass should run.
8175
bool Run;
8276

83-
/// Whether objc_claimAutoreleasedReturnValue is available.
84-
bool HasClaimRV = false;
85-
8677
/// The inline asm string to insert between calls and RetainRV calls to make
8778
/// the optimization work on targets which need it.
8879
const MDString *RVInstMarker;
@@ -526,39 +517,6 @@ bool ObjCARCContract::tryToPeepholeInstruction(
526517
}
527518
}
528519

529-
/// Should we use objc_claimAutoreleasedReturnValue?
530-
static bool useClaimRuntimeCall(Module &M) {
531-
// Let the flag override our OS-based default.
532-
if (UseObjCClaimRV != cl::BOU_UNSET)
533-
return UseObjCClaimRV == cl::BOU_TRUE;
534-
535-
Triple TT(M.getTargetTriple());
536-
537-
// On x86_64, claimARV doesn't make sense, as the marker isn't actually a nop
538-
// there (it's needed by the calling convention).
539-
if (!TT.isAArch64())
540-
return false;
541-
542-
unsigned Major = TT.getOSMajorVersion();
543-
switch (TT.getOS()) {
544-
default:
545-
return false;
546-
case Triple::IOS:
547-
case Triple::TvOS:
548-
return Major >= 16;
549-
case Triple::WatchOS:
550-
return Major >= 9;
551-
case Triple::BridgeOS:
552-
return Major >= 7;
553-
case Triple::MacOSX:
554-
return Major >= 13;
555-
case Triple::Darwin:
556-
return Major >= 21;
557-
}
558-
559-
return false;
560-
}
561-
562520
//===----------------------------------------------------------------------===//
563521
// Top Level Driver
564522
//===----------------------------------------------------------------------===//
@@ -570,8 +528,6 @@ bool ObjCARCContract::init(Module &M) {
570528

571529
EP.init(&M);
572530

573-
HasClaimRV = useClaimRuntimeCall(M);
574-
575531
// Initialize RVInstMarker.
576532
RVInstMarker = getRVInstMarker(M);
577533

@@ -589,7 +545,7 @@ bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) {
589545
AA = A;
590546
DT = D;
591547
PA.setAA(A);
592-
BundledRetainClaimRVs BRV(EP, /*ContractPass=*/true, HasClaimRV);
548+
BundledRetainClaimRVs BRV(/*ContractPass=*/true);
593549
BundledInsts = &BRV;
594550

595551
std::pair<bool, bool> R = BundledInsts->insertAfterInvokes(F, DT);

llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,7 @@ bool ObjCARCOpt::run(Function &F, AAResults &AA) {
24232423
return false;
24242424

24252425
Changed = CFGChanged = false;
2426-
BundledRetainClaimRVs BRV(EP, /*ContractPass=*/false, /*UseClaimRV=*/false);
2426+
BundledRetainClaimRVs BRV(/*ContractPass=*/false);
24272427
BundledInsts = &BRV;
24282428

24292429
LLVM_DEBUG(dbgs() << "<<< ObjCARCOpt: Visiting Function: " << F.getName()

llvm/test/Transforms/ObjCARC/contract-attached-call-retain-to-claim.ll

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)