[PATCH] Add ObjC ARC module flag and use it to control arc-contract pass

Steven Wu stevenwu at apple.com
Fri Feb 20 14:17:56 PST 2015

Hi dexonsmith, gottesmm,

Currently, there is no good way to tell if the bitcode is compiled
with ARC or not. However, it is required to run objc-arc-contract
pass for ObjC ARC. Introduces a new module flag for ObjC-ARC and
use that to decide if objc-arc-contract pass is required or not.



Index: lib/CodeGen/BackendUtil.cpp
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -568,7 +568,7 @@
   // Add ObjC ARC final-cleanup optimizations. This is done as part of the
   // "codegen" passes so that it isn't run multiple times when there is
   // inlining happening.
-  if (LangOpts.ObjCAutoRefCount &&
+  if (TheModule->getModuleFlag("Objective-C ARC") &&
       CodeGenOpts.OptimizationLevel > 0)
Index: lib/CodeGen/CGObjCMac.cpp
--- lib/CodeGen/CGObjCMac.cpp
+++ lib/CodeGen/CGObjCMac.cpp
@@ -4283,6 +4283,13 @@
+  // Add ObjCAutoRefCount as a module flag
+  if (CGM.getLangOpts().ObjCAutoRefCount) {
+    // AutoRefCount will overwrites files which don't have ARC.
+    Mod.addModuleFlag(llvm::Module::Override,
+                      "Objective-C ARC", (uint32_t)1);
+  }
   // Indicate whether we're compiling this to run on a simulator.
   const llvm::Triple &Triple = CGM.getTarget().getTriple();
   if (Triple.isiOS() &&

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7799.20432.patch
Type: text/x-patch
Size: 1154 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150220/2d86705a/attachment.bin>

More information about the cfe-commits mailing list