omp-expand.c (adjust_context_scope): New function.
authorKevin Buettner <kevinb@redhat.com>
Mon, 2 Oct 2017 00:27:21 +0000 (00:27 +0000)
committerKevin Buettner <kevinb@gcc.gnu.org>
Mon, 2 Oct 2017 00:27:21 +0000 (00:27 +0000)
* omp-expand.c (adjust_context_scope): New function.
(expand_parallel_call): Call adjust_context_scope.

From-SVN: r253335

gcc/ChangeLog
gcc/omp-expand.c

index 93dcaed..ede5fb0 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-01  Kevin Buettner  <kevinb@redhat.com>
+
+       * omp-expand.c (adjust_context_scope): New function.
+       (expand_parallel_call): Call adjust_context_scope.
+
 2017-10-01  Jeff Law  <law@redhat.com>
 
        * tree-ssa-dom.c (optimize_stmt): Make this a method within the
index 4bdcf19..0f45563 100644 (file)
@@ -499,6 +499,42 @@ parallel_needs_hsa_kernel_p (struct omp_region *region)
   return false;
 }
 
+/* Change DECL_CONTEXT of CHILD_FNDECL to that of the parent function.
+   Add CHILD_FNDECL to decl chain of the supercontext of the block
+   ENTRY_BLOCK - this is the block which originally contained the
+   code from which CHILD_FNDECL was created.
+   
+   Together, these actions ensure that the debug info for the outlined
+   function will be emitted with the correct lexical scope.  */
+
+static void
+adjust_context_and_scope (tree entry_block, tree child_fndecl)
+{
+  if (entry_block != NULL_TREE && TREE_CODE (entry_block) == BLOCK)
+    {
+      tree b = BLOCK_SUPERCONTEXT (entry_block);
+
+      if (TREE_CODE (b) == BLOCK)
+        {
+         tree parent_fndecl;
+
+         /* Follow supercontext chain until the parent fndecl
+            is found.  */
+         for (parent_fndecl = BLOCK_SUPERCONTEXT (b);
+              TREE_CODE (parent_fndecl) == BLOCK;
+              parent_fndecl = BLOCK_SUPERCONTEXT (parent_fndecl))
+           ;
+
+         gcc_assert (TREE_CODE (parent_fndecl) == FUNCTION_DECL);
+
+         DECL_CONTEXT (child_fndecl) = parent_fndecl;
+
+         DECL_CHAIN (child_fndecl) = BLOCK_VARS (b);
+         BLOCK_VARS (b) = child_fndecl;
+       }
+    }
+}
+
 /* Build the function calls to GOMP_parallel_start etc to actually
    generate the parallel operation.  REGION is the parallel region
    being expanded.  BB is the block where to insert the code.  WS_ARGS
@@ -668,6 +704,8 @@ expand_parallel_call (struct omp_region *region, basic_block bb,
   tree child_fndecl = gimple_omp_parallel_child_fn (entry_stmt);
   t2 = build_fold_addr_expr (child_fndecl);
 
+  adjust_context_and_scope (gimple_block (entry_stmt), child_fndecl);
+
   vec_alloc (args, 4 + vec_safe_length (ws_args));
   args->quick_push (t2);
   args->quick_push (t1);