Skip to content

Commit 9e51fb6

Browse files
[AutoUpgrader] Make ArcRuntime Autoupgrader more conservative
Summary: This is a tweak to r368311 and r368646 which auto upgrades the calls to objc runtime functions to objc runtime intrinsics, in order to make sure that the auto upgrader does not trigger with up-to-date bitcode. It is possible for bitcode that is up-to-date to contain direct calls to objc runtime function and those are not inserted by compiler as part of ARC and they should not be upgraded. Now auto upgrader only triggers as when the old style of ARC marker is used so it is guaranteed that it won't trigger on update-to-date bitcode. This also means it won't do this upgrade for bitcode from llvm-8 and llvm-9, which preserves the behavior of those releases. Ideally they should be upgraded as well but it is more important to make sure AutoUpgrader will not trigger on up-to-date bitcode. Reviewers: ahatanak, rjmccall, dexonsmith, pete Reviewed By: dexonsmith Subscribers: hiraditya, jkorous, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66153 llvm-svn: 368730
1 parent bbccb94 commit 9e51fb6

File tree

5 files changed

+48
-48
lines changed

5 files changed

+48
-48
lines changed

llvm/include/llvm/IR/AutoUpgrade.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,9 @@ namespace llvm {
5454
/// module is modified.
5555
bool UpgradeModuleFlags(Module &M);
5656

57-
/// This checks for objc retain release marker which should be upgraded. It
58-
/// returns true if module is modified.
59-
bool UpgradeRetainReleaseMarker(Module &M);
60-
61-
/// Convert calls to ARC runtime functions to intrinsic calls if the bitcode
62-
/// has the arm64 retainAutoreleasedReturnValue marker.
63-
void UpgradeARCRuntimeCalls(Module &M);
57+
/// Convert calls to ARC runtime functions to intrinsic calls and upgrade the
58+
/// old retain release marker to new module flag format.
59+
void UpgradeARCRuntime(Module &M);
6460

6561
void UpgradeSectionAttributes(Module &M);
6662

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5312,8 +5312,7 @@ Error BitcodeReader::materializeModule() {
53125312

53135313
UpgradeModuleFlags(*TheModule);
53145314

5315-
UpgradeRetainReleaseMarker(*TheModule);
5316-
UpgradeARCRuntimeCalls(*TheModule);
5315+
UpgradeARCRuntime(*TheModule);
53175316

53185317
return Error::success();
53195318
}

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3830,7 +3830,9 @@ bool llvm::UpgradeDebugInfo(Module &M) {
38303830
return Modified;
38313831
}
38323832

3833-
bool llvm::UpgradeRetainReleaseMarker(Module &M) {
3833+
/// This checks for objc retain release marker which should be upgraded. It
3834+
/// returns true if module is modified.
3835+
static bool UpgradeRetainReleaseMarker(Module &M) {
38343836
bool Changed = false;
38353837
const char *MarkerKey = "clang.arc.retainAutoreleasedReturnValueMarker";
38363838
NamedMDNode *ModRetainReleaseMarker = M.getNamedMetadata(MarkerKey);
@@ -3854,7 +3856,7 @@ bool llvm::UpgradeRetainReleaseMarker(Module &M) {
38543856
return Changed;
38553857
}
38563858

3857-
void llvm::UpgradeARCRuntimeCalls(Module &M) {
3859+
void llvm::UpgradeARCRuntime(Module &M) {
38583860
// This lambda converts normal function calls to ARC runtime functions to
38593861
// intrinsic calls.
38603862
auto UpgradeToIntrinsic = [&](const char *OldFunc,
@@ -3905,9 +3907,10 @@ void llvm::UpgradeARCRuntimeCalls(Module &M) {
39053907
// "llvm.objc.clang.arc.use".
39063908
UpgradeToIntrinsic("clang.arc.use", llvm::Intrinsic::objc_clang_arc_use);
39073909

3908-
// Return if the bitcode doesn't have the arm64 retainAutoreleasedReturnValue
3909-
// marker. We don't know for sure that it was compiled with ARC in that case.
3910-
if (!M.getModuleFlag("clang.arc.retainAutoreleasedReturnValueMarker"))
3910+
// Upgrade the retain release marker. If there is no need to upgrade
3911+
// the marker, that means either the module is already new enough to contain
3912+
// new intrinsics or it is not ARC. There is no need to upgrade runtime call.
3913+
if (!UpgradeRetainReleaseMarker(M))
39113914
return;
39123915

39133916
std::pair<const char *, llvm::Intrinsic::ID> RuntimeFuncs[] = {
Binary file not shown.

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

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
; upgrade-arc-runtime-calls.bc and upgrade-mrr-runtime-calls.bc are identical
55
; except that the former has the arm64 retainAutoreleasedReturnValueMarker
6-
; metadata.
6+
; metadata. upgrade-arc-runtime-calls-new.bc has the new module flag format of
7+
; marker, it should not be upgraded.
78

89
; RUN: llvm-dis < %S/upgrade-arc-runtime-calls.bc | FileCheck -check-prefixes=ARC %s
9-
; RUN: llvm-dis < %S/upgrade-mrr-runtime-calls.bc | FileCheck -check-prefixes=MRR %s
10+
; RUN: llvm-dis < %S/upgrade-mrr-runtime-calls.bc | FileCheck -check-prefixes=NOUPGRADE %s
11+
; RUN: llvm-dis < %S/upgrade-arc-runtime-calls-new.bc | FileCheck -check-prefixes=NOUPGRADE %s
1012

1113
define void @testRuntimeCalls(i8* %a, i8** %b, i8** %c, i32* %d, i32** %e) personality i32 (...)* @__gxx_personality_v0 {
1214
entry:
@@ -89,35 +91,35 @@ unwindBlock:
8991
// ARC-NEXT: tail call void @llvm.objc.arc.annotation.bottomup.bbend(i8** %[[B]], i8** %[[C]])
9092
// ARC-NEXT: invoke void @objc_autoreleasePoolPop(i8* %[[A]])
9193

92-
// MRR: define void @testRuntimeCalls(i8* %[[A:.*]], i8** %[[B:.*]], i8** %[[C:.*]], i32* %[[D:.*]], i32** %[[E:.*]]) personality
93-
// MRR: %[[V0:.*]] = tail call i8* @objc_autorelease(i8* %[[A]])
94-
// MRR-NEXT: tail call void @objc_autoreleasePoolPop(i8* %[[A]])
95-
// MRR-NEXT: %[[V1:.*]] = tail call i8* @objc_autoreleasePoolPush()
96-
// MRR-NEXT: %[[V2:.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* %[[A]])
97-
// MRR-NEXT: tail call void @objc_copyWeak(i8** %[[B]], i8** %[[C]])
98-
// MRR-NEXT: tail call void @objc_destroyWeak(i8** %[[B]])
99-
// MRR-NEXT: %[[V3:.*]] = tail call i32* @objc_initWeak(i32** %[[E]], i32* %[[D]])
100-
// MRR-NEXT: %[[V4:.*]] = tail call i8* @objc_loadWeak(i8** %[[B]])
101-
// MRR-NEXT: %[[V5:.*]] = tail call i8* @objc_loadWeakRetained(i8** %[[B]])
102-
// MRR-NEXT: tail call void @objc_moveWeak(i8** %[[B]], i8** %[[C]])
103-
// MRR-NEXT: tail call void @objc_release(i8* %[[A]])
104-
// MRR-NEXT: %[[V6:.*]] = tail call i8* @objc_retain(i8* %[[A]])
105-
// MRR-NEXT: %[[V7:.*]] = tail call i8* @objc_retainAutorelease(i8* %[[A]])
106-
// MRR-NEXT: %[[V8:.*]] = tail call i8* @objc_retainAutoreleaseReturnValue(i8* %[[A]])
107-
// MRR-NEXT: %[[V9:.*]] = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %[[A]])
108-
// MRR-NEXT: %[[V10:.*]] = tail call i8* @objc_retainBlock(i8* %[[A]])
109-
// MRR-NEXT: tail call void @objc_storeStrong(i8** %[[B]], i8* %[[A]])
110-
// MRR-NEXT: %[[V11:.*]] = tail call i8* @objc_storeWeak(i8** %[[B]], i8* %[[A]])
111-
// MRR-NEXT: tail call void (...) @llvm.objc.clang.arc.use(i8* %[[A]])
112-
// MRR-NEXT: %[[V12:.*]] = tail call i8* @objc_unsafeClaimAutoreleasedReturnValue(i8* %[[A]])
113-
// MRR-NEXT: %[[V13:.*]] = tail call i8* @objc_retainedObject(i8* %[[A]])
114-
// MRR-NEXT: %[[V14:.*]] = tail call i8* @objc_unretainedObject(i8* %[[A]])
115-
// MRR-NEXT: %[[V15:.*]] = tail call i8* @objc_unretainedPointer(i8* %[[A]])
116-
// MRR-NEXT: %[[V16:.*]] = tail call i8* @objc_retain.autorelease(i8* %[[A]])
117-
// MRR-NEXT: %[[V17:.*]] = tail call i32 @objc_sync.enter(i8* %[[A]])
118-
// MRR-NEXT: %[[V18:.*]] = tail call i32 @objc_sync.exit(i8* %[[A]])
119-
// MRR-NEXT: tail call void @objc_arc_annotation_topdown_bbstart(i8** %[[B]], i8** %[[C]])
120-
// MRR-NEXT: tail call void @objc_arc_annotation_topdown_bbend(i8** %[[B]], i8** %[[C]])
121-
// MRR-NEXT: tail call void @objc_arc_annotation_bottomup_bbstart(i8** %[[B]], i8** %[[C]])
122-
// MRR-NEXT: tail call void @objc_arc_annotation_bottomup_bbend(i8** %[[B]], i8** %[[C]])
123-
// MRR-NEXT: invoke void @objc_autoreleasePoolPop(i8* %[[A]])
94+
// NOUPGRADE: define void @testRuntimeCalls(i8* %[[A:.*]], i8** %[[B:.*]], i8** %[[C:.*]], i32* %[[D:.*]], i32** %[[E:.*]]) personality
95+
// NOUPGRADE: %[[V0:.*]] = tail call i8* @objc_autorelease(i8* %[[A]])
96+
// NOUPGRADE-NEXT: tail call void @objc_autoreleasePoolPop(i8* %[[A]])
97+
// NOUPGRADE-NEXT: %[[V1:.*]] = tail call i8* @objc_autoreleasePoolPush()
98+
// NOUPGRADE-NEXT: %[[V2:.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* %[[A]])
99+
// NOUPGRADE-NEXT: tail call void @objc_copyWeak(i8** %[[B]], i8** %[[C]])
100+
// NOUPGRADE-NEXT: tail call void @objc_destroyWeak(i8** %[[B]])
101+
// NOUPGRADE-NEXT: %[[V3:.*]] = tail call i32* @objc_initWeak(i32** %[[E]], i32* %[[D]])
102+
// NOUPGRADE-NEXT: %[[V4:.*]] = tail call i8* @objc_loadWeak(i8** %[[B]])
103+
// NOUPGRADE-NEXT: %[[V5:.*]] = tail call i8* @objc_loadWeakRetained(i8** %[[B]])
104+
// NOUPGRADE-NEXT: tail call void @objc_moveWeak(i8** %[[B]], i8** %[[C]])
105+
// NOUPGRADE-NEXT: tail call void @objc_release(i8* %[[A]])
106+
// NOUPGRADE-NEXT: %[[V6:.*]] = tail call i8* @objc_retain(i8* %[[A]])
107+
// NOUPGRADE-NEXT: %[[V7:.*]] = tail call i8* @objc_retainAutorelease(i8* %[[A]])
108+
// NOUPGRADE-NEXT: %[[V8:.*]] = tail call i8* @objc_retainAutoreleaseReturnValue(i8* %[[A]])
109+
// NOUPGRADE-NEXT: %[[V9:.*]] = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %[[A]])
110+
// NOUPGRADE-NEXT: %[[V10:.*]] = tail call i8* @objc_retainBlock(i8* %[[A]])
111+
// NOUPGRADE-NEXT: tail call void @objc_storeStrong(i8** %[[B]], i8* %[[A]])
112+
// NOUPGRADE-NEXT: %[[V11:.*]] = tail call i8* @objc_storeWeak(i8** %[[B]], i8* %[[A]])
113+
// NOUPGRADE-NEXT: tail call void (...) @llvm.objc.clang.arc.use(i8* %[[A]])
114+
// NOUPGRADE-NEXT: %[[V12:.*]] = tail call i8* @objc_unsafeClaimAutoreleasedReturnValue(i8* %[[A]])
115+
// NOUPGRADE-NEXT: %[[V13:.*]] = tail call i8* @objc_retainedObject(i8* %[[A]])
116+
// NOUPGRADE-NEXT: %[[V14:.*]] = tail call i8* @objc_unretainedObject(i8* %[[A]])
117+
// NOUPGRADE-NEXT: %[[V15:.*]] = tail call i8* @objc_unretainedPointer(i8* %[[A]])
118+
// NOUPGRADE-NEXT: %[[V16:.*]] = tail call i8* @objc_retain.autorelease(i8* %[[A]])
119+
// NOUPGRADE-NEXT: %[[V17:.*]] = tail call i32 @objc_sync.enter(i8* %[[A]])
120+
// NOUPGRADE-NEXT: %[[V18:.*]] = tail call i32 @objc_sync.exit(i8* %[[A]])
121+
// NOUPGRADE-NEXT: tail call void @objc_arc_annotation_topdown_bbstart(i8** %[[B]], i8** %[[C]])
122+
// NOUPGRADE-NEXT: tail call void @objc_arc_annotation_topdown_bbend(i8** %[[B]], i8** %[[C]])
123+
// NOUPGRADE-NEXT: tail call void @objc_arc_annotation_bottomup_bbstart(i8** %[[B]], i8** %[[C]])
124+
// NOUPGRADE-NEXT: tail call void @objc_arc_annotation_bottomup_bbend(i8** %[[B]], i8** %[[C]])
125+
// NOUPGRADE-NEXT: invoke void @objc_autoreleasePoolPop(i8* %[[A]])

0 commit comments

Comments
 (0)