[PATCH] Add ObjC ARC module flag and use it to control arc-contract pass
Steven Wu
stevenwu at apple.com
Mon Mar 2 14:56:07 PST 2015
Fix the code according to Duncan's feedback. Attempt to add a testcase.
Not sure if there is better to check if the pass is run other than using -debug-pass=Arguments.
http://reviews.llvm.org/D7799
Files:
lib/CodeGen/BackendUtil.cpp
lib/CodeGen/CGObjCMac.cpp
test/CodeGen/arc-passes.m
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -569,7 +569,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)
PM->add(createObjCARCContractPass());
Index: lib/CodeGen/CGObjCMac.cpp
===================================================================
--- lib/CodeGen/CGObjCMac.cpp
+++ lib/CodeGen/CGObjCMac.cpp
@@ -4284,6 +4284,12 @@
}
}
+ // Add ObjCAutoRefCount as a module flag
+ if (CGM.getLangOpts().ObjCAutoRefCount) {
+ Mod.addModuleFlag(llvm::Module::Error,
+ "Objective-C ARC", 1u);
+ }
+
// Indicate whether we're compiling this to run on a simulator.
const llvm::Triple &Triple = CGM.getTarget().getTriple();
if (Triple.isiOS() &&
Index: test/CodeGen/arc-passes.m
===================================================================
--- /dev/null
+++ test/CodeGen/arc-passes.m
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck %s -check-prefix=NO-ARC
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -emit-obj -O3 %s -o /dev/null -mllvm -debug-pass=Arguments 2>&1 | FileCheck %s -check-prefix=ARC-PASS
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-obj -O3 %s -o /dev/null -mllvm -debug-pass=Arguments 2>&1 | FileCheck %s -check-prefix=NO-ARC-PASS
+
+// CHECK: !{i32 1, !"Objective-C ARC", i32 1}
+// NO-ARC-NOT: !{i32 1, !"Objective-C ARC", i32 1}
+// ARC-PASS: -objc-arc-contract
+// NO-ARC-PASS-NOT: -objc-arc-contract
+
+void test() {
+}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7799.21048.patch
Type: text/x-patch
Size: 1951 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150302/0a835165/attachment.bin>
More information about the cfe-commits
mailing list