On Tue, 29 Nov 2005, Daniel Berlin wrote:

> On Tue, 2005-11-29 at 22:08 +0100, Richard Guenther wrote:
> > The patch below teaches points-to analysis about restrict qualifiers
> > of incoming parameters.  It is modeled after the special handling
> > of malloc result type pointers, namely creating fake variables we
> > point to and thus trigger creation of NMTs.  Unfortunately it doesn't
> > exactly work, as for the testcase

The following seems to work.  Semantics are not exactly C, but maybe
good enough for fortran.  Basically, restrict parameters are treated
like pointers returned from malloc.

Richard.


Index: tree-ssa-structalias.c
===================================================================
*** tree-ssa-structalias.c      (revision 107545)
--- tree-ssa-structalias.c      (working copy)
*************** intra_create_variable_infos (void)
*** 3975,3985 ****
        lhs.offset = 0;
        lhs.type = SCALAR;
        lhs.var  = create_variable_info_for (t, alias_get_name (t));
-       
-       for (p = get_varinfo (lhs.var); p; p = p->next)
-       make_constraint_to_anything (p);
-     } 
  
  }
  
  /* Set bits in INTO corresponding to the variable uids in solution set
--- 4046,4082 ----
        lhs.offset = 0;
        lhs.type = SCALAR;
        lhs.var  = create_variable_info_for (t, alias_get_name (t));
  
+       if (POINTER_TYPE_P (TREE_TYPE (t))
+         && TYPE_RESTRICT (TREE_TYPE (t)))
+       {
+         varinfo_t vi;
+         struct constraint_expr rhs;
+         tree heapvar = create_tmp_var_raw (ptr_type_node, "RESTRICT");
+         unsigned int id;
+         DECL_EXTERNAL (heapvar) = 1;
+         add_referenced_tmp_var (heapvar);
+         mark_sym_for_renaming (heapvar);
+         heapvar_insert (t, heapvar);
+         id = create_variable_info_for (heapvar,
+                                        alias_get_name (heapvar));
+         vi = get_varinfo (id);
+         vi->is_artificial_var = 1;
+         vi->is_heap_var = 1;
+         rhs.var = id;
+         rhs.type = ADDRESSOF;
+         rhs.offset = 0;
+           for (p = get_varinfo (lhs.var); p; p = p->next)
+           {
+             struct constraint_expr temp = lhs;
+             temp.var = p->id;
+             process_constraint (new_constraint (temp, rhs));
+           }
+       }
+       else      
+       for (p = get_varinfo (lhs.var); p; p = p->next)
+         make_constraint_to_anything (p);
+     } 
  }
  
  /* Set bits in INTO corresponding to the variable uids in solution set
*************** bool
*** 4039,4049 ****
  find_what_p_points_to (tree p)
  {
    unsigned int id = 0;
  
    if (!have_alias_info)
      return false;
  
!   if (lookup_id_for_tree (p, &id))
      {
        varinfo_t vi = get_varinfo (id);
        
--- 4136,4154 ----
  find_what_p_points_to (tree p)
  {
    unsigned int id = 0;
+   tree lookup_p = p;
  
    if (!have_alias_info)
      return false;
  
!   /* For parameters, get at the points-to set for the actual parm
!      decl.  */
!   if (TREE_CODE (p) == SSA_NAME 
!       && TREE_CODE (SSA_NAME_VAR (p)) == PARM_DECL 
!       && default_def (SSA_NAME_VAR (p)) == p)
!     lookup_p = SSA_NAME_VAR (p);
! 
!   if (lookup_id_for_tree (lookup_p, &id))
      {
        varinfo_t vi = get_varinfo (id);
        

Reply via email to