Kill every call to @clang.arc.use in the ARC contract phase.
authorJohn McCall <rjmccall@apple.com>
Fri, 22 Mar 2013 21:38:36 +0000 (21:38 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 22 Mar 2013 21:38:36 +0000 (21:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177769 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/ObjCARC/DependencyAnalysis.cpp
lib/Transforms/ObjCARC/ObjCARC.h
lib/Transforms/ObjCARC/ObjCARCContract.cpp
lib/Transforms/ObjCARC/ObjCARCOpts.cpp
lib/Transforms/ObjCARC/ObjCARCUtil.cpp
test/Transforms/ObjCARC/contract.ll

index 5aada9c3734dc7a4dc708708162d228bc4b918eb..8f917aeb3725f0948b42dbc9bd7b9775f53f4685 100644 (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;
index e062b665554afaf2a66b89674b16c871a94aa9cf..61602260be32bec0c5413c295c2884d08a442bab 100644 (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 ||
index 1c13d1cbea42ba3150565717a2ac89114a862e61..5d0865e8bea2bf6dad3edc05e5c2489437c7640e 100644 (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;
     }
index 9c14949877f90c58e46d0e339d9c74adef287e21..0410b3bb79a5ec9c67e18a9f15e6f7ad1dd97d3a 100644 (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).
index a841c64a9f52a5e1d2a2893bfbbe7a8a1b1f3a42..0a54451bb1793e2e7ccc387d2d5f2ae2ccfbf084 100644 (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.
index b6fba59603458984c0a0a091c13cde0a7d7dbe40..0b60683d99951d52a427088abf7f763dbb8776f6 100644 (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 }