This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFH] Restrict support for trees


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

double foo(double * __restrict__ x, double * __restrict__ y)
{
  double res;
  res = *y + *(y+1);
  res += *x + *(x+1);
  return res;
}

we generate the constraints (ok)

RESTRICT.4 = &ANYTHING
x = &RESTRICT.4
RESTRICT.5 = &ANYTHING
y = &RESTRICT.5
D.1282_3 = y + 64
D.1285_8 = x + 64

just like we do for the malloc case, but end up with an extra
TMT that causes

Variable: x, UID 1276, double * restrict, type memory tag: TMT.6, default 
def: x_6

Variable: y, UID 1277, double * restrict, type memory tag: TMT.6, default 
def: y_1

Variable: TMT.6, UID 1309, double, is addressable, is global, call 
clobbered, may aliases: { RESTRICT.5 RESTRICT.4 }

and thus

<bb 0>:
  #   VUSE <RESTRICT.4_14>;
  #   VUSE <RESTRICT.5_15>;
  D.1281_2 = *y_1;
  D.1282_3 = y_1 + 8B;
  #   VUSE <RESTRICT.5_15>;
  D.1283_4 = *D.1282_3;
  res_5 = D.1281_2 + D.1283_4;
  #   VUSE <RESTRICT.4_14>;
  #   VUSE <RESTRICT.5_15>;
  D.1284_7 = *x_6;
  D.1285_8 = x_6 + 8B;
  #   VUSE <RESTRICT.4_14>;
  D.1286_9 = *D.1285_8;
  D.1287_10 = D.1284_7 + D.1286_9;
  res_11 = res_5 + D.1287_10;
  D.1288_12 = res_11;
  return D.1288_12;

note how only the offsetted pointer is disambiguated by restrict,
while *x and *y seem to alias because of the TMT?

Any suggestion on why this happens?

Thanks,
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
--- 4045,4079 ----
        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);
+ 	  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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]