mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-12 01:25:49 +00:00
[objc-arc] Teach the ARC optimizer that objc_sync_enter/objc_sync_exit do not modify the ref count of an objc object and additionally are inert for modref purposes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185769 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -150,6 +150,14 @@ ObjCARCAliasAnalysis::getModRefInfo(ImmutableCallSite CS, const Location &Loc) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle special objective c calls defaulting to chaining.
|
||||||
|
const Function *F = CS.getCalledFunction();
|
||||||
|
if (F)
|
||||||
|
return StringSwitch<AliasAnalysis::ModRefResult>(F->getName())
|
||||||
|
.Case("objc_sync_start", NoModRef)
|
||||||
|
.Case("objc_sync_stop", NoModRef)
|
||||||
|
.Default(AliasAnalysis::getModRefInfo(CS, Loc));
|
||||||
|
|
||||||
return AliasAnalysis::getModRefInfo(CS, Loc);
|
return AliasAnalysis::getModRefInfo(CS, Loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -112,6 +112,8 @@ InstructionClass llvm::objcarc::GetFunctionClass(const Function *F) {
|
|||||||
.Case("objc_retain_autorelease", IC_FusedRetainAutorelease)
|
.Case("objc_retain_autorelease", IC_FusedRetainAutorelease)
|
||||||
.Case("objc_retainAutorelease", IC_FusedRetainAutorelease)
|
.Case("objc_retainAutorelease", IC_FusedRetainAutorelease)
|
||||||
.Case("objc_retainAutoreleaseReturnValue",IC_FusedRetainAutoreleaseRV)
|
.Case("objc_retainAutoreleaseReturnValue",IC_FusedRetainAutoreleaseRV)
|
||||||
|
.Case("objc_sync_enter", IC_User)
|
||||||
|
.Case("objc_sync_exit", IC_User)
|
||||||
.Default(IC_CallOrUser);
|
.Default(IC_CallOrUser);
|
||||||
|
|
||||||
// Argument is i8**
|
// Argument is i8**
|
||||||
|
@@ -3037,9 +3037,28 @@ end: ; preds = %if.end125, %if.end1
|
|||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
!0 = metadata !{}
|
|
||||||
|
|
||||||
declare i32 @__gxx_personality_v0(...)
|
declare i32 @__gxx_personality_v0(...)
|
||||||
|
|
||||||
|
declare i32 @objc_sync_enter(i8*)
|
||||||
|
declare i32 @objc_sync_exit(i8*)
|
||||||
|
|
||||||
|
; Make sure that we understand that objc_sync_{enter,exit} are IC_User not
|
||||||
|
; IC_Call/IC_CallOrUser.
|
||||||
|
|
||||||
|
; CHECK: define void @test67
|
||||||
|
; CHECK-NEXT: call i32 @objc_sync_enter(i8* %x)
|
||||||
|
; CHECK-NEXT: call i32 @objc_sync_exit(i8* %x)
|
||||||
|
; CHECK-NEXT: ret void
|
||||||
|
; CHECK-NEXT: }
|
||||||
|
define void @test67(i8* %x) {
|
||||||
|
call i8* @objc_retain(i8* %x)
|
||||||
|
call i32 @objc_sync_enter(i8* %x)
|
||||||
|
call i32 @objc_sync_exit(i8* %x)
|
||||||
|
call void @objc_release(i8* %x), !clang.imprecise_release !0
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
!0 = metadata !{}
|
||||||
|
|
||||||
; CHECK: attributes #0 = { nounwind readnone }
|
; CHECK: attributes #0 = { nounwind readnone }
|
||||||
; CHECK: attributes [[NUW]] = { nounwind }
|
; CHECK: attributes [[NUW]] = { nounwind }
|
||||||
|
@@ -3,20 +3,38 @@
|
|||||||
@x = common global i8* null, align 8
|
@x = common global i8* null, align 8
|
||||||
|
|
||||||
declare i8* @objc_retain(i8*)
|
declare i8* @objc_retain(i8*)
|
||||||
|
declare i32 @objc_sync_start(i8*)
|
||||||
|
declare i32 @objc_sync_stop(i8*)
|
||||||
|
|
||||||
; GVN should be able to eliminate this redundant load, with ARC-specific
|
; GVN should be able to eliminate this redundant load, with ARC-specific
|
||||||
; alias analysis.
|
; alias analysis.
|
||||||
|
|
||||||
; CHECK: define i8* @foo(i32 %n)
|
; CHECK: define i8* @test0(i32 %n)
|
||||||
; CHECK-NEXT: entry:
|
; CHECK-NEXT: entry:
|
||||||
; CHECK-NEXT: %s = load i8** @x
|
; CHECK-NEXT: %s = load i8** @x
|
||||||
; CHECK-NOT: load
|
; CHECK-NOT: load
|
||||||
; CHECK: ret i8* %s
|
; CHECK: ret i8* %s
|
||||||
; CHECK-NEXT: }
|
; CHECK-NEXT: }
|
||||||
define i8* @foo(i32 %n) nounwind {
|
define i8* @test0(i32 %n) nounwind {
|
||||||
entry:
|
entry:
|
||||||
%s = load i8** @x
|
%s = load i8** @x
|
||||||
%0 = tail call i8* @objc_retain(i8* %s) nounwind
|
%0 = tail call i8* @objc_retain(i8* %s) nounwind
|
||||||
%t = load i8** @x
|
%t = load i8** @x
|
||||||
ret i8* %s
|
ret i8* %t
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK: define i8* @test1(i32 %n)
|
||||||
|
; CHECK-NEXT: entry:
|
||||||
|
; CHECK-NEXT: %s = load i8** @x
|
||||||
|
; CHECK-NEXT: call i32 @objc_sync_start
|
||||||
|
; CHECK-NEXT: call i32 @objc_sync_stop
|
||||||
|
; CHECK-NEXT: ret i8* %s
|
||||||
|
; CHECK-NEXT: }
|
||||||
|
define i8* @test1(i32 %n) nounwind {
|
||||||
|
entry:
|
||||||
|
%s = load i8** @x
|
||||||
|
%0 = call i32 @objc_sync_start(i8* %s)
|
||||||
|
%t = load i8** @x
|
||||||
|
%1 = call i32 @objc_sync_stop(i8* %s)
|
||||||
|
ret i8* %t
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user