@@ -1197,6 +1197,14 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
1197
1197
if (is_oacc_parallel_or_serial (ctx ) || is_oacc_kernels (ctx ))
1198
1198
ctx -> local_reduction_clauses
1199
1199
= tree_cons (NULL , c , ctx -> local_reduction_clauses );
1200
+ if ((OMP_CLAUSE_REDUCTION_INSCAN (c )
1201
+ || OMP_CLAUSE_REDUCTION_TASK (c )) && ctx -> allocate_map )
1202
+ {
1203
+ tree decl = OMP_CLAUSE_DECL (c );
1204
+ /* For now. */
1205
+ if (ctx -> allocate_map -> get (decl ))
1206
+ ctx -> allocate_map -> remove (decl );
1207
+ }
1200
1208
/* FALLTHRU */
1201
1209
1202
1210
case OMP_CLAUSE_IN_REDUCTION :
@@ -4392,13 +4400,17 @@ lower_private_allocate (tree var, tree new_var, tree &allocator,
4392
4400
if (allocator )
4393
4401
return false;
4394
4402
gcc_assert (allocate_ptr == NULL_TREE );
4395
- if (ctx -> allocate_map && DECL_P (new_var ))
4403
+ if (ctx -> allocate_map
4404
+ && (DECL_P (new_var ) || (TYPE_P (new_var ) && size )))
4396
4405
if (tree * allocatorp = ctx -> allocate_map -> get (var ))
4397
4406
allocator = * allocatorp ;
4398
4407
if (allocator == NULL_TREE )
4399
4408
return false;
4400
4409
if (!is_ref && omp_is_reference (var ))
4401
- return false;
4410
+ {
4411
+ allocator = NULL_TREE ;
4412
+ return false;
4413
+ }
4402
4414
4403
4415
if (TREE_CODE (allocator ) != INTEGER_CST )
4404
4416
allocator = build_outer_var_ref (allocator , ctx );
@@ -4410,19 +4422,24 @@ lower_private_allocate (tree var, tree new_var, tree &allocator,
4410
4422
allocator = var ;
4411
4423
}
4412
4424
4413
- tree ptr_type , align , sz ;
4414
- if (is_ref )
4425
+ tree ptr_type , align , sz = size ;
4426
+ if (TYPE_P (new_var ))
4427
+ {
4428
+ ptr_type = build_pointer_type (new_var );
4429
+ align = build_int_cst (size_type_node , TYPE_ALIGN_UNIT (new_var ));
4430
+ }
4431
+ else if (is_ref )
4415
4432
{
4416
4433
ptr_type = build_pointer_type (TREE_TYPE (TREE_TYPE (new_var )));
4417
4434
align = build_int_cst (size_type_node ,
4418
4435
TYPE_ALIGN_UNIT (TREE_TYPE (ptr_type )));
4419
- sz = size ;
4420
4436
}
4421
4437
else
4422
4438
{
4423
4439
ptr_type = build_pointer_type (TREE_TYPE (new_var ));
4424
4440
align = build_int_cst (size_type_node , DECL_ALIGN_UNIT (new_var ));
4425
- sz = fold_convert (size_type_node , DECL_SIZE_UNIT (new_var ));
4441
+ if (sz == NULL_TREE )
4442
+ sz = fold_convert (size_type_node , DECL_SIZE_UNIT (new_var ));
4426
4443
}
4427
4444
if (TREE_CODE (sz ) != INTEGER_CST )
4428
4445
{
@@ -4855,7 +4872,23 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
4855
4872
tree type = TREE_TYPE (d );
4856
4873
gcc_assert (TREE_CODE (type ) == ARRAY_TYPE );
4857
4874
tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type ));
4875
+ tree sz = v ;
4858
4876
const char * name = get_name (orig_var );
4877
+ if (pass != 3 && !TREE_CONSTANT (v ))
4878
+ {
4879
+ tree t = maybe_lookup_decl (v , ctx );
4880
+ if (t )
4881
+ v = t ;
4882
+ else
4883
+ v = maybe_lookup_decl_in_outer_ctx (v , ctx );
4884
+ gimplify_expr (& v , ilist , NULL , is_gimple_val , fb_rvalue );
4885
+ t = fold_build2_loc (clause_loc , PLUS_EXPR ,
4886
+ TREE_TYPE (v ), v ,
4887
+ build_int_cst (TREE_TYPE (v ), 1 ));
4888
+ sz = fold_build2_loc (clause_loc , MULT_EXPR ,
4889
+ TREE_TYPE (v ), t ,
4890
+ TYPE_SIZE_UNIT (TREE_TYPE (type )));
4891
+ }
4859
4892
if (pass == 3 )
4860
4893
{
4861
4894
tree xv = create_tmp_var (ptr_type_node );
@@ -4913,6 +4946,13 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
4913
4946
gimplify_assign (cond , x , ilist );
4914
4947
x = xv ;
4915
4948
}
4949
+ else if (lower_private_allocate (var , type , allocator ,
4950
+ allocate_ptr , ilist , ctx ,
4951
+ true,
4952
+ TREE_CONSTANT (v )
4953
+ ? TYPE_SIZE_UNIT (type )
4954
+ : sz ))
4955
+ x = allocate_ptr ;
4916
4956
else if (TREE_CONSTANT (v ))
4917
4957
{
4918
4958
x = create_tmp_var_raw (type , name );
@@ -4924,20 +4964,8 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
4924
4964
{
4925
4965
tree atmp
4926
4966
= builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN );
4927
- tree t = maybe_lookup_decl (v , ctx );
4928
- if (t )
4929
- v = t ;
4930
- else
4931
- v = maybe_lookup_decl_in_outer_ctx (v , ctx );
4932
- gimplify_expr (& v , ilist , NULL , is_gimple_val , fb_rvalue );
4933
- t = fold_build2_loc (clause_loc , PLUS_EXPR ,
4934
- TREE_TYPE (v ), v ,
4935
- build_int_cst (TREE_TYPE (v ), 1 ));
4936
- t = fold_build2_loc (clause_loc , MULT_EXPR ,
4937
- TREE_TYPE (v ), t ,
4938
- TYPE_SIZE_UNIT (TREE_TYPE (type )));
4939
4967
tree al = size_int (TYPE_ALIGN (TREE_TYPE (type )));
4940
- x = build_call_expr_loc (clause_loc , atmp , 2 , t , al );
4968
+ x = build_call_expr_loc (clause_loc , atmp , 2 , sz , al );
4941
4969
}
4942
4970
4943
4971
tree ptype = build_pointer_type (TREE_TYPE (type ));
@@ -5199,6 +5227,12 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
5199
5227
gimple_seq_add_stmt (dlist , g );
5200
5228
gimple_seq_add_stmt (dlist , gimple_build_label (end2 ));
5201
5229
}
5230
+ if (allocator )
5231
+ {
5232
+ tree f = builtin_decl_explicit (BUILT_IN_GOMP_FREE );
5233
+ g = gimple_build_call (f , 2 , allocate_ptr , allocator );
5234
+ gimple_seq_add_stmt (dlist , g );
5235
+ }
5202
5236
continue ;
5203
5237
}
5204
5238
else if (pass == 2 )
0 commit comments