On 11-11-03 14:20 , Delesley Hutchins wrote:
This patch adds support for array indexing (i.e. operator []) in lock
expressions.  The current version of gcc seems to emit these as
expressions involving pointer arithmetic, so we  update
get_canonical_lock_expr() to handle such expressions.

Bootstrapped and passed gcc regression testsuite on
x86_64-unknown-linux-gnu.  Okay for google/gcc-4_6?

  -DeLesley

Changelog.google-4_6:
2011-11-03  DeLesley Hutchins<deles...@google.com>
    * tree-threadsafe-analyze.c (get_canonical_lock_expr):
      Add support for pointer arithmetic operations

Blank line after date.  End entry with '.'.  Align second line with '*'.

Index: tree-threadsafe-analyze.c
===================================================================
--- tree-threadsafe-analyze.c   (revision 180716)
+++ tree-threadsafe-analyze.c   (working copy)
@@ -79,6 +79,7 @@ along with GCC; see the file COPYING3.
 #include "coretypes.h"
 #include "tm.h"
 #include "tree.h"
+#include "gimple.h"

Well, we're getting gimple.h from somewhere else, but it's fine to include. Since you did, make sure you add it as a dependency for tree-threadsafe-analyze.o in Makefile.in.

 #include "c-family/c-common.h"
 #include "toplev.h"
 #include "input.h"
@@ -804,12 +805,27 @@ get_canonical_lock_expr (tree lock, tree
               && !gimple_nop_p (SSA_NAME_DEF_STMT (lock)))
             {
               gimple def_stmt = SSA_NAME_DEF_STMT (lock);
-              if (is_gimple_assign (def_stmt)
-                  && (get_gimple_rhs_class (gimple_assign_rhs_code (def_stmt))
-                      == GIMPLE_SINGLE_RHS))
-                return get_canonical_lock_expr (gimple_assign_rhs1 (def_stmt),
-                                                base_obj, is_temp_expr,
-                                                NULL_TREE);
+              if (is_gimple_assign (def_stmt))
+                {
+                  enum gimple_rhs_class gcls =
+                    get_gimple_rhs_class (gimple_assign_rhs_code (def_stmt));
+                  tree rhs = 0;

s/0/NULL_TREE/

+
+                  if (gcls == GIMPLE_SINGLE_RHS)
+                    rhs = gimple_assign_rhs1 (def_stmt);
+                  else if (gcls == GIMPLE_UNARY_RHS)
+                    rhs = build1 (gimple_assign_rhs_code (def_stmt),
+                                  TREE_TYPE (gimple_assign_lhs (def_stmt)),
+                                  gimple_assign_rhs1 (def_stmt));
+                  else if (gcls == GIMPLE_BINARY_RHS)
+                    rhs = build2 (gimple_assign_rhs_code (def_stmt),
+                                  TREE_TYPE (gimple_assign_lhs (def_stmt)),
+                                  gimple_assign_rhs1 (def_stmt),
+                                  gimple_assign_rhs2 (def_stmt));
+                  if (rhs)
+                    return get_canonical_lock_expr (rhs, base_obj,
+                                                    is_temp_expr, NULL_TREE);
+                }
               else if (is_gimple_call (def_stmt))
                 {
                   tree fdecl = gimple_call_fndecl (def_stmt);
@@ -981,6 +997,24 @@ get_canonical_lock_expr (tree lock, tree
                            TREE_TYPE (TREE_TYPE (canon_base)), canon_base);
           break;
         }
+      case PLUS_EXPR:
+      case POINTER_PLUS_EXPR:
+      case MULT_EXPR:

Why PLUS_EXPR and MULT_EXPR? Pointer arithmetic should use POINTER_PLUS_EXPR exclusively. I don't think you should be seeing PLUS_EXPRs here. The MULT_EXPR show up in scaling expressions?

+        {
+          tree left = TREE_OPERAND (lock, 0);
+          tree canon_left = get_canonical_lock_expr (left, base_obj,
+                                                     true /* is_temp_expr */,
+                                                     NULL_TREE);
+
+          tree right = TREE_OPERAND (lock, 1);
+          tree canon_right = get_canonical_lock_expr (right, base_obj,
+                                                      true /* is_temp_expr */,
+                                                      NULL_TREE);
+          if (left != canon_left || right != canon_right)
+            lock = build2 (TREE_CODE(lock), TREE_TYPE(lock),

Space before '('.

+                           canon_left, canon_right);
+          break;
+        }
       default:
         break;
     }



Diego.

Reply via email to