OSDN Git Service

* tree-ssa-loop-ivopts.c: New file.
[pf3gnuchains/gcc-fork.git] / gcc / tree-mudflap.c
index 2320bc9..580d9ad 100644 (file)
@@ -76,9 +76,8 @@ mf_build_string (const char *string)
   size_t len = strlen (string);
   tree result = mf_mark (build_string (len + 1, string));
 
-  TREE_TYPE (result)
-      = build_array_type (char_type_node,
-                          build_index_type (build_int_2 (len, 0)));
+  TREE_TYPE (result) = build_array_type
+    (char_type_node, build_index_type (build_int_cst (NULL_TREE, len)));
   TREE_CONSTANT (result) = 1;
   TREE_INVARIANT (result) = 1;
   TREE_READONLY (result) = 1;
@@ -195,10 +194,11 @@ mf_file_function_line_tree (location_t location)
   tree result;
 
   /* Add FILENAME[:LINENUMBER]. */
-  if (xloc.file == NULL && current_function_decl != NULL_TREE)
-    xloc.file = DECL_SOURCE_FILE (current_function_decl);
-  if (xloc.file == NULL)
-    xloc.file = "<unknown file>";
+  file = xloc.file;
+  if (file == NULL && current_function_decl != NULL_TREE)
+    file = DECL_SOURCE_FILE (current_function_decl);
+  if (file == NULL)
+    file = "<unknown file>";
 
   if (xloc.line > 0)
     {
@@ -268,6 +268,13 @@ static GTY (()) tree mf_register_fndecl;
 /* extern void __mf_unregister (void *ptr, size_t sz, int type); */
 static GTY (()) tree mf_unregister_fndecl;
 
+/* extern void __mf_init (); */
+static GTY (()) tree mf_init_fndecl;
+
+/* extern int __mf_set_options (const char*); */
+static GTY (()) tree mf_set_options_fndecl;
+
+
 /* Helper for mudflap_init: construct a decl with the given category,
    name, and type, mark it an external reference, and pushdecl it.  */
 static inline tree
@@ -303,13 +310,17 @@ mf_make_mf_cache_struct_type (tree field_type)
   return struct_type;
 }
 
-#define build_function_type_3(rtype, arg1, arg2, arg3) \
- build_function_type (rtype, tree_cons (0, arg1, tree_cons (0, arg2, \
-                             tree_cons (0, arg3, void_list_node))))
-#define build_function_type_4(rtype, arg1, arg2, arg3, arg4) \
- build_function_type (rtype, tree_cons (0, arg1, tree_cons (0, arg2, \
-                             tree_cons (0, arg3, tree_cons (0, arg4, \
-                             void_list_node)))))
+#define build_function_type_0(rtype)            \
+  build_function_type (rtype, void_list_node)
+#define build_function_type_1(rtype, arg1)                 \
+  build_function_type (rtype, tree_cons (0, arg1, void_list_node))
+#define build_function_type_3(rtype, arg1, arg2, arg3)                  \
+  build_function_type (rtype, tree_cons (0, arg1, tree_cons (0, arg2,   \
+                                                             tree_cons (0, arg3, void_list_node))))
+#define build_function_type_4(rtype, arg1, arg2, arg3, arg4)            \
+  build_function_type (rtype, tree_cons (0, arg1, tree_cons (0, arg2,   \
+                                                             tree_cons (0, arg3, tree_cons (0, arg4, \
+                                                                                            void_list_node)))))
 
 /* Initialize the global tree nodes that correspond to mf-runtime.h
    declarations.  */
@@ -321,42 +332,54 @@ mudflap_init (void)
   tree mf_cache_array_type;
   tree mf_check_register_fntype;
   tree mf_unregister_fntype;
+  tree mf_init_fntype;
+  tree mf_set_options_fntype;
 
   if (done)
     return;
   done = true;
 
   mf_uintptr_type = lang_hooks.types.type_for_mode (ptr_mode,
-                                                   /*unsignedp=*/true);
+                                                    /*unsignedp=*/true);
   mf_const_string_type
     = build_pointer_type (build_qualified_type
-                         (char_type_node, TYPE_QUAL_CONST));
+                          (char_type_node, TYPE_QUAL_CONST));
 
   mf_cache_struct_type = mf_make_mf_cache_struct_type (mf_uintptr_type);
   mf_cache_structptr_type = build_pointer_type (mf_cache_struct_type);
   mf_cache_array_type = build_array_type (mf_cache_struct_type, 0);
   mf_check_register_fntype =
     build_function_type_4 (void_type_node, ptr_type_node, size_type_node,
-                          integer_type_node, mf_const_string_type);
+                           integer_type_node, mf_const_string_type);
   mf_unregister_fntype =
     build_function_type_3 (void_type_node, ptr_type_node, size_type_node,
-                          integer_type_node);
+                           integer_type_node);
+  mf_init_fntype =
+    build_function_type_0 (void_type_node);
+  mf_set_options_fntype =
+    build_function_type_1 (integer_type_node, mf_const_string_type);
 
   mf_cache_array_decl = mf_make_builtin (VAR_DECL, "__mf_lookup_cache",
-                                        mf_cache_array_type);
+                                         mf_cache_array_type);
   mf_cache_shift_decl = mf_make_builtin (VAR_DECL, "__mf_lc_shift",
-                                        unsigned_char_type_node);
+                                         unsigned_char_type_node);
   mf_cache_mask_decl = mf_make_builtin (VAR_DECL, "__mf_lc_mask",
-                                       mf_uintptr_type);
+                                        mf_uintptr_type);
   mf_check_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_check",
-                                    mf_check_register_fntype);
+                                     mf_check_register_fntype);
   mf_register_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_register",
-                                       mf_check_register_fntype);
+                                        mf_check_register_fntype);
   mf_unregister_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_unregister",
-                                         mf_unregister_fntype);
+                                          mf_unregister_fntype);
+  mf_init_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_init",
+                                    mf_init_fntype);
+  mf_set_options_fndecl = mf_make_builtin (FUNCTION_DECL, "__mf_set_options",
+                                           mf_set_options_fntype);
 }
 #undef build_function_type_4
 #undef build_function_type_3
+#undef build_function_type_1
+#undef build_function_type_0
 
 
 /* ------------------------------------------------------------------------ */
@@ -446,7 +469,7 @@ mf_decl_clear_locals (void)
 
 static void
 mf_build_check_statement_for (tree addr, tree size,
-                             block_stmt_iterator *instr_bsi,
+                              block_stmt_iterator *instr_bsi,
                               location_t *locus, tree dirflag)
 {
   tree_stmt_iterator head, tsi;
@@ -536,13 +559,13 @@ mf_build_check_statement_for (tree addr, tree size,
   /* Quick validity check.
 
      if (__mf_elem->low > __mf_base
-        || (__mf_elem_high < __mf_base + sizeof(T) - 1))
-       {
-         __mf_check ();
-         ... and only if single-threaded:
-         __mf_lookup_shift_1 = f...;
-         __mf_lookup_mask_l = ...;
-       }
+         || (__mf_elem_high < __mf_base + sizeof(T) - 1))
+        {
+          __mf_check ();
+          ... and only if single-threaded:
+          __mf_lookup_shift_1 = f...;
+          __mf_lookup_mask_l = ...;
+        }
 
      It is expected that this body of code is rarely executed so we mark
      the edge to the THEN clause of the conditional jump as unlikely.  */
@@ -556,8 +579,8 @@ mf_build_check_statement_for (tree addr, tree size,
   /* Construct '__mf_elem->high < __mf_base + sizeof(T) - 1'.
 
      First build:
-       1) u <--  '__mf_elem->high'
-       2) v <--  '__mf_base + sizeof (T) - 1'.
+        1) u <--  '__mf_elem->high'
+        2) v <--  '__mf_base + sizeof (T) - 1'.
 
      Then build 'u <-- (u < v).  */
 
@@ -567,7 +590,7 @@ mf_build_check_statement_for (tree addr, tree size,
              TREE_CHAIN (TYPE_FIELDS (mf_cache_struct_type)), NULL_TREE);
 
   v = convert (mf_uintptr_type,
-              size_binop (MINUS_EXPR, size, size_one_node));
+               size_binop (MINUS_EXPR, size, size_one_node));
   v = fold (build (PLUS_EXPR, mf_uintptr_type, mf_base, v));
 
   u = build (LT_EXPR, boolean_type_node, u, v);
@@ -584,8 +607,8 @@ mf_build_check_statement_for (tree addr, tree size,
   /* Build the conditional jump.  'cond' is just a temporary so we can
      simply build a void COND_EXPR.  We do need labels in both arms though.  */
   t = build (COND_EXPR, void_type_node, cond,
-            build (GOTO_EXPR, void_type_node, tree_block_label (then_bb)),
-            build (GOTO_EXPR, void_type_node, tree_block_label (join_bb)));
+             build (GOTO_EXPR, void_type_node, tree_block_label (then_bb)),
+             build (GOTO_EXPR, void_type_node, tree_block_label (join_bb)));
   SET_EXPR_LOCUS (t, locus);
   tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING);
 
@@ -593,7 +616,7 @@ mf_build_check_statement_for (tree addr, tree size,
      the conditional jump,
 
      if (__mf_elem->low > __mf_base
-        || (__mf_elem_high < __mf_base + sizeof(T) - 1))
+         || (__mf_elem_high < __mf_base + sizeof(T) - 1))
 
      The lowered GIMPLE tree representing this code is in the statement
      list starting at 'head'.
@@ -612,9 +635,9 @@ mf_build_check_statement_for (tree addr, tree size,
      This is the body of the conditional.  */
   
   u = tree_cons (NULL_TREE,
-                mf_file_function_line_tree (locus == NULL ? UNKNOWN_LOCATION
-                                            : *locus),
-                NULL_TREE);
+                 mf_file_function_line_tree (locus == NULL ? UNKNOWN_LOCATION
+                                             : *locus),
+                 NULL_TREE);
   u = tree_cons (NULL_TREE, dirflag, u);
   u = tree_cons (NULL_TREE, size, u);
   u = tree_cons (NULL_TREE, mf_value, u);
@@ -672,14 +695,14 @@ mf_xform_derefs_1 (block_stmt_iterator *iter, tree *tp,
           {
             tree dom = TYPE_DOMAIN (TREE_TYPE (op0));
 
-           /* Test for index in range.  Break if not.  */
-           if (!dom
-               || (! TYPE_MIN_VALUE (dom)
-                   || ! really_constant_p (TYPE_MIN_VALUE (dom)))
-               || (! TYPE_MAX_VALUE (dom)
-                   || ! really_constant_p (TYPE_MAX_VALUE (dom)))
-               || (tree_int_cst_lt (op1, TYPE_MIN_VALUE (dom))
-                   || tree_int_cst_lt (TYPE_MAX_VALUE (dom), op1)))
+            /* Test for index in range.  Break if not.  */
+            if (!dom
+                || (! TYPE_MIN_VALUE (dom)
+                    || ! really_constant_p (TYPE_MIN_VALUE (dom)))
+                || (! TYPE_MAX_VALUE (dom)
+                    || ! really_constant_p (TYPE_MAX_VALUE (dom)))
+                || (tree_int_cst_lt (op1, TYPE_MIN_VALUE (dom))
+                    || tree_int_cst_lt (TYPE_MAX_VALUE (dom), op1)))
               break;
 
             /* If we're looking at a non-external VAR_DECL, then the 
@@ -726,14 +749,14 @@ mf_xform_derefs_1 (block_stmt_iterator *iter, tree *tp,
            things the hard way with PLUS.  */
         if (DECL_BIT_FIELD_TYPE (field))
           {
-           if (TREE_CODE (DECL_SIZE_UNIT (field)) == INTEGER_CST)
-             size = DECL_SIZE_UNIT (field);
+            if (TREE_CODE (DECL_SIZE_UNIT (field)) == INTEGER_CST)
+              size = DECL_SIZE_UNIT (field);
 
             addr = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
             addr = fold_convert (ptr_type_node, addr);
             addr = fold (build (PLUS_EXPR, ptr_type_node,
                                 addr, fold_convert (ptr_type_node,
-                                                   byte_position (field))));
+                                                    byte_position (field))));
           }
         else
           {
@@ -787,35 +810,35 @@ mf_xform_derefs (void)
     {
       next = bb->next_bb;
       for (i = bsi_start (bb); !bsi_end_p (i); bsi_next (&i))
-       {
-         tree s = bsi_stmt (i);
-
-         /* Only a few GIMPLE statements can reference memory.  */
-         switch (TREE_CODE (s))
-           {
-           case MODIFY_EXPR:
-             mf_xform_derefs_1 (&i, &TREE_OPERAND (s, 0), EXPR_LOCUS (s),
-                                integer_one_node);
-             mf_xform_derefs_1 (&i, &TREE_OPERAND (s, 1), EXPR_LOCUS (s),
-                                integer_zero_node);
-             break;
-
-           case RETURN_EXPR:
-             if (TREE_OPERAND (s, 0) != NULL_TREE)
-               {
-                 if (TREE_CODE (TREE_OPERAND (s, 0)) == MODIFY_EXPR)
-                   mf_xform_derefs_1 (&i, &TREE_OPERAND (TREE_OPERAND (s, 0), 1),
-                                      EXPR_LOCUS (s), integer_zero_node);
-                 else
-                   mf_xform_derefs_1 (&i, &TREE_OPERAND (s, 0), EXPR_LOCUS (s),
-                                      integer_zero_node);
-               }
-             break;
-
-           default:
-             ;
-           }
-       }
+        {
+          tree s = bsi_stmt (i);
+
+          /* Only a few GIMPLE statements can reference memory.  */
+          switch (TREE_CODE (s))
+            {
+            case MODIFY_EXPR:
+              mf_xform_derefs_1 (&i, &TREE_OPERAND (s, 0), EXPR_LOCUS (s),
+                                 integer_one_node);
+              mf_xform_derefs_1 (&i, &TREE_OPERAND (s, 1), EXPR_LOCUS (s),
+                                 integer_zero_node);
+              break;
+
+            case RETURN_EXPR:
+              if (TREE_OPERAND (s, 0) != NULL_TREE)
+                {
+                  if (TREE_CODE (TREE_OPERAND (s, 0)) == MODIFY_EXPR)
+                    mf_xform_derefs_1 (&i, &TREE_OPERAND (TREE_OPERAND (s, 0), 1),
+                                       EXPR_LOCUS (s), integer_zero_node);
+                  else
+                    mf_xform_derefs_1 (&i, &TREE_OPERAND (s, 0), EXPR_LOCUS (s),
+                                       integer_zero_node);
+                }
+              break;
+
+            default:
+              ;
+            }
+        }
       bb = next;
     }
   while (bb && bb->index <= saved_last_basic_block);
@@ -866,87 +889,23 @@ mx_register_decls (tree decl, tree *stmt_list)
     {
       /* Eligible decl?  */
       if ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
-         /* It must be a non-external, automatic variable.  */
-         && ! DECL_EXTERNAL (decl)
-         && ! TREE_STATIC (decl)
-         /* The decl must have its address taken.  */
-         && TREE_ADDRESSABLE (decl)
-         /* The type of the variable must be complete.  */
-         && COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (decl))
-         /* Don't process the same decl twice.  */
-         && ! mf_marked_p (decl))
+          /* It must be a non-external, automatic variable.  */
+          && ! DECL_EXTERNAL (decl)
+          && ! TREE_STATIC (decl)
+          /* The decl must have its address taken.  */
+          && TREE_ADDRESSABLE (decl)
+          /* The type of the variable must be complete.  */
+          && COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (decl))
+         /* The decl hasn't been decomposed somehow.  */
+         && DECL_VALUE_EXPR (decl) == NULL
+          /* Don't process the same decl twice.  */
+          && ! mf_marked_p (decl))
         {
           tree size = NULL_TREE, variable_name;
           tree unregister_fncall, unregister_fncall_params;
           tree register_fncall, register_fncall_params;
 
-          if (DECL_DEFER_OUTPUT (decl))
-            {
-              /* Oh no ... it's probably a variable-length array (VLA).
-                 The size and address cannot be computed by merely
-                 looking at the DECL.  See gimplify_decl_stmt for the
-                 method by which VLA declarations turn into calls to
-                 BUILT_IN_STACK_ALLOC.  We assume that multiple
-                 VLAs declared later in the same block get allocation 
-                 code later than the others.  */
-              tree stack_alloc_call = NULL_TREE;
-
-              while(! tsi_end_p (initially_stmts))
-                {
-                  tree t = tsi_stmt (initially_stmts);
-
-                  tree call = NULL_TREE;
-                  if (TREE_CODE (t) == CALL_EXPR)
-                    call = t;
-                  else if (TREE_CODE (t) == MODIFY_EXPR &&
-                           TREE_CODE (TREE_OPERAND (t, 1)) == CALL_EXPR)
-                    call = TREE_OPERAND (t, 1);
-                  else if (TREE_CODE (t) == TRY_FINALLY_EXPR)
-                    {
-                      /* We hope that this is the try/finally block sometimes
-                        constructed by gimplify_bind_expr() for a BIND_EXPR
-                        that contains VLAs.  This very naive recursion
-                        appears to be sufficient.  */
-                      initially_stmts = tsi_start (TREE_OPERAND (t, 0));
-                    }
-
-                  if (call != NULL_TREE)
-                    {
-                      if (TREE_CODE (TREE_OPERAND(call, 0)) == ADDR_EXPR &&
-                          TREE_OPERAND (TREE_OPERAND (call, 0), 0) ==
-                               implicit_built_in_decls [BUILT_IN_STACK_ALLOC])
-                        {
-                          tree stack_alloc_args = TREE_OPERAND (call, 1);
-                          tree stack_alloc_op1 = TREE_VALUE (stack_alloc_args);
-                          tree stack_alloc_op2 = TREE_VALUE (TREE_CHAIN (stack_alloc_args));
-                          
-                          if (TREE_CODE (stack_alloc_op1) == ADDR_EXPR &&
-                              TREE_OPERAND (stack_alloc_op1, 0) == decl)
-                            {
-                              /* Got it! */
-                              size = stack_alloc_op2;
-                              stack_alloc_call = call;
-                              /* Advance iterator to point past this allocation call.  */
-                              tsi_next (&initially_stmts);
-                              break;
-                            }
-                        }
-                    }
-
-                  tsi_next (&initially_stmts);
-                }
-
-              if (stack_alloc_call == NULL_TREE)
-                {
-                  warning ("mudflap cannot handle variable-sized declaration `%s'",
-                         IDENTIFIER_POINTER (DECL_NAME (decl)));
-                  break;
-                }
-            }
-          else
-            {
-              size = convert (size_type_node, TYPE_SIZE_UNIT (TREE_TYPE (decl)));
-            }
+         size = convert (size_type_node, TYPE_SIZE_UNIT (TREE_TYPE (decl)));
 
           /* (& VARIABLE, sizeof (VARIABLE), __MF_TYPE_STACK) */
           unregister_fncall_params =
@@ -957,8 +916,9 @@ mx_register_decls (tree decl, tree *stmt_list)
                                                  decl))),
                        tree_cons (NULL_TREE, 
                                   size,
-                                  tree_cons (NULL_TREE, 
-                                             build_int_2 (3, 0), /* __MF_TYPE_STACK */
+                                  tree_cons (NULL_TREE,
+                                            /* __MF_TYPE_STACK */
+                                             build_int_cst (NULL_TREE, 3),
                                              NULL_TREE)));
           /* __mf_unregister (...) */
           unregister_fncall = build_function_call_expr (mf_unregister_fndecl,
@@ -975,7 +935,8 @@ mx_register_decls (tree decl, tree *stmt_list)
                        tree_cons (NULL_TREE,
                                   size,
                                   tree_cons (NULL_TREE,
-                                             build_int_2 (3, 0), /* __MF_TYPE_STACK */
+                                            /* __MF_TYPE_STACK */
+                                             build_int_cst (NULL_TREE, 3),
                                              tree_cons (NULL_TREE,
                                                         variable_name,
                                                         NULL_TREE))));
@@ -1118,7 +1079,7 @@ mudflap_register_call (tree obj, tree object_size, tree varname)
 
   args = tree_cons (NULL_TREE, varname, NULL_TREE);
 
-  arg = build_int_2 (4, 0); /* __MF_TYPE_STATIC */
+  arg = build_int_cst (NULL_TREE, 4); /* __MF_TYPE_STATIC */
   args = tree_cons (NULL_TREE, arg, args);
 
   arg = convert (size_type_node, object_size);
@@ -1200,7 +1161,7 @@ mudflap_enqueue_constant (tree obj)
     return;
 
   if (TREE_CODE (obj) == STRING_CST)
-    object_size = build_int_2 (TREE_STRING_LENGTH (obj), 0);
+    object_size = build_int_cst (NULL_TREE, TREE_STRING_LENGTH (obj));
   else
     object_size = size_in_bytes (TREE_TYPE (obj));
 
@@ -1226,6 +1187,8 @@ mudflap_enqueue_constant (tree obj)
 void
 mudflap_finish_file (void)
 {
+  tree ctor_statements = NULL_TREE;
+
   /* Try to give the deferred objects one final try.  */
   if (deferred_static_decls)
     {
@@ -1244,11 +1207,30 @@ mudflap_finish_file (void)
       VARRAY_CLEAR (deferred_static_decls);
     }
 
+  /* Insert a call to __mf_init.  */
+  {
+    tree call2_stmt = build_function_call_expr (mf_init_fndecl, NULL_TREE);
+    append_to_statement_list (call2_stmt, &ctor_statements);
+  }
+  
+  /* If appropriate, call __mf_set_options to pass along read-ignore mode.  */
+  if (flag_mudflap_ignore_reads)
+    {
+      tree arg = tree_cons (NULL_TREE, 
+                            mf_build_string ("-ignore-reads"), NULL_TREE);
+      tree call_stmt = build_function_call_expr (mf_set_options_fndecl, arg);
+      append_to_statement_list (call_stmt, &ctor_statements);
+    }
+
+  /* Append all the enqueued registration calls.  */
   if (enqueued_call_stmt_chain)
     {
-      cgraph_build_static_cdtor ('I', enqueued_call_stmt_chain);
-      enqueued_call_stmt_chain = 0;
+      append_to_statement_list (enqueued_call_stmt_chain, &ctor_statements);
+      enqueued_call_stmt_chain = NULL_TREE;
     }
+
+  cgraph_build_static_cdtor ('I', ctor_statements, 
+                             MAX_RESERVED_INIT_PRIORITY-1);
 }