OSDN Git Service

* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Procedure>: Set default
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-loop-im.c
index 6c6a9f1..90b3a38 100644 (file)
@@ -1,19 +1,19 @@
 /* Loop invariant motion.
-   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Free Software
-   Foundation, Inc.
-   
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010
+   Free Software Foundation, Inc.
+
 This file is part of GCC.
-   
+
 GCC is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the
 Free Software Foundation; either version 3, or (at your option) any
 later version.
-   
+
 GCC is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
-   
+
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
@@ -251,13 +251,13 @@ clear_lim_data (gimple stmt)
 /* Calls CBCK for each index in memory reference ADDR_P.  There are two
    kinds situations handled; in each of these cases, the memory reference
    and DATA are passed to the callback:
-   
+
    Access to an array: ARRAY_{RANGE_}REF (base, index).  In this case we also
    pass the pointer to the index to the callback.
 
    Pointer dereference: INDIRECT_REF (addr).  In this case we also pass the
    pointer to addr to the callback.
-   
+
    If the callback returns false, the whole search stops and false is returned.
    Otherwise the function returns true after traversing through the whole
    reference *ADDR_P.  */
@@ -452,14 +452,14 @@ outermost_invariant_loop (tree def, struct loop *loop)
 
 /* DATA is a structure containing information associated with a statement
    inside LOOP.  DEF is one of the operands of this statement.
-   
+
    Find the outermost loop enclosing LOOP in that value of DEF is invariant
    and record this in DATA->max_loop field.  If DEF itself is defined inside
    this loop as well (i.e. we need to hoist it out of the loop if we want
    to hoist the statement represented by DATA), record the statement in that
    DEF is defined to the DATA->depends list.  Additionally if ADD_COST is true,
    add the cost of the computation of DEF to the DATA->cost.
-   
+
    If DEF is not invariant in LOOP, return false.  Otherwise return TRUE.  */
 
 static bool
@@ -657,7 +657,7 @@ mem_ref_in_stmt (gimple stmt)
    If MUST_PRESERVE_EXEC is true, additionally choose such a loop that
    we preserve the fact whether STMT is executed.  It also fills other related
    information to LIM_DATA (STMT).
-   
+
    The function returns false if STMT cannot be hoisted outside of the loop it
    is defined in, and true otherwise.  */
 
@@ -670,7 +670,7 @@ determine_max_movement (gimple stmt, bool must_preserve_exec)
   struct lim_aux_data *lim_data = get_lim_data (stmt);
   tree val;
   ssa_op_iter iter;
-  
+
   if (must_preserve_exec)
     level = ALWAYS_EXECUTED_IN (bb);
   else
@@ -1138,7 +1138,7 @@ force_move_till_op (tree op, struct loop *orig_loop, struct loop *loop)
     return;
 
   gcc_assert (TREE_CODE (op) == SSA_NAME);
-      
+
   stmt = SSA_NAME_DEF_STMT (op);
   if (gimple_nop_p (stmt))
     return;
@@ -1764,7 +1764,7 @@ gen_lsm_tmp_name (tree ref)
       gen_lsm_tmp_name (TREE_OPERAND (ref, 0));
       lsm_tmp_name_add ("_RE");
       break;
-      
+
     case IMAGPART_EXPR:
       gen_lsm_tmp_name (TREE_OPERAND (ref, 0));
       lsm_tmp_name_add ("_IM");
@@ -1776,8 +1776,8 @@ gen_lsm_tmp_name (tree ref)
       name = get_name (TREE_OPERAND (ref, 1));
       if (!name)
        name = "F";
-      lsm_tmp_name_add ("_");
       lsm_tmp_name_add (name);
+      break;
 
     case ARRAY_REF:
       gen_lsm_tmp_name (TREE_OPERAND (ref, 0));
@@ -1900,16 +1900,22 @@ hoist_memory_references (struct loop *loop, bitmap mem_refs,
     }
 }
 
-/* Returns true if REF is always accessed in LOOP.  */
+/* Returns true if REF is always accessed in LOOP.  If STORED_P is true
+   make sure REF is always stored to in LOOP.  */
 
 static bool
-ref_always_accessed_p (struct loop *loop, mem_ref_p ref)
+ref_always_accessed_p (struct loop *loop, mem_ref_p ref, bool stored_p)
 {
   VEC (mem_ref_loc_p, heap) *locs = NULL;
   unsigned i;
   mem_ref_loc_p loc;
   bool ret = false;
   struct loop *must_exec;
+  tree base;
+
+  base = get_base_address (ref->mem);
+  if (INDIRECT_REF_P (base))
+    base = TREE_OPERAND (base, 0);
 
   get_all_locs_in_loop (loop, ref, &locs);
   for (i = 0; VEC_iterate (mem_ref_loc_p, locs, i, loc); i++)
@@ -1917,6 +1923,22 @@ ref_always_accessed_p (struct loop *loop, mem_ref_p ref)
       if (!get_lim_data (loc->stmt))
        continue;
 
+      /* If we require an always executed store make sure the statement
+         stores to the reference.  */
+      if (stored_p)
+       {
+         tree lhs;
+         if (!gimple_get_lhs (loc->stmt))
+           continue;
+         lhs = get_base_address (gimple_get_lhs (loc->stmt));
+         if (!lhs)
+           continue;
+         if (INDIRECT_REF_P (lhs))
+           lhs = TREE_OPERAND (lhs, 0);
+         if (lhs != base)
+           continue;
+       }
+
       must_exec = get_lim_data (loc->stmt)->always_executed_in;
       if (!must_exec)
        continue;
@@ -2054,6 +2076,8 @@ ref_indep_loop_p (struct loop *loop, mem_ref_p ref)
 static bool
 can_sm_ref_p (struct loop *loop, mem_ref_p ref)
 {
+  tree base;
+
   /* Unless the reference is stored in the loop, there is nothing to do.  */
   if (!bitmap_bit_p (ref->stored, loop->num))
     return false;
@@ -2064,9 +2088,14 @@ can_sm_ref_p (struct loop *loop, mem_ref_p ref)
       || !for_each_index (&ref->mem, may_move_till, loop))
     return false;
 
-  /* If it can trap, it must be always executed in LOOP.  */
-  if (tree_could_trap_p (ref->mem)
-      && !ref_always_accessed_p (loop, ref))
+  /* If it can trap, it must be always executed in LOOP.
+     Readonly memory locations may trap when storing to them, but
+     tree_could_trap_p is a predicate for rvalues, so check that
+     explicitly.  */
+  base = get_base_address (ref->mem);
+  if ((tree_could_trap_p (ref->mem)
+       || (DECL_P (base) && TREE_READONLY (base)))
+      && !ref_always_accessed_p (loop, ref, true))
     return false;
 
   /* And it must be independent on all other memory references