Fix switch conversion in offloading functions
2018-03-26 Tom de Vries <tom@codesourcery.com> PR tree-optimization/85063 * omp-general.c (offloading_function_p): New function. Factor out of ... * omp-offload.c (pass_omp_target_link::gate): ... here. * omp-general.h (offloading_function_p): Declare. * tree-switch-conversion.c (build_one_array): Mark CSWTCH.x variable with attribute omp declare target for offloading functions. * testsuite/libgomp.c/switch-conversion-2.c: New test. * testsuite/libgomp.c/switch-conversion.c: New test. * testsuite/libgomp.oacc-c-c++-common/switch-conversion-2.c: New test. * testsuite/libgomp.oacc-c-c++-common/switch-conversion.c: New test. From-SVN: r258852
This commit is contained in:
parent
c2f3aac454
commit
46dbeb4085
10 changed files with 168 additions and 3 deletions
|
@ -1,3 +1,13 @@
|
||||||
|
2018-03-26 Tom de Vries <tom@codesourcery.com>
|
||||||
|
|
||||||
|
PR tree-optimization/85063
|
||||||
|
* omp-general.c (offloading_function_p): New function. Factor out
|
||||||
|
of ...
|
||||||
|
* omp-offload.c (pass_omp_target_link::gate): ... here.
|
||||||
|
* omp-general.h (offloading_function_p): Declare.
|
||||||
|
* tree-switch-conversion.c (build_one_array): Mark CSWTCH.x variable
|
||||||
|
with attribute omp declare target for offloading functions.
|
||||||
|
|
||||||
2018-03-24 Richard Sandiford <richard.sandiford@linaro.org>
|
2018-03-24 Richard Sandiford <richard.sandiford@linaro.org>
|
||||||
|
|
||||||
PR tree-optimization/84005
|
PR tree-optimization/84005
|
||||||
|
|
|
@ -612,6 +612,16 @@ oacc_get_fn_attrib (tree fn)
|
||||||
return lookup_attribute (OACC_FN_ATTRIB, DECL_ATTRIBUTES (fn));
|
return lookup_attribute (OACC_FN_ATTRIB, DECL_ATTRIBUTES (fn));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return true if FN is an OpenMP or OpenACC offloading function. */
|
||||||
|
|
||||||
|
bool
|
||||||
|
offloading_function_p (tree fn)
|
||||||
|
{
|
||||||
|
tree attrs = DECL_ATTRIBUTES (fn);
|
||||||
|
return (lookup_attribute ("omp declare target", attrs)
|
||||||
|
|| lookup_attribute ("omp target entrypoint", attrs));
|
||||||
|
}
|
||||||
|
|
||||||
/* Extract an oacc execution dimension from FN. FN must be an
|
/* Extract an oacc execution dimension from FN. FN must be an
|
||||||
offloaded function or routine that has already had its execution
|
offloaded function or routine that has already had its execution
|
||||||
dimensions lowered to the target-specific values. */
|
dimensions lowered to the target-specific values. */
|
||||||
|
|
|
@ -85,6 +85,7 @@ extern void oacc_replace_fn_attrib (tree fn, tree dims);
|
||||||
extern void oacc_set_fn_attrib (tree fn, tree clauses, vec<tree> *args);
|
extern void oacc_set_fn_attrib (tree fn, tree clauses, vec<tree> *args);
|
||||||
extern tree oacc_build_routine_dims (tree clauses);
|
extern tree oacc_build_routine_dims (tree clauses);
|
||||||
extern tree oacc_get_fn_attrib (tree fn);
|
extern tree oacc_get_fn_attrib (tree fn);
|
||||||
|
extern bool offloading_function_p (tree fn);
|
||||||
extern int oacc_get_fn_dim_size (tree fn, int axis);
|
extern int oacc_get_fn_dim_size (tree fn, int axis);
|
||||||
extern int oacc_get_ifn_dim_arg (const gimple *stmt);
|
extern int oacc_get_ifn_dim_arg (const gimple *stmt);
|
||||||
|
|
||||||
|
|
|
@ -1967,9 +1967,7 @@ public:
|
||||||
virtual bool gate (function *fun)
|
virtual bool gate (function *fun)
|
||||||
{
|
{
|
||||||
#ifdef ACCEL_COMPILER
|
#ifdef ACCEL_COMPILER
|
||||||
tree attrs = DECL_ATTRIBUTES (fun->decl);
|
return offloading_function_p (fun->decl);
|
||||||
return lookup_attribute ("omp declare target", attrs)
|
|
||||||
|| lookup_attribute ("omp target entrypoint", attrs);
|
|
||||||
#else
|
#else
|
||||||
(void) fun;
|
(void) fun;
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -49,6 +49,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
#include "alloc-pool.h"
|
#include "alloc-pool.h"
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
#include "tree-into-ssa.h"
|
#include "tree-into-ssa.h"
|
||||||
|
#include "omp-general.h"
|
||||||
|
|
||||||
/* ??? For lang_hooks.types.type_for_mode, but is there a word_mode
|
/* ??? For lang_hooks.types.type_for_mode, but is there a word_mode
|
||||||
type in the GIMPLE type system that is language-independent? */
|
type in the GIMPLE type system that is language-independent? */
|
||||||
|
@ -1162,6 +1163,10 @@ build_one_array (gswitch *swtch, int num, tree arr_index_type,
|
||||||
TREE_CONSTANT (decl) = 1;
|
TREE_CONSTANT (decl) = 1;
|
||||||
TREE_READONLY (decl) = 1;
|
TREE_READONLY (decl) = 1;
|
||||||
DECL_IGNORED_P (decl) = 1;
|
DECL_IGNORED_P (decl) = 1;
|
||||||
|
if (offloading_function_p (cfun->decl))
|
||||||
|
DECL_ATTRIBUTES (decl)
|
||||||
|
= tree_cons (get_identifier ("omp declare target"), NULL_TREE,
|
||||||
|
NULL_TREE);
|
||||||
varpool_node::finalize_decl (decl);
|
varpool_node::finalize_decl (decl);
|
||||||
|
|
||||||
fetch = build4 (ARRAY_REF, value_type, decl, tidx, NULL_TREE,
|
fetch = build4 (ARRAY_REF, value_type, decl, tidx, NULL_TREE,
|
||||||
|
|
|
@ -1,3 +1,11 @@
|
||||||
|
2018-03-26 Tom de Vries <tom@codesourcery.com>
|
||||||
|
|
||||||
|
PR tree-optimization/85063
|
||||||
|
* testsuite/libgomp.c/switch-conversion-2.c: New test.
|
||||||
|
* testsuite/libgomp.c/switch-conversion.c: New test.
|
||||||
|
* testsuite/libgomp.oacc-c-c++-common/switch-conversion-2.c: New test.
|
||||||
|
* testsuite/libgomp.oacc-c-c++-common/switch-conversion.c: New test.
|
||||||
|
|
||||||
2018-03-25 Thomas Koenig <tkoenig@gcc.gnu.org>
|
2018-03-25 Thomas Koenig <tkoenig@gcc.gnu.org>
|
||||||
|
|
||||||
PR fortran/84381
|
PR fortran/84381
|
||||||
|
|
31
libgomp/testsuite/libgomp.c/switch-conversion-2.c
Normal file
31
libgomp/testsuite/libgomp.c/switch-conversion-2.c
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/* PR tree-optimization/85063 */
|
||||||
|
/* { dg-additional-options "-ftree-switch-conversion" } */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
int n[1];
|
||||||
|
|
||||||
|
n[0] = 3;
|
||||||
|
|
||||||
|
#pragma omp target
|
||||||
|
{
|
||||||
|
int m = n[0];
|
||||||
|
switch (m & 3)
|
||||||
|
{
|
||||||
|
case 0: m = 4; break;
|
||||||
|
case 1: m = 3; break;
|
||||||
|
case 2: m = 2; break;
|
||||||
|
default:
|
||||||
|
m = 1; break;
|
||||||
|
}
|
||||||
|
n[0] = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n[0] != 1)
|
||||||
|
abort ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
36
libgomp/testsuite/libgomp.c/switch-conversion.c
Normal file
36
libgomp/testsuite/libgomp.c/switch-conversion.c
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/* PR tree-optimization/85063 */
|
||||||
|
/* { dg-additional-options "-ftree-switch-conversion" } */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#pragma omp declare target
|
||||||
|
static int __attribute__((noinline)) foo (int n)
|
||||||
|
{
|
||||||
|
switch (n & 3)
|
||||||
|
{
|
||||||
|
case 0: return 4;
|
||||||
|
case 1: return 3;
|
||||||
|
case 2: return 2;
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#pragma omp end declare target
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
int n[1];
|
||||||
|
|
||||||
|
n[0] = 4;
|
||||||
|
|
||||||
|
#pragma omp target
|
||||||
|
{
|
||||||
|
n[0] = foo (n[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n[0] != 4)
|
||||||
|
abort ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/* PR tree-optimization/85063 */
|
||||||
|
/* { dg-additional-options "-ftree-switch-conversion" } */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
int n[1];
|
||||||
|
|
||||||
|
n[0] = 3;
|
||||||
|
|
||||||
|
#pragma acc parallel copy(n)
|
||||||
|
{
|
||||||
|
int m = n[0];
|
||||||
|
switch (m & 3)
|
||||||
|
{
|
||||||
|
case 0: m = 4; break;
|
||||||
|
case 1: m = 3; break;
|
||||||
|
case 2: m = 2; break;
|
||||||
|
default:
|
||||||
|
m = 1; break;
|
||||||
|
}
|
||||||
|
n[0] = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n[0] != 1)
|
||||||
|
abort ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* PR tree-optimization/85063 */
|
||||||
|
/* { dg-additional-options "-ftree-switch-conversion" } */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#pragma acc routine seq
|
||||||
|
static int __attribute__((noinline)) foo (int n)
|
||||||
|
{
|
||||||
|
switch (n & 3)
|
||||||
|
{
|
||||||
|
case 0: return 4;
|
||||||
|
case 1: return 3;
|
||||||
|
case 2: return 2;
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
int n[1];
|
||||||
|
|
||||||
|
n[0] = 4;
|
||||||
|
|
||||||
|
#pragma acc parallel copy(n)
|
||||||
|
{
|
||||||
|
n[0] = foo (n[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n[0] != 4)
|
||||||
|
abort ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue