2015-09-23 Nathan Sidwell <nathan@codesourcery.com>
* target.def: GOACC hooks take gcall arg.
* doc/tm.texi: Regenerate.
* targhooks.h (default_goacc_reduction, default_goacc_fork_join,
default_coacc_lock): Gimple is a gcall pointer.
* omp-low.c (oacc_xform_on_device): Arg is a gcall. Adjust.
(oacc_xform_dim): Likewise.
(execute_oacc_transform): Adjust to pass gcall pointer to worker
functions. Handle rescan immediately.
(default_goacc_reduction, default_goacc_fork_join,
default_coacc_lock): Gimple is a gcall pointer.
* config/nvptx/nvptx.c (nvptx_xform_fork_join,
nvptx_xform_lock, nvptx_goacc_reduction_setup,
nvptx_goacc_reduction_init, nvptx_goacc_reduction_fini,
nvptx_goacc_reduction_teardown, nvptx_goacc_reduction): Argument
is a gcall, adjust.
===================================================================
@@ -1667,7 +1667,7 @@ DEFHOOK
calls to target-specific gimple. It is executed during the oacc_xform\n\
pass. It should return true, if the functions should be deleted. The\n\
default hook returns true, if there are no RTL expanders for them.",
-bool, (gimple stmt, const int dims[], bool is_fork),
+bool, (gcall *call, const int dims[], bool is_fork),
default_goacc_fork_join)
DEFHOOK
@@ -1677,7 +1677,7 @@ IFN_GOACC_LOCK_INIT function calls to ta
executed during the oacc_xform pass. It should return true, if the\n\
functions should be deleted. The default hook returns true, if there\n\
are no RTL expanders for them.",
-bool, (gimple stmt, const int dims[], unsigned ifn_code),
+bool, (gcall *call, const int dims[], unsigned ifn_code),
default_goacc_lock)
DEFHOOK
@@ -1692,7 +1692,7 @@ hook removes statement @var{call} after
inserted. This hook is also responsible for allocating any storage for\n\
reductions when necessary. It returns @var{true} if the expanded\n\
sequence introduces any calls to OpenACC-specific internal functions.",
-bool, (gimple call),
+bool, (gcall *call),
default_goacc_reduction)
HOOK_VECTOR_END (goacc)
===================================================================
@@ -14689,9 +14660,9 @@ make_pass_late_lower_omp (gcc::context *
offloaded function we're never 'none'. */
static void
-oacc_xform_on_device (gimple stmt)
+oacc_xform_on_device (gcall *call)
{
- tree arg = gimple_call_arg (stmt, 0);
+ tree arg = gimple_call_arg (call, 0);
unsigned val = GOMP_DEVICE_HOST;
#ifdef ACCEL_COMPILER
@@ -14708,14 +14679,14 @@ oacc_xform_on_device (gimple stmt)
}
#endif
result = fold_convert (integer_type_node, result);
- tree lhs = gimple_call_lhs (stmt);
+ tree lhs = gimple_call_lhs (call);
gimple_seq seq = NULL;
push_gimplify_context (true);
gimplify_assign (lhs, result, &seq);
pop_gimplify_context (NULL);
- gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
+ gimple_stmt_iterator gsi = gsi_for_stmt (call);
gsi_replace_with_seq (&gsi, seq, false);
}
@@ -14723,9 +14694,9 @@ oacc_xform_on_device (gimple stmt)
constants, where possible. */
static void
-oacc_xform_dim (gimple stmt, const int dims[], bool is_pos)
+oacc_xform_dim (gcall *call, const int dims[], bool is_pos)
{
- tree arg = gimple_call_arg (stmt, 0);
+ tree arg = gimple_call_arg (call, 0);
unsigned axis = (unsigned)TREE_INT_CST_LOW (arg);
int size = dims[axis];
@@ -14742,11 +14713,11 @@ oacc_xform_dim (gimple stmt, const int d
}
/* Replace the internal call with a constant. */
- tree lhs = gimple_call_lhs (stmt);
+ tree lhs = gimple_call_lhs (call);
gimple g = gimple_build_assign
(lhs, build_int_cst (integer_type_node, size));
- gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
+ gimple_stmt_iterator gsi = gsi_for_stmt (call);
gsi_replace (&gsi, g, false);
}
@@ -14815,10 +14786,8 @@ oacc_validate_dims (tree fn, tree attrs,
static unsigned int
execute_oacc_transform ()
{
- basic_block bb;
tree attrs = get_oacc_fn_attrib (current_function_decl);
int dims[GOMP_DIM_MAX];
- bool needs_rescan;
if (!attrs)
/* Not an offloaded function. */
@@ -14830,80 +14799,97 @@ execute_oacc_transform ()
dominance information to update SSA. */
calculate_dominance_info (CDI_DOMINATORS);
- do
- {
- needs_rescan = false;
-
- FOR_ALL_BB_FN (bb, cfun)
- for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
+ basic_block bb;
+ FOR_ALL_BB_FN (bb, cfun)
+ for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
+ {
+ gimple stmt = gsi_stmt (gsi);
+ int rescan = 0;
+
+ if (!is_gimple_call (stmt))
{
- gimple stmt = gsi_stmt (gsi);
+ gsi_next (&gsi);
+ continue;
+ }
- if (!is_gimple_call (stmt))
- ; /* Nothing. */
- else if (gimple_call_builtin_p (stmt, BUILT_IN_ACC_ON_DEVICE))
- /* acc_on_device must be evaluated at compile time for
- constant arguments. */
- {
- gsi_next (&gsi);
- oacc_xform_on_device (stmt);
- continue;
- }
- else if (gimple_call_internal_p (stmt))
+ /* Rewind to allow rescan. */
+ gsi_prev (&gsi);
+
+ gcall *call = as_a <gcall *> (stmt);
+
+ if (gimple_call_builtin_p (call, BUILT_IN_ACC_ON_DEVICE))
+ /* acc_on_device must be evaluated at compile time for
+ constant arguments. */
+ {
+ oacc_xform_on_device (call);
+ rescan = 1;
+ }
+ else if (gimple_call_internal_p (call))
+ {
+ unsigned ifn_code = gimple_call_internal_fn (call);
+ switch (ifn_code)
{
- unsigned ifn_code = gimple_call_internal_fn (stmt);
- switch (ifn_code)
- {
- default: break;
+ default: break;
- case IFN_GOACC_DIM_POS:
- case IFN_GOACC_DIM_SIZE:
- gsi_next (&gsi);
- oacc_xform_dim (stmt, dims, ifn_code == IFN_GOACC_DIM_POS);
- continue;
-
- case IFN_GOACC_LOCK:
- case IFN_GOACC_UNLOCK:
- case IFN_GOACC_LOCK_INIT:
- if (targetm.goacc.lock (stmt, dims, ifn_code))
- goto remove;
- break;
-
- case IFN_GOACC_REDUCTION_SETUP:
- case IFN_GOACC_REDUCTION_INIT:
- case IFN_GOACC_REDUCTION_FINI:
- case IFN_GOACC_REDUCTION_TEARDOWN:
- gsi_next (&gsi);
- if (targetm.goacc.reduction (stmt))
- needs_rescan = true;
- continue;
-
- case IFN_UNIQUE:
- {
- unsigned code;
-
- code = TREE_INT_CST_LOW (gimple_call_arg (stmt, 0));
-
- if ((code == IFN_UNIQUE_OACC_FORK
- || code == IFN_UNIQUE_OACC_JOIN)
- && (targetm.goacc.fork_join
- (stmt, dims, code == IFN_UNIQUE_OACC_FORK)))
- {
- remove:
- replace_uses_by (gimple_vdef (stmt),
- gimple_vuse (stmt));
- gsi_remove (&gsi, true);
- /* Removal will have advanced the iterator. */
- continue;
- }
- }
-
- break;
- }
+ case IFN_GOACC_DIM_POS:
+ case IFN_GOACC_DIM_SIZE:
+ oacc_xform_dim (call, dims, ifn_code == IFN_GOACC_DIM_POS);
+ rescan = 0;
+ break;
+
+ case IFN_GOACC_LOCK:
+ case IFN_GOACC_UNLOCK:
+ case IFN_GOACC_LOCK_INIT:
+ if (targetm.goacc.lock (call, dims, ifn_code))
+ rescan = -1;
+ break;
+
+ case IFN_GOACC_REDUCTION_SETUP:
+ case IFN_GOACC_REDUCTION_INIT:
+ case IFN_GOACC_REDUCTION_FINI:
+ case IFN_GOACC_REDUCTION_TEARDOWN:
+ /* Mark the function for SSA renaming. */
+ mark_virtual_operands_for_renaming (cfun);
+ if (targetm.goacc.reduction (call))
+ rescan = 1;
+ break;
+
+ case IFN_UNIQUE:
+ {
+ unsigned code;
+
+ code = TREE_INT_CST_LOW (gimple_call_arg (call, 0));
+
+ if ((code == IFN_UNIQUE_OACC_FORK
+ || code == IFN_UNIQUE_OACC_JOIN)
+ && (targetm.goacc.fork_join
+ (call, dims, code == IFN_UNIQUE_OACC_FORK)))
+ rescan = -1;
+ break;
+ }
}
+ }
+ if (gsi_end_p (gsi))
+ /* We rewound past the beginning of the BB. */
+ gsi = gsi_start_bb (bb);
+ else
+ /* Undo the rewind. */
+ gsi_next (&gsi);
+
+ if (!rescan)
+ {
+ /* If not rescanning, advance over the call. */
+ if (gsi_end_p (gsi))
+ break;
gsi_next (&gsi);
}
- } while (needs_rescan);
+ else if (rescan < 0)
+ {
+ replace_uses_by (gimple_vdef (call),
+ gimple_vuse (call));
+ gsi_remove (&gsi, true);
+ }
+ }
return 0;
}
@@ -14946,7 +14932,7 @@ default_goacc_dim_limit (unsigned ARG_UN
there is no RTL expander. */
bool
-default_goacc_fork_join (gimple ARG_UNUSED (stmt),
+default_goacc_fork_join (gcall *ARG_UNUSED (call),
const int *ARG_UNUSED (dims), bool is_fork)
{
if (is_fork)
@@ -14969,7 +14955,7 @@ default_goacc_fork_join (gimple ARG_UNUS
there is no RTL expander. */
bool
-default_goacc_lock (gimple ARG_UNUSED (stmt), const int*ARG_UNUSED (dims),
+default_goacc_lock (gcall *ARG_UNUSED (call), const int*ARG_UNUSED (dims),
unsigned ifn_code)
{
switch (ifn_code)
@@ -15003,12 +14989,10 @@ default_goacc_lock (gimple ARG_UNUSED (s
SETUP - emit 'LHS = *RES_PTR', LHS = NULL
TEARDOWN - emit '*RES_PTR = VAR'
If LHS is not NULL
- emit 'LHS = VAR'
-
- Return false -- does not need a rescan. */
+ emit 'LHS = VAR' */
bool
-default_goacc_reduction (gimple call)
+default_goacc_reduction (gcall *call)
{
gimple_stmt_iterator gsi = gsi_for_stmt (call);
tree lhs = gimple_call_lhs (call);
@@ -15016,9 +15000,6 @@ default_goacc_reduction (gimple call)
unsigned code = gimple_call_internal_fn (call);
gimple_seq seq = NULL;
- /* Mark the function for SSA renaming. */
- mark_virtual_operands_for_renaming (cfun);
-
if (code == IFN_GOACC_REDUCTION_SETUP
|| code == IFN_GOACC_REDUCTION_TEARDOWN)
{
===================================================================
@@ -5753,14 +5753,14 @@ This hook should return the maximum size
or zero if unbounded.
@end deftypefn
-@deftypefn {Target Hook} bool TARGET_GOACC_FORK_JOIN (gimple @var{stmt}, const int @var{dims[]}, bool @var{is_fork})
+@deftypefn {Target Hook} bool TARGET_GOACC_FORK_JOIN (gcall *@var{call}, const int @var{dims[]}, bool @var{is_fork})
This hook should convert IFN_GOACC_FORK and IFN_GOACC_JOIN function
calls to target-specific gimple. It is executed during the oacc_xform
pass. It should return true, if the functions should be deleted. The
default hook returns true, if there are no RTL expanders for them.
@end deftypefn
-@deftypefn {Target Hook} bool TARGET_GOACC_LOCK (gimple @var{stmt}, const int @var{dims[]}, unsigned @var{ifn_code})
+@deftypefn {Target Hook} bool TARGET_GOACC_LOCK (gcall *@var{call}, const int @var{dims[]}, unsigned @var{ifn_code})
This hook should convert IFN_GOACC_LOCK, IFN_GOACC_UNLOCK,
IFN_GOACC_LOCK_INIT function calls to target-specific gimple. It is
executed during the oacc_xform pass. It should return true, if the
@@ -5768,7 +5768,7 @@ functions should be deleted. The defaul
are no RTL expanders for them.
@end deftypefn
-@deftypefn {Target Hook} bool TARGET_GOACC_REDUCTION (gimple @var{call})
+@deftypefn {Target Hook} bool TARGET_GOACC_REDUCTION (gcall *@var{call})
This hook is used by the oacc_transform pass to expand calls to the
internal functions @var{GOACC_REDUCTION_SETUP},
@var{GOACC_REDUCTION_INIT},
===================================================================
@@ -4400,10 +4400,10 @@ nvptx_dim_limit (unsigned axis)
/* Determine whether fork & joins are needed. */
static bool
-nvptx_xform_fork_join (gimple stmt, const int dims[],
+nvptx_xform_fork_join (gcall *call, const int dims[],
bool ARG_UNUSED (is_fork))
{
- tree arg = gimple_call_arg (stmt, 1);
+ tree arg = gimple_call_arg (call, 1);
unsigned axis = TREE_INT_CST_LOW (arg);
/* We only care about worker and vector partitioning. */
@@ -4421,9 +4421,9 @@ nvptx_xform_fork_join (gimple stmt, cons
*/
static bool
-nvptx_xform_lock (gimple stmt, const int *ARG_UNUSED (dims), unsigned ifn_code)
+nvptx_xform_lock (gcall *call, const int *ARG_UNUSED (dims), unsigned ifn_code)
{
- tree arg = gimple_call_arg (stmt, 0);
+ tree arg = gimple_call_arg (call, 0);
unsigned mode = TREE_INT_CST_LOW (arg);
switch (ifn_code)
@@ -4542,7 +4542,7 @@ nvptx_generate_vector_shuffle (location_
*/
static bool
-nvptx_goacc_reduction_setup (gimple call)
+nvptx_goacc_reduction_setup (gcall *call)
{
gimple_stmt_iterator gsi = gsi_for_stmt (call);
tree lhs = gimple_call_lhs (call);
@@ -4611,7 +4611,7 @@ nvptx_goacc_reduction_setup (gimple call
*/
static bool
-nvptx_goacc_reduction_init (gimple call)
+nvptx_goacc_reduction_init (gcall *call)
{
gimple_stmt_iterator gsi = gsi_for_stmt (call);
tree lhs = gimple_call_lhs (call);
@@ -4718,7 +4718,7 @@ nvptx_goacc_reduction_init (gimple call)
*/
static bool
-nvptx_goacc_reduction_fini (gimple call)
+nvptx_goacc_reduction_fini (gcall *call)
{
gimple_stmt_iterator gsi = gsi_for_stmt (call);
tree lhs = gimple_call_lhs (call);
@@ -4815,7 +4815,7 @@ nvptx_goacc_reduction_fini (gimple call)
*/
static bool
-nvptx_goacc_reduction_teardown (gimple call)
+nvptx_goacc_reduction_teardown (gcall *call)
{
gimple_stmt_iterator gsi = gsi_for_stmt (call);
tree lhs = gimple_call_lhs (call);
@@ -4860,12 +4860,8 @@ nvptx_goacc_reduction_teardown (gimple c
/* Default goacc.reduction early expander. */
bool
-nvptx_goacc_reduction (gimple call)
+nvptx_goacc_reduction (gcall *call)
{
- /* Reductions modify the SSA names in complicated ways. Let update_ssa
- correct it. */
- mark_virtual_operands_for_renaming (cfun);
-
switch (gimple_call_internal_fn (call))
{
case IFN_GOACC_REDUCTION_SETUP:
===================================================================
@@ -107,11 +107,11 @@ extern unsigned default_add_stmt_cost (v
extern void default_finish_cost (void *, unsigned *, unsigned *, unsigned *);
extern void default_destroy_cost_data (void *);
-extern bool default_goacc_reduction (gimple);
+extern bool default_goacc_reduction (gcall *);
extern bool default_goacc_validate_dims (tree, int [], int);
extern unsigned default_goacc_dim_limit (unsigned);
-extern bool default_goacc_fork_join (gimple, const int [], bool);
-extern bool default_goacc_lock (gimple, const int [], unsigned);
+extern bool default_goacc_fork_join (gcall *, const int [], bool);
+extern bool default_goacc_lock (gcall *, const int [], unsigned);
/* These are here, and not in hooks.[ch], because not all users of
hooks.h include tm.h, and thus we don't have CUMULATIVE_ARGS. */