[llvm] r349558 - Add nonlazybind to objc_retain/objc_release when converting from intrinsics.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 18 14:31:34 PST 2018


Author: pete
Date: Tue Dec 18 14:31:34 2018
New Revision: 349558

URL: http://llvm.org/viewvc/llvm-project?rev=349558&view=rev
Log:
Add nonlazybind to objc_retain/objc_release when converting from intrinsics.

For performance reasons, clang set nonlazybind on these functions.  Now that we
are using intrinsics instead of runtime calls, we should set this attribute when
creating the runtime functions.

Modified:
    llvm/trunk/lib/CodeGen/PreISelIntrinsicLowering.cpp
    llvm/trunk/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll

Modified: llvm/trunk/lib/CodeGen/PreISelIntrinsicLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PreISelIntrinsicLowering.cpp?rev=349558&r1=349557&r2=349558&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PreISelIntrinsicLowering.cpp (original)
+++ llvm/trunk/lib/CodeGen/PreISelIntrinsicLowering.cpp Tue Dec 18 14:31:34 2018
@@ -57,7 +57,8 @@ static bool lowerLoadRelative(Function &
   return Changed;
 }
 
-static bool lowerObjCCall(Function &F, const char *NewFn) {
+static bool lowerObjCCall(Function &F, const char *NewFn,
+                          bool setNonLazyBind = false) {
   if (F.use_empty())
     return false;
 
@@ -65,6 +66,12 @@ static bool lowerObjCCall(Function &F, c
   // program already contains a function with this name.
   Module *M = F.getParent();
   Constant* FCache = M->getOrInsertFunction(NewFn, F.getFunctionType());
+  
+  // If we have Native ARC, set nonlazybind attribute for these APIs for
+  // performance.
+  if (setNonLazyBind)
+    if (Function* Fn = dyn_cast<Function>(FCache))
+      Fn->addFnAttr(Attribute::NonLazyBind);
 
   for (auto I = F.use_begin(), E = F.use_end(); I != E;) {
     auto *CI = dyn_cast<CallInst>(I->getUser());
@@ -125,10 +132,10 @@ static bool lowerIntrinsics(Module &M) {
       Changed |= lowerObjCCall(F, "objc_moveWeak");
       break;
     case Intrinsic::objc_release:
-      Changed |= lowerObjCCall(F, "objc_release");
+      Changed |= lowerObjCCall(F, "objc_release", true);
       break;
     case Intrinsic::objc_retain:
-      Changed |= lowerObjCCall(F, "objc_retain");
+      Changed |= lowerObjCCall(F, "objc_retain", true);
       break;
     case Intrinsic::objc_retainAutorelease:
       Changed |= lowerObjCCall(F, "objc_retainAutorelease");

Modified: llvm/trunk/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll?rev=349558&r1=349557&r2=349558&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll (original)
+++ llvm/trunk/test/Transforms/PreISelIntrinsicLowering/objc-arc.ll Tue Dec 18 14:31:34 2018
@@ -279,3 +279,8 @@ declare i8* @llvm.objc.unretainedPointer
 declare i8* @llvm.objc.retain.autorelease(i8*)
 declare i32 @llvm.objc.sync.enter(i8*)
 declare i32 @llvm.objc.sync.exit(i8*)
+
+; CHECK: declare void @objc_release(i8*) [[NLB:#[0-9]+]]
+; CHECK: declare i8* @objc_retain(i8*) [[NLB]]
+
+; CHECK: attributes [[NLB]] = { nonlazybind }




More information about the llvm-commits mailing list