aboutsummaryrefslogtreecommitdiff
path: root/gcc/omp-low.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-09-22 09:29:13 +0200
committerJakub Jelinek <jakub@redhat.com>2021-09-22 09:29:13 +0200
commit059b819e3c94aae3dd0be55bd512ee6ee4e28798 (patch)
treebb8b074085f64d452820b382f51a65c04cf26448 /gcc/omp-low.c
parent578b76873383784841f5478573f4ac5d251aa0ba (diff)
downloadgcc-059b819e3c94aae3dd0be55bd512ee6ee4e28798.zip
gcc-059b819e3c94aae3dd0be55bd512ee6ee4e28798.tar.gz
gcc-059b819e3c94aae3dd0be55bd512ee6ee4e28798.tar.bz2
openmp: Add support for allocator and align modifiers on allocate clauses
As the allocate-2.c testcase shows, this change isn't 100% backwards compatible, one could have allocate and/or align functions that return an OpenMP allocator handle and previously it would call those functions and now would use those names as keywords for the modifiers. But it allows specify extra alignment requirements for the allocations. 2021-09-22 Jakub Jelinek <jakub@redhat.com> gcc/ * tree.h (OMP_CLAUSE_ALLOCATE_ALIGN): Define. * tree.c (omp_clause_num_ops): Change number of OMP_CLAUSE_ALLOCATE arguments from 2 to 3. * tree-pretty-print.c (dump_omp_clause): Print allocator() around allocate clause allocator and print align if present. * omp-low.c (scan_sharing_clauses): Force allocate_map entry even for omp_default_mem_alloc if align modifier is present. If align modifier is present, use TREE_LIST to encode both allocator and align. (lower_private_allocate, lower_rec_input_clauses, create_task_copyfn): Handle align modifier on allocator clause if present. gcc/c-family/ * c-omp.c (c_omp_split_clauses): Copy over OMP_CLAUSE_ALLOCATE_ALIGN. gcc/c/ * c-parser.c (c_parser_omp_clause_allocate): Parse allocate clause modifiers. gcc/cp/ * parser.c (cp_parser_omp_clause_allocate): Parse allocate clause modifiers. * semantics.c (finish_omp_clauses) <OMP_CLAUSE_ALLOCATE>: Perform semantic analysis of OMP_CLAUSE_ALLOCATE_ALIGN. * pt.c (tsubst_omp_clauses) <case OMP_CLAUSE_ALLOCATE>: Handle also OMP_CLAUSE_ALLOCATE_ALIGN. gcc/testsuite/ * c-c++-common/gomp/allocate-6.c: New test. * c-c++-common/gomp/allocate-7.c: New test. * g++.dg/gomp/allocate-4.C: New test. libgomp/ * testsuite/libgomp.c-c++-common/allocate-2.c: New test. * testsuite/libgomp.c-c++-common/allocate-3.c: New test.
Diffstat (limited to 'gcc/omp-low.c')
-rw-r--r--gcc/omp-low.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 27a513e..26c5c02 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -1161,14 +1161,17 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE
&& (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) == NULL_TREE
/* omp_default_mem_alloc is 1 */
- || !integer_onep (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c))))
+ || !integer_onep (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c))
+ || OMP_CLAUSE_ALLOCATE_ALIGN (c) != NULL_TREE))
{
if (ctx->allocate_map == NULL)
ctx->allocate_map = new hash_map<tree, tree>;
- ctx->allocate_map->put (OMP_CLAUSE_DECL (c),
- OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)
- ? OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)
- : integer_zero_node);
+ tree val = integer_zero_node;
+ if (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c))
+ val = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
+ if (OMP_CLAUSE_ALLOCATE_ALIGN (c))
+ val = build_tree_list (val, OMP_CLAUSE_ALLOCATE_ALIGN (c));
+ ctx->allocate_map->put (OMP_CLAUSE_DECL (c), val);
}
for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
@@ -4725,6 +4728,12 @@ lower_private_allocate (tree var, tree new_var, tree &allocator,
return false;
}
+ unsigned HOST_WIDE_INT ialign = 0;
+ if (TREE_CODE (allocator) == TREE_LIST)
+ {
+ ialign = tree_to_uhwi (TREE_VALUE (allocator));
+ allocator = TREE_PURPOSE (allocator);
+ }
if (TREE_CODE (allocator) != INTEGER_CST)
allocator = build_outer_var_ref (allocator, ctx);
allocator = fold_convert (pointer_sized_int_node, allocator);
@@ -4739,21 +4748,21 @@ lower_private_allocate (tree var, tree new_var, tree &allocator,
if (TYPE_P (new_var))
{
ptr_type = build_pointer_type (new_var);
- align = build_int_cst (size_type_node, TYPE_ALIGN_UNIT (new_var));
+ ialign = MAX (ialign, TYPE_ALIGN_UNIT (new_var));
}
else if (is_ref)
{
ptr_type = build_pointer_type (TREE_TYPE (TREE_TYPE (new_var)));
- align = build_int_cst (size_type_node,
- TYPE_ALIGN_UNIT (TREE_TYPE (ptr_type)));
+ ialign = MAX (ialign, TYPE_ALIGN_UNIT (TREE_TYPE (ptr_type)));
}
else
{
ptr_type = build_pointer_type (TREE_TYPE (new_var));
- align = build_int_cst (size_type_node, DECL_ALIGN_UNIT (new_var));
+ ialign = MAX (ialign, DECL_ALIGN_UNIT (new_var));
if (sz == NULL_TREE)
sz = fold_convert (size_type_node, DECL_SIZE_UNIT (new_var));
}
+ align = build_int_cst (size_type_node, ialign);
if (TREE_CODE (sz) != INTEGER_CST)
{
tree szvar = create_tmp_var (size_type_node);
@@ -5707,6 +5716,8 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
if (tree *allocatep = ctx->allocate_map->get (var))
{
allocator = *allocatep;
+ if (TREE_CODE (allocator) == TREE_LIST)
+ allocator = TREE_PURPOSE (allocator);
if (TREE_CODE (allocator) != INTEGER_CST)
allocator = build_outer_var_ref (allocator, ctx);
allocator = fold_convert (pointer_sized_int_node,
@@ -6025,6 +6036,8 @@ lower_rec_input_clauses (tree clauses, gimple_seq *ilist, gimple_seq *dlist,
if (tree *allocatep = ctx->allocate_map->get (var))
{
allocator = *allocatep;
+ if (TREE_CODE (allocator) == TREE_LIST)
+ allocator = TREE_PURPOSE (allocator);
if (TREE_CODE (allocator) != INTEGER_CST)
allocator = build_outer_var_ref (allocator, ctx);
allocator = fold_convert (pointer_sized_int_node,
@@ -12070,6 +12083,12 @@ create_task_copyfn (gomp_task *task_stmt, omp_context *ctx)
if (tree *allocatorp = ctx->allocate_map->get (decl))
{
tree allocator = *allocatorp;
+ HOST_WIDE_INT ialign = 0;
+ if (TREE_CODE (allocator) == TREE_LIST)
+ {
+ ialign = tree_to_uhwi (TREE_VALUE (allocator));
+ allocator = TREE_PURPOSE (allocator);
+ }
if (TREE_CODE (allocator) != INTEGER_CST)
{
n = splay_tree_lookup (ctx->sfield_map,
@@ -12083,7 +12102,8 @@ create_task_copyfn (gomp_task *task_stmt, omp_context *ctx)
allocator = fold_convert (pointer_sized_int_node, allocator);
tree a = builtin_decl_explicit (BUILT_IN_GOMP_ALLOC);
tree align = build_int_cst (size_type_node,
- DECL_ALIGN_UNIT (decl));
+ MAX (ialign,
+ DECL_ALIGN_UNIT (decl)));
tree sz = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (dst)));
tree ptr = build_call_expr_loc (loc, a, 3, align, sz,
allocator);