OSDN Git Service

Backported from mainline
[pf3gnuchains/gcc-fork.git] / gcc / trans-mem.c
index 8780825..4483ce5 100644 (file)
@@ -1,5 +1,5 @@
 /* Passes for transactional memory support.
-   Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
 
    This file is part of GCC.
 
@@ -1496,9 +1496,7 @@ requires_barrier (basic_block entry_block, tree x, gimple stmt)
             during lower_sequence_tm/gimplification, leave the call
             to needs_to_live_in_memory until we eliminate
             lower_sequence_tm altogether.  */
-         needs_to_live_in_memory (x)
-         /* X escapes.  */
-         || ptr_deref_may_alias_global_p (x))
+         needs_to_live_in_memory (x))
        return true;
       else
        {
@@ -1759,6 +1757,10 @@ struct tm_region
   bitmap irr_blocks;
 };
 
+typedef struct tm_region *tm_region_p;
+DEF_VEC_P (tm_region_p);
+DEF_VEC_ALLOC_P (tm_region_p, heap);
+
 /* True if there are pending edge statements to be committed for the
    current function being scanned in the tmmark pass.  */
 bool pending_edge_inserts_p;
@@ -1860,18 +1862,23 @@ tm_region_init (struct tm_region *region)
   VEC(basic_block, heap) *queue = NULL;
   bitmap visited_blocks = BITMAP_ALLOC (NULL);
   struct tm_region *old_region;
+  VEC(tm_region_p, heap) *bb_regions = NULL;
 
   all_tm_regions = region;
   bb = single_succ (ENTRY_BLOCK_PTR);
 
+  /* We could store this information in bb->aux, but we may get called
+     through get_all_tm_blocks() from another pass that may be already
+     using bb->aux.  */
+  VEC_safe_grow_cleared (tm_region_p, heap, bb_regions, last_basic_block);
+
   VEC_safe_push (basic_block, heap, queue, bb);
-  gcc_assert (!bb->aux);       /* FIXME: Remove me.  */
-  bb->aux = region;
+  VEC_replace (tm_region_p, bb_regions, bb->index, region);
   do
     {
       bb = VEC_pop (basic_block, queue);
-      region = (struct tm_region *)bb->aux;
-      bb->aux = NULL;
+      region = VEC_index (tm_region_p, bb_regions, bb->index);
+      VEC_replace (tm_region_p, bb_regions, bb->index, NULL);
 
       /* Record exit and irrevocable blocks.  */
       region = tm_region_init_1 (region, bb);
@@ -1888,20 +1895,20 @@ tm_region_init (struct tm_region *region)
          {
            bitmap_set_bit (visited_blocks, e->dest->index);
            VEC_safe_push (basic_block, heap, queue, e->dest);
-           gcc_assert (!e->dest->aux); /* FIXME: Remove me.  */
 
            /* If the current block started a new region, make sure that only
               the entry block of the new region is associated with this region.
               Other successors are still part of the old region.  */
            if (old_region != region && e->dest != region->entry_block)
-             e->dest->aux = old_region;
+             VEC_replace (tm_region_p, bb_regions, e->dest->index, old_region);
            else
-             e->dest->aux = region;
+             VEC_replace (tm_region_p, bb_regions, e->dest->index, region);
          }
     }
   while (!VEC_empty (basic_block, queue));
   VEC_free (basic_block, heap, queue);
   BITMAP_FREE (visited_blocks);
+  VEC_free (tm_region_p, heap, bb_regions);
 }
 
 /* The "gate" function for all transactional memory expansion and optimization
@@ -2269,6 +2276,8 @@ expand_call_tm (struct tm_region *region,
     }
 
   node = cgraph_get_node (fn_decl);
+  /* All calls should have cgraph here. */
+  gcc_assert (node);
   if (node->local.tm_may_enter_irr)
     transaction_subcode_ior (region, GTMA_MAY_ENTER_IRREVOCABLE);
 
@@ -2424,6 +2433,40 @@ get_tm_region_blocks (basic_block entry_block,
   return bbs;
 }
 
+/* Set the IN_TRANSACTION for all gimple statements that appear in a
+   transaction.  */
+
+void
+compute_transaction_bits (void)
+{
+  struct tm_region *region;
+  VEC (basic_block, heap) *queue;
+  unsigned int i;
+  basic_block bb;
+
+  /* ?? Perhaps we need to abstract gate_tm_init further, because we
+     certainly don't need it to calculate CDI_DOMINATOR info.  */
+  gate_tm_init ();
+
+  FOR_EACH_BB (bb)
+    bb->flags &= ~BB_IN_TRANSACTION;
+
+  for (region = all_tm_regions; region; region = region->next)
+    {
+      queue = get_tm_region_blocks (region->entry_block,
+                                   region->exit_blocks,
+                                   region->irr_blocks,
+                                   NULL,
+                                   /*stop_at_irr_p=*/true);
+      for (i = 0; VEC_iterate (basic_block, queue, i, bb); ++i)
+       bb->flags |= BB_IN_TRANSACTION;
+      VEC_free (basic_block, heap, queue);
+    }
+
+  if (all_tm_regions)
+    bitmap_obstack_release (&tm_obstack);
+}
+
 /* Entry point to the MARK phase of TM expansion.  Here we replace
    transactional memory statements with calls to builtins, and function
    calls with their transactional clones (if available).  But we don't
@@ -2540,6 +2583,7 @@ expand_block_edges (struct tm_region *region, basic_block bb)
 
   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); )
     {
+      bool do_next = true;
       gimple stmt = gsi_stmt (gsi);
 
       /* ??? TM_COMMIT (and any other tm builtin function) in a nested
@@ -2561,6 +2605,7 @@ expand_block_edges (struct tm_region *region, basic_block bb)
              make_tm_edge (stmt, bb, region);
              bb = e->dest;
              gsi = gsi_start_bb (bb);
+             do_next = false;
            }
 
          /* Delete any tail-call annotation that may have been added.
@@ -2569,7 +2614,8 @@ expand_block_edges (struct tm_region *region, basic_block bb)
          gimple_call_set_tail (stmt, false);
        }
 
-      gsi_next (&gsi);
+      if (do_next)
+       gsi_next (&gsi);
     }
 }
 
@@ -3736,6 +3782,13 @@ ipa_tm_scan_irr_block (basic_block bb)
             assembly statement is not relevant to the transaction
             is to wrap it in a __tm_waiver block.  This is not
             yet implemented, so we can't check for it.  */
+         if (is_tm_safe (current_function_decl))
+           {
+             tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
+             SET_EXPR_LOCATION (t, gimple_location (stmt));
+             TREE_BLOCK (t) = gimple_block (stmt);
+             error ("%Kasm not allowed in %<transaction_safe%> function", t);
+           }
          return true;
 
        default:
@@ -4221,7 +4274,7 @@ struct create_version_alias_info
   tree new_decl;
 };
 
-/* A subrontine of ipa_tm_create_version, called via
+/* A subroutine of ipa_tm_create_version, called via
    cgraph_for_node_and_aliases.  Create new tm clones for each of
    the existing aliases.  */
 static bool
@@ -4261,12 +4314,14 @@ ipa_tm_create_version_alias (struct cgraph_node *node, void *data)
 
   new_node = cgraph_same_body_alias (NULL, new_decl, info->new_decl);
   new_node->tm_clone = true;
+  new_node->local.externally_visible = info->old_node->local.externally_visible;
   /* ?? Do not traverse aliases here.  */
   get_cg_data (&node, false)->clone = new_node;
 
   record_tm_clone_pair (old_decl, new_decl);
 
-  if (info->old_node->needed)
+  if (info->old_node->needed
+      || ipa_ref_list_first_refering (&info->old_node->ref_list))
     ipa_tm_mark_needed_node (new_node);
   return false;
 }
@@ -4296,6 +4351,7 @@ ipa_tm_create_version (struct cgraph_node *old_node)
     DECL_COMDAT_GROUP (new_decl) = tm_mangle (DECL_COMDAT_GROUP (old_decl));
 
   new_node = cgraph_copy_node_for_versioning (old_node, new_decl, NULL, NULL);
+  new_node->local.externally_visible = old_node->local.externally_visible;
   new_node->lowered = true;
   new_node->tm_clone = 1;
   get_cg_data (&old_node, true)->clone = new_node;
@@ -4311,14 +4367,15 @@ ipa_tm_create_version (struct cgraph_node *old_node)
          DECL_WEAK (new_decl) = 0;
        }
 
-      tree_function_versioning (old_decl, new_decl, NULL, false, NULL,
+      tree_function_versioning (old_decl, new_decl, NULL, false, NULL, false,
                                NULL, NULL);
     }
 
   record_tm_clone_pair (old_decl, new_decl);
 
   cgraph_call_function_insertion_hooks (new_node);
-  if (old_node->needed)
+  if (old_node->needed
+      || ipa_ref_list_first_refering (&old_node->ref_list))
     ipa_tm_mark_needed_node (new_node);
 
   /* Do the same thing, but for any aliases of the original node.  */
@@ -4667,7 +4724,7 @@ ipa_tm_transform_clone (struct cgraph_node *node)
   /* If this function makes no calls and has no irrevocable blocks,
      then there's nothing to do.  */
   /* ??? Remove non-aborting top-level transactions.  */
-  if (!node->callees && !d->irrevocable_blocks_clone)
+  if (!node->callees && !node->indirect_calls && !d->irrevocable_blocks_clone)
     return;
 
   current_function_decl = d->clone->decl;