Skip to content

Commit 084ea8a

Browse files
committed
OpenMP: middle-end support for dispatch + adjust_args
This patch adds middle-end support for the `dispatch` construct and the `adjust_args` clause. The heavy lifting is done in `gimplify_omp_dispatch` and `gimplify_call_expr` respectively. For `adjust_args`, this mostly consists in emitting a call to `omp_get_mapped_ptr` for the adequate device. For dispatch, the following steps are performed: * Handle the device clause, if any: set the default-device ICV at the top of the dispatch region and restore its previous value at the end. * Handle novariants and nocontext clauses, if any. Evaluate compile-time constants and select a variant, if possible. Otherwise, emit code to handle all possible cases at run time. gcc/ChangeLog: * builtins.cc (builtin_fnspec): Handle BUILT_IN_OMP_GET_MAPPED_PTR. * gimple-low.cc (lower_stmt): Handle GIMPLE_OMP_DISPATCH. * gimple-pretty-print.cc (dump_gimple_omp_dispatch): New function. (pp_gimple_stmt_1): Handle GIMPLE_OMP_DISPATCH. * gimple-walk.cc (walk_gimple_stmt): Likewise. * gimple.cc (gimple_build_omp_dispatch): New function. (gimple_copy): Handle GIMPLE_OMP_DISPATCH. * gimple.def (GIMPLE_OMP_DISPATCH): Define. * gimple.h (gimple_build_omp_dispatch): Declare. (gimple_has_substatements): Handle GIMPLE_OMP_DISPATCH. (gimple_omp_dispatch_clauses): New function. (gimple_omp_dispatch_clauses_ptr): Likewise. (gimple_omp_dispatch_set_clauses): Likewise. (gimple_return_set_retval): Handle GIMPLE_OMP_DISPATCH. * gimplify.cc (enum omp_region_type): Add ORT_DISPATCH. (struct gimplify_omp_ctx): Add in_call_args. (gimplify_call_expr): Handle need_device_ptr arguments. (is_gimple_stmt): Handle OMP_DISPATCH. (gimplify_scan_omp_clauses): Handle OMP_CLAUSE_DEVICE in a dispatch construct. Handle OMP_CLAUSE_NOVARIANTS and OMP_CLAUSE_NOCONTEXT. (omp_has_novariants): New function. (omp_has_nocontext): Likewise. (omp_construct_selector_matches): Handle OMP_DISPATCH with nocontext clause. (find_ifn_gomp_dispatch): New function. (gimplify_omp_dispatch): Likewise. (gimplify_expr): Handle OMP_DISPATCH. * gimplify.h (omp_has_novariants): Declare. * internal-fn.cc (expand_GOMP_DISPATCH): New function. * internal-fn.def (GOMP_DISPATCH): Define. * omp-builtins.def (BUILT_IN_OMP_GET_MAPPED_PTR): Define. (BUILT_IN_OMP_GET_DEFAULT_DEVICE): Define. (BUILT_IN_OMP_SET_DEFAULT_DEVICE): Define. * omp-general.cc (omp_construct_traits_to_codes): Add OMP_DISPATCH. (struct omp_ts_info): Add dispatch. (omp_resolve_declare_variant): Handle novariants. Adjust DECL_ASSEMBLER_NAME. * omp-low.cc (scan_omp_1_stmt): Handle GIMPLE_OMP_DISPATCH. (lower_omp_dispatch): New function. (lower_omp_1): Call it. * tree-inline.cc (remap_gimple_stmt): Handle GIMPLE_OMP_DISPATCH. (estimate_num_insns): Handle GIMPLE_OMP_DISPATCH.
1 parent 0e15f1d commit 084ea8a

15 files changed

+641
-22
lines changed

gcc/builtins.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12583,6 +12583,8 @@ builtin_fnspec (tree callee)
1258312583
by its first argument. */
1258412584
case BUILT_IN_POSIX_MEMALIGN:
1258512585
return ".cOt";
12586+
case BUILT_IN_OMP_GET_MAPPED_PTR:
12587+
return ". R ";
1258612588

1258712589
default:
1258812590
return "";

gcc/gimple-low.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ lower_stmt (gimple_stmt_iterator *gsi, struct lower_data *data)
746746
case GIMPLE_EH_MUST_NOT_THROW:
747747
case GIMPLE_OMP_FOR:
748748
case GIMPLE_OMP_SCOPE:
749+
case GIMPLE_OMP_DISPATCH:
749750
case GIMPLE_OMP_SECTIONS:
750751
case GIMPLE_OMP_SECTIONS_SWITCH:
751752
case GIMPLE_OMP_SECTION:

gcc/gimple-pretty-print.cc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,35 @@ dump_gimple_omp_scope (pretty_printer *pp, const gimple *gs,
17271727
}
17281728
}
17291729

1730+
/* Dump a GIMPLE_OMP_DISPATCH tuple on the pretty_printer BUFFER. */
1731+
1732+
static void
1733+
dump_gimple_omp_dispatch (pretty_printer *buffer, const gimple *gs, int spc,
1734+
dump_flags_t flags)
1735+
{
1736+
if (flags & TDF_RAW)
1737+
{
1738+
dump_gimple_fmt (buffer, spc, flags, "%G <%+BODY <%S>%nCLAUSES <", gs,
1739+
gimple_omp_body (gs));
1740+
dump_omp_clauses (buffer, gimple_omp_dispatch_clauses (gs), spc, flags);
1741+
dump_gimple_fmt (buffer, spc, flags, " >");
1742+
}
1743+
else
1744+
{
1745+
pp_string (buffer, "#pragma omp dispatch");
1746+
dump_omp_clauses (buffer, gimple_omp_dispatch_clauses (gs), spc, flags);
1747+
if (!gimple_seq_empty_p (gimple_omp_body (gs)))
1748+
{
1749+
newline_and_indent (buffer, spc + 2);
1750+
pp_left_brace (buffer);
1751+
pp_newline (buffer);
1752+
dump_gimple_seq (buffer, gimple_omp_body (gs), spc + 4, flags);
1753+
newline_and_indent (buffer, spc + 2);
1754+
pp_right_brace (buffer);
1755+
}
1756+
}
1757+
}
1758+
17301759
/* Dump a GIMPLE_OMP_TARGET tuple on the pretty_printer PP. */
17311760

17321761
static void
@@ -2806,6 +2835,10 @@ pp_gimple_stmt_1 (pretty_printer *pp, const gimple *gs, int spc,
28062835
dump_gimple_omp_scope (pp, gs, spc, flags);
28072836
break;
28082837

2838+
case GIMPLE_OMP_DISPATCH:
2839+
dump_gimple_omp_dispatch(pp, gs, spc, flags);
2840+
break;
2841+
28092842
case GIMPLE_OMP_MASTER:
28102843
case GIMPLE_OMP_SECTION:
28112844
case GIMPLE_OMP_STRUCTURED_BLOCK:

gcc/gimple-walk.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt,
707707
case GIMPLE_OMP_PARALLEL:
708708
case GIMPLE_OMP_TASK:
709709
case GIMPLE_OMP_SCOPE:
710+
case GIMPLE_OMP_DISPATCH:
710711
case GIMPLE_OMP_SECTIONS:
711712
case GIMPLE_OMP_SINGLE:
712713
case GIMPLE_OMP_TARGET:

gcc/gimple.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,21 @@ gimple_build_omp_scope (gimple_seq body, tree clauses)
12391239
return p;
12401240
}
12411241

1242+
/* Build a GIMPLE_OMP_DISPATCH statement.
1243+
1244+
BODY is the target function call to be dispatched.
1245+
CLAUSES are any of the OMP dispatch construct's clauses. */
1246+
1247+
gimple *
1248+
gimple_build_omp_dispatch (gimple_seq body, tree clauses)
1249+
{
1250+
gimple *p = gimple_alloc (GIMPLE_OMP_DISPATCH, 0);
1251+
gimple_omp_dispatch_set_clauses (p, clauses);
1252+
if (body)
1253+
gimple_omp_set_body (p, body);
1254+
1255+
return p;
1256+
}
12421257

12431258
/* Build a GIMPLE_OMP_TARGET statement.
12441259
@@ -2152,6 +2167,11 @@ gimple_copy (gimple *stmt)
21522167
gimple_omp_scope_set_clauses (copy, t);
21532168
goto copy_omp_body;
21542169

2170+
case GIMPLE_OMP_DISPATCH:
2171+
t = unshare_expr (gimple_omp_dispatch_clauses (stmt));
2172+
gimple_omp_dispatch_set_clauses (copy, t);
2173+
goto copy_omp_body;
2174+
21552175
case GIMPLE_OMP_TARGET:
21562176
{
21572177
gomp_target *omp_target_stmt = as_a <gomp_target *> (stmt);

gcc/gimple.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ DEFGSCODE(GIMPLE_OMP_SCAN, "gimple_omp_scan", GSS_OMP_SINGLE_LAYOUT)
350350
CLAUSES is an OMP_CLAUSE chain holding the associated clauses. */
351351
DEFGSCODE(GIMPLE_OMP_SCOPE, "gimple_omp_scope", GSS_OMP_SINGLE_LAYOUT)
352352

353+
/* GIMPLE_OMP_DISPATCH <BODY, CLAUSES> represents #pragma omp dispatch
354+
BODY is the target function call to be dispatched.
355+
CLAUSES is an OMP_CLAUSE chain holding the associated clauses. */
356+
DEFGSCODE(GIMPLE_OMP_DISPATCH, "gimple_omp_dispatch", GSS_OMP_SINGLE_LAYOUT)
357+
353358
/* OMP_SECTION <BODY> represents #pragma omp section.
354359
BODY is the sequence of statements in the section body. */
355360
DEFGSCODE(GIMPLE_OMP_SECTION, "gimple_omp_section", GSS_OMP)

gcc/gimple.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ struct GTY((tag("GSS_OMP_CONTINUE")))
742742
};
743743

744744
/* GIMPLE_OMP_SINGLE, GIMPLE_OMP_ORDERED, GIMPLE_OMP_TASKGROUP,
745-
GIMPLE_OMP_SCAN, GIMPLE_OMP_MASKED, GIMPLE_OMP_SCOPE. */
745+
GIMPLE_OMP_SCAN, GIMPLE_OMP_MASKED, GIMPLE_OMP_SCOPE, GIMPLE_OMP_DISPATCH. */
746746

747747
struct GTY((tag("GSS_OMP_SINGLE_LAYOUT")))
748748
gimple_statement_omp_single_layout : public gimple_statement_omp
@@ -1591,6 +1591,7 @@ gomp_task *gimple_build_omp_task (gimple_seq, tree, tree, tree, tree,
15911591
gimple *gimple_build_omp_section (gimple_seq);
15921592
gimple *gimple_build_omp_structured_block (gimple_seq);
15931593
gimple *gimple_build_omp_scope (gimple_seq, tree);
1594+
gimple *gimple_build_omp_dispatch (gimple_seq, tree);
15941595
gimple *gimple_build_omp_master (gimple_seq);
15951596
gimple *gimple_build_omp_masked (gimple_seq, tree);
15961597
gimple *gimple_build_omp_taskgroup (gimple_seq, tree);
@@ -1882,6 +1883,7 @@ gimple_has_substatements (gimple *g)
18821883
case GIMPLE_OMP_PARALLEL:
18831884
case GIMPLE_OMP_TASK:
18841885
case GIMPLE_OMP_SCOPE:
1886+
case GIMPLE_OMP_DISPATCH:
18851887
case GIMPLE_OMP_SECTIONS:
18861888
case GIMPLE_OMP_SINGLE:
18871889
case GIMPLE_OMP_TARGET:
@@ -5434,6 +5436,34 @@ gimple_omp_scope_set_clauses (gimple *gs, tree clauses)
54345436
= clauses;
54355437
}
54365438

5439+
/* Return the clauses associated with OMP_DISPATCH statement GS. */
5440+
5441+
inline tree
5442+
gimple_omp_dispatch_clauses (const gimple *gs)
5443+
{
5444+
GIMPLE_CHECK (gs, GIMPLE_OMP_DISPATCH);
5445+
return static_cast<const gimple_statement_omp_single_layout *> (gs)->clauses;
5446+
}
5447+
5448+
/* Return a pointer to the clauses associated with OMP dispatch statement
5449+
GS. */
5450+
5451+
inline tree *
5452+
gimple_omp_dispatch_clauses_ptr (gimple *gs)
5453+
{
5454+
GIMPLE_CHECK (gs, GIMPLE_OMP_DISPATCH);
5455+
return &static_cast<gimple_statement_omp_single_layout *> (gs)->clauses;
5456+
}
5457+
5458+
/* Set CLAUSES to be the clauses associated with OMP dispatch statement
5459+
GS. */
5460+
5461+
inline void
5462+
gimple_omp_dispatch_set_clauses (gimple *gs, tree clauses)
5463+
{
5464+
GIMPLE_CHECK (gs, GIMPLE_OMP_DISPATCH);
5465+
static_cast<gimple_statement_omp_single_layout *> (gs)->clauses = clauses;
5466+
}
54375467

54385468
/* Return the kind of the OMP_FOR statemement G. */
54395469

@@ -6768,6 +6798,7 @@ gimple_return_set_retval (greturn *gs, tree retval)
67686798
case GIMPLE_OMP_TARGET: \
67696799
case GIMPLE_OMP_TEAMS: \
67706800
case GIMPLE_OMP_SCOPE: \
6801+
case GIMPLE_OMP_DISPATCH: \
67716802
case GIMPLE_OMP_SECTION: \
67726803
case GIMPLE_OMP_STRUCTURED_BLOCK: \
67736804
case GIMPLE_OMP_MASTER: \

0 commit comments

Comments
 (0)