This patch implements propagation of PROP_gimple_lomp_dev during inlining to
allow using it to decide whether pass_omp_device_lower needs to run.

We need to clear this property in expand_omp_simd when the _simt_ clause is
present even if we are not doing any SIMT transforms, because we need to
cleanup the call to GOMP_USE_SIMT () guarding the entry to the cloned loop.

        * omp-expand.c (expand_omp_simd): Clear PROP_gimple_lomp_dev regardless 
        of safelen status.
        * omp-offload.c (pass_omp_device_lower::gate): Use PROP_gimple_lomp_dev.
        * passes.c (dump_properties): Handle PROP_gimple_lomp_dev.
        * tree-inline.c (expand_call_inline): Propagate PROP_gimple_lomp_dev.

---
 gcc/omp-expand.c  | 11 +++++++----
 gcc/omp-offload.c |  9 ++-------
 gcc/passes.c      |  2 ++
 gcc/tree-inline.c |  9 ++++++---
 4 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c
index 6a29df6..1312735 100644
--- a/gcc/omp-expand.c
+++ b/gcc/omp-expand.c
@@ -4590,13 +4590,16 @@ expand_omp_simd (struct omp_region *region, struct 
omp_for_data *fd)
     }
   tree step = fd->loop.step;
 
-  bool is_simt = (safelen_int > 1
-                 && omp_find_clause (gimple_omp_for_clauses (fd->for_stmt),
-                                     OMP_CLAUSE__SIMT_));
-  tree simt_lane = NULL_TREE, simt_maxlane = NULL_TREE;
+  bool is_simt = omp_find_clause (gimple_omp_for_clauses (fd->for_stmt),
+                                 OMP_CLAUSE__SIMT_);
   if (is_simt)
     {
       cfun->curr_properties &= ~PROP_gimple_lomp_dev;
+      is_simt = safelen_int > 1;
+    }
+  tree simt_lane = NULL_TREE, simt_maxlane = NULL_TREE;
+  if (is_simt)
+    {
       simt_lane = create_tmp_var (unsigned_type_node);
       gimple *g = gimple_build_call_internal (IFN_GOMP_SIMT_LANE, 0);
       gimple_call_set_lhs (g, simt_lane);
diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c
index 8c2c6eb..acecb63 100644
--- a/gcc/omp-offload.c
+++ b/gcc/omp-offload.c
@@ -1613,14 +1613,9 @@ public:
   {}
 
   /* opt_pass methods: */
-  virtual bool gate (function *ARG_UNUSED (fun))
+  virtual bool gate (function *fun)
     {
-      /* FIXME: this should use PROP_gimple_lomp_dev.  */
-#ifdef ACCEL_COMPILER
-      return true;
-#else
-      return ENABLE_OFFLOADING && (flag_openmp || in_lto_p);
-#endif
+      return !(fun->curr_properties & PROP_gimple_lomp_dev);
     }
   virtual unsigned int execute (function *)
     {
diff --git a/gcc/passes.c b/gcc/passes.c
index d11b712..db006f9 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -2900,6 +2900,8 @@ dump_properties (FILE *dump, unsigned int props)
     fprintf (dump, "PROP_rtl\n");
   if (props & PROP_gimple_lomp)
     fprintf (dump, "PROP_gimple_lomp\n");
+  if (props & PROP_gimple_lomp_dev)
+    fprintf (dump, "PROP_gimple_lomp_dev\n");
   if (props & PROP_gimple_lcx)
     fprintf (dump, "PROP_gimple_lcx\n");
   if (props & PROP_gimple_lvec)
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index 0de0b89..9b49e0d 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -4413,6 +4413,7 @@ expand_call_inline (basic_block bb, gimple *stmt, 
copy_body_data *id)
   bool purge_dead_abnormal_edges;
   gcall *call_stmt;
   unsigned int i;
+  unsigned int prop_mask, src_properties;
 
   /* The gimplifier uses input_location in too many places, such as
      internal_get_tmp_var ().  */
@@ -4617,11 +4618,13 @@ expand_call_inline (basic_block bb, gimple *stmt, 
copy_body_data *id)
   id->call_stmt = stmt;
 
   /* If the src function contains an IFN_VA_ARG, then so will the dst
-     function after inlining.  */
-  if ((id->src_cfun->curr_properties & PROP_gimple_lva) == 0)
+     function after inlining.  Likewise for IFN_GOMP_USE_SIMT.  */
+  prop_mask = PROP_gimple_lva | PROP_gimple_lomp_dev;
+  src_properties = id->src_cfun->curr_properties & prop_mask;
+  if (src_properties != prop_mask)
     {
       struct function *dst_cfun = DECL_STRUCT_FUNCTION (id->dst_fn);
-      dst_cfun->curr_properties &= ~PROP_gimple_lva;
+      dst_cfun->curr_properties &= src_properties | ~prop_mask;
     }
 
   gcc_assert (!id->src_cfun->after_inlining);
-- 
1.8.3.1

Reply via email to