public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [gomp] OpenMP 3.0 C parser changes
@ 2007-11-13 21:54 Jakub Jelinek
  2007-11-13 22:42 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2007-11-13 21:54 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Henderson

Hi!

This patch parses the new OpenMP 3.0 stuff in the C parser, except that
collapse clause is just parsed ATM and stored in the list of clauses,
the parser doesn't ensure for collapse(X) there are X perfectly nested
loops with the required properties.  The next step will be handle that
and then gimplification of OMP_TASK (which should be similar to
OMP_PARALLEL, except the few different implicit data sharing rules
where OMP_TASK has some stuff implicitly firstprivate, while OMP_PARALLEL
has them shared).

Committed to gomp-3_0-branch.

2007-11-13  Jakub Jelinek  <jakub@redhat.com>

	* c-parser.c (c_parser_pragma): Handle PRAGMA_OMP_TASKWAIT.
	(c_parser_omp_clause_name): Handle collapse and untied clauses.
	(c_parser_omp_clause_collapse, c_parser_omp_clause_untied): New
	functions.
	(c_parser_omp_clause_schedule): Handle schedule(auto).
	(c_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_COLLAPSE
	and PRAGMA_OMP_CLAUSE_UNTIED.
	(OMP_TASK_CLAUSE_MASK): Define.
	(c_parser_omp_task, c_parser_omp_taskwait): New functions.
	(c_parser_omp_construct): Handle PRAGMA_OMP_TASK.
	* tree-gimple.c (is_gimple_stmt): Handle OMP_TASK.
	* tree.def (OMP_TASK): New tree code.
	* c-tree.h (c_begin_omp_task, c_finish_omp_task): New prototypes.
	* omp-builtins.def (BUILT_IN_GOMP_TASKWAIT): New builtin.
	* tree.h (OMP_DIRECTIVE_P): Add OMP_TASK.
	(OMP_CLAUSE_COLLAPSE, OMP_CLAUSE_UNTIED): New clause codes.
	(OMP_TASK_BODY, OMP_TASK_CLAUSES, OMP_TASK_FN, OMP_TASK_DATA_ARG):
	Define.
	(OMP_CLAUSE_COLLAPSE_EXPR): Define.
	(OMP_CLAUSE_SCHEDULE_AUTO): New schedule kind.
	* tree.c (omp_clause_num_ops, omp_clause_code_name): Add
	OMP_CLAUSE_COLLAPSE and OMP_CLAUSE_UNTIED entries.
	(walk_tree_1): Handle OMP_CLAUSE_COLLAPSE and OMP_CLAUSE_UNTIED.
	* c-pragma.h (PRAGMA_OMP_TASK, PRAGMA_OMP_TASKWAIT): New.
	(PRAGMA_OMP_CLAUSE_COLLAPSE, PRAGMA_OMP_CLAUSE_UNTIED): New.
	* c-typeck.c (c_begin_omp_task, c_finish_omp_task): New functions.
	(c_finish_omp_clauses): Handle OMP_CLAUSE_COLLAPSE and
	OMP_CLAUSE_UNTIED.
	* c-pragma.c (init_pragma): Init omp task and omp taskwait pragmas.
	* c-common.h (c_finish_omp_taskwait): New prototype.
	* gimple-low.c (lower_stmt): Handle OMP_TASK.
	* tree-pretty-print.c (dump_omp_clause): Handle
	OMP_CLAUSE_SCHEDULE_AUTO, OMP_CLAUSE_UNTIED and OMP_CLAUSE_COLLAPSE.
	(dump_generic_node): Handle OMP_TASK.
	* c-omp.c (c_finish_omp_taskwait): New function.
	(c_split_parallel_clauses): Put OMP_CLAUSE_COLLAPSE clause to
	ws_clauses.

--- gcc/c-parser.c.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/c-parser.c	2007-11-13 20:55:46.000000000 +0100
@@ -1020,6 +1020,7 @@ static void c_parser_omp_construct (c_pa
 static void c_parser_omp_threadprivate (c_parser *);
 static void c_parser_omp_barrier (c_parser *);
 static void c_parser_omp_flush (c_parser *);
+static void c_parser_omp_taskwait (c_parser *);
 
 enum pragma_context { pragma_external, pragma_stmt, pragma_compound };
 static bool c_parser_pragma (c_parser *, enum pragma_context);
@@ -6544,6 +6545,17 @@ c_parser_pragma (c_parser *parser, enum 
       c_parser_omp_flush (parser);
       return false;
 
+    case PRAGMA_OMP_TASKWAIT:
+      if (context != pragma_compound)
+	{
+	  if (context == pragma_stmt)
+	    c_parser_error (parser, "%<#pragma omp taskwait%> may only be "
+			    "used in compound statements");
+	  goto bad_stmt;
+	}
+      c_parser_omp_taskwait (parser);
+      return false;
+
     case PRAGMA_OMP_THREADPRIVATE:
       c_parser_omp_threadprivate (parser);
       return false;
@@ -6650,7 +6662,9 @@ c_parser_omp_clause_name (c_parser *pars
       switch (p[0])
 	{
 	case 'c':
-	  if (!strcmp ("copyin", p))
+	  if (!strcmp ("collapse", p))
+	    result = PRAGMA_OMP_CLAUSE_COLLAPSE;
+	  else if (!strcmp ("copyin", p))
 	    result = PRAGMA_OMP_CLAUSE_COPYIN;
           else if (!strcmp ("copyprivate", p))
 	    result = PRAGMA_OMP_CLAUSE_COPYPRIVATE;
@@ -6687,6 +6701,10 @@ c_parser_omp_clause_name (c_parser *pars
 	  else if (!strcmp ("shared", p))
 	    result = PRAGMA_OMP_CLAUSE_SHARED;
 	  break;
+	case 'u':
+	  if (!strcmp ("untied", p))
+	    result = PRAGMA_OMP_CLAUSE_UNTIED;
+	  break;
 	}
     }
 
@@ -6775,6 +6793,35 @@ c_parser_omp_var_list_parens (c_parser *
   return list;
 }
 
+/* OpenMP 3.0:
+   collapse ( constant-expression ) */
+
+static tree
+c_parser_omp_clause_collapse (c_parser *parser, tree list)
+{
+  tree c, num = error_mark_node;
+
+  check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
+
+  if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
+    {
+      num = c_parser_expr_no_commas (parser, NULL).value;
+      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>");
+    }
+  if (num == error_mark_node)
+    return list;
+  if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
+      || TREE_CODE (num) != INTEGER_CST
+      || tree_int_cst_sgn (num) != 1)
+    {
+      error ("collapse argument needs positive constant integer expression");
+      return list;
+    }
+  c = build_omp_clause (OMP_CLAUSE_COLLAPSE);
+  OMP_CLAUSE_CHAIN (c) = list;
+  return c;
+}
+
 /* OpenMP 2.5:
    copyin ( variable-list ) */
 
@@ -7032,7 +7079,7 @@ c_parser_omp_clause_reduction (c_parser 
    schedule ( schedule-kind , expression )
 
    schedule-kind:
-     static | dynamic | guided | runtime
+     static | dynamic | guided | runtime | auto
 */
 
 static tree
@@ -7076,6 +7123,8 @@ c_parser_omp_clause_schedule (c_parser *
     }
   else if (c_parser_next_token_is_keyword (parser, RID_STATIC))
     OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC;
+  else if (c_parser_next_token_is_keyword (parser, RID_AUTO))
+    OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO;
   else
     goto invalid_kind;
 
@@ -7089,6 +7138,9 @@ c_parser_omp_clause_schedule (c_parser *
       if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME)
 	error ("schedule %<runtime%> does not take "
 	       "a %<chunk_size%> parameter");
+      else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
+	error ("schedule %<auto%> does not take "
+	       "a %<chunk_size%> parameter");
       else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
 	OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
       else
@@ -7119,6 +7171,22 @@ c_parser_omp_clause_shared (c_parser *pa
   return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list);
 }
 
+/* OpenMP 3.0:
+   untied */
+
+static tree
+c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list)
+{
+  tree c;
+
+  /* FIXME: Should we allow duplicates?  */
+  check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied");
+
+  c = build_omp_clause (OMP_CLAUSE_UNTIED);
+  OMP_CLAUSE_CHAIN (c) = list;
+  return c;
+}
+
 /* Parse all OpenMP clauses.  The set clauses allowed by the directive
    is a bitmask in MASK.  Return the list of clauses found; the result
    of clause default goes in *pdefault.  */
@@ -7137,6 +7205,10 @@ c_parser_omp_all_clauses (c_parser *pars
 
       switch (c_kind)
 	{
+	case PRAGMA_OMP_CLAUSE_COLLAPSE:
+	  clauses = c_parser_omp_clause_collapse (parser, clauses);
+	  c_name = "collapse";
+	  break;
 	case PRAGMA_OMP_CLAUSE_COPYIN:
 	  clauses = c_parser_omp_clause_copyin (parser, clauses);
 	  c_name = "copyin";
@@ -7189,6 +7261,10 @@ c_parser_omp_all_clauses (c_parser *pars
 	  clauses = c_parser_omp_clause_shared (parser, clauses);
 	  c_name = "shared";
 	  break;
+	case PRAGMA_OMP_CLAUSE_UNTIED:
+	  clauses = c_parser_omp_clause_untied (parser, clauses);
+	  c_name = "untied";
+	  break;
 	default:
 	  c_parser_error (parser, "expected %<#pragma omp%> clause");
 	  goto saw_error;
@@ -7745,6 +7821,43 @@ c_parser_omp_single (c_parser *parser)
   return add_stmt (stmt);
 }
 
+/* OpenMP 3.0:
+   # pragma omp task task-clause[optseq] new-line
+*/
+
+#define OMP_TASK_CLAUSE_MASK				\
+	( (1u << PRAGMA_OMP_CLAUSE_IF)			\
+	| (1u << PRAGMA_OMP_CLAUSE_UNTIED)		\
+	| (1u << PRAGMA_OMP_CLAUSE_DEFAULT)		\
+	| (1u << PRAGMA_OMP_CLAUSE_PRIVATE)		\
+	| (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE)	\
+	| (1u << PRAGMA_OMP_CLAUSE_SHARED))
+
+static tree
+c_parser_omp_task (c_parser *parser)
+{
+  tree clauses, block;
+
+  clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK,
+				      "#pragma omp task");
+
+  block = c_begin_omp_task ();
+  c_parser_statement (parser);
+  return c_finish_omp_task (clauses, block);
+}
+
+/* OpenMP 3.0:
+   # pragma omp taskwait new-line
+*/
+
+static void
+c_parser_omp_taskwait (c_parser *parser)
+{
+  c_parser_consume_pragma (parser);
+  c_parser_skip_to_pragma_eol (parser);
+
+  c_finish_omp_taskwait ();
+}
 
 /* Main entry point to parsing most OpenMP pragmas.  */
 
@@ -7791,6 +7904,9 @@ c_parser_omp_construct (c_parser *parser
     case PRAGMA_OMP_SINGLE:
       stmt = c_parser_omp_single (parser);
       break;
+    case PRAGMA_OMP_TASK:
+      stmt = c_parser_omp_task (parser);
+      break;
     default:
       gcc_unreachable ();
     }
--- gcc/tree-gimple.c.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/tree-gimple.c	2007-11-13 20:29:22.000000000 +0100
@@ -240,6 +240,7 @@ is_gimple_stmt (tree t)
     case OMP_CRITICAL:
     case OMP_RETURN:
     case OMP_CONTINUE:
+    case OMP_TASK:
       /* These are always void.  */
       return true;
 
--- gcc/tree.def.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/tree.def	2007-11-13 18:04:29.000000000 +0100
@@ -989,6 +989,18 @@ DEFTREECODE (TARGET_MEM_REF, "target_mem
 
 DEFTREECODE (OMP_PARALLEL, "omp_parallel", tcc_statement, 4)
 
+/* OpenMP - #pragma omp task [clause1 ... clauseN]
+   Operand 0: OMP_TASK_BODY: Code to be executed by all threads.
+   Operand 1: OMP_TASK_CLAUSES: List of clauses.
+   Operand 2: OMP_TASK_FN: FUNCTION_DECL used when outlining the
+	      body of the task region.  Only valid after
+	      pass_lower_omp.
+   Operand 3: OMP_TASK_DATA_ARG: Local variable in the parent
+	      function containing data to be shared with the child
+	      function.  */
+
+DEFTREECODE (OMP_TASK, "omp_task", tcc_statement, 4)
+
 /* OpenMP - #pragma omp for [clause1 ... clauseN]
    Operand 0: OMP_FOR_BODY: Loop body.
    Operand 1: OMP_FOR_CLAUSES: List of clauses.
--- gcc/c-tree.h.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/c-tree.h	2007-11-13 18:10:05.000000000 +0100
@@ -598,6 +598,8 @@ extern void c_end_vm_scope (unsigned int
 extern tree c_expr_to_decl (tree, bool *, bool *, bool *);
 extern tree c_begin_omp_parallel (void);
 extern tree c_finish_omp_parallel (tree, tree);
+extern tree c_begin_omp_task (void);
+extern tree c_finish_omp_task (tree, tree);
 extern tree c_finish_omp_clauses (tree);
 
 /* Set to 0 at beginning of a function definition, set to 1 if
--- gcc/omp-builtins.def.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/omp-builtins.def	2007-11-13 18:23:40.000000000 +0100
@@ -35,6 +35,8 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_ATOMIC_E
 		  BT_FN_VOID, ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_BARRIER, "GOMP_barrier",
 		  BT_FN_VOID, ATTR_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_TASKWAIT, "GOMP_taskwait",
+		  BT_FN_VOID, ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_CRITICAL_START, "GOMP_critical_start",
 		  BT_FN_VOID, ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_CRITICAL_END, "GOMP_critical_end",
--- gcc/tree.h.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/tree.h	2007-11-13 18:06:23.000000000 +0100
@@ -186,6 +186,7 @@ extern const enum tree_code_class tree_c
 
 #define OMP_DIRECTIVE_P(NODE)				\
     (TREE_CODE (NODE) == OMP_PARALLEL			\
+     || TREE_CODE (NODE) == OMP_TASK			\
      || TREE_CODE (NODE) == OMP_FOR			\
      || TREE_CODE (NODE) == OMP_SECTIONS		\
      || TREE_CODE (NODE) == OMP_SECTIONS_SWITCH		\
@@ -338,7 +339,13 @@ enum omp_clause_code
   OMP_CLAUSE_ORDERED,
 
   /* OpenMP clause: default.  */
-  OMP_CLAUSE_DEFAULT
+  OMP_CLAUSE_DEFAULT,
+
+  /* OpenMP clause: collapse (constant-integer-expression).  */
+  OMP_CLAUSE_COLLAPSE,
+
+  /* OpenMP clause: untied.  */
+  OMP_CLAUSE_UNTIED
 };
 \f
 /* The definition of tree nodes fills the next several pages.  */
@@ -1733,6 +1740,11 @@ struct tree_constructor GTY(())
 #define OMP_PARALLEL_FN(NODE) TREE_OPERAND (OMP_PARALLEL_CHECK (NODE), 2)
 #define OMP_PARALLEL_DATA_ARG(NODE) TREE_OPERAND (OMP_PARALLEL_CHECK (NODE), 3)
 
+#define OMP_TASK_BODY(NODE)	   TREE_OPERAND (OMP_TASK_CHECK (NODE), 0)
+#define OMP_TASK_CLAUSES(NODE)	   TREE_OPERAND (OMP_TASK_CHECK (NODE), 1)
+#define OMP_TASK_FN(NODE)	   TREE_OPERAND (OMP_TASK_CHECK (NODE), 2)
+#define OMP_TASK_DATA_ARG(NODE)	   TREE_OPERAND (OMP_TASK_CHECK (NODE), 3)
+
 #define OMP_FOR_BODY(NODE)	   TREE_OPERAND (OMP_FOR_CHECK (NODE), 0)
 #define OMP_FOR_CLAUSES(NODE)	   TREE_OPERAND (OMP_FOR_CHECK (NODE), 1)
 #define OMP_FOR_INIT(NODE)	   TREE_OPERAND (OMP_FOR_CHECK (NODE), 2)
@@ -1796,6 +1808,8 @@ struct tree_constructor GTY(())
   OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_NUM_THREADS),0)
 #define OMP_CLAUSE_SCHEDULE_CHUNK_EXPR(NODE) \
   OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_SCHEDULE), 0)
+#define OMP_CLAUSE_COLLAPSE_EXPR(NODE) \
+  OMP_CLAUSE_OPERAND (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_COLLAPSE),0)
 
 #define OMP_CLAUSE_REDUCTION_CODE(NODE)	\
   (OMP_CLAUSE_SUBCODE_CHECK (NODE, OMP_CLAUSE_REDUCTION)->omp_clause.subcode.reduction_code)
@@ -1811,6 +1825,7 @@ enum omp_clause_schedule_kind
   OMP_CLAUSE_SCHEDULE_STATIC,
   OMP_CLAUSE_SCHEDULE_DYNAMIC,
   OMP_CLAUSE_SCHEDULE_GUIDED,
+  OMP_CLAUSE_SCHEDULE_AUTO,
   OMP_CLAUSE_SCHEDULE_RUNTIME
 };
 
--- gcc/tree.c.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/tree.c	2007-11-13 20:15:56.000000000 +0100
@@ -186,7 +186,9 @@ unsigned const char omp_clause_num_ops[]
   1, /* OMP_CLAUSE_SCHEDULE  */
   0, /* OMP_CLAUSE_NOWAIT  */
   0, /* OMP_CLAUSE_ORDERED  */
-  0  /* OMP_CLAUSE_DEFAULT  */
+  0, /* OMP_CLAUSE_DEFAULT  */
+  1, /* OMP_CLAUSE_COLLAPSE  */
+  0  /* OMP_CLAUSE_UNTIED   */
 };
 
 const char * const omp_clause_code_name[] =
@@ -204,7 +206,9 @@ const char * const omp_clause_code_name[
   "schedule",
   "nowait",
   "ordered",
-  "default"
+  "default",
+  "collapse",
+  "untied"
 };
 \f
 /* Init tree.c.  */
@@ -8494,6 +8498,8 @@ walk_tree_1 (tree *tp, walk_tree_fn func
 	case OMP_CLAUSE_NOWAIT:
 	case OMP_CLAUSE_ORDERED:
 	case OMP_CLAUSE_DEFAULT:
+	case OMP_CLAUSE_COLLAPSE:
+	case OMP_CLAUSE_UNTIED:
 	  WALK_SUBTREE_TAIL (OMP_CLAUSE_CHAIN (*tp));
 
 	case OMP_CLAUSE_REDUCTION:
--- gcc/c-pragma.h.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/c-pragma.h	2007-11-13 17:47:31.000000000 +0100
@@ -41,6 +41,8 @@ typedef enum pragma_kind {
   PRAGMA_OMP_SECTION,
   PRAGMA_OMP_SECTIONS,
   PRAGMA_OMP_SINGLE,
+  PRAGMA_OMP_TASK,
+  PRAGMA_OMP_TASKWAIT,
   PRAGMA_OMP_THREADPRIVATE,
 
   PRAGMA_GCC_PCH_PREPROCESS,
@@ -49,11 +51,12 @@ typedef enum pragma_kind {
 } pragma_kind;
 
 
-/* All clauses defined by OpenMP 2.5.
+/* All clauses defined by OpenMP 2.5 and 3.0.
    Used internally by both C and C++ parsers.  */
 typedef enum pragma_omp_clause {
   PRAGMA_OMP_CLAUSE_NONE = 0,
 
+  PRAGMA_OMP_CLAUSE_COLLAPSE,
   PRAGMA_OMP_CLAUSE_COPYIN,
   PRAGMA_OMP_CLAUSE_COPYPRIVATE,
   PRAGMA_OMP_CLAUSE_DEFAULT,
@@ -66,7 +69,8 @@ typedef enum pragma_omp_clause {
   PRAGMA_OMP_CLAUSE_PRIVATE,
   PRAGMA_OMP_CLAUSE_REDUCTION,
   PRAGMA_OMP_CLAUSE_SCHEDULE,
-  PRAGMA_OMP_CLAUSE_SHARED
+  PRAGMA_OMP_CLAUSE_SHARED,
+  PRAGMA_OMP_CLAUSE_UNTIED
 } pragma_omp_clause;
 
 extern struct cpp_reader* parse_in;
--- gcc/c-typeck.c.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/c-typeck.c	2007-11-13 20:09:55.000000000 +0100
@@ -8681,6 +8681,32 @@ c_finish_omp_parallel (tree clauses, tre
   return add_stmt (stmt);
 }
 
+tree
+c_begin_omp_task (void)
+{
+  tree block;
+
+  keep_next_level ();
+  block = c_begin_compound_stmt (true);
+
+  return block;
+}
+
+tree
+c_finish_omp_task (tree clauses, tree block)
+{
+  tree stmt;
+
+  block = c_end_compound_stmt (block, true);
+
+  stmt = make_node (OMP_TASK);
+  TREE_TYPE (stmt) = void_type_node;
+  OMP_TASK_CLAUSES (stmt) = clauses;
+  OMP_TASK_BODY (stmt) = block;
+
+  return add_stmt (stmt);
+}
+
 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
    Remove any elements from the list that are invalid.  */
 
@@ -8841,6 +8867,8 @@ c_finish_omp_clauses (tree clauses)
 	case OMP_CLAUSE_NOWAIT:
 	case OMP_CLAUSE_ORDERED:
 	case OMP_CLAUSE_DEFAULT:
+	case OMP_CLAUSE_UNTIED:
+	case OMP_CLAUSE_COLLAPSE:
 	  pc = &OMP_CLAUSE_CHAIN (c);
 	  continue;
 
--- gcc/c-pragma.c.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/c-pragma.c	2007-11-13 17:45:28.000000000 +0100
@@ -935,6 +935,8 @@ init_pragma (void)
 	{ "section", PRAGMA_OMP_SECTION },
 	{ "sections", PRAGMA_OMP_SECTIONS },
 	{ "single", PRAGMA_OMP_SINGLE },
+	{ "task", PRAGMA_OMP_TASK },
+	{ "taskwait", PRAGMA_OMP_TASKWAIT },
 	{ "threadprivate", PRAGMA_OMP_THREADPRIVATE }
       };
 
--- gcc/c-common.h.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/c-common.h	2007-11-13 18:20:04.000000000 +0100
@@ -993,6 +993,7 @@ extern tree c_finish_omp_ordered (tree);
 extern void c_finish_omp_barrier (void);
 extern tree c_finish_omp_atomic (enum tree_code, tree, tree);
 extern void c_finish_omp_flush (void);
+extern void c_finish_omp_taskwait (void);
 extern tree c_finish_omp_for (location_t, tree, tree, tree, tree, tree, tree);
 extern void c_split_parallel_clauses (tree, tree *, tree *);
 extern enum omp_clause_default_kind c_omp_predetermined_sharing (tree);
--- gcc/gimple-low.c.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/gimple-low.c	2007-11-13 20:31:11.000000000 +0100
@@ -276,6 +276,7 @@ lower_stmt (tree_stmt_iterator *tsi, str
       break;
 
     case OMP_PARALLEL:
+    case OMP_TASK:
       lower_omp_directive (tsi, data);
       return;
 
--- gcc/tree-pretty-print.c.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/tree-pretty-print.c	2007-11-13 20:56:20.000000000 +0100
@@ -366,6 +366,9 @@ dump_omp_clause (pretty_printer *buffer,
       case OMP_CLAUSE_SCHEDULE_RUNTIME:
 	pp_string (buffer, "runtime");
 	break;
+      case OMP_CLAUSE_SCHEDULE_AUTO:
+	pp_string (buffer, "auto");
+	break;
       default:
 	gcc_unreachable ();
 	}
@@ -379,6 +382,18 @@ dump_omp_clause (pretty_printer *buffer,
       pp_character (buffer, ')');
       break;
 
+    case OMP_CLAUSE_UNTIED:
+      pp_string (buffer, "untied");
+      break;
+
+    case OMP_CLAUSE_COLLAPSE:
+      pp_string (buffer, "collapse(");
+      dump_generic_node (buffer,
+			 OMP_CLAUSE_COLLAPSE_EXPR (clause),
+			 spc, flags, false);
+      pp_character (buffer, ')');
+      break;
+
     default:
       /* Should never happen.  */
       dump_generic_node (buffer, clause, spc, flags, false);
@@ -1847,6 +1862,26 @@ dump_generic_node (pretty_printer *buffe
       is_expr = false;
       break;
 
+    case OMP_TASK:
+      pp_string (buffer, "#pragma omp task");
+      dump_omp_clauses (buffer, OMP_TASK_CLAUSES (node), spc, flags);
+      if (OMP_TASK_FN (node))
+	{
+	  pp_string (buffer, " [child fn: ");
+	  dump_generic_node (buffer, OMP_TASK_FN (node), spc, flags, false);
+
+	  pp_string (buffer, " (");
+
+	  if (OMP_TASK_DATA_ARG (node))
+	    dump_generic_node (buffer, OMP_TASK_DATA_ARG (node), spc, flags,
+			       false);
+	  else
+	    pp_string (buffer, "???");
+
+	  pp_string (buffer, ")]");
+	}
+      goto dump_omp_body;
+
     case OMP_FOR:
       pp_string (buffer, "#pragma omp for");
       dump_omp_clauses (buffer, OMP_FOR_CLAUSES (node), spc, flags);
--- gcc/c-omp.c.jj	2007-10-22 22:20:21.000000000 +0200
+++ gcc/c-omp.c	2007-11-13 20:32:12.000000000 +0100
@@ -80,6 +80,19 @@ c_finish_omp_barrier (void)
 }
 
 
+/* Complete a #pragma omp taskwait construct.  */
+
+void
+c_finish_omp_taskwait (void)
+{
+  tree x;
+
+  x = built_in_decls[BUILT_IN_GOMP_TASKWAIT];
+  x = build_call_expr (x, 0);
+  add_stmt (x);
+}
+
+
 /* Complete a #pragma omp atomic construct.  The expression to be 
    implemented atomically is LHS code= RHS.  The value returned is
    either error_mark_node (if the construct was erroneous) or an
@@ -416,6 +429,7 @@ c_split_parallel_clauses (tree clauses, 
 
 	case OMP_CLAUSE_SCHEDULE:
 	case OMP_CLAUSE_ORDERED:
+	case OMP_CLAUSE_COLLAPSE:
 	  OMP_CLAUSE_CHAIN (clauses) = *ws_clauses;
 	  *ws_clauses = clauses;
 	  break;

	Jakub

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gomp] OpenMP 3.0 C parser changes
  2007-11-13 21:54 [gomp] OpenMP 3.0 C parser changes Jakub Jelinek
@ 2007-11-13 22:42 ` Tom Tromey
  2007-11-14 21:40   ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2007-11-13 22:42 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Richard Henderson

>>>>> "Jakub" == Jakub Jelinek <jakub@redhat.com> writes:

Jakub> Committed to gomp-3_0-branch.

Jakub> +      error ("collapse argument needs positive constant integer expression");

Before merging back to the trunk, would you mind changing this to pass
an explicit location using %H?  Perhaps the start of the expression
would be the best location.  Except for the few places where it is
really difficult, I'd like to keep the C parser "%H-clean"; this is
(IMO) more maintainable and generally gives better column information.

In this particular error, maybe collapse should be quoted with %<...%>?

Jakub> +	error ("schedule %<auto%> does not take "
Jakub> +	       "a %<chunk_size%> parameter");

... %H here too.

thanks,
Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [gomp] OpenMP 3.0 C parser changes
  2007-11-13 22:42 ` Tom Tromey
@ 2007-11-14 21:40   ` Jakub Jelinek
  0 siblings, 0 replies; 3+ messages in thread
From: Jakub Jelinek @ 2007-11-14 21:40 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gcc-patches, Richard Henderson

On Tue, Nov 13, 2007 at 01:49:20PM -0700, Tom Tromey wrote:
> >>>>> "Jakub" == Jakub Jelinek <jakub@redhat.com> writes:
> 
> Jakub> Committed to gomp-3_0-branch.
> 
> Jakub> +      error ("collapse argument needs positive constant integer expression");
> 
> Before merging back to the trunk, would you mind changing this to pass
> an explicit location using %H?  Perhaps the start of the expression
> would be the best location.  Except for the few places where it is
> really difficult, I'd like to keep the C parser "%H-clean"; this is
> (IMO) more maintainable and generally gives better column information.

Sorry, the branch wasn't merged with the trunk for 3 weeks, so almost no
error message was using it there.
Merged from the trunk today and committed following.
I'm not sure what exacly should be allowed in between collapsed for
statements (only optional { }, or also empty statements, perhaps even
variable declarations without initializers, or unused labels), so I have
asked on OpenMP forum and will probably continue with OMP_TASK instead.

2007-11-14  Jakub Jelinek  <jakub@redhat.com>

	* c-parser.c (c_parser_omp_clause_collapse): Include correct
	location in the error message.  Ensure the argument is reasonable
	positive integer and set OMP_CLAUSE_COLLAPSE_EXPR to it.
	(c_parser_omp_clause_schedule): Include correct location in the
	error message.
	(c_parser_omp_for_loop): Add clauses argument, on success set
	OMP_FOR_CLAUSES to it.  Look up collapse count in clauses.
	(c_parser_omp_for, c_parser_omp_parallel): Adjust callers.
	(OMP_FOR_CLAUSE_MASK): Add 1 << PRAGMA_OMP_CLAUSE_COLLAPSE.
	* omp-builtins.def (BUILT_IN_GOMP_LOOP_AUTO_START,
	BUILT_IN_GOMP_LOOP_ORDERED_AUTO_START, BUILT_IN_GOMP_LOOP_AUTO_NEXT,
	BUILT_IN_GOMP_LOOP_ORDERED_AUTO_NEXT,
	BUILT_IN_GOMP_PARALLEL_LOOP_AUTO_START): New.
	* gimplify.c (gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses):
	Handle OMP_CLAUSE_COLLAPSE and OMP_CLAUSE_UNTIED.
	* omp-low.c (scan_sharing_clauses): Likewise.
	(expand_omp_for): Adjust fn_index computation for the addition of
	schedule(auto).

--- gcc/c-parser.c.jj	2007-11-14 14:48:41.000000000 +0100
+++ gcc/c-parser.c	2007-11-14 18:01:19.000000000 +0100
@@ -6872,9 +6872,12 @@ static tree
 c_parser_omp_clause_collapse (c_parser *parser, tree list)
 {
   tree c, num = error_mark_node;
+  HOST_WIDE_INT n;
+  location_t loc;
 
   check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse");
 
+  loc = c_parser_peek_token (parser)->location;
   if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
     {
       num = c_parser_expr_no_commas (parser, NULL).value;
@@ -6883,13 +6886,16 @@ c_parser_omp_clause_collapse (c_parser *
   if (num == error_mark_node)
     return list;
   if (!INTEGRAL_TYPE_P (TREE_TYPE (num))
-      || TREE_CODE (num) != INTEGER_CST
-      || tree_int_cst_sgn (num) != 1)
+      || !host_integerp (num, 0)
+      || (n = tree_low_cst (num, 0)) <= 0
+      || (int) n != n)
     {
-      error ("collapse argument needs positive constant integer expression");
+      error ("%Hcollapse argument needs positive constant integer expression",
+	     &loc);
       return list;
     }
   c = build_omp_clause (OMP_CLAUSE_COLLAPSE);
+  OMP_CLAUSE_COLLAPSE_EXPR (c) = num;
   OMP_CLAUSE_CHAIN (c) = list;
   return c;
 }
@@ -7214,8 +7220,8 @@ c_parser_omp_clause_schedule (c_parser *
 	error ("%Hschedule %<runtime%> does not take "
 	       "a %<chunk_size%> parameter", &here);
       else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO)
-	error ("schedule %<auto%> does not take "
-	       "a %<chunk_size%> parameter");
+	error ("%Hschedule %<auto%> does not take "
+	       "a %<chunk_size%> parameter", &here);
       else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE)
 	OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
       else
@@ -7533,10 +7539,15 @@ c_parser_omp_flush (c_parser *parser)
    so that we can push a new decl if necessary to make it private.  */
 
 static tree
-c_parser_omp_for_loop (c_parser *parser)
+c_parser_omp_for_loop (c_parser *parser, tree clauses)
 {
-  tree decl, cond, incr, save_break, save_cont, body, init;
+  tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
   location_t loc;
+  int collapse = 1;
+
+  for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl))
+    if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE)
+      collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0);
 
   if (!c_parser_next_token_is_keyword (parser, RID_FOR))
     {
@@ -7609,7 +7620,12 @@ c_parser_omp_for_loop (c_parser *parser)
   /* Only bother calling c_finish_omp_for if we havn't already generated
      an error from the initialization parsing.  */
   if (decl != NULL && decl != error_mark_node && init != error_mark_node)
-    return c_finish_omp_for (loc, decl, init, cond, incr, body, NULL);
+    {
+      stmt = c_finish_omp_for (loc, decl, init, cond, incr, body, NULL);
+      if (stmt)
+	OMP_FOR_CLAUSES (stmt) = clauses;
+      return stmt;
+    }
   return NULL;
 
  error_init:
@@ -7631,6 +7647,7 @@ c_parser_omp_for_loop (c_parser *parser)
 	| (1u << PRAGMA_OMP_CLAUSE_REDUCTION)		\
 	| (1u << PRAGMA_OMP_CLAUSE_ORDERED)		\
 	| (1u << PRAGMA_OMP_CLAUSE_SCHEDULE)		\
+	| (1u << PRAGMA_OMP_CLAUSE_COLLAPSE)		\
 	| (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
 
 static tree
@@ -7642,9 +7659,7 @@ c_parser_omp_for (c_parser *parser)
 				      "#pragma omp for");
 
   block = c_begin_compound_stmt (true);
-  ret = c_parser_omp_for_loop (parser);
-  if (ret)
-    OMP_FOR_CLAUSES (ret) = clauses;
+  ret = c_parser_omp_for_loop (parser, clauses);
   block = c_end_compound_stmt (block, true);
   add_stmt (block);
 
@@ -7849,9 +7864,7 @@ c_parser_omp_parallel (c_parser *parser)
     case PRAGMA_OMP_PARALLEL_FOR:
       block = c_begin_omp_parallel ();
       c_split_parallel_clauses (clauses, &par_clause, &ws_clause);
-      stmt = c_parser_omp_for_loop (parser);
-      if (stmt)
-	OMP_FOR_CLAUSES (stmt) = ws_clause;
+      c_parser_omp_for_loop (parser, ws_clause);
       stmt = c_finish_omp_parallel (par_clause, block);
       OMP_PARALLEL_COMBINED (stmt) = 1;
       break;
--- gcc/omp-builtins.def.jj	2007-11-14 12:47:20.000000000 +0100
+++ gcc/omp-builtins.def	2007-11-14 16:02:08.000000000 +0100
@@ -62,6 +62,10 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_GUI
 		  "GOMP_loop_guided_start",
 		  BT_FN_BOOL_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR,
 		  ATTR_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_AUTO_START,
+		  "GOMP_loop_auto_start",
+		  BT_FN_BOOL_LONG_LONG_LONG_LONGPTR_LONGPTR,
+		  ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_RUNTIME_START,
 		  "GOMP_loop_runtime_start",
 		  BT_FN_BOOL_LONG_LONG_LONG_LONGPTR_LONGPTR,
@@ -78,6 +82,10 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORD
 		  "GOMP_loop_ordered_guided_start",
 		  BT_FN_BOOL_LONG_LONG_LONG_LONG_LONGPTR_LONGPTR,
 		  ATTR_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORDERED_AUTO_START,
+		  "GOMP_loop_ordered_auto_start",
+		  BT_FN_BOOL_LONG_LONG_LONG_LONGPTR_LONGPTR,
+		  ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORDERED_RUNTIME_START,
 		  "GOMP_loop_ordered_runtime_start",
 		  BT_FN_BOOL_LONG_LONG_LONG_LONGPTR_LONGPTR,
@@ -88,6 +96,8 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_DYN
 		  BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_GUIDED_NEXT, "GOMP_loop_guided_next",
 		  BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_AUTO_NEXT, "GOMP_loop_auto_next",
+		  BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_RUNTIME_NEXT, "GOMP_loop_runtime_next",
 		  BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORDERED_STATIC_NEXT,
@@ -99,6 +109,9 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORD
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORDERED_GUIDED_NEXT,
 		  "GOMP_loop_ordered_guided_next",
 		  BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORDERED_AUTO_NEXT,
+		  "GOMP_loop_ordered_auto_next",
+		  BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_LOOP_ORDERED_RUNTIME_NEXT,
 		  "GOMP_loop_ordered_runtime_next",
 		  BT_FN_BOOL_LONGPTR_LONGPTR, ATTR_NOTHROW_LIST)
@@ -117,6 +130,10 @@ DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL
 		  "GOMP_parallel_loop_guided_start",
 		  BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG_LONG,
 		  ATTR_NOTHROW_LIST)
+DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL_LOOP_AUTO_START,
+		  "GOMP_parallel_loop_auto_start",
+		  BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG,
+		  ATTR_NOTHROW_LIST)
 DEF_GOMP_BUILTIN (BUILT_IN_GOMP_PARALLEL_LOOP_RUNTIME_START,
 		  "GOMP_parallel_loop_runtime_start",
 		  BT_FN_VOID_OMPFN_PTR_UINT_LONG_LONG_LONG,
--- gcc/gimplify.c.jj	2007-11-14 14:39:21.000000000 +0100
+++ gcc/gimplify.c	2007-11-14 17:33:47.000000000 +0100
@@ -4958,6 +4958,8 @@ gimplify_scan_omp_clauses (tree *list_p,
 
 	case OMP_CLAUSE_NOWAIT:
 	case OMP_CLAUSE_ORDERED:
+	case OMP_CLAUSE_UNTIED:
+	case OMP_CLAUSE_COLLAPSE:
 	  break;
 
 	case OMP_CLAUSE_DEFAULT:
@@ -5093,6 +5095,8 @@ gimplify_adjust_omp_clauses (tree *list_
 	case OMP_CLAUSE_NOWAIT:
 	case OMP_CLAUSE_ORDERED:
 	case OMP_CLAUSE_DEFAULT:
+	case OMP_CLAUSE_UNTIED:
+	case OMP_CLAUSE_COLLAPSE:
 	  break;
 
 	default:
--- gcc/omp-low.c.jj	2007-11-14 14:31:22.000000000 +0100
+++ gcc/omp-low.c	2007-11-14 17:39:24.000000000 +0100
@@ -1030,6 +1030,8 @@ scan_sharing_clauses (tree clauses, omp_
 
 	case OMP_CLAUSE_NOWAIT:
 	case OMP_CLAUSE_ORDERED:
+	case OMP_CLAUSE_COLLAPSE:
+	case OMP_CLAUSE_UNTIED:
 	  break;
 
 	default:
@@ -1076,6 +1078,8 @@ scan_sharing_clauses (tree clauses, omp_
 	case OMP_CLAUSE_SCHEDULE:
 	case OMP_CLAUSE_NOWAIT:
 	case OMP_CLAUSE_ORDERED:
+	case OMP_CLAUSE_COLLAPSE:
+	case OMP_CLAUSE_UNTIED:
 	  break;
 
 	default:
@@ -3279,7 +3283,7 @@ expand_omp_for (struct omp_region *regio
     }
   else
     {
-      int fn_index = fd.sched_kind + fd.have_ordered * 4;
+      int fn_index = fd.sched_kind + fd.have_ordered * 5;
       int start_ix = BUILT_IN_GOMP_LOOP_STATIC_START + fn_index;
       int next_ix = BUILT_IN_GOMP_LOOP_STATIC_NEXT + fn_index;
       expand_omp_for_generic (region, &fd, start_ix, next_ix);

	Jakub

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-11-14 19:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-13 21:54 [gomp] OpenMP 3.0 C parser changes Jakub Jelinek
2007-11-13 22:42 ` Tom Tromey
2007-11-14 21:40   ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).