r302270 - CodeGen: avoid use of @clang.arc.use intrinsic at O0

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Mon May 8 18:37:47 PDT 2017


Thank you for the fix. I committed a follow-up patch in r302495, which makes IRGen emit @objc_retain at -O0.

> On May 5, 2017, at 11:39 AM, Saleem Abdulrasool via cfe-commits <cfe-commits at lists.llvm.org> wrote:
> 
> Author: compnerd
> Date: Fri May  5 13:39:06 2017
> New Revision: 302270
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=302270&view=rev
> Log:
> CodeGen: avoid use of @clang.arc.use intrinsic at O0
> 
> The clang.arc.use intrinsic is removed via the ARC Contract Pass.  This
> pass is only executed in optimized builds (>= opt level 1).  Prevent the
> optimization implemented in SVN r301667 from triggering at optimization
> level 0 like every other ARC use intrinsic usage.
> 
> Modified:
>    cfe/trunk/lib/CodeGen/CGBlocks.cpp
>    cfe/trunk/test/CodeGenObjC/arc-foreach.m
> 
> Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=302270&r1=302269&r2=302270&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri May  5 13:39:06 2017
> @@ -623,9 +623,13 @@ static void enterBlockScope(CodeGenFunct
>     // For const-qualified captures, emit clang.arc.use to ensure the captured
>     // object doesn't get released while we are still depending on its validity
>     // within the block.
> -    if (VT.isConstQualified() && VT.getObjCLifetime() == Qualifiers::OCL_Strong)
> +    if (VT.isConstQualified() &&
> +        VT.getObjCLifetime() == Qualifiers::OCL_Strong &&
> +        CGF.CGM.getCodeGenOpts().OptimizationLevel != 0) {
> +      assert(CGF.CGM.getLangOpts().ObjCAutoRefCount &&
> +             "expected ObjC ARC to be enabled");
>       destroyer = CodeGenFunction::emitARCIntrinsicUse;
> -    else if (dtorKind == QualType::DK_objc_strong_lifetime) {
> +    } else if (dtorKind == QualType::DK_objc_strong_lifetime) {
>       destroyer = CodeGenFunction::destroyARCStrongImprecise;
>     } else {
>       destroyer = CGF.getDestroyer(dtorKind);
> 
> Modified: cfe/trunk/test/CodeGenObjC/arc-foreach.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-foreach.m?rev=302270&r1=302269&r2=302270&view=diff
> ==============================================================================
> --- cfe/trunk/test/CodeGenObjC/arc-foreach.m (original)
> +++ cfe/trunk/test/CodeGenObjC/arc-foreach.m Fri May  5 13:39:06 2017
> @@ -1,5 +1,5 @@
> -// RUN: %clang_cc1 -fblocks -fobjc-arc -fobjc-runtime-has-weak -triple x86_64-apple-darwin -emit-llvm %s -o %t-64.s
> -// RUN: FileCheck -check-prefix CHECK-LP64 --input-file=%t-64.s %s
> +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fblocks -fobjc-arc -fobjc-runtime-has-weak -emit-llvm %s -o - | FileCheck -check-prefix CHECK-LP64 %s
> +// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -fblocks -fobjc-arc -fobjc-runtime-has-weak -emit-llvm %s -o - | FileCheck -check-prefix CHECK-LP64-OPT %s
> // rdar://9503326
> // rdar://9606600
> 
> @@ -29,6 +29,11 @@ void test0(NSArray *array) {
> // CHECK-LP64-NEXT: [[BUFFER:%.*]] = alloca [16 x i8*], align 8
> // CHECK-LP64-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]],
> 
> +// CHECK-LP64-OPT-LABEL: define void @test0
> +// CHECK-LP64-OPT: [[STATE:%.*]] = alloca [[STATE_T:%.*]], align 8
> +// CHECK-LP64-OPT-NEXT: [[BUFFER:%.*]] = alloca [16 x i8*], align 8
> +// CHECK-LP64-OPT-NEXT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]], align 8
> +
> // Initialize 'array'.
> // CHECK-LP64-NEXT: store [[ARRAY_T]]* null, [[ARRAY_T]]** [[ARRAY]]
> // CHECK-LP64-NEXT: [[ZERO:%.*]] = bitcast [[ARRAY_T]]** [[ARRAY]] to i8**
> @@ -66,8 +71,12 @@ void test0(NSArray *array) {
> // CHECK-LP64-NEXT: store i8* [[T1]], i8** [[T0]]
> // CHECK-LP64-NEXT: [[BLOCK1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]]
> // CHECK-LP64-NEXT: call void @use_block(void ()* [[BLOCK1]])
> -// CHECK-LP64-NEXT: [[CAPTURE:%.*]] = load i8*, i8** [[D0]]
> -// CHECK-LP64: call void (...) @clang.arc.use(i8* [[CAPTURE]])
> +// CHECK-LP64-NEXT: call void @objc_storeStrong(i8** [[D0]], i8* null)
> +// CHECK-LP64-NOT:  call void (...) @clang.arc.use(i8* [[CAPTURE]])
> +
> +// CHECK-LP64-OPT: [[D0:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* [[BLOCK]], i64 0, i32 5
> +// CHECK-LP64-OPT: [[CAPTURE:%.*]] = load i8*, i8** [[D0]]
> +// CHECK-LP64-OPT: call void (...) @clang.arc.use(i8* [[CAPTURE]])
> 
> // CHECK-LP64:      [[T0:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_
> // CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[ARRAY_T]]* [[SAVED_ARRAY]] to i8*
> @@ -200,15 +209,24 @@ NSArray *array4;
> // CHECK-LP64:         [[T0:%.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>* [[BLOCK]], i32 0, i32 5
> // CHECK-LP64:         [[BC:%.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, [[TY]]* }>* [[BLOCK]], i32 0, i32 5
> // CHECK-LP64:         [[T1:%.*]] = load [[TY]]*, [[TY]]** [[SELF_ADDR]]
> -// CHECK-LP64:         store [[TY]]* [[T1]], [[TY]]** [[BC]]
> +// CHECK-LP64:         store [[TY]]* [[T1]], [[TY]]** [[BC]], align 8
> 
> -// CHECK-LP64:         [[T5:%.*]] = load [[TY]]*, [[TY]]** [[T0]]
> -// CHECK-LP64:         call void (...) @clang.arc.use([[TY]]* [[T5]])
> +// CHECK-LP64-OPT-LABEL: define internal void @"\01-[I1 foo2]"(
> +// CHECK-LP64-OPT: [[TY:%.*]]* %self
> +// CHECK-LP64-OPT: [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]],
> +// CHECK-LP64-OPT: [[T0:%.*]] = getelementptr inbounds [[BLOCK_T]], [[BLOCK_T]]* [[BLOCK]], i64 0, i32 5
> +
> +// CHECK-LP64:         [[T5:%.*]] = bitcast [[TY]]** [[T0]] to i8**
> +// CHECK-LP64:         call void @objc_storeStrong(i8** [[T5]], i8* null)
> +// CHECK-LP64-NOT:     call void (...) @clang.arc.use([[TY]]* [[T5]])
> // CHECK-LP64:         switch i32 {{%.*}}, label %[[UNREACHABLE:.*]] [
> // CHECK-LP64-NEXT:      i32 0, label %[[CLEANUP_CONT:.*]]
> // CHECK-LP64-NEXT:      i32 2, label %[[FORCOLL_END:.*]]
> // CHECK-LP64-NEXT:    ]
> 
> +// CHECK-LP64-OPT: [[T5:%.*]] = load [[TY]]*, [[TY]]** [[T0]]
> +// CHECK-LP64-OPT: call void (...) @clang.arc.use([[TY]]* [[T5]])
> +
> // CHECK-LP64:       {{^|:}}[[CLEANUP_CONT]]
> // CHECK-LP64-NEXT:    br label %[[FORCOLL_END]]
> 
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list