Kill every call to @clang.arc.use in the ARC contract phase.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177769 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
John McCall 2013-03-22 21:38:36 +00:00
parent 46125e1a8b
commit 1f9c4407c0
6 changed files with 33 additions and 3 deletions

View File

@ -38,6 +38,7 @@ llvm::objcarc::CanAlterRefCount(const Instruction *Inst, const Value *Ptr,
switch (Class) {
case IC_Autorelease:
case IC_AutoreleaseRV:
case IC_IntrinsicUser:
case IC_User:
// These operations never directly modify a reference count.
return false;

View File

@ -89,6 +89,7 @@ enum InstructionClass {
IC_CopyWeak, ///< objc_copyWeak (derived)
IC_DestroyWeak, ///< objc_destroyWeak (derived)
IC_StoreStrong, ///< objc_storeStrong (derived)
IC_IntrinsicUser, ///< clang.arc.use
IC_CallOrUser, ///< could call objc_release and/or "use" pointers
IC_Call, ///< could call objc_release
IC_User, ///< could "use" a pointer
@ -97,6 +98,13 @@ enum InstructionClass {
raw_ostream &operator<<(raw_ostream &OS, const InstructionClass Class);
/// \brief Test if the given class is a kind of user.
inline static bool IsUser(InstructionClass Class) {
return Class == IC_User ||
Class == IC_CallOrUser ||
Class == IC_IntrinsicUser;
}
/// \brief Test if the given class is objc_retain or equivalent.
static inline bool IsRetain(InstructionClass Class) {
return Class == IC_Retain ||

View File

@ -453,6 +453,10 @@ bool ObjCARCContract::runOnFunction(Function &F) {
if (isa<AllocaInst>(Inst))
TailOkForStoreStrongs = false;
continue;
case IC_IntrinsicUser:
// Remove calls to @clang.arc.use(...).
Inst->eraseFromParent();
continue;
default:
continue;
}

View File

@ -211,6 +211,9 @@ static bool DoesRetainableObjPtrEscape(const User *Ptr) {
// These special functions make copies of their pointer arguments.
return true;
}
case IC_IntrinsicUser:
// Use by the use intrinsic is not an escape.
continue;
case IC_User:
case IC_None:
// Use by an instruction which copies the value is an escape if the
@ -1601,8 +1604,7 @@ ObjCARCOpt::VisitInstructionBottomUp(Instruction *Inst,
else
S.RRI.ReverseInsertPts.insert(llvm::next(BasicBlock::iterator(Inst)));
S.SetSeq(S_Use);
} else if (Seq == S_Release &&
(Class == IC_User || Class == IC_CallOrUser)) {
} else if (Seq == S_Release && IsUser(Class)) {
// Non-movable releases depend on any possible objc pointer use.
S.SetSeq(S_Stop);
assert(S.RRI.ReverseInsertPts.empty());
@ -2392,6 +2394,7 @@ void ObjCARCOpt::OptimizeWeakCalls(Function &F) {
goto clobbered;
case IC_AutoreleasepoolPush:
case IC_None:
case IC_IntrinsicUser:
case IC_User:
// Weak pointers are only modified through the weak entry points
// (and arbitrary calls, which could call the weak entry points).

View File

@ -72,6 +72,8 @@ raw_ostream &llvm::objcarc::operator<<(raw_ostream &OS,
return OS << "IC_Call";
case IC_User:
return OS << "IC_User";
case IC_IntrinsicUser:
return OS << "IC_IntrinsicUser";
case IC_None:
return OS << "IC_None";
}
@ -81,10 +83,11 @@ raw_ostream &llvm::objcarc::operator<<(raw_ostream &OS,
InstructionClass llvm::objcarc::GetFunctionClass(const Function *F) {
Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
// No arguments.
// No (mandatory) arguments.
if (AI == AE)
return StringSwitch<InstructionClass>(F->getName())
.Case("objc_autoreleasePoolPush", IC_AutoreleasepoolPush)
.Case("clang.arc.use", IC_IntrinsicUser)
.Default(IC_CallOrUser);
// One argument.

View File

@ -162,4 +162,15 @@ return: ; preds = %if.then, %entry
ret i8* %retval
}
; Kill calls to @clang.arc.use(...)
; CHECK: define void @test9(
; CHECK-NOT: clang.arc.use
; CHECK: }
define void @test9(i8* %a, i8* %b) {
call void (...)* @clang.arc.use(i8* %a, i8* %b) nounwind
ret void
}
declare void @clang.arc.use(...) nounwind
; CHECK: attributes [[NUW]] = { nounwind }