[gomp4] expand acc_on_device earlier

Thomas Schwinge thomas@codesourcery.com
Mon Aug 3 12:03:00 GMT 2015


Hi!

On Sun, 2 Aug 2015 21:23:30 -0400, Nathan Sidwell <nathan@acm.org> wrote:
> I've committed this to gomp4 branch.  It expands the acc_on_device builtin 
> earlier in the new oacc_xform pass.  This will allow more optimization earlier on.

As far as I remember, the Fortran front end doesn't know about/doesn't
know how to use these GCC builtins, so it's not currently able to do such
compile-time folding of acc_on_device.

> 	libgomp/
> 	* openacc.h (acc_on_device): Take int and explain why.

> --- libgomp/openacc.h	(revision 226462)
> +++ libgomp/openacc.h	(working copy)
> @@ -78,7 +78,11 @@ void acc_wait_all (void) __GOACC_NOTHROW
>  void acc_wait_all_async (int) __GOACC_NOTHROW;
>  void acc_init (acc_device_t) __GOACC_NOTHROW;
>  void acc_shutdown (acc_device_t) __GOACC_NOTHROW;
> -int acc_on_device (acc_device_t) __GOACC_NOTHROW;
> +/* Library function declaration.  Although it should take an
> +   acc_device_t argument, that causes problems with matching the
> +   builtin, which takes an int (to avoid declaring the enumeration
> +   inside the compiler).  */
> +int acc_on_device (int) __GOACC_NOTHROW;
>  void *acc_malloc (size_t) __GOACC_NOTHROW;
>  void acc_free (void *) __GOACC_NOTHROW;
>  /* Some of these would be more correct with const qualifiers, but

Hmm, too bad this doesn't resolve the following C++ XFAIL (the test case
is fine for C), gcc/testsuite/c-c++-common/goacc/acc_on_device-2.c:

    /* Have to enable optimizations, as otherwise builtins won't be expanded.  */
    /* { dg-additional-options "-O -fdump-rtl-expand" } */
    
    /* Duplicate parts of libgomp/openacc.h, because we can't include it here.  */
    
    #if __cplusplus
    extern "C" {
    #endif
    
    typedef enum acc_device_t { acc_device_X = 123 } acc_device_t;
    extern int acc_on_device (int);
    
    #if __cplusplus
    }
    #endif
    
    int
    f (void)
    {
      const acc_device_t dev = acc_device_X;
      return acc_on_device (dev);
    }
    
    /* With -fopenacc, we're expecting the builtin to be expanded, so no calls.
       TODO: in C++, the use of enum acc_device_t for acc_on_device's parameter
       perturbs expansion as a builtin, which expects an int parameter.  It's fine
       when changing acc_device_t to plain int, but that's not necessarily what a
       user will be doing.
    
       { dg-final { scan-rtl-dump-times "\\\(call \[^\\n\]* acc_on_device" 0 "expand" { xfail c++ } } } */

Do you happen to have any insight into that?


Meanwhile, committed to gomp-4_0-branch in r226501:

commit 38d7f116bf18f4a4012fda532aa70d47f3f20652
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Mon Aug 3 11:59:15 2015 +0000

    Update acc_on_device test cases
    
    ... to match r226484 changes.
    
    	gcc/testsuite/
    	* c-c++-common/goacc/acc_on_device-2-off.c (acc_on_device): Change
    	formal parameter to int.
    	* c-c++-common/goacc/acc_on_device-2.c (acc_on_device): Likewise.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@226501 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/testsuite/ChangeLog.gomp                           |  4 ++++
 gcc/testsuite/c-c++-common/goacc/acc_on_device-2-off.c |  4 +++-
 gcc/testsuite/c-c++-common/goacc/acc_on_device-2.c     | 10 ++++++----
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git gcc/testsuite/ChangeLog.gomp gcc/testsuite/ChangeLog.gomp
index 33519ef..8dd9a4c 100644
--- gcc/testsuite/ChangeLog.gomp
+++ gcc/testsuite/ChangeLog.gomp
@@ -1,5 +1,9 @@
 2015-08-03  Thomas Schwinge  <thomas@codesourcery.com>
 
+	* c-c++-common/goacc/acc_on_device-2-off.c (acc_on_device): Change
+	formal parameter to int.
+	* c-c++-common/goacc/acc_on_device-2.c (acc_on_device): Likewise.
+
 	* c-c++-common/restrict-2.c: Update for new pass_lim.
 	* c-c++-common/restrict-4.c: Same.
 	* g++.dg/tree-ssa/pr33615.C: Same.
diff --git gcc/testsuite/c-c++-common/goacc/acc_on_device-2-off.c gcc/testsuite/c-c++-common/goacc/acc_on_device-2-off.c
index 59c72f7..71abe11 100644
--- gcc/testsuite/c-c++-common/goacc/acc_on_device-2-off.c
+++ gcc/testsuite/c-c++-common/goacc/acc_on_device-2-off.c
@@ -1,12 +1,14 @@
 /* Have to enable optimizations, as otherwise builtins won't be expanded.  */
 /* { dg-additional-options "-O -fdump-rtl-expand -fno-openacc" } */
 
+/* Duplicate parts of libgomp/openacc.h, because we can't include it here.  */
+
 #if __cplusplus
 extern "C" {
 #endif
 
 typedef enum acc_device_t { acc_device_X = 123 } acc_device_t;
-extern int acc_on_device (acc_device_t);
+extern int acc_on_device (int);
 
 #if __cplusplus
 }
diff --git gcc/testsuite/c-c++-common/goacc/acc_on_device-2.c gcc/testsuite/c-c++-common/goacc/acc_on_device-2.c
index ef622a8..243e562 100644
--- gcc/testsuite/c-c++-common/goacc/acc_on_device-2.c
+++ gcc/testsuite/c-c++-common/goacc/acc_on_device-2.c
@@ -1,12 +1,14 @@
 /* Have to enable optimizations, as otherwise builtins won't be expanded.  */
 /* { dg-additional-options "-O -fdump-rtl-expand" } */
 
+/* Duplicate parts of libgomp/openacc.h, because we can't include it here.  */
+
 #if __cplusplus
 extern "C" {
 #endif
 
 typedef enum acc_device_t { acc_device_X = 123 } acc_device_t;
-extern int acc_on_device (acc_device_t);
+extern int acc_on_device (int);
 
 #if __cplusplus
 }
@@ -20,9 +22,9 @@ f (void)
 }
 
 /* With -fopenacc, we're expecting the builtin to be expanded, so no calls.
-   TODO: in C++, even under extern "C", the use of enum for acc_device_t
+   TODO: in C++, the use of enum acc_device_t for acc_on_device's parameter
    perturbs expansion as a builtin, which expects an int parameter.  It's fine
-   when changing acc_device_t to plain int, but that's not what we're doing in
-   <openacc.h>.
+   when changing acc_device_t to plain int, but that's not necessarily what a
+   user will be doing.
 
    { dg-final { scan-rtl-dump-times "\\\(call \[^\\n\]* acc_on_device" 0 "expand" { xfail c++ } } } */


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


More information about the Gcc-patches mailing list