]> gcc.gnu.org Git - gcc.git/blobdiff - gcc/tree-nested.c
tree-core.h: Include symtab.h.
[gcc.git] / gcc / tree-nested.c
index 9b4493bade0152fc971968fe6507083ed0249f14..6b750208dfdb9ceef5183a80471535ee43226033 100644 (file)
@@ -1,5 +1,5 @@
 /* Nested function decomposition for GIMPLE.
-   Copyright (C) 2004-2013 Free Software Foundation, Inc.
+   Copyright (C) 2004-2015 Free Software Foundation, Inc.
 
    This file is part of GCC.
 
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
+#include "backend.h"
 #include "tree.h"
+#include "gimple.h"
+#include "rtl.h"
+#include "alias.h"
+#include "fold-const.h"
+#include "stringpool.h"
+#include "stor-layout.h"
 #include "tm_p.h"
-#include "function.h"
 #include "tree-dump.h"
 #include "tree-inline.h"
-#include "gimple.h"
+#include "internal-fn.h"
 #include "gimplify.h"
 #include "gimple-iterator.h"
 #include "gimple-walk.h"
 #include "tree-iterator.h"
-#include "bitmap.h"
 #include "cgraph.h"
 #include "tree-cfg.h"
+#include "flags.h"
+#include "insn-config.h"
+#include "expmed.h"
+#include "dojump.h"
+#include "explow.h"
+#include "calls.h"
+#include "emit-rtl.h"
+#include "varasm.h"
+#include "stmt.h"
 #include "expr.h"      /* FIXME: For STACK_SAVEAREA_MODE and SAVE_NONLOCAL.  */
 #include "langhooks.h"
-#include "pointer-set.h"
 #include "gimple-low.h"
+#include "gomp-constants.h"
 
 
 /* The object of this pass is to lower the representation of a set of nested
@@ -86,9 +99,9 @@ struct nesting_info
   struct nesting_info *inner;
   struct nesting_info *next;
 
-  struct pointer_map_t *field_map;
-  struct pointer_map_t *var_map;
-  struct pointer_set_t *mem_refs;
+  hash_map<tree, tree> *field_map;
+  hash_map<tree, tree> *var_map;
+  hash_set<tree *> *mem_refs;
   bitmap suppress_expansion;
 
   tree context;
@@ -279,15 +292,13 @@ static tree
 lookup_field_for_decl (struct nesting_info *info, tree decl,
                       enum insert_option insert)
 {
-  void **slot;
-
   if (insert == NO_INSERT)
     {
-      slot = pointer_map_contains (info->field_map, decl);
-      return slot ? (tree) *slot : NULL_TREE;
+      tree *slot = info->field_map->get (decl);
+      return slot ? *slot : NULL_TREE;
     }
 
-  slot = pointer_map_insert (info->field_map, decl);
+  tree *slot = &info->field_map->get_or_insert (decl);
   if (!*slot)
     {
       tree field = make_node (FIELD_DECL);
@@ -317,7 +328,7 @@ lookup_field_for_decl (struct nesting_info *info, tree decl,
        info->any_parm_remapped = true;
     }
 
-  return (tree) *slot;
+  return *slot;
 }
 
 /* Build or return the variable that holds the static chain within
@@ -404,7 +415,7 @@ get_chain_field (struct nesting_info *info)
 
 static tree
 init_tmp_var_with_call (struct nesting_info *info, gimple_stmt_iterator *gsi,
-                       gimple call)
+                       gcall *call)
 {
   tree t;
 
@@ -514,15 +525,13 @@ static tree
 lookup_tramp_for_decl (struct nesting_info *info, tree decl,
                       enum insert_option insert)
 {
-  void **slot;
-
   if (insert == NO_INSERT)
     {
-      slot = pointer_map_contains (info->var_map, decl);
-      return slot ? (tree) *slot : NULL_TREE;
+      tree *slot = info->var_map->get (decl);
+      return slot ? *slot : NULL_TREE;
     }
 
-  slot = pointer_map_insert (info->var_map, decl);
+  tree *slot = &info->var_map->get_or_insert (decl);
   if (!*slot)
     {
       tree field = make_node (FIELD_DECL);
@@ -536,7 +545,7 @@ lookup_tramp_for_decl (struct nesting_info *info, tree decl,
       info->any_tramp_created = true;
     }
 
-  return (tree) *slot;
+  return *slot;
 }
 
 /* Build or return the field within the non-local frame state that holds
@@ -611,7 +620,7 @@ walk_function (walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
 /* Invoke CALLBACK on a GIMPLE_OMP_FOR's init, cond, incr and pre-body.  */
 
 static void
-walk_gimple_omp_for (gimple for_stmt,
+walk_gimple_omp_for (gomp_for *for_stmt,
                     walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
                     struct nesting_info *info)
 {
@@ -699,7 +708,7 @@ walk_all_functions (walk_stmt_fn callback_stmt, walk_tree_fn callback_op,
 static bool
 check_for_nested_with_variably_modified (tree fndecl, tree orig_fndecl)
 {
-  struct cgraph_node *cgn = cgraph_get_node (fndecl);
+  struct cgraph_node *cgn = cgraph_node::get (fndecl);
   tree arg;
 
   for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
@@ -723,9 +732,9 @@ static struct nesting_info *
 create_nesting_tree (struct cgraph_node *cgn)
 {
   struct nesting_info *info = XCNEW (struct nesting_info);
-  info->field_map = pointer_map_create ();
-  info->var_map = pointer_map_create ();
-  info->mem_refs = pointer_set_create ();
+  info->field_map = new hash_map<tree, tree>;
+  info->var_map = new hash_map<tree, tree>;
+  info->mem_refs = new hash_set<tree *>;
   info->suppress_expansion = BITMAP_ALLOC (&nesting_info_bitmap_obstack);
   info->context = cgn->decl;
 
@@ -819,7 +828,7 @@ static void note_nonlocal_vla_type (struct nesting_info *info, tree type);
 /* A subroutine of convert_nonlocal_reference_op.  Create a local variable
    in the nested function with DECL_VALUE_EXPR set to reference the true
    variable in the parent function.  This is used both for debug info
-   and in OpenMP lowering.  */
+   and in OMP lowering.  */
 
 static tree
 get_nonlocal_debug_decl (struct nesting_info *info, tree decl)
@@ -827,12 +836,11 @@ get_nonlocal_debug_decl (struct nesting_info *info, tree decl)
   tree target_context;
   struct nesting_info *i;
   tree x, field, new_decl;
-  void **slot;
 
-  slot = pointer_map_insert (info->var_map, decl);
+  tree *slot = &info->var_map->get_or_insert (decl);
 
   if (*slot)
-    return (tree) *slot;
+    return *slot;
 
   target_context = decl_function_context (decl);
 
@@ -1053,7 +1061,9 @@ static bool
 convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
 {
   struct nesting_info *const info = (struct nesting_info *) wi->info;
-  bool need_chain = false, need_stmts = false;
+  /* If not optimizing, we will force the creation of the CHAIN object in
+     convert_all_function_calls, so we need to take it into account here.  */
+  bool need_chain = info->outer && !optimize, need_stmts = false;
   tree clause, decl;
   int dummy;
   bitmap new_suppress;
@@ -1075,6 +1085,15 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
            need_stmts = true;
          goto do_decl_clause;
 
+       case OMP_CLAUSE_LINEAR:
+         if (OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause))
+           need_stmts = true;
+         wi->val_only = true;
+         wi->is_lhs = false;
+         convert_nonlocal_reference_op (&OMP_CLAUSE_LINEAR_STEP (clause),
+                                        &dummy, wi);
+         goto do_decl_clause;
+
        case OMP_CLAUSE_PRIVATE:
        case OMP_CLAUSE_FIRSTPRIVATE:
        case OMP_CLAUSE_COPYPRIVATE:
@@ -1100,10 +1119,65 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
        case OMP_CLAUSE_FINAL:
        case OMP_CLAUSE_IF:
        case OMP_CLAUSE_NUM_THREADS:
+       case OMP_CLAUSE_DEPEND:
+       case OMP_CLAUSE_DEVICE:
+       case OMP_CLAUSE_NUM_TEAMS:
+       case OMP_CLAUSE_THREAD_LIMIT:
+       case OMP_CLAUSE_SAFELEN:
+       case OMP_CLAUSE__CILK_FOR_COUNT_:
          wi->val_only = true;
          wi->is_lhs = false;
          convert_nonlocal_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
-                                        &dummy, wi);
+                                        &dummy, wi);
+         break;
+
+       case OMP_CLAUSE_DIST_SCHEDULE:
+         if (OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (clause) != NULL)
+           {
+             wi->val_only = true;
+             wi->is_lhs = false;
+             convert_nonlocal_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
+                                            &dummy, wi);
+           }
+         break;
+
+       case OMP_CLAUSE_MAP:
+       case OMP_CLAUSE_TO:
+       case OMP_CLAUSE_FROM:
+         if (OMP_CLAUSE_SIZE (clause))
+           {
+             wi->val_only = true;
+             wi->is_lhs = false;
+             convert_nonlocal_reference_op (&OMP_CLAUSE_SIZE (clause),
+                                            &dummy, wi);
+           }
+         if (DECL_P (OMP_CLAUSE_DECL (clause)))
+           goto do_decl_clause;
+         wi->val_only = true;
+         wi->is_lhs = false;
+         walk_tree (&OMP_CLAUSE_DECL (clause), convert_nonlocal_reference_op,
+                    wi, NULL);
+         break;
+
+       case OMP_CLAUSE_ALIGNED:
+         if (OMP_CLAUSE_ALIGNED_ALIGNMENT (clause))
+           {
+             wi->val_only = true;
+             wi->is_lhs = false;
+             convert_nonlocal_reference_op
+               (&OMP_CLAUSE_ALIGNED_ALIGNMENT (clause), &dummy, wi);
+           }
+         /* Like do_decl_clause, but don't add any suppression.  */
+         decl = OMP_CLAUSE_DECL (clause);
+         if (TREE_CODE (decl) == VAR_DECL
+             && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
+           break;
+         if (decl_function_context (decl) != info->context)
+           {
+             OMP_CLAUSE_DECL (clause) = get_nonlocal_debug_decl (info, decl);
+             if (OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_PRIVATE)
+               need_chain = true;
+           }
          break;
 
        case OMP_CLAUSE_NOWAIT:
@@ -1113,6 +1187,7 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
        case OMP_CLAUSE_COLLAPSE:
        case OMP_CLAUSE_UNTIED:
        case OMP_CLAUSE_MERGEABLE:
+       case OMP_CLAUSE_PROC_BIND:
          break;
 
        default:
@@ -1150,6 +1225,12 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
                     &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause));
          break;
 
+       case OMP_CLAUSE_LINEAR:
+         walk_body (convert_nonlocal_reference_stmt,
+                    convert_nonlocal_reference_op, info,
+                    &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause));
+         break;
+
        default:
          break;
        }
@@ -1273,7 +1354,8 @@ convert_nonlocal_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
     case GIMPLE_OMP_FOR:
       save_suppress = info->suppress_expansion;
       convert_nonlocal_omp_clauses (gimple_omp_for_clauses_ptr (stmt), wi);
-      walk_gimple_omp_for (stmt, convert_nonlocal_reference_stmt,
+      walk_gimple_omp_for (as_a <gomp_for *> (stmt),
+                          convert_nonlocal_reference_stmt,
                           convert_nonlocal_reference_op, info);
       walk_body (convert_nonlocal_reference_stmt,
                 convert_nonlocal_reference_op, info, gimple_omp_body_ptr (stmt));
@@ -1297,10 +1379,42 @@ convert_nonlocal_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
       break;
 
     case GIMPLE_OMP_TARGET:
+      if (!is_gimple_omp_offloaded (stmt))
+       {
+         save_suppress = info->suppress_expansion;
+         convert_nonlocal_omp_clauses (gimple_omp_target_clauses_ptr (stmt),
+                                       wi);
+         info->suppress_expansion = save_suppress;
+         walk_body (convert_nonlocal_reference_stmt,
+                    convert_nonlocal_reference_op, info,
+                    gimple_omp_body_ptr (stmt));
+         break;
+       }
       save_suppress = info->suppress_expansion;
-      convert_nonlocal_omp_clauses (gimple_omp_target_clauses_ptr (stmt), wi);
+      if (convert_nonlocal_omp_clauses (gimple_omp_target_clauses_ptr (stmt),
+                                       wi))
+       {
+         tree c, decl;
+         decl = get_chain_decl (info);
+         c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
+         OMP_CLAUSE_DECL (c) = decl;
+         OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TO);
+         OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
+         OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
+         gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt), c);
+       }
+
+      save_local_var_chain = info->new_local_var_chain;
+      info->new_local_var_chain = NULL;
+
       walk_body (convert_nonlocal_reference_stmt, convert_nonlocal_reference_op,
                 info, gimple_omp_body_ptr (stmt));
+
+      if (info->new_local_var_chain)
+       declare_vars (info->new_local_var_chain,
+                     gimple_seq_first_stmt (gimple_omp_body (stmt)),
+                     false);
+      info->new_local_var_chain = save_local_var_chain;
       info->suppress_expansion = save_suppress;
       break;
 
@@ -1321,12 +1435,33 @@ convert_nonlocal_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
       break;
 
     case GIMPLE_BIND:
-      if (!optimize && gimple_bind_block (stmt))
-       note_nonlocal_block_vlas (info, gimple_bind_block (stmt));
+      {
+      gbind *bind_stmt = as_a <gbind *> (stmt);
+      if (!optimize && gimple_bind_block (bind_stmt))
+       note_nonlocal_block_vlas (info, gimple_bind_block (bind_stmt));
+
+      for (tree var = gimple_bind_vars (bind_stmt); var; var = DECL_CHAIN (var))
+       if (TREE_CODE (var) == NAMELIST_DECL)
+         {
+           /* Adjust decls mentioned in NAMELIST_DECL.  */
+           tree decls = NAMELIST_DECL_ASSOCIATED_DECL (var);
+           tree decl;
+           unsigned int i;
+
+           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (decls), i, decl)
+             {
+               if (TREE_CODE (decl) == VAR_DECL
+                   && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
+                 continue;
+               if (decl_function_context (decl) != info->context)
+                 CONSTRUCTOR_ELT (decls, i)->value
+                   = get_nonlocal_debug_decl (info, decl);
+             }
+         }
 
       *handled_ops_p = false;
       return NULL_TREE;
-
+      }
     case GIMPLE_COND:
       wi->val_only = true;
       wi->is_lhs = false;
@@ -1348,18 +1483,17 @@ convert_nonlocal_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
 
 /* A subroutine of convert_local_reference.  Create a local variable
    in the parent function with DECL_VALUE_EXPR set to reference the
-   field in FRAME.  This is used both for debug info and in OpenMP
+   field in FRAME.  This is used both for debug info and in OMP
    lowering.  */
 
 static tree
 get_local_debug_decl (struct nesting_info *info, tree decl, tree field)
 {
   tree x, new_decl;
-  void **slot;
 
-  slot = pointer_map_insert (info->var_map, decl);
+  tree *slot = &info->var_map->get_or_insert (decl);
   if (*slot)
-    return (tree) *slot;
+    return *slot;
 
   /* Make sure frame_decl gets created.  */
   (void) get_frame_type (info);
@@ -1523,7 +1657,7 @@ convert_local_reference_op (tree *tp, int *walk_subtrees, void *data)
         fold here, as the chain record type is not yet finalized.  */
       if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR
          && !DECL_P (TREE_OPERAND (TREE_OPERAND (t, 0), 0)))
-       pointer_set_insert (info->mem_refs, tp);
+       info->mem_refs->add (tp);
       wi->val_only = save_val_only;
       break;
 
@@ -1557,7 +1691,9 @@ static bool
 convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
 {
   struct nesting_info *const info = (struct nesting_info *) wi->info;
-  bool need_frame = false, need_stmts = false;
+  /* If not optimizing, we will force the creation of the FRAME object in
+     convert_all_function_calls, so we need to take it into account here.  */
+  bool need_frame = info->inner && !optimize, need_stmts = false;
   tree clause, decl;
   int dummy;
   bitmap new_suppress;
@@ -1579,6 +1715,15 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
            need_stmts = true;
          goto do_decl_clause;
 
+       case OMP_CLAUSE_LINEAR:
+         if (OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause))
+           need_stmts = true;
+         wi->val_only = true;
+         wi->is_lhs = false;
+         convert_local_reference_op (&OMP_CLAUSE_LINEAR_STEP (clause), &dummy,
+                                     wi);
+         goto do_decl_clause;
+
        case OMP_CLAUSE_PRIVATE:
        case OMP_CLAUSE_FIRSTPRIVATE:
        case OMP_CLAUSE_COPYPRIVATE:
@@ -1609,12 +1754,72 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
        case OMP_CLAUSE_FINAL:
        case OMP_CLAUSE_IF:
        case OMP_CLAUSE_NUM_THREADS:
+       case OMP_CLAUSE_DEPEND:
+       case OMP_CLAUSE_DEVICE:
+       case OMP_CLAUSE_NUM_TEAMS:
+       case OMP_CLAUSE_THREAD_LIMIT:
+       case OMP_CLAUSE_SAFELEN:
+       case OMP_CLAUSE__CILK_FOR_COUNT_:
          wi->val_only = true;
          wi->is_lhs = false;
          convert_local_reference_op (&OMP_CLAUSE_OPERAND (clause, 0), &dummy,
                                      wi);
          break;
 
+       case OMP_CLAUSE_DIST_SCHEDULE:
+         if (OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (clause) != NULL)
+           {
+             wi->val_only = true;
+             wi->is_lhs = false;
+             convert_local_reference_op (&OMP_CLAUSE_OPERAND (clause, 0),
+                                         &dummy, wi);
+           }
+         break;
+
+       case OMP_CLAUSE_MAP:
+       case OMP_CLAUSE_TO:
+       case OMP_CLAUSE_FROM:
+         if (OMP_CLAUSE_SIZE (clause))
+           {
+             wi->val_only = true;
+             wi->is_lhs = false;
+             convert_local_reference_op (&OMP_CLAUSE_SIZE (clause),
+                                         &dummy, wi);
+           }
+         if (DECL_P (OMP_CLAUSE_DECL (clause)))
+           goto do_decl_clause;
+         wi->val_only = true;
+         wi->is_lhs = false;
+         walk_tree (&OMP_CLAUSE_DECL (clause), convert_local_reference_op,
+                    wi, NULL);
+         break;
+
+       case OMP_CLAUSE_ALIGNED:
+         if (OMP_CLAUSE_ALIGNED_ALIGNMENT (clause))
+           {
+             wi->val_only = true;
+             wi->is_lhs = false;
+             convert_local_reference_op
+               (&OMP_CLAUSE_ALIGNED_ALIGNMENT (clause), &dummy, wi);
+           }
+         /* Like do_decl_clause, but don't add any suppression.  */
+         decl = OMP_CLAUSE_DECL (clause);
+         if (TREE_CODE (decl) == VAR_DECL
+             && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
+           break;
+         if (decl_function_context (decl) == info->context
+             && !use_pointer_in_frame (decl))
+           {
+             tree field = lookup_field_for_decl (info, decl, NO_INSERT);
+             if (field)
+               {
+                 OMP_CLAUSE_DECL (clause)
+                   = get_local_debug_decl (info, decl, field);
+                 need_frame = true;
+               }
+           }
+         break;
+
        case OMP_CLAUSE_NOWAIT:
        case OMP_CLAUSE_ORDERED:
        case OMP_CLAUSE_DEFAULT:
@@ -1622,6 +1827,7 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
        case OMP_CLAUSE_COLLAPSE:
        case OMP_CLAUSE_UNTIED:
        case OMP_CLAUSE_MERGEABLE:
+       case OMP_CLAUSE_PROC_BIND:
          break;
 
        default:
@@ -1659,6 +1865,12 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi)
                     &OMP_CLAUSE_LASTPRIVATE_GIMPLE_SEQ (clause));
          break;
 
+       case OMP_CLAUSE_LINEAR:
+         walk_body (convert_local_reference_stmt,
+                    convert_local_reference_op, info,
+                    &OMP_CLAUSE_LINEAR_GIMPLE_SEQ (clause));
+         break;
+
        default:
          break;
        }
@@ -1713,7 +1925,8 @@ convert_local_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
     case GIMPLE_OMP_FOR:
       save_suppress = info->suppress_expansion;
       convert_local_omp_clauses (gimple_omp_for_clauses_ptr (stmt), wi);
-      walk_gimple_omp_for (stmt, convert_local_reference_stmt,
+      walk_gimple_omp_for (as_a <gomp_for *> (stmt),
+                          convert_local_reference_stmt,
                           convert_local_reference_op, info);
       walk_body (convert_local_reference_stmt, convert_local_reference_op,
                 info, gimple_omp_body_ptr (stmt));
@@ -1737,10 +1950,38 @@ convert_local_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
       break;
 
     case GIMPLE_OMP_TARGET:
+      if (!is_gimple_omp_offloaded (stmt))
+       {
+         save_suppress = info->suppress_expansion;
+         convert_local_omp_clauses (gimple_omp_target_clauses_ptr (stmt), wi);
+         info->suppress_expansion = save_suppress;
+         walk_body (convert_local_reference_stmt, convert_local_reference_op,
+                    info, gimple_omp_body_ptr (stmt));
+         break;
+       }
       save_suppress = info->suppress_expansion;
-      convert_local_omp_clauses (gimple_omp_target_clauses_ptr (stmt), wi);
-      walk_body (convert_local_reference_stmt, convert_local_reference_op,
-                info, gimple_omp_body_ptr (stmt));
+      if (convert_local_omp_clauses (gimple_omp_target_clauses_ptr (stmt), wi))
+       {
+         tree c;
+         (void) get_frame_type (info);
+         c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
+         OMP_CLAUSE_DECL (c) = info->frame_decl;
+         OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
+         OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (info->frame_decl);
+         OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
+         gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt), c);
+       }
+
+      save_local_var_chain = info->new_local_var_chain;
+      info->new_local_var_chain = NULL;
+
+      walk_body (convert_local_reference_stmt, convert_local_reference_op, info,
+                gimple_omp_body_ptr (stmt));
+
+      if (info->new_local_var_chain)
+       declare_vars (info->new_local_var_chain,
+                     gimple_seq_first_stmt (gimple_omp_body (stmt)), false);
+      info->new_local_var_chain = save_local_var_chain;
       info->suppress_expansion = save_suppress;
       break;
 
@@ -1780,6 +2021,38 @@ convert_local_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
       *handled_ops_p = false;
       return NULL_TREE;
 
+    case GIMPLE_BIND:
+      for (tree var = gimple_bind_vars (as_a <gbind *> (stmt));
+          var;
+          var = DECL_CHAIN (var))
+       if (TREE_CODE (var) == NAMELIST_DECL)
+         {
+           /* Adjust decls mentioned in NAMELIST_DECL.  */
+           tree decls = NAMELIST_DECL_ASSOCIATED_DECL (var);
+           tree decl;
+           unsigned int i;
+
+           FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (decls), i, decl)
+             {
+               if (TREE_CODE (decl) == VAR_DECL
+                   && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
+                 continue;
+               if (decl_function_context (decl) == info->context
+                   && !use_pointer_in_frame (decl))
+                 {
+                   tree field = lookup_field_for_decl (info, decl, NO_INSERT);
+                   if (field)
+                     {
+                       CONSTRUCTOR_ELT (decls, i)->value
+                         = get_local_debug_decl (info, decl, field);
+                     }
+                 }
+             }
+         }
+
+      *handled_ops_p = false;
+      return NULL_TREE;
+
     default:
       /* For every other statement that we are not interested in
         handling here, let the walker traverse the operands.  */
@@ -1803,8 +2076,7 @@ convert_nl_goto_reference (gimple_stmt_iterator *gsi, bool *handled_ops_p,
 {
   struct nesting_info *const info = (struct nesting_info *) wi->info, *i;
   tree label, new_label, target_context, x, field;
-  void **slot;
-  gimple call;
+  gcall *call;
   gimple stmt = gsi_stmt (*gsi);
 
   if (gimple_code (stmt) != GIMPLE_GOTO)
@@ -1837,7 +2109,7 @@ convert_nl_goto_reference (gimple_stmt_iterator *gsi, bool *handled_ops_p,
      (hairy target-specific) non-local goto receiver code to be generated
      when we expand rtl.  Enter this association into var_map so that we
      can insert the new label into the IL during a second pass.  */
-  slot = pointer_map_insert (i->var_map, label);
+  tree *slot = &i->var_map->get_or_insert (label);
   if (*slot == NULL)
     {
       new_label = create_artificial_label (UNKNOWN_LOCATION);
@@ -1845,7 +2117,7 @@ convert_nl_goto_reference (gimple_stmt_iterator *gsi, bool *handled_ops_p,
       *slot = new_label;
     }
   else
-    new_label = (tree) *slot;
+    new_label = *slot;
 
   /* Build: __builtin_nl_goto(new_label, &chain->nl_goto_field).  */
   field = get_nl_goto_field (i);
@@ -1875,10 +2147,9 @@ convert_nl_goto_receiver (gimple_stmt_iterator *gsi, bool *handled_ops_p,
   struct nesting_info *const info = (struct nesting_info *) wi->info;
   tree label, new_label;
   gimple_stmt_iterator tmp_gsi;
-  void **slot;
-  gimple stmt = gsi_stmt (*gsi);
+  glabel *stmt = dyn_cast <glabel *> (gsi_stmt (*gsi));
 
-  if (gimple_code (stmt) != GIMPLE_LABEL)
+  if (!stmt)
     {
       *handled_ops_p = false;
       return NULL_TREE;
@@ -1886,7 +2157,7 @@ convert_nl_goto_receiver (gimple_stmt_iterator *gsi, bool *handled_ops_p,
 
   label = gimple_label_label (stmt);
 
-  slot = pointer_map_contains (info->var_map, label);
+  tree *slot = info->var_map->get (label);
   if (!slot)
     {
       *handled_ops_p = false;
@@ -1922,7 +2193,7 @@ convert_tramp_reference_op (tree *tp, int *walk_subtrees, void *data)
   struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
   struct nesting_info *const info = (struct nesting_info *) wi->info, *i;
   tree t = *tp, decl, target_context, x, builtin;
-  gimple call;
+  gcall *call;
 
   *walk_subtrees = 0;
   switch (TREE_CODE (t))
@@ -2011,6 +2282,13 @@ convert_tramp_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
        break;
       }
 
+    case GIMPLE_OMP_TARGET:
+      if (!is_gimple_omp_offloaded (stmt))
+       {
+         *handled_ops_p = false;
+         return NULL_TREE;
+       }
+      /* FALLTHRU */
     case GIMPLE_OMP_PARALLEL:
     case GIMPLE_OMP_TASK:
       {
@@ -2031,7 +2309,6 @@ convert_tramp_reference_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
     default:
       *handled_ops_p = false;
       return NULL_TREE;
-      break;
     }
 
   *handled_ops_p = true;
@@ -2065,8 +2342,9 @@ convert_gimple_call (gimple_stmt_iterator *gsi, bool *handled_ops_p,
       target_context = decl_function_context (decl);
       if (target_context && DECL_STATIC_CHAIN (decl))
        {
-         gimple_call_set_chain (stmt, get_static_chain (info, target_context,
-                                                        &wi->gsi));
+         gimple_call_set_chain (as_a <gcall *> (stmt),
+                                get_static_chain (info, target_context,
+                                                  &wi->gsi));
          info->static_chain_added |= (1 << (info->context != target_context));
        }
       break;
@@ -2103,6 +2381,42 @@ convert_gimple_call (gimple_stmt_iterator *gsi, bool *handled_ops_p,
       info->static_chain_added |= save_static_chain_added;
       break;
 
+    case GIMPLE_OMP_TARGET:
+      if (!is_gimple_omp_offloaded (stmt))
+       {
+         walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
+         break;
+       }
+      save_static_chain_added = info->static_chain_added;
+      info->static_chain_added = 0;
+      walk_body (convert_gimple_call, NULL, info, gimple_omp_body_ptr (stmt));
+      for (i = 0; i < 2; i++)
+       {
+         tree c, decl;
+         if ((info->static_chain_added & (1 << i)) == 0)
+           continue;
+         decl = i ? get_chain_decl (info) : info->frame_decl;
+         /* Don't add CHAIN.* or FRAME.* twice.  */
+         for (c = gimple_omp_target_clauses (stmt);
+              c;
+              c = OMP_CLAUSE_CHAIN (c))
+           if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
+               && OMP_CLAUSE_DECL (c) == decl)
+             break;
+         if (c == NULL)
+           {
+             c = build_omp_clause (gimple_location (stmt), OMP_CLAUSE_MAP);
+             OMP_CLAUSE_DECL (c) = decl;
+             OMP_CLAUSE_SET_MAP_KIND (c, i ? GOMP_MAP_TO : GOMP_MAP_TOFROM);
+             OMP_CLAUSE_SIZE (c) = DECL_SIZE_UNIT (decl);
+             OMP_CLAUSE_CHAIN (c) = gimple_omp_target_clauses (stmt);
+             gimple_omp_target_set_clauses (as_a <gomp_target *> (stmt),
+                                            c);
+           }
+       }
+      info->static_chain_added |= save_static_chain_added;
+      break;
+
     case GIMPLE_OMP_FOR:
       walk_body (convert_gimple_call, NULL, info,
                 gimple_omp_for_pre_body_ptr (stmt));
@@ -2110,7 +2424,6 @@ convert_gimple_call (gimple_stmt_iterator *gsi, bool *handled_ops_p,
     case GIMPLE_OMP_SECTIONS:
     case GIMPLE_OMP_SECTION:
     case GIMPLE_OMP_SINGLE:
-    case GIMPLE_OMP_TARGET:
     case GIMPLE_OMP_TEAMS:
     case GIMPLE_OMP_MASTER:
     case GIMPLE_OMP_TASKGROUP:
@@ -2140,11 +2453,21 @@ convert_all_function_calls (struct nesting_info *root)
   struct nesting_info *n;
 
   /* First, optimistically clear static_chain for all decls that haven't
-     used the static chain already for variable access.  */
+     used the static chain already for variable access.  But always create
+     it if not optimizing.  This makes it possible to reconstruct the static
+     nesting tree at run time and thus to resolve up-level references from
+     within the debugger.  */
   FOR_EACH_NEST_INFO (n, root)
     {
       tree decl = n->context;
-      if (!n->outer || (!n->chain_decl && !n->chain_field))
+      if (!optimize)
+       {
+         if (n->inner)
+           (void) get_frame_type (n);
+         if (n->outer)
+           (void) get_chain_decl (n);
+       }
+      else if (!n->outer || (!n->chain_decl && !n->chain_field))
        {
          DECL_STATIC_CHAIN (decl) = 0;
          if (dump_file && (dump_flags & TDF_DETAILS))
@@ -2201,7 +2524,7 @@ static tree
 nesting_copy_decl (tree decl, copy_body_data *id)
 {
   struct nesting_copy_body_data *nid = (struct nesting_copy_body_data *) id;
-  void **slot = pointer_map_contains (nid->root->var_map, decl);
+  tree *slot = nid->root->var_map->get (decl);
 
   if (slot)
     return (tree) *slot;
@@ -2230,15 +2553,14 @@ contains_remapped_vars (tree *tp, int *walk_subtrees, void *data)
 {
   struct nesting_info *root = (struct nesting_info *) data;
   tree t = *tp;
-  void **slot;
 
   if (DECL_P (t))
     {
       *walk_subtrees = 0;
-      slot = pointer_map_contains (root->var_map, t);
+      tree *slot = root->var_map->get (t);
 
       if (slot)
-       return (tree) *slot;
+       return *slot;
     }
   return NULL;
 }
@@ -2268,7 +2590,7 @@ remap_vla_decls (tree block, struct nesting_info *root)
              && variably_modified_type_p (type, NULL)))
          continue;
 
-       if (pointer_map_contains (root->var_map, TREE_OPERAND (val, 0))
+       if (root->var_map->get (TREE_OPERAND (val, 0))
            || walk_tree (&type, contains_remapped_vars, root, NULL))
          break;
       }
@@ -2278,7 +2600,7 @@ remap_vla_decls (tree block, struct nesting_info *root)
 
   memset (&id, 0, sizeof (id));
   id.cb.copy_decl = nesting_copy_decl;
-  id.cb.decl_map = pointer_map_create ();
+  id.cb.decl_map = new hash_map<tree, tree>;
   id.root = root;
 
   for (; var; var = DECL_CHAIN (var))
@@ -2286,7 +2608,6 @@ remap_vla_decls (tree block, struct nesting_info *root)
       {
        struct nesting_info *i;
        tree newt, context;
-       void **slot;
 
        val = DECL_VALUE_EXPR (var);
        type = TREE_TYPE (var);
@@ -2296,7 +2617,7 @@ remap_vla_decls (tree block, struct nesting_info *root)
              && variably_modified_type_p (type, NULL)))
          continue;
 
-       slot = pointer_map_contains (root->var_map, TREE_OPERAND (val, 0));
+       tree *slot = root->var_map->get (TREE_OPERAND (val, 0));
        if (!slot && !walk_tree (&type, contains_remapped_vars, root, NULL))
          continue;
 
@@ -2339,12 +2660,12 @@ remap_vla_decls (tree block, struct nesting_info *root)
          SET_DECL_VALUE_EXPR (var, val);
       }
 
-  pointer_map_destroy (id.cb.decl_map);
+  delete id.cb.decl_map;
 }
 
 /* Fold the MEM_REF *E.  */
-static bool
-fold_mem_refs (const void *e, void *data ATTRIBUTE_UNUSED)
+bool
+fold_mem_refs (tree *const &e, void *data ATTRIBUTE_UNUSED)
 {
   tree *ref_p = CONST_CAST2 (tree *, const tree *, (const tree *)e);
   *ref_p = fold (*ref_p);
@@ -2414,10 +2735,6 @@ finalize_nesting_tree_1 (struct nesting_info *root)
          else
            x = p;
 
-         y = build3 (COMPONENT_REF, TREE_TYPE (field),
-                     root->frame_decl, field, NULL_TREE);
-         stmt = gimple_build_assign (y, x);
-         gimple_seq_add_stmt (&stmt_list, stmt);
          /* If the assignment is from a non-register the stmt is
             not valid gimple.  Make it so by using a temporary instead.  */
          if (!is_gimple_reg (x)
@@ -2425,8 +2742,12 @@ finalize_nesting_tree_1 (struct nesting_info *root)
            {
              gimple_stmt_iterator gsi = gsi_last (stmt_list);
              x = init_tmp_var (root, x, &gsi);
-             gimple_assign_set_rhs1 (stmt, x);
            }
+
+         y = build3 (COMPONENT_REF, TREE_TYPE (field),
+                     root->frame_decl, field, NULL_TREE);
+         stmt = gimple_build_assign (y, x);
+         gimple_seq_add_stmt (&stmt_list, stmt);
        }
     }
 
@@ -2470,9 +2791,9 @@ finalize_nesting_tree_1 (struct nesting_info *root)
   /* If we created initialization statements, insert them.  */
   if (stmt_list)
     {
-      gimple bind;
+      gbind *bind;
       annotate_all_with_location (stmt_list, DECL_SOURCE_LOCATION (context));
-      bind = gimple_seq_first_stmt (gimple_body (context));
+      bind = gimple_seq_first_stmt_as_a_bind (gimple_body (context));
       gimple_seq_add_seq (&stmt_list, gimple_bind_body (bind));
       gimple_bind_set_body (bind, stmt_list);
     }
@@ -2501,7 +2822,7 @@ finalize_nesting_tree_1 (struct nesting_info *root)
   if (root->debug_var_chain)
     {
       tree debug_var;
-      gimple scope;
+      gbind *scope;
 
       remap_vla_decls (DECL_INITIAL (root->context), root);
 
@@ -2518,7 +2839,7 @@ finalize_nesting_tree_1 (struct nesting_info *root)
 
          memset (&id, 0, sizeof (id));
          id.cb.copy_decl = nesting_copy_decl;
-         id.cb.decl_map = pointer_map_create ();
+         id.cb.decl_map = new hash_map<tree, tree>;
          id.root = root;
 
          for (; debug_var; debug_var = DECL_CHAIN (debug_var))
@@ -2553,10 +2874,10 @@ finalize_nesting_tree_1 (struct nesting_info *root)
                  TYPE_NAME (newt) = remap_decl (TYPE_NAME (newt), &id.cb);
              }
 
-         pointer_map_destroy (id.cb.decl_map);
+         delete id.cb.decl_map;
        }
 
-      scope = gimple_seq_first_stmt (gimple_body (root->context));
+      scope = gimple_seq_first_stmt_as_a_bind (gimple_body (root->context));
       if (gimple_bind_block (scope))
        declare_vars (root->debug_var_chain, scope, true);
       else
@@ -2566,7 +2887,7 @@ finalize_nesting_tree_1 (struct nesting_info *root)
     }
 
   /* Fold the rewritten MEM_REF trees.  */
-  pointer_set_traverse (root->mem_refs, fold_mem_refs, NULL);
+  root->mem_refs->traverse<void *, fold_mem_refs> (NULL);
 
   /* Dump the translated tree function.  */
   if (dump_file)
@@ -2589,14 +2910,14 @@ finalize_nesting_tree (struct nesting_info *root)
 static void
 unnest_nesting_tree_1 (struct nesting_info *root)
 {
-  struct cgraph_node *node = cgraph_get_node (root->context);
+  struct cgraph_node *node = cgraph_node::get (root->context);
 
   /* For nested functions update the cgraph to reflect unnesting.
      We also delay finalizing of these functions up to this point.  */
   if (node->origin)
     {
-       cgraph_unnest_node (node);
-       cgraph_finalize_function (root->context, true);
+       node->unnest ();
+       cgraph_node::finalize_function (root->context, true);
     }
 }
 
@@ -2619,9 +2940,9 @@ free_nesting_tree (struct nesting_info *root)
   do
     {
       next = iter_nestinfo_next (node);
-      pointer_map_destroy (node->var_map);
-      pointer_map_destroy (node->field_map);
-      pointer_set_destroy (node->mem_refs);
+      delete node->var_map;
+      delete node->field_map;
+      delete node->mem_refs;
       free (node);
       node = next;
     }
@@ -2649,7 +2970,7 @@ lower_nested_functions (tree fndecl)
   struct nesting_info *root;
 
   /* If there are no nested functions, there's nothing to do.  */
-  cgn = cgraph_get_node (fndecl);
+  cgn = cgraph_node::get (fndecl);
   if (!cgn->nested)
     return;
 
This page took 0.055705 seconds and 5 git commands to generate.