extern void c_finish_omp_taskyield (location_t);
extern tree c_finish_omp_for (location_t, enum tree_code, tree, tree, tree,
tree, tree, tree, tree, bool);
+extern int c_omp_find_generated_loop (tree &, int, walk_tree_lh);
extern bool c_omp_check_loop_iv (tree, tree, walk_tree_lh);
extern bool c_omp_check_loop_iv_exprs (location_t, enum tree_code, tree, int,
tree, tree, tree, walk_tree_lh);
case OMP_DISTRIBUTE:
case OMP_LOOP:
case OMP_TASKLOOP:
+ case OMP_TILE:
+ case OMP_UNROLL:
case OACC_LOOP:
genericize_omp_for_stmt (stmt_p, walk_subtrees, data, func, lh);
break;
tree cond = TREE_VEC_ELT (condv, i);
tree incr = TREE_VEC_ELT (incrv, i);
+ if (init == NULL_TREE)
+ {
+ gcc_assert (decl == NULL_TREE
+ && cond == NULL_TREE
+ && incr == NULL_TREE);
+ for (i++; i < TREE_VEC_LENGTH (declv); i++)
+ gcc_assert (TREE_VEC_ELT (declv, i) == NULL_TREE
+ && TREE_VEC_ELT (initv, i) == NULL_TREE
+ && TREE_VEC_ELT (condv, i) == NULL_TREE
+ && TREE_VEC_ELT (incrv, i) == NULL_TREE);
+ break;
+ }
+
elocus = locus;
if (EXPR_HAS_LOCATION (init))
elocus = EXPR_LOCATION (init);
c_omp_is_loop_iterator (tree decl, struct c_omp_check_loop_iv_data *d)
{
for (int i = 0; i < TREE_VEC_LENGTH (d->declv); i++)
- if (decl == TREE_VEC_ELT (d->declv, i)
- || (TREE_CODE (TREE_VEC_ELT (d->declv, i)) == TREE_LIST
- && decl == TREE_PURPOSE (TREE_VEC_ELT (d->declv, i))))
+ if (TREE_VEC_ELT (d->declv, i) == NULL_TREE)
+ continue;
+ else if (decl == TREE_VEC_ELT (d->declv, i)
+ || (TREE_CODE (TREE_VEC_ELT (d->declv, i)) == TREE_LIST
+ && decl == TREE_PURPOSE (TREE_VEC_ELT (d->declv, i))))
return i;
else if (TREE_CODE (TREE_VEC_ELT (d->declv, i)) == TREE_LIST
&& TREE_CHAIN (TREE_VEC_ELT (d->declv, i))
return ret;
}
+/* Callback for walk_tree to find nested loop transforming construct. */
+
+static tree
+c_find_nested_loop_xform_r (tree *tp, int *walk_subtrees, void *)
+{
+ *walk_subtrees = 0;
+ switch (TREE_CODE (*tp))
+ {
+ case OMP_TILE:
+ case OMP_UNROLL:
+ return *tp;
+ case BIND_EXPR:
+ *walk_subtrees = 1;
+ break;
+ case STATEMENT_LIST:
+ *walk_subtrees = 1;
+ break;
+ case TRY_FINALLY_EXPR:
+ *walk_subtrees = 1;
+ break;
+ default:
+ break;
+ }
+ return NULL;
+}
+
+/* Find Jth loop among generated loops of STMT. */
+
+int
+c_omp_find_generated_loop (tree &stmt, int j, walk_tree_lh lh)
+{
+ stmt = walk_tree_1 (&stmt, c_find_nested_loop_xform_r,
+ NULL, NULL, lh);
+ gcc_assert (stmt);
+ switch (TREE_CODE (stmt))
+ {
+ case OMP_UNROLL:
+ gcc_assert (omp_find_clause (OMP_FOR_CLAUSES (stmt),
+ OMP_CLAUSE_PARTIAL));
+ /* FALLTHRU */
+ case OMP_TILE:
+ int k;
+ k = 0;
+ for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (stmt)); ++i)
+ if (i == j)
+ {
+ if (TREE_VEC_ELT (OMP_FOR_INIT (stmt), i) == NULL_TREE)
+ {
+ stmt = OMP_FOR_BODY (stmt);
+ return c_omp_find_generated_loop (stmt, k, lh);
+ }
+ else
+ return i;
+ }
+ else if (TREE_VEC_ELT (OMP_FOR_INIT (stmt), i) == NULL_TREE)
+ ++k;
+ gcc_unreachable ();
+ default:
+ gcc_unreachable ();
+ }
+}
+
/* Diagnose invalid references to loop iterators in lb, b and incr
expressions. */
{
hash_set<tree> pset;
struct c_omp_check_loop_iv_data data;
- int i;
+ int i, k = 0;
data.declv = declv;
data.fail = false;
data.ppset = &pset;
for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (stmt)); i++)
{
+ tree this_stmt = stmt;
+ int j = i;
tree init = TREE_VEC_ELT (OMP_FOR_INIT (stmt), i);
+ if (init == NULL_TREE)
+ {
+ if (k == 0)
+ data.declv = copy_node (declv);
+ this_stmt = OMP_FOR_BODY (stmt);
+ j = c_omp_find_generated_loop (this_stmt, k++, lh);
+ init = TREE_VEC_ELT (OMP_FOR_INIT (this_stmt), j);
+ TREE_VEC_ELT (data.declv, i) = TREE_OPERAND (init, 0);
+ }
gcc_assert (TREE_CODE (init) == MODIFY_EXPR);
tree decl = TREE_OPERAND (init, 0);
- tree cond = TREE_VEC_ELT (OMP_FOR_COND (stmt), i);
+ tree cond = TREE_VEC_ELT (OMP_FOR_COND (this_stmt), j);
gcc_assert (COMPARISON_CLASS_P (cond));
gcc_assert (TREE_OPERAND (cond, 0) == decl);
- tree incr = TREE_VEC_ELT (OMP_FOR_INCR (stmt), i);
+ tree incr = TREE_VEC_ELT (OMP_FOR_INCR (this_stmt), j);
data.expr_loc = EXPR_LOCATION (TREE_OPERAND (init, 1));
tree vec_outer1 = NULL_TREE, vec_outer2 = NULL_TREE;
int kind = 0;
expression then involves the subtraction and always refers
to the original value. The C++ FE needs to warn on those
earlier. */
- if (decl == TREE_VEC_ELT (declv, i)
- || (TREE_CODE (TREE_VEC_ELT (declv, i)) == TREE_LIST
- && decl == TREE_PURPOSE (TREE_VEC_ELT (declv, i))))
+ if (decl == TREE_VEC_ELT (data.declv, i)
+ || (TREE_CODE (TREE_VEC_ELT (data.declv, i)) == TREE_LIST
+ && decl == TREE_PURPOSE (TREE_VEC_ELT (data.declv, i))))
{
data.expr_loc = EXPR_LOCATION (cond);
data.kind = kind | 1;
" used in a single loop", vec_outer1, vec_outer2);
data.fail = true;
}
+ else if ((vec_outer1 || vec_outer2) && this_stmt != stmt)
+ {
+ location_t loc = data.expr_loc;
+ if (loc == UNKNOWN_LOCATION)
+ loc = data.stmt_loc;
+ sorry_at (loc, "non-rectangular loops from generated loops "
+ "unsupported");
+ data.fail = true;
+ }
if (vec_outer1 || vec_outer2)
OMP_FOR_NON_RECTANGULAR (stmt) = 1;
if (TREE_CODE (incr) == MODIFY_EXPR)
for (int i = 1; i < TREE_VEC_LENGTH (OMP_FOR_INIT (stmt)); i++)
{
tree init = TREE_VEC_ELT (OMP_FOR_INIT (stmt), i);
+ if (init == NULL_TREE)
+ {
+ sorry_at (loc, "imperfectly nested loop using generated loops");
+ ok = false;
+ continue;
+ }
tree cond = TREE_VEC_ELT (OMP_FOR_COND (stmt), i);
tree incr = TREE_VEC_ELT (OMP_FOR_INCR (stmt), i);
gcc_assert (TREE_CODE (init) == MODIFY_EXPR);
C_OMP_DIR_STANDALONE, false },
{ "taskyield", nullptr, nullptr, PRAGMA_OMP_TASKYIELD,
C_OMP_DIR_STANDALONE, false },
- /* { "tile", nullptr, nullptr, PRAGMA_OMP_TILE,
- C_OMP_DIR_CONSTRUCT, false }, */
+ { "tile", nullptr, nullptr, PRAGMA_OMP_TILE,
+ C_OMP_DIR_CONSTRUCT, false },
{ "teams", nullptr, nullptr, PRAGMA_OMP_TEAMS,
C_OMP_DIR_CONSTRUCT, true },
{ "threadprivate", nullptr, nullptr, PRAGMA_OMP_THREADPRIVATE,
- C_OMP_DIR_DECLARATIVE, false }
- /* { "unroll", nullptr, nullptr, PRAGMA_OMP_UNROLL,
- C_OMP_DIR_CONSTRUCT, false }, */
+ C_OMP_DIR_DECLARATIVE, false },
+ { "unroll", nullptr, nullptr, PRAGMA_OMP_UNROLL,
+ C_OMP_DIR_CONSTRUCT, false },
};
/* Find (non-combined/composite) OpenMP directive (if any) which starts
{ "target", PRAGMA_OMP_TARGET },
{ "taskloop", PRAGMA_OMP_TASKLOOP },
{ "teams", PRAGMA_OMP_TEAMS },
+ { "tile", PRAGMA_OMP_TILE },
+ { "unroll", PRAGMA_OMP_UNROLL },
};
void
PRAGMA_OMP_TASKYIELD,
PRAGMA_OMP_THREADPRIVATE,
PRAGMA_OMP_TEAMS,
+ PRAGMA_OMP_TILE,
+ PRAGMA_OMP_UNROLL,
/* PRAGMA_OMP__LAST_ should be equal to the last PRAGMA_OMP_* code. */
- PRAGMA_OMP__LAST_ = PRAGMA_OMP_TEAMS,
+ PRAGMA_OMP__LAST_ = PRAGMA_OMP_UNROLL,
PRAGMA_GCC_PCH_PREPROCESS,
PRAGMA_IVDEP,
PRAGMA_OMP_CLAUSE_FIRSTPRIVATE,
PRAGMA_OMP_CLAUSE_FOR,
PRAGMA_OMP_CLAUSE_FROM,
+ PRAGMA_OMP_CLAUSE_FULL,
PRAGMA_OMP_CLAUSE_GRAINSIZE,
PRAGMA_OMP_CLAUSE_HAS_DEVICE_ADDR,
PRAGMA_OMP_CLAUSE_HINT,
PRAGMA_OMP_CLAUSE_ORDER,
PRAGMA_OMP_CLAUSE_ORDERED,
PRAGMA_OMP_CLAUSE_PARALLEL,
+ PRAGMA_OMP_CLAUSE_PARTIAL,
PRAGMA_OMP_CLAUSE_PRIORITY,
PRAGMA_OMP_CLAUSE_PRIVATE,
PRAGMA_OMP_CLAUSE_PROC_BIND,
static void c_parser_omp_barrier (c_parser *);
static void c_parser_omp_depobj (c_parser *);
static void c_parser_omp_flush (c_parser *);
+static bool c_parser_omp_next_tokens_can_be_canon_loop (c_parser *,
+ enum tree_code, bool);
static tree c_parser_omp_loop_nest (c_parser *, bool *);
static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code,
tree, tree *, bool *);
return token->type == CPP_CLOSE_SQUARE;
}
+/* Skip standard attribute tokens starting at Nth token (with 1 as the
+ next token), return index of the first token after the standard
+ attribute tokens, or N on failure. */
+
+static size_t
+c_parser_skip_std_attribute_spec_seq (c_parser *parser, size_t n)
+{
+ size_t orig_n = n;
+ while (true)
+ {
+ if (c_parser_peek_nth_token_raw (parser, n)->type == CPP_OPEN_SQUARE
+ && (c_parser_peek_nth_token_raw (parser, n + 1)->type
+ == CPP_OPEN_SQUARE))
+ {
+ unsigned int m = n + 2;
+ if (!c_parser_check_balanced_raw_token_sequence (parser, &m))
+ return orig_n;
+ c_token *token = c_parser_peek_nth_token_raw (parser, m);
+ if (token->type != CPP_CLOSE_SQUARE)
+ return orig_n;
+ token = c_parser_peek_nth_token_raw (parser, m + 1);
+ if (token->type != CPP_CLOSE_SQUARE)
+ return orig_n;
+ n = m + 2;
+ }
+ else
+ break;
+ }
+ return n;
+}
+
static tree
c_parser_std_attribute_specifier_sequence (c_parser *parser)
{
"%<reduction%> %<inscan%> clause");
omp_for_parse_state->perfect_nesting_fail = true;
}
- /* TODO: Also reject loops with TILE directive. */
+ else if (omp_for_parse_state->code == OMP_TILE)
+ {
+ error_at (omp_for_parse_state->for_loc,
+ "inner loops must be perfectly nested in "
+ "%<pragma omp tile%>");
+ omp_for_parse_state->perfect_nesting_fail = true;
+ }
if (omp_for_parse_state->perfect_nesting_fail)
omp_for_parse_state->fail = true;
}
__extension__ before the nested statement. */
if (in_omp_loop_block && !last_label)
{
+ tree_code code = omp_for_parse_state->code;
if (want_nested_loop
- && c_parser_next_token_is_keyword (parser, RID_FOR))
+ && c_parser_omp_next_tokens_can_be_canon_loop (parser, code,
+ false))
{
/* Found the next nested loop. If there were intervening
code statements collected before now, wrap them in an
result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
else if (!strcmp ("from", p))
result = PRAGMA_OMP_CLAUSE_FROM;
+ else if (!strcmp ("full", p))
+ result = PRAGMA_OMP_CLAUSE_FULL;
break;
case 'g':
if (!strcmp ("gang", p))
case 'p':
if (!strcmp ("parallel", p))
result = PRAGMA_OMP_CLAUSE_PARALLEL;
+ else if (!strcmp ("partial", p))
+ result = PRAGMA_OMP_CLAUSE_PARTIAL;
else if (!strcmp ("present", p))
result = PRAGMA_OACC_CLAUSE_PRESENT;
/* As of OpenACC 2.5, these are now aliases of the non-present_or
if (has_modifiers)
{
c_parser_consume_token (parser);
- matching_parens parens2;;
+ matching_parens parens2;
parens2.require_open (parser);
location_t expr_loc = c_parser_peek_token (parser)->location;
c_expr expr = c_parser_expr_no_commas (parser, NULL);
return list;
}
+/* OpenMP 5.1
+ full */
+
+static tree
+c_parser_omp_clause_full (c_parser *parser, tree list)
+{
+ check_no_duplicate_clause (list, OMP_CLAUSE_FULL, "full");
+
+ location_t loc = c_parser_peek_token (parser)->location;
+ tree c = build_omp_clause (loc, OMP_CLAUSE_FULL);
+ OMP_CLAUSE_CHAIN (c) = list;
+ return c;
+}
+
+/* OpenMP 5.1
+ partial ( constant-expression ) */
+
+static tree
+c_parser_omp_clause_partial (c_parser *parser, tree list)
+{
+ tree num = NULL_TREE;
+ location_t loc = c_parser_peek_token (parser)->location;
+
+ check_no_duplicate_clause (list, OMP_CLAUSE_PARTIAL, "partial");
+
+ if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
+ {
+ matching_parens parens;
+ parens.consume_open (parser);
+ num = c_parser_expr_no_commas (parser, NULL).value;
+ parens.skip_until_found_close (parser);
+
+ if (num == error_mark_node)
+ return list;
+
+ mark_exp_read (num);
+ num = c_fully_fold (num, false, NULL);
+ HOST_WIDE_INT n;
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
+ || !tree_fits_shwi_p (num)
+ || (n = tree_to_shwi (num)) <= 0
+ || (int) n != n)
+ {
+ error_at (loc, "%<partial%> argument needs positive constant "
+ "integer expression");
+ return list;
+ }
+ }
+
+ tree c = build_omp_clause (loc, OMP_CLAUSE_PARTIAL);
+ OMP_CLAUSE_PARTIAL_EXPR (c) = num;
+ OMP_CLAUSE_CHAIN (c) = list;
+ return c;
+}
+
/* OpenMP 5.0:
detach ( event-handle ) */
clauses);
c_name = "enter";
break;
+ case PRAGMA_OMP_CLAUSE_FULL:
+ c_name = "full";
+ clauses = c_parser_omp_clause_full (parser, clauses);
+ break;
+ case PRAGMA_OMP_CLAUSE_PARTIAL:
+ c_name = "partial";
+ clauses = c_parser_omp_clause_partial (parser, clauses);
+ break;
default:
c_parser_error (parser, "expected an OpenMP clause");
goto saw_error;
}
+/* Check if the next tokens can start a canonical loop. Return true if yes,
+ otherwise diagnose an error if ERROR_P is true, and return false. */
+static bool
+c_parser_omp_next_tokens_can_be_canon_loop (c_parser *parser,
+ enum tree_code code,
+ bool error_p)
+{
+ if (code == OACC_LOOP)
+ {
+ if (c_parser_next_token_is_keyword (parser, RID_FOR))
+ return true;
+ if (error_p)
+ c_parser_error (parser, "for statement expected");
+ }
+ else
+ {
+ if (c_parser_next_token_is_keyword (parser, RID_FOR))
+ return true;
+
+ if (c_parser_next_token_is (parser, CPP_PRAGMA))
+ switch (c_parser_peek_token (parser)->pragma_kind)
+ {
+ case PRAGMA_OMP_UNROLL:
+ case PRAGMA_OMP_TILE:
+ return true;
+ default:
+ break;
+ }
+
+ /* Skip standard attributes on next for in case they are
+ [[omp::directive (unroll partial (4))]] or
+ [[omp::directive (tile sizes (1, 2, 3))]] etc. */
+ size_t n = c_parser_skip_std_attribute_spec_seq (parser, 1);
+ c_token *token = c_parser_peek_nth_token_raw (parser, n);
+ /* TOKEN is a raw token that hasn't been converted to a keyword yet,
+ we have to do the lookup explicitly. */
+ if (token->type == CPP_NAME
+ && C_IS_RESERVED_WORD (token->value)
+ && C_RID_CODE (token->value) == RID_FOR)
+ return true;
+ if (error_p)
+ c_parser_error (parser, "loop nest expected");
+ }
+
+ return false;
+}
+
+static tree c_parser_omp_tile (location_t, c_parser *, bool *);
+static tree c_parser_omp_unroll (location_t, c_parser *, bool *);
+
/* This function parses a single level of a loop nest, invoking itself
recursively if necessary.
gcc_assert (omp_for_parse_state);
int depth = omp_for_parse_state->depth;
- /* We have already matched the FOR token but not consumed it yet. */
+ /* Arrange for C23 standard attribute syntax to be parsed as regular
+ pragmas. */
+ if (c_parser_nth_token_starts_std_attributes (parser, 1))
+ {
+ tree std_attrs = c_parser_std_attribute_specifier_sequence (parser);
+ c_parser_handle_statement_omp_attributes (parser, std_attrs, NULL);
+ if (std_attrs)
+ error_at (c_parser_peek_token (parser)->location,
+ "attributes other than OpenMP directives "
+ "are not allowed on %<for%> in loop nest");
+ }
+
loc = c_parser_peek_token (parser)->location;
+
+ /* Handle loop transformations first. */
+ if (c_parser_next_token_is (parser, CPP_PRAGMA))
+ {
+ tree transform = NULL_TREE, sizes, body = NULL_TREE;
+ int count = 0;
+ switch (c_parser_peek_token (parser)->pragma_kind)
+ {
+ case PRAGMA_OMP_UNROLL:
+ c_parser_consume_pragma (parser);
+ body = push_stmt_list ();
+ transform = c_parser_omp_unroll (loc, parser, if_p);
+ body = pop_stmt_list (body);
+ if (transform == NULL_TREE || transform == error_mark_node)
+ {
+ transform = error_mark_node;
+ break;
+ }
+ gcc_assert (TREE_CODE (transform) == OMP_UNROLL);
+ if (omp_find_clause (OMP_FOR_CLAUSES (transform),
+ OMP_CLAUSE_PARTIAL))
+ {
+ if (omp_for_parse_state->count - depth > 1)
+ {
+ error_at (loc, "%<unroll%> construct with %<partial%> "
+ "clause generates just one loop with "
+ "canonical form but %d loops are needed",
+ omp_for_parse_state->count - depth);
+ transform = error_mark_node;
+ }
+ else
+ count = 1;
+ }
+ else
+ {
+ error_at (loc, "generated loop of %<unroll%> construct "
+ "without %<partial%> clause does not have "
+ "canonical form");
+ transform = error_mark_node;
+ }
+ break;
+ case PRAGMA_OMP_TILE:
+ c_parser_consume_pragma (parser);
+ body = push_stmt_list ();
+ transform = c_parser_omp_tile (loc, parser, if_p);
+ body = pop_stmt_list (body);
+ if (transform == NULL_TREE || transform == error_mark_node)
+ {
+ transform = error_mark_node;
+ break;
+ }
+ gcc_assert (TREE_CODE (transform) == OMP_TILE);
+ sizes = omp_find_clause (OMP_FOR_CLAUSES (transform),
+ OMP_CLAUSE_SIZES);
+ gcc_assert (sizes);
+ count = list_length (OMP_CLAUSE_SIZES_LIST (sizes));
+ if (depth + count < omp_for_parse_state->count)
+ {
+ error_at (loc, "%<tile%> construct generates %d loops "
+ "with canonical form but %d loops are needed",
+ count, omp_for_parse_state->count - depth);
+ transform = error_mark_node;
+ }
+ break;
+ default:
+ c_parser_pragma (parser, pragma_stmt, NULL);
+ break;
+ }
+ if (transform == NULL_TREE)
+ error_at (loc, "expected %<for%> loop or OpenMP loop "
+ "transformation construct");
+ if (transform == NULL_TREE || transform == error_mark_node)
+ {
+ omp_for_parse_state->fail = true;
+ return NULL_TREE;
+ }
+ for (count = omp_for_parse_state->count; depth < count; ++depth)
+ {
+ TREE_VEC_ELT (omp_for_parse_state->declv, depth) = NULL_TREE;
+ TREE_VEC_ELT (omp_for_parse_state->initv, depth) = NULL_TREE;
+ TREE_VEC_ELT (omp_for_parse_state->condv, depth) = NULL_TREE;
+ TREE_VEC_ELT (omp_for_parse_state->incrv, depth) = NULL_TREE;
+ }
+ omp_for_parse_state->want_nested_loop = false;
+ return body;
+ }
+
+ /* We have already matched the FOR token but not consumed it yet. */
gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR));
c_parser_consume_token (parser);
parse_next:
moreloops = depth < omp_for_parse_state->count - 1;
omp_for_parse_state->want_nested_loop = moreloops;
- if (moreloops && c_parser_next_token_is_keyword (parser, RID_FOR))
+ if (moreloops
+ && c_parser_omp_next_tokens_can_be_canon_loop (parser,
+ omp_for_parse_state->code,
+ false))
{
omp_for_parse_state->depth++;
body = c_parser_omp_loop_nest (parser, if_p);
OMP_FOR. That keeps the gimplifier happy later on, and meanwhile
we have already resolved all references to the iteration variable
in its true scope. */
- add_stmt (body);
+ if (body)
+ add_stmt (body);
body = c_end_compound_stmt (loc, loop_scope, true);
if (decl && TREE_CODE (body) == BIND_EXPR)
{
tree ret = NULL_TREE;
tree ordered_cl = NULL_TREE;
int i, collapse = 1, ordered = 0, count;
- bool tiling = false;
+ bool oacc_tiling = false;
bool inscan = false;
struct omp_for_parse_data data;
struct omp_for_parse_data *save_data = parser->omp_for_parse_state;
collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_TILE)
{
- tiling = true;
+ oacc_tiling = true;
collapse = list_length (OMP_CLAUSE_TILE_LIST (cl));
}
+ else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_SIZES)
+ collapse = list_length (OMP_CLAUSE_SIZES_LIST (cl));
else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED
&& OMP_CLAUSE_ORDERED_EXPR (cl))
{
ordered = collapse;
}
- gcc_assert (tiling || (collapse >= 1 && ordered >= 0));
+ gcc_assert (oacc_tiling || (collapse >= 1 && ordered >= 0));
count = ordered ? ordered : collapse;
- if (!c_parser_next_token_is_keyword (parser, RID_FOR))
- {
- c_parser_error (parser, "for statement expected");
- return NULL;
- }
+ if (!c_parser_omp_next_tokens_can_be_canon_loop (parser, code, true))
+ return NULL;
/* Initialize parse state for recursive descent. */
data.declv = make_tree_vec (count);
data.initv = make_tree_vec (count);
data.condv = make_tree_vec (count);
data.incrv = make_tree_vec (count);
- data.pre_body = NULL_TREE;;
+ data.pre_body = NULL_TREE;
data.bindings = NULL_TREE;
data.for_loc = c_parser_peek_token (parser)->location;
data.count = count;
/* Check for errors involving lb/ub/incr expressions referencing
variables declared in intervening code. */
if (data.saw_intervening_code
+ && stmt
&& !c_omp_check_loop_binding_exprs (stmt, NULL))
stmt = NULL_TREE;
for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (stmt)); i++)
{
tree init = TREE_VEC_ELT (OMP_FOR_INIT (stmt), i);
+ if (init == NULL_TREE)
+ break;
gcc_assert (TREE_CODE (init) == MODIFY_EXPR);
tree decl = TREE_OPERAND (init, 0);
tree cond = TREE_VEC_ELT (OMP_FOR_COND (stmt), i);
return ret;
}
+/* OpenMP 5.1: Parse sizes list for "omp tile sizes"
+ sizes ( size-expr-list ) */
+static tree
+c_parser_omp_tile_sizes (c_parser *parser, location_t loc)
+{
+ tree sizes = NULL_TREE;
+
+ if (c_parser_next_token_is (parser, CPP_COMMA))
+ c_parser_consume_token (parser);
+
+ c_token *tok = c_parser_peek_token (parser);
+ if (tok->type != CPP_NAME
+ || strcmp ("sizes", IDENTIFIER_POINTER (tok->value)))
+ {
+ c_parser_error (parser, "expected %<sizes%>");
+ return error_mark_node;
+ }
+ c_parser_consume_token (parser);
+
+ matching_parens parens;
+ if (!parens.require_open (parser))
+ return error_mark_node;
+
+ do
+ {
+ if (sizes && !c_parser_require (parser, CPP_COMMA, "expected %<,%>"))
+ return error_mark_node;
+
+ location_t expr_loc = c_parser_peek_token (parser)->location;
+ c_expr cexpr = c_parser_expr_no_commas (parser, NULL);
+ cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true);
+ tree expr = cexpr.value;
+
+ if (expr == error_mark_node)
+ {
+ parens.skip_until_found_close (parser);
+ return error_mark_node;
+ }
+
+ expr = c_fully_fold (expr, false, NULL);
+
+ HOST_WIDE_INT n;
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
+ || !tree_fits_shwi_p (expr)
+ || (n = tree_to_shwi (expr)) <= 0
+ || (int) n != n)
+ {
+ c_parser_error (parser, "%<sizes%> argument needs positive"
+ " integral constant");
+ expr = integer_one_node;
+ }
+
+ sizes = tree_cons (NULL_TREE, expr, sizes);
+ }
+ while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN));
+ parens.require_close (parser);
+
+ gcc_assert (sizes);
+ tree c = build_omp_clause (loc, OMP_CLAUSE_SIZES);
+ OMP_CLAUSE_SIZES_LIST (c) = nreverse (sizes);
+
+ return c;
+}
+
+/* OpenMP 5.1:
+ #pragma omp tile sizes ( size-expr-list ) new-line
+ for-loop
+
+ LOC is the location of the #pragma token. */
+
+static tree
+c_parser_omp_tile (location_t loc, c_parser *parser, bool *if_p)
+{
+ tree clauses = c_parser_omp_tile_sizes (parser, loc);
+ c_parser_skip_to_pragma_eol (parser);
+
+ if (!clauses || clauses == error_mark_node)
+ return error_mark_node;
+
+ tree block = c_begin_compound_stmt (true);
+ tree ret = c_parser_omp_for_loop (loc, parser, OMP_TILE, clauses,
+ NULL, if_p);
+ block = c_end_compound_stmt (loc, block, true);
+ add_stmt (block);
+
+ return ret;
+}
+
+#define OMP_UNROLL_CLAUSE_MASK \
+ ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARTIAL) \
+ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FULL))
+
+/* OpenMP 5.1
+ #pragma omp unroll unroll-clause[optseq] new-line
+ for-loop
+
+ LOC is the location of the #pragma token. */
+
+static tree
+c_parser_omp_unroll (location_t loc, c_parser *parser, bool *if_p)
+{
+ tree clauses = c_parser_omp_all_clauses (parser, OMP_UNROLL_CLAUSE_MASK,
+ "#pragma omp unroll", true);
+
+ tree block = c_begin_compound_stmt (true);
+ tree ret = c_parser_omp_for_loop (loc, parser, OMP_UNROLL, clauses,
+ NULL, if_p);
+ block = c_end_compound_stmt (loc, block, true);
+ add_stmt (block);
+
+ return ret;
+}
+
/* OpenMP 5.1
#pragma omp nothing new-line */
case PRAGMA_OMP_ASSUME:
c_parser_omp_assume (parser, if_p);
return;
+ case PRAGMA_OMP_TILE:
+ stmt = c_parser_omp_tile (loc, parser, if_p);
+ break;
+ case PRAGMA_OMP_UNROLL:
+ stmt = c_parser_omp_unroll (loc, parser, if_p);
+ break;
default:
gcc_unreachable ();
}
bool allocate_seen = false;
bool implicit_moved = false;
bool target_in_reduction_seen = false;
+ tree *full_seen = NULL;
+ bool partial_seen = false;
bool openacc = (ort & C_ORT_ACC) != 0;
bitmap_obstack_initialize (NULL);
{
error_at (OMP_CLAUSE_LOCATION (*nowait_clause),
"%<nowait%> clause must not be used together "
- "with %<copyprivate%>");
+ "with %<copyprivate%> clause");
*nowait_clause = OMP_CLAUSE_CHAIN (*nowait_clause);
nowait_clause = NULL;
}
{
error_at (OMP_CLAUSE_LOCATION (c),
"%<nowait%> clause must not be used together "
- "with %<copyprivate%>");
+ "with %<copyprivate%> clause");
remove = true;
break;
}
{
error_at (OMP_CLAUSE_LOCATION (c),
"%<order%> clause must not be used together "
- "with %<ordered%>");
+ "with %<ordered%> clause");
remove = true;
break;
}
{
error_at (OMP_CLAUSE_LOCATION (*order_clause),
"%<order%> clause must not be used together "
- "with %<ordered%>");
+ "with %<ordered%> clause");
*order_clause = OMP_CLAUSE_CHAIN (*order_clause);
order_clause = NULL;
}
pc = &OMP_CLAUSE_CHAIN (c);
continue;
+ case OMP_CLAUSE_FULL:
+ full_seen = pc;
+ pc = &OMP_CLAUSE_CHAIN (c);
+ continue;
+
+ case OMP_CLAUSE_PARTIAL:
+ partial_seen = true;
+ pc = &OMP_CLAUSE_CHAIN (c);
+ continue;
+
+ case OMP_CLAUSE_SIZES:
+ pc = &OMP_CLAUSE_CHAIN (c);
+ continue;
+
case OMP_CLAUSE_INBRANCH:
case OMP_CLAUSE_NOTINBRANCH:
if (branch_seen)
*grainsize_seen = OMP_CLAUSE_CHAIN (*grainsize_seen);
}
+ if (full_seen && partial_seen)
+ {
+ error_at (OMP_CLAUSE_LOCATION (*full_seen),
+ "%<full%> clause must not be used together with "
+ "%<partial%> clause");
+ *full_seen = OMP_CLAUSE_CHAIN (*full_seen);
+ }
+
if (detach_seen)
{
if (mergeable_seen)
case OMP_DISTRIBUTE:
case OMP_LOOP:
case OMP_TASKLOOP:
+ case OMP_TILE:
+ case OMP_UNROLL:
ret = cp_gimplify_omp_for (expr_p, pre_p);
break;
case OMP_DISTRIBUTE:
case OMP_LOOP:
case OMP_TASKLOOP:
+ case OMP_TILE:
+ case OMP_UNROLL:
case OACC_LOOP:
cp_walk_tree (&OMP_FOR_BODY (stmt), cp_fold_r, data, NULL);
cp_walk_tree (&OMP_FOR_CLAUSES (stmt), cp_fold_r, data, NULL);
&& TREE_CODE (inner) == OMP_FOR)
{
for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (inner)); i++)
- if (OMP_FOR_ORIG_DECLS (inner)
+ if (TREE_VEC_ELT (OMP_FOR_INIT (inner), i)
+ && OMP_FOR_ORIG_DECLS (inner)
&& TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner),
i)) == TREE_LIST
&& TREE_PURPOSE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner),
case OMP_FOR:
case OMP_SIMD:
case OMP_LOOP:
+ case OMP_TILE:
+ case OMP_UNROLL:
case OACC_LOOP:
case STATEMENT_LIST:
/* These cases are handled by shared code. */
extern bool value_dependent_expression_p (tree);
extern bool instantiation_dependent_uneval_expression_p (tree);
extern bool any_value_dependent_elements_p (const_tree);
-extern bool dependent_omp_for_p (tree, tree, tree, tree);
+extern bool dependent_omp_for_p (tree, tree, tree, tree, tree);
extern tree resolve_typename_type (tree, bool);
extern tree template_for_substitution (tree);
extern bool reregister_specialization (tree, tree, tree);
static bool cp_parser_skip_to_closing_square_bracket
(cp_parser *);
static size_t cp_parser_skip_balanced_tokens (cp_parser *, size_t);
+static bool cp_parser_next_tokens_can_be_canon_loop (cp_parser *,
+ enum tree_code, bool);
static tree cp_parser_omp_loop_nest (cp_parser *, bool *);
// -------------------------------------------------------------------------- //
"%<reduction%> %<inscan%> clause");
omp_for_parse_state->perfect_nesting_fail = true;
}
- /* TODO: Also reject loops with TILE directive. */
+ else if (omp_for_parse_state->code == OMP_TILE)
+ {
+ error_at (omp_for_parse_state->for_loc,
+ "inner loops must be perfectly nested "
+ "with %<tile%> directive");
+ omp_for_parse_state->perfect_nesting_fail = true;
+ }
if (omp_for_parse_state->perfect_nesting_fail)
omp_for_parse_state->fail = true;
}
else if (in_omp_loop_block)
{
bool want_nested_loop = omp_for_parse_state->want_nested_loop;
+ tree_code code = omp_for_parse_state->code;
if (want_nested_loop
- && token->type == CPP_KEYWORD && token->keyword == RID_FOR)
+ && cp_parser_next_tokens_can_be_canon_loop (parser, code, false))
{
/* Found the nested loop. */
omp_for_parse_state->depth++;
result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE;
else if (!strcmp ("from", p))
result = PRAGMA_OMP_CLAUSE_FROM;
+ else if (!strcmp ("full", p))
+ result = PRAGMA_OMP_CLAUSE_FULL;
break;
case 'g':
if (!strcmp ("gang", p))
case 'p':
if (!strcmp ("parallel", p))
result = PRAGMA_OMP_CLAUSE_PARALLEL;
+ if (!strcmp ("partial", p))
+ result = PRAGMA_OMP_CLAUSE_PARTIAL;
else if (!strcmp ("present", p))
result = PRAGMA_OACC_CLAUSE_PRESENT;
else if (!strcmp ("present_or_copy", p)
return c;
}
+/* OpenMP 5.1
+ full */
+
+static tree
+cp_parser_omp_clause_full (tree list, location_t loc)
+{
+ check_no_duplicate_clause (list, OMP_CLAUSE_FULL, "full", loc);
+
+ tree c = build_omp_clause (loc, OMP_CLAUSE_FULL);
+ OMP_CLAUSE_CHAIN (c) = list;
+ return c;
+}
+
+/* OpenMP 5.1
+ partial ( constant-expression ) */
+
+static tree
+cp_parser_omp_clause_partial (cp_parser *parser, tree list, location_t loc)
+{
+ tree num = NULL_TREE;
+ check_no_duplicate_clause (list, OMP_CLAUSE_PARTIAL, "partial", loc);
+
+ if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
+ {
+ matching_parens parens;
+ parens.consume_open (parser);
+ num = cp_parser_constant_expression (parser);
+ if (num == error_mark_node
+ || !parens.require_close (parser))
+ cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true,
+ /*or_comma=*/false,
+ /*consume_paren=*/true);
+ if (num == error_mark_node)
+ return list;
+ }
+
+ tree c = build_omp_clause (loc, OMP_CLAUSE_PARTIAL);
+ OMP_CLAUSE_PARTIAL_EXPR (c) = num;
+ OMP_CLAUSE_CHAIN (c) = list;
+ return c;
+}
+
/* OpenMP 4.0:
aligned ( variable-list )
aligned ( variable-list : constant-expression ) */
else if (nested == 2)
error_at (cp_lexer_peek_token (parser->lexer)->location,
"clauses in %<simd%> trait should be separated "
- "by %<,%>");
+ "by %<,%>");
}
token = cp_lexer_peek_token (parser->lexer);
clauses);
c_name = "enter";
break;
+ case PRAGMA_OMP_CLAUSE_PARTIAL:
+ clauses = cp_parser_omp_clause_partial (parser, clauses,
+ token->location);
+ c_name = "partial";
+ break;
+ case PRAGMA_OMP_CLAUSE_FULL:
+ clauses = cp_parser_omp_clause_full (clauses, token->location);
+ c_name = "full";
+ break;
default:
cp_parser_error (parser, "expected an OpenMP clause");
goto saw_error;
}
+/* Check that the next token starts a loop nest. Return true if yes,
+ otherwise diagnose an error if ERROR_P is true and return false. */
+static bool
+cp_parser_next_tokens_can_be_canon_loop (cp_parser *parser, enum tree_code code,
+ bool error_p)
+{
+ if (code == OACC_LOOP)
+ {
+ if (cp_lexer_next_token_is_keyword (parser->lexer, RID_FOR))
+ return true;
+ if (error_p)
+ cp_parser_error (parser, "for statement expected");
+ }
+ else
+ {
+ if (cp_lexer_next_token_is_keyword (parser->lexer, RID_FOR))
+ return true;
+ if (cp_lexer_next_token_is (parser->lexer, CPP_PRAGMA)
+ && ((cp_parser_pragma_kind (cp_lexer_peek_token (parser->lexer))
+ == PRAGMA_OMP_UNROLL)
+ || (cp_parser_pragma_kind (cp_lexer_peek_token (parser->lexer))
+ == PRAGMA_OMP_TILE)))
+ return true;
+ /* Skip standard attributes on next for in case they are
+ [[omp::directive (unroll partial (4))]] or
+ [[omp::directive (tile sizes (1, 2, 3))]] etc. */
+ size_t n = cp_parser_skip_std_attribute_spec_seq (parser, 1);
+ if (cp_lexer_nth_token_is_keyword (parser->lexer, n, RID_FOR))
+ return true;
+ if (error_p)
+ {
+ if (cp_lexer_next_token_is (parser->lexer, CPP_PRAGMA))
+ error_at (cp_lexer_peek_token (parser->lexer)->location,
+ "loop nest expected");
+ else
+ cp_parser_error (parser, "loop nest expected");
+ }
+ }
+ return false;
+}
+
+static tree cp_parser_omp_unroll (cp_parser *, cp_token *, bool *);
+static tree cp_parser_omp_tile (cp_parser *, cp_token *, bool *);
+
/* This function parses a single level of a loop nest, invoking itself
recursively if necessary.
gcc_assert (omp_for_parse_state);
int depth = omp_for_parse_state->depth;
- /* We have already matched the FOR token but not consumed it yet. */
- gcc_assert (cp_lexer_next_token_is_keyword (parser->lexer, RID_FOR));
+ /* Handle loop transformations first. Note that when we get here
+ omp_for_parse_state->depth has already been incremented to indicate
+ the depth of the *next* loop, not the level of the loop body the
+ transformation directive appears in. */
+
+ /* Arrange for C++ standard attribute syntax to be parsed as regular
+ pragmas. Give an error if there are other random attributes present. */
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
+ tree std_attrs = cp_parser_std_attribute_spec_seq (parser);
+ std_attrs = cp_parser_handle_statement_omp_attributes (parser, std_attrs);
+ if (std_attrs)
+ error_at (token->location,
+ "attributes other than OpenMP directives "
+ "are not allowed on %<for%> in loop nest");
+
+ if (cp_lexer_next_token_is (parser->lexer, CPP_PRAGMA))
+ {
+ tree transform = NULL_TREE, sizes, body = NULL_TREE;
+ int count = 0;
+ cp_token *pragma_tok;
+ tree stmt;
+ loc = cp_lexer_peek_token (parser->lexer)->location;
+ switch (cp_parser_pragma_kind (cp_lexer_peek_token (parser->lexer)))
+ {
+ case PRAGMA_OMP_UNROLL:
+ pragma_tok = cp_lexer_consume_token (parser->lexer);
+ parser->lexer->in_pragma = true;
+ body = push_stmt_list ();
+ stmt = push_omp_privatization_clauses (false);
+ transform = cp_parser_omp_unroll (parser, pragma_tok, if_p);
+ pop_omp_privatization_clauses (stmt);
+ body = pop_stmt_list (body);
+ if (transform == NULL_TREE || transform == error_mark_node)
+ {
+ transform = error_mark_node;
+ break;
+ }
+ gcc_assert (TREE_CODE (transform) == OMP_UNROLL);
+ if (omp_find_clause (OMP_FOR_CLAUSES (transform),
+ OMP_CLAUSE_PARTIAL))
+ {
+ if (omp_for_parse_state->count - depth > 1)
+ {
+ error_at (loc, "%<unroll%> construct with %<partial%> "
+ "clause generates just one loop with "
+ "canonical form but %d loops are needed",
+ omp_for_parse_state->count - depth);
+ transform = error_mark_node;
+ }
+ else
+ count = 1;
+ }
+ else
+ {
+ error_at (loc, "generated loop of %<unroll%> construct "
+ "without %<partial%> clause does not have "
+ "canonical form");
+ transform = error_mark_node;
+ }
+ break;
+ case PRAGMA_OMP_TILE:
+ pragma_tok = cp_lexer_consume_token (parser->lexer);
+ parser->lexer->in_pragma = true;
+ body = push_stmt_list ();
+ stmt = push_omp_privatization_clauses (false);
+ transform = cp_parser_omp_tile (parser, pragma_tok, if_p);
+ pop_omp_privatization_clauses (stmt);
+ body = pop_stmt_list (body);
+ if (transform == NULL_TREE || transform == error_mark_node)
+ {
+ transform = error_mark_node;
+ break;
+ }
+ gcc_assert (TREE_CODE (transform) == OMP_TILE);
+ sizes = omp_find_clause (OMP_FOR_CLAUSES (transform),
+ OMP_CLAUSE_SIZES);
+ gcc_assert (sizes);
+ count = list_length (OMP_CLAUSE_SIZES_LIST (sizes));
+ if (depth + count < omp_for_parse_state->count)
+ {
+ error_at (loc, "%<tile%> construct generates %d loops "
+ "with canonical form but %d loops are needed",
+ count, omp_for_parse_state->count - depth);
+ transform = error_mark_node;
+ }
+ break;
+ default:
+ cp_parser_pragma (parser, pragma_stmt, NULL);
+ break;
+ }
+ if (transform == NULL_TREE)
+ error_at (loc, "expected %<for%> loop or OpenMP loop "
+ "transformation construct");
+ if (transform == NULL_TREE || transform == error_mark_node)
+ {
+ omp_for_parse_state->fail = true;
+ return NULL_TREE;
+ }
+ for (count = omp_for_parse_state->count; depth < count; ++depth)
+ {
+ TREE_VEC_ELT (omp_for_parse_state->declv, depth) = global_namespace;
+ TREE_VEC_ELT (omp_for_parse_state->initv, depth) = NULL_TREE;
+ TREE_VEC_ELT (omp_for_parse_state->condv, depth) = NULL_TREE;
+ TREE_VEC_ELT (omp_for_parse_state->incrv, depth) = NULL_TREE;
+ if (omp_for_parse_state->orig_declv)
+ TREE_VEC_ELT (omp_for_parse_state->incrv, depth) = NULL_TREE;
+ vec_safe_push (omp_for_parse_state->init_blockv, NULL_TREE);
+ vec_safe_push (omp_for_parse_state->body_blockv, NULL_TREE);
+ vec_safe_push (omp_for_parse_state->init_placeholderv, NULL_TREE);
+ vec_safe_push (omp_for_parse_state->body_placeholderv, NULL_TREE);
+ }
+ omp_for_parse_state->want_nested_loop = false;
+ return body;
+ }
+
+ /* Diagnose errors if we don't have a "for" loop following the
+ optional loop transforms. Otherwise, consume the token. */
+ if (!cp_lexer_next_token_is_keyword (parser->lexer, RID_FOR))
+ {
+ omp_for_parse_state->fail = true;
+ cp_token *token = cp_lexer_peek_token (parser->lexer);
+ /* Don't call cp_parser_error here since it overrides the
+ provided message with a more confusing one if there was
+ a bad pragma or attribute directive. */
+ error_at (token->location, "loop nest expected");
+ /* See if we can recover by skipping over bad pragma(s). */
+ while (token->type == CPP_PRAGMA)
+ {
+ cp_parser_skip_to_pragma_eol (parser, token);
+ if (cp_parser_next_tokens_can_be_canon_loop (parser, omp_for_parse_state->code,
+ false))
+ return cp_parser_omp_loop_nest (parser, if_p);
+ token = cp_lexer_peek_token (parser->lexer);
+ }
+ return NULL_TREE;
+ }
loc = cp_lexer_consume_token (parser->lexer)->location;
/* Forbid break/continue in the loop initializer, condition, and
moreloops = depth < omp_for_parse_state->count - 1;
omp_for_parse_state->want_nested_loop = moreloops;
- if (moreloops && cp_lexer_next_token_is_keyword (parser->lexer, RID_FOR))
+ if (moreloops
+ && cp_parser_next_tokens_can_be_canon_loop (parser,
+ omp_for_parse_state->code,
+ false))
{
omp_for_parse_state->depth++;
- add_stmt (cp_parser_omp_loop_nest (parser, if_p));
+ tree nest = cp_parser_omp_loop_nest (parser, if_p);
+ if (nest)
+ add_stmt (nest);
omp_for_parse_state->depth--;
}
else if (moreloops
tree cl, ordered_cl = NULL_TREE;
int collapse = 1, ordered = 0;
unsigned int count;
- bool tiling = false;
+ bool oacc_tiling = false;
bool inscan = false;
struct omp_for_parse_data data;
struct omp_for_parse_data *save_data = parser->omp_for_parse_state;
collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl));
else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_TILE)
{
- tiling = true;
+ oacc_tiling = true;
collapse = list_length (OMP_CLAUSE_TILE_LIST (cl));
}
+ else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_SIZES)
+ collapse = list_length (OMP_CLAUSE_SIZES_LIST (cl));
else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED
&& OMP_CLAUSE_ORDERED_EXPR (cl))
{
ordered = collapse;
}
- gcc_assert (tiling || (collapse >= 1 && ordered >= 0));
+ gcc_assert (oacc_tiling || (collapse >= 1 && ordered >= 0));
count = ordered ? ordered : collapse;
- if (!cp_lexer_next_token_is_keyword (parser->lexer, RID_FOR))
- {
- cp_parser_error (parser, "for statement expected");
- return NULL;
- }
+ if (!cp_parser_next_tokens_can_be_canon_loop (parser, code, true))
+ return NULL;
/* Initialize parse state for recursive descent. */
data.declv = make_tree_vec (count);
data.ordered_cl = ordered_cl;
parser->omp_for_parse_state = &data;
- cp_parser_omp_loop_nest (parser, if_p);
+ tree body = cp_parser_omp_loop_nest (parser, if_p);
/* Bomb out early if there was an error (not enough loops, etc). */
if (data.fail || data.declv == NULL_TREE)
/* First insert markers for structured blocks for intervening code in
the loop bodies. */
for (unsigned int i = 0; i < count - 1; i++)
- {
- bool good = find_structured_blocks (&(data.body_blockv[i]),
- data.init_placeholderv[i+1]);
- gcc_assert (good);
- }
+ if (data.body_blockv[i])
+ for (unsigned int j = i + 1; j < count; j++)
+ if (data.init_placeholderv[j])
+ {
+ bool good = find_structured_blocks (&data.body_blockv[i],
+ data.init_placeholderv[j]);
+ gcc_assert (good);
+ break;
+ }
/* Do the substitution from the inside out. */
for (unsigned int i = count - 1; i > 0; i--)
- {
- substitute_in_tree (&(data.body_blockv[i-1]),
- data.init_placeholderv[i],
- data.body_blockv[i], false);
- substitute_in_tree (&(data.init_blockv[i-1]),
- data.body_placeholderv[i-1],
- data.init_blockv[i], true);
- }
+ if (data.init_placeholderv[i])
+ for (unsigned int j = i; j > 0; j--)
+ if (data.body_blockv[j - 1])
+ {
+ substitute_in_tree (&data.body_blockv[j - 1],
+ data.init_placeholderv[i],
+ data.body_blockv[i], false);
+ substitute_in_tree (&data.init_blockv[j - 1],
+ data.body_placeholderv[j - 1],
+ data.init_blockv[i], true);
+ break;
+ }
+
+ for (unsigned int i = 0; i < count; ++i)
+ if (data.body_blockv[i])
+ {
+ body = data.body_blockv[i];
+ break;
+ }
/* Generate the OMP_FOR. Note finish_omp_for adds the OMP_FOR
(and possibly other stuff) to the current statement list but
returns a pointer to the OMP_FOR itself, or null in case of error. */
result = push_stmt_list ();
ret = finish_omp_for (loc_first, code, data.declv, data.orig_declv,
- data.initv, data.condv, data.incrv,
- data.body_blockv[0],
+ data.initv, data.condv, data.incrv, body,
data.pre_body, &data.orig_inits, data.clauses);
result = pop_stmt_list (result);
/* Check for errors involving lb/ub/incr expressions referencing
variables declared in intervening code. */
if (data.saw_intervening_code
+ && ret
&& !c_omp_check_loop_binding_exprs (ret, &data.orig_inits))
ret = NULL_TREE;
if (ret)
- {
- /* Splice the omp_for into the nest of init blocks. */
- substitute_in_tree (&(data.init_blockv[0]),
- data.body_placeholderv[count - 1],
- result, true);
-
- /* Some later processing for combined directives assumes
- that the BIND_EXPR containing range for variables appears
- at top level in the OMP_FOR body. Fix that up if it's
- not the case, e.g. because there is intervening code. */
- if (code != OACC_LOOP)
- finish_omp_for_block (data.init_blockv[0], ret);
-
- /* Clean up the block subblock/superblock links. Per comment in
- begin_compound_stmt, "we don't build BLOCK nodes when processing
- templates", so skip this step in that case. */
- if (!processing_template_decl)
+ for (unsigned int i = 0; i < count; ++i)
+ if (data.init_blockv[i])
{
- tree superblock = NULL_TREE;
- cp_walk_tree (&data.init_blockv[0], fixup_blocks_walker,
- (void *)&superblock, NULL);
- }
+ int j;
+ for (j = count - 1; j >= 0; --j)
+ if (data.body_placeholderv[j])
+ break;
+ gcc_assert (j >= 0);
+
+ /* Splice the omp_for into the nest of init blocks. */
+ substitute_in_tree (&data.init_blockv[i],
+ data.body_placeholderv[j],
+ result, true);
+
+ /* Some later processing for combined directives assumes
+ that the BIND_EXPR containing range for variables appears
+ at top level in the OMP_FOR body. Fix that up if it's
+ not the case, e.g. because there is intervening code. */
+ if (code != OACC_LOOP)
+ finish_omp_for_block (data.init_blockv[i], ret);
+
+ /* Clean up the block subblock/superblock links. Per comment in
+ begin_compound_stmt, "we don't build BLOCK nodes when processing
+ templates", so skip this step in that case. */
+ if (!processing_template_decl)
+ {
+ tree superblock = NULL_TREE;
+ cp_walk_tree (&data.init_blockv[i], fixup_blocks_walker,
+ (void *)&superblock, NULL);
+ }
- /* Finally record the result. */
- add_stmt (data.init_blockv[0]);
- }
+ /* Finally record the result. */
+ add_stmt (data.init_blockv[0]);
+ result = NULL_TREE;
+ break;
+ }
+ if (ret && result)
+ add_stmt (result);
parser->omp_for_parse_state = save_data;
return ret;
return true;
}
+
+/* OpenMP 5.1: Parse sizes list for "omp tile sizes"
+ sizes ( size-expr-list ) */
+static tree
+cp_parser_omp_tile_sizes (cp_parser *parser, location_t loc)
+{
+ tree sizes = NULL_TREE;
+
+ if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
+ cp_lexer_consume_token (parser->lexer);
+
+ cp_token *tok = cp_lexer_peek_token (parser->lexer);
+ if (tok->type != CPP_NAME
+ || strcmp ("sizes", IDENTIFIER_POINTER (tok->u.value)))
+ {
+ cp_parser_error (parser, "expected %<sizes%>");
+ return error_mark_node;
+ }
+ cp_lexer_consume_token (parser->lexer);
+
+ matching_parens parens;
+ if (!parens.require_open (parser))
+ return error_mark_node;
+
+ do
+ {
+ if (sizes && !cp_parser_require (parser, CPP_COMMA, RT_COMMA))
+ return error_mark_node;
+
+ tree expr = cp_parser_constant_expression (parser);
+ if (expr == error_mark_node)
+ {
+ cp_parser_skip_to_closing_parenthesis (parser,
+ /*recovering=*/true,
+ /*or_comma=*/false,
+ /*consume_paren=*/true);
+ return error_mark_node;
+ }
+
+ sizes = tree_cons (NULL_TREE, expr, sizes);
+ }
+ while (cp_lexer_next_token_is_not (parser->lexer, CPP_CLOSE_PAREN));
+ parens.require_close (parser);
+
+ gcc_assert (sizes);
+ tree c = build_omp_clause (loc, OMP_CLAUSE_SIZES);
+ OMP_CLAUSE_SIZES_LIST (c) = nreverse (sizes);
+ return c;
+}
+
+/* OpenMP 5.1:
+ #pragma omp tile sizes ( size-expr-list ) */
+
+static tree
+cp_parser_omp_tile (cp_parser *parser, cp_token *tok, bool *if_p)
+{
+ tree clauses = cp_parser_omp_tile_sizes (parser, tok->location);
+ cp_parser_require_pragma_eol (parser, tok);
+
+ if (!clauses || clauses == error_mark_node)
+ return error_mark_node;
+
+ tree block = begin_omp_structured_block ();
+ clauses = finish_omp_clauses (clauses, C_ORT_OMP);
+ tree ret = cp_parser_omp_for_loop (parser, OMP_TILE, clauses, NULL, if_p);
+ block = finish_omp_structured_block (block);
+ add_stmt (block);
+
+ return ret;
+}
+
+#define OMP_UNROLL_CLAUSE_MASK \
+ ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARTIAL) \
+ | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FULL))
+
+/* OpenMP 5.1:
+ #pragma omp unroll unroll-clause[optseq] */
+
+static tree
+cp_parser_omp_unroll (cp_parser *parser, cp_token *tok, bool *if_p)
+{
+ tree clauses = cp_parser_omp_all_clauses (parser, OMP_UNROLL_CLAUSE_MASK,
+ "#pragma omp unroll", tok, true);
+
+ tree block = begin_omp_structured_block ();
+ tree ret = cp_parser_omp_for_loop (parser, OMP_UNROLL, clauses, NULL, if_p);
+ block = finish_omp_structured_block (block);
+ add_stmt (block);
+
+ return ret;
+}
+
/* OpenACC 2.0:
# pragma acc cache (variable-list) new-line
case PRAGMA_OMP_ASSUME:
cp_parser_omp_assume (parser, pragma_tok, if_p);
return;
+ case PRAGMA_OMP_TILE:
+ stmt = cp_parser_omp_tile (parser, pragma_tok, if_p);
+ break;
+ case PRAGMA_OMP_UNROLL:
+ stmt = cp_parser_omp_unroll (parser, pragma_tok, if_p);
+ break;
default:
gcc_unreachable ();
}
case PRAGMA_OMP_TASKGROUP:
case PRAGMA_OMP_TASKLOOP:
case PRAGMA_OMP_TEAMS:
+ case PRAGMA_OMP_TILE:
+ case PRAGMA_OMP_UNROLL:
if (context != pragma_stmt && context != pragma_compound)
goto bad_stmt;
stmt = push_omp_privatization_clauses (false);
OMP_CLAUSE_OPERAND (nc, 0)
= tsubst_stmt (OMP_CLAUSE_OPERAND (oc, 0), args, complain, in_decl);
break;
+ case OMP_CLAUSE_PARTIAL:
+ OMP_CLAUSE_PARTIAL_EXPR (nc)
+ = tsubst_expr (OMP_CLAUSE_PARTIAL_EXPR (oc), args, complain,
+ in_decl);
+ break;
+ case OMP_CLAUSE_SIZES:
+ OMP_CLAUSE_SIZES_LIST (nc)
+ = tsubst_expr (OMP_CLAUSE_SIZES_LIST (oc), args, complain,
+ in_decl);
+ break;
case OMP_CLAUSE_REDUCTION:
case OMP_CLAUSE_IN_REDUCTION:
case OMP_CLAUSE_TASK_REDUCTION:
case OMP_CLAUSE_IF_PRESENT:
case OMP_CLAUSE_FINALIZE:
case OMP_CLAUSE_NOHOST:
+ case OMP_CLAUSE_FULL:
break;
default:
gcc_unreachable ();
case OMP_SIMD:
case OMP_DISTRIBUTE:
case OMP_TASKLOOP:
+ case OMP_TILE:
+ case OMP_UNROLL:
case OACC_LOOP:
{
tree clauses, body, pre_body;
if (OMP_FOR_INIT (t) != NULL_TREE)
for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (t)); i++)
- any_range_for
- |= tsubst_omp_for_iterator (t, i, declv, orig_declv, initv,
- condv, incrv, &clauses, args,
- complain, in_decl);
+ {
+ if (TREE_VEC_ELT (OMP_FOR_INIT (t), i))
+ any_range_for
+ |= tsubst_omp_for_iterator (t, i, declv, orig_declv, initv,
+ condv, incrv, &clauses, args,
+ complain, in_decl);
+ else
+ {
+ TREE_VEC_ELT (declv, i) = global_namespace;
+ TREE_VEC_ELT (initv, i) = NULL_TREE;
+ TREE_VEC_ELT (condv, i) = NULL_TREE;
+ TREE_VEC_ELT (incrv, i) = NULL_TREE;
+ if (orig_declv)
+ TREE_VEC_ELT (orig_declv, i) = NULL_TREE;
+ }
+ }
omp_parallel_combined_clauses = NULL;
if (any_range_for)
gcc_assert (orig_declv);
body = begin_omp_structured_block ();
for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (t)); i++)
- if (TREE_VEC_ELT (orig_declv, i) != TREE_VEC_ELT (declv, i)
+ if (TREE_VEC_ELT (declv, i) != global_namespace
+ && TREE_VEC_ELT (orig_declv, i) != TREE_VEC_ELT (declv, i)
&& TREE_CODE (TREE_VEC_ELT (orig_declv, i)) == TREE_LIST
&& TREE_CHAIN (TREE_VEC_ELT (orig_declv, i)))
cp_finish_omp_range_for (TREE_VEC_ELT (orig_declv, i),
}
/* Returns TRUE if OMP_FOR with DECLV, INITV, CONDV and INCRV vectors
- are dependent. */
+ are dependent. BODY is the body to use for loop transforming
+ constructs. */
bool
-dependent_omp_for_p (tree declv, tree initv, tree condv, tree incrv)
+dependent_omp_for_p (tree declv, tree initv, tree condv, tree incrv, tree body)
{
- int i;
+ int i, k;
if (!processing_template_decl)
return false;
- for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
+ for (i = 0, k = 0; i < TREE_VEC_LENGTH (declv); i++)
{
tree decl = TREE_VEC_ELT (declv, i);
tree init = TREE_VEC_ELT (initv, i);
tree cond = TREE_VEC_ELT (condv, i);
tree incr = TREE_VEC_ELT (incrv, i);
+ if (decl == NULL_TREE)
+ {
+ tree stmt = body;
+ int j = c_omp_find_generated_loop (stmt, k++, cp_walk_subtrees);
+ init = TREE_VEC_ELT (OMP_FOR_INIT (stmt), j);
+ decl = TREE_OPERAND (init, 0);
+ cond = TREE_VEC_ELT (OMP_FOR_INIT (stmt), j);
+ incr = TREE_VEC_ELT (OMP_FOR_INIT (stmt), j);
+ }
+
if (type_dependent_expression_p (decl)
|| TREE_CODE (decl) == SCOPE_REF)
return true;
bool implicit_moved = false;
bool target_in_reduction_seen = false;
bool num_tasks_seen = false;
+ bool partial_seen = false;
bitmap_obstack_initialize (NULL);
bitmap_initialize (&generic_head, &bitmap_default_obstack);
"be positive constant integer expression");
remove = true;
}
- else
- t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
}
OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
}
if (!processing_template_decl)
{
t = maybe_constant_value (t);
- t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
if (TREE_CODE (t) != INTEGER_CST)
{
error_at (OMP_CLAUSE_LOCATION (c),
"integral constant");
remove = true;
}
- t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
}
}
}
break;
+ case OMP_CLAUSE_SIZES:
+ for (tree list = OMP_CLAUSE_SIZES_LIST (c);
+ !remove && list; list = TREE_CHAIN (list))
+ {
+ t = TREE_VALUE (list);
+
+ if (t == error_mark_node)
+ t = integer_one_node;
+ else if (!type_dependent_expression_p (t)
+ && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
+ {
+ error_at (OMP_CLAUSE_LOCATION (c),
+ "%<sizes%> argument needs positive integral "
+ "constant");
+ t = integer_one_node;
+ }
+ else
+ {
+ t = mark_rvalue_use (t);
+ if (!processing_template_decl)
+ {
+ t = maybe_constant_value (t);
+ HOST_WIDE_INT n;
+ if (!tree_fits_shwi_p (t)
+ || !INTEGRAL_TYPE_P (TREE_TYPE (t))
+ || (n = tree_to_shwi (t)) <= 0
+ || (int)n != n)
+ {
+ error_at (OMP_CLAUSE_LOCATION (c),
+ "%<sizes%> argument needs positive "
+ "integral constant");
+ t = integer_one_node;
+ }
+ }
+ }
+
+ /* Update list item. */
+ TREE_VALUE (list) = t;
+ }
+ break;
+
case OMP_CLAUSE_ORDERED:
ordered_seen = true;
break;
}
break;
+ case OMP_CLAUSE_FULL:
+ break;
+
+ case OMP_CLAUSE_PARTIAL:
+ partial_seen = true;
+ t = OMP_CLAUSE_PARTIAL_EXPR (c);
+ if (!t)
+ break;
+
+ if (t == error_mark_node)
+ t = NULL_TREE;
+ else if (!type_dependent_expression_p (t)
+ && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
+ {
+ error_at (OMP_CLAUSE_LOCATION (c),
+ "%<partial%> argument needs positive constant "
+ "integer expression");
+ t = NULL_TREE;
+ }
+ else
+ {
+ t = mark_rvalue_use (t);
+ if (!processing_template_decl)
+ {
+ t = maybe_constant_value (t);
+
+ HOST_WIDE_INT n;
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
+ || !tree_fits_shwi_p (t)
+ || (n = tree_to_shwi (t)) <= 0
+ || (int)n != n)
+ {
+ error_at (OMP_CLAUSE_LOCATION (c),
+ "%<partial%> argument needs positive "
+ "constant integer expression");
+ t = NULL_TREE;
+ }
+ }
+ }
+
+ OMP_CLAUSE_PARTIAL_EXPR (c) = t;
+ break;
+
default:
gcc_unreachable ();
}
{
error_at (OMP_CLAUSE_LOCATION (c),
"%<order%> clause must not be used together "
- "with %<ordered%>");
+ "with %<ordered%> clause");
*pc = OMP_CLAUSE_CHAIN (c);
continue;
}
}
pc = &OMP_CLAUSE_CHAIN (c);
continue;
+ case OMP_CLAUSE_FULL:
+ if (partial_seen)
+ {
+ error_at (OMP_CLAUSE_LOCATION (c),
+ "%<full%> clause must not be used together "
+ "with %<partial%> clause");
+ *pc = OMP_CLAUSE_CHAIN (c);
+ continue;
+ }
+ pc = &OMP_CLAUSE_CHAIN (c);
+ continue;
case OMP_CLAUSE_NOWAIT:
if (copyprivate_seen)
{
error_at (OMP_CLAUSE_LOCATION (c),
"%<nowait%> clause must not be used together "
- "with %<copyprivate%>");
+ "with %<copyprivate%> clause");
*pc = OMP_CLAUSE_CHAIN (c);
continue;
}
gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
if (TREE_VEC_LENGTH (declv) > 1)
{
- tree c;
-
- c = omp_find_clause (clauses, OMP_CLAUSE_TILE);
- if (c)
- collapse = list_length (OMP_CLAUSE_TILE_LIST (c));
+ if (tree ti = omp_find_clause (clauses, OMP_CLAUSE_TILE))
+ collapse = list_length (OMP_CLAUSE_TILE_LIST (ti));
else
{
- c = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE);
- if (c)
- collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c));
+ if (tree co = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE))
+ collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (co));
+ else if (tree si = omp_find_clause (clauses, OMP_CLAUSE_SIZES))
+ collapse = list_length (OMP_CLAUSE_SIZES_LIST (si));
if (collapse != TREE_VEC_LENGTH (declv))
ordered = TREE_VEC_LENGTH (declv);
}
incr = TREE_VEC_ELT (incrv, i);
elocus = locus;
+ if (decl == global_namespace)
+ {
+ gcc_assert (init == NULL_TREE && cond == NULL_TREE && incr == NULL_TREE);
+ TREE_VEC_ELT (declv, i) = NULL_TREE;
+ init_locv.safe_push (UNKNOWN_LOCATION);
+ continue;
+ }
/* We are going to throw out the init's original MODIFY_EXPR or
MODOP_EXPR below. Save its location so we can use it when
reconstructing the expression farther down. Alternatively, if the
return NULL;
}
- if (dependent_omp_for_p (declv, initv, condv, incrv))
+ if (dependent_omp_for_p (declv, initv, condv, incrv, body))
{
tree stmt;
for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
{
+ if (TREE_VEC_ELT (declv, i) == NULL_TREE)
+ continue;
/* This is really just a place-holder. We'll be decomposing this
again and going through the cp_build_modify_expr path below when
we instantiate the thing. */
TREE_VEC_ELT (orig_incr, i) = incr;
elocus = init_locv[i];
+ if (decl == NULL_TREE)
+ {
+ i++;
+ continue;
+ }
+
if (!DECL_P (decl))
{
error_at (elocus, "expected iteration declaration or initialization");
for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
{
init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i);
+ if (init == NULL_TREE)
+ continue;
decl = TREE_OPERAND (init, 0);
cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), i);
incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
fofb.b = NULL_TREE;
fofb.omp_for = omp_for;
for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for)); i++)
- if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)) == TREE_LIST
+ if (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i)
+ && (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i))
+ == TREE_LIST)
&& TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i)))
{
tree v = TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for), i));
}
if (omp_clauses->assume)
show_omp_assumes (omp_clauses->assume);
+ if (omp_clauses->full)
+ fputs (" FULL", dumpfile);
+ if (omp_clauses->partial)
+ {
+ fputs (" PARTIAL", dumpfile);
+ if (omp_clauses->partial > 0)
+ fprintf (dumpfile, "(%d)", omp_clauses->partial);
+ }
+ if (omp_clauses->sizes_list)
+ {
+ gfc_expr_list *sizes;
+ fputs (" SIZES(", dumpfile);
+ for (sizes = omp_clauses->sizes_list; sizes; sizes = sizes->next)
+ {
+ show_expr (sizes->expr);
+ if (sizes->next)
+ fputs (", ", dumpfile);
+ }
+ fputc (')', dumpfile);
+ }
}
/* Show a single OpenMP or OpenACC directive node and everything underneath it
name = "TEAMS DISTRIBUTE PARALLEL DO SIMD"; break;
case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD: name = "TEAMS DISTRIBUTE SIMD"; break;
case EXEC_OMP_TEAMS_LOOP: name = "TEAMS LOOP"; break;
+ case EXEC_OMP_TILE: name = "TILE"; break;
+ case EXEC_OMP_UNROLL: name = "UNROLL"; break;
case EXEC_OMP_WORKSHARE: name = "WORKSHARE"; break;
default:
gcc_unreachable ();
case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
case EXEC_OMP_TEAMS_LOOP:
+ case EXEC_OMP_TILE:
+ case EXEC_OMP_UNROLL:
case EXEC_OMP_WORKSHARE:
omp_clauses = c->ext.omp_clauses;
break;
case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
case EXEC_OMP_TEAMS_LOOP:
+ case EXEC_OMP_TILE:
+ case EXEC_OMP_UNROLL:
case EXEC_OMP_WORKSHARE:
show_omp_node (level, c);
break;
ST_OMP_ALLOCATE, ST_OMP_ALLOCATE_EXEC,
ST_OMP_ALLOCATORS, ST_OMP_END_ALLOCATORS,
/* Note: gfc_match_omp_nothing returns ST_NONE. */
- ST_OMP_NOTHING, ST_NONE
+ ST_OMP_NOTHING, ST_NONE,
+ ST_OMP_UNROLL, ST_OMP_END_UNROLL,
+ ST_OMP_TILE, ST_OMP_END_TILE
};
/* Types of interfaces that we can have. Assignment interfaces are
struct gfc_expr *dist_chunk_size;
struct gfc_expr *message;
struct gfc_omp_assumptions *assume;
+ struct gfc_expr_list *sizes_list;
const char *critical_name;
enum gfc_omp_default_sharing default_sharing;
enum gfc_omp_atomic_op atomic_op;
enum gfc_omp_defaultmap defaultmap[OMP_DEFAULTMAP_CAT_NUM];
int collapse, orderedc;
+ int partial;
unsigned nowait:1, ordered:1, untied:1, mergeable:1, ancestor:1;
unsigned inbranch:1, notinbranch:1, nogroup:1;
unsigned sched_simd:1, sched_monotonic:1, sched_nonmonotonic:1;
unsigned non_rectangular:1, order_concurrent:1;
unsigned contains_teams_construct:1, target_first_st_is_teams:1;
unsigned contained_in_target_construct:1, indirect:1;
+ unsigned full:1, erroneous:1;
ENUM_BITFIELD (gfc_omp_sched_kind) sched_kind:3;
ENUM_BITFIELD (gfc_omp_device_type) device_type:2;
ENUM_BITFIELD (gfc_omp_memorder) memorder:3;
EXEC_OMP_TARGET_TEAMS_LOOP, EXEC_OMP_MASKED, EXEC_OMP_PARALLEL_MASKED,
EXEC_OMP_PARALLEL_MASKED_TASKLOOP, EXEC_OMP_PARALLEL_MASKED_TASKLOOP_SIMD,
EXEC_OMP_MASKED_TASKLOOP, EXEC_OMP_MASKED_TASKLOOP_SIMD, EXEC_OMP_SCOPE,
+ EXEC_OMP_UNROLL, EXEC_OMP_TILE,
EXEC_OMP_ERROR, EXEC_OMP_ALLOCATE, EXEC_OMP_ALLOCATORS
};
/* trans-intrinsic.cc */
bool gfc_inline_intrinsic_function_p (gfc_expr *);
+/* trans-openmp.cc */
+int gfc_expr_list_len (gfc_expr_list *);
+
/* bbt.cc */
typedef int (*compare_fn) (void *, void *);
void gfc_insert_bbt (void *, void *, compare_fn);
match gfc_match_omp_teams_distribute_simd (void);
match gfc_match_omp_teams_loop (void);
match gfc_match_omp_threadprivate (void);
+match gfc_match_omp_tile (void);
+match gfc_match_omp_unroll (void);
match gfc_match_omp_workshare (void);
match gfc_match_omp_end_critical (void);
match gfc_match_omp_end_nowait (void);
#include "bitmap.h"
#include "omp-api.h" /* For omp_runtime_api_procname. */
+location_t gfc_get_location (locus *);
static gfc_statement omp_code_to_statement (gfc_code *);
i == OMP_LIST_USES_ALLOCATORS);
gfc_free_expr_list (c->wait_list);
gfc_free_expr_list (c->tile_list);
+ gfc_free_expr_list (c->sizes_list);
free (CONST_CAST (char *, c->critical_name));
if (c->assume)
{
}
static match
-match_oacc_expr_list (const char *str, gfc_expr_list **list,
- bool allow_asterisk)
+match_omp_oacc_expr_list (const char *str, gfc_expr_list **list,
+ bool allow_asterisk, bool is_omp)
{
gfc_expr_list *head, *tail, *p;
locus old_loc;
return MATCH_YES;
syntax:
- gfc_error ("Syntax error in OpenACC expression list at %C");
+ if (is_omp)
+ gfc_error ("Syntax error in OpenMP expression list at %C");
+ else
+ gfc_error ("Syntax error in OpenACC expression list at %C");
cleanup:
gfc_free_expr_list (head);
OMP_CLAUSE_ASSUMPTIONS, /* OpenMP 5.1. */
OMP_CLAUSE_USES_ALLOCATORS, /* OpenMP 5.0 */
OMP_CLAUSE_INDIRECT, /* OpenMP 5.1 */
+ OMP_CLAUSE_FULL, /* OpenMP 5.1. */
+ OMP_CLAUSE_PARTIAL, /* OpenMP 5.1. */
+ OMP_CLAUSE_SIZES, /* OpenMP 5.1. */
/* This must come last. */
OMP_MASK2_LAST
};
&& gfc_match_motion_var_list ("from (", &c->lists[OMP_LIST_FROM],
&head) == MATCH_YES)
continue;
+ if ((mask & OMP_CLAUSE_FULL)
+ && (m = gfc_match_dupl_check (!c->full, "full")) != MATCH_NO)
+ {
+ if (m == MATCH_ERROR)
+ goto error;
+ c->full = needs_space = true;
+ continue;
+ }
break;
case 'g':
if ((mask & OMP_CLAUSE_GANG)
}
break;
case 'p':
+ if (mask & OMP_CLAUSE_PARTIAL)
+ {
+ if ((m = gfc_match_dupl_check (!c->partial, "partial"))
+ != MATCH_NO)
+ {
+ int expr;
+ if (m == MATCH_ERROR)
+ goto error;
+
+ c->partial = -1;
+
+ gfc_expr *cexpr = NULL;
+ m = gfc_match (" ( %e )", &cexpr);
+ if (m == MATCH_NO)
+ ;
+ else if (m == MATCH_YES
+ && !gfc_extract_int (cexpr, &expr, -1)
+ && expr > 0)
+ c->partial = expr;
+ else
+ gfc_error_now ("PARTIAL clause argument not constant "
+ "positive integer at %C");
+ gfc_free_expr (cexpr);
+ continue;
+ }
+ }
if ((mask & OMP_CLAUSE_COPY)
&& gfc_match ("pcopy ( ") == MATCH_YES
&& gfc_match_omp_map_clause (&c->lists[OMP_LIST_MAP],
}
continue;
}
+ if ((mask & OMP_CLAUSE_SIZES)
+ && ((m = gfc_match_dupl_check (!c->sizes_list, "sizes"))
+ != MATCH_NO))
+ {
+ if (m == MATCH_ERROR)
+ goto error;
+ m = match_omp_oacc_expr_list (" (", &c->sizes_list, false, true);
+ if (m == MATCH_ERROR)
+ goto error;
+ if (m == MATCH_YES)
+ continue;
+ gfc_error ("Expected %<(%> after %qs at %C", "sizes");
+ goto error;
+ }
break;
case 't':
if ((mask & OMP_CLAUSE_TASK_REDUCTION)
}
if ((mask & OMP_CLAUSE_TILE)
&& !c->tile_list
- && match_oacc_expr_list ("tile (", &c->tile_list,
- true) == MATCH_YES)
+ && match_omp_oacc_expr_list ("tile (", &c->tile_list,
+ true, false) == MATCH_YES)
continue;
if ((mask & OMP_CLAUSE_TO) && (mask & OMP_CLAUSE_LINK))
{
if ((mask & OMP_CLAUSE_WAIT)
&& gfc_match ("wait") == MATCH_YES)
{
- m = match_oacc_expr_list (" (", &c->wait_list, false);
+ m = match_omp_oacc_expr_list (" (", &c->wait_list, false, false);
if (m == MATCH_ERROR)
goto error;
else if (m == MATCH_NO)
bool space = true;
match m;
- m = match_oacc_expr_list (" (", &wait_list, true);
+ m = match_omp_oacc_expr_list (" (", &wait_list, true, false);
if (m == MATCH_ERROR)
return m;
else if (m == MATCH_YES)
(omp_mask (OMP_CLAUSE_AT) | OMP_CLAUSE_MESSAGE | OMP_CLAUSE_SEVERITY)
#define OMP_WORKSHARE_CLAUSES \
omp_mask (OMP_CLAUSE_NOWAIT)
+#define OMP_UNROLL_CLAUSES \
+ (omp_mask (OMP_CLAUSE_FULL) | OMP_CLAUSE_PARTIAL)
+#define OMP_TILE_CLAUSES \
+ (omp_mask (OMP_CLAUSE_SIZES))
#define OMP_ALLOCATORS_CLAUSES \
omp_mask (OMP_CLAUSE_ALLOCATE)
| OMP_SIMD_CLAUSES);
}
+match
+gfc_match_omp_tile (void)
+{
+ return match_omp (EXEC_OMP_TILE, OMP_TILE_CLAUSES);
+}
+
+match
+gfc_match_omp_unroll (void)
+{
+ return match_omp (EXEC_OMP_UNROLL, OMP_UNROLL_CLAUSES);
+}
match
gfc_match_omp_workshare (void)
gfc_error ("%<REDUCTION%> clause at %L must not be used together with "
"%<NOGROUP%> clause",
&omp_clauses->lists[OMP_LIST_REDUCTION]->where);
+ if (omp_clauses->full && omp_clauses->partial)
+ gfc_error ("%<FULL%> clause at %C must not be used together with "
+ "%<PARTIAL%> clause");
if (omp_clauses->async)
if (omp_clauses->async_expr)
resolve_scalar_int_expr (omp_clauses->async_expr, "ASYNC");
gfc_error ("%s must contain at least one MAP clause at %L",
p, &code->loc);
}
+ if (omp_clauses->sizes_list)
+ {
+ gfc_expr_list *el;
+ for (el = omp_clauses->sizes_list; el; el = el->next)
+ {
+ resolve_scalar_int_expr (el->expr, "SIZES");
+ if (el->expr->expr_type != EXPR_CONSTANT)
+ gfc_error ("SIZES requires constant expression at %L",
+ &el->expr->where);
+ else if (el->expr->expr_type == EXPR_CONSTANT
+ && el->expr->ts.type == BT_INTEGER
+ && mpz_sgn (el->expr->value.integer) <= 0)
+ gfc_error ("INTEGER expression of %s clause at %L must be "
+ "positive", "SIZES", &el->expr->where);
+ }
+ }
if (!openacc && omp_clauses->detach)
{
return NULL;
for (code = chain; code; code = code->next)
- {
- if (code->op == EXEC_DO)
+ switch (code->op)
+ {
+ case EXEC_DO:
+ case EXEC_OMP_TILE:
+ case EXEC_OMP_UNROLL:
return code;
- else if (code->op == EXEC_BLOCK)
- {
- gfc_code *c = find_nested_loop_in_block (code);
- if (c)
- return c;
- }
- }
+ case EXEC_BLOCK:
+ if (gfc_code *c = find_nested_loop_in_block (code))
+ return c;
+ break;
+ default:
+ break;
+ }
return NULL;
}
omp_current_do_collapse = code->ext.omp_clauses->orderedc;
else if (code->ext.omp_clauses->collapse)
omp_current_do_collapse = code->ext.omp_clauses->collapse;
+ else if (code->ext.omp_clauses->sizes_list)
+ omp_current_do_collapse
+ = gfc_expr_list_len (code->ext.omp_clauses->sizes_list);
else
omp_current_do_collapse = 1;
if (code->ext.omp_clauses->lists[OMP_LIST_REDUCTION_INSCAN])
if (code == c)
return;
c = find_nested_loop_in_chain (c->block->next);
+ if (c && (c->op == EXEC_OMP_TILE || c->op == EXEC_OMP_UNROLL))
+ return;
}
/* An openacc context may represent a data clause. Abort if so. */
gfc_code *tail = NULL;
gfc_code *innermost_loop = NULL;
- for (code = *chainp; code; code = code->next, chainp = &((*chainp)->next))
+ for (code = *chainp; code; code = code->next, chainp = &(*chainp)->next)
{
if (code->op == EXEC_DO)
{
innermost_loop = code;
else
innermost_loop
- = restructure_intervening_code (&(code->block->next),
+ = restructure_intervening_code (&code->block->next,
code, count - 1);
break;
}
code->next = NULL;
innermost_loop
- = restructure_intervening_code (&(ns->code), outer_loop,
+ = restructure_intervening_code (&ns->code, outer_loop,
count);
/* At this point we have already pulled out the nested loop and
{
do_code = find_nested_loop_in_chain (do_code->block->next);
gcc_assert (do_code);
+ if (do_code->op == EXEC_OMP_TILE || do_code->op == EXEC_OMP_UNROLL)
+ {
+ --i;
+ continue;
+ }
gfc_symbol *ivar = do_code->ext.iterator->var->symtree->n.sym;
if (var == ivar)
return true;
{
if (code->op == EXEC_DO)
return code;
+ else if (code->op == EXEC_OMP_TILE || code->op == EXEC_OMP_UNROLL)
+ return check_nested_loop_in_chain (code->block->next, expr, sym, bad);
else if (code->op == EXEC_BLOCK)
{
gfc_code *c = check_nested_loop_in_block (code, expr, sym, bad);
{
do_code = find_nested_loop_in_chain (do_code->block->next);
gcc_assert (do_code);
+ if (do_code->op == EXEC_OMP_TILE || do_code->op == EXEC_OMP_UNROLL)
+ {
+ --i;
+ continue;
+ }
gfc_symbol *ivar = do_code->ext.iterator->var->symtree->n.sym;
if (gfc_find_sym_in_expr (ivar, expr))
return false;
resolve_omp_do (gfc_code *code)
{
gfc_code *do_code, *next;
- int list, i, count;
+ int list, i, count, non_generated_count;
gfc_omp_namelist *n;
gfc_symbol *dovar;
const char *name;
bool is_simd = false;
bool errorp = false;
bool perfect_nesting_errorp = false;
+ bool imperfect = false;
switch (code->op)
{
is_simd = true;
break;
case EXEC_OMP_TEAMS_LOOP: name = "!$OMP TEAMS LOOP"; break;
+ case EXEC_OMP_TILE: name = "!$OMP TILE"; break;
+ case EXEC_OMP_UNROLL: name = "!$OMP UNROLL"; break;
default: gcc_unreachable ();
}
if (code->ext.omp_clauses)
resolve_omp_clauses (code, code->ext.omp_clauses, NULL);
+ if (code->op == EXEC_OMP_TILE && code->ext.omp_clauses->sizes_list == NULL)
+ gfc_error ("SIZES clause is required on !$OMP TILE construct at %L",
+ &code->loc);
+
do_code = code->block->next;
if (code->ext.omp_clauses->orderedc)
count = code->ext.omp_clauses->orderedc;
+ else if (code->ext.omp_clauses->sizes_list)
+ count = gfc_expr_list_len (code->ext.omp_clauses->sizes_list);
else
{
count = code->ext.omp_clauses->collapse;
count = 1;
}
+ non_generated_count = count;
/* While the spec defines the loop nest depth independently of the COLLAPSE
clause, in practice the middle end only pays attention to the COLLAPSE
depth and treats any further inner loops as the final-loop-body. So
{
gfc_error ("%s cannot be a DO WHILE or DO without loop control "
"at %L", name, &do_code->loc);
- return;
+ goto fail;
}
if (do_code->op == EXEC_DO_CONCURRENT)
{
gfc_error ("%s cannot be a DO CONCURRENT loop at %L", name,
&do_code->loc);
- return;
+ goto fail;
+ }
+ if (do_code->op == EXEC_OMP_TILE || do_code->op == EXEC_OMP_UNROLL)
+ {
+ if (do_code->op == EXEC_OMP_UNROLL)
+ {
+ if (!do_code->ext.omp_clauses->partial)
+ {
+ gfc_error ("Generated loop of UNROLL construct at %L "
+ "without PARTIAL clause does not have "
+ "canonical form", &do_code->loc);
+ goto fail;
+ }
+ else if (i != count)
+ {
+ gfc_error ("UNROLL construct at %L with PARTIAL clause "
+ "generates just one loop with canonical form "
+ "but %d loops are needed",
+ &do_code->loc, count - i + 1);
+ goto fail;
+ }
+ }
+ else if (do_code->op == EXEC_OMP_TILE)
+ {
+ if (do_code->ext.omp_clauses->sizes_list == NULL)
+ /* This should have been diagnosed earlier already. */
+ return;
+ int l = gfc_expr_list_len (do_code->ext.omp_clauses->sizes_list);
+ if (count - i + 1 > l)
+ {
+ gfc_error ("TILE construct at %L generates %d loops "
+ "with canonical form but %d loops are needed",
+ &do_code->loc, l, count - i + 1);
+ goto fail;
+ }
+ }
+ if (do_code->ext.omp_clauses && do_code->ext.omp_clauses->erroneous)
+ goto fail;
+ if (imperfect && !perfect_nesting_errorp)
+ {
+ sorry_at (gfc_get_location (&do_code->loc),
+ "Imperfectly nested loop using generated loops");
+ errorp = true;
+ }
+ if (non_generated_count == count)
+ non_generated_count = i - 1;
+ --i;
+ do_code = do_code->block->next;
+ continue;
}
gcc_assert (do_code->op == EXEC_DO);
if (do_code->ext.iterator->var->ts.type != BT_INTEGER)
errorp = true;
}
if (start_var || end_var)
- code->ext.omp_clauses->non_rectangular = 1;
+ {
+ code->ext.omp_clauses->non_rectangular = 1;
+ if (i > non_generated_count)
+ {
+ sorry_at (gfc_get_location (&do_code->loc),
+ "Non-rectangular loops from generated loops "
+ "unsupported");
+ errorp = true;
+ }
+ }
/* Only parse loop body into nested loop and intervening code if
there are supposed to be more loops in the nest to collapse. */
/* Parse error, can't recover from this. */
gfc_error ("not enough DO loops for collapsed %s (level %d) at %L",
name, i, &code->loc);
- return;
+ goto fail;
}
else if (next != do_code->block->next || next->next)
/* Imperfectly nested loop found. */
name, &code->loc);
perfect_nesting_errorp = true;
}
- /* FIXME: Also diagnose for TILE directives. */
+ else if (code->op == EXEC_OMP_TILE)
+ {
+ gfc_error ("%s inner loops must be perfectly nested at %L",
+ name, &code->loc);
+ perfect_nesting_errorp = true;
+ }
if (perfect_nesting_errorp)
errorp = true;
}
if (diagnose_intervening_code_errors (do_code->block->next,
name, next))
errorp = true;
+ imperfect = true;
}
do_code = next;
}
/* Give up now if we found any constraint violations. */
if (errorp)
- return;
+ {
+ fail:
+ if (code->ext.omp_clauses)
+ code->ext.omp_clauses->erroneous = 1;
+ return;
+ }
- restructure_intervening_code (&(code->block->next), code, count);
+ if (non_generated_count)
+ restructure_intervening_code (&code->block->next, code,
+ non_generated_count);
}
return ST_OMP_PARALLEL_LOOP;
case EXEC_OMP_DEPOBJ:
return ST_OMP_DEPOBJ;
+ case EXEC_OMP_TILE:
+ return ST_OMP_TILE;
+ case EXEC_OMP_UNROLL:
+ return ST_OMP_UNROLL;
default:
gcc_unreachable ();
}
case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
case EXEC_OMP_TEAMS_LOOP:
+ case EXEC_OMP_TILE:
+ case EXEC_OMP_UNROLL:
resolve_omp_do (code);
break;
case EXEC_OMP_TARGET:
case 'e':
matchs ("end assume", gfc_match_omp_eos_error, ST_OMP_END_ASSUME);
matchs ("end simd", gfc_match_omp_eos_error, ST_OMP_END_SIMD);
+ matchs ("end tile", gfc_match_omp_eos_error, ST_OMP_END_TILE);
+ matchs ("end unroll", gfc_match_omp_eos_error, ST_OMP_END_UNROLL);
matcho ("error", gfc_match_omp_error, ST_OMP_ERROR);
break;
+ case 'n':
+ matcho ("nothing", gfc_match_omp_nothing, ST_NONE);
+ break;
case 's':
matchs ("scan", gfc_match_omp_scan, ST_OMP_SCAN);
matchs ("simd", gfc_match_omp_simd, ST_OMP_SIMD);
break;
- case 'n':
- matcho ("nothing", gfc_match_omp_nothing, ST_NONE);
+ case 't':
+ matchs ("tile", gfc_match_omp_tile, ST_OMP_TILE);
+ break;
+ case 'u':
+ matchs ("unroll", gfc_match_omp_unroll, ST_OMP_UNROLL);
break;
}
case ST_OMP_LOOP: case ST_OMP_PARALLEL_LOOP: case ST_OMP_TEAMS_LOOP: \
case ST_OMP_TARGET_PARALLEL_LOOP: case ST_OMP_TARGET_TEAMS_LOOP: \
case ST_OMP_ALLOCATE_EXEC: case ST_OMP_ALLOCATORS: case ST_OMP_ASSUME: \
+ case ST_OMP_TILE: case ST_OMP_UNROLL: \
case ST_CRITICAL: \
case ST_OACC_PARALLEL_LOOP: case ST_OACC_PARALLEL: case ST_OACC_KERNELS: \
case ST_OACC_DATA: case ST_OACC_HOST_DATA: case ST_OACC_LOOP: \
case ST_OMP_END_TEAMS_LOOP:
p = "!$OMP END TEAMS LOOP";
break;
+ case ST_OMP_END_TILE:
+ p = "!$OMP END TILE";
+ break;
+ case ST_OMP_END_UNROLL:
+ p = "!$OMP END UNROLL";
+ break;
case ST_OMP_END_WORKSHARE:
p = "!$OMP END WORKSHARE";
break;
case ST_OMP_THREADPRIVATE:
p = "!$OMP THREADPRIVATE";
break;
+ case ST_OMP_TILE:
+ p = "!$OMP TILE";
+ break;
+ case ST_OMP_UNROLL:
+ p = "!$OMP UNROLL";
+ break;
case ST_OMP_WORKSHARE:
p = "!$OMP WORKSHARE";
break;
/* Parse the statements of OpenMP do/parallel do. */
static gfc_statement
-parse_omp_do (gfc_statement omp_st)
+parse_omp_do (gfc_statement omp_st, int nested)
{
gfc_statement st;
gfc_code *cp, *np;
unexpected_eof ();
else if (st == ST_DO)
break;
+ else if (st == ST_OMP_UNROLL || st == ST_OMP_TILE)
+ {
+ st = parse_omp_do (st, nested + 1);
+ if (st == ST_IMPLIED_ENDDO)
+ return st;
+ goto do_end;
+ }
else
unexpected_statement (st);
}
parse_do_block ();
+ for (; nested; --nested)
+ pop_state ();
if (gfc_statement_label != NULL
&& gfc_state_stack->previous != NULL
&& gfc_state_stack->previous->state == COMP_DO
pop_state ();
st = next_statement ();
+do_end:
gfc_statement omp_end_st = ST_OMP_END_DO;
switch (omp_st)
{
case ST_OMP_TEAMS_DISTRIBUTE_SIMD:
omp_end_st = ST_OMP_END_TEAMS_DISTRIBUTE_SIMD;
break;
- case ST_OMP_TEAMS_LOOP:
- omp_end_st = ST_OMP_END_TEAMS_LOOP;
- break;
+ case ST_OMP_TEAMS_LOOP: omp_end_st = ST_OMP_END_TEAMS_LOOP; break;
+ case ST_OMP_TILE: omp_end_st = ST_OMP_END_TILE; break;
+ case ST_OMP_UNROLL: omp_end_st = ST_OMP_END_UNROLL; break;
default: gcc_unreachable ();
}
if (st == omp_end_st)
case ST_OMP_PARALLEL_DO:
case ST_OMP_PARALLEL_DO_SIMD:
- st = parse_omp_do (st);
+ st = parse_omp_do (st, 0);
continue;
case ST_OMP_ATOMIC:
case ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
case ST_OMP_TEAMS_DISTRIBUTE_SIMD:
case ST_OMP_TEAMS_LOOP:
- st = parse_omp_do (st);
+ case ST_OMP_TILE:
+ case ST_OMP_UNROLL:
+ st = parse_omp_do (st, 0);
if (st == ST_IMPLIED_ENDDO)
return st;
continue;
case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
case EXEC_OMP_TEAMS_LOOP:
case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
+ case EXEC_OMP_TILE:
+ case EXEC_OMP_UNROLL:
case EXEC_OMP_WORKSHARE:
break;
case EXEC_OMP_LOOP:
case EXEC_OMP_SIMD:
case EXEC_OMP_TARGET_SIMD:
+ case EXEC_OMP_TILE:
+ case EXEC_OMP_UNROLL:
gfc_resolve_omp_do_blocks (code, ns);
break;
case EXEC_SELECT_TYPE:
case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
case EXEC_OMP_TEAMS_LOOP:
+ case EXEC_OMP_TILE:
+ case EXEC_OMP_UNROLL:
case EXEC_OMP_WORKSHARE:
gfc_resolve_omp_directive (code, ns);
break;
case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
case EXEC_OMP_TEAMS_LOOP:
+ case EXEC_OMP_TILE:
+ case EXEC_OMP_UNROLL:
case EXEC_OMP_WORKSHARE:
gfc_free_omp_clauses (p->ext.omp_clauses);
break;
omp_clauses = gfc_trans_add_clause (c, omp_clauses);
}
+ if (clauses->full)
+ {
+ c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_FULL);
+ omp_clauses = gfc_trans_add_clause (c, omp_clauses);
+ }
+
+ if (clauses->partial)
+ {
+ c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_PARTIAL);
+ OMP_CLAUSE_PARTIAL_EXPR (c)
+ = (clauses->partial > 0
+ ? build_int_cst (integer_type_node, clauses->partial)
+ : NULL_TREE);
+ omp_clauses = gfc_trans_add_clause (c, omp_clauses);
+ }
+
+ if (clauses->sizes_list)
+ {
+ tree list = NULL_TREE;
+ for (gfc_expr_list *el = clauses->sizes_list; el; el = el->next)
+ list = tree_cons (NULL_TREE, gfc_convert_expr_to_tree (block, el->expr),
+ list);
+
+ c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_SIZES);
+ OMP_CLAUSE_SIZES_LIST (c) = nreverse (list);
+ omp_clauses = gfc_trans_add_clause (c, omp_clauses);
+ }
+
if (clauses->ordered)
{
c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_ORDERED);
}
if (clauses->tile_list)
{
- vec<tree, va_gc> *tvec;
- gfc_expr_list *el;
-
- vec_alloc (tvec, 4);
-
- for (el = clauses->tile_list; el; el = el->next)
- vec_safe_push (tvec, gfc_convert_expr_to_tree (block, el->expr));
+ tree list = NULL_TREE;
+ for (gfc_expr_list *el = clauses->tile_list; el; el = el->next)
+ list = tree_cons (NULL_TREE, gfc_convert_expr_to_tree (block, el->expr),
+ list);
c = build_omp_clause (gfc_get_location (&where), OMP_CLAUSE_TILE);
- OMP_CLAUSE_TILE_LIST (c) = build_tree_list_vec (tvec);
+ OMP_CLAUSE_TILE_LIST (c) = nreverse (list);
omp_clauses = gfc_trans_add_clause (c, omp_clauses);
- tvec->truncate (0);
}
if (clauses->vector)
{
return true;
}
+int
+gfc_expr_list_len (gfc_expr_list *list)
+{
+ unsigned len = 0;
+ for (; list; list = list->next)
+ len++;
+
+ return len;
+}
+
static tree
gfc_trans_omp_do (gfc_code *code, gfc_exec_op op, stmtblock_t *pblock,
gfc_omp_clauses *do_clauses, tree par_clauses)
dovar_init *di;
unsigned ix;
vec<tree, va_heap, vl_embed> *saved_doacross_steps = doacross_steps;
- gfc_expr_list *tile = do_clauses ? do_clauses->tile_list : clauses->tile_list;
+ gfc_expr_list *oacc_tile
+ = do_clauses ? do_clauses->tile_list : clauses->tile_list;
+ gfc_expr_list *sizes
+ = do_clauses ? do_clauses->sizes_list : clauses->sizes_list;
gfc_code *orig_code = code;
/* Both collapsed and tiled loops are lowered the same way. In
OpenACC, those clauses are not compatible, so prioritize the tile
clause, if present. */
- if (tile)
- {
- collapse = 0;
- for (gfc_expr_list *el = tile; el; el = el->next)
- collapse++;
- }
+ if (oacc_tile)
+ collapse = gfc_expr_list_len (oacc_tile);
+ else if (sizes)
+ collapse = gfc_expr_list_len (sizes);
doacross_steps = NULL;
if (clauses->orderedc)
collapse = 1;
code = code->block->next;
- gcc_assert (code->op == EXEC_DO);
init = make_tree_vec (collapse);
cond = make_tree_vec (collapse);
int dovar_found = 0;
tree dovar_decl;
+ if (code->op == EXEC_OMP_TILE || code->op == EXEC_OMP_UNROLL)
+ {
+ TREE_VEC_ELT (init, i) = NULL_TREE;
+ TREE_VEC_ELT (cond, i) = NULL_TREE;
+ TREE_VEC_ELT (incr, i) = NULL_TREE;
+ TREE_VEC_ELT (incr, i) = NULL_TREE;
+ if (orig_decls)
+ TREE_VEC_ELT (orig_decls, i) = NULL_TREE;
+ continue;
+ }
+ gcc_assert (code->op == EXEC_DO);
if (clauses)
{
gfc_omp_namelist *n = NULL;
if (code1 != scan)
tmpcode->next = scan;
}
+ else if (code->op == EXEC_OMP_TILE || code->op == EXEC_OMP_UNROLL)
+ tmp = gfc_trans_omp_code (code, true);
else
tmp = gfc_trans_omp_code (code->block->next, true);
gfc_add_expr_to_block (&body, tmp);
case EXEC_OMP_LOOP: stmt = make_node (OMP_LOOP); break;
case EXEC_OMP_TASKLOOP: stmt = make_node (OMP_TASKLOOP); break;
case EXEC_OACC_LOOP: stmt = make_node (OACC_LOOP); break;
+ case EXEC_OMP_TILE: stmt = make_node (OMP_TILE); break;
+ case EXEC_OMP_UNROLL: stmt = make_node (OMP_UNROLL); break;
default: gcc_unreachable ();
}
case EXEC_OMP_LOOP:
case EXEC_OMP_SIMD:
case EXEC_OMP_TASKLOOP:
+ case EXEC_OMP_TILE:
+ case EXEC_OMP_UNROLL:
return gfc_trans_omp_do (code, code->op, NULL, code->ext.omp_clauses,
NULL);
case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
case EXEC_OMP_TEAMS_LOOP:
+ case EXEC_OMP_TILE:
+ case EXEC_OMP_UNROLL:
case EXEC_OMP_WORKSHARE:
res = gfc_trans_omp_directive (code);
break;
case OMP_SIMD:
case OMP_DISTRIBUTE:
case OMP_LOOP:
+ case OMP_TILE:
+ case OMP_UNROLL:
case OACC_LOOP:
case OMP_SCAN:
case OMP_SCOPE:
if (*tp == NULL || is_gimple_constant (*tp))
return;
- *tp = get_initialized_tmp_var (*tp, pre_p, NULL, false);
+ if (TREE_CODE (*tp) == SAVE_EXPR)
+ gimplify_save_expr (tp, pre_p, NULL);
+ else
+ *tp = get_initialized_tmp_var (*tp, pre_p, NULL, false);
/* Reference to pointer conversion is considered useless,
but is significant for firstprivate clause. Force it
here. */
return NULL_TREE;
}
+/* Gimplify standalone loop transforming directive which has the
+ transformations applied already. So, all that is needed is gimplify
+ the remaining loops as normal loops. */
+
+static enum gimplify_status
+gimplify_omp_loop_xform (tree *expr_p, gimple_seq *pre_p)
+{
+ tree for_stmt = *expr_p;
+
+ if (OMP_FOR_PRE_BODY (for_stmt))
+ gimplify_and_add (OMP_FOR_PRE_BODY (for_stmt), pre_p);
+
+ gimple_seq pre_body = NULL, post_body = NULL;
+ for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
+ {
+ if (TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i) == NULL_TREE)
+ continue;
+ tree iters = NULL_TREE;
+ if (i == 0
+ && TREE_CODE (for_stmt) == OMP_UNROLL
+ && !omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_PARTIAL))
+ {
+ if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_FULL))
+ iters = omp_loop_number_of_iterations (for_stmt, 0, NULL);
+ else
+ iters = build_int_cst (integer_type_node, 8);
+ }
+ tree t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
+ gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
+ tree decl = TREE_OPERAND (t, 0);
+ gcc_assert (DECL_P (decl));
+ gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (decl))
+ || POINTER_TYPE_P (TREE_TYPE (decl)));
+ if (DECL_ARTIFICIAL (decl)
+ && TREE_PRIVATE (t)
+ && gimplify_omp_ctxp
+ && gimplify_omp_ctxp->region_type != ORT_NONE)
+ {
+ struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
+ do
+ {
+ splay_tree_node n
+ = splay_tree_lookup (ctx->variables, (splay_tree_key) decl);
+ if (n != NULL)
+ break;
+ else if (ctx->region_type != ORT_WORKSHARE
+ && ctx->region_type != ORT_TASKGROUP
+ && ctx->region_type != ORT_SIMD
+ && ctx->region_type != ORT_ACC
+ && !(ctx->region_type & ORT_TARGET_DATA))
+ {
+ omp_add_variable (ctx, decl, GOVD_PRIVATE);
+ break;
+ }
+ ctx = ctx->outer_context;
+ }
+ while (ctx);
+ }
+ if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC)
+ {
+ gcc_assert (seen_error ());
+ continue;
+ }
+ gimplify_expr (&TREE_OPERAND (t, 1), pre_p, NULL, is_gimple_val,
+ fb_rvalue);
+ gimplify_and_add (t, &pre_body);
+ t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i);
+ gcc_assert (TREE_OPERAND (t, 0) == decl);
+ if (TREE_CODE (TREE_OPERAND (t, 1)) == TREE_VEC)
+ {
+ gcc_assert (seen_error ());
+ continue;
+ }
+ gimplify_expr (&TREE_OPERAND (t, 1), pre_p, NULL, is_gimple_val,
+ fb_rvalue);
+ tree l1 = create_artificial_label (UNKNOWN_LOCATION);
+ tree l2 = create_artificial_label (UNKNOWN_LOCATION);
+ tree l3 = create_artificial_label (UNKNOWN_LOCATION);
+ gimplify_seq_add_stmt (&pre_body, gimple_build_goto (l2));
+ gimplify_seq_add_stmt (&pre_body, gimple_build_label (l1));
+ gimple_seq this_post_body = NULL;
+ t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
+ if (TREE_CODE (t) == MODIFY_EXPR)
+ {
+ t = TREE_OPERAND (t, 1);
+ if (TREE_CODE (t) == PLUS_EXPR
+ && TREE_OPERAND (t, 1) == decl)
+ {
+ TREE_OPERAND (t, 1) = TREE_OPERAND (t, 0);
+ TREE_OPERAND (t, 0) = decl;
+ }
+ gimplify_expr (&TREE_OPERAND (t, 1), pre_p, NULL, is_gimple_val,
+ fb_rvalue);
+ }
+ gimplify_and_add (TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i),
+ &this_post_body);
+ gimplify_seq_add_stmt (&this_post_body, gimple_build_label (l2));
+ t = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i);
+ gcond *cond = NULL;
+ tree d = decl;
+ gimplify_expr (&d, &this_post_body, NULL, is_gimple_val, fb_rvalue);
+ if (iters && tree_fits_uhwi_p (iters))
+ {
+ unsigned HOST_WIDE_INT niters = tree_to_uhwi (iters);
+ if ((unsigned HOST_WIDE_INT) (int) niters == niters
+ && (int) niters > 0)
+ {
+ t = build2 (TREE_CODE (t), boolean_type_node, d,
+ TREE_OPERAND (t, 1));
+ t = build3 (ANNOTATE_EXPR, TREE_TYPE (t), t,
+ build_int_cst (integer_type_node,
+ annot_expr_unroll_kind),
+ build_int_cst (integer_type_node, niters));
+ gimplify_expr (&t, &this_post_body, NULL, is_gimple_val,
+ fb_rvalue);
+ cond = gimple_build_cond (NE_EXPR, t, boolean_false_node,
+ l1, l3);
+ }
+ }
+ if (cond == NULL)
+ cond = gimple_build_cond (TREE_CODE (t), d, TREE_OPERAND (t, 1),
+ l1, l3);
+ gimplify_seq_add_stmt (&this_post_body, cond);
+ gimplify_seq_add_stmt (&this_post_body, gimple_build_label (l3));
+ gimplify_seq_add_seq (&this_post_body, post_body);
+ post_body = this_post_body;
+ }
+ gimplify_seq_add_seq (pre_p, pre_body);
+ gimplify_and_add (OMP_FOR_BODY (for_stmt), pre_p);
+ gimplify_seq_add_seq (pre_p, post_body);
+
+ *expr_p = NULL_TREE;
+ return GS_ALL_DONE;
+}
+
/* Gimplify the gross structure of an OMP_FOR statement. */
static enum gimplify_status
bool loop_p = (omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_BIND)
!= NULL_TREE);
- if (OMP_FOR_INIT (for_stmt) == NULL_TREE)
+ while (OMP_FOR_INIT (for_stmt) == NULL_TREE)
{
tree *data[4] = { NULL, NULL, NULL, NULL };
gcc_assert (TREE_CODE (for_stmt) != OACC_LOOP);
*expr_p = NULL_TREE;
return GS_ERROR;
}
+ gcc_assert (inner_for_stmt == *data[3]);
+ omp_maybe_apply_loop_xforms (data[3],
+ data[2]
+ ? OMP_FOR_CLAUSES (*data[2])
+ : TREE_CODE (for_stmt) == OMP_FOR
+ ? OMP_FOR_CLAUSES (for_stmt)
+ : NULL_TREE);
+ if (inner_for_stmt != *data[3])
+ continue;
if (data[2] && OMP_FOR_PRE_BODY (*data[2]))
{
append_to_statement_list_force (OMP_FOR_PRE_BODY (*data[2]),
OMP_PARALLEL_CLAUSES (*data[1]) = c;
}
}
+ break;
+ }
+ if (OMP_FOR_INIT (for_stmt) != NULL_TREE)
+ {
+ omp_maybe_apply_loop_xforms (expr_p, NULL_TREE);
+ if (*expr_p != for_stmt)
+ return GS_OK;
}
switch (TREE_CODE (for_stmt))
case OMP_SIMD:
ort = ORT_SIMD;
break;
+ case OMP_TILE:
+ case OMP_UNROLL:
+ gcc_assert (inner_for_stmt == NULL_TREE);
+ return gimplify_omp_loop_xform (expr_p, pre_p);
default:
gcc_unreachable ();
}
enum omp_clause_bind_kind kind = OMP_CLAUSE_BIND_THREAD;
int i;
+ omp_maybe_apply_loop_xforms (expr_p, NULL_TREE);
+ if (*expr_p != for_stmt)
+ return GS_OK;
+
/* If order is not present, the behavior is as if order(concurrent)
appeared. */
tree order = omp_find_clause (clauses, OMP_CLAUSE_ORDER);
case OMP_FOR:
case OMP_DISTRIBUTE:
case OMP_TASKLOOP:
+ case OMP_TILE:
+ case OMP_UNROLL:
case OACC_LOOP:
ret = gimplify_omp_for (expr_p, pre_p);
break;
case LE_EXPR:
if (POINTER_TYPE_P (TREE_TYPE (*n2)))
- *n2 = fold_build_pointer_plus_hwi_loc (loc, *n2, 1);
+ {
+ tree unit = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (v)));
+ gcc_assert (TREE_CODE (unit) == INTEGER_CST);
+ *n2 = fold_build_pointer_plus_loc (loc, *n2, unit);
+ }
else
*n2 = fold_build2_loc (loc, PLUS_EXPR, TREE_TYPE (*n2), *n2,
build_int_cst (TREE_TYPE (*n2), 1));
break;
case GE_EXPR:
if (POINTER_TYPE_P (TREE_TYPE (*n2)))
- *n2 = fold_build_pointer_plus_hwi_loc (loc, *n2, -1);
+ {
+ tree unit = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (v)));
+ gcc_assert (TREE_CODE (unit) == INTEGER_CST);
+ unit = convert_to_ptrofftype_loc (loc, unit);
+ unit = fold_build1_loc (loc, NEGATE_EXPR, TREE_TYPE (unit),
+ unit);
+ *n2 = fold_build_pointer_plus_loc (loc, *n2, unit);
+ }
else
*n2 = fold_build2_loc (loc, MINUS_EXPR, TREE_TYPE (*n2), *n2,
build_int_cst (TREE_TYPE (*n2), 1));
fputs ("\n", stderr);
}
+/* Return number of iterations of loop I in FOR_STMT. If PSTEP is non-NULL,
+ *PSTEP will be the loop step. */
+
+tree
+omp_loop_number_of_iterations (tree for_stmt, int i, tree *pstep)
+{
+ tree t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
+ gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
+ tree decl = TREE_OPERAND (t, 0);
+ tree n1 = TREE_OPERAND (t, 1);
+ tree type = TREE_TYPE (decl);
+ tree cond = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i);
+ gcc_assert (COMPARISON_CLASS_P (cond));
+ gcc_assert (TREE_OPERAND (cond, 0) == decl);
+ tree_code cond_code = TREE_CODE (cond);
+ tree n2 = TREE_OPERAND (cond, 1);
+ t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
+ tree step = NULL_TREE;
+ switch (TREE_CODE (t))
+ {
+ case PREINCREMENT_EXPR:
+ case POSTINCREMENT_EXPR:
+ gcc_assert (!POINTER_TYPE_P (type));
+ gcc_assert (TREE_OPERAND (t, 0) == decl);
+ step = build_int_cst (type, 1);
+ break;
+ case PREDECREMENT_EXPR:
+ case POSTDECREMENT_EXPR:
+ gcc_assert (!POINTER_TYPE_P (type));
+ gcc_assert (TREE_OPERAND (t, 0) == decl);
+ step = build_int_cst (type, -1);
+ break;
+ case MODIFY_EXPR:
+ gcc_assert (TREE_OPERAND (t, 0) == decl);
+ t = TREE_OPERAND (t, 1);
+ switch (TREE_CODE (t))
+ {
+ case PLUS_EXPR:
+ if (TREE_OPERAND (t, 1) == decl)
+ {
+ TREE_OPERAND (t, 1) = TREE_OPERAND (t, 0);
+ TREE_OPERAND (t, 0) = decl;
+ }
+ /* FALLTHRU */
+ case POINTER_PLUS_EXPR:
+ case MINUS_EXPR:
+ step = omp_get_for_step_from_incr (EXPR_LOCATION (t), t);
+ break;
+ default:
+ gcc_unreachable ();
+ }
+ break;
+ default:
+ gcc_unreachable ();
+ }
+ omp_adjust_for_condition (EXPR_LOCATION (for_stmt), &cond_code, &n2,
+ decl, step);
+ if (pstep)
+ *pstep = step;
+ if (INTEGRAL_TYPE_P (type)
+ && TYPE_PRECISION (type) < TYPE_PRECISION (long_long_integer_type_node))
+ {
+ n1 = fold_convert (long_long_integer_type_node, n1);
+ n2 = fold_convert (long_long_integer_type_node, n2);
+ step = fold_convert (long_long_integer_type_node, step);
+ }
+ if (cond_code == LT_EXPR
+ || POINTER_TYPE_P (type)
+ || !TYPE_UNSIGNED (TREE_TYPE (n1)))
+ {
+ if (POINTER_TYPE_P (type))
+ t = fold_build2 (POINTER_DIFF_EXPR, ssizetype, n2, n1);
+ else
+ t = fold_build2 (MINUS_EXPR, TREE_TYPE (n1), n2, n1);
+ t = fold_build2 (CEIL_DIV_EXPR, TREE_TYPE (t), t, step);
+ }
+ else
+ {
+ t = fold_build2 (MINUS_EXPR, type, n1, n2);
+ t = fold_build2 (CEIL_DIV_EXPR, type, t,
+ fold_build1 (NEGATE_EXPR, type, step));
+ }
+ return t;
+}
+
+/* Tile transformation:
+ Original loop:
+
+ #pragma omp tile sizes(16, 32)
+ for (i = 0; i < k; ++i)
+ for (j = 0; j < 128; j += 2)
+ {
+ baz (i, j);
+ }
+
+ Transformed loop:
+ #pragma omp tile sizes(16, 32)
+ for (i.0 = 0; i.0 < k; i.0 += 16)
+ for (j.0 = 0; j.0 < 128; j.0 += 64)
+ {
+ i = i.0;
+ i.1 = MIN_EXPR <i.0 + 16, k>;
+ goto <D.2783>;
+ <D.2782>:;
+ j = j.0;
+ j.1 = j.0 + 32;
+ goto <D.2786>;
+ <D.2785>:;
+ {
+ baz (i, j);
+ }
+ j += 2;
+ <D.2786>:;
+ if (j < j.1) goto <D.2785>; else goto <D.2787>;
+ <D.2787>:;
+ ++i;
+ <D.2783>:;
+ if (i < i.1) goto <D.2782>; else goto <D.2784>;
+ <D.2784>:;
+ }
+
+ where the grid loops have canonical form, but the inner
+ loops don't and so are immediately lowered. */
+
+static void
+omp_apply_tile (tree for_stmt, tree sizes, int size)
+{
+ tree pre_body = NULL_TREE, post_body = NULL_TREE;
+ tree orig_sizes = sizes;
+ if (OMP_FOR_NON_RECTANGULAR (for_stmt))
+ {
+ error_at (EXPR_LOCATION (for_stmt), "non-rectangular %<tile%>");
+ return;
+ }
+ for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
+ {
+ if (orig_sizes)
+ {
+ size = tree_to_uhwi (TREE_VALUE (sizes));
+ sizes = TREE_CHAIN (sizes);
+ }
+ if (size == 1)
+ continue;
+ if (OMP_FOR_ORIG_DECLS (for_stmt) == NULL_TREE)
+ {
+ OMP_FOR_ORIG_DECLS (for_stmt)
+ = make_tree_vec (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)));
+ for (int j = 0; j < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); j++)
+ {
+ gcc_assert (TREE_CODE (TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), j))
+ == MODIFY_EXPR);
+ TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), j)
+ = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), j), 0);
+ }
+ }
+ tree step;
+ tree iters = omp_loop_number_of_iterations (for_stmt, i, &step);
+ tree t = TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i);
+ tree decl = TREE_OPERAND (t, 0);
+ tree type = TREE_TYPE (decl);
+ tree griddecl = create_tmp_var_raw (type);
+ DECL_CONTEXT (griddecl) = current_function_decl;
+ t = build1 (DECL_EXPR, void_type_node, griddecl);
+ append_to_statement_list (t, &OMP_FOR_PRE_BODY (for_stmt));
+ TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i), 0) = griddecl;
+ TREE_PRIVATE (TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i)) = 1;
+ tree cond = TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i);
+ TREE_OPERAND (cond, 0) = griddecl;
+ tree ub = save_expr (TREE_OPERAND (cond, 1));
+ TREE_OPERAND (cond, 1) = ub;
+ t = TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i);
+ if (TREE_CODE (cond) == NE_EXPR)
+ {
+ tree_code cond_code = TREE_CODE (cond);
+ omp_adjust_for_condition (EXPR_LOCATION (for_stmt), &cond_code,
+ &ub, griddecl, step);
+ TREE_SET_CODE (cond, cond_code);
+ }
+ step = save_expr (step);
+ tree gridstep = fold_build2 (MULT_EXPR, TREE_TYPE (step),
+ step, build_int_cst (TREE_TYPE (step),
+ size));
+ if (POINTER_TYPE_P (type))
+ t = build2 (POINTER_PLUS_EXPR, type, griddecl,
+ fold_convert (sizetype, gridstep));
+ else
+ t = build2 (PLUS_EXPR, type, griddecl, gridstep);
+ t = build2 (MODIFY_EXPR, type, griddecl, t);
+ TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i) = t;
+ t = build2 (MODIFY_EXPR, type, decl, griddecl);
+ append_to_statement_list (t, &pre_body);
+ if (POINTER_TYPE_P (type))
+ t = build2 (POINTER_PLUS_EXPR, type, griddecl,
+ fold_convert (sizetype, gridstep));
+ else
+ t = build2 (PLUS_EXPR, type, griddecl, gridstep);
+ bool minmax_needed = true;
+ if (TREE_CODE (iters) == INTEGER_CST)
+ {
+ wide_int witers = wi::to_wide (iters);
+ wide_int wsize = wide_int::from (size, witers.get_precision (),
+ TYPE_SIGN (TREE_TYPE (iters)));
+ if (wi::multiple_of_p (witers, wsize, TYPE_SIGN (TREE_TYPE (iters))))
+ minmax_needed = false;
+ }
+ if (minmax_needed)
+ switch (TREE_CODE (cond))
+ {
+ case LE_EXPR:
+ if (POINTER_TYPE_P (type))
+ t = build2 (MIN_EXPR, type, t,
+ build2 (POINTER_PLUS_EXPR, type, ub, size_int (1)));
+ else
+ t = build2 (MIN_EXPR, type, t,
+ build2 (PLUS_EXPR, type, ub, build_one_cst (type)));
+ break;
+ case LT_EXPR:
+ t = build2 (MIN_EXPR, type, t, ub);
+ break;
+ case GE_EXPR:
+ if (POINTER_TYPE_P (type))
+ t = build2 (MAX_EXPR, type, t,
+ build2 (POINTER_PLUS_EXPR, type, ub, size_int (-1)));
+ else
+ t = build2 (MAX_EXPR, type, t,
+ build2 (PLUS_EXPR, type, ub,
+ build_minus_one_cst (type)));
+ break;
+ case GT_EXPR:
+ t = build2 (MAX_EXPR, type, t, ub);
+ break;
+ default:
+ gcc_unreachable ();
+ }
+ tree end = create_tmp_var_raw (type);
+ DECL_CONTEXT (end) = current_function_decl;
+ end = build4 (TARGET_EXPR, type, end, t, NULL_TREE, NULL_TREE);
+ TREE_SIDE_EFFECTS (end) = 1;
+ append_to_statement_list (end, &pre_body);
+ tree lab1 = create_artificial_label (UNKNOWN_LOCATION);
+ tree lab2 = create_artificial_label (UNKNOWN_LOCATION);
+ t = build1 (GOTO_EXPR, void_type_node, lab2);
+ append_to_statement_list (t, &pre_body);
+ t = build1 (LABEL_EXPR, void_type_node, lab1);
+ append_to_statement_list (t, &pre_body);
+ tree this_post_body = NULL_TREE;
+ if (POINTER_TYPE_P (type))
+ t = build2 (POINTER_PLUS_EXPR, type, decl,
+ fold_convert (sizetype, step));
+ else
+ t = build2 (PLUS_EXPR, type, decl, step);
+ t = build2 (MODIFY_EXPR, type, decl, t);
+ append_to_statement_list (t, &this_post_body);
+ t = build1 (LABEL_EXPR, void_type_node, lab2);
+ append_to_statement_list (t, &this_post_body);
+ t = build2 ((TREE_CODE (cond) == LT_EXPR || TREE_CODE (cond) == LE_EXPR)
+ ? LT_EXPR : GT_EXPR, boolean_type_node, decl, end);
+ if (orig_sizes == NULL_TREE)
+ {
+ gcc_assert (i == 0);
+ t = build3 (ANNOTATE_EXPR, TREE_TYPE (t), t,
+ build_int_cst (integer_type_node,
+ annot_expr_unroll_kind),
+ build_int_cst (integer_type_node, size));
+ }
+ t = build3 (COND_EXPR, void_type_node, t,
+ build1 (GOTO_EXPR, void_type_node, lab1), NULL_TREE);
+ append_to_statement_list (t, &this_post_body);
+ append_to_statement_list (post_body, &this_post_body);
+ post_body = this_post_body;
+ }
+ if (pre_body || post_body)
+ {
+ append_to_statement_list (OMP_FOR_BODY (for_stmt), &pre_body);
+ append_to_statement_list (post_body, &pre_body);
+ OMP_FOR_BODY (for_stmt) = pre_body;
+ }
+}
+
+/* Callback for walk_tree to find nested loop transforming construct. */
+
+static tree
+find_nested_loop_xform (tree *tp, int *walk_subtrees, void *data)
+{
+ tree **pdata = (tree **) data;
+ *walk_subtrees = 0;
+ switch (TREE_CODE (*tp))
+ {
+ case OMP_TILE:
+ case OMP_UNROLL:
+ pdata[1] = tp;
+ return *tp;
+ case BIND_EXPR:
+ if (BIND_EXPR_VARS (*tp)
+ || (BIND_EXPR_BLOCK (*tp)
+ && BLOCK_VARS (BIND_EXPR_BLOCK (*tp))))
+ pdata[0] = tp;
+ *walk_subtrees = 1;
+ break;
+ case STATEMENT_LIST:
+ if (!tsi_one_before_end_p (tsi_start (*tp)))
+ pdata[0] = tp;
+ *walk_subtrees = 1;
+ break;
+ case TRY_FINALLY_EXPR:
+ pdata[0] = tp;
+ *walk_subtrees = 1;
+ break;
+ default:
+ break;
+ }
+ return NULL;
+}
+
+/* Main entry point for performing OpenMP loop transformations. */
+
+void
+omp_maybe_apply_loop_xforms (tree *expr_p, tree for_clauses)
+{
+ tree for_stmt = *expr_p;
+
+ switch (TREE_CODE (for_stmt))
+ {
+ case OMP_TILE:
+ case OMP_UNROLL:
+ if (OMP_LOOPXFORM_LOWERED (for_stmt))
+ return;
+ break;
+ default:
+ break;
+ }
+
+ tree *inner_expr_p = expr_p;
+ tree inner_for_stmt = for_stmt;
+ for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)); i++)
+ {
+ /* If some loop nest needs one or more loops in canonical form
+ from nested loop transforming constructs, first perform the
+ loop transformation on the nested construct and then move over
+ the corresponding loops in canonical form from the inner construct
+ to the outer one. */
+ if (TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i) == NULL_TREE)
+ {
+ if (inner_for_stmt == for_stmt
+ && omp_find_clause (for_clauses ? for_clauses
+ : OMP_FOR_CLAUSES (for_stmt),
+ OMP_CLAUSE_ORDERED))
+ {
+ error_at (EXPR_LOCATION (for_stmt),
+ "%<ordered%> clause used with generated loops");
+ *expr_p = void_node;
+ return;
+ }
+ tree *data[2] = { NULL, NULL };
+ walk_tree (&OMP_FOR_BODY (inner_for_stmt),
+ find_nested_loop_xform, &data, NULL);
+ gcc_assert (data[1]);
+ if (data[0])
+ {
+ /* If there is a BIND_EXPR declaring some vars, or statement
+ list with more than one stmt etc., move the intervening
+ code around the outermost loop. */
+ tree t = *inner_expr_p;
+ *inner_expr_p = OMP_FOR_BODY (inner_for_stmt);
+ OMP_FOR_BODY (inner_for_stmt) = *data[1];
+ *data[1] = t;
+ inner_expr_p = data[1];
+ data[1] = &OMP_FOR_BODY (inner_for_stmt);
+ }
+ inner_for_stmt = *data[1];
+
+ omp_maybe_apply_loop_xforms (data[1], NULL_TREE);
+ if (*data[1] != inner_for_stmt)
+ {
+ tree *data2[2] = { NULL, NULL };
+ walk_tree (data[1], find_nested_loop_xform, &data2, NULL);
+ gcc_assert (data2[1]
+ && *data2[1] == inner_for_stmt
+ && data2[0]);
+ tree t = *inner_expr_p;
+ *inner_expr_p = *data[1];
+ *data[1] = *data2[1];
+ *data2[1] = t;
+ inner_expr_p = data2[1];
+ }
+ tree clauses = OMP_FOR_CLAUSES (inner_for_stmt);
+ gcc_checking_assert (TREE_CODE (inner_for_stmt) != OMP_UNROLL
+ || omp_find_clause (clauses,
+ OMP_CLAUSE_PARTIAL));
+ append_to_statement_list (OMP_FOR_PRE_BODY (inner_for_stmt),
+ &OMP_FOR_PRE_BODY (for_stmt));
+ OMP_FOR_PRE_BODY (inner_for_stmt) = NULL_TREE;
+ if (OMP_FOR_ORIG_DECLS (for_stmt) == NULL_TREE
+ && OMP_FOR_ORIG_DECLS (inner_for_stmt) != NULL_TREE)
+ {
+ OMP_FOR_ORIG_DECLS (for_stmt)
+ = make_tree_vec (TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)));
+ for (int j = 0; j < TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt));
+ j++)
+ {
+ if (TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), j) == NULL_TREE)
+ continue;
+ gcc_assert (TREE_CODE (TREE_VEC_ELT (OMP_FOR_INIT (for_stmt),
+ j)) == MODIFY_EXPR);
+ TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), j)
+ = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), j),
+ 0);
+ }
+ }
+ for (int j = 0; j < TREE_VEC_LENGTH (OMP_FOR_INIT (inner_for_stmt));
+ ++j)
+ {
+ if (i + j == TREE_VEC_LENGTH (OMP_FOR_INIT (for_stmt)))
+ break;
+ if (OMP_FOR_ORIG_DECLS (for_stmt))
+ {
+ if (OMP_FOR_ORIG_DECLS (inner_for_stmt))
+ {
+ TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i + j)
+ = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt),
+ j);
+ TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner_for_stmt), j)
+ = NULL_TREE;
+ }
+ else
+ {
+ tree t = TREE_VEC_ELT (OMP_FOR_INIT (inner_for_stmt), j);
+ gcc_assert (TREE_CODE (t) == MODIFY_EXPR);
+ TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i + j)
+ = TREE_OPERAND (t, 0);
+ }
+ }
+ TREE_VEC_ELT (OMP_FOR_INIT (for_stmt), i + j)
+ = TREE_VEC_ELT (OMP_FOR_INIT (inner_for_stmt), j);
+ TREE_VEC_ELT (OMP_FOR_COND (for_stmt), i + j)
+ = TREE_VEC_ELT (OMP_FOR_COND (inner_for_stmt), j);
+ TREE_VEC_ELT (OMP_FOR_INCR (for_stmt), i + j)
+ = TREE_VEC_ELT (OMP_FOR_INCR (inner_for_stmt), j);
+ TREE_VEC_ELT (OMP_FOR_INIT (inner_for_stmt), j) = NULL_TREE;
+ TREE_VEC_ELT (OMP_FOR_COND (inner_for_stmt), j) = NULL_TREE;
+ TREE_VEC_ELT (OMP_FOR_INCR (inner_for_stmt), j) = NULL_TREE;
+ }
+ }
+ }
+
+ switch (TREE_CODE (for_stmt))
+ {
+ case OMP_TILE:
+ tree sizes;
+ sizes = omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_SIZES);
+ omp_apply_tile (for_stmt, OMP_CLAUSE_SIZES_LIST (sizes), 0);
+ OMP_LOOPXFORM_LOWERED (for_stmt) = 1;
+ break;
+ case OMP_UNROLL:
+ tree partial;
+ partial = omp_find_clause (OMP_FOR_CLAUSES (for_stmt),
+ OMP_CLAUSE_PARTIAL);
+ if (partial)
+ omp_apply_tile (for_stmt, NULL_TREE,
+ OMP_CLAUSE_PARTIAL_EXPR (partial)
+ ? tree_to_shwi (OMP_CLAUSE_PARTIAL_EXPR (partial))
+ : 8);
+ else if (omp_find_clause (OMP_FOR_CLAUSES (for_stmt), OMP_CLAUSE_FULL))
+ {
+ tree iters = omp_loop_number_of_iterations (for_stmt, 0, NULL);
+ if (TREE_CODE (iters) != INTEGER_CST)
+ error_at (EXPR_LOCATION (for_stmt),
+ "non-constant iteration count of %<unroll full%> loop");
+ }
+ OMP_LOOPXFORM_LOWERED (for_stmt) = 1;
+ break;
+ default:
+ break;
+ }
+}
#include "gt-omp-general.h"
extern bool omp_parse_expr (vec<omp_addr_token *> &, tree);
+extern tree omp_loop_number_of_iterations (tree, int, tree * = NULL);
+extern void omp_maybe_apply_loop_xforms (tree *, tree);
+
#endif /* GCC_OMP_GENERAL_H */
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+extern void dummy (int);
+
+void
+test (void)
+{
+ [[omp::directive (tile sizes(1))]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (tile sizes(1)),
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (tile sizes(1, 2)),
+ directive (tile sizes(1, 2)))]]
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (tile sizes(5, 6)),
+ directive (tile sizes(1, 2, 3)))]]
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ for (int k = 0; k < 100; ++k)
+ dummy (i);
+
+ [[omp::sequence (directive (tile sizes(1)),
+ directive (unroll partial),
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::directive (tile sizes(1, 2))]]
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::directive (tile sizes(1))]]
+ for (int i = 0; i < 100; ++i)
+ {
+ dummy (i);
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+ }
+
+ [[omp::directive (tile sizes(1))]]
+ for (int i = 0; i < 100; ++i)
+ {
+ for (int j = 0; j < 100; ++j)
+ dummy (j);
+ dummy (i);
+ }
+}
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+extern void dummy (int);
+
+void
+test (void)
+{
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1)),
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1, 2)),
+ directive (tile sizes(1, 2)))]]
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(5, 6)),
+ directive (tile sizes(1, 2, 3)))]]
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ for (int k = 0; k < 100; ++k)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1)),
+ directive (unroll partial),
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1, 2)))]]
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ {
+ dummy (i);
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+ }
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ {
+ for (int j = 0; j < 100; ++j)
+ dummy (j);
+ dummy (i);
+ }
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+}
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+extern void dummy (int);
+
+void
+test (void)
+{
+ [[omp::sequence (directive (for collapse(1)),
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(2)),
+ directive (tile sizes(1, 2)))]]
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(1)),
+ directive (tile sizes(1)),
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(1)),
+ directive (tile sizes(1)),
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(2)),
+ directive (tile sizes(1, 2)),
+ directive (tile sizes(1, 2)))]]
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(2)),
+ directive (tile sizes(5, 6)),
+ directive (tile sizes(1, 2, 3)))]]
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ for (int k = 0; k < 100; ++k)
+ dummy (i);
+}
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+extern void dummy (int);
+
+void
+test (void)
+{
+ [[omp::directive (tile sizes(0))]] /* { dg-error "'sizes' argument needs positive integral constant" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::directive (tile sizes(-1))]] /* { dg-error "'sizes' argument needs positive integral constant" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::directive (tile sizes())]] /* { dg-error "expected expression before" "" { target c } } */
+ for (int i = 0; i < 100; ++i) /* { dg-error "expected primary-expression before" "" { target c++ } .-1 } */
+ dummy (i);
+
+ [[omp::directive (tile sizes)]] /* { dg-error "expected '\\\(' before end of line" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::directive (tile sizes(1) sizes(1))]] /* { dg-error "expected end of line before 'sizes'" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::directive (tile, sizes(1), sizes(1))]] /* { dg-error "expected end of line before ','" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (tile sizes(1, 2)),
+ directive (tile sizes(1)))]] /* { dg-error "'tile' construct generates 1 loops with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (tile sizes(1)),
+ directive (unroll partia), /* { dg-error "expected an OpenMP clause before 'partia'" } */
+ directive (tile sizes(1)))]] /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" "" { target *-*-* } .-1 } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (tile sizes(1)),
+ directive (unroll))]] /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (tile sizes(1)),
+ directive (unroll full))]] /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (tile sizes(8,8)),
+ directive (unroll partial), /* { dg-error "'unroll' construct with 'partial' clause generates just one loop with canonical form but 2 loops are needed" } */
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (tile sizes(8,8)),
+ directive (unroll partial))]] /* { dg-error "'unroll' construct with 'partial' clause generates just one loop with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::directive (tile sizes(1, 2))]] /* { dg-error "non-rectangular 'tile'" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = i; j < 100; ++j)
+ dummy (i);
+
+ [[omp::directive (tile sizes(1, 2))]] /* { dg-error "non-rectangular 'tile'" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 2; j < i; ++j)
+ dummy (i);
+
+ [[omp::directive (tile sizes(1, 2, 3))]]
+ for (int i = 0; i < 100; ++i) /* { dg-error "not enough nested loops" } */
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::directive (tile sizes(1, 2))]]
+ for (int i = 0; i < 100; ++i) /* { dg-error "inner loops must be perfectly nested" } */
+ {
+ dummy (i);
+ for (int j = 0; j < 100; ++j)
+ dummy (j);
+ }
+
+ [[omp::directive (tile sizes(1, 2))]]
+ for (int i = 0; i < 100; ++i) /* { dg-error "inner loops must be perfectly nested" } */
+ {
+ for (int j = 0; j < 100; ++j)
+ dummy (j);
+ dummy (i);
+ }
+
+ int s;
+ [[omp::directive (tile sizes(s))]] /* { dg-error "'sizes' argument needs positive integral constant" "" { target { ! c++98_only } } } */
+ /* { dg-error "the value of 's' is not usable in a constant expression" "" { target { c++ && { ! c++98_only } } } .-1 } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::directive (tile sizes(42.0))]] /* { dg-error "'sizes' argument needs positive integral constant" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+}
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+extern void dummy (int);
+
+void
+test (void)
+{
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(0)))]] /* { dg-error "'sizes' argument needs positive integral constant" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(-1)))]] /* { dg-error "'sizes' argument needs positive integral constant" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for), /* { dg-error "expected primary-expression before" "" { target c++ } .+1 } */
+ directive (tile sizes()))]] /* { dg-error "expected expression before" "" { target c } } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for), /* { dg-error "expected primary-expression before" "" { target c++ } .+1 } */
+ directive (tile sizes(,)))]] /* { dg-error "expected expression before" "" { target c } } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes))]] /* { dg-error "expected '\\\(' before end of line" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1) sizes(1)))]] /* { dg-error "expected end of line before 'sizes'" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1, 2)),
+ directive (tile sizes(1)))]] /* { dg-error "'tile' construct generates 1 loops with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1)),
+ directive (unroll partia), /* { dg-error "expected an OpenMP clause before 'partia'" } */
+ directive (tile sizes(1)))]] /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" "" { target *-*-* } .-1 } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1)),
+ directive (unroll))]] /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1)),
+ directive (unroll full))]] /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(8,8)),
+ directive (unroll partial), /* { dg-error "'unroll' construct with 'partial' clause generates just one loop with canonical form but 2 loops are needed" } */
+ directive (tile sizes(1)))]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(8,8)),
+ directive (unroll partial))]] /* { dg-error "'unroll' construct with 'partial' clause generates just one loop with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1, 2)))]] /* { dg-error "non-rectangular 'tile'" "" { target c } } */
+ for (int i = 0; i < 100; ++i) /* { dg-error "non-rectangular 'tile'" "" { target c++ } } */
+ for (int j = i; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1, 2)))]] /* { dg-error "non-rectangular 'tile'" "" { target c } } */
+ for (int i = 0; i < 100; ++i) /* { dg-error "non-rectangular 'tile'" "" { target c++ } } */
+ for (int j = 2; j < i; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1, 2, 3)))]]
+ for (int i = 0; i < 100; ++i) /* { dg-error "not enough nested loops" } */
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1, 2)))]]
+ for (int i = 0; i < 100; ++i) /* { dg-error "inner loops must be perfectly nested" } */
+ {
+ dummy (i);
+ for (int j = 0; j < 100; ++j)
+ dummy (j);
+ }
+
+ [[omp::sequence (directive (parallel for),
+ directive (tile sizes(1, 2)))]]
+ for (int i = 0; i < 100; ++i) /* { dg-error "inner loops must be perfectly nested" } */
+ {
+ for (int j = 0; j < 100; ++j)
+ dummy (j);
+ dummy (i);
+ }
+}
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+extern void dummy (int);
+
+void
+test (void)
+{
+ [[omp::sequence (directive (for),
+ directive (tile sizes(1, 2)))]] /* { dg-error "non-rectangular 'tile'" "" { target c } } */
+ for (int i = 0; i < 100; ++i) /* { dg-error "non-rectangular 'tile'" "" { target c++ } } */
+ for (int j = i; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (for),
+ directive (tile sizes(1, 2)))]] /* { dg-error "non-rectangular 'tile'" "" { target c } } */
+ for (int i = 0; i < 100; ++i) /* { dg-error "non-rectangular 'tile'" "" { target c++ } } */
+ for (int j = 0; j < i; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(2)),
+ directive (tile sizes(1)))]] /* { dg-error "'tile' construct generates 1 loops with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(3)),
+ directive (tile sizes(1, 2)))]] /* { dg-error "'tile' construct generates 2 loops with canonical form but 3 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(2)),
+ directive (tile sizes(1, 2)),
+ directive (tile sizes(1)))]] /* { dg-error "'tile' construct generates 1 loops with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(2)),
+ directive (tile sizes(1, 2)),
+ directive (tile sizes(1, 2)))]]
+ for (int i = 0; i < 100; ++i) /* { dg-error "not enough nested loops" } */
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(2)),
+ directive (tile sizes(5, 6)),
+ directive (tile sizes(1, 2, 3)))]]
+ for (int i = 0; i < 100; ++i) /* { dg-error "not enough nested loops" } */
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(2)),
+ directive (tile sizes(1, 2)),
+ directive (tile sizes(1)))]] /* { dg-error "'tile' construct generates 1 loops with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(3)),
+ directive (tile sizes(1, 2)), /* { dg-error "'tile' construct generates 2 loops with canonical form but 3 loops are needed" } */
+ directive (tile sizes(1, 2)))]]
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ [[omp::sequence (directive (for collapse(3)),
+ directive (tile sizes(5, 6)), /* { dg-error "'tile' construct generates 2 loops with canonical form but 3 loops are needed" } */
+ directive (tile sizes(1, 2, 3)))]]
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ for (int k = 0; k < 100; ++k)
+ dummy (i);
+}
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+extern void dummy (int);
+
+void
+test1 (void)
+{
+ [[omp::directive (unroll partial)]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+}
+
+void
+test2 (void)
+{
+ [[omp::directive (unroll partial(10))]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+}
+
+void
+test3 (void)
+{
+ [[omp::directive (unroll full)]]
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+}
+
+void
+test4 (void)
+{
+ [[omp::directive (unroll full)]]
+ for (int i = 0; i > 100; ++i)
+ dummy (i);
+}
+
+void
+test5 (void)
+{
+ [[omp::directive (unroll full)]]
+ for (int i = 1; i <= 100; ++i)
+ dummy (i);
+}
+
+void
+test6 (void)
+{
+ [[omp::directive (unroll full)]]
+ for (int i = 200; i >= 100; i--)
+ dummy (i);
+}
+
+void
+test7 (void)
+{
+ [[omp::directive (unroll full)]]
+ for (int i = -100; i > 100; ++i)
+ dummy (i);
+}
+
+void
+test8 (void)
+{
+ [[omp::directive (unroll full)]]
+ for (int i = 100; i > -200; --i)
+ dummy (i);
+}
+
+void
+test9 (void)
+{
+ [[omp::directive (unroll full)]]
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+}
+
+void
+test10 (void)
+{
+ [[omp::directive (unroll full)]]
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+}
+
+void
+test12 (void)
+{
+ [[omp::sequence (directive (unroll full),
+ directive (unroll partial),
+ directive (unroll partial))]]
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+}
+
+void
+test13 (void)
+{
+ for (int i = 0; i < 100; ++i)
+ [[omp::sequence (directive (unroll full),
+ directive (unroll partial),
+ directive (unroll partial))]]
+ for (int j = -300; j != 100; ++j)
+ dummy (i);
+}
+
+void
+test14 (void)
+{
+ [[omp::directive (for)]]
+ for (int i = 0; i < 100; ++i)
+ [[omp::sequence (directive (unroll full),
+ directive (unroll partial),
+ directive (unroll partial))]]
+ for (int j = -300; j != 100; ++j)
+ dummy (i);
+}
+
+void
+test15 (void)
+{
+ [[omp::directive (for)]]
+ for (int i = 0; i < 100; ++i)
+ {
+ dummy (i);
+
+ [[omp::sequence (directive (unroll full),
+ directive (unroll partial),
+ directive (unroll partial))]]
+ for (int j = -300; j != 100; ++j)
+ dummy (j);
+
+ dummy (i);
+ }
+ }
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+/* { dg-prune-output "error: invalid controlling predicate" } */
+
+extern void dummy (int);
+
+void
+test (void)
+{
+ [[omp::sequence (directive (unroll partial),
+ directive (unroll full))]] /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (for),
+ directive (unroll full), /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ directive (unroll partial))]]
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (for),
+ directive (unroll full),
+ directive (unroll full))]] /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (for),
+ directive (unroll partial partial))]] /* { dg-error "too many 'partial' clauses" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ [[omp::directive (unroll full full)]] /* { dg-error "too many 'full' clauses" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (unroll partial),
+ directive (unroll))]] /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (for),
+ directive (unroll))]] /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ int i;
+
+ [[omp::sequence (directive (for), /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" "" { target *-*-* } .+1 } */
+ directive (unroll foo))]] /* { dg-error "expected an OpenMP clause before 'foo'" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ [[omp::directive (unroll partial(i))]]
+ /* { dg-error "the value of 'i' is not usable in a constant expression" "" { target c++ } .-1 } */
+ /* { dg-error "'partial' argument needs positive constant integer expression" "" { target *-*-* } .-2 } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ [[omp::directive (unroll parti)]] /* { dg-error "expected an OpenMP clause before 'parti'" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (for),
+ directive (unroll partial(1)), /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" "" { target *-*-* } .+1 } */
+ directive (unroll parti))]] /* { dg-error "expected an OpenMP clause before 'parti'" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ [[omp::sequence (directive (for),
+ directive (unroll partial(1)), /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" "" { target *-*-* } .+1 } */
+ directive (unroll parti))]] /* { dg-error "expected an OpenMP clause before 'parti'" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ int sum = 0;
+ [[omp::sequence (directive (parallel for reduction(+ : sum) collapse(2)),
+ directive (unroll partial(1)))]] /* { dg-error "'unroll' construct with 'partial' clause generates just one loop with canonical form but 2 loops are needed" } */
+ for (int i = 3; i < 10; ++i)
+ for (int j = -2; j < 7; ++j)
+ sum++;
+}
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+/* { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple -fdump-tree-cunroll" } */
+
+extern void dummy (int);
+
+void
+test1 (void)
+{
+ [[omp::directive (unroll full)]]
+ for (int i = 0; i < 10; i++)
+ dummy (i);
+}
+
+/* Loop should be removed with 10 copies of the body remaining */
+/* { dg-final { scan-tree-dump-times "dummy" 10 "cunroll" } } */
+/* { dg-final { scan-tree-dump "#pragma omp unroll" "original" } } */
+/* { dg-final { scan-tree-dump-not "#pragma omp" "gimple" } } */
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+extern void dummy (int);
+
+void
+test (void)
+{
+ [[omp::directive (target parallel for collapse(2))]]
+ for (int i = -300; i != 100; ++i)
+ [[omp::directive (unroll, partial)]]
+ for (int j = 0; j != 100; ++j)
+ dummy (i);
+}
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+extern void dummy (int);
+
+void
+test (void)
+{
+ #pragma omp target parallel for collapse(2)
+ for (int i = -300; i != 100; ++i)
+ [[omp::directive (tile sizes (2))]]
+ for (int j = 0; j != 100; ++j)
+ dummy (i);
+
+ [[omp::directive (target parallel for, collapse(2))]]
+ for (int i = -300; i != 100; ++i)
+ [[omp::directive (tile, sizes(2, 3))]]
+ for (int j = 0; j != 100; ++j)
+ for (int k = 0; k != 100; ++k)
+ dummy (i);
+}
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+/* Test that omp::sequence is handled properly in a loop nest, but that
+ invalid attribute specifiers are rejected. */
+
+extern void dummy (int);
+
+void
+test1 (void)
+{
+ [[omp::directive (target parallel for collapse(2))]]
+ for (int i = -300; i != 100; ++i)
+ [[omp::sequence (directive (unroll, partial))]]
+ for (int j = 0; j != 100; ++j)
+ dummy (i);
+}
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+extern void dummy (int);
+
+void
+test (void)
+{
+ [[omp::directive (target parallel for collapse(2))]]
+ for (int i = -300; i != 100; ++i)
+ [[omp::directive (tile sizes(2, 3))]]
+ for (int j = 0; j != 100; ++j) /* { dg-error "not enough nested loops" } */
+ dummy (i);
+}
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-additional-options "-std=c23" { target c } } */
+
+/* Test that omp::sequence is handled properly in a loop nest, but that
+ invalid attribute specifiers are rejected. */
+
+extern void dummy (int);
+
+void
+test2 (void)
+{
+ [[omp::directive (target parallel for collapse(2))]]
+ for (int i = -300; i != 100; ++i)
+ [[omp::directive (masked)]] /* { dg-error "expected 'for' loop or OpenMP loop transformation construct" } */
+ for (int j = 0; j != 100; ++j) /* { dg-error "loop not permitted" } */
+ dummy (i);
+}
+
+void
+test3 (void)
+{
+ [[omp::directive (target parallel for collapse(2))]]
+ for (int i = -300; i != 100; ++i)
+ [[omp::directive (unroll, partial)]] /* { dg-error "attributes on the same statement" } */
+ [[omp::directive (masked)]]
+ for (int j = 0; j != 100; ++j)
+ dummy (i);
+}
+
+void
+test4 (void)
+{
+ [[omp::directive (target parallel for collapse(2))]]
+ for (int i = -300; i != 100; ++i)
+ [[omp::sequence (directive (unroll, partial),
+ directive (masked))]] /* { dg-error "loop nest expected" } */
+ for (int j = 0; j != 100; ++j)
+ dummy (i); /* { dg-error "declared" } */
+}
+
+void
+test5 (void)
+{
+ [[omp::directive (target parallel for collapse(2))]]
+ for (int i = -300; i != 100; ++i)
+ [[omp::sequence (directive (masked), /* { dg-error "expected 'for' loop or OpenMP loop transformation construct" } */
+ directive (unroll, partial))]]
+ for (int j = 0; j != 100; ++j)
+ dummy (i);
+}
+
+void
+test6 (void)
+{
+ [[omp::directive (target parallel for collapse(2))]]
+ for (int i = -300; i != 100; ++i)
+ [[omp::directive (unroll, partial), /* { dg-error "attributes on the same statement" } */
+ omp::directive (masked)]]
+ for (int j = 0; j != 100; ++j)
+ dummy (i);
+}
/* { dg-do compile { target { c || c++11 } } } */
/* Check that a nested FOR loop with standard c/c++ attributes on it
- is treated as intervening code, since it doesn't match the grammar
- for canonical loop nest form. */
+ (not the C++ attribute syntax for OpenMP directives)
+ gives an error. */
extern void do_something (void);
+
+/* This one should be OK, an empty attribute list is ignored in both C
+ and C++. */
void imperfect1 (int x, int y)
{
#pragma omp for collapse (2)
- for (int i = 0; i < x; i++) /* { dg-error "not enough nested loops" } */
+ for (int i = 0; i < x; i++)
{
- [[]] for (int j = 0; j < y; j++) /* { dg-error "loop not permitted in intervening code" } */
+ [[]] for (int j = 0; j < y; j++)
do_something ();
}
}
void perfect1 (int x, int y)
{
#pragma omp for ordered (2)
- for (int i = 0; i < x; i++) /* { dg-error "not enough nested loops" } */
- /* { dg-error "inner loops must be perfectly nested" "" { target *-*-*} .-1 } */
+ for (int i = 0; i < x; i++)
{
- [[]] for (int j = 0; j < y; j++) /* { dg-error "loop not permitted in intervening code" } */
+ [[]] for (int j = 0; j < y; j++)
do_something ();
}
}
/* Similar, but put the attributes on a block wrapping the nested loop
- instead. */
+ instead. This is not allowed by the grammar. */
void imperfect2 (int x, int y)
{
--- /dev/null
+void
+test (void)
+{
+#pragma omp tile sizes (2,4,6)
+ for (unsigned i = 0; i < 10; i++) /* { dg-error "inner loops must be perfectly nested" } */
+ for (unsigned j = 0; j < 10; j++)
+ {
+ float intervening_decl = 0;
+#pragma omp unroll partial(2)
+ for (unsigned k = 0; k < 10; k++);
+ }
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+void
+foo (void)
+{
+ int i;
+ #pragma omp for ordered /* { dg-error "'ordered' clause used with generated loops" } */
+ #pragma omp tile sizes (2)
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered
+ ;
+ }
+ #pragma omp for ordered /* { dg-error "'ordered' clause used with generated loops" } */
+ #pragma omp tile sizes (2)
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered threads
+ ;
+ }
+ #pragma omp for simd ordered /* { dg-error "'ordered' clause used with generated loops" "" { target c } } */
+ #pragma omp tile sizes (2) /* { dg-error "'ordered' clause used with generated loops" "" { target c++ } } */
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered threads, simd
+ ;
+ }
+ #pragma omp for simd ordered(1) /* { dg-error "'ordered' clause used with generated loops" "" { target c } } */
+ #pragma omp tile sizes (2) /* { dg-error "'ordered' clause used with generated loops" "" { target c++ } } */
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered depend(sink: i - 1)
+ #pragma omp ordered depend(source)
+ }
+ #pragma omp for simd ordered(1) /* { dg-error "'ordered' clause used with generated loops" "" { target c } } */
+ #pragma omp tile sizes (2) /* { dg-error "'ordered' clause used with generated loops" "" { target c++ } } */
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered doacross(sink: i - 1)
+ #pragma omp ordered doacross(source:omp_cur_iteration)
+ }
+ #pragma omp parallel for ordered /* { dg-error "'ordered' clause used with generated loops" "" { target c } } */
+ #pragma omp tile sizes (2) /* { dg-error "'ordered' clause used with generated loops" "" { target c++ } } */
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered depend(sink: i - 1)
+ #pragma omp ordered depend(source)
+ }
+ #pragma omp parallel for ordered /* { dg-error "'ordered' clause used with generated loops" "" { target c } } */
+ #pragma omp tile sizes (2) /* { dg-error "'ordered' clause used with generated loops" "" { target c++ } } */
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered doacross(sink: i - 1)
+ #pragma omp ordered doacross(source:)
+ }
+ #pragma omp for ordered(1) /* { dg-error "'ordered' clause used with generated loops" } */
+ #pragma omp tile sizes (2)
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered depend(sink: i - 1)
+ #pragma omp ordered depend(source)
+ }
+ #pragma omp for ordered(1) /* { dg-error "'ordered' clause used with generated loops" } */
+ #pragma omp tile sizes (2)
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered doacross(sink: i - 1)
+ #pragma omp ordered doacross(source:omp_cur_iteration)
+ }
+}
+
+void
+bar (void)
+{
+ int i;
+ #pragma omp for ordered /* { dg-error "'ordered' clause used with generated loops" } */
+ #pragma omp unroll partial (2)
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered
+ ;
+ }
+ #pragma omp for ordered /* { dg-error "'ordered' clause used with generated loops" } */
+ #pragma omp unroll partial (2)
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered threads
+ ;
+ }
+ #pragma omp for simd ordered /* { dg-error "'ordered' clause used with generated loops" "" { target c } } */
+ #pragma omp unroll partial (2) /* { dg-error "'ordered' clause used with generated loops" "" { target c++ } } */
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered threads, simd
+ ;
+ }
+ #pragma omp for simd ordered(1) /* { dg-error "'ordered' clause used with generated loops" "" { target c } } */
+ #pragma omp unroll partial (2) /* { dg-error "'ordered' clause used with generated loops" "" { target c++ } } */
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered depend(sink: i - 1)
+ #pragma omp ordered depend(source)
+ }
+ #pragma omp for simd ordered(1) /* { dg-error "'ordered' clause used with generated loops" "" { target c } } */
+ #pragma omp unroll partial (2) /* { dg-error "'ordered' clause used with generated loops" "" { target c++ } } */
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered doacross(sink: i - 1)
+ #pragma omp ordered doacross(source:omp_cur_iteration)
+ }
+ #pragma omp parallel for ordered /* { dg-error "'ordered' clause used with generated loops" "" { target c } } */
+ #pragma omp unroll partial (2) /* { dg-error "'ordered' clause used with generated loops" "" { target c++ } } */
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered depend(sink: i - 1)
+ #pragma omp ordered depend(source)
+ }
+ #pragma omp parallel for ordered /* { dg-error "'ordered' clause used with generated loops" "" { target c } } */
+ #pragma omp unroll partial (2) /* { dg-error "'ordered' clause used with generated loops" "" { target c++ } } */
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered doacross(sink: i - 1)
+ #pragma omp ordered doacross(source:)
+ }
+ #pragma omp for ordered(1) /* { dg-error "'ordered' clause used with generated loops" } */
+ #pragma omp unroll partial (2)
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered depend(sink: i - 1)
+ #pragma omp ordered depend(source)
+ }
+ #pragma omp for ordered(1) /* { dg-error "'ordered' clause used with generated loops" } */
+ #pragma omp unroll partial (2)
+ for (i = 0; i < 64; i++)
+ {
+ #pragma omp ordered doacross(sink: i - 1)
+ #pragma omp ordered doacross(source:omp_cur_iteration)
+ }
+}
--- /dev/null
+int a;
+
+void
+foo (int *c, int *d)
+{
+ #pragma omp for reduction (inscan, +: a) /* { dg-error "'a' specified in 'inscan' 'reduction' clause but not in 'scan' directive clause" } */
+ #pragma omp tile sizes (2)
+ for (int i = 0; i < 64; ++i)
+ {
+ a = a + c[i];
+ #pragma omp scan inclusive (a) /* { dg-error "'#pragma omp scan' may only be used in a loop construct with 'inscan' 'reduction' clause" } */
+ d[i] = a;
+ }
+}
+
+void
+bar (int **c, int **d)
+{
+ #pragma omp for collapse (2) reduction (inscan, +: a) /* { dg-error "'a' specified in 'inscan' 'reduction' clause but not in 'scan' directive clause" } */
+ for (int i = 0; i < 64; ++i)
+ #pragma omp tile sizes (3)
+ for (int j = 0; j < 64; ++j)
+ {
+ d[i][j] = a;
+ #pragma omp scan exclusive (a) /* { dg-error "'#pragma omp scan' may only be used in a loop construct with 'inscan' 'reduction' clause" } */
+ a = a + c[i][j];
+ }
+}
+
+void
+baz (int *c, int *d)
+{
+ #pragma omp for reduction (inscan, +: a) /* { dg-error "'a' specified in 'inscan' 'reduction' clause but not in 'scan' directive clause" } */
+ #pragma omp unroll partial (2)
+ for (int i = 0; i < 64; ++i)
+ {
+ d[i] = a;
+ #pragma omp scan exclusive (a) /* { dg-error "'#pragma omp scan' may only be used in a loop construct with 'inscan' 'reduction' clause" } */
+ a = a + c[i];
+ }
+}
+
+void
+qux (int **c, int **d)
+{
+ #pragma omp for collapse (2) reduction (inscan, +: a) /* { dg-error "'a' specified in 'inscan' 'reduction' clause but not in 'scan' directive clause" } */
+ for (int i = 0; i < 64; ++i)
+ #pragma omp unroll partial (3)
+ for (int j = 0; j < 64; ++j)
+ {
+ a = a + c[i][j];
+ #pragma omp scan inclusive (a) /* { dg-error "'#pragma omp scan' may only be used in a loop construct with 'inscan' 'reduction' clause" } */
+ d[i][j] = a;
+ }
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test (void)
+{
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(1)
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(1, 2)
+ #pragma omp tile sizes(1, 2)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp tile sizes(5, 6)
+ #pragma omp tile sizes(1, 2, 3)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ for (int k = 0; k < 100; ++k)
+ dummy (i);
+
+ #pragma omp tile sizes(1)
+ #pragma omp unroll partial
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(1, 2)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ {
+ dummy (i);
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+ }
+
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ {
+ for (int j = 0; j < 100; ++j)
+ dummy (j);
+ dummy (i);
+ }
+}
--- /dev/null
+void
+test1 (void)
+{
+ int i, j, k, l;
+ #pragma omp for collapse(4) private (i, j, k, l) /* { dg-error "the same loop iteration variables 'i' used in multiple associated loops" "" { target c } } */
+ for (i = 0; i < 1024; ++i) /* { dg-error "the same loop iteration variables 'i' used in multiple associated loops" "" { target c++ } } */
+ #pragma omp tile sizes (2, 2, 2)
+ for (j = 0; j < 1024; ++j)
+ #pragma omp tile sizes (3, 3)
+ for (k = 0; k < 1024; ++k)
+ #pragma omp tile sizes (4)
+ for (i = 0; i < 1024; ++i)
+ ;
+}
+
+void
+test2 (void)
+{
+ long long i;
+ int j, k, l;
+ #pragma omp for collapse(4) private (i, j, k, l) /* { dg-error "outer iteration variable 'i' used in initializer expression has type other than 'int'" "" { target c } } */
+ for (i = 0; i < 1024; ++i) /* { dg-error "outer iteration variable 'i' used in initializer expression has type other than 'int'" "" { target c++ } } */
+ #pragma omp tile sizes (2, 2, 2)
+ for (j = 0; j < 1024; ++j)
+ #pragma omp tile sizes (3, 3)
+ for (k = 0; k < 1024; ++k)
+ #pragma omp tile sizes (4)
+ for (l = i; l < 1024; ++l)
+ ;
+}
+
+void
+test3 (void)
+{
+ int i, j, k, l;
+ #pragma omp for collapse(4) private (i, j, k, l)
+ for (i = 0; i < 1024; ++i)
+ #pragma omp tile sizes (2, 2, 2)
+ for (j = 0; j < 1024; ++j)
+ #pragma omp tile sizes (3, 3)
+ for (k = 0; k < 1024; ++k)
+ #pragma omp tile sizes (4)
+ for (l = 0; l < 7 * i * i; ++l) /* { dg-error "condition expression refers to iteration variable 'i'" } */
+ ;
+}
+
+void
+test4 (void)
+{
+ int i, j, k, l;
+ #pragma omp for collapse(4) private (i, j, k, l)
+ for (i = 0; i < 1024; ++i)
+ #pragma omp tile sizes (2, 2, 2)
+ for (j = 0; j < 1024; ++j)
+ #pragma omp tile sizes (3, 3)
+ for (k = 0; k < 1024; ++k)
+ #pragma omp tile sizes (4)
+ for (l = i * i; l < 1024; ++l) /* { dg-error "initializer expression refers to iteration variable 'i'" } */
+ ;
+}
+
+void
+test5 (void)
+{
+ int i, j, k, l;
+ #pragma omp for collapse(4) private (i, j, k, l)
+ for (i = 0; i < 1024; ++i)
+ #pragma omp tile sizes (2, 2, 2) /* { dg-error "increment expression refers to iteration variable 'j'" "" { target c } } */
+ for (j = 0; j < 1024; ++j) /* { dg-error "increment expression refers to iteration variable 'j'" "" { target c++ } } */
+ #pragma omp tile sizes (3, 3)
+ for (k = 0; k < 1024; ++k)
+ #pragma omp tile sizes (4)
+ for (l = 0; l < 1024; l += j)
+ ;
+}
+
+void
+test6 (void)
+{
+ int i, j, k, l;
+ #pragma omp for collapse(4) private (i, j, k, l)
+ for (i = 0; i < 1024; ++i)
+ #pragma omp tile sizes (2, 2, 2)
+ for (j = 0; j < 1024; ++j)
+ #pragma omp tile sizes (3, 3)
+ for (k = 0; k < 1024; ++k)
+ #pragma omp tile sizes (4)
+ for (l = 0; l < i - 2; ++l) /* { dg-message "non-rectangular loops from generated loops unsupported" } */
+ ;
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test (void)
+{
+ #pragma omp tile sizes(0) /* { dg-error "'sizes' argument needs positive integral constant" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(-1) /* { dg-error "'sizes' argument needs positive integral constant" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes() /* { dg-error "expected expression before" "" { target c} } */
+ /* { dg-error "expected primary-expression before" "" { target c++ } .-1 } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(,) /* { dg-error "expected expression before" "" { target c } } */
+ /* { dg-error "expected primary-expression before" "" { target c++ } .-1 } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(1,2 /* { dg-error "expected ',' before end of line" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes /* { dg-error "expected '\\\(' before end of line" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(1) sizes(1) /* { dg-error "expected end of line before 'sizes'" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(1, 2)
+ #pragma omp tile sizes(1) /* { dg-error "'tile' construct generates 1 loops with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp tile sizes(1)
+ #pragma omp unroll partia /* { dg-error "expected an OpenMP clause before 'partia'" } */
+ #pragma omp tile sizes(1) /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" "" { target *-*-* } .-1 } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(1)
+ #pragma omp unroll /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(1)
+ #pragma omp unroll full /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(8,8)
+ #pragma omp unroll partial /* { dg-error "'unroll' construct with 'partial' clause generates just one loop with canonical form but 2 loops are needed" } */
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(8,8)
+ #pragma omp unroll partial /* { dg-error "'unroll' construct with 'partial' clause generates just one loop with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(1, 2) /* { dg-error "non-rectangular 'tile'" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = i; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp tile sizes(1, 2) /* { dg-error "non-rectangular 'tile'" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 2; j < i; ++j)
+ dummy (i);
+
+ #pragma omp tile sizes(1, 2, 3)
+ for (int i = 0; i < 100; ++i) /* { dg-error "not enough nested loops" } */
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp tile sizes(1, 2)
+ for (int i = 0; i < 100; ++i) /* { dg-error "inner loops must be perfectly nested" } */
+ {
+ dummy (i);
+ for (int j = 0; j < 100; ++j)
+ dummy (j);
+ }
+
+ #pragma omp tile sizes(1, 2)
+ for (int i = 0; i < 100; ++i) /* { dg-error "inner loops must be perfectly nested" } */
+ {
+ for (int j = 0; j < 100; ++j)
+ dummy (j);
+ dummy (i);
+ }
+
+ int s;
+ #pragma omp tile sizes(s) /* { dg-error "'sizes' argument needs positive integral constant" "" { target { ! c++98_only } } } */
+ /* { dg-error "the value of 's' is not usable in a constant expression" "" { target { c++ && { ! c++98_only } } } .-1 } */
+ /* { dg-error "'s' cannot appear in a constant-expression" "" { target c++98_only } .-2 } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(42.0) /* { dg-error "'sizes' argument needs positive integral constant" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test (void)
+{
+ #pragma omp parallel for
+ #pragma omp tile sizes(0) /* { dg-error "'sizes' argument needs positive integral constant" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(-1) /* { dg-error "'sizes' argument needs positive integral constant" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes(5, -42) /* { dg-error "'sizes' argument needs positive integral constant" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp tile sizes(0.5f) /* { dg-error "'sizes' argument needs positive integral constant" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes() /* { dg-error "expected expression before" "" { target c} } */
+ /* { dg-error "expected primary-expression before" "" { target c++ } .-1 } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(,) /* { dg-error "expected expression before" "" { target c } } */
+ /* { dg-error "expected primary-expression before" "" { target c++ } .-1 } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1,2 /* { dg-error "expected ',' before end of line" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes /* { dg-error "expected '\\\(' before end of line" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1) sizes(1) /* { dg-error "expected end of line before 'sizes'" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1, 2)
+ #pragma omp tile sizes(1) /* { dg-error "'tile' construct generates 1 loops with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1)
+ #pragma omp unroll partia /* { dg-error "expected an OpenMP clause before 'partia'" } */
+ #pragma omp tile sizes(1) /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" "" { target *-*-* } .-1 } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1)
+ #pragma omp unroll /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1)
+ #pragma omp unroll full /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(8,8)
+ #pragma omp unroll partial /* { dg-error "'unroll' construct with 'partial' clause generates just one loop with canonical form but 2 loops are needed" } */
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(8,8)
+ #pragma omp unroll partial /* { dg-error "'unroll' construct with 'partial' clause generates just one loop with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1, 2) /* { dg-error "non-rectangular 'tile'" "" { target c } } */
+ for (int i = 0; i < 100; ++i) /* { dg-error "non-rectangular 'tile'" "" { target c++ } } */
+ for (int j = i; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1, 2) /* { dg-error "non-rectangular 'tile'" "" { target c } } */
+ for (int i = 0; i < 100; ++i) /* { dg-error "non-rectangular 'tile'" "" { target c++ } } */
+ for (int j = 2; j < i; ++j)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1, 2, 3)
+ for (int i = 0; i < 100; ++i) /* { dg-error "not enough nested loops" } */
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1, 2)
+ for (int i = 0; i < 100; ++i) /* { dg-error "inner loops must be perfectly nested" } */
+ {
+ dummy (i);
+ for (int j = 0; j < 100; ++j)
+ dummy (j);
+ }
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1, 2)
+ for (int i = 0; i < 100; ++i) /* { dg-error "inner loops must be perfectly nested" } */
+ {
+ for (int j = 0; j < 100; ++j)
+ dummy (j);
+ dummy (i);
+ }
+
+ #pragma omp tile /* { dg-error "expected 'sizes'" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp tile sizes (1) sizes (1) /* { dg-error "expected end of line" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test (void)
+{
+ #pragma omp for
+ #pragma omp tile sizes(1, 2) /* { dg-error "non-rectangular 'tile'" "" { target c } } */
+ for (int i = 0; i < 100; ++i) /* { dg-error "non-rectangular 'tile'" "" { target c++ } } */
+ for (int j = i; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp for
+ #pragma omp tile sizes(1, 2) /* { dg-error "non-rectangular 'tile'" "" { target c } } */
+ for (int i = 0; i < 100; ++i) /* { dg-error "non-rectangular 'tile'" "" { target c++ } } */
+ for (int j = 0; j < i; ++j)
+ dummy (i);
+
+
+ #pragma omp for collapse(2)
+ #pragma omp tile sizes(1) /* { dg-error "'tile' construct generates 1 loops with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp for collapse(3)
+ #pragma omp tile sizes(1, 2) /* { dg-error "'tile' construct generates 2 loops with canonical form but 3 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp for collapse(2)
+ #pragma omp tile sizes(1, 2)
+ #pragma omp tile sizes(1) /* { dg-error "'tile' construct generates 1 loops with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp for collapse(2)
+ #pragma omp tile sizes(1, 2)
+ #pragma omp tile sizes(1, 2)
+ for (int i = 0; i < 100; ++i) /* { dg-error "not enough nested loops" } */
+ dummy (i);
+
+ #pragma omp for collapse(2)
+ #pragma omp tile sizes(5, 6)
+ #pragma omp tile sizes(1, 2, 3)
+ for (int i = 0; i < 100; ++i) /* { dg-error "not enough nested loops" } */
+ dummy (i);
+
+ #pragma omp for collapse(2)
+ #pragma omp tile sizes(1, 2)
+ #pragma omp tile sizes(1) /* { dg-error "'tile' construct generates 1 loops with canonical form but 2 loops are needed" } */
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp for collapse(3)
+ #pragma omp tile sizes(1, 2) /* { dg-error "'tile' construct generates 2 loops with canonical form but 3 loops are needed" } */
+ #pragma omp tile sizes(1, 2)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp for collapse(3)
+ #pragma omp tile sizes(5, 6) /* { dg-error "'tile' construct generates 2 loops with canonical form but 3 loops are needed" } */
+ #pragma omp tile sizes(1, 2, 3)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ for (int k = 0; k < 100; ++k)
+ dummy (i);
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test (void)
+{
+ #pragma omp for
+ #pragma omp tile sizes(2, 3)
+ #pragma omp tile sizes(3, 4, 5)
+ #pragma omp tile sizes(6, 7, 8, 9)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ for (int k = 0; k < 100; ++k)
+ for (int l = 0; l < 100; ++l)
+ dummy (i);
+
+ #pragma omp for
+ #pragma omp tile sizes(2, 3)
+ for (int i = 0; i < 100; ++i)
+ #pragma omp tile sizes(3, 4, 5)
+ for (int j = 0; j < 100; ++j)
+ #pragma omp tile sizes(6, 7, 8, 9)
+ for (int k = 0; k < 100; ++k)
+ for (int l = 0; l < 100; ++l)
+ for (int m = 0; m < 100; ++m)
+ #pragma omp unroll partial(2)
+ for (int n = 0; n < 100; ++n)
+ dummy (i);
+
+ #pragma omp for collapse(2)
+ for (int i = 0; i < 100; ++i)
+ #pragma omp tile sizes(2, 3)
+ #pragma omp tile sizes(3, 4, 5)
+ #pragma omp tile sizes(6, 7, 8, 9)
+ for (int j = 0; j < 100; ++j)
+ for (int k = 0; k < 100; ++k)
+ for (int l = 0; l < 100; ++l)
+ for (int m = 0; m < 100; ++m)
+ dummy (i);
+
+ #pragma omp for collapse(2)
+ for (int i = 0; i < 100; ++i)
+ #pragma omp tile sizes(2, 3)
+ for (int j = 0; j < 100; ++j)
+ #pragma omp tile sizes(3, 4, 5)
+ for (int k = 0; k < 100; ++k)
+ #pragma omp tile sizes(6, 7, 8, 9)
+ for (int l = 0; l < 100; ++l)
+ for (int m = 0; m < 100; ++m)
+ for (int n = 0; n < 100; ++n)
+ #pragma omp unroll partial(2)
+ for (int o = 0; o < 100; ++o)
+ dummy (i);
+}
--- /dev/null
+/* It isn't really clear what is supposed to be valid and what isn't when mixing
+ imperfectly nested loops with generated loops. Sorry for now until that is
+ clarified. */
+void foo (int, int);
+
+void
+bar (void)
+{
+ #pragma omp for collapse(2) /* { dg-message "imperfectly nested loop using generated loops" "" { target c } } */
+ for (int i = 0; i < 32; ++i) /* { dg-message "imperfectly nested loop using generated loops" "" { target c++ } } */
+ {
+ foo (i, -1);
+ #pragma omp tile sizes (2)
+ for (int j = 0; j < 32; ++j)
+ foo (i, j);
+ foo (i, -2);
+ }
+}
+
+void
+baz (void)
+{
+ #pragma omp for collapse(2) /* { dg-message "imperfectly nested loop using generated loops" "" { target c } } */
+ for (int i = 0; i < 32; ++i) /* { dg-message "imperfectly nested loop using generated loops" "" { target c++ } } */
+ {
+ foo (i, -1);
+ #pragma omp tile sizes (2, 2)
+ for (int j = 0; j < 32; ++j)
+ #pragma omp tile sizes (2, 2)
+ for (int k = 0; k < 32; ++k)
+ for (int l = 0; l < 32; ++l)
+ foo (i + k, j + l);
+ foo (i, -2);
+ }
+}
+
+void
+qux (void)
+{
+ #pragma omp for collapse(2) /* { dg-message "imperfectly nested loop using generated loops" "" { target c } } */
+ for (int i = 0; i < 32; ++i) /* { dg-message "imperfectly nested loop using generated loops" "" { target c++ } } */
+ {
+ int m = i + 6;
+ foo (i, -1);
+ #pragma omp tile sizes (2)
+ for (int j = m; j < 32; ++j)
+ foo (i, j);
+ foo (i, -2);
+ }
+}
+
+void
+freddy (void)
+{
+ #pragma omp for collapse(2) /* { dg-message "imperfectly nested loop using generated loops" "" { target c } } */
+ for (int i = 0; i < 32; ++i) /* { dg-message "imperfectly nested loop using generated loops" "" { target c++ } } */
+ {
+ int m = i + 6;
+ foo (i, -1);
+ #pragma omp tile sizes (2, 2)
+ for (int j = 0; j < 32; ++j)
+ #pragma omp tile sizes (2, 2)
+ for (int k = 0; k < 32; ++k)
+ for (int l = m; l < 32; ++l)
+ foo (i + k, j + l);
+ foo (i, -2);
+ }
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test (void)
+{
+ #pragma omp parallel for
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1)
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1, 2)
+ #pragma omp tile sizes(1, 2)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(5, 6)
+ #pragma omp tile sizes(1, 2, 3)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ for (int k = 0; k < 100; ++k)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1)
+ #pragma omp unroll partial
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1, 2)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ {
+ dummy (i);
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+ }
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ {
+ for (int j = 0; j < 100; ++j)
+ dummy (j);
+ dummy (i);
+ }
+
+ #pragma omp parallel for
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test (void)
+{
+ #pragma omp for collapse(1)
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp for collapse(2)
+ #pragma omp tile sizes(1, 2)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp for collapse(1)
+ #pragma omp tile sizes(1)
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp for collapse(1)
+ #pragma omp tile sizes(1)
+ #pragma omp tile sizes(1)
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+
+ #pragma omp for collapse(2)
+ #pragma omp tile sizes(1, 2)
+ #pragma omp tile sizes(1, 2)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ dummy (i);
+
+ #pragma omp for collapse(2)
+ #pragma omp tile sizes(5, 6)
+ #pragma omp tile sizes(1, 2, 3)
+ for (int i = 0; i < 100; ++i)
+ for (int j = 0; j < 100; ++j)
+ for (int k = 0; k < 100; ++k)
+ dummy (i);
+}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O0 -fopenmp-simd" } */
+
+#include <stdio.h>
+
+#define ASSERT_EQ(var, val) \
+ do \
+ { \
+ if ((var) != (val)) \
+ { \
+ fprintf (stderr, "%s:%d: Unexpected value %d, expected %d\n", \
+ __FILE__, __LINE__, (var), (val)); \
+ __builtin_abort (); \
+ } \
+ } \
+ while (0)
+
+int
+test1 (void)
+{
+ int iter = 0;
+ int i;
+#pragma omp tile sizes(3)
+ for (i = 0; i < 10; i = i + 2)
+ {
+ ASSERT_EQ (i, iter);
+ iter = iter + 2;
+ }
+
+ ASSERT_EQ (i, 10);
+ return iter;
+}
+
+int
+test2 (void)
+{
+ int iter = 0;
+ int i;
+#pragma omp tile sizes(3)
+ for (i = 0; i < 10; i = i + 2)
+ {
+ ASSERT_EQ (i, iter);
+ iter = iter + 2;
+ }
+
+ ASSERT_EQ (i, 10);
+ return iter;
+}
+
+int
+test3 (void)
+{
+ int iter = 0;
+ int i;
+#pragma omp tile sizes(8)
+ for (i = 0; i < 10; i = i + 2)
+ {
+ ASSERT_EQ (i, iter);
+ iter = iter + 2;
+ }
+
+ ASSERT_EQ (i, 10);
+ return iter;
+}
+
+int
+test4 (void)
+{
+ int iter = 10;
+ int i;
+#pragma omp tile sizes(8)
+ for (i = 10; i > 0; i = i - 2)
+ {
+ ASSERT_EQ (i, iter);
+ iter = iter - 2;
+ }
+ ASSERT_EQ (i, 0);
+ return iter;
+}
+
+int
+test5 (void)
+{
+ int iter = 10;
+ int i;
+#pragma omp tile sizes(71)
+ for (i = 10; i > 0; i = i - 2)
+ {
+ ASSERT_EQ (i, iter);
+ iter = iter - 2;
+ }
+
+ ASSERT_EQ (i, 0);
+ return iter;
+}
+
+int
+test6 (void)
+{
+ int iter = 10;
+ int i;
+#pragma omp tile sizes(1)
+ for (i = 10; i > 0; i = i - 2)
+ {
+ ASSERT_EQ (i, iter);
+ iter = iter - 2;
+ }
+ ASSERT_EQ (i, 0);
+ return iter;
+}
+
+int
+test7 (void)
+{
+ int iter = 5;
+ int i;
+#pragma omp tile sizes(2)
+ for (i = 5; i < -5; i = i - 3)
+ {
+ fprintf (stderr, "%d\n", i);
+ __builtin_abort ();
+ iter = iter - 3;
+ }
+
+ /* No iteration expected */
+ return iter;
+}
+
+int
+test8 (void)
+{
+ int iter = 5;
+ int i;
+#pragma omp tile sizes(2)
+ for (i = 5; i > -5; i = i - 3)
+ {
+ ASSERT_EQ (i, iter);
+ /* Expect only first iteration of the last tile to execute */
+ if (iter != -4)
+ iter = iter - 3;
+ }
+
+ ASSERT_EQ (i, -7);
+ return iter;
+}
+
+
+int
+test9 (void)
+{
+ int iter = 5;
+ int i;
+#pragma omp tile sizes(5)
+ for (i = 5; i >= -5; i = i - 4)
+ {
+ ASSERT_EQ (i, iter);
+ /* Expect only first iteration of the last tile to execute */
+ if (iter != - 3)
+ iter = iter - 4;
+ }
+
+ ASSERT_EQ (i, -7);
+ return iter;
+}
+
+int
+test10 (void)
+{
+ int iter = 5;
+ int i;
+#pragma omp tile sizes(5)
+ for (i = 5; i >= -5; i--)
+ {
+ ASSERT_EQ (i, iter);
+ iter--;
+ }
+
+ ASSERT_EQ (i, -6);
+ return iter;
+}
+
+int
+test11 (void)
+{
+ int iter = 5;
+ int i;
+#pragma omp tile sizes(15)
+ for (i = 5; i != -5; i--)
+ {
+ ASSERT_EQ (i, iter);
+ iter--;
+ }
+ ASSERT_EQ (i, -5);
+ return iter;
+}
+
+int
+test12 (void)
+{
+ int iter = 0;
+ unsigned i;
+#pragma omp tile sizes(3)
+ for (i = 0; i != 5; i++)
+ {
+ ASSERT_EQ (i, iter);
+ iter++;
+ }
+
+ ASSERT_EQ (i, 5);
+ return iter;
+}
+
+int
+test13 (void)
+{
+ int iter = -5;
+ long long unsigned int i = 42;
+#pragma omp tile sizes(15)
+ for (int i = -5; i < 5; i = i + 3)
+ {
+ ASSERT_EQ (i, iter);
+ iter += 3;
+ }
+
+ ASSERT_EQ (i, 42);
+ return iter;
+}
+
+int
+test14 (unsigned init, int step)
+{
+ int iter = init;
+ long long unsigned int i;
+#pragma omp tile sizes(8)
+ for (i = init; i < 2 * init; i = i + step)
+ iter++;
+
+ if (init)
+ ASSERT_EQ (i, 2 * init + (init == 5));
+ return iter;
+}
+
+int
+test15 (unsigned init, int step)
+{
+ int iter = init;
+ int i;
+#pragma omp tile sizes(8)
+ for (unsigned i = init; i > 2 * init; i = i + step)
+ iter++;
+
+ return iter;
+}
+
+int
+main ()
+{
+ int last_iter;
+
+ last_iter = test1 ();
+ ASSERT_EQ (last_iter, 10);
+
+ last_iter = test2 ();
+ ASSERT_EQ (last_iter, 10);
+
+ last_iter = test3 ();
+ ASSERT_EQ (last_iter, 10);
+
+ last_iter = test4 ();
+ ASSERT_EQ (last_iter, 0);
+
+ last_iter = test5 ();
+ ASSERT_EQ (last_iter, 0);
+
+ last_iter = test6 ();
+ ASSERT_EQ (last_iter, 0);
+
+ last_iter = test7 ();
+ ASSERT_EQ (last_iter, 5);
+
+ last_iter = test8 ();
+ ASSERT_EQ (last_iter, -4);
+
+ last_iter = test9 ();
+ ASSERT_EQ (last_iter, -3);
+
+ last_iter = test10 ();
+ ASSERT_EQ (last_iter, -6);
+
+ last_iter = test11 ();
+ ASSERT_EQ (last_iter, -5);
+
+ last_iter = test12 ();
+ ASSERT_EQ (last_iter, 5);
+
+ last_iter = test13 ();
+ ASSERT_EQ (last_iter, 7);
+
+ last_iter = test14 (0, 1);
+ ASSERT_EQ (last_iter, 0);
+
+ last_iter = test14 (0, -1);
+ ASSERT_EQ (last_iter, 0);
+
+ last_iter = test14 (8, 2);
+ ASSERT_EQ (last_iter, 12);
+
+ last_iter = test14 (5, 3);
+ ASSERT_EQ (last_iter, 7);
+
+ last_iter = test15 (8, -1);
+ ASSERT_EQ (last_iter, 8);
+
+ last_iter = test15 (8, -2);
+ ASSERT_EQ (last_iter, 8);
+
+ last_iter = test15 (5, -3);
+ ASSERT_EQ (last_iter, 5);
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O0 -fopenmp-simd" } */
+
+#include <stdio.h>
+
+#define ASSERT_EQ(var, val) \
+ do \
+ { \
+ if ((var) != (val)) \
+ { \
+ fprintf (stderr, "%s:%d: Unexpected value %d, expected %d\n", \
+ __FILE__, __LINE__, (var), (val)); \
+ __builtin_abort (); \
+ } \
+ } \
+ while (0)
+
+#define ASSERT_EQ_PTR(var, ptr) \
+ do \
+ { \
+ if ((var) != (ptr)) \
+ { \
+ fprintf (stderr, "%s:%d: Unexpected value %p, expected %p\n", \
+ __FILE__, __LINE__, (var), (ptr)); \
+ __builtin_abort (); \
+ } \
+ } \
+ while (0)
+
+int
+test1 (int data[10])
+{
+ int iter = 0;
+ int *i;
+ #pragma omp tile sizes(5)
+ for (i = data; i < data + 10; i++)
+ {
+ ASSERT_EQ (*i, data[iter]);
+ ASSERT_EQ_PTR (i, data + iter);
+ iter++;
+ }
+
+ ASSERT_EQ_PTR (i, data + 10);
+ return iter;
+}
+
+int
+test2 (int data[10])
+{
+ int iter = 0;
+ int *i;
+ #pragma omp tile sizes(5)
+ for (i = data; i < data + 10; i = i + 2)
+ {
+ ASSERT_EQ_PTR (i, data + 2 * iter);
+ ASSERT_EQ (*i, data[2 * iter]);
+ iter++;
+ }
+
+ ASSERT_EQ_PTR (i, data + 10);
+ return iter;
+}
+
+int
+test3 (int data[10])
+{
+ int iter = 0;
+ int *i;
+ #pragma omp tile sizes(5)
+ for (i = data; i <= data + 9; i = i + 2)
+ {
+ ASSERT_EQ (*i, data[2 * iter]);
+ iter++;
+ }
+
+ ASSERT_EQ_PTR (i, data + 10);
+ return iter;
+}
+
+int
+test4 (int data[10])
+{
+ int iter = 0;
+ int *i;
+ #pragma omp tile sizes(5)
+ for (i = data; i != data + 10; i = i + 1)
+ {
+ ASSERT_EQ (*i, data[iter]);
+ iter++;
+ }
+
+ ASSERT_EQ_PTR (i, data + 10);
+ return iter;
+}
+
+int
+test5 (int data[15])
+{
+ int iter = 0;
+ int *i;
+ #pragma omp tile sizes(3)
+ for (i = data + 14; i >= data + 5; i--)
+ {
+ ASSERT_EQ (*i, data[14 - iter]);
+ iter++;
+ }
+
+ ASSERT_EQ_PTR (i, data + 4);
+ return iter;
+}
+
+int
+test6 (int data[15])
+{
+ int iter = 0;
+ int *i;
+ #pragma omp tile sizes(3)
+ for (i = data + 14; i > data + 4; i--)
+ {
+ ASSERT_EQ (*i, data[14 - iter]);
+ iter++;
+ }
+
+ ASSERT_EQ_PTR (i, data + 4);
+ return iter;
+}
+
+int
+test7 (int data[15])
+{
+ int iter = 0;
+ #pragma omp tile sizes(1)
+ for (int *i = data + 14; i != data + 4; i--)
+ {
+ ASSERT_EQ (*i, data[14 - iter]);
+ iter++;
+ }
+
+ return iter;
+}
+
+int
+main ()
+{
+ int iter_count;
+ int data[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ int data2[15] = { -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
+ iter_count = test1 (data);
+ ASSERT_EQ (iter_count, 10);
+
+ iter_count = test2 (data);
+ ASSERT_EQ (iter_count, 5);
+
+ iter_count = test3 (data);
+ ASSERT_EQ (iter_count, 5);
+
+ iter_count = test4 (data);
+ ASSERT_EQ (iter_count, 10);
+
+ iter_count = test5 (data2);
+ ASSERT_EQ (iter_count, 10);
+
+ iter_count = test6 (data2);
+ ASSERT_EQ (iter_count, 10);
+
+ iter_count = test7 (data2);
+ ASSERT_EQ (iter_count, 10);
+}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O0 -fopenmp-simd" } */
+
+int
+test1 (void)
+{
+ int sum = 0;
+ for (int k = 0; k < 10; k++)
+ {
+ #pragma omp tile sizes(5,7)
+ for (int i = 0; i < 10; i++)
+ for (int j = 0; j < 10; j = j + 2)
+ sum = sum + 1;
+ }
+
+ return sum;
+}
+
+int
+main ()
+{
+ int result = test1 ();
+
+ if (result != 500)
+ __builtin_abort ();
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O0 -fopenmp-simd" } */
+
+#include <stdio.h>
+
+#define ASSERT_EQ(var, val) \
+ do \
+ { \
+ if ((var) != (val)) \
+ { \
+ fprintf (stderr, "%s:%d: Unexpected value %d, expected %d\n", \
+ __FILE__, __LINE__, (var), (val)); \
+ __builtin_abort (); \
+ } \
+ } \
+ while (0)
+
+#define ASSERT_EQ_PTR(var, ptr) \
+ do \
+ { \
+ if ((var) != (ptr)) \
+ { \
+ fprintf (stderr, "%s:%d: Unexpected value %p, expected %p\n", \
+ __FILE__, __LINE__, (var), (ptr)); \
+ __builtin_abort (); \
+ } \
+ } \
+ while (0)
+
+int
+main ()
+{
+ int iter_count;
+ int data[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ int iter = 0;
+ int *i;
+
+ #pragma omp tile sizes(1)
+ for (i = data; i < data + 10; i = i + 2)
+ {
+ ASSERT_EQ_PTR (i, data + 2 * iter);
+ ASSERT_EQ (*i, data[2 * iter]);
+ iter++;
+ }
+
+ unsigned long real_iter_count
+ = ((unsigned long)i - (unsigned long)data) / (sizeof (int) * 2);
+ ASSERT_EQ (real_iter_count, 5);
+
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O0 -fopenmp-simd" } */
+
+#include <stdio.h>
+
+#define ASSERT_EQ(var, val) \
+ do \
+ { \
+ if ((var) != (val)) \
+ { \
+ fprintf (stderr, "%s:%d: Unexpected value %d, expected %d\n", \
+ __FILE__, __LINE__, (var), (val)); \
+ __builtin_abort (); \
+ } \
+ } \
+ while (0)
+
+int
+main ()
+{
+ int iter_j = 0, iter_k = 0;
+ unsigned i, j, k;
+
+ #pragma omp tile sizes(3,5,8)
+ for (i = 0; i < 2; i=i+2)
+ for (j = 0; j < 3; j=j+1)
+ for (k = 0; k < 5; k=k+3)
+ {
+ /* fprintf (stderr, "i=%d j=%d k=%d\n", i, j, k);
+ fprintf (stderr, "iter_j=%d iter_k=%d\n", iter_j, iter_k); */
+ ASSERT_EQ (i, 0);
+ if (k == 0)
+ {
+ ASSERT_EQ (j, iter_j);
+ iter_k = 0;
+ }
+
+ ASSERT_EQ (k, iter_k);
+
+ iter_k = iter_k + 3;
+ if (k == 3)
+ iter_j++;
+ }
+
+ ASSERT_EQ (i, 2);
+ ASSERT_EQ (j, 3);
+ ASSERT_EQ (k, 6);
+
+ return 0;
+}
--- /dev/null
+/* { dg-additional-options "-O2" } */
+
+int foo (int);
+
+void
+mult (float *matrix1, float *matrix2, float *result,
+ unsigned dim0, unsigned dim1, unsigned dim2, unsigned dim3)
+{
+ #pragma omp taskloop collapse(3)
+ for (unsigned i = 0; i < dim0; i++)
+ #pragma omp tile sizes(2, 2)
+ #pragma omp tile sizes(2, 2)
+ #pragma omp tile sizes(2, 2)
+ for (unsigned j = 0; j < dim1; j += dim2 * foo (0))
+ #pragma omp unroll partial(2)
+ #pragma omp unroll partial(2)
+ for (unsigned k = 0; k < dim1; k += dim3 * foo (1))
+ result[i * dim1 + j] += matrix1[i * dim1 + k] * matrix2[k * dim0 + j];
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test1 (void)
+{
+ #pragma omp unroll partial
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+}
+
+void
+test2 (void)
+{
+ #pragma omp unroll partial(10)
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+}
+
+void
+test3 (void)
+{
+ #pragma omp unroll full
+ for (int i = 0; i < 100; ++i)
+ dummy (i);
+}
+
+void
+test4 (void)
+{
+ #pragma omp unroll full
+ for (int i = 0; i > 100; ++i)
+ dummy (i);
+}
+
+void
+test5 (void)
+{
+ #pragma omp unroll full
+ for (int i = 1; i <= 100; ++i)
+ dummy (i);
+}
+
+void
+test6 (void)
+{
+ #pragma omp unroll full
+ for (int i = 200; i >= 100; i--)
+ dummy (i);
+}
+
+void
+test7 (void)
+{
+ #pragma omp unroll full
+ for (int i = -100; i > 100; ++i)
+ dummy (i);
+}
+
+void
+test8 (void)
+{
+ #pragma omp unroll full
+ for (int i = 100; i > -200; --i)
+ dummy (i);
+}
+
+void
+test9 (void)
+{
+ #pragma omp unroll full
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+}
+
+void
+test10 (void)
+{
+ #pragma omp unroll full
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+}
+
+void
+test12 (void)
+{
+ #pragma omp unroll full
+ #pragma omp unroll partial
+ #pragma omp unroll partial
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+}
+
+void
+test13 (void)
+{
+ for (int i = 0; i < 100; ++i)
+ #pragma omp unroll full
+ #pragma omp unroll partial
+ #pragma omp unroll partial
+ for (int j = -300; j != 100; ++j)
+ dummy (i);
+}
+
+void
+test14 (void)
+{
+ #pragma omp for
+ for (int i = 0; i < 100; ++i)
+ #pragma omp unroll full
+ #pragma omp unroll partial
+ #pragma omp unroll partial
+ for (int j = -300; j != 100; ++j)
+ dummy (i);
+}
+
+void
+test15 (void)
+{
+ #pragma omp for
+ for (int i = 0; i < 100; ++i)
+ {
+ dummy (i);
+
+ #pragma omp unroll full
+ #pragma omp unroll partial
+ #pragma omp unroll partial
+ for (int j = -300; j != 100; ++j)
+ dummy (j);
+
+ dummy (i);
+ }
+ }
--- /dev/null
+/* { dg-do compile { target { c || c++11 } } } */
+/* { dg-prune-output "error: invalid controlling predicate" } */
+
+extern void dummy (int);
+
+void
+test (void)
+{
+ #pragma omp unroll partial
+ #pragma omp unroll full /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp for
+ #pragma omp unroll full /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ #pragma omp unroll partial
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp for
+ #pragma omp unroll full
+ #pragma omp unroll full /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp for
+ #pragma omp unroll partial partial /* { dg-error "too many 'partial' clauses" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp unroll full full /* { dg-error "too many 'full' clauses" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp unroll partial
+ #pragma omp unroll /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp for
+ #pragma omp unroll /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ int i;
+ #pragma omp for /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" "" { target *-*-* } .+1 } */
+ #pragma omp unroll( /* { dg-error "expected an OpenMP clause before '\\\(' token" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp for /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" "" { target *-*-* } .+1 } */
+ #pragma omp unroll foo /* { dg-error "expected an OpenMP clause before 'foo'" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp unroll partial( /* { dg-error "expected expression before end of line" "" { target c } } */
+ /* { dg-error "expected primary-expression before end of line" "" { target c++ } .-1 } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp unroll partial() /* { dg-error "expected expression before '\\\)' token" "" { target c } } */
+ /* { dg-error "expected primary-expression before '\\\)' token" "" { target c++ } .-1 } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp unroll partial(i)
+ /* { dg-error "the value of 'i' is not usable in a constant expression" "" { target c++ } .-1 } */
+ /* { dg-error "'partial' argument needs positive constant integer expression" "" { target *-*-* } .-2 } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp unroll parti /* { dg-error "expected an OpenMP clause before 'parti'" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp for
+ #pragma omp unroll partial(1) /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" "" { target *-*-* } .+1 } */
+ #pragma omp unroll parti /* { dg-error "expected an OpenMP clause before 'parti'" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ #pragma omp for
+ #pragma omp unroll partial(1) /* { dg-error "generated loop of 'unroll' construct without 'partial' clause does not have canonical form" "" { target *-*-* } .+1 } */
+ #pragma omp unroll parti /* { dg-error "expected an OpenMP clause before 'parti'" } */
+ for (int i = -300; i != 100; ++i)
+ dummy (i);
+
+ int sum = 0;
+ #pragma omp parallel for reduction(+ : sum) collapse(2)
+ #pragma omp unroll partial(1) /* { dg-error "'unroll' construct with 'partial' clause generates just one loop with canonical form but 2 loops are needed" } */
+ for (int i = 3; i < 10; ++i)
+ for (int j = -2; j < 7; ++j)
+ sum++;
+
+ #pragma omp unroll partial full /* { dg-error "'full' clause must not be used together with 'partial' clause" } */
+ for (int i = 0; i < 42; ++i)
+ dummy (i);
+
+ #pragma omp unroll full partial /* { dg-error "'full' clause must not be used together with 'partial' clause" } */
+ for (int i = 0; i < 42; ++i)
+ dummy (i);
+
+ #pragma omp unroll partial(7) full /* { dg-error "'full' clause must not be used together with 'partial' clause" } */
+ for (int i = 0; i < 42; ++i)
+ dummy (i);
+
+ #pragma omp unroll full partial(28) /* { dg-error "'full' clause must not be used together with 'partial' clause" } */
+ for (int i = 0; i < 42; ++i)
+ dummy (i);
+
+ #pragma omp unroll partial(0.5) /* { dg-error "'partial' argument needs positive constant integer expression" } */
+ for (int i = 0; i < 42; ++i)
+ dummy (i);
+
+ #pragma omp unroll partial(0) /* { dg-error "'partial' argument needs positive constant integer expression" } */
+ for (int i = 0; i < 42; ++i)
+ dummy (i);
+
+ #pragma omp unroll partial(-42) /* { dg-error "'partial' argument needs positive constant integer expression" } */
+ for (int i = 0; i < 42; ++i)
+ dummy (i);
+}
--- /dev/null
+/* { dg-additional-options "-O2 -fdump-tree-cunroll -fdump-tree-original -fdump-tree-gimple" } */
+
+extern void dummy (int);
+
+void
+test1 (void)
+{
+#pragma omp unroll full
+ for (int i = 0; i < 10; i++)
+ dummy (i);
+}
+
+/* Loop should be removed with 10 copies of the body remaining */
+/* { dg-final { scan-tree-dump-times "dummy" 10 "cunroll" } } */
+/* { dg-final { scan-tree-dump "#pragma omp unroll" "original" } } */
+/* { dg-final { scan-tree-dump-not "#pragma omp" "gimple" } } */
--- /dev/null
+/* { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple" } */
+
+extern void dummy (int);
+
+void
+test1 (void)
+{
+ int i;
+#pragma omp unroll
+ for (int i = 0; i < 96; i++)
+ dummy (i);
+}
+
+/* GCC unrolls the loop 8 times, but only during RTL optimizations. */
+/* { dg-final { scan-tree-dump "#pragma omp unroll" "original" } } */
+/* { dg-final { scan-tree-dump-not "#pragma omp" "gimple" } } */
+/* { dg-final { scan-tree-dump-times "dummy" 1 "gimple" } } */
+/* { dg-final { scan-assembler-times "dummy" 8 } } */
--- /dev/null
+/* { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple" } */
+
+extern void dummy (int);
+
+void
+test1 (void)
+{
+ int i;
+#pragma omp unroll partial
+ for (int i = 0; i < 96; i++)
+ dummy (i);
+}
+
+/* GCC uses partial(8) for this case. */
+/* { dg-final { scan-tree-dump "#pragma omp unroll" "original" } } */
+/* { dg-final { scan-tree-dump-not "#pragma omp" "gimple" } } */
+/* { dg-final { scan-tree-dump-times "dummy" 1 "gimple" } } */
+/* { dg-final { scan-assembler-times "dummy" 8 } } */
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O0 -fopenmp-simd" } */
+
+#include <stdio.h>
+
+#define ASSERT_EQ(var, val) \
+ do \
+ { \
+ if ((var) != (val)) \
+ { \
+ fprintf (stderr, "%s:%d: Unexpected value %d, expected %d\n", \
+ __FILE__, __LINE__, (var), (val)); \
+ __builtin_abort (); \
+ } \
+ } \
+ while (0)
+
+#define ASSERT_EQ_PTR(var, ptr) \
+ do \
+ { \
+ if ((var) != (ptr)) \
+ { \
+ fprintf (stderr, "%s:%d: Unexpected value %p, expected %p\n", \
+ __FILE__, __LINE__, (var), (ptr)); \
+ __builtin_abort (); \
+ } \
+ } \
+ while (0)
+
+int
+test1 (int data[10])
+{
+ int iter = 0;
+ int *i;
+
+ #pragma omp unroll partial(8)
+ for (i = data; i < data + 10; i++)
+ {
+ ASSERT_EQ (*i, data[iter]);
+ ASSERT_EQ_PTR (i, data + iter);
+ iter++;
+ }
+
+ return iter;
+}
+
+int
+test2 (int data[10])
+{
+ int iter = 0;
+ int *i;
+
+ #pragma omp unroll partial(8)
+ for (i = data; i < data + 10; i = i + 2)
+ {
+ ASSERT_EQ_PTR (i, data + 2 * iter);
+ ASSERT_EQ (*i, data[2 * iter]);
+ iter++;
+ }
+
+ return iter;
+}
+
+int
+test3 (int data[10])
+{
+ int iter = 0;
+ int *i;
+
+ #pragma omp unroll partial(8)
+ for (i = data; i <= data + 9; i = i + 2)
+ {
+ ASSERT_EQ (*i, data[2 * iter]);
+ iter++;
+ }
+
+ return iter;
+}
+
+int
+test4 (int data[10])
+{
+ int iter = 0;
+ int *i;
+ #pragma omp unroll partial(8)
+ for (i = data; i != data + 10; i = i + 1)
+ {
+ ASSERT_EQ (*i, data[iter]);
+ iter++;
+ }
+
+ return iter;
+}
+
+int
+test5 (int data[15])
+{
+ int iter = 0;
+ int *i;
+ #pragma omp unroll partial(7)
+ for (i = data + 14; i >= data + 5; i--)
+ {
+ ASSERT_EQ (*i, data[14 - iter]);
+ iter++;
+ }
+
+ return iter;
+}
+
+int
+test6 (int data[15])
+{
+ int iter = 0;
+ int *i;
+
+ #pragma omp unroll partial(7)
+ for (i = data + 14; i > data + 4; i--)
+ {
+ ASSERT_EQ (*i, data[14 - iter]);
+ iter++;
+ }
+
+ return iter;
+}
+
+int
+test7 (int data[10])
+{
+ int iter = 0;
+
+ #pragma omp unroll partial(7)
+ for (int *i = data + 14; i != data + 4; i--)
+ {
+ ASSERT_EQ (*i, data[14 - iter]);
+ iter++;
+ }
+
+ return iter;
+}
+
+int
+main ()
+{
+ int iter_count;
+ int data[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ int data2[15] = { -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
+ iter_count = test1 (data);
+ ASSERT_EQ (iter_count, 10);
+
+ iter_count = test2 (data);
+ ASSERT_EQ (iter_count, 5);
+
+ iter_count = test3 (data);
+ ASSERT_EQ (iter_count, 5);
+
+ iter_count = test4 (data);
+ ASSERT_EQ (iter_count, 10);
+
+ iter_count = test5 (data2);
+ ASSERT_EQ (iter_count, 10);
+
+ iter_count = test6 (data2);
+ ASSERT_EQ (iter_count, 10);
+
+ iter_count = test7 (data2);
+ ASSERT_EQ (iter_count, 10);
+}
--- /dev/null
+extern void dummy (int);
+int a[100];
+
+void
+test1 (void)
+{
+#pragma omp unroll full
+ for (int i = -20; i < 20; i += 6)
+ dummy (i);
+}
+
+void
+test2 (void)
+{
+#pragma omp unroll full
+ for (int *i = &a[6]; i < &a[78]; i += 4)
+ dummy (*i);
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test3 (int x)
+{
+#pragma omp unroll full /* { dg-error "non-constant iteration count of 'unroll full' loop" } */
+ for (int i = x; i < 20; i += 3)
+ dummy (i);
+}
+
+void
+test4 (int x)
+{
+#pragma omp unroll full /* { dg-error "non-constant iteration count of 'unroll full' loop" } */
+ for (int i = 5; i < x + 6; ++i)
+ dummy (i);
+}
+
+void
+test5 (int x)
+{
+#pragma omp unroll full /* { dg-error "non-constant iteration count of 'unroll full' loop" } */
+ for (int i = 5; i < 142; i += x)
+ dummy (i);
+}
--- /dev/null
+/* { dg-additional-options "-O2 -fdump-tree-gimple" } */
+
+void bar (int);
+
+void
+foo (void)
+{
+ #pragma omp unroll full
+ for (int i = 1; i <= 100; i += 6)
+ bar (i);
+}
+
+/* { dg-final { scan-tree-dump "\.ANNOTATE \\\(\[^\n\r]*, 1, 17\\\);" "gimple" } } */
--- /dev/null
+extern void dummy (int);
+
+void
+test (void)
+{
+ #pragma omp target parallel for collapse(2)
+ for (int i = -300; i != 100; ++i)
+ #pragma omp unroll partial
+ for (int j = 0; j != 100; ++j)
+ dummy (i);
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test (void)
+{
+ #pragma omp target parallel for collapse(2)
+ for (int i = -300; i != 100; ++i)
+ #pragma omp tile sizes(2)
+ for (int j = 0; j != 100; ++j)
+ dummy (i);
+
+ #pragma omp target parallel for collapse(2)
+ for (int i = -300; i != 100; ++i)
+ #pragma omp tile sizes(2, 3)
+ for (int j = 0; j != 100; ++j)
+ for (int k = 0; k != 100; ++k)
+ dummy (i);
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test (void)
+{
+ #pragma omp target parallel for collapse(2)
+ for (int i = -300; i != 100; ++i)
+ #pragma omp tile sizes(2, 3)
+ for (int j = 0; j != 100; ++j) /* { dg-error "not enough nested loops" } */
+ dummy (i);
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test1 (void)
+{
+ #pragma omp target parallel for collapse(3)
+ for (int i = -300; i != 100; ++i)
+ for (int j = i; j != i * 2; ++j)
+ #pragma omp unroll partial
+ for (int k = 2; k != 100; ++k)
+ dummy (i);
+
+ #pragma omp unroll full
+ for (int i = -300; i != 100; ++i)
+ for (int j = i; j != i * 2; ++j)
+ for (int k = 2; k != 100; ++k)
+ dummy (i);
+
+ for (int i = -300; i != 100; ++i)
+ #pragma omp unroll full
+ for (int j = i; j != i + 10; ++j)
+ for (int k = 2; k != 100; ++k)
+ dummy (i);
+
+ for (int i = -300; i != 100; ++i)
+ #pragma omp unroll full
+ for (int j = i; j != i + 10; ++j)
+ for (int k = j; k != 100; ++k)
+ dummy (i);
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test1 (void)
+{
+ #pragma omp target parallel for collapse(2)
+ for (int i = -300; i != 100; ++i)
+ #pragma omp unroll partial
+ for (int j = 2; j != i; ++j) /* { dg-message "non-rectangular loops from generated loops unsupported" } */
+ dummy (i);
+}
+
+void
+test2 (void)
+{
+ int i,j;
+ #pragma omp target parallel for collapse(2)
+ for (i = -300; i != 100; ++i)
+ #pragma omp unroll partial
+ for (j = 2; j != i; ++j) /* { dg-message "non-rectangular loops from generated loops unsupported" } */
+ dummy (i);
+}
--- /dev/null
+extern void dummy (int);
+
+void
+test1 (void)
+{
+ #pragma omp target parallel for collapse(2)
+ for (int i = -300; i != 100; ++i)
+ #pragma omp unroll partial(2)
+ for (int j = i * 2; j <= i * 4 + 1; ++j) /* { dg-message "non-rectangular loops from generated loops unsupported" } */
+ dummy (i);
+}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-fno-openmp -fopenmp-simd -fdump-tree-original -fdump-tree-gimple" } */
+
+int
+compute_sum1 (void)
+{
+ int sum = 0;
+ int i, j;
+
+ #pragma omp simd reduction(+:sum)
+ for (i = 3; i < 10; ++i)
+ #pragma omp unroll full
+ for (j = -2; j < 7; ++j)
+ sum++;
+
+ if (i != 10 || j != 7)
+ __builtin_abort ();
+
+ return sum;
+}
+
+int
+compute_sum2 (void)
+{
+ int sum = 0;
+ int i, j;
+
+ #pragma omp simd reduction(+:sum)
+ #pragma omp unroll partial(5)
+ for (i = 3; i < 10; ++i)
+ for (j = -2; j < 7; ++j)
+ sum++;
+
+ if (i != 10 || j != 7)
+ __builtin_abort ();
+
+ return sum;
+}
+
+int
+compute_sum3 (void)
+{
+ int sum = 0;
+ int i, j;
+
+ #pragma omp simd reduction(+:sum)
+ #pragma omp unroll partial(1)
+ for (i = 3; i < 10; ++i)
+ for (j = -2; j < 7; ++j)
+ sum++;
+
+ if (i != 10 || j != 7)
+ __builtin_abort ();
+
+ return sum;
+}
+
+int
+main ()
+{
+ if (compute_sum1 () != 7 * 9
+ || compute_sum2 () != 7 * 9
+ || compute_sum3 () != 7 * 9)
+ __builtin_abort ();
+
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump {omp unroll} "original" } } */
+/* { dg-final { scan-tree-dump-not {omp unroll} "gimple" } } */
for (int i = 0; i < 16; i++)
;
#pragma omp for
- [[omp::directive (master)]] // { dg-error "for statement expected before '\\\[' token" }
+ [[omp::directive (master)]] // { dg-error "loop nest expected before '\\\[' token" }
;
#pragma omp target teams
[[omp::directive (parallel)]] // { dg-error "mixing OpenMP directives with attribute and pragma syntax on the same statement" }
// Malformed parallel loops.
#pragma omp for
- i = 0; // { dg-error "for statement expected" }
+ i = 0; // { dg-error "loop nest expected" }
for ( ; i < 10; )
{
baz (i);
bar ()
{
#pragma omp parallel master taskloop
- foo (); // { dg-error "for statement expected before" }
+ foo (); // { dg-error "loop nest expected before" }
}
void
--- /dev/null
+// { dg-do compile { target c++11 } }
+
+#include <vector>
+
+extern void dummy (int);
+
+template<class T, int U, unsigned V> void
+test1_template ()
+{
+ std::vector<int> v;
+
+ for (unsigned i = 0; i < 10; i++)
+ v.push_back (i);
+
+#pragma omp teams distribute parallel for num_teams(V)
+ for (int i : v)
+ dummy (i);
+
+#pragma omp tile sizes (V, U)
+ for (T i : v)
+ for (T j : v)
+ for (T k : v)
+ dummy (i);
+}
+
+void
+test ()
+{
+ test1_template <long, 5, 3> ();
+};
--- /dev/null
+// { dg-do compile { target c++11 } }
+
+#include <vector>
+
+extern void dummy (int);
+
+template<class T, int U, unsigned V> void
+test1_template ()
+{
+ std::vector<int> v;
+
+ for (unsigned i = 0; i < 10; i++)
+ v.push_back (i);
+
+#pragma omp for
+ for (int i : v)
+ dummy (i);
+
+#pragma omp tile sizes (U, 10, V) // { dg-error "'sizes' argument needs positive integral constant" }
+ for (T i : v)
+ for (T j : v)
+ for (T k : v)
+ dummy (i);
+}
+
+void
+test ()
+{
+ test1_template <long, 5, 0> ();
+}
--- /dev/null
+// { dg-do compile { target c++11 } }
+
+#include <vector>
+
+extern void dummy (int);
+
+void
+test1 ()
+{
+ std::vector<int> v;
+
+ for (unsigned i = 0; i < 1000; i++)
+ v.push_back (i);
+
+ #pragma omp for
+ for (int i : v)
+ dummy (i);
+
+ #pragma omp unroll partial(5)
+ for (int i : v)
+ dummy (i);
+}
+
+void
+test2 ()
+{
+ std::vector<std::vector<int>> v;
+
+ for (unsigned i = 0; i < 10; i++)
+ {
+ std::vector<int> u;
+ for (unsigned j = 0; j < 10; j++)
+ u.push_back (j);
+ v.push_back (u);
+ }
+
+ #pragma omp for
+ #pragma omp unroll partial(5)
+ for (auto u : v)
+ for (int i : u)
+ dummy (i);
+}
--- /dev/null
+// { dg-do compile { target c++11 } }
+
+#include <vector>
+
+extern void dummy (int);
+
+template<class T, int U1, int U2, int U3> void
+test_template ()
+{
+ std::vector<int> v;
+
+ for (unsigned i = 0; i < 1000; i++)
+ v.push_back (i);
+
+#pragma omp for
+ for (int i : v)
+ dummy (i);
+
+#pragma omp unroll partial(U1)
+ for (T i : v)
+ dummy (i);
+
+#pragma omp unroll partial(U2) // { dg-error "'partial' argument needs positive constant integer expression" }
+ for (T i : v)
+ dummy (i);
+
+#pragma omp unroll partial(U3) // { dg-error "'partial' argument needs positive constant integer expression" }
+ for (T i : v)
+ dummy (i);
+
+#pragma omp for
+#pragma omp unroll partial(U1)
+ for (T i : v)
+ dummy (i);
+
+#pragma omp for
+#pragma omp unroll partial(U2) // { dg-error "'partial' argument needs positive constant integer expression" }
+ for (T i : v)
+ dummy (i);
+
+#pragma omp for
+#pragma omp unroll partial(U3) // { dg-error "'partial' argument needs positive constant integer expression" }
+ for (T i : v)
+ dummy (i);
+}
+
+void
+test ()
+{
+ test_template <long, 5,-2, 0> ();
+}
--- /dev/null
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-fdump-tree-original -fdump-tree-gimple" }
+
+#include <vector>
+
+extern void dummy (int);
+
+constexpr unsigned
+fib (unsigned n)
+{
+ return n <= 2 ? 1 : fib (n-1) + fib (n-2);
+}
+
+void
+test1 ()
+{
+ std::vector<int> v;
+
+ for (unsigned i = 0; i < 1000; i++)
+ v.push_back (i);
+
+#pragma omp unroll partial(fib(10))
+ for (int i : v)
+ dummy (i);
+}
+
+
+// Loop should be unrolled fib(10) = 55 times
+// { dg-final { scan-tree-dump {#pragma omp unroll partial\(55\)} "original" } }
+// { dg-final { scan-tree-dump-not "#pragma omp" "gimple" } }
for (int i = 0; i < 16; i++)
;
#pragma omp for
- [[omp::directive (master)]] /* { dg-error "for statement expected before '\\\[' token" } */
+ [[omp::directive (master)]] /* { dg-error "loop nest expected before '\\\[' token" } */
;
#pragma omp target teams
[[omp::directive (parallel)]] /* { dg-error "mixing OpenMP directives with attribute and pragma syntax on the same statement" } */
/* Malformed parallel loops. */
#pragma omp for
- i = 0; /* { dg-error "3:for statement expected" } */
+ i = 0; /* { dg-error "3:loop nest expected" } */
for ( ; i < 10; )
{
baz (i);
/* Malformed parallel loops. */
#pragma omp for
- i = 0; /* { dg-error "for statement expected" } */
+ i = 0; /* { dg-error "loop nest expected" } */
for ( ; i < 10; )
{
baz (i);
--- /dev/null
+subroutine test1
+ !$omp parallel do collapse(2)
+ do i=0,100
+ !$omp unroll partial(2)
+ do j=-300,100
+ call dummy (j)
+ end do
+ end do
+end subroutine test1
+
+subroutine test3
+ !$omp parallel do collapse(3)
+ do i=0,100
+ do j=-300,100
+ !$omp unroll partial(2)
+ do k=-300,100
+ call dummy (k)
+ end do
+ end do
+ end do
+end subroutine test3
+
+subroutine test6
+ !$omp parallel do collapse(3)
+ do i=0,100
+ !$omp tile sizes(3,2)
+ do j=-300,100
+ !$omp unroll partial(2)
+ do k=-300,100
+ call dummy (k)
+ end do
+ end do
+ end do
+end subroutine test6
+
+subroutine test7
+ !$omp parallel do collapse(3)
+ do i=0,100
+ !$omp tile sizes(3,3)
+ do j=-300,100
+ !$omp tile sizes(5)
+ do k=-300,100
+ call dummy (k)
+ end do
+ end do
+ end do
+end subroutine test7
+
+subroutine test8
+ !$omp parallel do collapse(1)
+ do i=0,100
+ !$omp tile sizes(3,3)
+ do j=-300,100
+ !$omp tile sizes(5)
+ do k=-300,100
+ call dummy (k)
+ end do
+ end do
+ end do
+end subroutine test8
--- /dev/null
+subroutine test2
+ !$omp parallel do collapse(3)
+ do i=0,100
+ !$omp unroll partial(2) ! { dg-error "UNROLL construct at \\\(1\\\) with PARTIAL clause generates just one loop with canonical form but 2 loops are needed" }
+ do j=-300,100
+ do k=-300,100
+ call dummy (k)
+ end do
+ end do
+ end do
+end subroutine test2
+
+subroutine test4
+ !$omp parallel do collapse(3)
+ do i=0,100
+ !$omp tile sizes(3) ! { dg-error "TILE construct at \\\(1\\\) generates 1 loops with canonical form but 2 loops are needed" }
+ do j=-300,100
+ !$omp unroll partial(2)
+ do k=-300,100
+ call dummy (k)
+ end do
+ end do
+ end do
+end subroutine test4
+
+subroutine test5
+ !$omp parallel do collapse(3)
+ !$omp tile sizes(3,2) ! { dg-error "TILE construct at \\\(1\\\) generates 2 loops with canonical form but 3 loops are needed" }
+ do i=0,100
+ do j=-300,100
+ do k=-300,100
+ call dummy (k)
+ end do
+ end do
+ end do
+end subroutine test5
+
+subroutine test9
+ !$omp parallel do collapse(3)
+ do i=0,100
+ !$omp tile sizes(3,3,3)
+ do j=-300,100
+ !$omp tile sizes(5) ! { dg-error "TILE construct at \\\(1\\\) generates 1 loops with canonical form but 2 loops are needed" }
+ do k=-300,100
+ call dummy (k)
+ end do
+ end do
+ end do
+end subroutine test9
+
+subroutine test10
+ !$omp parallel do
+ do i=0,100
+ !$omp tile sizes(3,3,3)
+ do j=-300,100
+ !$omp tile sizes(5) ! { dg-error "TILE construct at \\\(1\\\) generates 1 loops with canonical form but 2 loops are needed" }
+ do k=-300,100
+ call dummy (k)
+ end do
+ end do
+ end do
+end subroutine test10
end do
func_simd = r
end
+
+pure integer function func_unroll(n)
+ implicit none
+ integer, value :: n
+ integer :: j, r
+ r = 0
+ !$omp unroll partial(2)
+ do j = 1, n
+ r = r + j
+ end do
+ func_unroll = r
+end
+
+pure integer function func_tile(n)
+ implicit none
+ integer, value :: n
+ integer :: j, r
+ r = 0
+ !$omp tile sizes(2)
+ do j = 1, n
+ r = r + j
+ end do
+ func_tile = r
+end
end do
end
-!pure integer function func_unroll(n)
-integer function func_unroll(n)
- implicit none
- integer, value :: n
- integer :: j, r
- r = 0
- !$omp unroll partial(2) ! { dg-error "Unclassifiable OpenMP directive" }
- do j = 1, n
- r = r + j
- end do
- func_unroll = r
-end
-
-!pure integer function func_tile(n)
-integer function func_tile(n)
- implicit none
- integer, value :: n
- integer :: j, r
- r = 0
- !$omp tile sizes(2) ! { dg-error "Unclassifiable OpenMP directive" }
- do j = 1, n
- r = r + j
- end do
- func_tile = r
-end
--- /dev/null
+subroutine foo (c, d, a)
+ integer :: i, a, c(64), d(64)
+ !$omp do reduction (inscan, +: a)
+ !$omp tile sizes (2)
+ do i = 1, 64
+ a = a + c(i)
+ !$omp scan inclusive (a) ! { dg-error "Unexpected !\\\$OMP SCAN at \\\(1\\\) outside loop construct with 'inscan' REDUCTION clause" }
+ d(i) = a
+ end do
+end subroutine foo
+
+subroutine bar (c, d, a)
+ integer :: i, j, a, c(64, 64), d(64, 64)
+ !$omp do collapse (2) reduction (inscan, +: a)
+ do i = 1, 64
+ !$omp tile sizes (2)
+ do j = 1, 64
+ d(i, j) = a
+ !$omp scan exclusive (a) ! { dg-error "Unexpected !\\\$OMP SCAN at \\\(1\\\) outside loop construct with 'inscan' REDUCTION clause" }
+ a = a + c(i, j)
+ end do
+ end do
+end subroutine bar
+
+subroutine baz (c, d, a)
+ integer :: i, a, c(64), d(64)
+ !$omp do reduction (inscan, +: a)
+ !$omp unroll partial (2)
+ do i = 1, 64
+ d(i) = a
+ !$omp scan exclusive (a) ! { dg-error "Unexpected !\\\$OMP SCAN at \\\(1\\\) outside loop construct with 'inscan' REDUCTION clause" }
+ a = a + c(i)
+ end do
+end subroutine baz
+
+subroutine qux (c, d, a)
+ integer :: i, j, a, c(64, 64), d(64, 64)
+ !$omp do collapse (2) reduction (inscan, +: a)
+ do i = 1, 64
+ !$omp tile sizes (2)
+ do j = 1, 64
+ a = a + c(i, j)
+ !$omp scan inclusive (a) ! { dg-error "Unexpected !\\\$OMP SCAN at \\\(1\\\) outside loop construct with 'inscan' REDUCTION clause" }
+ d(i, j) = a
+ end do
+ end do
+end subroutine qux
--- /dev/null
+subroutine test
+ implicit none
+ integer :: i, j, k
+
+ !$omp tile sizes ( 1 )
+ do i = 1,100
+ call dummy(i)
+ end do
+
+ !$omp tile sizes(1)
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile
+
+ !$omp tile sizes(2+3)
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile
+
+ !$omp tile sizes(1,2)
+ do i = 1,100
+ do j = 1,100
+ call dummy(j)
+ end do
+ end do
+ !$omp end tile
+
+ !$omp tile sizes(1,2,1)
+ do i = 1,100
+ do j = 1,100
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test
--- /dev/null
+! It isn't really clear what is supposed to be valid and what isn't when mixing
+! imperfectly nested loops with generated loops. Sorry for now until that is
+! clarified.
+
+subroutine bar
+ integer :: i, j
+ !$omp do collapse(2)
+ do i = 0, 31
+ call foo (i, -1)
+ !$omp tile sizes (2) ! { dg-message "Imperfectly nested loop using generated loops" }
+ do j = 0, 31
+ call foo (i, j)
+ end do
+ call foo (i, -2)
+ end do
+end subroutine bar
+
+subroutine baz
+ integer :: i, j, k, l
+ !$omp do collapse(2)
+ do i = 0, 31
+ call foo (i, -1)
+ !$omp tile sizes (2, 2) ! { dg-message "Imperfectly nested loop using generated loops" }
+ do j = 0, 31
+ !$omp tile sizes (2, 2)
+ do k = 0, 31
+ do l = 0, 31
+ call foo (i + k, j + l)
+ end do
+ end do
+ end do
+ call foo (i, -2)
+ end do
+end subroutine baz
+
+subroutine qux
+ integer :: i, j, k, l, m
+ !$omp do collapse(2)
+ do i = 0, 31
+ m = i + 6
+ call foo (i, -1)
+ !$omp tile sizes (2) ! { dg-message "Imperfectly nested loop using generated loops" }
+ do j = m, 31
+ call foo (i, j)
+ end do
+ call foo (i, -2)
+ end do
+end subroutine qux
+
+subroutine freddy
+ integer :: i, j, k, l, m
+ !$omp do collapse(2)
+ do i = 0, 31
+ block
+ integer :: m
+ m = i + 6
+ call foo (i, -1)
+ !$omp tile sizes (2, 2) ! { dg-message "Imperfectly nested loop using generated loops" }
+ do j = 0, 31
+ !$omp tile sizes (2, 2)
+ do k = 0, 31
+ do l = m, 31
+ call foo (i + k, j + l)
+ end do
+ end do
+ end do
+ call foo (i, -2)
+ end block
+ end do
+end subroutine freddy
--- /dev/null
+subroutine test1
+ implicit none
+ integer :: i, j, k
+
+ !$omp tile sizes (1,2)
+ !$omp tile sizes (1,2)
+ do i = 1,100
+ do j = 1,100
+ call dummy(j)
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+
+ !$omp tile sizes (8)
+ !$omp tile sizes (1,2)
+ !$omp tile sizes (1,2,3)
+ do i = 1,100
+ do j = 1,100
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test1
+
+subroutine test2
+ implicit none
+ integer :: i, j, k
+
+ !$omp taskloop collapse(2)
+ !$omp tile sizes (3,4)
+ !$omp tile sizes (1,2)
+ do i = 1,100
+ do j = 1,100
+ call dummy(j)
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+ !$omp end taskloop
+
+ !$omp taskloop simd
+ !$omp tile sizes (8)
+ !$omp tile sizes (1,2)
+ !$omp tile sizes (1,2,3)
+ do i = 1,100
+ do j = 1,100
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+ !$omp end taskloop simd
+end subroutine test2
--- /dev/null
+subroutine test
+ implicit none
+ integer :: i, j, k
+
+ !$omp parallel do collapse(2) ordered(2) ! { dg-error "'ordered' clause used with generated loops" }
+ !$omp tile sizes (1,2)
+ do i = 1,100
+ do j = 1,100
+ call dummy(j)
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+ !$omp end parallel do
+end subroutine test
--- /dev/null
+subroutine test1
+ implicit none
+ integer :: i, j, k
+
+ !$omp tile sizes (1,2)
+ !$omp tile sizes (1) ! { dg-error "TILE construct at \\\(1\\\) generates 1 loops with canonical form but 2 loops are needed" }
+ do i = 1,100
+ do j = 1,100
+ call dummy(j)
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test1
+
+subroutine test2
+ implicit none
+ integer :: i, j, k
+
+ !$omp tile sizes (1,2)
+ !$omp tile sizes (1) ! { dg-error "TILE construct at \\\(1\\\) generates 1 loops with canonical form but 2 loops are needed" }
+ do i = 1,100
+ do j = 1,100
+ call dummy(j)
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test2
+
+subroutine test3
+ implicit none
+ integer :: i, j, k
+
+ !$omp target teams distribute
+ !$omp tile sizes (1,2)
+ !$omp tile sizes (1) ! { dg-error "TILE construct at \\\(1\\\) generates 1 loops with canonical form but 2 loops are needed" }
+ do i = 1,100
+ do j = 1,100
+ call dummy(j)
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test3
+
+subroutine test4
+ implicit none
+ integer :: i, j, k
+
+ !$omp target teams distribute collapse(2)
+ !$omp tile sizes (8) ! { dg-error "TILE construct at \\\(1\\\) generates 1 loops with canonical form but 2 loops are needed" }
+ !$omp tile sizes (1,2)
+ do i = 1,100
+ do j = 1,100
+ call dummy(j)
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test4
+
+subroutine test5
+ implicit none
+ integer :: i, j, k
+
+ !$omp parallel do collapse(2) ordered(2)
+ !$omp tile sizes (8) ! { dg-error "TILE construct at \\\(1\\\) generates 1 loops with canonical form but 2 loops are needed" }
+ !$omp tile sizes (1,2)
+ do i = 1,100
+ do j = 1,100
+ call dummy(j)
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+ !$omp end tile
+ !$omp end parallel do
+end subroutine test5
--- /dev/null
+subroutine test
+ implicit none
+ integer :: i, j, k, l, m, n, o
+ !$omp do private (i, j, k, l)
+ !$omp tile sizes(2, 3)
+ !$omp tile sizes(3, 4, 5)
+ !$omp tile sizes(6, 7, 8, 9)
+ do i = 1, 100
+ do j = 1, 100
+ do k = 1, 100
+ do l = 1, 100
+ call dummy(i)
+ end do
+ end do
+ end do
+ end do
+
+ !$omp do private (i, j, k, l, m, n)
+ !$omp tile sizes(2, 3)
+ do i = 1, 100
+ !$omp tile sizes(3, 4, 5)
+ do j = 1, 100
+ !$omp tile sizes(6, 7, 8, 9)
+ do k = 1, 100
+ do l = 1, 100
+ do m = 1, 100
+ !$omp unroll partial(2)
+ do n = 1, 100
+ call dummy(i)
+ end do
+ end do
+ end do
+ end do
+ end do
+ end do
+
+ !$omp do collapse(2) private (i, j, k, l, m)
+ do i = 1, 100
+ !$omp tile sizes(2, 3)
+ !$omp tile sizes(3, 4, 5)
+ !$omp tile sizes(6, 7, 8, 9)
+ do j = 1, 100
+ do k = 1, 100
+ do l = 1, 100
+ do m = 1, 100
+ call dummy(i)
+ end do
+ end do
+ end do
+ end do
+ end do
+
+ !$omp do private (i, j, k, l, m, n, o) collapse(2)
+ do i = 1, 100
+ !$omp tile sizes(2, 3)
+ do j = 1, 100
+ !$omp tile sizes(3, 4, 5)
+ do k = 1, 100
+ !$omp tile sizes(6, 7, 8, 9)
+ do l = 1, 100
+ do m = 1, 100
+ do n = 1, 100
+ !$omp unroll partial(2)
+ do o = 1, 100
+ call dummy(i)
+ end do
+ end do
+ end do
+ end do
+ end do
+ end do
+ end do
+end subroutine test
--- /dev/null
+subroutine test
+ !$omp tile sizes(1,2,1) ! { dg-error "not enough DO loops for collapsed !\\\$OMP TILE" }
+ do i = 1,100
+ do j = 1,100
+ call dummy(i)
+ end do
+ end do
+ !$omp end tile
+end subroutine test
--- /dev/null
+subroutine test
+ implicit none
+ integer :: i, j, k
+
+ !$omp tile sizes(-21) ! { dg-error "INTEGER expression of SIZES clause at \\\(1\\\) must be positive" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile
+
+ !$omp tile sizes(0) ! { dg-error "INTEGER expression of SIZES clause at \\\(1\\\) must be positive" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile
+
+ !$omp tile sizes(i) ! { dg-error "SIZES requires constant expression" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile
+
+ !$omp tile sizes ! { dg-error "Expected '\\\(' after 'sizes' at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile ! { dg-error "Unexpected !\\\$OMP END TILE statement at \\\(1\\\)" }
+
+ !$omp tile sizes( ! { dg-error "Syntax error in OpenMP expression list at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile ! { dg-error "Unexpected !\\\$OMP END TILE statement at \\\(1\\\)" }
+
+ !$omp tile sizes(2 ! { dg-error "Syntax error in OpenMP expression list at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile ! { dg-error "Unexpected !\\\$OMP END TILE statement at \\\(1\\\)" }
+
+ !$omp tile sizes() ! { dg-error "Syntax error in OpenMP expression list at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile ! { dg-error "Unexpected !\\\$OMP END TILE statement at \\\(1\\\)" }
+
+ !$omp tile sizes(2,) ! { dg-error "Syntax error in OpenMP expression list at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile ! { dg-error "Unexpected !\\\$OMP END TILE statement at \\\(1\\\)" }
+
+ !$omp tile sizes(,2) ! { dg-error "Syntax error in OpenMP expression list at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile ! { dg-error "Unexpected !\\\$OMP END TILE statement at \\\(1\\\)" }
+
+ !$omp tile sizes(,i) ! { dg-error "Syntax error in OpenMP expression list at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile ! { dg-error "Unexpected !\\\$OMP END TILE statement at \\\(1\\\)" }
+
+ !$omp tile sizes(i,) ! { dg-error "Syntax error in OpenMP expression list at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile ! { dg-error "Unexpected !\\\$OMP END TILE statement at \\\(1\\\)" }
+
+ !$omp tile sizes(1,2) ! { dg-error "not enough DO loops for collapsed !\\\$OMP TILE" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end tile
+
+ !$omp tile sizes(1,2,1) ! { dg-error "not enough DO loops for collapsed !\\\$OMP TILE" }
+ do i = 1,100
+ do j = 1,100
+ call dummy(i)
+ end do
+ end do
+ !$omp end tile
+
+ !$omp tile sizes(1,2,1) ! { dg-error "!\\\$OMP TILE inner loops must be perfectly nested at \\\(1\\\)" }
+ do i = 1,100
+ do j = 1,100
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ call dummy(i)
+ end do
+ !$omp end tile
+
+ !$omp tile sizes(1,2,1) ! { dg-error "!\\\$OMP TILE inner loops must be perfectly nested at \\\(1\\\)" }
+ do i = 1,100
+ do j = 1,100
+ do k = 1,100
+ call dummy(i)
+ end do
+ call dummy(j)
+ end do
+ end do
+ !$omp end tile
+
+ !$omp tile sizes(1,2,1) ! { dg-error "!\\\$OMP TILE inner loops must be perfectly nested at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ do j = 1,100
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+
+ !$omp tile sizes(1,2,1) ! { dg-error "!\\\$OMP TILE inner loops must be perfectly nested at \\\(1\\\)" }
+ do i = 1,100
+ do j = 1,100
+ call dummy(j)
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test
--- /dev/null
+subroutine test3
+ implicit none
+ integer :: i, j, k
+
+ !$omp taskloop collapse(3)
+ !$omp tile sizes (1,2) ! { dg-error "TILE construct at \\\(1\\\) generates 2 loops with canonical form but 3 loops are needed" }
+ !$omp tile sizes (1,2)
+ do i = 1,100
+ do j = 1,100
+ call dummy(j)
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+ !$omp end taskloop
+end subroutine test3
--- /dev/null
+subroutine test1
+ integer :: i, j, k, l
+ !$omp do collapse(4) private (i, j, k, l)
+ do i = 0, 1023 ! { dg-error "cannot be redefined inside loop" }
+ !$omp tile sizes (2, 2, 2)
+ do j = 0, 1023
+ !$omp tile sizes (3, 3)
+ do k = 0, 1023
+ !$omp tile sizes (4)
+ do i = 0, 1023 ! { dg-error "!\\\$OMP DO iteration variable used in more than one loop" }
+ end do ! { dg-error "cannot be redefined inside loop" "" { target *-*-* } .-1 }
+ end do
+ end do
+ end do
+end subroutine test1
+
+subroutine test2
+ integer(kind=8) :: i
+ integer :: j, k, l
+ !$omp do collapse(4) private (i, j, k, l)
+ do i = 0, 1023
+ !$omp tile sizes (2, 2, 2)
+ do j = 0, 1023
+ !$omp tile sizes (3, 3)
+ do k = 0, 1023
+ !$omp tile sizes (4)
+ do l = i, 1023 ! { dg-error "!\\\$OMP DO loop start expression not in canonical form" }
+ end do
+ end do
+ end do
+ end do
+end subroutine test2
+
+subroutine test3
+ integer :: i, j, k, l
+ !$omp do collapse(4) private (i, j, k, l)
+ do i = 0, 1023
+ !$omp tile sizes (2, 2, 2)
+ do j = 0, 1023
+ !$omp tile sizes (3, 3)
+ do k = 0, 1023
+ !$omp tile sizes (4)
+ do l = 0, 7 * i * i ! { dg-error "!\\\$OMP DO loop end expression not in canonical form" }
+ end do
+ end do
+ end do
+ end do
+end subroutine test3
+
+subroutine test4
+ integer :: i, j, k, l
+ !$omp do collapse(4) private (i, j, k, l)
+ do i = 0, 1023
+ !$omp tile sizes (2, 2, 2)
+ do j = 0, 1023
+ !$omp tile sizes (3, 3)
+ do k = 0, 1023
+ !$omp tile sizes (4)
+ do l = i * i, 1023 ! { dg-error "!\\\$OMP DO loop start expression not in canonical form" }
+ end do
+ end do
+ end do
+ end do
+end subroutine test4
+
+subroutine test5
+ integer :: i, j, k, l
+ !$omp do collapse(4) private (i, j, k, l)
+ do i = 0, 1023
+ !$omp tile sizes (2, 2, 2)
+ do j = 0, 1023
+ !$omp tile sizes (3, 3)
+ do k = 0, 1023
+ !$omp tile sizes (4)
+ do l = 0, 1023, j ! { dg-error "!\\\$OMP TILE loop increment not in canonical form" }
+ end do
+ end do
+ end do
+ end do
+end subroutine test5
+
+subroutine test6
+ integer :: i, j, k, l
+ !$omp do collapse(4) private (i, j, k, l)
+ do i = 0, 1023
+ !$omp tile sizes (2, 2, 2)
+ do j = 0, 1023
+ !$omp tile sizes (3, 3)
+ do k = 0, 1023
+ !$omp tile sizes (4)
+ do l = 0, i - 2 ! { dg-message "Non-rectangular loops from generated loops unsupported" }
+ end do
+ end do
+ end do
+ end do
+end subroutine test6
--- /dev/null
+subroutine test0
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+ !$omp parallel do collapse(2) private(inner)
+ !$omp tile sizes (8, 1)
+ do i = 1,m
+ !$omp tile sizes (8, 1)
+ do j = 1,n
+ !$omp unroll partial(10)
+ do k = 1, n
+ if (k == 1) then
+ inner = 0
+ endif
+ end do
+ end do
+ end do
+end subroutine test0
--- /dev/null
+subroutine test0m
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+ !$omp parallel do collapse(2) private(inner)
+ do i = 1,m
+ !$omp tile sizes (8, 1) ! { dg-error "!\\\$OMP TILE inner loops must be perfectly nested" }
+ do j = 1,n
+ do k = 1, n
+ if (k == 1) then
+ inner = 0
+ endif
+ inner = inner + a(k, i) * b(j, k)
+ end do
+ c(j, i) = inner
+ end do
+ end do
+end subroutine test0m
+
+subroutine test1
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+ !$omp parallel do collapse(2) private(inner)
+ !$omp tile sizes (8, 1)
+ do i = 1,m
+ !$omp tile sizes (8, 1) ! { dg-error "!\\\$OMP TILE inner loops must be perfectly nested" }
+ do j = 1,n
+ !$omp unroll partial(10)
+ do k = 1, n
+ if (k == 1) then
+ inner = 0
+ endif
+ inner = inner + a(k, i) * b(j, k)
+ end do
+ c(j, i) = inner
+ end do
+ end do
+end subroutine test1
+
+subroutine test2
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+ !$omp parallel do collapse(2) private(inner)
+ !$omp tile sizes (8, 1)
+ do i = 1,m
+ !$omp tile sizes (8, 1) ! { dg-error "!\\\$OMP TILE inner loops must be perfectly nested" }
+ do j = 1,n
+ do k = 1, n
+ if (k == 1) then
+ inner = 0
+ endif
+ inner = inner + a(k, i) * b(j, k)
+ end do
+ c(j, i) = inner
+ end do
+ end do
+end subroutine test2
+
+subroutine test3
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+ !$omp parallel do collapse(2) private(inner)
+ do i = 1,m
+ !$omp tile sizes (8, 1) ! { dg-error "!\\\$OMP TILE inner loops must be perfectly nested" }
+ do j = 1,n
+ do k = 1, n
+ if (k == 1) then
+ inner = 0
+ endif
+ inner = inner + a(k, i) * b(j, k)
+ end do
+ c(j, i) = inner
+ end do
+ end do
+end subroutine test3
--- /dev/null
+! { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple" }
+
+subroutine test1
+ !$omp parallel do collapse(2)
+ do i=0,100
+ !$omp tile sizes(4)
+ do j=-300,100
+ call dummy (j)
+ end do
+ end do
+end subroutine test1
+
+! Collapse of the gimple_omp_for should be unaffacted by the transformation
+! { dg-final { scan-tree-dump-times "#pragma omp for nowait collapse\\\(2\\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma omp tile sizes\\\(4\\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma omp for nowait collapse\\\(2\\\)\[\n\r\]+ +for \\\(i = 0; i <= 100; i = i \\\+ 1\\\)\[\n\r\]+ +for \\\(j.\\\d = -300; j.\\\d <= 100; j.\\\d = j.\\\d \\\+ 4\\\)" 1 "gimple" } }
--- /dev/null
+! { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple" }
+
+subroutine test2
+ !$omp parallel do
+ !$omp tile sizes(3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(3,3)
+ do k=-300,100
+ do l=0,100
+ call dummy (l)
+ end do
+ end do
+ end do
+ end do
+end subroutine test2
+
+! { dg-final { scan-tree-dump-times "#pragma omp for nowait" 1 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma omp tile sizes\\\(3, 3\\\)" 2 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma omp for nowait\[\n\r\]+ +for \\\(i.\\\d = 0; i.\\\d <= 100; i.\\\d = i.\\\d \\\+ 3\\\)" 1 "gimple" } }
--- /dev/null
+! { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple" }
+
+subroutine test3
+ !$omp parallel do
+ !$omp tile sizes(3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(3,3)
+ do k=-300,100
+ do l=0,100
+ call dummy (l)
+ end do
+ end do
+ end do
+ end do
+end subroutine test3
+
+! { dg-final { scan-tree-dump-times "#pragma omp for nowait" 1 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma omp tile sizes\\\(3, 3, 3\\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma omp tile sizes\\\(3, 3\\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-not "#pragma omp tile" "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp for nowait\[\n\r\]+ +for \\\(i.\\\d = 0; i.\\\d <= 100; i.\\\d = i.\\\d \\\+ 3\\\)" 1 "gimple" } }
--- /dev/null
+subroutine test3
+ !$omp parallel do
+ !$omp tile sizes(3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(3,3)
+ do k=-300,100
+ do l=0,100
+ call dummy (l)
+ end do
+ end do
+ end do
+ end do
+end subroutine test3
--- /dev/null
+subroutine test1a
+ !$omp parallel do
+ !$omp tile sizes(3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(5)
+ do k=-300,100
+ call dummy (k)
+ end do
+ end do
+ end do
+end subroutine test1a
+
+subroutine test2a
+ !$omp parallel do
+ !$omp tile sizes(3,3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(5,5)
+ do k=-300,100
+ do l=-300,100
+ do m=-300,100
+ call dummy (m)
+ end do
+ end do
+ end do
+ end do
+ end do
+end subroutine test2a
+
+subroutine test1b
+ !$omp parallel do
+ !$omp tile sizes(3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(5)
+ do k=-300,100
+ call dummy (k)
+ end do
+ end do
+ end do
+end subroutine test1b
+
+subroutine test2b
+ !$omp parallel do
+ !$omp tile sizes(3,3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(5,5)
+ do k=-300,100
+ do l=-300,100
+ do m=-300,100
+ call dummy (m)
+ end do
+ end do
+ end do
+ end do
+ end do
+end subroutine test2b
--- /dev/null
+subroutine test
+ !$omp tile sizes(3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(3,3)
+ do k=-300,100
+ do l=0,100
+ call dummy (l)
+ end do
+ end do
+ end do
+ end do
+end subroutine test
--- /dev/null
+subroutine test3
+ !$omp tile sizes(3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(3,3)
+ do k=-300,100
+ do l=0,100
+ call dummy (l)
+ end do
+ end do
+ end do
+ end do
+end subroutine test3
--- /dev/null
+subroutine test3a
+ !$omp parallel do
+ !$omp tile sizes(3,3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(5) ! { dg-error "TILE construct at \\\(1\\\) generates 1 loops with canonical form but 2 loops are needed" }
+ do k=-300,100
+ do l=-300,100
+ call dummy (l)
+ end do
+ end do
+ end do
+ end do
+end subroutine test3a
+
+subroutine test4a
+ !$omp parallel do
+ !$omp tile sizes(3,3,3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(5,5) ! { dg-error "TILE construct at \\\(1\\\) generates 2 loops with canonical form but 3 loops are needed" }
+ do k=-300,100
+ do l=-300,100
+ do m=-300,100
+ call dummy (m)
+ end do
+ end do
+ end do
+ end do
+ end do
+end subroutine test4a
+
+subroutine test3b
+ !$omp parallel do
+ !$omp tile sizes(3,3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(5) ! { dg-error "TILE construct at \\\(1\\\) generates 1 loops with canonical form but 2 loops are needed" }
+ do k=-300,100
+ do l=-300,100
+ call dummy (l)
+ end do
+ end do
+ end do
+ end do
+end subroutine test3b
+
+subroutine test4b
+ !$omp parallel do
+ !$omp tile sizes(3,3,3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp tile sizes(5,5) ! { dg-error "TILE construct at \\\(1\\\) generates 2 loops with canonical form but 3 loops are needed" }
+ do k=-300,100
+ do l=-300,100
+ do m=-300,100
+ call dummy (m)
+ end do
+ end do
+ end do
+ end do
+ end do
+end subroutine test4b
--- /dev/null
+subroutine test1
+ !$omp tile sizes(1)
+ do i = 1,100
+ do j = 1,i
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test1
+
+subroutine test5
+ !$omp tile sizes(1,2)
+ do i = 1,100
+ do j = 1,100
+ do k = 1,j
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test5
--- /dev/null
+subroutine test
+ !$omp tile sizes(1,2,1) ! { dg-error "non-rectangular 'tile'" }
+ do i = 1,100
+ do j = 1,100
+ do k = 1,i
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$end omp tile
+end subroutine test
--- /dev/null
+subroutine test2
+ !$omp tile sizes(1,2) ! { dg-error "non-rectangular 'tile'" }
+ do i = 1,100
+ do j = 1,i
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test2
+
+subroutine test3
+ !$omp tile sizes(1,2,1) ! { dg-error "non-rectangular 'tile'" }
+ do i = 1,100
+ do j = 1,i
+ do k = 1,100
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test3
+
+subroutine test4
+ !$omp tile sizes(1,2,1) ! { dg-error "non-rectangular 'tile'" }
+ do i = 1,100
+ do j = 1,100
+ do k = 1,i
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test4
+
+subroutine test6
+ !$omp tile sizes(1,2,1) ! { dg-error "non-rectangular 'tile'" }
+ do i = 1,100
+ do j = 1,100
+ do k = 1,j
+ call dummy(i)
+ end do
+ end do
+ end do
+ !$omp end tile
+end subroutine test6
--- /dev/null
+function mult (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c( n, m ))
+
+ !$omp tile sizes (8)
+ !$omp unroll partial(1)
+ do i = 1,m
+ do j = 1,n
+ inner = 0
+ do k = 1, n
+ inner = inner + a(k, i) * b(j, k)
+ end do
+ c(j, i) = inner
+ end do
+ end do
+end function mult
--- /dev/null
+function mult (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c( n, m ))
+
+ !$omp parallel do collapse(2)
+ !$omp tile sizes (8,8)
+ !$omp unroll partial(2) ! { dg-error "UNROLL construct at \\\(1\\\) with PARTIAL clause generates just one loop with canonical form but 2 loops are needed" }
+ do i = 1,m
+ do j = 1,n
+ inner = 0
+ do k = 1, n
+ inner = inner + a(k, i) * b(j, k)
+ end do
+ c(j, i) = inner
+ end do
+ end do
+
+ !$omp tile sizes (8,8)
+ !$omp unroll partial(2) ! { dg-error "UNROLL construct at \\\(1\\\) with PARTIAL clause generates just one loop with canonical form but 2 loops are needed" }
+ do i = 1,m
+ do j = 1,n
+ inner = 0
+ do k = 1, n
+ inner = inner + a(k, i) * b(j, k)
+ end do
+ c(j, i) = inner
+ end do
+ end do
+
+ !$omp parallel do collapse(2)
+ !$omp tile sizes (8,8)
+ !$omp unroll full ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,m
+ do j = 1,n
+ inner = 0
+ do k = 1, n
+ inner = inner + a(k, i) * b(j, k)
+ end do
+ c(j, i) = inner
+ end do
+ end do
+end function mult
--- /dev/null
+subroutine test16
+ implicit none
+ integer :: i
+
+ !$omp do
+ !$omp unroll partial(1)
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test16
+
+subroutine test17
+ implicit none
+ integer :: i
+
+ !$omp do
+ !$omp unroll partial(2)
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test17
+
+subroutine test20
+ implicit none
+ integer :: i
+
+ !$omp do
+ !$omp unroll partial
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test20
--- /dev/null
+subroutine test(i)
+ !$omp unroll full
+ call dummy0 ! { dg-error "Unexpected CALL statement at \\\(1\\\)" }
+end subroutine test ! { dg-error "Unexpected END statement at \\\(1\\\)" }
+
+! { dg-error "Unexpected end of file" "" { target "*-*-*" } 0 }
--- /dev/null
+subroutine test1(i)
+ implicit none
+ integer :: i
+ !$omp unroll
+ !$omp unroll full ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,10
+ call dummy(i)
+ end do
+end subroutine test1
+
+subroutine test2(i)
+ implicit none
+ integer :: i
+ !$omp unroll full
+ !$omp unroll full ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,10
+ call dummy(i)
+ end do
+end subroutine test2
+
+subroutine test3(i)
+ implicit none
+ integer :: i
+ !$omp unroll full
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ !$omp unroll full ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,10
+ call dummy(i)
+ end do
+end subroutine test3
+
+subroutine test4(i)
+ implicit none
+ integer :: i
+ !$omp do
+ !$omp unroll full ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,10
+ call dummy(i)
+ end do
+end subroutine test4
+
+subroutine test5(i)
+ implicit none
+ integer :: i
+ !$omp do
+ !$omp unroll full ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,10
+ call dummy(i)
+ end do
+end subroutine test5
+
+subroutine test6(i)
+ implicit none
+ integer :: i
+ !$omp do
+ !$omp unroll full ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,10
+ call dummy(i)
+ end do
+end subroutine test6
+
+subroutine test7(i)
+ implicit none
+ integer :: i
+ !$omp loop
+ !$omp unroll full ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,10
+ call dummy(i)
+ end do
+end subroutine test7
--- /dev/null
+subroutine test1
+ implicit none
+ integer :: i
+ !$omp unroll
+ do while (i < 10) ! { dg-error "!\\\$OMP UNROLL cannot be a DO WHILE or DO without loop control at \\\(1\\\)" }
+ call dummy(i)
+ i = i + 1
+ end do
+end subroutine test1
+
+subroutine test2
+ implicit none
+ integer :: i
+ !$omp unroll
+ do ! { dg-error "!\\\$OMP UNROLL cannot be a DO WHILE or DO without loop control at \\\(1\\\)" }
+ call dummy(i)
+ i = i + 1
+ if (i >= 10) exit
+ end do
+end subroutine test2
+
+subroutine test3
+ implicit none
+ integer :: i
+ !$omp unroll
+ do concurrent (i=1:10) ! { dg-error "!\\\$OMP UNROLL cannot be a DO CONCURRENT loop at \\\(1\\\)" }
+ call dummy(i) ! { dg-error "Subroutine call to 'dummy' in DO CONCURRENT block at \\\(1\\\) is not PURE" }
+ end do
+end subroutine test3
--- /dev/null
+subroutine foo
+ integer :: i, j
+ !$omp do collapse(2)
+ do i = 1, 512
+ !$omp unroll partial (3)
+ do j = 1, 512
+ end do
+ !$omp end unroll
+ end do
+ !$omp end do
+end subroutine foo
+
+subroutine bar
+ integer :: i, j
+ !$omp do collapse(2)
+ do i = 1, 512
+ !$omp unroll partial (3)
+ do j = 1, 512
+ end do
+ end do
+ !$omp end do
+end subroutine bar
+
+subroutine baz
+ integer :: i, j
+ !$omp do collapse(2)
+ do i = 1, 512
+ !$omp unroll partial (3)
+ do j = 1, 512
+ end do
+ !$omp end unroll
+ end do
+end subroutine baz
+
+subroutine qux
+ integer :: i, j
+ !$omp do collapse(2)
+ do i = 1, 512
+ !$omp unroll partial (3)
+ do j = 1, 512
+ end do
+ end do
+end subroutine qux
--- /dev/null
+! { dg-additional-options "-fdump-tree-original" }
+
+subroutine test1
+ implicit none
+ integer :: i
+ !$omp unroll
+ do i = 1,10
+ call dummy(i)
+ end do
+end subroutine test1
+
+subroutine test2
+ implicit none
+ integer :: i
+ !$omp unroll full
+ do i = 1,10
+ call dummy(i)
+ end do
+end subroutine test2
+
+! { dg-final { scan-tree-dump-times "#pragma omp unroll" 2 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma omp unroll full" 1 "original" } }
--- /dev/null
+! { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple" }
+
+subroutine test1
+ implicit none
+ integer :: i
+ !$omp unroll full
+ do i = 1,10
+ call dummy(i)
+ end do
+end subroutine test1
+
+! Loop should be removed with 10 copies of the body remaining
+! { dg-final { scan-tree-dump "#pragma omp unroll full" "original" } }
+! { dg-final { scan-tree-dump-not "#pragma omp" "gimple" } }
+! { dg-final { scan-tree-dump "\.ANNOTATE \\\(\[^\n\r\]*, 1, 10\\\);" "gimple" } }
--- /dev/null
+! { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple" }
+
+subroutine test1
+ implicit none
+ integer :: i
+ !$omp unroll
+ do i = 1,100
+ call dummy(i)
+ end do
+end subroutine test1
+
+! { dg-final { scan-tree-dump "#pragma omp unroll" "original" } }
+! { dg-final { scan-tree-dump-not "#pragma omp" "gimple" } }
+! { dg-final { scan-tree-dump-times "dummy" 1 "gimple" } }
+! { dg-final { scan-tree-dump "\.ANNOTATE \\\(\[^\n\r\]*, 1, 8\\\);" "gimple" } }
--- /dev/null
+! { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple" }
+
+subroutine test1
+ implicit none
+ integer :: i
+ !$omp unroll partial
+ do i = 1,100
+ call dummy(i)
+ end do
+end subroutine test1
+
+! { dg-final { scan-tree-dump "#pragma omp unroll partial" "original" } }
+! { dg-final { scan-tree-dump-not "#pragma omp" "gimple" } }
+! { dg-final { scan-tree-dump "\.ANNOTATE \\\(\[^\n\r\]*, 1, 8\\\);" "gimple" } }
--- /dev/null
+subroutine test1
+ implicit none
+ integer :: i
+
+ !$omp do
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+end subroutine test1
+
+subroutine test2
+ implicit none
+ integer :: i
+
+ !$omp do
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test2
+
+subroutine test3
+ implicit none
+ integer :: i
+
+ !$omp do
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end do
+end subroutine test3
+
+subroutine test4
+ implicit none
+ integer :: i
+
+ !$omp do
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+ !$omp end do
+end subroutine test4
+
+subroutine test5
+ implicit none
+ integer :: i
+
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+end subroutine test5
+
+subroutine test6
+ implicit none
+ integer :: i
+
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test6
+
+subroutine test7
+ implicit none
+ integer :: i
+
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test7
+
+subroutine test8
+ implicit none
+ integer :: i
+
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+ !$omp end unroll
+end subroutine test8
+
+subroutine test9
+ implicit none
+ integer :: i
+
+ !$omp do
+ !$omp unroll full ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+end subroutine test9
+
+subroutine test10
+ implicit none
+ integer :: i
+
+ !$omp unroll full
+ !$omp unroll full ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+end subroutine test10
+
+subroutine test11
+ implicit none
+ integer :: i,j
+
+ !$omp do
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ do j = 1,100
+ call dummy2(i,j)
+ end do
+ end do
+end subroutine test11
+
+subroutine test12
+ implicit none
+ integer :: i,j
+
+ !$omp do
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ call dummy(i) ! { dg-error "Unexpected CALL statement at \\\(1\\\)" }
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do j = 1,100
+ call dummy2(i,j)
+ end do
+ end do
+end subroutine test12
+
+subroutine test13
+ implicit none
+ integer :: i,j
+
+ !$omp do
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do j = 1,100
+ call dummy2(i,j)
+ end do
+ call dummy(i)
+ end do
+end subroutine test13
+
+subroutine test14
+ implicit none
+ integer :: i
+
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+ !$omp end unroll
+ !$omp end unroll ! { dg-error "Unexpected !\\\$OMP END UNROLL statement at \\\(1\\\)" }
+end subroutine test14
+
+subroutine test15
+ implicit none
+ integer :: i
+
+ !$omp do
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+ !$omp end unroll
+ !$omp end unroll ! { dg-error "Unexpected !\\\$OMP END UNROLL statement at \\\(1\\\)" }
+end subroutine test15
+
+subroutine test18
+ implicit none
+ integer :: i
+
+ !$omp do
+ !$omp unroll partial(0) ! { dg-error "PARTIAL clause argument not constant positive integer at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test18
+
+subroutine test19
+ implicit none
+ integer :: i
+
+ !$omp do
+ !$omp unroll partial(-10) ! { dg-error "PARTIAL clause argument not constant positive integer at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test19
+
+subroutine test21
+ implicit none
+ integer :: i
+
+ !$omp unroll partial
+ do concurrent (i = 1:100) ! { dg-error "!\\\$OMP UNROLL cannot be a DO CONCURRENT loop at \\\(1\\\)" }
+ call dummy(i) ! { dg-error "Subroutine call to 'dummy' in DO CONCURRENT block at \\\(1\\\) is not PURE" }
+ end do
+ !$omp end unroll
+end subroutine test21
+
+subroutine test22
+ implicit none
+ integer :: i
+
+ !$omp do
+ !$omp unroll partial
+ do concurrent (i = 1:100) ! { dg-error "!\\\$OMP UNROLL cannot be a DO CONCURRENT loop at \\\(1\\\)" }
+ call dummy(i) ! { dg-error "Subroutine call to 'dummy' in DO CONCURRENT block at \\\(1\\\) is not PURE" }
+ end do
+ !$omp end unroll
+end subroutine test22
--- /dev/null
+subroutine foo
+ integer :: i
+ !$omp do
+ !$omp unroll partial ( 3 )
+ do i = 1, 512
+ end do
+ !$omp end unroll
+ !$omp end do
+end subroutine foo
+
+subroutine bar
+ integer :: i
+ !$omp do
+ !$omp unroll partial(3)
+ do i = 1, 512
+ end do
+ !$omp end do
+end subroutine bar
+
+subroutine baz
+ integer :: i
+ !$omp do
+ !$omp unroll partial (3)
+ do i = 1, 512
+ end do
+end subroutine baz
+
+subroutine qux
+ integer :: i
+ !$omp do
+ !$omp unroll partial (3)
+ do i = 1, 512
+ end do
+ !$omp end unroll
+end subroutine qux
--- /dev/null
+! { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple" } */
+
+subroutine test1
+ implicit none
+ integer :: i
+ !$omp parallel do collapse(1)
+ !$omp unroll partial(4)
+ !$omp unroll partial(3)
+ !$omp unroll partial(2)
+ !$omp unroll partial(1)
+ do i = 1,100
+ call dummy(i)
+ end do
+end subroutine test1
+
+! Loop should be unrolled 1 * 2 * 3 * 4 = 24 times
+! { dg-final { scan-tree-dump "#pragma omp for nowait collapse\\\(1\\\)" "original" } }
+! { dg-final { scan-tree-dump "#pragma omp unroll partial\\\(1\\\)" "original" } }
+! { dg-final { scan-tree-dump "#pragma omp unroll partial\\\(2\\\)" "original" } }
+! { dg-final { scan-tree-dump "#pragma omp unroll partial\\\(3\\\)" "original" } }
+! { dg-final { scan-tree-dump "#pragma omp unroll partial\\\(4\\\)" "original" } }
+! { dg-final { scan-tree-dump-not "#pragma omp unroll" "gimple" } }
+! { dg-final { scan-tree-dump-times "\.ANNOTATE \\\(\[^\n\r\]*, 1, 2\\\);" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "\.ANNOTATE \\\(\[^\n\r\]*, 1, 3\\\);" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "\.ANNOTATE \\\(\[^\n\r\]*, 1, 4\\\);" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp for" 1 "gimple" } }
--- /dev/null
+! { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple" }
+
+subroutine test1
+ implicit none
+ integer :: i
+ !$omp unroll full
+ !$omp unroll partial(3)
+ !$omp unroll partial(2)
+ !$omp unroll partial(1)
+ do i = 1,100
+ call dummy(i)
+ end do
+end subroutine test1
+
+! { dg-final { scan-tree-dump "#pragma omp unroll full" "original" } }
+! { dg-final { scan-tree-dump "#pragma omp unroll partial\\\(1\\\)" "original" } }
+! { dg-final { scan-tree-dump "#pragma omp unroll partial\\\(2\\\)" "original" } }
+! { dg-final { scan-tree-dump "#pragma omp unroll partial\\\(3\\\)" "original" } }
+! { dg-final { scan-tree-dump-not "#pragma omp unroll" "gimple" } }
+! { dg-final { scan-tree-dump "\.ANNOTATE \\\(\[^\n\r]*, 1, 2\\\);" "gimple" } }
+! { dg-final { scan-tree-dump "\.ANNOTATE \\\(\[^\n\r]*, 1, 3\\\);" "gimple" } }
+! { dg-final { scan-tree-dump "\.ANNOTATE \\\(\[^\n\r]*, 1, 17\\\);" "gimple" } }
--- /dev/null
+subroutine test1a
+ !$omp parallel do
+ !$omp tile sizes(3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp unroll partial(5)
+ do k=-300,100
+ do l=0,100
+ call dummy (l)
+ end do
+ end do
+ end do
+ end do
+end subroutine test1a
+
+subroutine test1b
+ !$omp tile sizes(3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp unroll partial(5)
+ do k=-300,100
+ do l=0,100
+ call dummy (l)
+ end do
+ end do
+ end do
+ end do
+end subroutine test1b
--- /dev/null
+subroutine test2a
+ !$omp parallel do
+ !$omp tile sizes(3,3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp unroll partial(5) ! { dg-error "UNROLL construct at \\\(1\\\) with PARTIAL clause generates just one loop with canonical form but 2 loops are needed" }
+ do k=-300,100
+ do l=0,100
+ call dummy (l)
+ end do
+ end do
+ end do
+ end do
+end subroutine test2a
+
+subroutine test2b
+ !$omp tile sizes(3,3,3,3)
+ do i=0,100
+ do j=-300,100
+ !$omp unroll partial(5) ! { dg-error "UNROLL construct at \\\(1\\\) with PARTIAL clause generates just one loop with canonical form but 2 loops are needed" }
+ do k=-300,100
+ do l=0,100
+ call dummy (l)
+ end do
+ end do
+ end do
+ end do
+end subroutine test2b
--- /dev/null
+! { dg-additional-options "-O2 -fdump-tree-gimple" }
+
+subroutine test
+ !$omp unroll
+ do i = 1,5
+ do j = 1,10
+ call dummy3(i,j)
+ end do
+ end do
+ !$omp end unroll
+
+ !$omp unroll
+ do i = 1,6
+ do j = 1,6
+ call dummy3(i,j)
+ end do
+ end do
+ !$omp end unroll
+end subroutine test
+
+! { dg-final { scan-tree-dump-times "\.ANNOTATE \\\(\[^\n\r\]*, 1, 8\\\);" 2 "gimple" } }
--- /dev/null
+subroutine test
+ implicit none
+
+ integer :: i, j, k
+ !$omp unroll full
+ do i = -3, 5
+ do j = 1,10
+ do k = j,j*2 + 1
+ call dummy (i)
+ end do
+ end do
+ end do
+end subroutine
--- /dev/null
+subroutine test
+ implicit none
+
+ integer :: i, j, k
+ !$omp target parallel do collapse(2)
+ do i = -300, 100
+ !$omp unroll partial
+ do j = i,i*2 ! { dg-message "Non-rectangular loops from generated loops unsupported" }
+ call dummy (i)
+ end do
+ end do
+
+ !$omp target parallel do collapse(3)
+ do i = -300, 100
+ do j = 1,10
+ !$omp unroll partial
+ do k = j,j*2 + 1 ! { dg-message "Non-rectangular loops from generated loops unsupported" }
+ call dummy (i)
+ end do
+ end do
+ end do
+end subroutine
--- /dev/null
+! { dg-options "-fno-openmp -fopenmp-simd" }
+
+subroutine test15
+ implicit none
+ integer :: i
+
+ !$omp simd
+ !$omp unroll partial(1)
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test15
+
+subroutine test16
+ implicit none
+ integer :: i
+
+ !$omp simd
+ !$omp unroll partial(2)
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test16
+
+subroutine test19
+ implicit none
+ integer :: i
+
+ !$omp simd
+ !$omp unroll partial
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test19
--- /dev/null
+! { dg-do run }
+! { dg-options "-O2 -fopenmp-simd -fdump-tree-original -fdump-tree-gimple" }
+
+module test_functions
+ contains
+ integer function compute_sum() result(sum)
+ implicit none
+
+ integer :: i,j
+
+ !$omp simd
+ do i = 1,10,3
+ !$omp unroll full
+ do j = 1,10,3
+ sum = sum + 1
+ end do
+ end do
+ end function
+
+ integer function compute_sum2() result(sum)
+ implicit none
+
+ integer :: i,j
+
+ !$omp simd
+ !$omp unroll partial(2)
+ do i = 1,10,3
+ do j = 1,10,3
+ sum = sum + 1
+ end do
+ end do
+ end function
+end module test_functions
+
+program test
+ use test_functions
+ implicit none
+
+ integer :: result
+
+ result = compute_sum ()
+ write (*,*) result
+ if (result .ne. 16) then
+ call abort
+ end if
+
+ result = compute_sum2 ()
+ write (*,*) result
+ if (result .ne. 16) then
+ call abort
+ end if
+end program
+
+! { dg-final { scan-tree-dump "omp unroll full" "original" } }
+! { dg-final { scan-tree-dump "omp unroll partial\\\(2\\\)" "original" } }
+! { dg-final { scan-tree-dump-not "omp unroll" "gimple" } }
--- /dev/null
+! { dg-options "-fno-openmp -fopenmp-simd" }
+
+subroutine test1
+ implicit none
+ integer :: i
+
+ !$omp simd
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+end subroutine test1
+
+subroutine test2
+ implicit none
+ integer :: i
+
+ !$omp simd
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test2
+
+subroutine test3
+ implicit none
+ integer :: i
+
+ !$omp simd
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end do
+end subroutine test3
+
+subroutine test4
+ implicit none
+ integer :: i
+
+ !$omp simd
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+ !$omp end do
+end subroutine test4
+
+subroutine test5
+ implicit none
+ integer :: i
+
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+end subroutine test5
+
+subroutine test6
+ implicit none
+ integer :: i
+
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test6
+
+subroutine test7
+ implicit none
+ integer :: i
+
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+ !$omp end unroll
+end subroutine test7
+
+subroutine test8
+ implicit none
+ integer :: i
+
+ !$omp simd
+ !$omp unroll full ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+end subroutine test8
+
+subroutine test9
+ implicit none
+ integer :: i
+
+ !$omp unroll full
+ !$omp unroll full ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+end subroutine test9
+
+subroutine test10
+ implicit none
+ integer :: i,j
+
+ !$omp simd
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ do j = 1,100
+ call dummy2(i,j)
+ end do
+ end do
+end subroutine test10
+
+subroutine test11
+ implicit none
+ integer :: i,j
+
+ !$omp simd
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ call dummy(i) ! { dg-error "Unexpected CALL statement at \\\(1\\\)" }
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do j = 1,100
+ call dummy2(i,j)
+ end do
+ end do
+end subroutine test11
+
+subroutine test12
+ implicit none
+ integer :: i,j
+
+ !$omp simd
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do j = 1,100
+ call dummy2(i,j)
+ end do
+ call dummy(i)
+ end do
+end subroutine test12
+
+subroutine test13
+ implicit none
+ integer :: i
+
+ !$omp unroll
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+ !$omp end unroll
+ !$omp end unroll ! { dg-error "Unexpected !\\\$OMP END UNROLL statement at \\\(1\\\)" }
+end subroutine test13
+
+subroutine test14
+ implicit none
+ integer :: i
+
+ !$omp simd
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ !$omp unroll ! { dg-error "Generated loop of UNROLL construct at \\\(1\\\) without PARTIAL clause does not have canonical form" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+ !$omp end unroll
+ !$omp end unroll ! { dg-error "Unexpected !\\\$OMP END UNROLL statement at \\\(1\\\)" }
+end subroutine test14
+
+subroutine test17
+ implicit none
+ integer :: i
+
+ !$omp simd
+ !$omp unroll partial(0) ! { dg-error "PARTIAL clause argument not constant positive integer at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test17
+
+subroutine test18
+ implicit none
+ integer :: i
+
+ !$omp simd
+ !$omp unroll partial(-10) ! { dg-error "PARTIAL clause argument not constant positive integer at \\\(1\\\)" }
+ do i = 1,100
+ call dummy(i)
+ end do
+ !$omp end unroll
+end subroutine test18
--- /dev/null
+! { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple" }
+
+function mult (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c( n, m ))
+
+ !$omp parallel do
+ !$omp unroll partial(1)
+ !$omp tile sizes (8,8)
+ do i = 1,m
+ do j = 1,n
+ inner = 0
+ do k = 1, n
+ inner = inner + a(k, i) * b(j, k)
+ end do
+ c(j, i) = inner
+ end do
+ end do
+end function mult
+
+! { dg-final { scan-tree-dump-times "#pragma omp for nowait" 1 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma omp unroll partial\\\(1\\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma omp tile sizes\\\(8, 8\\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-not "#pragma omp unroll" "gimple" } }
+! { dg-final { scan-tree-dump-not "#pragma omp tile" "gimple" } }
+
+! Tiling adds two floor and two tile loops.
+! Unroll with partial(1) is effectively ignored and the innermost
+! loop isn't associated with anything. So that means 5 loops,
+! with the outermost associated with !$omp parallel do, where
+! the innermost loop gimplifies condition into a boolean temporary.
+
+! { dg-final { scan-tree-dump-times "if \\\(\[A-Za-z0-9_.\]+ <" 3 "gimple" } }
--- /dev/null
+! { dg-additional-options "-O2 -fdump-tree-original -fdump-tree-gimple" }
+
+function mult (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c( n, m ))
+ c = 0
+
+ !$omp target
+ !$omp parallel do
+ !$omp unroll partial(2)
+ !$omp tile sizes (8,8,4)
+ do i = 1,m
+ do j = 1,n
+ do k = 1, n
+ c(j,i) = c(j,i) + a(k, i) * b(j, k)
+ end do
+ end do
+ end do
+ !$omp end target
+end function mult
+
+! { dg-final { scan-tree-dump-times "#pragma omp for nowait" 1 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma omp unroll partial\\\(2\\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-times "#pragma omp tile sizes\\\(8, 8, 4\\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-not "#pragma omp unroll" "gimple" } }
+! { dg-final { scan-tree-dump-not "#pragma omp tile" "gimple" } }
+
+! Check the number of loops
+
+! Tiling adds three tile and three floor loops.
+! The outermost tile loop is then partially unrolled, turning it
+! into one tile and one floor loop, so now 7 loops in total, one
+! of them being fully unrolled. And finally the outermost loop is
+! associated with the !$omp parallel do and so not lowered during
+! gimplification.
+
+! { dg-final { scan-tree-dump-times "if \\\(\[A-Za-z0-9_.\]+ <" 5 "gimple" } }
+! { dg-final { scan-tree-dump-times "\.ANNOTATE \\\(\[^\n\r\]*, 1, 2\\\);" 1 "gimple" } }
--- /dev/null
+! { dg-additional-options "-fdump-tree-original -fdump-tree-gimple" }
+
+function mult (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c( n, m ))
+
+ !$omp parallel do collapse(2)
+ !$omp tile sizes (8,8)
+ do i = 1,m
+ do j = 1,n
+ inner = 0
+ !$omp unroll partial(10)
+ do k = 1, n
+ inner = inner + a(k, i) * b(j, k)
+ end do
+ c(j, i) = inner
+ end do
+ end do
+end function mult
+
+! { dg-final { scan-tree-dump-times "#pragma omp unroll partial" 1 "original" } }
+! { dg-final { scan-tree-dump-not "#pragma omp unroll partial" "gimple" } }
/* OpenMP clause: indirect [(constant-integer-expression)]. */
OMP_CLAUSE_INDIRECT,
+ /* OpenMP clause: partial (constant-integer-expression). */
+ OMP_CLAUSE_PARTIAL,
+
+ /* OpenMP clause: full. */
+ OMP_CLAUSE_FULL,
+
+ /* OpenMP clause: sizes (constant-integer-expression-list). */
+ OMP_CLAUSE_SIZES,
+
/* Internally used only clause, holding SIMD uid. */
OMP_CLAUSE__SIMDUID_,
spc, flags, false);
pp_right_paren (pp);
break;
+ case OMP_CLAUSE_PARTIAL:
+ pp_string (pp, "partial");
+ if (OMP_CLAUSE_PARTIAL_EXPR (clause))
+ {
+ pp_left_paren (pp);
+ dump_generic_node (pp, OMP_CLAUSE_PARTIAL_EXPR (clause),
+ spc, flags, false);
+ pp_right_paren (pp);
+ }
+ break;
+ case OMP_CLAUSE_FULL:
+ pp_string (pp, "full");
+ break;
+ case OMP_CLAUSE_SIZES:
+ pp_string (pp, "sizes(");
+ dump_generic_node (pp, OMP_CLAUSE_SIZES_LIST (clause),
+ spc, flags, false);
+ pp_right_paren (pp);
+ break;
case OMP_CLAUSE_IF_PRESENT:
pp_string (pp, "if_present");
pp_string (pp, "#pragma omp loop");
goto dump_omp_loop;
+ case OMP_TILE:
+ pp_string (pp, "#pragma omp tile");
+ goto dump_omp_loop;
+
+ case OMP_UNROLL:
+ pp_string (pp, "#pragma omp unroll");
+ goto dump_omp_loop;
+
case OACC_LOOP:
pp_string (pp, "#pragma acc loop");
goto dump_omp_loop;
spc -= 2;
for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (node)); i++)
{
+ if (TREE_VEC_ELT (OMP_FOR_INIT (node), i) == NULL_TREE)
+ continue;
spc += 2;
newline_and_indent (pp, spc);
pp_string (pp, "for (");
0, /* OMP_CLAUSE_BIND */
1, /* OMP_CLAUSE_FILTER */
1, /* OMP_CLAUSE_INDIRECT */
+ 1, /* OMP_CLAUSE_PARTIAL */
+ 0, /* OMP_CLAUSE_FULL */
+ 1, /* OMP_CLAUSE_SIZES */
1, /* OMP_CLAUSE__SIMDUID_ */
0, /* OMP_CLAUSE__SIMT_ */
0, /* OMP_CLAUSE_INDEPENDENT */
"bind",
"filter",
"indirect",
+ "partial",
+ "full",
+ "sizes",
"_simduid_",
"_simt_",
"independent",
Operands like for OMP_FOR. */
DEFTREECODE (OMP_LOOP, "omp_loop", tcc_statement, 7)
+/* OpenMP - #pragma omp tile [clause1 ... clauseN]
+ Operands like for OMP_FOR. */
+DEFTREECODE (OMP_TILE, "omp_tile", tcc_statement, 7)
+
+/* OpenMP - #pragma omp unroll [clause1 ... clauseN]
+ Operands like for OMP_FOR. */
+DEFTREECODE (OMP_UNROLL, "omp_unroll", tcc_statement, 7)
+
/* OpenMP - #pragma acc loop [clause1 ... clauseN]
Operands like for OMP_FOR. */
DEFTREECODE (OACC_LOOP, "oacc_loop", tcc_statement, 7)
#define OMP_FOR_PRE_BODY(NODE) TREE_OPERAND (OMP_LOOPING_CHECK (NODE), 5)
#define OMP_FOR_ORIG_DECLS(NODE) TREE_OPERAND (OMP_LOOPING_CHECK (NODE), 6)
+#define OMP_LOOPXFORM_CHECK(NODE) TREE_RANGE_CHECK (NODE, OMP_TILE, OMP_UNROLL)
+#define OMP_LOOPXFORM_LOWERED(NODE) \
+ (OMP_LOOPXFORM_CHECK (NODE)->base.public_flag)
+
#define OMP_SECTIONS_BODY(NODE) TREE_OPERAND (OMP_SECTIONS_CHECK (NODE), 0)
#define OMP_SECTIONS_CLAUSES(NODE) TREE_OPERAND (OMP_SECTIONS_CHECK (NODE), 1)
OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_HINT), 0)
#define OMP_CLAUSE_FILTER_EXPR(NODE) \
OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_FILTER), 0)
+#define OMP_CLAUSE_PARTIAL_EXPR(NODE) \
+ OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_PARTIAL), 0)
+#define OMP_CLAUSE_SIZES_LIST(NODE) \
+ OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_SIZES), 0)
#define OMP_CLAUSE_GRAINSIZE_EXPR(NODE) \
OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_GRAINSIZE),0)
--- /dev/null
+/* { dg-additional-options "-O0 -fdump-tree-original -Wall -Wno-unknown-pragmas" } */
+
+#define COMMON_DIRECTIVE
+#define COMMON_TOP_TRANSFORM omp unroll full
+#define COLLAPSE_1
+#define COLLAPSE_2
+#define COLLAPSE_3
+#define IMPLEMENTATION_FILE "../libgomp.c-c++-common/matrix-constant-iter.h"
+
+#include "../libgomp.c-c++-common/matrix-transform-variants-1.h"
+
+/* A consistency check to prevent broken macro usage. */
+/* { dg-final { scan-tree-dump-times "unroll full" 13 "original" } } */
--- /dev/null
+// { dg-additional-options "-std=c++11 -O0" }
+
+#include <vector>
+
+constexpr unsigned
+fib (unsigned n)
+{
+ return n <= 2 ? 1 : fib (n-1) + fib (n-2);
+}
+
+int
+test1 ()
+{
+ std::vector<int> v;
+
+ for (unsigned i = 0; i <= 9; i++)
+ v.push_back (1);
+
+ int sum = 0;
+ for (int k = 0; k < 10; k++)
+ #pragma omp tile sizes(fib(4))
+ for (int i : v) {
+ for (int j = 8; j != -2; --j)
+ sum = sum + i;
+ }
+
+ return sum;
+}
+
+int
+test2 ()
+{
+ std::vector<int> v;
+
+ for (unsigned i = 0; i <= 10; i++)
+ v.push_back (i);
+
+ int sum = 0;
+ for (int k = 0; k < 10; k++)
+ #pragma omp parallel for collapse(2) reduction(+:sum)
+ #pragma omp tile sizes(fib(4), 1)
+ for (int i : v)
+ for (int j = 8; j > -2; --j)
+ sum = sum + i;
+
+ return sum;
+}
+
+int
+main ()
+{
+ if (test1 () != 1000)
+ __builtin_abort ();
+
+ if (test2 () != 5500)
+ __builtin_abort ();
+}
--- /dev/null
+// { dg-additional-options "-std=c++11 -O0" }
+
+#include <vector>
+
+int
+main ()
+{
+ std::vector<int> v;
+ std::vector<int> w;
+
+ for (unsigned i = 0; i <= 9; i++)
+ v.push_back (i);
+
+ int iter = 0;
+ #pragma omp for
+ #pragma omp tile sizes(5)
+ for (int i : v)
+ {
+ w.push_back (iter);
+ iter++;
+ }
+
+ for (int i = 0; i < w.size (); i++)
+ if (w[i] != i)
+ __builtin_abort ();
+}
--- /dev/null
+// { dg-additional-options "-std=c++11 -O0" }
+
+#include <vector>
+#include <stdio.h>
+
+constexpr unsigned
+fib (unsigned n)
+{
+ return n <= 2 ? 1 : fib (n-1) + fib (n-2);
+}
+
+int
+test1 ()
+{
+ std::vector<int> v;
+
+ for (unsigned i = 0; i <= 9; i++)
+ v.push_back (1);
+
+ int sum = 0;
+ for (int k = 0; k < 10; k++)
+ #pragma omp unroll partial(fib(3))
+ for (int i : v)
+ {
+ for (int j = 8; j != -2; --j)
+ sum = sum + i;
+ }
+
+ return sum;
+}
+
+int
+test2 ()
+{
+ std::vector<int> v;
+
+ for (unsigned i = 0; i <= 10; i++)
+ v.push_back (i);
+
+ int sum = 0;
+ #pragma omp parallel for reduction(+:sum)
+ for (int k = 0; k < 10; k++)
+ #pragma omp unroll
+ #pragma omp unroll partial(fib(4))
+ for (int i : v)
+ {
+ #pragma omp unroll full
+ for (int j = 8; j != -2; --j)
+ sum = sum + i;
+ }
+
+ return sum;
+}
+
+int
+main ()
+{
+ if (test1 () != 1000)
+ __builtin_abort ();
+
+ if (test2 () != 5500)
+ __builtin_abort ();
+}
--- /dev/null
+// { dg-do run }
+// { dg-additional-options "-std=c++11" }
+
+#include <vector>
+#include <iostream>
+
+int
+main ()
+{
+ std::vector<std::vector<int>> v;
+ std::vector<int> w;
+
+ for (unsigned i = 0; i < 10; i++)
+ {
+ std::vector<int> u;
+ for (unsigned j = 0; j < 10; j++)
+ u.push_back (j);
+ v.push_back (u);
+ }
+
+ #pragma omp for
+ #pragma omp unroll partial(7)
+ for (auto u : v)
+ for (int x : u)
+ w.push_back (x);
+
+ std::size_t l = w.size ();
+ for (std::size_t i = 0; i < l; i++)
+ if (w[i] != i % 10)
+ __builtin_abort ();
+}
--- /dev/null
+template <int dim0, int dim1>
+int sum ()
+{
+ int sum = 0;
+ #pragma omp unroll full
+ #pragma omp tile sizes (dim0, dim1)
+ for (unsigned i = 0; i < 4; i++)
+ for (unsigned j = 0; j < 5; j++)
+ sum++;
+
+ return sum;
+}
+
+int main ()
+{
+ if (sum <1,1> () != 20)
+ __builtin_abort ();
+ if (sum <1,2> () != 20)
+ __builtin_abort ();
+ if (sum <1,3> () != 20)
+ __builtin_abort ();
+ if (sum <1,4> () != 20)
+ __builtin_abort ();
+ if (sum <1,5> () != 20)
+ __builtin_abort ();
+
+ if (sum <2,1> () != 20)
+ __builtin_abort ();
+ if (sum <2,2> () != 20)
+ __builtin_abort ();
+ if (sum <2,3> () != 20)
+ __builtin_abort ();
+ if (sum <2,4> () != 20)
+ __builtin_abort ();
+ if (sum <2,5> () != 20)
+ __builtin_abort ();
+
+ if (sum <3,1> () != 20)
+ __builtin_abort ();
+ if (sum <3,2> () != 20)
+ __builtin_abort ();
+ if (sum <3,3> () != 20)
+ __builtin_abort ();
+ if (sum <3,4> () != 20)
+ __builtin_abort ();
+ if (sum <3,5> () != 20)
+ __builtin_abort ();
+
+ if (sum <4,1> () != 20)
+ __builtin_abort ();
+ if (sum <4,2> () != 20)
+ __builtin_abort ();
+ if (sum <4,3> () != 20)
+ __builtin_abort ();
+ if (sum <4,4> () != 20)
+ __builtin_abort ();
+ if (sum <4,5> () != 20)
+ __builtin_abort ();
+
+ if (sum <5,1> () != 20)
+ __builtin_abort ();
+ if (sum <5,2> () != 20)
+ __builtin_abort ();
+ if (sum <5,3> () != 20)
+ __builtin_abort ();
+ if (sum <5,4> () != 20)
+ __builtin_abort ();
+ if (sum <5,5> () != 20)
+ __builtin_abort ();
+
+ if (sum <6,1> () != 20)
+ __builtin_abort ();
+ if (sum <6,2> () != 20)
+ __builtin_abort ();
+ if (sum <6,3> () != 20)
+ __builtin_abort ();
+ if (sum <6,4> () != 20)
+ __builtin_abort ();
+ if (sum <6,5> () != 20)
+ __builtin_abort ();
+}
--- /dev/null
+/* { dg-do run } */
+
+/* Like imperfect1.c, but also includes loop transforms. */
+
+static int f1count[3], f2count[3];
+
+int
+f1 (int depth, int iter)
+{
+ f1count[depth]++;
+ return iter;
+}
+
+int
+f2 (int depth, int iter)
+{
+ f2count[depth]++;
+ return iter;
+}
+
+void
+s1 (int a1, int a2, int a3)
+{
+ int i, j, k;
+
+ #pragma omp for collapse(2) private (j, k)
+ for (i = 0; i < a1; i++)
+ {
+ f1 (0, i);
+ for (j = 0; j < a2; j++)
+ {
+ f1 (1, j);
+ #pragma omp unroll partial
+ for (k = 0; k < a3; k++)
+ {
+ f1 (2, k);
+ f2 (2, k);
+ }
+ f2 (1, j);
+ }
+ f2 (0, i);
+ }
+}
+
+int
+main ()
+{
+ f1count[0] = 0;
+ f1count[1] = 0;
+ f1count[2] = 0;
+ f2count[0] = 0;
+ f2count[1] = 0;
+ f2count[2] = 0;
+
+ s1 (3, 4, 5);
+
+ /* All intervening code at the same depth must be executed the same
+ number of times. */
+ if (f1count[0] != f2count[0]) __builtin_abort ();
+ if (f1count[1] != f2count[1]) __builtin_abort ();
+ if (f1count[2] != f2count[2]) __builtin_abort ();
+
+ /* Intervening code must be executed at least as many times as the loop
+ that encloses it. */
+ if (f1count[0] < 3) __builtin_abort ();
+ if (f1count[1] < 3 * 4) __builtin_abort ();
+
+ /* Intervening code must not be executed more times than the number
+ of logical iterations. */
+ if (f1count[0] > 3 * 4 * 5) __builtin_abort ();
+ if (f1count[1] > 3 * 4 * 5) __builtin_abort ();
+
+ /* Check that the innermost loop body is executed exactly the number
+ of logical iterations expected. */
+ if (f1count[2] != 3 * 4 * 5) __builtin_abort ();
+}
--- /dev/null
+/* { dg-do run } */
+
+/* Like imperfect1.c, but also includes loop transforms. */
+
+static int f1count[3], f2count[3];
+
+int
+f1 (int depth, int iter)
+{
+ f1count[depth]++;
+ return iter;
+}
+
+int
+f2 (int depth, int iter)
+{
+ f2count[depth]++;
+ return iter;
+}
+
+void
+s1 (int a1, int a2, int a3)
+{
+ int i, j, k;
+
+ #pragma omp for collapse(2) private (j, k)
+ for (i = 0; i < a1; i++)
+ {
+ f1 (0, i);
+ for (j = 0; j < a2; j++)
+ {
+ f1 (1, j);
+ #pragma omp tile sizes(5)
+ for (k = 0; k < a3; k++)
+ {
+ f1 (2, k);
+ f2 (2, k);
+ }
+ f2 (1, j);
+ }
+ f2 (0, i);
+ }
+}
+
+int
+main ()
+{
+ f1count[0] = 0;
+ f1count[1] = 0;
+ f1count[2] = 0;
+ f2count[0] = 0;
+ f2count[1] = 0;
+ f2count[2] = 0;
+
+ s1 (3, 4, 5);
+
+ /* All intervening code at the same depth must be executed the same
+ number of times. */
+ if (f1count[0] != f2count[0]) __builtin_abort ();
+ if (f1count[1] != f2count[1]) __builtin_abort ();
+ if (f1count[2] != f2count[2]) __builtin_abort ();
+
+ /* Intervening code must be executed at least as many times as the loop
+ that encloses it. */
+ if (f1count[0] < 3) __builtin_abort ();
+ if (f1count[1] < 3 * 4) __builtin_abort ();
+
+ /* Intervening code must not be executed more times than the number
+ of logical iterations. */
+ if (f1count[0] > 3 * 4 * 5) __builtin_abort ();
+ if (f1count[1] > 3 * 4 * 5) __builtin_abort ();
+
+ /* Check that the innermost loop body is executed exactly the number
+ of logical iterations expected. */
+ if (f1count[2] != 3 * 4 * 5) __builtin_abort ();
+}
--- /dev/null
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+
+#ifndef FUN_NAME_SUFFIX
+#define FUN_NAME_SUFFIX
+#endif
+
+#ifdef MULT
+#undef MULT
+#endif
+#define MULT CAT(mult, FUN_NAME_SUFFIX)
+
+#ifdef MAIN
+#undef MAIN
+#endif
+#define MAIN CAT(main, FUN_NAME_SUFFIX)
+
+void
+MULT (float *matrix1, float *matrix2, float *result,
+ unsigned dim0, unsigned dim1)
+{
+ memset (result, 0, sizeof (float) * dim0 * dim1);
+ DIRECTIVE
+ TRANSFORMATION1
+ for (unsigned i = 0; i < dim0; i++)
+ TRANSFORMATION2
+ for (unsigned j = 0; j < dim1; j++)
+ TRANSFORMATION3
+ for (unsigned k = 0; k < dim1; k++)
+ result[i * dim1 + j] += matrix1[i * dim1 + k] * matrix2[k * dim0 + j];
+}
+
+int
+MAIN ()
+{
+ unsigned dim0 = 20;
+ unsigned dim1 = 20;
+
+ float *result = (float *) malloc (sizeof (float) * dim0 * dim1);
+ float *matrix1 = (float *) malloc (sizeof (float) * dim0 * dim1);
+ float *matrix2 = (float *) malloc (sizeof (float) * dim0 * dim1);
+
+ for (unsigned i = 0; i < dim0; i++)
+ for (unsigned j = 0; j < dim1; j++)
+ matrix1[i * dim1 + j] = j;
+
+ for (unsigned i = 0; i < dim0; i++)
+ for (unsigned j = 0; j < dim1; j++)
+ if (i == j)
+ matrix2[i * dim1 + j] = 1;
+ else
+ matrix2[i * dim1 + j] = 0;
+
+ MULT (matrix1, matrix2, result, dim0, dim1);
+
+ for (unsigned i = 0; i < dim0; i++)
+ for (unsigned j = 0; j < dim1; j++)
+ {
+ if (matrix1[i * dim1 + j] != result[i * dim1 + j])
+ {
+ print_matrix (matrix1, dim0, dim1);
+ print_matrix (matrix2, dim0, dim1);
+ print_matrix (result, dim0, dim1);
+ fprintf (stderr, "%s: ERROR at %d, %d\n", __FUNCTION__, i, j);
+ abort ();
+ }
+ }
+
+ free (matrix2);
+ free (matrix1);
+ free (result);
+
+ return 0;
+}
+
+#undef DIRECTIVE
+#undef TRANSFORMATION1
+#undef TRANSFORMATION2
+#undef TRANSFORMATION3
+#undef FUN_NAME_SUFFIX
--- /dev/null
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+
+#ifndef FUN_NAME_SUFFIX
+#define FUN_NAME_SUFFIX
+#endif
+
+#ifdef MULT
+#undef MULT
+#endif
+#define MULT CAT(mult, FUN_NAME_SUFFIX)
+
+#ifdef MAIN
+#undef MAIN
+#endif
+#define MAIN CAT(main, FUN_NAME_SUFFIX)
+
+void
+MULT (float *matrix1, float *matrix2, float *result)
+{
+ const unsigned dim0 = 20;
+ const unsigned dim1 = 20;
+
+ memset (result, 0, sizeof (float) * dim0 * dim1);
+ DIRECTIVE
+ TRANSFORMATION1
+ for (unsigned i = 0; i < dim0; i++)
+ TRANSFORMATION2
+ for (unsigned j = 0; j < dim1; j++)
+ TRANSFORMATION3
+ for (unsigned k = 0; k < dim1; k++)
+ result[i * dim1 + j] += matrix1[i * dim1 + k] * matrix2[k * dim0 + j];
+}
+
+int
+MAIN ()
+{
+ const unsigned dim0 = 20;
+ const unsigned dim1 = 20;
+
+ float *result = (float *) malloc (sizeof (float) * dim0 * dim1);
+ float *matrix1 = (float *) malloc (sizeof (float) * dim0 * dim1);
+ float *matrix2 = (float *) malloc (sizeof (float) * dim0 * dim1);
+
+ for (unsigned i = 0; i < dim0; i++)
+ for (unsigned j = 0; j < dim1; j++)
+ matrix1[i * dim1 + j] = j;
+
+ for (unsigned i = 0; i < dim0; i++)
+ for (unsigned j = 0; j < dim1; j++)
+ if (i == j)
+ matrix2[i * dim1 + j] = 1;
+ else
+ matrix2[i * dim1 + j] = 0;
+
+ MULT (matrix1, matrix2, result);
+
+ for (unsigned i = 0; i < dim0; i++)
+ for (unsigned j = 0; j < dim1; j++)
+ {
+ if (matrix1[i * dim1 + j] != result[i * dim1 + j])
+ {
+ printf ("%s: error at %d, %d\n", __FUNCTION__, i, j);
+ print_matrix (matrix1, dim0, dim1);
+ print_matrix (matrix2, dim0, dim1);
+ print_matrix (result, dim0, dim1);
+ printf ("\n");
+ abort ();
+ }
+ }
+
+ free (matrix2);
+ free (matrix1);
+ free (result);
+
+ return 0;
+}
+
+#undef DIRECTIVE
+#undef TRANSFORMATION1
+#undef TRANSFORMATION2
+#undef TRANSFORMATION3
+#undef FUN_NAME_SUFFIX
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+
+#define CAT(x,y) XCAT(x,y)
+#define XCAT(x,y) x ## y
+#define DO_PRAGMA(x) XDO_PRAGMA(x)
+#define XDO_PRAGMA(x) _Pragma (#x)
+
+void
+print_matrix (float *matrix, unsigned dim0, unsigned dim1)
+{
+ for (unsigned i = 0; i < dim0; i++)
+ {
+ for (unsigned j = 0; j < dim1; j++)
+ fprintf (stderr, "%f ", matrix[i * dim1 + j]);
+ fprintf (stderr, "\n");
+ }
+ fprintf (stderr, "\n");
+}
--- /dev/null
+/* { dg-additional-options "-fdump-tree-original -Wall -Wno-unknown-pragmas" } */
+
+#undef COMMON_DIRECTIVE
+#define COLLAPSE_1 collapse(1)
+#define COLLAPSE_2 collapse(2)
+#define COLLAPSE_3 collapse(3)
+
+#include "matrix-transform-variants-1.h"
+
+/* A consistency check to prevent broken macro usage. */
+/* { dg-final { scan-tree-dump-times "unroll partial" 12 "original" } } */
--- /dev/null
+/* { dg-additional-options "-O2 -fdump-tree-original -Wall -Wno-unknown-pragmas" } */
+
+#undef COMMON_DIRECTIVE
+#define COMMON_TOP_TRANSFORM omp unroll full
+#define COLLAPSE_1
+#define COLLAPSE_2
+#define COLLAPSE_3
+#define IMPLEMENTATION_FILE "matrix-constant-iter.h"
+
+#include "matrix-transform-variants-1.h"
+
+/* A consistency check to prevent broken macro usage. */
+/* { dg-final { scan-tree-dump-times "unroll full" 13 "original" } } */
--- /dev/null
+/* { dg-additional-options "-Wall -Wno-unknown-pragmas" } */
+
+#define COMMON_DIRECTIVE "omp teams distribute parallel for"
+#define COLLAPSE_1 "collapse(1)"
+#define COLLAPSE_2 "collapse(2)"
+#define COLLAPSE_3 "collapse(3)"
+
+#include "matrix-transform-variants-1.h"
--- /dev/null
+/* { dg-additional-options "-fdump-tree-original -Wall -Wno-unknown-pragmas" } */
+
+#define COMMON_DIRECTIVE omp for
+#define COLLAPSE_1 collapse(1)
+#define COLLAPSE_2 collapse(2)
+#define COLLAPSE_3 collapse(3)
+
+#include "matrix-transform-variants-1.h"
+
+
+/* A consistency check to prevent broken macro usage. */
+/* { dg-final { scan-tree-dump-times "omp for" 13 "original" } } */
+/* { dg-final { scan-tree-dump-times "collapse" 12 "original" } } */
--- /dev/null
+/* { dg-additional-options "-fdump-tree-original -Wall -Wno-unknown-pragmas" } */
+
+#define COMMON_DIRECTIVE omp parallel for
+#define COLLAPSE_1 collapse(1)
+#define COLLAPSE_2 collapse(2)
+#define COLLAPSE_3
+
+#include "matrix-transform-variants-1.h"
+
+
+/* A consistency check to prevent broken macro usage. */
+/* { dg-final { scan-tree-dump-times "omp parallel" 13 "original" } } */
+/* { dg-final { scan-tree-dump-times "collapse" 9 "original" } } */
--- /dev/null
+/* { dg-additional-options "-Wall -Wno-unknown-pragmas" } */
+
+#define COMMON_DIRECTIVE omp parallel masked taskloop
+#define COLLAPSE_1 collapse(1)
+#define COLLAPSE_2 collapse(2)
+#define COLLAPSE_3
+
+#include "matrix-transform-variants-1.h"
--- /dev/null
+/* { dg-additional-options "-Wall -Wno-unknown-pragmas" } */
+
+#define COMMON_DIRECTIVE omp parallel masked taskloop simd
+#define COLLAPSE_1 collapse(1)
+#define COLLAPSE_2 collapse(2)
+#define COLLAPSE_3
+
+#include "matrix-transform-variants-1.h"
--- /dev/null
+/* This test appears to have too much parallelism to run without a GPU. */
+/* { dg-do run { target { offload_device } } } */
+/* { dg-additional-options "-fdump-tree-original -Wall -Wno-unknown-pragmas" } */
+
+#define COMMON_DIRECTIVE omp target parallel for map(tofrom:result[0:dim0 * dim1]) map(to:matrix1[0:dim0 * dim1], matrix2[0:dim0 * dim1])
+#define COLLAPSE_1 collapse(1)
+#define COLLAPSE_2 collapse(2)
+#define COLLAPSE_3
+
+#include "matrix-transform-variants-1.h"
+
+/* A consistency check to prevent broken macro usage. */
+/* { dg-final { scan-tree-dump-times "omp target" 13 "original" } } */
+/* { dg-final { scan-tree-dump-times "collapse" 9 "original" } } */
+/* { dg-final { scan-tree-dump-times "unroll partial" 12 "original" } } */
--- /dev/null
+/* This test appears to have too much parallelism to run without a GPU. */
+/* { dg-do run { target { offload_device } } } */
+/* { dg-additional-options "-Wall -Wno-unknown-pragmas" } */
+
+#define COMMON_DIRECTIVE omp target teams distribute parallel for map(tofrom:result[:dim0 * dim1]) map(to:matrix1[0:dim0 * dim1], matrix2[0:dim0 * dim1])
+#define COLLAPSE_1 collapse(1)
+#define COLLAPSE_2 collapse(2)
+#define COLLAPSE_3
+
+#include "matrix-transform-variants-1.h"
--- /dev/null
+/* { dg-additional-options "-Wall -Wno-unknown-pragmas" } */
+
+#define COMMON_DIRECTIVE omp taskloop
+#define COLLAPSE_1 collapse(1)
+#define COLLAPSE_2 collapse(2)
+#define COLLAPSE_3 collapse(3)
+
+#include "matrix-transform-variants-1.h"
--- /dev/null
+/* { dg-additional-options "-Wall -Wno-unknown-pragmas" } */
+
+#define COMMON_DIRECTIVE omp teams distribute parallel for
+#define COLLAPSE_1 collapse(1)
+#define COLLAPSE_2 collapse(2)
+#define COLLAPSE_3
+
+#include "matrix-transform-variants-1.h"
--- /dev/null
+/* { dg-additional-options "-Wall -Wno-unknown-pragmas" } */
+
+#define COMMON_DIRECTIVE omp simd
+#define COLLAPSE_1 collapse(1)
+#define COLLAPSE_2 collapse(2)
+#define COLLAPSE_3 collapse(3)
+
+#include "matrix-transform-variants-1.h"
--- /dev/null
+#include "matrix-helper.h"
+
+#ifndef COMMON_TOP_TRANSFORM
+#define COMMON_TOP_TRANSFORM
+#endif
+
+#ifndef IMPLEMENTATION_FILE
+#define IMPLEMENTATION_FILE "matrix-1.h"
+#endif
+
+#define FUN_NAME_SUFFIX 1
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM) _Pragma("omp unroll partial(2)") _Pragma("omp tile sizes(10)")
+#define TRANSFORMATION2
+#define TRANSFORMATION3
+#include IMPLEMENTATION_FILE
+
+#define FUN_NAME_SUFFIX 2
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE COLLAPSE_3)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM) _Pragma("omp tile sizes(8,16,4)")
+#define TRANSFORMATION2
+#define TRANSFORMATION3
+#include IMPLEMENTATION_FILE
+
+#define FUN_NAME_SUFFIX 3
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE COLLAPSE_2)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM) _Pragma("omp tile sizes(8, 8)")
+#define TRANSFORMATION2
+#define TRANSFORMATION3
+#include IMPLEMENTATION_FILE
+
+#define FUN_NAME_SUFFIX 4
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE COLLAPSE_1)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM) _Pragma("omp tile sizes(8, 8)")
+#define TRANSFORMATION2
+#define TRANSFORMATION3
+#include IMPLEMENTATION_FILE
+
+#define FUN_NAME_SUFFIX 5
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE COLLAPSE_1)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM) _Pragma("omp tile sizes(8, 8, 8)")
+#define TRANSFORMATION2
+#define TRANSFORMATION3
+#include IMPLEMENTATION_FILE
+
+#define FUN_NAME_SUFFIX 6
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE COLLAPSE_1)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM) _Pragma("omp tile sizes(10)") _Pragma("omp unroll partial(2)")
+#define TRANSFORMATION2
+#define TRANSFORMATION3
+#include IMPLEMENTATION_FILE
+
+#define FUN_NAME_SUFFIX 7
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE COLLAPSE_2)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM) _Pragma("omp tile sizes(7, 11)")
+#define TRANSFORMATION2 _Pragma("omp unroll partial(7)")
+#define TRANSFORMATION3
+#include IMPLEMENTATION_FILE
+
+#define FUN_NAME_SUFFIX 8
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE COLLAPSE_2)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM) _Pragma("omp tile sizes(7, 11)")
+#define TRANSFORMATION2 _Pragma("omp tile sizes(7)") _Pragma("omp unroll partial(7)")
+#define TRANSFORMATION3
+#include IMPLEMENTATION_FILE
+
+#define FUN_NAME_SUFFIX 9
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE COLLAPSE_2)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM) _Pragma("omp tile sizes(7, 11)")
+#define TRANSFORMATION2 _Pragma("omp tile sizes(7)") _Pragma("omp unroll partial(3)") _Pragma("omp tile sizes(7)")
+#define TRANSFORMATION3
+#include IMPLEMENTATION_FILE
+
+#define FUN_NAME_SUFFIX 10
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE COLLAPSE_1)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM) _Pragma("omp unroll partial(5)") _Pragma("omp tile sizes(7)") _Pragma("omp unroll partial(3)") _Pragma("omp tile sizes(7)")
+#define TRANSFORMATION2
+#define TRANSFORMATION3
+#include IMPLEMENTATION_FILE
+
+#define FUN_NAME_SUFFIX 11
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE COLLAPSE_2)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM)
+#define TRANSFORMATION2 _Pragma("omp unroll partial(5)") _Pragma("omp tile sizes(7)") _Pragma("omp unroll partial(3)") _Pragma("omp tile sizes(7)")
+#define TRANSFORMATION3
+#include IMPLEMENTATION_FILE
+
+#define FUN_NAME_SUFFIX 12
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE COLLAPSE_3)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM)
+#define TRANSFORMATION2
+#define TRANSFORMATION3 _Pragma("omp unroll partial(5)") _Pragma("omp tile sizes(7)") _Pragma("omp unroll partial(3)") _Pragma("omp tile sizes(7)")
+#include IMPLEMENTATION_FILE
+
+#define FUN_NAME_SUFFIX 13
+#ifdef COMMON_DIRECTIVE
+#define DIRECTIVE DO_PRAGMA(COMMON_DIRECTIVE COLLAPSE_3)
+#else
+#define DIRECTIVE
+#endif
+#define TRANSFORMATION1 DO_PRAGMA(COMMON_TOP_TRANSFORM)
+#define TRANSFORMATION2 _Pragma("omp tile sizes(7,8)")
+#define TRANSFORMATION3 _Pragma("omp unroll partial(3)") _Pragma("omp tile sizes(7)")
+#include IMPLEMENTATION_FILE
+
+int
+main ()
+{
+ main1 ();
+ main2 ();
+ main3 ();
+ main4 ();
+ main5 ();
+ main6 ();
+ main7 ();
+ main8 ();
+ main9 ();
+ main10 ();
+ main11 ();
+ main12 ();
+ main13 ();
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+
+/* Like imperfect-transform.c, but enables offloading. */
+
+static int f1count[3], f2count[3];
+#pragma omp declare target enter (f1count, f2count)
+
+int
+f1 (int depth, int iter)
+{
+ #pragma omp atomic
+ f1count[depth]++;
+ return iter;
+}
+
+int
+f2 (int depth, int iter)
+{
+ #pragma omp atomic
+ f2count[depth]++;
+ return iter;
+}
+
+void
+s1 (int a1, int a2, int a3)
+{
+ int i, j, k;
+
+ #pragma omp target parallel for collapse(2) map(always, tofrom:f1count, f2count) private (j, k)
+ for (i = 0; i < a1; i++)
+ {
+ f1 (0, i);
+ for (j = 0; j < a2; j++)
+ {
+ f1 (1, j);
+ #pragma omp unroll partial
+ for (k = 0; k < a3; k++)
+ {
+ f1 (2, k);
+ f2 (2, k);
+ }
+ f2 (1, j);
+ }
+ f2 (0, i);
+ }
+}
+
+int
+main ()
+{
+ f1count[0] = 0;
+ f1count[1] = 0;
+ f1count[2] = 0;
+ f2count[0] = 0;
+ f2count[1] = 0;
+ f2count[2] = 0;
+
+ s1 (3, 4, 5);
+
+ /* All intervening code at the same depth must be executed the same
+ number of times. */
+ if (f1count[0] != f2count[0]) __builtin_abort ();
+ if (f1count[1] != f2count[1]) __builtin_abort ();
+ if (f1count[2] != f2count[2]) __builtin_abort ();
+
+ /* Intervening code must be executed at least as many times as the loop
+ that encloses it. */
+ if (f1count[0] < 3) __builtin_abort ();
+ if (f1count[1] < 3 * 4) __builtin_abort ();
+
+ /* Intervening code must not be executed more times than the number
+ of logical iterations. */
+ if (f1count[0] > 3 * 4 * 5) __builtin_abort ();
+ if (f1count[1] > 3 * 4 * 5) __builtin_abort ();
+
+ /* Check that the innermost loop body is executed exactly the number
+ of logical iterations expected. */
+ if (f1count[2] != 3 * 4 * 5) __builtin_abort ();
+}
--- /dev/null
+/* { dg-do run } */
+
+/* Like imperfect-transform.c, but enables offloading. */
+
+static int f1count[3], f2count[3];
+#pragma omp declare target enter (f1count, f2count)
+
+int
+f1 (int depth, int iter)
+{
+ #pragma omp atomic
+ f1count[depth]++;
+ return iter;
+}
+
+int
+f2 (int depth, int iter)
+{
+ #pragma omp atomic
+ f2count[depth]++;
+ return iter;
+}
+
+void
+s1 (int a1, int a2, int a3)
+{
+ int i, j, k;
+
+ #pragma omp target parallel for collapse(2) map(always, tofrom:f1count, f2count) private (j, k)
+ for (i = 0; i < a1; i++)
+ {
+ f1 (0, i);
+ for (j = 0; j < a2; j++)
+ {
+ f1 (1, j);
+ #pragma omp tile sizes(5)
+ for (k = 0; k < a3; k++)
+ {
+ f1 (2, k);
+ f2 (2, k);
+ }
+ f2 (1, j);
+ }
+ f2 (0, i);
+ }
+}
+
+int
+main ()
+{
+ f1count[0] = 0;
+ f1count[1] = 0;
+ f1count[2] = 0;
+ f2count[0] = 0;
+ f2count[1] = 0;
+ f2count[2] = 0;
+
+ s1 (3, 4, 5);
+
+ /* All intervening code at the same depth must be executed the same
+ number of times. */
+ if (f1count[0] != f2count[0]) __builtin_abort ();
+ if (f1count[1] != f2count[1]) __builtin_abort ();
+ if (f1count[2] != f2count[2]) __builtin_abort ();
+
+ /* Intervening code must be executed at least as many times as the loop
+ that encloses it. */
+ if (f1count[0] < 3) __builtin_abort ();
+ if (f1count[1] < 3 * 4) __builtin_abort ();
+
+ /* Intervening code must not be executed more times than the number
+ of logical iterations. */
+ if (f1count[0] > 3 * 4 * 5) __builtin_abort ();
+ if (f1count[1] > 3 * 4 * 5) __builtin_abort ();
+
+ /* Check that the innermost loop body is executed exactly the number
+ of logical iterations expected. */
+ if (f1count[2] != 3 * 4 * 5) __builtin_abort ();
+}
--- /dev/null
+/* { dg-additional-options "-Wall -Wno-unknown-pragmas" } */
+
+int
+compute_sum1 (void)
+{
+ int sum = 0;
+ int i, j;
+
+ #pragma omp parallel for reduction(+:sum) lastprivate(j)
+ #pragma omp unroll partial
+ for (i = 3; i < 10; ++i)
+ for (j = -2; j < 7; ++j)
+ sum++;
+
+ if (j != 7)
+ __builtin_abort ();
+
+ return sum;
+}
+
+int
+compute_sum2 (void)
+{
+ int sum = 0;
+ int i, j;
+
+ #pragma omp parallel for reduction(+:sum) lastprivate(j)
+ #pragma omp unroll partial(5)
+ for (i = 3; i < 10; ++i)
+ for (j = -2; j < 7; ++j)
+ sum++;
+
+ if (j != 7)
+ __builtin_abort ();
+
+ return sum;
+}
+
+int
+compute_sum3 (void)
+{
+ int sum = 0;
+ int i, j;
+
+ #pragma omp parallel for reduction(+:sum) lastprivate(j)
+ #pragma omp unroll partial(1)
+ for (i = 3; i < 10; ++i)
+ for (j = -2; j < 7; ++j)
+ sum++;
+
+ if (j != 7)
+ __builtin_abort ();
+
+ return sum;
+}
+
+int
+main ()
+{
+ if (compute_sum1 () != 7 * 9)
+ __builtin_abort ();
+
+ if (compute_sum2 () != 7 * 9)
+ __builtin_abort ();
+
+ if (compute_sum3 () != 7 * 9)
+ __builtin_abort ();
+
+ return 0;
+}
--- /dev/null
+/* { dg-additional-options "-Wall -Wno-unknown-pragmas" } */
+
+void
+test1 (void)
+{
+ int sum = 0;
+
+ for (int i = -3; i != 1; ++i)
+ for (int j = -2; j < i * -1; ++j)
+ sum++;
+
+ if (sum != 14)
+ __builtin_abort ();
+}
+
+void
+test2 (void)
+{
+ int sum = 0;
+
+ #pragma omp unroll partial
+ for (int i = -3; i != 1; ++i)
+ for (int j = -2; j < i * -1; ++j)
+ sum++;
+
+ if (sum != 14)
+ __builtin_abort ();
+}
+
+void
+test3 (void)
+{
+ int sum = 0;
+
+ #pragma omp unroll partial
+ for (int i = -3; i != 1; ++i)
+ #pragma omp unroll partial
+ for (int j = -2; j < i * -1; ++j)
+ sum++;
+
+ if (sum != 14)
+ __builtin_abort ();
+}
+
+int sum;
+
+void
+test4 (void)
+{
+ #pragma omp for reduction(+:sum)
+ #pragma omp unroll partial(5)
+ for (int i = -3; i != 1; ++i)
+ #pragma omp unroll partial(2)
+ for (int j = -2; j < i * -1; ++j)
+ sum++;
+
+ if (sum != 14)
+ __builtin_abort ();
+}
+
+void
+test5 (void)
+{
+ int sum = 0;
+
+ #pragma omp parallel for reduction(+:sum)
+ #pragma omp unroll partial(2)
+ for (int i = -3; i != 1; ++i)
+ #pragma omp unroll partial(2)
+ for (int j = -2; j < i * -1; ++j)
+ sum++;
+
+ if (sum != 14)
+ __builtin_abort ();
+}
+
+void
+test6 (void)
+{
+ int sum = 0;
+ #pragma omp target parallel for reduction(+:sum)
+ #pragma omp unroll partial(7)
+ for (int i = -3; i != 1; ++i)
+ #pragma omp unroll partial(2)
+ for (int j = -2; j < i * -1; ++j)
+ sum++;
+
+ if (sum != 14)
+ __builtin_abort ();
+}
+
+void
+test7 (void)
+{
+ int sum = 0;
+#pragma omp target teams distribute parallel for reduction(+:sum)
+#pragma omp unroll partial(7)
+ for (int i = -3; i != 1; ++i)
+#pragma omp unroll partial(2)
+ for (int j = -2; j < i * -1; ++j)
+ sum++;
+
+ if (sum != 14)
+ __builtin_abort ();
+}
+
+int
+main ()
+{
+ test1 ();
+ test2 ();
+ test3 ();
+ test4 ();
+ test5 ();
+ test6 ();
+ test7 ();
+ return 0;
+}
--- /dev/null
+! { dg-do run }
+
+! Like imperfect1.f90, but also includes loop transforms.
+
+program foo
+ integer, save :: f1count(3), f2count(3)
+
+ f1count(1) = 0
+ f1count(2) = 0
+ f1count(3) = 0
+ f2count(1) = 0
+ f2count(2) = 0
+ f2count(3) = 0
+
+ call s1 (3, 4, 5)
+
+ ! All intervening code at the same depth must be executed the same
+ ! number of times.
+ if (f1count(1) /= f2count(1)) error stop 101
+ if (f1count(2) /= f2count(2)) error stop 102
+ if (f1count(3) /= f2count(3)) error stop 103
+
+ ! Intervening code must be executed at least as many times as the loop
+ ! that encloses it.
+ if (f1count(1) < 3) error stop 111
+ if (f1count(2) < 3 * 4) error stop 112
+
+ ! Intervening code must not be executed more times than the number
+ ! of logical iterations.
+ if (f1count(1) > 3 * 4 * 5) error stop 121
+ if (f1count(2) > 3 * 4 * 5) error stop 122
+
+ ! Check that the innermost loop body is executed exactly the number
+ ! of logical iterations expected.
+ if (f1count(3) /= 3 * 4 * 5) error stop 131
+
+contains
+
+subroutine f1 (depth, iter)
+ integer :: depth, iter
+ f1count(depth) = f1count(depth) + 1
+end subroutine
+
+subroutine f2 (depth, iter)
+ integer :: depth, iter
+ f2count(depth) = f2count(depth) + 1
+end subroutine
+
+subroutine s1 (a1, a2, a3)
+ integer :: a1, a2, a3
+ integer :: i, j, k
+
+ !$omp do collapse(2) private (j, k)
+ do i = 1, a1
+ call f1 (1, i)
+ do j = 1, a2
+ call f1 (2, j)
+ !$omp unroll partial
+ do k = 1, a3
+ call f1 (3, k)
+ call f2 (3, k)
+ end do
+ call f2 (2, j)
+ end do
+ call f2 (1, i)
+ end do
+
+end subroutine
+
+end program
--- /dev/null
+! { dg-do run }
+
+! Like imperfect1.f90, but also includes loop transforms.
+
+program foo
+ integer, save :: f1count(3), f2count(3)
+
+ f1count(1) = 0
+ f1count(2) = 0
+ f1count(3) = 0
+ f2count(1) = 0
+ f2count(2) = 0
+ f2count(3) = 0
+
+ call s1 (3, 4, 5)
+
+ ! All intervening code at the same depth must be executed the same
+ ! number of times.
+ if (f1count(1) /= f2count(1)) error stop 101
+ if (f1count(2) /= f2count(2)) error stop 102
+ if (f1count(3) /= f2count(3)) error stop 103
+
+ ! Intervening code must be executed at least as many times as the loop
+ ! that encloses it.
+ if (f1count(1) < 3) error stop 111
+ if (f1count(2) < 3 * 4) error stop 112
+
+ ! Intervening code must not be executed more times than the number
+ ! of logical iterations.
+ if (f1count(1) > 3 * 4 * 5) error stop 121
+ if (f1count(2) > 3 * 4 * 5) error stop 122
+
+ ! Check that the innermost loop body is executed exactly the number
+ ! of logical iterations expected.
+ if (f1count(3) /= 3 * 4 * 5) error stop 131
+
+contains
+
+subroutine f1 (depth, iter)
+ integer :: depth, iter
+ f1count(depth) = f1count(depth) + 1
+end subroutine
+
+subroutine f2 (depth, iter)
+ integer :: depth, iter
+ f2count(depth) = f2count(depth) + 1
+end subroutine
+
+subroutine s1 (a1, a2, a3)
+ integer :: a1, a2, a3
+ integer :: i, j, k
+
+ !$omp do collapse(2) private (j, k)
+ do i = 1, a1
+ call f1 (1, i)
+ do j = 1, a2
+ call f1 (2, j)
+ !$omp tile sizes(5)
+ do k = 1, a3
+ call f1 (3, k)
+ call f2 (3, k)
+ end do
+ call f2 (2, j)
+ end do
+ call f2 (1, i)
+ end do
+
+end subroutine
+
+end program
--- /dev/null
+module matrix
+ implicit none
+ integer :: n = 10
+ integer :: m = 10
+
+contains
+ function mult (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c( n, m ))
+ !$omp target parallel do collapse(2) &
+ !$omp & private(inner, i, j, k) map(to:a,b) map(from:c)
+ !$omp tile sizes (8, 1)
+ do i = 1,m
+ !$omp tile sizes (8)
+ do j = 1,n
+ !$omp unroll partial(10)
+ do k = 1, n
+ if (k == 1) then
+ inner = 0
+ endif
+ inner = inner + a(k, i) * b(j, k)
+ if (k == n) then
+ c(j, i) = inner
+ endif
+ end do
+ end do
+ end do
+ end function mult
+
+ subroutine print_matrix (m)
+ integer, allocatable :: m(:,:)
+ integer :: i, j, n
+
+ n = size (m, 1)
+ do i = 1,n
+ do j = 1,n
+ write (*, fmt="(i4)", advance='no') m(j, i)
+ end do
+ write (*, *) ""
+ end do
+ write (*, *) ""
+ end subroutine
+
+end module matrix
+
+program main
+ use matrix
+ implicit none
+
+ integer, allocatable :: a(:,:),b(:,:),c(:,:)
+ integer :: i,j
+
+ allocate(a( n, m ))
+ allocate(b( n, m ))
+
+ do i = 1,n
+ do j = 1,m
+ a(j,i) = merge(1,0, i.eq.j)
+ b(j,i) = j
+ end do
+ end do
+
+ c = mult (a, b)
+
+ call print_matrix (a)
+ call print_matrix (b)
+ call print_matrix (c)
+
+ do i = 1,n
+ do j = 1,m
+ if (b(i,j) .ne. c(i,j)) stop 1
+ end do
+ end do
+
+end program main
--- /dev/null
+! { dg-do run }
+
+program foo
+ integer :: count
+ call s1
+contains
+
+ subroutine s1 ()
+ integer :: i, count
+
+ count = 0
+
+ !$omp target parallel do map(tofrom:count) reduction(+:count) private(i)
+ !$omp unroll partial
+ do i = 1, 100
+ count = count + 1
+ end do
+
+ if (count .ne. 100) stop 1
+
+ end subroutine
+
+end program
--- /dev/null
+! { dg-do run }
+
+! Like imperfect-transform.f90, but enables offloading.
+
+program foo
+ integer, save :: f1count(3), f2count(3)
+ !$omp declare target enter (f1count, f2count)
+
+ f1count(1) = 0
+ f1count(2) = 0
+ f1count(3) = 0
+ f2count(1) = 0
+ f2count(2) = 0
+ f2count(3) = 0
+
+ call s1 (3, 4, 5)
+
+ ! All intervening code at the same depth must be executed the same
+ ! number of times.
+ if (f1count(1) /= f2count(1)) error stop 101
+ if (f1count(2) /= f2count(2)) error stop 102
+ if (f1count(3) /= f2count(3)) error stop 103
+
+ ! Intervening code must be executed at least as many times as the loop
+ ! that encloses it.
+ if (f1count(1) < 3) error stop 111
+ if (f1count(2) < 3 * 4) error stop 112
+
+ ! Intervening code must not be executed more times than the number
+ ! of logical iterations.
+ if (f1count(1) > 3 * 4 * 5) error stop 121
+ if (f1count(2) > 3 * 4 * 5) error stop 122
+
+ ! Check that the innermost loop body is executed exactly the number
+ ! of logical iterations expected.
+ if (f1count(3) /= 3 * 4 * 5) error stop 131
+
+contains
+
+subroutine f1 (depth, iter)
+ integer :: depth, iter
+ !$omp atomic
+ f1count(depth) = f1count(depth) + 1
+end subroutine
+
+subroutine f2 (depth, iter)
+ integer :: depth, iter
+ !$omp atomic
+ f2count(depth) = f2count(depth) + 1
+end subroutine
+
+subroutine s1 (a1, a2, a3)
+ integer :: a1, a2, a3
+ integer :: i, j, k
+
+ !$omp target parallel do collapse(2) map(always, tofrom:f1count, f2count) &
+ !$omp & private (j, k)
+ do i = 1, a1
+ call f1 (1, i)
+ do j = 1, a2
+ call f1 (2, j)
+ !$omp unroll partial
+ do k = 1, a3
+ call f1 (3, k)
+ call f2 (3, k)
+ end do
+ call f2 (2, j)
+ end do
+ call f2 (1, i)
+ end do
+
+end subroutine
+
+end program
--- /dev/null
+! { dg-do run }
+
+! Like imperfect-transform.f90, but enables offloading.
+
+program foo
+ integer, save :: f1count(3), f2count(3)
+ !$omp declare target enter (f1count, f2count)
+
+ f1count(1) = 0
+ f1count(2) = 0
+ f1count(3) = 0
+ f2count(1) = 0
+ f2count(2) = 0
+ f2count(3) = 0
+
+ call s1 (3, 4, 5)
+
+ ! All intervening code at the same depth must be executed the same
+ ! number of times.
+ if (f1count(1) /= f2count(1)) error stop 101
+ if (f1count(2) /= f2count(2)) error stop 102
+ if (f1count(3) /= f2count(3)) error stop 103
+
+ ! Intervening code must be executed at least as many times as the loop
+ ! that encloses it.
+ if (f1count(1) < 3) error stop 111
+ if (f1count(2) < 3 * 4) error stop 112
+
+ ! Intervening code must not be executed more times than the number
+ ! of logical iterations.
+ if (f1count(1) > 3 * 4 * 5) error stop 121
+ if (f1count(2) > 3 * 4 * 5) error stop 122
+
+ ! Check that the innermost loop body is executed exactly the number
+ ! of logical iterations expected.
+ if (f1count(3) /= 3 * 4 * 5) error stop 131
+
+contains
+
+subroutine f1 (depth, iter)
+ integer :: depth, iter
+ !$omp atomic
+ f1count(depth) = f1count(depth) + 1
+end subroutine
+
+subroutine f2 (depth, iter)
+ integer :: depth, iter
+ !$omp atomic
+ f2count(depth) = f2count(depth) + 1
+end subroutine
+
+subroutine s1 (a1, a2, a3)
+ integer :: a1, a2, a3
+ integer :: i, j, k
+
+ !$omp target parallel do collapse(2) map(always, tofrom:f1count, f2count) &
+ !$omp & private(j, k)
+ do i = 1, a1
+ call f1 (1, i)
+ do j = 1, a2
+ call f1 (2, j)
+ !$omp tile sizes(5)
+ do k = 1, a3
+ call f1 (3, k)
+ call f2 (3, k)
+ end do
+ call f2 (2, j)
+ end do
+ call f2 (1, i)
+ end do
+
+end subroutine
+
+end program
--- /dev/null
+module matrix
+ implicit none
+ integer :: n = 10
+ integer :: m = 10
+
+contains
+ function mult (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c( n, m ))
+ !$omp parallel do collapse(2) private(inner, i, j, k)
+ !$omp tile sizes (8, 1)
+ do i = 1,m
+ do j = 1,n
+ inner = 0
+ do k = 1, n
+ inner = inner + a(k, i) * b(j, k)
+ end do
+ c(j, i) = inner
+ end do
+ end do
+ end function mult
+
+ subroutine print_matrix (m)
+ integer, allocatable :: m(:,:)
+ integer :: i, j, n
+
+ n = size (m, 1)
+ do i = 1,n
+ do j = 1,n
+ write (*, fmt="(i4)", advance='no') m(j, i)
+ end do
+ write (*, *) ""
+ end do
+ write (*, *) ""
+ end subroutine
+
+end module matrix
+
+program main
+ use matrix
+ implicit none
+
+ integer, allocatable :: a(:,:),b(:,:),c(:,:)
+ integer :: i,j
+
+ allocate(a( n, m ))
+ allocate(b( n, m ))
+
+ do i = 1,n
+ do j = 1,m
+ a(j,i) = merge(1,0, i.eq.j)
+ b(j,i) = j
+ end do
+ end do
+
+ c = mult (a, b)
+
+ call print_matrix (a)
+ call print_matrix (b)
+ call print_matrix (c)
+
+ do i = 1,n
+ do j = 1,m
+ if (b(i,j) .ne. c(i,j)) stop 1
+ end do
+ end do
+
+end program main
--- /dev/null
+! { dg-do run }
+
+module test_functions
+ contains
+ integer function compute_sum1() result(sum)
+ implicit none
+ integer :: i,j
+
+ sum = 0
+ !$omp parallel do reduction(+:sum) private(j)
+ do i = 1,10,3
+ !$omp tile sizes(2)
+ do j = 1,10,3
+ sum = sum + 1
+ end do
+ end do
+ end function
+
+ integer function compute_sum2() result(sum)
+ implicit none
+ integer :: i,j
+
+ sum = 0
+ !$omp parallel do reduction(+:sum) private(j)
+ do i = 1,10,3
+ !$omp tile sizes(16)
+ do j = 1,10,3
+ sum = sum + 1
+ end do
+ end do
+ end function
+
+ integer function compute_sum3() result(sum)
+ implicit none
+ integer :: i,j
+
+ sum = 0
+ !$omp parallel do reduction(+:sum) private(j)
+ do i = 1,10,3
+ !$omp tile sizes(100)
+ do j = 1,10,3
+ sum = sum + 1
+ end do
+ end do
+ end function
+
+ integer function compute_sum4() result(sum)
+ implicit none
+ integer :: i,j
+
+ sum = 0
+ !$omp parallel do reduction(+:sum) private(i, j)
+ !$omp tile sizes(6,10)
+ do i = 1,10,3
+ do j = 1,10,3
+ sum = sum + 1
+ end do
+ end do
+ end function
+
+ integer function compute_sum5() result(sum)
+ implicit none
+ integer :: i,j
+
+ sum = 0
+ !$omp parallel do collapse(2) reduction(+:sum) private(i, j)
+ !$omp tile sizes(6,10)
+ do i = 1,10,3
+ do j = 1,10,3
+ sum = sum + 1
+ end do
+ end do
+ !$omp end tile
+ !$omp end parallel do
+ end function
+end module test_functions
+
+program test
+ use test_functions
+ implicit none
+ integer :: result
+
+ result = compute_sum1 ()
+ if (result .ne. 16) then
+ stop 1
+ end if
+
+ result = compute_sum2 ()
+ if (result .ne. 16) then
+ stop 2
+ end if
+
+ result = compute_sum3 ()
+ if (result .ne. 16) then
+ stop 3
+ end if
+
+ result = compute_sum4 ()
+ if (result .ne. 16) then
+ stop 4
+ end if
+
+ result = compute_sum5 ()
+ if (result .ne. 16) then
+ stop 5
+ end if
+end program
--- /dev/null
+module matrix
+ implicit none
+ integer :: n = 10
+ integer :: m = 10
+
+contains
+
+ function mult (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c(n, m))
+ do i = 1,10
+ do j = 1,n
+ c(j,i) = 0
+ end do
+ end do
+
+ !$omp unroll partial(10)
+ !$omp tile sizes(1, 3)
+ do i = 1,10
+ do j = 1,n
+ do k = 1, n
+ c(j,i) = c(j,i) + a(k, i) * b(j, k)
+ end do
+ end do
+ end do
+ end function mult
+
+ function mult2 (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c(n, m))
+ do i = 1,10
+ do j = 1,n
+ c(j,i) = 0
+ end do
+ end do
+
+ !$omp unroll partial(2)
+ !$omp tile sizes(1,2)
+ do i = 1,10
+ do j = 1,n
+ do k = 1, n
+ c(j,i) = c(j,i) + a(k, i) * b(j, k)
+ end do
+ end do
+ end do
+ end function mult2
+
+ subroutine print_matrix (m)
+ integer, allocatable :: m(:,:)
+ integer :: i, j, n
+
+ n = size (m, 1)
+ do i = 1,n
+ do j = 1,n
+ write (*, fmt="(i4)", advance='no') m(j, i)
+ end do
+ write (*, *) ""
+ end do
+ write (*, *) ""
+ end subroutine
+
+end module matrix
+
+program main
+ use matrix
+ implicit none
+ integer, allocatable :: a(:,:), b(:,:), c(:,:), d(:, :)
+ integer :: i, j
+
+ allocate(a(n, m))
+ allocate(b(n, m))
+
+ do i = 1,n
+ do j = 1,m
+ a(j,i) = merge(1,0, i.eq.j)
+ b(j,i) = j
+ end do
+ end do
+
+ d = mult (a, b)
+
+ call print_matrix (a)
+ call print_matrix (b)
+ call print_matrix (d)
+
+ do i = 1,n
+ do j = 1,m
+ if (b(i,j) .ne. d(i,j)) stop 1
+ end do
+ end do
+
+ c = mult2 (a, b)
+
+ call print_matrix (a)
+ call print_matrix (b)
+ call print_matrix (c)
+
+ do i = 1,n
+ do j = 1,m
+ if (b(i,j) .ne. c(i,j)) stop 2
+ end do
+ end do
+
+end program main
--- /dev/null
+module matrix
+ implicit none
+ integer :: n = 10
+ integer :: m = 10
+
+contains
+
+ function copy (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c(n, m))
+ do i = 1,10
+ do j = 1,n
+ c(j,i) = 0
+ end do
+ end do
+
+ !$omp unroll partial(2)
+ !$omp tile sizes (1,5)
+ do i = 1,10
+ do j = 1,n
+ c(j,i) = c(j,i) + a(j, i)
+ end do
+ end do
+ end function copy
+
+ subroutine print_matrix (m)
+ integer, allocatable :: m(:,:)
+ integer :: i, j, n
+
+ n = size (m, 1)
+ do i = 1,n
+ do j = 1,n
+ write (*, fmt="(i4)", advance='no') m(j, i)
+ end do
+ write (*, *) ""
+ end do
+ write (*, *) ""
+ end subroutine
+end module matrix
+
+program main
+ use matrix
+ implicit none
+
+ integer, allocatable :: a(:,:),b(:,:),c(:,:)
+ integer :: i,j
+
+ allocate(a(n, m))
+ allocate(b(n, m))
+
+ do i = 1,n
+ do j = 1,m
+ a(j,i) = 1
+ end do
+ end do
+
+ c = copy (a, b)
+
+ call print_matrix (a)
+ call print_matrix (b)
+ call print_matrix (c)
+
+ do i = 1,n
+ do j = 1,m
+ if (c(i,j) .ne. a(i,j)) stop 1
+ end do
+ end do
+
+end program main
--- /dev/null
+module matrix
+ implicit none
+ integer :: n = 4
+ integer :: m = 4
+
+contains
+ function mult (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c(n, m))
+ !$omp parallel do private(inner, j, k)
+ do i = 1,m
+ !$omp unroll partial(4)
+ !$omp tile sizes (5)
+ do j = 1,n
+ do k = 1, n
+ if (k == 1) then
+ inner = 0
+ endif
+ inner = inner + a(k, i) * b(j, k)
+ if (k == n) then
+ c(j, i) = inner
+ endif
+ end do
+ end do
+ end do
+ end function mult
+
+ subroutine print_matrix (m)
+ integer, allocatable :: m(:,:)
+ integer :: i, j, n
+
+ n = size (m, 1)
+ do i = 1,n
+ do j = 1,n
+ write (*, fmt="(i4)", advance='no') m(j, i)
+ end do
+ write (*, *) ""
+ end do
+ write (*, *) ""
+ end subroutine
+
+end module matrix
+
+program main
+ use matrix
+ implicit none
+
+ integer, allocatable :: a(:,:),b(:,:),c(:,:)
+ integer :: i,j
+
+ allocate(a(n, m))
+ allocate(b(n, m))
+
+ do i = 1,n
+ do j = 1,m
+ a(j,i) = merge(1,0, i.eq.j)
+ b(j,i) = j
+ end do
+ end do
+
+ c = mult (a, b)
+
+ call print_matrix (a)
+ call print_matrix (b)
+ call print_matrix (c)
+
+ do i = 1,n
+ do j = 1,m
+ if (b(i,j) .ne. c(i,j)) stop 1
+ end do
+ end do
+
+end program main
--- /dev/null
+module matrix
+ implicit none
+ integer :: n = 4
+ integer :: m = 4
+
+contains
+ function mult (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c(n, m))
+ do i = 1,m
+ do j = 1,n
+ c(j, i) = 0
+ end do
+ end do
+
+ !$omp parallel do private(j, k)
+ do i = 1,m
+ !$omp tile sizes (5,2)
+ do j = 1,n
+ do k = 1, n
+ c(j,i) = c(j,i) + a(k, i) * b(j, k)
+ end do
+ end do
+ end do
+ end function mult
+
+ subroutine print_matrix (m)
+ integer, allocatable :: m(:,:)
+ integer :: i, j, n
+
+ n = size (m, 1)
+ do i = 1,n
+ do j = 1,n
+ write (*, fmt="(i4)", advance='no') m(j, i)
+ end do
+ write (*, *) ""
+ end do
+ write (*, *) ""
+ end subroutine
+
+end module matrix
+
+program main
+ use matrix
+ implicit none
+
+ integer, allocatable :: a(:,:),b(:,:),c(:,:)
+ integer :: i,j
+
+ allocate(a(n, m))
+ allocate(b(n, m))
+
+ do i = 1,n
+ do j = 1,m
+ a(j,i) = merge(1,0, i.eq.j)
+ b(j,i) = j
+ end do
+ end do
+
+ c = mult (a, b)
+
+ call print_matrix (a)
+ call print_matrix (b)
+ call print_matrix (c)
+
+ do i = 1,n
+ do j = 1,m
+ if (b(i,j) .ne. c(i,j)) stop 1
+ end do
+ end do
+
+end program main
--- /dev/null
+! { dg-do run }
+
+module test_functions
+ contains
+ integer function compute_sum() result(sum)
+ implicit none
+ integer :: i,j
+
+ sum = 0
+ !$omp parallel do reduction(+:sum) private(j)
+ do i = 1,10,3
+ !$omp unroll full
+ do j = 1,10,3
+ sum = sum + 1
+ end do
+ end do
+ end function
+
+ integer function compute_sum2() result(sum)
+ implicit none
+ integer :: i,j
+
+ sum = 0
+ !$omp parallel do reduction(+:sum) private(i, j)
+ !$omp unroll partial(2)
+ do i = 1,10,3
+ do j = 1,10,3
+ sum = sum + 1
+ end do
+ end do
+ end function
+end module test_functions
+
+program test
+ use test_functions
+ implicit none
+
+ integer :: result
+
+ result = compute_sum ()
+ if (result .ne. 16) then
+ stop 1
+ end if
+
+ result = compute_sum2 ()
+ if (result .ne. 16) then
+ stop 2
+ end if
+end program
--- /dev/null
+! { dg-do run }
+! { dg-additional-options "-g" }
+
+module test_functions
+contains
+ integer function compute_sum1 () result(sum)
+ implicit none
+ integer :: i
+
+ sum = 0
+ !$omp unroll full
+ do i = 1,10,3
+ sum = sum + 1
+ end do
+ end function compute_sum1
+
+ integer function compute_sum2() result(sum)
+ implicit none
+ integer :: i
+
+ sum = 0
+ !$omp unroll full
+ do i = -20,1,3
+ sum = sum + 1
+ end do
+ end function compute_sum2
+
+ integer function compute_sum3() result(sum)
+ implicit none
+ integer :: i
+
+ sum = 0
+ !$omp unroll full
+ do i = 30,1,-3
+ sum = sum + 1
+ end do
+ end function compute_sum3
+
+ integer function compute_sum4() result(sum)
+ implicit none
+ integer :: i
+
+ sum = 0
+ !$omp unroll full
+ do i = 50,-60,-10
+ sum = sum + 1
+ end do
+ end function compute_sum4
+
+end module test_functions
+
+program test
+ use test_functions
+ implicit none
+ integer :: result
+
+ result = compute_sum1 ()
+ if (result .ne. 4) then
+ stop 1
+ end if
+
+ result = compute_sum2 ()
+ if (result .ne. 8) then
+ stop 2
+ end if
+
+ result = compute_sum3 ()
+ if (result .ne. 10) then
+ stop 3
+ end if
+
+ result = compute_sum4 ()
+ if (result .ne. 12) then
+ stop 4
+ end if
+end program
--- /dev/null
+! Test lowering of the internal representation of "omp unroll" loops
+! which are not unrolled.
+
+! { dg-do run }
+
+module test_functions
+contains
+ integer function compute_sum1 () result(sum)
+ implicit none
+ integer :: i
+
+ sum = 0
+ !$omp unroll
+ do i = 0,50
+ sum = sum + 1
+ end do
+ end function compute_sum1
+
+ integer function compute_sum3 (step,n) result(sum)
+ implicit none
+ integer :: i, step, n
+
+ sum = 0
+ !$omp unroll
+ do i = 0,n,step
+ sum = sum + 1
+ end do
+ end function compute_sum3
+end module test_functions
+
+program test
+ use test_functions
+ implicit none
+
+ integer :: result
+
+ result = compute_sum1 ()
+ if (result .ne. 51) then
+ stop 1
+ end if
+
+ result = compute_sum3 (1, 100)
+ if (result .ne. 101) then
+ stop 2
+ end if
+
+ result = compute_sum3 (2, 100)
+ if (result .ne. 51) then
+ stop 3
+ end if
+
+ result = compute_sum3 (-2, -100)
+ if (result .ne. 51) then
+ stop 4
+ end if
+end program
--- /dev/null
+! { dg-do run }
+! { dg-additional-options "-g" }
+
+module test_functions
+contains
+ integer function compute_sum1 () result(sum)
+ implicit none
+ integer :: i
+
+ sum = 0
+ !$omp unroll partial(2)
+ do i = 1,50
+ sum = sum + 1
+ end do
+ end function compute_sum1
+
+ integer function compute_sum3 (step,n) result(sum)
+ implicit none
+ integer :: i, step, n
+
+ sum = 0
+ !$omp unroll partial(5)
+ do i = 1,n,step
+ sum = sum + 1
+ end do
+ end function compute_sum3
+end module test_functions
+
+program test
+ use test_functions
+ implicit none
+ integer :: result
+
+ result = compute_sum1 ()
+ if (result .ne. 50) then
+ stop 1
+ end if
+
+ result = compute_sum3 (1, 100)
+ if (result .ne. 100) then
+ stop 2
+ end if
+
+ result = compute_sum3 (1, 9)
+ if (result .ne. 9) then
+ stop 3
+ end if
+
+ result = compute_sum3 (2, 96)
+ if (result .ne. 48) then
+ stop 4
+ end if
+
+ result = compute_sum3 (-2, -98)
+ if (result .ne. 50) then
+ stop 5
+ end if
+
+ result = compute_sum3 (-2, -100)
+ if (result .ne. 51) then
+ stop 6
+ end if
+end program
--- /dev/null
+! { dg-do run }
+! { dg-additional-options "-g" }
+
+module test_functions
+contains
+ integer function compute_sum4 (step,n) result(sum)
+ implicit none
+ integer :: i, step, n
+
+ sum = 0
+ !$omp parallel do reduction(+:sum) private(i)
+ !$omp unroll partial(5)
+ do i = 1,n,step
+ sum = sum + 1
+ end do
+ end function compute_sum4
+end module test_functions
+
+program test
+ use test_functions
+ implicit none
+ integer :: result
+
+ result = compute_sum4 (1, 100)
+ if (result .ne. 100) then
+ stop 1
+ end if
+
+ result = compute_sum4 (1, 9)
+ if (result .ne. 9) then
+ stop 2
+ end if
+
+ result = compute_sum4 (2, 96)
+ if (result .ne. 48) then
+ stop 3
+ end if
+
+ result = compute_sum4 (-2, -98)
+ if (result .ne. 50) then
+ stop 4
+ end if
+
+ result = compute_sum4 (-2, -100)
+ if (result .ne. 51) then
+ stop 5
+ end if
+end program
--- /dev/null
+! { dg-do run }
+! { dg-additional-options "-g" }
+
+module test_functions
+contains
+ integer function compute_sum4 (step,n) result(sum)
+ implicit none
+ integer :: i, step, n
+
+ sum = 0
+ !$omp parallel do reduction(+:sum) lastprivate(i)
+ !$omp unroll partial(5)
+ do i = 1,n,step
+ sum = sum + 1
+ end do
+ end function compute_sum4
+
+ integer function compute_sum5 (step,n) result(sum)
+ implicit none
+ integer :: i, step, n
+
+ sum = 0
+ !$omp parallel do reduction(+:sum) lastprivate(i)
+ !$omp unroll partial(5)
+ !$omp unroll partial(10)
+ do i = 1,n,step
+ sum = sum + 1
+ end do
+ end function compute_sum5
+
+ integer function compute_sum6 (step,n) result(sum)
+ implicit none
+ integer :: i, j, step, n
+
+ sum = 0
+ !$omp parallel do reduction(+:sum) lastprivate(i) &
+ !$omp & private(j)
+ do i = 1,n,step
+ !$omp unroll full
+ !$omp unroll partial(10)
+ do j = 1, 1000
+ sum = sum + 1
+ end do
+ end do
+ end function compute_sum6
+end module test_functions
+
+program test
+ use test_functions
+ implicit none
+ integer :: result
+
+ result = compute_sum4 (1, 100)
+ if (result .ne. 100) then
+ stop 1
+ end if
+
+ result = compute_sum4 (1, 9)
+ if (result .ne. 9) then
+ stop 2
+ end if
+
+ result = compute_sum4 (2, 96)
+ if (result .ne. 48) then
+ stop 3
+ end if
+
+ result = compute_sum4 (-2, -98)
+ if (result .ne. 50) then
+ stop 4
+ end if
+
+ result = compute_sum4 (-2, -100)
+ if (result .ne. 51) then
+ stop 5
+ end if
+
+ result = compute_sum5 (1, 100)
+ if (result .ne. 100) then
+ stop 6
+ end if
+
+ result = compute_sum5 (1, 9)
+ if (result .ne. 9) then
+ stop 7
+ end if
+
+ result = compute_sum5 (2, 96)
+ if (result .ne. 48) then
+ stop 8
+ end if
+
+ result = compute_sum5 (-2, -98)
+ if (result .ne. 50) then
+ stop 9
+ end if
+
+ result = compute_sum5 (-2, -100)
+ if (result .ne. 51) then
+ stop 10
+ end if
+end program
--- /dev/null
+! { dg-do run }
+! { dg-additional-options "-cpp" }
+
+#ifndef UNROLL_FACTOR
+#define UNROLL_FACTOR 1
+#endif
+module test_functions
+contains
+ subroutine copy (array1, array2)
+ implicit none
+ integer :: array1(:)
+ integer :: array2(:)
+ integer :: i
+
+ !$omp parallel do private(i)
+ !$omp unroll partial(UNROLL_FACTOR)
+ do i = 1, 100
+ array1(i) = array2(i)
+ end do
+ end subroutine
+
+ subroutine copy2 (array1, array2)
+ implicit none
+
+ integer :: array1(100)
+ integer :: array2(100)
+ integer :: i
+
+ !$omp parallel do private(i)
+ !$omp unroll partial(UNROLL_FACTOR)
+ do i = 0,99
+ array1(i+1) = array2(i+1)
+ end do
+ end subroutine copy2
+
+ subroutine copy3 (array1, array2)
+ implicit none
+
+ integer :: array1(100)
+ integer :: array2(100)
+ integer :: i
+
+ !$omp parallel do lastprivate(i)
+ !$omp unroll partial(UNROLL_FACTOR)
+ do i = -49,50
+ if (i < 0) then
+ array1((-1)*i) = array2((-1)*i)
+ else
+ array1(50+i) = array2(50+i)
+ endif
+ end do
+ end subroutine copy3
+
+ subroutine copy4 (array1, array2)
+ implicit none
+ integer :: array1(:)
+ integer :: array2(:)
+ integer :: i
+
+ !$omp parallel do private(i)
+ !$omp unroll partial(UNROLL_FACTOR)
+ do i = 2, 200, 2
+ array1(i/2) = array2(i/2)
+ end do
+ end subroutine copy4
+
+ subroutine copy5 (array1, array2)
+ implicit none
+ integer :: array1(:)
+ integer :: array2(:)
+ integer :: i
+
+ !$omp parallel do private(i)
+ !$omp unroll partial(UNROLL_FACTOR)
+ do i = 200, 2, -2
+ array1(i/2) = array2(i/2)
+ end do
+ end subroutine
+
+ subroutine copy6 (array1, array2, lower, upper, step)
+ implicit none
+ integer :: array1(:)
+ integer :: array2(:)
+ integer :: lower, upper, step
+ integer :: i
+
+ !$omp parallel do private(i)
+ !$omp unroll partial(UNROLL_FACTOR)
+ do i = lower, upper, step
+ array1 (i) = array2(i)
+ end do
+ end subroutine
+
+ subroutine prepare (array1, array2)
+ implicit none
+ integer :: array1(:)
+ integer :: array2(:)
+
+ array1 = 2
+ array2 = 0
+ end subroutine
+
+ subroutine check_equal (array1, array2)
+ implicit none
+ integer :: array1(:)
+ integer :: array2(:)
+ integer :: i
+
+ do i=1,100
+ if (array1(i) /= array2(i)) then
+ stop 1
+ end if
+ end do
+ end subroutine
+
+ subroutine check_equal_at_steps (array1, array2, lower, upper, step)
+ implicit none
+ integer :: array1(:)
+ integer :: array2(:)
+ integer :: lower, upper, step
+ integer :: i
+
+ do i=lower, upper, step
+ if (array1(i) /= array2(i)) then
+ stop 2
+ end if
+ end do
+ end subroutine
+
+ subroutine check_unchanged_at_non_steps (array1, array2, lower, upper, step)
+ implicit none
+ integer :: array1(:)
+ integer :: array2(:)
+ integer :: lower, upper, step
+ integer :: i, j
+
+ do i=lower, upper,step
+ do j=i,i+step-1
+ if (array2(j) /= 0) then
+ stop 3
+ end if
+ end do
+ end do
+ end subroutine
+end module test_functions
+
+program test
+ use test_functions
+ implicit none
+ integer :: array1(100), array2(100)
+
+ call prepare (array1, array2)
+ call copy (array1, array2)
+ call check_equal (array1, array2)
+
+ call prepare (array1, array2)
+ call copy2 (array1, array2)
+ call check_equal (array1, array2)
+
+ call prepare (array1, array2)
+ call copy3 (array1, array2)
+ call check_equal (array1, array2)
+
+ call prepare (array1, array2)
+ call copy4 (array1, array2)
+ call check_equal (array1, array2)
+
+ call prepare (array1, array2)
+ call copy5 (array1, array2)
+ call check_equal (array1, array2)
+
+ call prepare (array1, array2)
+ call copy6 (array1, array2, 1, 100, 5)
+ call check_equal_at_steps (array1, array2, 1, 100, 5)
+ call check_unchanged_at_non_steps (array1, array2, 1, 100, 5)
+
+ call prepare (array1, array2)
+ call copy6 (array1, array2, 1, 50, 5)
+ call check_equal_at_steps (array1, array2, 1, 50, 5)
+ call check_unchanged_at_non_steps (array1, array2, 1, 50, 5)
+
+ call prepare (array1, array2)
+ call copy6 (array1, array2, 3, 18, 7)
+ call check_equal_at_steps (array1, array2, 3 , 18, 7)
+ call check_unchanged_at_non_steps (array1, array2, 3, 18, 7)
+end program
--- /dev/null
+! { dg-do run }
+! { dg-additional-options "-g -cpp" }
+
+! Check an unroll factor that divides the number of iterations
+! of the loops in the test implementation.
+#define UNROLL_FACTOR 5
+#include "unroll-7.f90"
--- /dev/null
+! { dg-do run }
+! { dg-additional-options "-g -cpp" }
+
+! Check an unroll factor that does not divide the number of iterations
+! of the loops in the test implementation.
+#define UNROLL_FACTOR 3
+#include "unroll-7.f90"
--- /dev/null
+! { dg-do run }
+! { dg-additional-options "-g -cpp" }
+
+! Check an unroll factor that is larger than the number of iterations
+! of the loops in the test implementation.
+#define UNROLL_FACTOR 113
+#include "unroll-7.f90"
--- /dev/null
+! { dg-do run }
+! { dg-additional-options "-g" }
+
+module test_functions
+contains
+ subroutine copy (array1, array2, step, n)
+ implicit none
+ integer :: array1(n)
+ integer :: array2(n)
+ integer :: i, step, n
+
+ call omp_set_num_threads (4)
+ !$omp parallel do shared(array1) shared(array2) schedule(static, 4) &
+ !$omp & private(i)
+ !$omp unroll partial(2)
+ do i = 1,n
+ array1(i) = array2(i)
+ end do
+ end subroutine
+end module test_functions
+
+program test
+ use test_functions
+ implicit none
+ integer :: array1(100), array2(100)
+ integer :: i
+
+ array1 = 2
+ call copy(array1, array2, 1, 100)
+ do i=1,100
+ if (array1(i) /= array2(i)) then
+ stop 1
+ end if
+ end do
+end program
--- /dev/null
+! { dg-do run }
+! { dg-options "-fno-openmp -fopenmp-simd" }
+
+module test_functions
+ contains
+ integer function compute_sum() result(sum)
+ implicit none
+ integer :: i,j
+
+ sum = 0
+ !$omp simd reduction(+:sum)
+ do i = 1,10,3
+ !$omp unroll full
+ do j = 1,10,3
+ sum = sum + 1
+ end do
+ end do
+ end function compute_sum
+end module test_functions
+
+program test
+ use test_functions
+ implicit none
+ integer :: result
+
+ result = compute_sum ()
+ if (result .ne. 16) then
+ stop 1
+ end if
+end program
--- /dev/null
+module matrix
+ implicit none
+ integer :: n = 10
+ integer :: m = 10
+
+contains
+
+ function mult (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c( n, m ))
+ do i = 1,10
+ do j = 1,n
+ c(j,i) = 0
+ end do
+ end do
+
+ !$omp unroll partial(10)
+ !$omp tile sizes(1, 3)
+ do i = 1,10
+ do j = 1,n
+ do k = 1, n
+ c(j,i) = c(j,i) + a(k, i) * b(j, k)
+ end do
+ end do
+ end do
+ end function mult
+
+ function mult2 (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c(n, m))
+ do i = 1,10
+ do j = 1,n
+ c(j,i) = 0
+ end do
+ end do
+
+ !$omp unroll partial(2)
+ !$omp tile sizes(1,2)
+ do i = 1,10
+ do j = 1,n
+ do k = 1, n
+ c(j,i) = c(j,i) + a(k, i) * b(j, k)
+ end do
+ end do
+ end do
+ end function mult2
+
+ subroutine print_matrix (m)
+ integer, allocatable :: m(:,:)
+ integer :: i, j, n
+
+ n = size (m, 1)
+ do i = 1,n
+ do j = 1,n
+ write (*, fmt="(i4)", advance='no') m(j, i)
+ end do
+ write (*, *) ""
+ end do
+ write (*, *) ""
+ end subroutine
+
+end module matrix
+
+program main
+ use matrix
+ implicit none
+ integer, allocatable :: a(:,:),b(:,:),c(:,:),d(:,:)
+ integer :: i,j
+
+ allocate(a( n, m ))
+ allocate(b( n, m ))
+
+ do i = 1,n
+ do j = 1,m
+ a(j,i) = merge(1,0, i.eq.j)
+ b(j,i) = j
+ end do
+ end do
+
+ d = mult (a, b)
+
+ call print_matrix (a)
+ call print_matrix (b)
+ call print_matrix (d)
+
+ do i = 1,n
+ do j = 1,m
+ if (b(i,j) .ne. d(i,j)) stop 1
+ end do
+ end do
+
+ c = mult2 (a, b)
+
+ call print_matrix (a)
+ call print_matrix (b)
+ call print_matrix (c)
+
+ do i = 1,n
+ do j = 1,m
+ if (b(i,j) .ne. c(i,j)) stop 2
+ end do
+ end do
+
+end program main
--- /dev/null
+module matrix
+ implicit none
+ integer :: n = 10
+ integer :: m = 10
+
+contains
+
+ function copy (a, b) result (c)
+ integer, allocatable, dimension (:,:) :: a,b,c
+ integer :: i, j, k, inner
+
+ allocate(c(n, m))
+ do i = 1,10
+ do j = 1,n
+ c(j,i) = 0
+ end do
+ end do
+
+ !$omp unroll partial(2)
+ !$omp tile sizes (1,5)
+ do i = 1,10
+ do j = 1,n
+ c(j,i) = c(j,i) + a(j, i)
+ end do
+ end do
+ end function copy
+
+ subroutine print_matrix (m)
+ integer, allocatable :: m(:,:)
+ integer :: i, j, n
+
+ n = size (m, 1)
+ do i = 1,n
+ do j = 1,n
+ write (*, fmt="(i4)", advance='no') m(j, i)
+ end do
+ write (*, *) ""
+ end do
+ write (*, *) ""
+ end subroutine
+end module matrix
+
+program main
+ use matrix
+ implicit none
+ integer, allocatable :: a(:,:),b(:,:),c(:,:)
+ integer :: i,j
+
+ allocate(a(n, m))
+ allocate(b(n, m))
+
+ do i = 1,n
+ do j = 1,m
+ a(j,i) = 1
+ end do
+ end do
+
+ c = copy (a, b)
+
+ call print_matrix (a)
+ call print_matrix (b)
+ call print_matrix (c)
+
+ do i = 1,n
+ do j = 1,m
+ if (c(i,j) .ne. a(i,j)) stop 1
+ end do
+ end do
+
+end program main