DEF_FUNCTION_TYPE_3 (BT_FN_UINT_UINT_PTR_PTR, BT_UINT, BT_UINT, BT_PTR, BT_PTR)
DEF_FUNCTION_TYPE_3 (BT_FN_PTR_PTR_CONST_SIZE_BOOL,
BT_PTR, BT_PTR, BT_CONST_SIZE, BT_BOOL)
+DEF_FUNCTION_TYPE_3 (BT_FN_PTR_SIZE_SIZE_PTRMODE,
+ BT_PTR, BT_SIZE, BT_SIZE, BT_PTRMODE)
DEF_FUNCTION_TYPE_4 (BT_FN_SIZE_CONST_PTR_SIZE_SIZE_FILEPTR,
BT_SIZE, BT_CONST_PTR, BT_SIZE, BT_SIZE, BT_FILEPTR)
case BUILT_IN_MALLOC:
case BUILT_IN_ALIGNED_ALLOC:
case BUILT_IN_CALLOC:
+ case BUILT_IN_GOMP_ALLOC:
return "mC";
CASE_BUILT_IN_ALLOCA:
return "mc";
across it. */
case BUILT_IN_STACK_RESTORE:
case BUILT_IN_FREE:
+ case BUILT_IN_GOMP_FREE:
return ".co ";
case BUILT_IN_VA_END:
return ".cO ";
return decl;
}
-/* So far we need just these 7 attribute types. */
+/* So far we need just these 8 attribute types. */
#define ATTR_NULL 0
#define ATTR_LEAF_LIST (ECF_LEAF)
#define ATTR_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF)
#define ATTR_PURE_NOTHROW_LEAF_LIST (ECF_NOTHROW | ECF_LEAF | ECF_PURE)
#define ATTR_NOTHROW_LIST (ECF_NOTHROW)
#define ATTR_CONST_NOTHROW_LIST (ECF_NOTHROW | ECF_CONST)
+#define ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LIST \
+ (ECF_NOTHROW)
static void
gfc_define_builtin (const char *name, tree type, enum built_in_function code,
#undef DEF_GOACC_BUILTIN
#undef DEF_GOACC_BUILTIN_COMPILER
#undef DEF_GOMP_BUILTIN
+ tree gomp_alloc = builtin_decl_explicit (BUILT_IN_GOMP_ALLOC);
+ tree two = build_int_cst (integer_type_node, 2);
+ DECL_ATTRIBUTES (gomp_alloc)
+ = tree_cons (get_identifier ("warn_unused_result"), NULL_TREE,
+ tree_cons (get_identifier ("alloc_size"),
+ build_tree_list (NULL_TREE, two),
+ DECL_ATTRIBUTES (gomp_alloc)));
}
gfc_define_builtin ("__builtin_trap", builtin_types[BT_FN_VOID],
build_pointer_type
(build_qualified_type (void_type_node,
TYPE_QUAL_VOLATILE|TYPE_QUAL_CONST)))
+DEF_PRIMITIVE_TYPE (BT_PTRMODE, (*lang_hooks.types.type_for_mode)(ptr_mode, 0))
DEF_POINTER_TYPE (BT_PTR_LONG, BT_LONG)
DEF_POINTER_TYPE (BT_PTR_ULONGLONG, BT_ULONGLONG)
DEF_POINTER_TYPE (BT_PTR_PTR, BT_PTR)
BT_CONST_VOLATILE_PTR)
DEF_FUNCTION_TYPE_2 (BT_FN_BOOL_INT_BOOL, BT_BOOL, BT_INT, BT_BOOL)
DEF_FUNCTION_TYPE_2 (BT_FN_VOID_UINT_UINT, BT_VOID, BT_UINT, BT_UINT)
+DEF_FUNCTION_TYPE_2 (BT_FN_VOID_PTR_PTRMODE,
+ BT_VOID, BT_PTR, BT_PTRMODE)
DEF_POINTER_TYPE (BT_PTR_FN_VOID_PTR_PTR, BT_FN_VOID_PTR_PTR)
DEF_FUNCTION_TYPE_3 (BT_FN_VOID_SIZE_SIZE_PTR, BT_VOID, BT_SIZE, BT_SIZE,
BT_PTR)
DEF_FUNCTION_TYPE_3 (BT_FN_UINT_UINT_PTR_PTR, BT_UINT, BT_UINT, BT_PTR, BT_PTR)
+DEF_FUNCTION_TYPE_3 (BT_FN_PTR_SIZE_SIZE_PTRMODE,
+ BT_PTR, BT_SIZE, BT_SIZE, BT_PTRMODE)
DEF_FUNCTION_TYPE_4 (BT_FN_VOID_OMPFN_PTR_UINT_UINT,
BT_VOID, BT_PTR_FN_VOID_PTR, BT_PTR, BT_UINT, BT_UINT)
remove = true;
break;
}
+ else if (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c) == NULL_TREE
+ || (TREE_CODE (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c))
+ == INTEGER_CST))
+ ;
else if (code == OMP_TASKLOOP
- && OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)
- && (TREE_CODE (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c))
- != INTEGER_CST))
+ || !DECL_P (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)))
OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)
= get_initialized_tmp_var (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c),
pre_p, NULL, false);
&& omp_shared_to_firstprivate_optimizable_decl_p (decl))
omp_mark_stores (gimplify_omp_ctxp->outer_context, decl);
}
+ else
+ n->value &= ~GOVD_EXPLICIT;
break;
case OMP_CLAUSE_LASTPRIVATE:
&& omp_shared_to_firstprivate_optimizable_decl_p (decl))
omp_mark_stores (gimplify_omp_ctxp->outer_context, decl);
break;
+
+ case OMP_CLAUSE_ALLOCATE:
+ decl = OMP_CLAUSE_DECL (c);
+ n = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
+ if (n != NULL && !(n->value & GOVD_SEEN))
+ {
+ if ((n->value & (GOVD_PRIVATE | GOVD_FIRSTPRIVATE | GOVD_LINEAR))
+ != 0
+ && (n->value & (GOVD_REDUCTION | GOVD_LASTPRIVATE)) == 0)
+ remove = true;
+ }
+ if (!remove
+ && OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)
+ && TREE_CODE (OMP_CLAUSE_ALLOCATE_ALLOCATOR (c)) != INTEGER_CST
+ && ((ctx->region_type & (ORT_PARALLEL | ORT_TARGET)) != 0
+ || (ctx->region_type & ORT_TASKLOOP) == ORT_TASK
+ || (ctx->region_type & ORT_HOST_TEAMS) == ORT_HOST_TEAMS))
+ {
+ tree allocator = OMP_CLAUSE_ALLOCATE_ALLOCATOR (c);
+ n = splay_tree_lookup (ctx->variables, (splay_tree_key) allocator);
+ if (n == NULL)
+ {
+ enum omp_clause_default_kind default_kind
+ = ctx->default_kind;
+ ctx->default_kind = OMP_CLAUSE_DEFAULT_FIRSTPRIVATE;
+ omp_notice_variable (ctx, OMP_CLAUSE_ALLOCATE_ALLOCATOR (c),
+ true);
+ ctx->default_kind = default_kind;
+ }
+ else
+ omp_notice_variable (ctx, OMP_CLAUSE_ALLOCATE_ALLOCATOR (c),
+ true);
+ }
+ break;
+
case OMP_CLAUSE_COPYIN:
case OMP_CLAUSE_COPYPRIVATE:
case OMP_CLAUSE_IF:
case OMP_CLAUSE_FINALIZE:
case OMP_CLAUSE_INCLUSIVE:
case OMP_CLAUSE_EXCLUSIVE:
- case OMP_CLAUSE_ALLOCATE:
break;
default:
c = omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_TILE);
if (c)
tile = list_length (OMP_CLAUSE_TILE_LIST (c));
+ c = omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_ALLOCATE);
+ hash_set<tree> *allocate_uids = NULL;
+ if (c)
+ {
+ allocate_uids = new hash_set<tree>;
+ for (; c; c = OMP_CLAUSE_CHAIN (c))
+ if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ALLOCATE)
+ allocate_uids->add (OMP_CLAUSE_DECL (c));
+ }
for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
{
t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
as an iteration counter. This is valid, since DECL cannot be
modified in the body of the loop. Similarly for any iteration vars
in simd with collapse > 1 where the iterator vars must be
- lastprivate. */
+ lastprivate. And similarly for vars mentioned in allocate clauses. */
if (orig_for_stmt != for_stmt)
var = decl;
else if (!is_gimple_reg (decl)
|| (ort == ORT_SIMD
- && TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) > 1))
+ && TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)) > 1)
+ || (allocate_uids && allocate_uids->contains (decl)))
{
struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
/* Make sure omp_add_variable is not called on it prematurely.
}
BITMAP_FREE (has_decl_expr);
+ delete allocate_uids;
if (TREE_CODE (orig_for_stmt) == OMP_TASKLOOP
|| (loop_p && orig_for_stmt == for_stmt))
DEF_GOACC_BUILTIN (BUILT_IN_GOACC_WAIT, "GOACC_wait",
BT_FN_VOID_INT_INT_VAR,
ATTR_NOTHROW_LIST)
+DEF_GOACC_BUILTIN (BUILT_IN_GOACC_DECLARE, "GOACC_declare",
+ BT_FN_VOID_INT_SIZE_PTR_PTR_PTR, ATTR_NOTHROW_LIST)
DEF_GOACC_BUILTIN_COMPILER (BUILT_IN_ACC_ON_DEVICE, "acc_on_device",
BT_FN_INT_INT, ATTR_CONST_NOTHROW_LEAF_LIST)
DEF_GOMP_BUILTIN (BUILT_IN_GOMP_WORKSHARE_TASK_REDUCTION_UNREGISTER,
"GOMP_workshare_task_reduction_unregister",
BT_FN_VOID_BOOL, ATTR_NOTHROW_LEAF_LIST)
-DEF_GOACC_BUILTIN (BUILT_IN_GOACC_DECLARE, "GOACC_declare",
- BT_FN_VOID_INT_SIZE_PTR_PTR_PTR, ATTR_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_ALLOC,
+ "GOMP_alloc", BT_FN_PTR_SIZE_SIZE_PTRMODE,
+ ATTR_ALLOC_WARN_UNUSED_RESULT_SIZE_2_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_FREE,
+ "GOMP_free", BT_FN_VOID_PTR_PTRMODE, ATTR_NOTHROW_LEAF_LIST)
: POINTER_PLUS_EXPR, TREE_TYPE (t), v, a);
t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
false, GSI_CONTINUE_LINKING);
- assign_stmt = gimple_build_assign (dest, t);
- gsi_insert_after (&gsi, assign_stmt, GSI_CONTINUE_LINKING);
+ expand_omp_build_assign (&gsi, dest, t, true);
}
if (fd->collapse > 1)
expand_omp_for_init_vars (fd, &gsi, counts, NULL, inner_stmt, startvar);
: POINTER_PLUS_EXPR, TREE_TYPE (t), t, a);
t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
false, GSI_CONTINUE_LINKING);
- assign_stmt = gimple_build_assign (dest, t);
- gsi_insert_after (&gsi, assign_stmt, GSI_CONTINUE_LINKING);
+ expand_omp_build_assign (&gsi, dest, t, true);
}
if (fd->collapse > 1)
{
: POINTER_PLUS_EXPR, TREE_TYPE (t), v, a);
t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
false, GSI_CONTINUE_LINKING);
- assign_stmt = gimple_build_assign (dest, t);
- gsi_insert_after (&gsi, assign_stmt, GSI_CONTINUE_LINKING);
+ expand_omp_build_assign (&gsi, dest, t, true);
}
if (fd->collapse > 1)
expand_omp_for_init_vars (fd, &gsi, counts, NULL, inner_stmt, startvar);
corresponding tracking loop iteration variables. */
hash_map<tree, tree> *lastprivate_conditional_map;
+ /* And a hash map from the allocate variables to their corresponding
+ allocators. */
+ hash_map<tree, tree> *allocate_map;
+
/* A tree_list of the reduction clauses in this context. This is
only used for checking the consistency of OpenACC reduction
clauses in scan_omp_for and is not guaranteed to contain a valid
}
delete ctx->lastprivate_conditional_map;
+ delete ctx->allocate_map;
XDELETE (ctx);
}
tree c, decl;
bool scan_array_reductions = false;
+ for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
+ 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))))
+ {
+ if (is_task_ctx (ctx))
+ continue; /* For now. */
+ 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);
+ }
+
for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
{
bool by_ref;
case OMP_CLAUSE_SHARED:
decl = OMP_CLAUSE_DECL (c);
+ if (ctx->allocate_map && ctx->allocate_map->get (decl))
+ ctx->allocate_map->remove (decl);
/* Ignore shared directives in teams construct inside of
target construct. */
if (gimple_code (ctx->stmt) == GIMPLE_OMP_TEAMS
return v;
}
+/* Lower early initialization of privatized variable NEW_VAR
+ if it needs an allocator (has allocate clause). */
+
+static bool
+lower_private_allocate (tree var, tree new_var, tree &allocator,
+ tree &allocate_ptr, gimple_seq *ilist,
+ omp_context *ctx, bool is_ref, tree size)
+{
+ if (allocator)
+ return false;
+ gcc_assert (allocate_ptr == NULL_TREE);
+ if (ctx->allocate_map && DECL_P (new_var))
+ if (tree *allocatorp = ctx->allocate_map->get (var))
+ allocator = *allocatorp;
+ if (allocator == NULL_TREE)
+ return false;
+ if (!is_ref && omp_is_reference (var))
+ return false;
+
+ if (TREE_CODE (allocator) != INTEGER_CST)
+ allocator = build_outer_var_ref (allocator, ctx);
+ allocator = fold_convert (pointer_sized_int_node, allocator);
+ if (TREE_CODE (allocator) != INTEGER_CST)
+ {
+ tree var = create_tmp_var (TREE_TYPE (allocator));
+ gimplify_assign (var, allocator, ilist);
+ allocator = var;
+ }
+
+ tree ptr_type, align, sz;
+ 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)));
+ sz = size;
+ }
+ else
+ {
+ ptr_type = build_pointer_type (TREE_TYPE (new_var));
+ align = build_int_cst (size_type_node, DECL_ALIGN_UNIT (new_var));
+ sz = fold_convert (size_type_node, DECL_SIZE_UNIT (new_var));
+ }
+ if (TREE_CODE (sz) != INTEGER_CST)
+ {
+ tree szvar = create_tmp_var (size_type_node);
+ gimplify_assign (szvar, sz, ilist);
+ sz = szvar;
+ }
+ allocate_ptr = create_tmp_var (ptr_type);
+ tree a = builtin_decl_explicit (BUILT_IN_GOMP_ALLOC);
+ gimple *g = gimple_build_call (a, 3, align, sz, allocator);
+ gimple_call_set_lhs (g, allocate_ptr);
+ gimple_seq_add_stmt (ilist, g);
+ if (!is_ref)
+ {
+ SET_DECL_VALUE_EXPR (new_var, build_simple_mem_ref (allocate_ptr));
+ DECL_HAS_VALUE_EXPR_P (new_var) = 1;
+ }
+ return true;
+}
+
/* Generate code to implement the input clauses, FIRSTPRIVATE and COPYIN,
from the receiver (aka child) side and initializers for REFERENCE_TYPE
private variables. Initialization statements go in ILIST, while calls
bool task_reduction_p = false;
bool task_reduction_needs_orig_p = false;
tree cond = NULL_TREE;
+ tree allocator, allocate_ptr;
switch (c_kind)
{
if (task_reduction_p != (pass >= 2))
continue;
+ allocator = NULL_TREE;
+ allocate_ptr = NULL_TREE;
new_var = var = OMP_CLAUSE_DECL (c);
if ((c_kind == OMP_CLAUSE_REDUCTION
|| c_kind == OMP_CLAUSE_IN_REDUCTION)
if (c_kind != OMP_CLAUSE_FIRSTPRIVATE || !is_task_ctx (ctx))
{
- gcall *stmt;
- tree tmp, atmp;
+ tree tmp;
ptr = DECL_VALUE_EXPR (new_var);
gcc_assert (TREE_CODE (ptr) == INDIRECT_REF);
gcc_assert (DECL_P (ptr));
x = TYPE_SIZE_UNIT (TREE_TYPE (new_var));
- /* void *tmp = __builtin_alloca */
- atmp = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
- stmt = gimple_build_call (atmp, 2, x,
- size_int (DECL_ALIGN (var)));
- cfun->calls_alloca = 1;
- tmp = create_tmp_var_raw (ptr_type_node);
- gimple_add_tmp_var (tmp);
- gimple_call_set_lhs (stmt, tmp);
-
- gimple_seq_add_stmt (ilist, stmt);
+ if (lower_private_allocate (var, new_var, allocator,
+ allocate_ptr, ilist, ctx,
+ false, x))
+ tmp = allocate_ptr;
+ else
+ {
+ /* void *tmp = __builtin_alloca */
+ tree atmp
+ = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
+ gcall *stmt
+ = gimple_build_call (atmp, 2, x,
+ size_int (DECL_ALIGN (var)));
+ cfun->calls_alloca = 1;
+ tmp = create_tmp_var_raw (ptr_type_node);
+ gimple_add_tmp_var (tmp);
+ gimple_call_set_lhs (stmt, tmp);
+
+ gimple_seq_add_stmt (ilist, stmt);
+ }
x = fold_convert_loc (clause_loc, TREE_TYPE (ptr), tmp);
gimplify_assign (ptr, x, ilist);
x = build_receiver_ref (var, false, ctx);
x = build_fold_addr_expr_loc (clause_loc, x);
}
+ else if (lower_private_allocate (var, new_var, allocator,
+ allocate_ptr,
+ ilist, ctx, true, x))
+ x = allocate_ptr;
else if (TREE_CONSTANT (x))
{
/* For reduction in SIMD loop, defer adding the
tree nx;
bool copy_ctor;
copy_ctor = false;
+ lower_private_allocate (var, new_var, allocator, allocate_ptr,
+ ilist, ctx, false, NULL_TREE);
nx = unshare_expr (new_var);
if (is_simd
&& OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
x = lang_hooks.decls.omp_clause_dtor (c, new_var);
if (x)
gimplify_and_add (x, dlist);
+ if (allocator)
+ {
+ tree f = builtin_decl_explicit (BUILT_IN_GOMP_FREE);
+ gimple *g
+ = gimple_build_call (f, 2, allocate_ptr, allocator);
+ gimple_seq_add_stmt (dlist, g);
+ }
break;
case OMP_CLAUSE_LINEAR:
goto do_dtor;
}
do_firstprivate:
+ lower_private_allocate (var, new_var, allocator, allocate_ptr,
+ ilist, ctx, false, NULL_TREE);
x = build_outer_var_ref (var, ctx);
if (is_simd)
{
}
else
{
+ lower_private_allocate (var, new_var, allocator,
+ allocate_ptr, ilist, ctx, false,
+ NULL_TREE);
x = build_outer_var_ref (var, ctx);
if (omp_is_reference (var)
}
else
{
+ lower_private_allocate (var, new_var, allocator,
+ allocate_ptr, ilist, ctx,
+ false, NULL_TREE);
if (omp_is_reference (var) && is_simd)
handle_simd_reference (clause_loc, new_vard, ilist);
if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
ref = build_outer_var_ref (var, ctx);
gimplify_assign (ref, x, dlist);
}
+ if (allocator)
+ goto do_dtor;
}
}
break;
continue;
nvar = maybe_lookup_decl (ovar, ctx);
- if (!nvar || !DECL_HAS_VALUE_EXPR_P (nvar))
+ if (!nvar
+ || !DECL_HAS_VALUE_EXPR_P (nvar)
+ || (ctx->allocate_map
+ && ctx->allocate_map->get (ovar)))
continue;
/* If CTX is a nested parallel directive. Find the immediately
break;
case BUILT_IN_ALIGNED_ALLOC:
+ case BUILT_IN_GOMP_ALLOC:
{
tree align = get_constant_value (gimple_call_arg (stmt, 0));
if (align
CASE_BUILT_IN_ALLOCA:
case BUILT_IN_STRDUP:
case BUILT_IN_STRNDUP:
+ case BUILT_IN_GOMP_ALLOC:
return;
default:;
case BUILT_IN_CALLOC:
CASE_BUILT_IN_ALLOCA:
case BUILT_IN_FREE:
+ case BUILT_IN_GOMP_ALLOC:
+ case BUILT_IN_GOMP_FREE:
return false;
default:;
&& gimple_call_from_new_or_delete (as_a <gcall *> (stmt))
&& gimple_call_operator_delete_p (as_a <gcall *> (stmt)));
if (is_delete_operator
- || gimple_call_builtin_p (stmt, BUILT_IN_FREE))
+ || gimple_call_builtin_p (stmt, BUILT_IN_FREE)
+ || gimple_call_builtin_p (stmt, BUILT_IN_GOMP_FREE))
{
tree ptr = gimple_call_arg (stmt, 0);
gcall *def_stmt;
&& ((DECL_BUILT_IN_CLASS (def_callee) == BUILT_IN_NORMAL
&& (DECL_FUNCTION_CODE (def_callee) == BUILT_IN_ALIGNED_ALLOC
|| DECL_FUNCTION_CODE (def_callee) == BUILT_IN_MALLOC
- || DECL_FUNCTION_CODE (def_callee) == BUILT_IN_CALLOC))
+ || DECL_FUNCTION_CODE (def_callee) == BUILT_IN_CALLOC
+ || DECL_FUNCTION_CODE (def_callee) == BUILT_IN_GOMP_ALLOC))
|| (DECL_IS_REPLACEABLE_OPERATOR_NEW_P (def_callee)
&& gimple_call_from_new_or_delete (def_stmt))))
{
- if (is_delete_operator)
- {
- if (!valid_new_delete_pair_p (def_stmt, stmt))
- mark_operand_necessary (gimple_call_arg (stmt, 0));
-
- /* Delete operators can have alignment and (or) size
- as next arguments. When being a SSA_NAME, they
- must be marked as necessary. */
- if (gimple_call_num_args (stmt) >= 2)
- for (unsigned i = 1; i < gimple_call_num_args (stmt);
- i++)
- {
- tree arg = gimple_call_arg (stmt, i);
- if (TREE_CODE (arg) == SSA_NAME)
- mark_operand_necessary (arg);
- }
- }
+ if (is_delete_operator
+ && !valid_new_delete_pair_p (def_stmt, stmt))
+ mark_operand_necessary (gimple_call_arg (stmt, 0));
+
+ /* Delete operators can have alignment and (or) size
+ as next arguments. When being a SSA_NAME, they
+ must be marked as necessary. Similarly GOMP_free. */
+ if (gimple_call_num_args (stmt) >= 2)
+ for (unsigned i = 1; i < gimple_call_num_args (stmt);
+ i++)
+ {
+ tree arg = gimple_call_arg (stmt, i);
+ if (TREE_CODE (arg) == SSA_NAME)
+ mark_operand_necessary (arg);
+ }
continue;
}
ialias (omp_init_allocator)
ialias (omp_destroy_allocator)
-void *
-omp_alloc (size_t size, omp_allocator_handle_t allocator)
+static void *
+omp_aligned_alloc (size_t alignment, size_t size,
+ omp_allocator_handle_t allocator)
{
struct omp_allocator_data *allocator_data;
- size_t alignment, new_size;
+ size_t new_size;
void *ptr, *ret;
if (__builtin_expect (size == 0, 0))
if (allocator > omp_max_predefined_alloc)
{
allocator_data = (struct omp_allocator_data *) allocator;
- alignment = allocator_data->alignment;
+ if (alignment < allocator_data->alignment)
+ alignment = allocator_data->alignment;
}
else
{
allocator_data = NULL;
- alignment = sizeof (void *);
+ if (alignment < sizeof (void *))
+ alignment = sizeof (void *);
}
new_size = sizeof (struct omp_mem_header);
return NULL;
}
+void *
+omp_alloc (size_t size, omp_allocator_handle_t allocator)
+{
+ return omp_aligned_alloc (1, size, allocator);
+}
+
+/* Like omp_aligned_alloc, but apply on top of that:
+ "For allocations that arise from this ... the null_fb value of the
+ fallback allocator trait behaves as if the abort_fb had been specified." */
+
+void *
+GOMP_alloc (size_t alignment, size_t size, uintptr_t allocator)
+{
+ void *ret = omp_aligned_alloc (alignment, size,
+ (omp_allocator_handle_t) allocator);
+ if (__builtin_expect (ret == NULL, 0) && size)
+ gomp_fatal ("Out of memory allocating %lu bytes",
+ (unsigned long) size);
+ return ret;
+}
+
void
omp_free (void *ptr, omp_allocator_handle_t allocator)
{
}
free (data->ptr);
}
+
+ialias (omp_free)
+
+void
+GOMP_free (void *ptr, uintptr_t allocator)
+{
+ return omp_free (ptr, (omp_allocator_handle_t) allocator);
+}
GOMP_workshare_task_reduction_unregister;
} GOMP_4.5;
+GOMP_5.0.1 {
+ global:
+ GOMP_alloc;
+ GOMP_free;
+} GOMP_5.0;
+
OACC_2.0 {
global:
acc_get_num_devices;
extern void GOMP_teams_reg (void (*) (void *), void *, unsigned, unsigned,
unsigned);
+/* allocator.c */
+
+extern void *GOMP_alloc (size_t, size_t, uintptr_t);
+extern void GOMP_free (void *, uintptr_t);
+
/* oacc-async.c */
extern void GOACC_wait (int, int, ...);
extern omp_allocator_handle_t omp_get_default_allocator (void) __GOMP_NOTHROW;
extern void *omp_alloc (__SIZE_TYPE__,
omp_allocator_handle_t __GOMP_DEFAULT_NULL_ALLOCATOR)
- __GOMP_NOTHROW;
+ __GOMP_NOTHROW __attribute__((__malloc__, __alloc_size__ (1)));
extern void omp_free (void *,
omp_allocator_handle_t __GOMP_DEFAULT_NULL_ALLOCATOR)
__GOMP_NOTHROW;
--- /dev/null
+#include <omp.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+void
+foo (int &x, int &y, int &r, int &l, int (&l2)[4], int &l3, int &n, omp_allocator_handle_t h, int fl)
+{
+ int i;
+ typedef int T[x];
+ T v, w;
+ T &v2 = v;
+ T &w2 = w;
+ int xo = x;
+ for (i = 0; i < x; i++)
+ w[i] = i;
+ #pragma omp parallel private (y, v2) firstprivate (x) allocate (x, y, v2)
+ {
+ int *volatile p1 = &x;
+ int *volatile p2 = &y;
+ if (x != 42)
+ abort ();
+ #pragma omp barrier
+ *p2 = 1;
+ p1[0]++;
+ v2[0] = 7;
+ v2[41] = 8;
+ #pragma omp barrier
+ if (x != 43 || y != 1)
+ abort ();
+ if (v2[0] != 7 || v2[41] != 8)
+ abort ();
+ if ((fl & 2) && (((uintptr_t) p1 | (uintptr_t) p2
+ | (uintptr_t) &v2[0]) & 63) != 0)
+ abort ();
+ }
+ x = xo;
+ #pragma omp teams
+ #pragma omp parallel private (y) firstprivate (x, w2) allocate (h: x, y, w2)
+ {
+ int *volatile p1 = &x;
+ int *volatile p2 = &y;
+ if (x != 42 || w2[17] != 17 || w2[41] != 41)
+ abort ();
+ #pragma omp barrier
+ *p2 = 1;
+ p1[0]++;
+ w2[19]++;
+ #pragma omp barrier
+ if (x != 43 || y != 1 || w2[19] != 20)
+ abort ();
+ if ((fl & 1) && (((uintptr_t) p1 | (uintptr_t) p2
+ | (uintptr_t) &w2[0]) & 63) != 0)
+ abort ();
+ }
+ x = xo;
+ #pragma omp parallel for private (y) firstprivate (x) allocate (h: x, y, r, l, n) reduction(+: r) lastprivate (l) linear (n: 16)
+ for (i = 0; i < 64; i++)
+ {
+ if (x != 42)
+ abort ();
+ y = 1;
+ l = i;
+ n += y + 15;
+ r += i;
+ if ((fl & 1) && (((uintptr_t) &x | (uintptr_t) &y | (uintptr_t) &r
+ | (uintptr_t) &l | (uintptr_t) &n) & 63) != 0)
+ abort ();
+ }
+ #pragma omp parallel
+ {
+ #pragma omp for lastprivate (l2) allocate (h: l2, l3) lastprivate (conditional: l3)
+ for (i = 0; i < 64; i++)
+ {
+ l2[0] = i;
+ l2[1] = i + 1;
+ l2[2] = i + 2;
+ l2[3] = i + 3;
+ if (i < 37)
+ l3 = i;
+ if ((fl & 1) && (((uintptr_t) &l2[0] | (uintptr_t) &l3) & 63) != 0)
+ abort ();
+ }
+ }
+ if (r != 64 * 63 / 2 || l != 63 || n != 8 + 16 * 64)
+ abort ();
+ if (l2[0] != 63 || l2[1] != 63 + 1 || l2[2] != 63 + 2 || l2[3] != 63 + 3 || l3 != 36)
+ abort ();
+}
+
+void
+bar (int &x, int &y, int &r, int &l, int (&l2)[4], int &l3, int &n, omp_allocator_handle_t h)
+{
+ int i;
+ typedef int T[x];
+ T v, w;
+ T &v2 = v;
+ T &w2 = w;
+ int xo = x;
+ for (i = 0; i < x; i++)
+ w[i] = i;
+ #pragma omp parallel private (y, v2) firstprivate (x) allocate (x, y, v2)
+ {
+ int *volatile p1 = &x;
+ int *volatile p2 = &y;
+ if (x != 42)
+ abort ();
+ #pragma omp barrier
+ *p2 = 1;
+ p1[0]++;
+ v2[0] = 7;
+ v2[41] = 8;
+ #pragma omp barrier
+ if (x != 43 || y != 1)
+ abort ();
+ if (v2[0] != 7 || v2[41] != 8)
+ abort ();
+ }
+ x = xo;
+ #pragma omp teams
+ #pragma omp parallel private (y) firstprivate (x, w2) allocate (h: x, y, w2)
+ {
+ int *volatile p1 = &x;
+ int *volatile p2 = &y;
+ if (x != 42 || w2[17] != 17 || w2[41] != 41)
+ abort ();
+ #pragma omp barrier
+ *p2 = 1;
+ p1[0]++;
+ #pragma omp barrier
+ if (x != 43 || y != 1)
+ abort ();
+ }
+ x = xo;
+ #pragma omp parallel for private (y) firstprivate (x) allocate (h: x, y, r, l, n) reduction(+: r) lastprivate (l) linear (n: 16)
+ for (i = 0; i < 64; i++)
+ {
+ if (x != 42)
+ abort ();
+ y = 1;
+ l = i;
+ n += y + 15;
+ r += i;
+ }
+ #pragma omp parallel
+ {
+ #pragma omp for lastprivate (l2) allocate (h: l2, l3) lastprivate (conditional: l3)
+ for (i = 0; i < 64; i++)
+ {
+ l2[0] = i;
+ l2[1] = i + 1;
+ l2[2] = i + 2;
+ l2[3] = i + 3;
+ if (i < 37)
+ l3 = i;
+ }
+ }
+ if (r != 64 * 63 / 2 || l != 63 || n != 8 + 16 * 64)
+ abort ();
+ if (l2[0] != 63 || l2[1] != 63 + 1 || l2[2] != 63 + 2 || l2[3] != 63 + 3 || l3 != 36)
+ abort ();
+}
+
+int
+main ()
+{
+ omp_alloctrait_t traits[3]
+ = { { omp_atk_alignment, 64 },
+ { omp_atk_fallback, omp_atv_null_fb } };
+ omp_allocator_handle_t a
+ = omp_init_allocator (omp_default_mem_space, 2, traits);
+ if (a == omp_null_allocator)
+ abort ();
+ omp_set_default_allocator (omp_default_mem_alloc);
+ int x = 42, y = 0, r = 0, l, l2[4], l3, n = 8;
+ foo (x, y, r, l, l2, l3, n, omp_null_allocator, 0);
+ x = 42; y = 0; r = 0; l = -1; l2[0] = -1; l2[1] = -1;
+ l2[2] = -1; l2[3] = -1; n = 8;
+ foo (x, y, r, l, l2, l3, n, omp_default_mem_alloc, 0);
+ x = 42; y = 0; r = 0; l = -1; l2[0] = -1; l2[1] = -1;
+ l2[2] = -1; l2[3] = -1; n = 8;
+ foo (x, y, r, l, l2, l3, n, a, 1);
+ x = 42; y = 0; r = 0; l = -1; l2[0] = -1; l2[1] = -1;
+ l2[2] = -1; l2[3] = -1; n = 8;
+ omp_set_default_allocator (a);
+ foo (x, y, r, l, l2, l3, n, omp_null_allocator, 3);
+ x = 42; y = 0; r = 0; l = -1; l2[0] = -1; l2[1] = -1;
+ l2[2] = -1; l2[3] = -1; n = 8;
+ foo (x, y, r, l, l2, l3, n, omp_default_mem_alloc, 2);
+ x = 42; y = 0; r = 0; l = -1; l2[0] = -1; l2[1] = -1;
+ l2[2] = -1; l2[3] = -1; n = 8;
+ bar (x, y, r, l, l2, l3, n, a);
+ omp_destroy_allocator (a);
+ return 0;
+}
--- /dev/null
+#include <omp.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+void
+foo (int x, omp_allocator_handle_t h, int fl)
+{
+ int y = 0, r = 0, i, i1, l, l2[4], l3, n = 8;
+ int i2, j2, n2 = 9, l4;
+ int i3, j3, n3 = 10, l5;
+ int i4, j4, n4 = 11, l6;
+ int i5;
+ int v[x], w[x];
+ int xo = x;
+ for (i = 0; i < x; i++)
+ w[i] = i;
+ #pragma omp parallel private (y, v) firstprivate (x) allocate (x, y, v)
+ {
+ int *volatile p1 = &x;
+ int *volatile p2 = &y;
+ if (x != 42)
+ abort ();
+ #pragma omp barrier
+ *p2 = 1;
+ p1[0]++;
+ v[0] = 7;
+ v[41] = 8;
+ #pragma omp barrier
+ if (x != 43 || y != 1)
+ abort ();
+ if (v[0] != 7 || v[41] != 8)
+ abort ();
+ if ((fl & 2) && (((uintptr_t) p1 | (uintptr_t) p2
+ | (uintptr_t) &v[0]) & 63) != 0)
+ abort ();
+ }
+ x = xo;
+ #pragma omp teams
+ #pragma omp parallel private (y) firstprivate (x, w) allocate (h: x, y, w)
+ {
+ int *volatile p1 = &x;
+ int *volatile p2 = &y;
+ if (x != 42 || w[17] != 17 || w[41] != 41)
+ abort ();
+ #pragma omp barrier
+ *p2 = 1;
+ p1[0]++;
+ w[19]++;
+ #pragma omp barrier
+ if (x != 43 || y != 1 || w[19] != 20)
+ abort ();
+ if ((fl & 1) && (((uintptr_t) p1 | (uintptr_t) p2
+ | (uintptr_t) &w[0]) & 63) != 0)
+ abort ();
+ }
+ x = xo;
+ #pragma omp parallel for private (y) firstprivate (x) allocate (h: x, y, r, l, n) reduction(+: r) lastprivate (l) linear (n: 16)
+ for (i = 0; i < 64; i++)
+ {
+ if (x != 42)
+ abort ();
+ y = 1;
+ l = i;
+ n += y + 15;
+ r += i;
+ if ((fl & 1) && (((uintptr_t) &x | (uintptr_t) &y | (uintptr_t) &r
+ | (uintptr_t) &l | (uintptr_t) &n) & 63) != 0)
+ abort ();
+ }
+ #pragma omp parallel
+ {
+ #pragma omp for lastprivate (l2) private (i1) allocate (h: l2, l3, i1) lastprivate (conditional: l3)
+ for (i1 = 0; i1 < 64; i1++)
+ {
+ l2[0] = i1;
+ l2[1] = i1 + 1;
+ l2[2] = i1 + 2;
+ l2[3] = i1 + 3;
+ if (i1 < 37)
+ l3 = i1;
+ if ((fl & 1) && (((uintptr_t) &l2[0] | (uintptr_t) &l3 | (uintptr_t) &i1) & 63) != 0)
+ abort ();
+ }
+ #pragma omp for collapse(2) lastprivate(l4, i2, j2) linear (n2:17) allocate (h: n2, l4, i2, j2)
+ for (i2 = 3; i2 < 5; i2++)
+ for (j2 = 17; j2 < 22; j2 += 2)
+ {
+ n2 += 17;
+ l4 = i2 * 31 + j2;
+ if ((fl & 1) && (((uintptr_t) &l4 | (uintptr_t) &n2
+ | (uintptr_t) &i2 | (uintptr_t) &j2) & 63) != 0)
+ abort ();
+ }
+ #pragma omp for collapse(2) lastprivate(l5, i3, j3) linear (n3:17) schedule (static, 3) allocate (n3, l5, i3, j3)
+ for (i3 = 3; i3 < 5; i3++)
+ for (j3 = 17; j3 < 23; j3 += 2)
+ {
+ n3 += 17;
+ l5 = i3 * 31 + j3;
+ if ((fl & 2) && (((uintptr_t) &l5 | (uintptr_t) &n3
+ | (uintptr_t) &i3 | (uintptr_t) &j3) & 63) != 0)
+ abort ();
+ }
+ #pragma omp for collapse(2) lastprivate(l6, i4, j4) linear (n4:17) schedule (dynamic) allocate (h: n4, l6, i4, j4)
+ for (i4 = 3; i4 < 5; i4++)
+ for (j4 = 17; j4 < 22; j4 += 2)
+ {
+ n4 += 17;
+ l6 = i4 * 31 + j4;
+ if ((fl & 1) && (((uintptr_t) &l6 | (uintptr_t) &n4
+ | (uintptr_t) &i4 | (uintptr_t) &j4) & 63) != 0)
+ abort ();
+ }
+ #pragma omp for lastprivate (i5) allocate (i5)
+ for (i5 = 1; i5 < 17; i5 += 3)
+ {
+ if ((fl & 2) && (((uintptr_t) &i5) & 63) != 0)
+ abort ();
+ }
+ }
+ if (r != 64 * 63 / 2 || l != 63 || n != 8 + 16 * 64)
+ abort ();
+ if (l2[0] != 63 || l2[1] != 63 + 1 || l2[2] != 63 + 2 || l2[3] != 63 + 3 || l3 != 36)
+ abort ();
+ if (i2 != 5 || j2 != 23 || n2 != 9 + 6 * 17 || l4 != 4 * 31 + 21)
+ abort ();
+ if (i3 != 5 || j3 != 23 || n3 != 10 + 6 * 17 || l5 != 4 * 31 + 21)
+ abort ();
+ if (i4 != 5 || j4 != 23 || n4 != 11 + 6 * 17 || l6 != 4 * 31 + 21)
+ abort ();
+ if (i5 != 19)
+ abort ();
+}
+
+void
+bar (int x, omp_allocator_handle_t h)
+{
+ int y = 0, r = 0, i, i1, l, l2[4], l3, n = 8;
+ int i2, j2, n2 = 9, l4;
+ int i3, j3, n3 = 10, l5;
+ int i4, j4, n4 = 11, l6;
+ int i5;
+ int xo = x;
+ #pragma omp parallel private (y) firstprivate (x) allocate (x, y)
+ {
+ int *volatile p1 = &x;
+ int *volatile p2 = &y;
+ if (x != 42)
+ abort ();
+ #pragma omp barrier
+ *p2 = 1;
+ p1[0]++;
+ #pragma omp barrier
+ if (x != 43 || y != 1)
+ abort ();
+ }
+ x = xo;
+ #pragma omp teams
+ #pragma omp parallel private (y) firstprivate (x) allocate (h: x, y)
+ {
+ int *volatile p1 = &x;
+ int *volatile p2 = &y;
+ if (x != 42)
+ abort ();
+ #pragma omp barrier
+ *p2 = 1;
+ p1[0]++;
+ #pragma omp barrier
+ if (x != 43 || y != 1)
+ abort ();
+ }
+ x = xo;
+ #pragma omp parallel for private (y) firstprivate (x) allocate (h: x, y, r, l, n) reduction(+: r) lastprivate (l) linear (n: 16)
+ for (i = 0; i < 64; i++)
+ {
+ if (x != 42)
+ abort ();
+ y = 1;
+ l = i;
+ n += y + 15;
+ r += i;
+ }
+ #pragma omp parallel
+ {
+ #pragma omp for lastprivate (l2) private (i1) allocate (h: l2, l3, i1) lastprivate (conditional: l3)
+ for (i1 = 0; i1 < 64; i1++)
+ {
+ l2[0] = i1;
+ l2[1] = i1 + 1;
+ l2[2] = i1 + 2;
+ l2[3] = i1 + 3;
+ if (i1 < 37)
+ l3 = i1;
+ }
+ #pragma omp for collapse(2) lastprivate(l4, i2, j2) linear (n2:17) allocate (h: n2, l4, i2, j2)
+ for (i2 = 3; i2 < 5; i2++)
+ for (j2 = 17; j2 < 22; j2 += 2)
+ {
+ n2 += 17;
+ l4 = i2 * 31 + j2;
+ }
+ #pragma omp for collapse(2) lastprivate(l5, i3, j3) linear (n3:17) schedule (static, 3) allocate (n3, l5, i3, j3)
+ for (i3 = 3; i3 < 5; i3++)
+ for (j3 = 17; j3 < 23; j3 += 2)
+ {
+ n3 += 17;
+ l5 = i3 * 31 + j3;
+ }
+ #pragma omp for collapse(2) lastprivate(l6, i4, j4) linear (n4:17) schedule (dynamic) allocate (h: n4, l6, i4, j4)
+ for (i4 = 3; i4 < 5; i4++)
+ for (j4 = 17; j4 < 22; j4 += 2)
+ {
+ n4 += 17;
+ l6 = i4 * 31 + j4;
+ }
+ #pragma omp for lastprivate (i5) allocate (i5)
+ for (i5 = 1; i5 < 17; i5 += 3)
+ ;
+ }
+ if (r != 64 * 63 / 2 || l != 63 || n != 8 + 16 * 64)
+ abort ();
+ if (l2[0] != 63 || l2[1] != 63 + 1 || l2[2] != 63 + 2 || l2[3] != 63 + 3 || l3 != 36)
+ abort ();
+ if (i2 != 5 || j2 != 23 || n2 != 9 + 6 * 17 || l4 != 4 * 31 + 21)
+ abort ();
+ if (i3 != 5 || j3 != 23 || n3 != 10 + 6 * 17 || l5 != 4 * 31 + 21)
+ abort ();
+ if (i4 != 5 || j4 != 23 || n4 != 11 + 6 * 17 || l6 != 4 * 31 + 21)
+ abort ();
+ if (i5 != 19)
+ abort ();
+}
+
+int
+main ()
+{
+ omp_alloctrait_t traits[3]
+ = { { omp_atk_alignment, 64 },
+ { omp_atk_fallback, omp_atv_null_fb } };
+ omp_allocator_handle_t a
+ = omp_init_allocator (omp_default_mem_space, 2, traits);
+ if (a == omp_null_allocator)
+ abort ();
+ omp_set_default_allocator (omp_default_mem_alloc);
+ foo (42, omp_null_allocator, 0);
+ foo (42, omp_default_mem_alloc, 0);
+ foo (42, a, 1);
+ omp_set_default_allocator (a);
+ foo (42, omp_null_allocator, 3);
+ foo (42, omp_default_mem_alloc, 2);
+ bar (42, a);
+ omp_destroy_allocator (a);
+ return 0;
+}