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

Duncan P. N. Exon Smith dexonsmith at apple.com
Tue Mar 3 13:20:30 PST 2015


> On 2015-Mar-02, at 14:56, Steven Wu <stevenwu at apple.com> wrote:
> 
> 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.

Steven and I talked offline.  All the passes that depend on this flag
are function passes.  Since it's possible to switch on a per-function
basis, this should be a function attribute (not a module flag).

> 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/
> <D7799.21048.patch>





More information about the cfe-commits mailing list