This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gomp] parse OpenMP directives


Hi,

The following patch registers a set of functions for parsing the
OpenMP directives.  Most of the functions are not yet implemented, but
I wanted to get some feed-back from the CPP people on whether this is
the right approach for parsing the directives.

Installed in the gomp-branch after bootstrap on i686.

Sebastian

Index: ChangeLog.gomp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/ChangeLog.gomp,v
retrieving revision 1.1.2.1
diff -d -u -p -r1.1.2.1 ChangeLog.gomp
--- ChangeLog.gomp	8 Oct 2004 18:47:52 -0000	1.1.2.1
+++ ChangeLog.gomp	13 Oct 2004 07:59:28 -0000
@@ -1,4 +1,17 @@
 2004-10-13  Sebastian Pop  <pop@cri.ensmp.fr>
 
+	* Makefile.in (C_AND_OBJC_OBJS): Add dependence on c-gomp.o.
+	(c-gomp.o): New rule.
+	* c-gomp.c: New file.
+	* c-common.h (c_gomp_parallel_pragma, c_gomp_for_pragma,
+	c_gomp_parallel_for_pragma, c_gomp_parallel_sections_pragma,
+	c_gomp_sections_pragma, c_gomp_section_pragma, c_gomp_single_pragma,
+	c_gomp_master_pragma, c_gomp_critical_pragma, c_gomp_barrier_pragma,
+	c_gomp_atomic_pragma, c_gomp_flush_pragma, c_gomp_ordered_pragma,
+	c_gomp_threadprivate_pragma): Declared.
+	* c-pragma.c (init_pragma): Register all the above functions.
+
+2004-10-08  Sebastian Pop  <pop@cri.ensmp.fr>
+
 	Merge from mainline (gomp-merge-2004-10-08).
 	* ChangeLog.gomp: New file.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1375.2.1
diff -d -u -p -r1.1375.2.1 Makefile.in
--- Makefile.in	8 Oct 2004 18:47:52 -0000	1.1375.2.1
+++ Makefile.in	13 Oct 2004 07:59:29 -0000
@@ -879,7 +879,7 @@ C_AND_OBJC_OBJS = attribs.o c-errors.o c
   c-convert.o c-aux-info.o c-common.o c-opts.o c-format.o c-semantics.o \
   c-incpath.o cppdefault.o c-ppoutput.o c-cppbuiltin.o prefix.o \
   c-objc-common.o c-dump.o c-pch.o $(C_TARGET_OBJS) \
-  c-gimplify.o tree-mudflap.o c-pretty-print.o
+  c-gimplify.o tree-mudflap.o c-pretty-print.o c-gomp.o
 
 # Language-specific object files for C.
 C_OBJS = c-parse.o c-lang.o stub-objc.o $(C_AND_OBJC_OBJS)
@@ -1401,6 +1401,9 @@ c-convert.o : c-convert.c $(CONFIG_H) $(
 c-pragma.o: c-pragma.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
     $(TREE_H) function.h $(C_PRAGMA_H) toplev.h output.h $(GGC_H) $(TM_P_H) \
     $(C_COMMON_H) $(TARGET_H) gt-c-pragma.h
+c-gomp.o: c-gomp.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
+    $(TREE_H) function.h $(C_PRAGMA_H) toplev.h output.h $(GGC_H) $(TM_P_H) \
+    $(C_COMMON_H) $(TARGET_H) $(C_TREE_H) gt-c-pragma.h
 graph.o: graph.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) toplev.h $(FLAGS_H) output.h \
     $(RTL_H) function.h hard-reg-set.h $(BASIC_BLOCK_H) graph.h
 sbitmap.o: sbitmap.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) $(FLAGS_H) \
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.263.2.1
diff -d -u -p -r1.263.2.1 c-common.h
--- c-common.h	8 Oct 2004 18:48:00 -0000	1.263.2.1
+++ c-common.h	13 Oct 2004 07:59:29 -0000
@@ -896,6 +896,22 @@ extern void c_stddef_cpp_builtins (void)
 extern void fe_file_change (const struct line_map *);
 extern void c_parse_error (const char *, enum cpp_ttype, tree);
 
+/* In c-gomp.c  */
+extern void c_gomp_parallel_pragma (cpp_reader *pfile);
+extern void c_gomp_for_pragma (cpp_reader *pfile);
+extern void c_gomp_parallel_for_pragma (cpp_reader *pfile);
+extern void c_gomp_parallel_sections_pragma (cpp_reader *pfile);
+extern void c_gomp_sections_pragma (cpp_reader *pfile);
+extern void c_gomp_section_pragma (cpp_reader *pfile);
+extern void c_gomp_single_pragma (cpp_reader *pfile);
+extern void c_gomp_master_pragma (cpp_reader *pfile);
+extern void c_gomp_critical_pragma (cpp_reader *pfile);
+extern void c_gomp_barrier_pragma (cpp_reader *pfile);
+extern void c_gomp_atomic_pragma (cpp_reader *pfile);
+extern void c_gomp_flush_pragma (cpp_reader *pfile);
+extern void c_gomp_ordered_pragma (cpp_reader *pfile);
+extern void c_gomp_threadprivate_pragma (cpp_reader *pfile);
+
 /* Objective-C / Objective-C++ entry points.  */
 
 /* The following ObjC/ObjC++ functions are called by the C and/or C++
Index: c-gomp.c
===================================================================
RCS file: c-gomp.c
diff -N c-gomp.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ c-gomp.c	13 Oct 2004 07:59:29 -0000
@@ -0,0 +1,297 @@
+/* Handle OpenMP #pragma.
+   Copyright (C) 2004 Free Software Foundation, Inc.
+   Contributed by Sebastian Pop <pop@cri.ensmp.fr>
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
+
+/* This file contains the functions that handle the parsing and
+   validation of OpenMP pragmas.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "errors.h"
+#include "ggc.h"
+#include "tree.h"
+#include "function.h"
+#include "cpplib.h"
+#include "c-pragma.h"
+#include "c-tree.h"
+#include "flags.h"
+#include "toplev.h"
+#include "ggc.h"
+#include "c-common.h"
+#include "output.h"
+#include "tm_p.h"
+#include "target.h"
+
+#define NYI gomp_nyi ()
+
+/* Inform that this is not yet implemented.  */
+
+static void 
+gomp_nyi (void)
+{
+  inform ("GOMP: Not implemented yet.");
+}
+
+/* Return true when fails to find an open parenthesis.  */
+
+static bool
+gomp_expect_open_parenthesis (void)
+{
+  tree name_t;
+  enum cpp_ttype token = c_lex (&name_t);
+  
+  if (token != CPP_OPEN_PAREN)
+    {
+      error ("Expected an open parenthesis.");
+      return true;
+    }
+  return false;
+}
+
+
+/* The following functions handle OpenMP clauses.  */
+
+/* Return true when it fails.  Does the job for a private clause in a
+   parallel directive.  */
+
+static bool
+c_gomp_parallel_private (void)
+{
+  tree name_t, name_decl;
+  enum cpp_ttype token;
+
+  if (gomp_expect_open_parenthesis ())
+    return true;
+
+  while (1)
+    {
+      token = c_lex (&name_t);
+      switch (token)
+	{
+	case CPP_CLOSE_PAREN:
+	  return false;
+
+	case CPP_COMMA:
+	  break;
+
+	case CPP_NAME:
+	  if (name_t == NULL_TREE 
+	      || (name_decl = lookup_name (name_t)) == NULL_TREE
+	      || TREE_CODE (name_decl) != VAR_DECL)
+	    {
+	      error ("Expected a variable.");
+	      return true;
+	    }
+	  /* TODO: mark that variable as private...  */
+	  break;
+
+	default:
+	  {
+	    error ("Expected a list of variables.");
+	    return true;
+	  }
+	}
+    }
+}
+
+
+/* The following functions handle OpenMP directives.  */
+
+/* Parse a "#pragma omp parallel [clause[ [, ]clause] ... ] new-line".  */
+
+void
+c_gomp_parallel_pragma (cpp_reader *pfile)
+{
+  tree name_t;
+
+  while (1)
+    {
+      enum cpp_ttype token = c_lex (&name_t);
+      
+      switch (token)
+	{
+	case CPP_NAME:
+	  {
+	    if (!strcmp (IDENTIFIER_POINTER (name_t), "for"))
+	      {
+		c_gomp_parallel_for_pragma (pfile);
+		return;
+	      }
+
+	    else if (!strcmp (IDENTIFIER_POINTER (name_t), "sections"))
+	      {
+		c_gomp_parallel_sections_pragma (pfile);
+		return;
+	      }
+
+	    else if (!strcmp (IDENTIFIER_POINTER (name_t), "if"))
+	      NYI;
+
+	    else if (!strcmp (IDENTIFIER_POINTER (name_t), "private"))
+	      {
+		if (c_gomp_parallel_private ())
+		  return;
+	      }
+	    else if (!strcmp (IDENTIFIER_POINTER (name_t), "firstprivate"))
+	      NYI;
+
+	    else if (!strcmp (IDENTIFIER_POINTER (name_t), "default"))
+	      NYI;
+
+	    else if (!strcmp (IDENTIFIER_POINTER (name_t), "shared"))
+	      NYI;
+
+	    else if (!strcmp (IDENTIFIER_POINTER (name_t), "copyin"))
+	      NYI;
+
+	    else if (!strcmp (IDENTIFIER_POINTER (name_t), "reduction"))
+	      NYI;
+
+	    else if (!strcmp (IDENTIFIER_POINTER (name_t), "num_threads"))
+	      NYI;
+
+	    else
+	      error ("Unrecognized clause in pragma omp parallel.");
+
+	    break;
+	  }
+	  
+	case CPP_EOF:
+	  /* New line.  */
+	  goto done;
+	  
+	default:
+	  error ("Unrecognized token in pragma omp parallel.");
+	  return;
+	}
+    }
+
+ done:;
+  return;
+}
+
+/* Parse a "#pragma omp for [clause[ [, ]clause] ... ] new-line".  */
+
+void
+c_gomp_for_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
+/* Parse a "#pragma omp parallel for [clause[ [, ]clause] ... ] new-line".
+   This is a combined directive.  */
+
+void
+c_gomp_parallel_for_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
+/* Parse a "#pragma omp parallel sections [clause[ [, ]clause] ... ] new-line".
+   This is a combined directive.  */
+
+void
+c_gomp_parallel_sections_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
+/* Parse a "#pragma omp sections [clause[ [, ]clause] ... ] new-line".  */
+
+void
+c_gomp_sections_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
+/* Parse a "#pragma omp section [clause[ [, ]clause] ... ] new-line".  */
+
+void
+c_gomp_section_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
+/* Parse a "#pragma omp single [clause[ [, ]clause] ... ] new-line".  */
+
+void
+c_gomp_single_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
+/* Parse a "#pragma omp master new-line".  */
+
+void
+c_gomp_master_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
+/* Parse a "#pragma omp critical [(name)] new-line".  */
+
+void
+c_gomp_critical_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
+/* Parse a "#pragma omp barrier new-line".  */
+
+void
+c_gomp_barrier_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
+/* Parse a "#pragma omp atomic new-line".  */
+
+void
+c_gomp_atomic_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
+/* Parse a "#pragma omp flush [(variable-list)] new-line".  */
+
+void
+c_gomp_flush_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
+/* Parse a "#pragma omp ordered new-line".  */
+
+void
+c_gomp_ordered_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
+/* Parse a "#pragma omp threadprivate (variable-list) new-line".  */
+
+void
+c_gomp_threadprivate_pragma (cpp_reader *pfile ATTRIBUTE_UNUSED)
+{
+  NYI;
+}
+
Index: c-pragma.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-pragma.c,v
retrieving revision 1.76.2.1
diff -d -u -p -r1.76.2.1 c-pragma.c
--- c-pragma.c	8 Oct 2004 18:48:01 -0000	1.76.2.1
+++ c-pragma.c	13 Oct 2004 07:59:29 -0000
@@ -655,6 +655,20 @@ init_pragma (void)
 
   c_register_pragma ("GCC", "pch_preprocess", c_common_pch_pragma);
 
+  /* Register pragmas defined in the OpenMP name space.  */
+  c_register_pragma ("omp", "parallel", c_gomp_parallel_pragma);
+  c_register_pragma ("omp", "for", c_gomp_for_pragma);
+  c_register_pragma ("omp", "sections", c_gomp_sections_pragma);
+  c_register_pragma ("omp", "section", c_gomp_section_pragma);
+  c_register_pragma ("omp", "single", c_gomp_single_pragma);
+  c_register_pragma ("omp", "master", c_gomp_master_pragma);
+  c_register_pragma ("omp", "critical", c_gomp_critical_pragma);
+  c_register_pragma ("omp", "barrier", c_gomp_barrier_pragma);
+  c_register_pragma ("omp", "atomic", c_gomp_atomic_pragma);
+  c_register_pragma ("omp", "flush", c_gomp_flush_pragma);
+  c_register_pragma ("omp", "ordered", c_gomp_ordered_pragma);
+  c_register_pragma ("omp", "threadprivate", c_gomp_threadprivate_pragma);
+
 #ifdef REGISTER_TARGET_PRAGMAS
   REGISTER_TARGET_PRAGMAS ();
 #endif
Index: cp/ChangeLog.gomp
===================================================================
RCS file: cp/ChangeLog.gomp
diff -N cp/ChangeLog.gomp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ cp/ChangeLog.gomp	13 Oct 2004 07:59:29 -0000
@@ -0,0 +1,4 @@
+2004-10-13  Sebastian Pop  <pop@cri.ensmp.fr>
+
+	* Make-lang.in (CXX_C_OBJS): Add dependence on c-gomp.o.
+	* ChangeLog.gomp: New file.
Index: cp/Make-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/Make-lang.in,v
retrieving revision 1.192.4.1
diff -d -u -p -r1.192.4.1 Make-lang.in
--- cp/Make-lang.in	8 Oct 2004 18:49:37 -0000	1.192.4.1
+++ cp/Make-lang.in	13 Oct 2004 07:59:29 -0000
@@ -74,7 +74,7 @@ g++-cross$(exeext): g++$(exeext)
 CXX_C_OBJS = attribs.o c-common.o c-format.o c-pragma.o c-semantics.o c-lex.o \
 	c-dump.o $(CXX_TARGET_OBJS) c-pretty-print.o c-opts.o c-pch.o \
 	c-incpath.o cppdefault.o c-ppoutput.o c-cppbuiltin.o prefix.o \
-	c-gimplify.o tree-inline.o
+	c-gimplify.o tree-inline.o c-gomp.o
 
 # Language-specific object files for C++ and Objective C++.
 CXX_AND_OBJCXX_OBJS = cp/call.o cp/decl.o cp/expr.o cp/pt.o cp/typeck2.o \


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]