[gomp4] Prohibit exceptions in OpenACC regions

Thomas Schwinge thomas@codesourcery.com
Wed May 13 21:15:00 GMT 2015


Hi!

On Tue, 14 Apr 2015 17:01:23 -0700, Cesar Philippidis <cesar_philippidis@mentor.com> wrote:
> This patch addresses the SjLj compile time failures, typically
> associated with routine calls in c++. My solution to this problem is to
> introduce a new "oacc function" attribute and prevent
> finish_eh_generation from inserting any EH code for functions marked
> with those attributes. I was thinking about creating a new target
> machine hook to selectively disable EH for targets which don't support
> it. However, I figured openacc acc shouldn't generate exceptions so I
> went with the attribute approach.
> 
> For those curious, I chose the name "oacc function" for the attribute
> because it gets attached to both parallel/kernels regions and acc routines.

Committed to gomp-4_0-branch in r223180:

commit 92c8a16805acc367b81f89ada760e136b5f7eab1
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed May 13 21:00:33 2015 +0000

    Prohibit exceptions in OpenACC regions
    
    	gcc/
    	* except.c (finish_eh_generation): Don't finalize exeception
    	handlers for functions containing the "oacc function" attribute.
    	* omp-low.c (create_omp_child_function): Add an "oacc function"
    	attribute to acc regions.
    	gcc/c-family/
    	* c-common.c (c_common_attribute_table): Add an "oacc function"
    	attribute.
    	gcc/c/
    	* c-parser.c (c_finish_oacc_routine): Add an "oacc function"
    	attribute to routines.
    	gcc/cp/
    	* parser.c (cp_parser_late_parsing_oacc_routine): Add an
    	"oacc function" attribute to routines.
    	gcc/fortran/
    	* f95-lang.c (gfc_attribute_table): Add and "oacc function"
    	attribute.
    	* gfortran.h (symbol_attribute): Add oacc_function bit.
    	* openmp.c (gfc_match_oacc_routine): Use it.
    	* trans-decl.c (add_attributes_to_decl): Lower it.
    	libgomp/
    	* testsuite/libgomp.oacc-c-c++-common/routine-1.c: Remove
    	-fno-exceptions.
    	* testsuite/libgomp.oacc-c-c++-common/routine-2.c: Likewise.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@223180 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.gomp                                      | 5 +++++
 gcc/c-family/ChangeLog.gomp                             | 5 +++++
 gcc/c-family/c-common.c                                 | 1 +
 gcc/c/ChangeLog.gomp                                    | 3 +++
 gcc/c/c-parser.c                                        | 4 +++-
 gcc/cp/ChangeLog.gomp                                   | 3 +++
 gcc/cp/parser.c                                         | 1 +
 gcc/except.c                                            | 4 ++++
 gcc/fortran/ChangeLog.gomp                              | 8 ++++++++
 gcc/fortran/f95-lang.c                                  | 6 ++++--
 gcc/fortran/gfortran.h                                  | 3 +++
 gcc/fortran/openmp.c                                    | 1 +
 gcc/fortran/trans-decl.c                                | 4 ++++
 gcc/omp-low.c                                           | 6 ++++++
 libgomp/ChangeLog.gomp                                  | 6 ++++++
 libgomp/testsuite/libgomp.oacc-c-c++-common/routine-1.c | 4 ++--
 libgomp/testsuite/libgomp.oacc-c-c++-common/routine-2.c | 4 ++--
 17 files changed, 61 insertions(+), 7 deletions(-)

diff --git gcc/ChangeLog.gomp gcc/ChangeLog.gomp
index 9e72962..a4683c3 100644
--- gcc/ChangeLog.gomp
+++ gcc/ChangeLog.gomp
@@ -1,5 +1,10 @@
 2015-05-13  Cesar Philippidis  <cesar@codesourcery.com>
 
+	* except.c (finish_eh_generation): Don't finalize exeception
+	handlers for functions containing the "oacc function" attribute.
+	* omp-low.c (create_omp_child_function): Add an "oacc function"
+	attribute to acc regions.
+
 	* langhooks-def.h (lhd_omp_mappable_type): Add bool argument.
 	* langhooks.c (lhd_omp_mappable_type): Likewise, for the
 	parameter.
diff --git gcc/c-family/ChangeLog.gomp gcc/c-family/ChangeLog.gomp
index 3e01b28..9f999cd 100644
--- gcc/c-family/ChangeLog.gomp
+++ gcc/c-family/ChangeLog.gomp
@@ -1,3 +1,8 @@
+2015-05-13  Cesar Philippidis  <cesar@codesourcery.com>
+
+	* c-common.c (c_common_attribute_table): Add an "oacc function"
+	attribute.
+
 2015-05-13  Thomas Schwinge  <thomas@codesourcery.com>
 	    Bernd Schmidt  <bernds@codesourcery.com>
 	    Cesar Philippidis  <cesar@codesourcery.com>
diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 5835517..c6e15fc 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -824,6 +824,7 @@ const struct attribute_spec c_common_attribute_table[] =
   { "bnd_instrument",         0, 0, true, false, false,
 			      handle_bnd_instrument, false },
   { "oacc declare",           0, -1, true,  false, false, NULL, false },
+  { "oacc function",          0, 0, true,  false, false, NULL, false },
   { NULL,                     0, 0, false, false, false, NULL, false }
 };
 
diff --git gcc/c/ChangeLog.gomp gcc/c/ChangeLog.gomp
index 08c8ed0..c99f29d 100644
--- gcc/c/ChangeLog.gomp
+++ gcc/c/ChangeLog.gomp
@@ -1,5 +1,8 @@
 2015-05-13  Cesar Philippidis  <cesar@codesourcery.com>
 
+	* c-parser.c (c_finish_oacc_routine): Add an "oacc function"
+	attribute to routines.
+
 	* c-decl.c (c_decl_attributes): Update call to omp_mappable_type.
 	* c-typeck.c (c_finish_omp_clauses): Likewise.
 
diff --git gcc/c/c-parser.c gcc/c/c-parser.c
index 999f3d4..74adeb8 100644
--- gcc/c/c-parser.c
+++ gcc/c/c-parser.c
@@ -13032,7 +13032,9 @@ c_finish_oacc_routine (c_parser *parser, tree fndecl, tree clauses,
   clauses = build_tree_list (get_identifier ("omp declare target"),
 			     clauses);
   TREE_CHAIN (clauses) = DECL_ATTRIBUTES (fndecl);
-  DECL_ATTRIBUTES (fndecl) = clauses;
+  DECL_ATTRIBUTES (fndecl)
+    = tree_cons (get_identifier ("oacc function"),
+		 NULL_TREE, clauses);
 }
 
 /* OpenACC 2.0:
diff --git gcc/cp/ChangeLog.gomp gcc/cp/ChangeLog.gomp
index 529206a..a3ca81f 100644
--- gcc/cp/ChangeLog.gomp
+++ gcc/cp/ChangeLog.gomp
@@ -1,5 +1,8 @@
 2015-05-13  Cesar Philippidis  <cesar@codesourcery.com>
 
+	* parser.c (cp_parser_late_parsing_oacc_routine): Add an
+	"oacc function" attribute to routines.
+
 	* cp-tree.h (cp_omp_mappable_type): Add bool parameter.
 	* decl2.c (cp_check_const_attributes): Likewise. Use it.
 	(cp_omp_mappable_type): Update call to cp_omp_mappable_type.
diff --git gcc/cp/parser.c gcc/cp/parser.c
index ee097e2..e418ca2 100644
--- gcc/cp/parser.c
+++ gcc/cp/parser.c
@@ -33249,6 +33249,7 @@ cp_parser_late_parsing_oacc_routine (cp_parser *parser, tree attrs)
     cl = tree_cons (NULL_TREE, cl, NULL_TREE);
 
   attrs = build_tree_list (get_identifier ("omp declare target"), cl);
+  attrs = tree_cons (get_identifier ("oacc function"), NULL_TREE, attrs);
   data->fndecl_seen = true;
   return attrs;
 }
diff --git gcc/except.c gcc/except.c
index d609592..b638f17 100644
--- gcc/except.c
+++ gcc/except.c
@@ -1503,6 +1503,10 @@ finish_eh_generation (void)
 {
   basic_block bb;
 
+  if (lookup_attribute ("oacc function",
+			DECL_ATTRIBUTES (current_function_decl)))
+    return;
+
   /* Construct the landing pads.  */
   if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
     sjlj_build_landing_pads ();
diff --git gcc/fortran/ChangeLog.gomp gcc/fortran/ChangeLog.gomp
index cdfb1f0..8a2cd7b 100644
--- gcc/fortran/ChangeLog.gomp
+++ gcc/fortran/ChangeLog.gomp
@@ -1,3 +1,11 @@
+2015-05-13  Cesar Philippidis  <cesar@codesourcery.com>
+
+	* f95-lang.c (gfc_attribute_table): Add and "oacc function"
+	attribute.
+	* gfortran.h (symbol_attribute): Add oacc_function bit.
+	* openmp.c (gfc_match_oacc_routine): Use it.
+	* trans-decl.c (add_attributes_to_decl): Lower it.
+
 2015-05-13  Thomas Schwinge  <thomas@codesourcery.com>
 	    Bernd Schmidt  <bernds@codesourcery.com>
 	    Cesar Philippidis  <cesar@codesourcery.com>
diff --git gcc/fortran/f95-lang.c gcc/fortran/f95-lang.c
index 84be2a3..5003581 100644
--- gcc/fortran/f95-lang.c
+++ gcc/fortran/f95-lang.c
@@ -104,8 +104,8 @@ static alias_set_type gfc_get_alias_set (tree);
 static void gfc_init_ts (void);
 static tree gfc_builtin_function (tree);
 
-/* Handle an "omp declare target" attribute; arguments as in
-   struct attribute_spec.handler.  */
+/* Handle an "omp declare target" or "oacc function" attribute;
+   arguments as in struct attribute_spec.handler.  */
 static tree
 gfc_handle_omp_declare_target_attribute (tree *, tree, tree, int, bool *)
 {
@@ -119,6 +119,8 @@ static const struct attribute_spec gfc_attribute_table[] =
        affects_type_identity } */
   { "omp declare target", 0, 0, true,  false, false,
     gfc_handle_omp_declare_target_attribute, false },
+  { "oacc function", 0, 0, true,  false, false,
+    gfc_handle_omp_declare_target_attribute, false },
   { NULL,		  0, 0, false, false, false, NULL, false }
 };
 
diff --git gcc/fortran/gfortran.h gcc/fortran/gfortran.h
index 58689c3..e73c269 100644
--- gcc/fortran/gfortran.h
+++ gcc/fortran/gfortran.h
@@ -861,6 +861,9 @@ typedef struct
   /* Mentioned in OMP DECLARE TARGET.  */
   unsigned omp_declare_target:1;
 
+  /* This is an OpenACC acclerator function.  */
+  unsigned oacc_function:1;
+
   /* Attributes set by compiler extensions (!GCC$ ATTRIBUTES).  */
   unsigned ext_attr:EXT_ATTR_NUM;
 
diff --git gcc/fortran/openmp.c gcc/fortran/openmp.c
index 0aa7d51..fc16d8c 100644
--- gcc/fortran/openmp.c
+++ gcc/fortran/openmp.c
@@ -1776,6 +1776,7 @@ gfc_match_oacc_routine (void)
 				       gfc_current_ns->proc_name->name,
 				       &old_loc))
 	goto cleanup;
+      gfc_current_ns->proc_name->attr.oacc_function = 1;
     }
   else
     gcc_unreachable ();
diff --git gcc/fortran/trans-decl.c gcc/fortran/trans-decl.c
index 3dbf128..6cdc472 100644
--- gcc/fortran/trans-decl.c
+++ gcc/fortran/trans-decl.c
@@ -1309,6 +1309,10 @@ add_attributes_to_decl (symbol_attribute sym_attr, tree list)
     list = tree_cons (get_identifier ("omp declare target"),
 		      NULL_TREE, list);
 
+  if (sym_attr.oacc_function)
+    list = tree_cons (get_identifier ("oacc function"),
+		      NULL_TREE, list);
+
   return list;
 }
 
diff --git gcc/omp-low.c gcc/omp-low.c
index a71f554..c4f8033 100644
--- gcc/omp-low.c
+++ gcc/omp-low.c
@@ -2559,6 +2559,12 @@ create_omp_child_function (omp_context *ctx, bool task_copy)
       = tree_cons (get_identifier ("omp target entrypoint"),
                    NULL_TREE, DECL_ATTRIBUTES (decl));
 
+  if (is_gimple_omp_oacc (ctx->stmt)
+      && !lookup_attribute ("omp function", DECL_ATTRIBUTES (decl)))
+    DECL_ATTRIBUTES (decl)
+      = tree_cons (get_identifier ("oacc function"), NULL_TREE,
+		   DECL_ATTRIBUTES (decl));
+
   t = build_decl (DECL_SOURCE_LOCATION (decl),
 		  RESULT_DECL, NULL_TREE, void_type_node);
   DECL_ARTIFICIAL (t) = 1;
diff --git libgomp/ChangeLog.gomp libgomp/ChangeLog.gomp
index fb2bbc3..1d7d9da 100644
--- libgomp/ChangeLog.gomp
+++ libgomp/ChangeLog.gomp
@@ -1,3 +1,9 @@
+2015-05-13  Cesar Philippidis  <cesar@codesourcery.com>
+
+	* testsuite/libgomp.oacc-c-c++-common/routine-1.c: Remove
+	-fno-exceptions.
+	* testsuite/libgomp.oacc-c-c++-common/routine-2.c: Likewise.
+
 2015-05-13  Thomas Schwinge  <thomas@codesourcery.com>
 	    Bernd Schmidt  <bernds@codesourcery.com>
 	    Cesar Philippidis  <cesar@codesourcery.com>
diff --git libgomp/testsuite/libgomp.oacc-c-c++-common/routine-1.c libgomp/testsuite/libgomp.oacc-c-c++-common/routine-1.c
index a27d076..144f892 100644
--- libgomp/testsuite/libgomp.oacc-c-c++-common/routine-1.c
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/routine-1.c
@@ -1,7 +1,7 @@
-/* FIXME: remove -fno-var-tracking and -fno-exceptions from dg-options.  */
+/* FIXME: remove -fno-var-tracking from dg-options.  */
 
 /* { dg-do run } */
-/* { dg-options "-fno-inline -fno-var-tracking -fno-exceptions" } */
+/* { dg-options "-fno-inline -fno-var-tracking" } */
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git libgomp/testsuite/libgomp.oacc-c-c++-common/routine-2.c libgomp/testsuite/libgomp.oacc-c-c++-common/routine-2.c
index 8ec4d8b..f08aeda 100644
--- libgomp/testsuite/libgomp.oacc-c-c++-common/routine-2.c
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/routine-2.c
@@ -1,7 +1,7 @@
-/* FIXME: remove -fno-var-tracking and -fno-exceptions from dg-options.  */
+/* FIXME: remove -fno-var-tracking from dg-options.  */
 
 /* { dg-do run } */
-/* { dg-options "-fno-inline -fno-var-tracking -fno-exceptions" } */
+/* { dg-options "-fno-inline -fno-var-tracking" } */
 
 #include <stdio.h>
 #include <stdlib.h>


Grüße,
 Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20150513/05658519/attachment.sig>


More information about the Gcc-patches mailing list