Skip to content

Commit c109808

Browse files
committed
Revert "Do not call replaceAllUsesWith to upgrade calls to ARC runtime functions"
This reverts commit r368634 because it broke a bot. llvm-svn: 368637
1 parent 4acb4ee commit c109808

File tree

4 files changed

+9
-91
lines changed

4 files changed

+9
-91
lines changed

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,8 +3855,6 @@ bool llvm::UpgradeRetainReleaseMarker(Module &M) {
38553855
}
38563856

38573857
void llvm::UpgradeARCRuntimeCalls(Module &M) {
3858-
// This lambda converts normal function calls to ARC runtime functions to
3859-
// intrinsic calls.
38603858
auto UpgradeToIntrinsic = [&](const char *OldFunc,
38613859
llvm::Intrinsic::ID IntrinsicFunc) {
38623860
Function *Fn = M.getFunction(OldFunc);
@@ -3865,43 +3863,11 @@ void llvm::UpgradeARCRuntimeCalls(Module &M) {
38653863
return;
38663864

38673865
Function *NewFn = llvm::Intrinsic::getDeclaration(&M, IntrinsicFunc);
3868-
for (Use &U : Fn->uses()) {
3869-
CallInst *CI = dyn_cast<CallInst>(U.getUser());
3870-
if (!CI || CI->getCalledFunction() != Fn)
3871-
continue;
3872-
3873-
IRBuilder<> Builder(CI->getParent(), CI->getIterator());
3874-
FunctionType *NewFuncTy = NewFn->getFunctionType();
3875-
SmallVector<Value *, 2> Args;
3876-
3877-
for (unsigned I = 0, E = CI->getNumArgOperands(); I != E; ++I) {
3878-
Value *Arg = CI->getArgOperand(I);
3879-
// Bitcast argument to the parameter type of the new function if it's
3880-
// not a variadic argument.
3881-
if (I < NewFuncTy->getNumParams())
3882-
Arg = Builder.CreateBitCast(Arg, NewFuncTy->getParamType(I));
3883-
Args.push_back(Arg);
3884-
}
3885-
3886-
// Create a call instruction that calls the new function.
3887-
CallInst *NewCall = Builder.CreateCall(NewFuncTy, NewFn, Args);
3888-
NewCall->setTailCallKind(cast<CallInst>(CI)->getTailCallKind());
3889-
NewCall->setName(CI->getName());
3890-
3891-
// Bitcast the return value back to the type of the old call.
3892-
Value *NewRetVal = Builder.CreateBitCast(NewCall, CI->getType());
3893-
3894-
if (!CI->use_empty())
3895-
CI->replaceAllUsesWith(NewRetVal);
3896-
CI->eraseFromParent();
3897-
}
3898-
3899-
if (Fn->use_empty())
3900-
Fn->eraseFromParent();
3866+
Fn->replaceAllUsesWith(NewFn);
3867+
Fn->eraseFromParent();
39013868
};
39023869

3903-
// Unconditionally convert a call to "clang.arc.use" to a call to
3904-
// "llvm.objc.clang.arc.use".
3870+
// Unconditionally convert "clang.arc.use" to "llvm.objc.clang.arc.use".
39053871
UpgradeToIntrinsic("clang.arc.use", llvm::Intrinsic::objc_clang_arc_use);
39063872

39073873
// Return if the bitcode doesn't have the arm64 retainAutoreleasedReturnValue
-144 Bytes
Binary file not shown.

llvm/test/Bitcode/upgrade-arc-runtime-calls.ll

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,14 @@
88
; RUN: llvm-dis < %S/upgrade-arc-runtime-calls.bc | FileCheck -check-prefixes=ARC %s
99
; RUN: llvm-dis < %S/upgrade-mrr-runtime-calls.bc | FileCheck -check-prefixes=MRR %s
1010

11-
define void @testRuntimeCalls(i8* %a, i8** %b, i8** %c, i32* %d, i32** %e) personality i32 (...)* @__gxx_personality_v0 {
12-
entry:
13-
%v0 = tail call i8* @objc_autorelease(i8* %a) #0
14-
tail call void @objc_autoreleasePoolPop(i8* %a) #0
15-
%v1 = tail call i8* @objc_autoreleasePoolPush() #0
16-
%v2 = tail call i8* @objc_autoreleaseReturnValue(i8* %a) #0
17-
tail call void @objc_copyWeak(i8** %b, i8** %c) #0
18-
tail call void @objc_destroyWeak(i8** %b) #0
19-
%v3 = tail call i32* @objc_initWeak(i32** %e, i32* %d) #0
20-
%v4 = tail call i8* @objc_loadWeak(i8** %b) #0
21-
%v5 = tail call i8* @objc_loadWeakRetained(i8** %b) #0
22-
tail call void @objc_moveWeak(i8** %b, i8** %c) #0
23-
tail call void @objc_release(i8* %a) #0
24-
%v6 = tail call i8* @objc_retain(i8* %a) #0
25-
%v7 = tail call i8* @objc_retainAutorelease(i8* %a) #0
26-
%v8 = tail call i8* @objc_retainAutoreleaseReturnValue(i8* %a) #0
27-
%v9 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %a) #0
28-
%v10 = tail call i8* @objc_retainBlock(i8* %a) #0
29-
tail call void @objc_storeStrong(i8** %b, i8* %a) #0
30-
%v11 = tail call i8* @objc_storeWeak(i8** %b, i8* %a) #0
31-
tail call void (...) @clang.arc.use(i8* %a) #0
32-
%v12 = tail call i8* @objc_unsafeClaimAutoreleasedReturnValue(i8* %a) #0
33-
%v13 = tail call i8* @objc_retainedObject(i8* %a) #0
34-
%v14 = tail call i8* @objc_unretainedObject(i8* %a) #0
35-
%v15 = tail call i8* @objc_unretainedPointer(i8* %a) #0
36-
%v16 = tail call i8* @objc_retain.autorelease(i8* %a) #0
37-
%v17 = tail call i32 @objc_sync.enter(i8* %a) #0
38-
%v18 = tail call i32 @objc_sync.exit(i8* %a) #0
39-
tail call void @objc_arc_annotation_topdown_bbstart(i8** %b, i8** %c) #0
40-
tail call void @objc_arc_annotation_topdown_bbend(i8** %b, i8** %c) #0
41-
tail call void @objc_arc_annotation_bottomup_bbstart(i8** %b, i8** %c) #0
42-
tail call void @objc_arc_annotation_bottomup_bbend(i8** %b, i8** %c) #0
43-
invoke void @objc_autoreleasePoolPop(i8* %a)
44-
to label %normalBlock unwind label %unwindBlock
45-
normalBlock:
46-
ret void
47-
unwindBlock:
48-
%ll = landingpad { i8*, i32 }
49-
cleanup
50-
ret void
51-
}
52-
53-
// Check that auto-upgrader converts function calls to intrinsic calls. Note that
54-
// the auto-upgrader doesn't touch invoke instructions.
55-
56-
// ARC: define void @testRuntimeCalls(i8* %[[A:.*]], i8** %[[B:.*]], i8** %[[C:.*]], i32* %[[D:.*]], i32** %[[E:.*]]) personality
11+
// ARC: define void @testRuntimeCalls(i8* %[[A:.*]], i8** %[[B:.*]], i8** %[[C:.*]]) {
5712
// ARC: %[[V0:.*]] = tail call i8* @llvm.objc.autorelease(i8* %[[A]])
5813
// ARC-NEXT: tail call void @llvm.objc.autoreleasePoolPop(i8* %[[A]])
5914
// ARC-NEXT: %[[V1:.*]] = tail call i8* @llvm.objc.autoreleasePoolPush()
6015
// ARC-NEXT: %[[V2:.*]] = tail call i8* @llvm.objc.autoreleaseReturnValue(i8* %[[A]])
6116
// ARC-NEXT: tail call void @llvm.objc.copyWeak(i8** %[[B]], i8** %[[C]])
6217
// ARC-NEXT: tail call void @llvm.objc.destroyWeak(i8** %[[B]])
63-
// ARC-NEXT: %[[V100:.*]] = bitcast i32** %[[E]] to i8**
64-
// ARC-NEXT: %[[V101:.*]] = bitcast i32* %[[D]] to i8*
65-
// ARC-NEXT: %[[V102:.*]] = tail call i8* @llvm.objc.initWeak(i8** %[[V100]], i8* %[[V101]])
66-
// ARC-NEXT: %[[V103:.*]] = bitcast i8* %[[V102]] to i32*
18+
// ARC-NEXT: %[[V3:.*]] = tail call i8* @llvm.objc.initWeak(i8** %[[B]], i8* %[[A]])
6719
// ARC-NEXT: %[[V4:.*]] = tail call i8* @llvm.objc.loadWeak(i8** %[[B]])
6820
// ARC-NEXT: %[[V5:.*]] = tail call i8* @llvm.objc.loadWeakRetained(i8** %[[B]])
6921
// ARC-NEXT: tail call void @llvm.objc.moveWeak(i8** %[[B]], i8** %[[C]])
@@ -87,16 +39,16 @@ unwindBlock:
8739
// ARC-NEXT: tail call void @llvm.objc.arc.annotation.topdown.bbend(i8** %[[B]], i8** %[[C]])
8840
// ARC-NEXT: tail call void @llvm.objc.arc.annotation.bottomup.bbstart(i8** %[[B]], i8** %[[C]])
8941
// ARC-NEXT: tail call void @llvm.objc.arc.annotation.bottomup.bbend(i8** %[[B]], i8** %[[C]])
90-
// ARC-NEXT: invoke void @objc_autoreleasePoolPop(i8* %[[A]])
42+
// ARC-NEXT: ret void
9143

92-
// MRR: define void @testRuntimeCalls(i8* %[[A:.*]], i8** %[[B:.*]], i8** %[[C:.*]], i32* %[[D:.*]], i32** %[[E:.*]]) personality
44+
// MRR: define void @testRuntimeCalls(i8* %[[A:.*]], i8** %[[B:.*]], i8** %[[C:.*]]) {
9345
// MRR: %[[V0:.*]] = tail call i8* @objc_autorelease(i8* %[[A]])
9446
// MRR-NEXT: tail call void @objc_autoreleasePoolPop(i8* %[[A]])
9547
// MRR-NEXT: %[[V1:.*]] = tail call i8* @objc_autoreleasePoolPush()
9648
// MRR-NEXT: %[[V2:.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* %[[A]])
9749
// MRR-NEXT: tail call void @objc_copyWeak(i8** %[[B]], i8** %[[C]])
9850
// MRR-NEXT: tail call void @objc_destroyWeak(i8** %[[B]])
99-
// MRR-NEXT: %[[V3:.*]] = tail call i32* @objc_initWeak(i32** %[[E]], i32* %[[D]])
51+
// MRR-NEXT: %[[V3:.*]] = tail call i8* @objc_initWeak(i8** %[[B]], i8* %[[A]])
10052
// MRR-NEXT: %[[V4:.*]] = tail call i8* @objc_loadWeak(i8** %[[B]])
10153
// MRR-NEXT: %[[V5:.*]] = tail call i8* @objc_loadWeakRetained(i8** %[[B]])
10254
// MRR-NEXT: tail call void @objc_moveWeak(i8** %[[B]], i8** %[[C]])
@@ -120,4 +72,4 @@ unwindBlock:
12072
// MRR-NEXT: tail call void @objc_arc_annotation_topdown_bbend(i8** %[[B]], i8** %[[C]])
12173
// MRR-NEXT: tail call void @objc_arc_annotation_bottomup_bbstart(i8** %[[B]], i8** %[[C]])
12274
// MRR-NEXT: tail call void @objc_arc_annotation_bottomup_bbend(i8** %[[B]], i8** %[[C]])
123-
// MRR-NEXT: invoke void @objc_autoreleasePoolPop(i8* %[[A]])
75+
// MRR-NEXT: ret void
-160 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)