[PATCH] [OPENMP] Do not emit implicit barrier for single directive with 'copyprivate' clause(s).

John McCall rjmccall at gmail.com
Thu Apr 23 09:24:00 PDT 2015


LGTM.

On Thu, Apr 23, 2015 at 5:08 AM, Alexey Bataev <a.bataev at hotmail.com> wrote:

> Hi rjmccall, hfinkel,
>
> Runtime function for 'copyprivate' directive generates implicit barriers,
> so no need to emit it.
>
> http://reviews.llvm.org/D9215
>
> Files:
>   lib/CodeGen/CGStmtOpenMP.cpp
>   test/OpenMP/single_codegen.cpp
>
> Index: test/OpenMP/single_codegen.cpp
> ===================================================================
> --- test/OpenMP/single_codegen.cpp
> +++ test/OpenMP/single_codegen.cpp
> @@ -51,13 +51,24 @@
>  // CHECK-NEXT:  call void @__kmpc_end_single([[IDENT_T_TY]]*
> [[DEFAULT_LOC]], i32 [[GTID]])
>  // CHECK-NEXT:  br label {{%?}}[[EXIT]]
>  // CHECK:       [[EXIT]]
> -// CHECK-NOT:   __kmpc_cancel_barrier
> +// CHECK-NOT:   call {{.+}} @__kmpc_cancel_barrier
>  #pragma omp single nowait
>    a = 2;
>  // CHECK:       [[RES:%.+]] = call i32 @__kmpc_single([[IDENT_T_TY]]*
> [[DEFAULT_LOC]], i32 [[GTID]])
>  // CHECK-NEXT:  [[IS_SINGLE:%.+]] = icmp ne i32 [[RES]], 0
>  // CHECK-NEXT:  br i1 [[IS_SINGLE]], label {{%?}}[[THEN:.+]], label
> {{%?}}[[EXIT:.+]]
>  // CHECK:       [[THEN]]
> +// CHECK-NEXT:  store i8 2, i8* [[A_ADDR]]
> +// CHECK-NEXT:  call void @__kmpc_end_single([[IDENT_T_TY]]*
> [[DEFAULT_LOC]], i32 [[GTID]])
> +// CHECK-NEXT:  br label {{%?}}[[EXIT]]
> +// CHECK:       [[EXIT]]
> +// CHECK:       call{{.*}} @__kmpc_cancel_barrier([[IDENT_T_TY]]*
> [[IMPLICIT_BARRIER_SINGLE_LOC]], i32 [[GTID]])
> +#pragma omp single
> +  a = 2;
> +// CHECK:       [[RES:%.+]] = call i32 @__kmpc_single([[IDENT_T_TY]]*
> [[DEFAULT_LOC]], i32 [[GTID]])
> +// CHECK-NEXT:  [[IS_SINGLE:%.+]] = icmp ne i32 [[RES]], 0
> +// CHECK-NEXT:  br i1 [[IS_SINGLE]], label {{%?}}[[THEN:.+]], label
> {{%?}}[[EXIT:.+]]
> +// CHECK:       [[THEN]]
>  // CHECK-NEXT:  invoke void [[FOO]]()
>  // CHECK:       to label {{%?}}[[CONT:.+]] unwind
>  // CHECK:       [[CONT]]
> @@ -86,7 +97,7 @@
>  // CHECK:       [[COPY_LIST_VOID_PTR:%.+]] = bitcast [5 x i8*]*
> [[COPY_LIST]] to i8*
>  // CHECK:       [[DID_IT_VAL:%.+]] = load i32, i32* [[DID_IT]],
>  // CHECK:       call void @__kmpc_copyprivate([[IDENT_T_TY]]*
> [[DEFAULT_LOC]], i32 [[GTID]], i32 40, i8* [[COPY_LIST_VOID_PTR]], void
> (i8*, i8*)* [[COPY_FUNC:@.+]], i32 [[DID_IT_VAL]])
> -// CHECK:       call{{.*}} @__kmpc_cancel_barrier([[IDENT_T_TY]]*
> [[IMPLICIT_BARRIER_SINGLE_LOC]], i32 [[GTID]])
> +// CHECK-NOT:   call {{.+}} @__kmpc_cancel_barrier
>  #pragma omp single copyprivate(a, c, tc, a2, tc2)
>    foo();
>  // CHECK-NOT:   call i32 @__kmpc_single
> Index: lib/CodeGen/CGStmtOpenMP.cpp
> ===================================================================
> --- lib/CodeGen/CGStmtOpenMP.cpp
> +++ lib/CodeGen/CGStmtOpenMP.cpp
> @@ -1251,8 +1251,9 @@
>    CGM.getOpenMPRuntime().emitSingleRegion(*this, CodeGen, S.getLocStart(),
>                                            CopyprivateVars, DestExprs,
> SrcExprs,
>                                            AssignmentOps);
> -  // Emit an implicit barrier at the end.
> -  if (!S.getSingleClause(OMPC_nowait)) {
> +  // Emit an implicit barrier at the end (if no 'nowait' clause and no
> +  // 'copyprivate' clause).
> +  if (!S.getSingleClause(OMPC_nowait) && CopyprivateVars.empty()) {
>      CGM.getOpenMPRuntime().emitBarrierCall(*this, S.getLocStart(),
> OMPD_single);
>    }
>  }
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/
>



-- 
I suppose you'd like my real thoughts as well.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150423/562f056c/attachment.html>


More information about the cfe-commits mailing list