Re: Correct way to access predecessors of a gimple statement?

2013-05-05 Thread Sudakshina Das
Hello Kartik

You can use the iterator FOR_EACH_EDGE in this form:

FOR_EACH_EDGE (e, ei, bb->preds)

where e is an edge ei is edge iterator bb is a basic block.
I hope that gave you what you were looking for.

Sudakshina Das



On Sun, May 5, 2013 at 10:05 AM, Kartik Singhal  wrote:
>
> Hi
>
> I am trying to implement a GVN algorithm as a plugin for GCC 4.6.
>
> With help from GCC IRC channel, internals doc and reading the source,
> I was able to get a prototype working for the case of a single block.
>
> Now, I am trying to handle the case of confluence of multiple edges
> i.e. obtain redundancy information from multiple paths at a merge
> point. I am stuck trying to figure out how to access all the immediate
> predecessors of a statement. I have looked into CFG chapter of
> internals doc (block and edge), though edge data structure seems to
> give a hint, I couldn't clearly find out how to leverage it for my
> purpose. Any hints or code example would be a great help.
>
> If it is of any help, the algorithm is at [1] and my code at [2]
> (*very* naive and not considering performance at all in the first
> implementation attempt).
>
> [1]: http://arxiv.org/abs/1303.1880
> [2]: https://github.com/k4rtik/btp-gvn/blob/master/gvn-plugin/plugin.c
>
> Thanks
> --
> Kartik
> http://k4rtik.wordpress.com/


A pass that worked in gcc-4.6.2 fails in gcc-4.7.2

2013-01-23 Thread Sudakshina Das
Dear all,

I am currently updating a pass that was made for gcc-4.6.*, so that it
works for gcc.4.7.2.

In the pass for gcc-4.6.*, a code fragment from tree-ssa-structalias.c
was picked up and used.
Given below is the fragment taken form create_function_info_for () .
This fragment was used to create variable information for the function
and it was picked up to perform a similar operation in the added pass
as well.

But in gcc-4.7.2 some changes are introduced in the fragment. The code
given below shows the changes that have been introduced in
create_function_info_for () of tree-ssa-structalias.c in gcc-4.7.2
along with the original code in the comments.

  /* Add one representative for all further args.  */
  if (is_varargs)
{
  varinfo_t argvi;
  const char *newname;
  char *tempname;
  tree decl;

  asprintf (&tempname, "%s.varargs", name);
  newname = ggc_strdup (tempname);
  free (tempname);

  /* We need sth that can be pointed to for va_start.  */

/ CHANGED CODE in GCC-4.7.2 ***/
  decl = build_fake_var_decl (ptr_type_node);

/ ORIGINAL CODE in GCC-4.6.2 ***
/*  decl = create_tmp_var_raw (ptr_type_node, name);
get_var_ann (decl);
*/

  argvi = new_var_info (decl, newname);
  argvi->offset = fi_parm_base + num_args;
  argvi->size = ~0;
  argvi->is_full_var = true;
  argvi->is_heap_var = true;
  argvi->fullsize = vi->fullsize;
  gcc_assert (prev_vi->offset < argvi->offset);
  prev_vi->next = argvi;
  prev_vi = argvi;
}

  return vi;


So I made the same changes in the pass where this fragment was used.
But after making the changes the pass is now giving an "internal
compiler error" and a "segmentation fault" at runtime.

After debugging I could narrow it down to the function
build_fake_var_decl() and to be specific at the memory allocation
statement highlighted below.


tree
build_fake_var_decl (tree type)
{
/ My debugging showed that the control came
here */
  tree decl = (tree) XOBNEW (&fake_var_decl_obstack, struct tree_var_decl);
/ But did not come here
**/
  memset (decl, 0, sizeof (struct tree_var_decl));
  TREE_SET_CODE (decl, VAR_DECL);
  TREE_TYPE (decl) = type;
  DECL_UID (decl) = allocate_decl_uid ();
  SET_DECL_PT_UID (decl, -1);
  layout_decl (decl, 0);
  return decl;
}

The builf_fake_var_decl() function is a gcc function defined in
tree-ssa-structalias.c. To be able to use it in my pass, I removed the
keyword static in its definition.

I cannot figure out what can possibly cause this error in the XOBNEW function.

Please help!!!

Sudakshina Das


Re: A pass that worked in gcc-4.6.2 fails in gcc-4.7.2

2013-01-24 Thread Sudakshina Das
On Thu, Jan 24, 2013 at 5:15 PM, Richard Biener
 wrote:
>
> On Thu, Jan 24, 2013 at 7:06 AM, Sudakshina Das
>  wrote:
> > Dear all,
> >
> > I am currently updating a pass that was made for gcc-4.6.*, so that it
> > works for gcc.4.7.2.
> >
> > In the pass for gcc-4.6.*, a code fragment from tree-ssa-structalias.c
> > was picked up and used.
> > Given below is the fragment taken form create_function_info_for () .
> > This fragment was used to create variable information for the function
> > and it was picked up to perform a similar operation in the added pass
> > as well.
> >
> > But in gcc-4.7.2 some changes are introduced in the fragment. The code
> > given below shows the changes that have been introduced in
> > create_function_info_for () of tree-ssa-structalias.c in gcc-4.7.2
> > along with the original code in the comments.
> >
> >   /* Add one representative for all further args.  */
> >   if (is_varargs)
> > {
> >   varinfo_t argvi;
> >   const char *newname;
> >   char *tempname;
> >   tree decl;
> >
> >   asprintf (&tempname, "%s.varargs", name);
> >   newname = ggc_strdup (tempname);
> >   free (tempname);
> >
> >   /* We need sth that can be pointed to for va_start.  */
> >
> > / CHANGED CODE in GCC-4.7.2 ***/
> >   decl = build_fake_var_decl (ptr_type_node);
> >
> > / ORIGINAL CODE in GCC-4.6.2 ***
> > /*  decl = create_tmp_var_raw (ptr_type_node, name);
> > get_var_ann (decl);
> > */
> >
> >   argvi = new_var_info (decl, newname);
> >   argvi->offset = fi_parm_base + num_args;
> >   argvi->size = ~0;
> >   argvi->is_full_var = true;
> >   argvi->is_heap_var = true;
> >   argvi->fullsize = vi->fullsize;
> >   gcc_assert (prev_vi->offset < argvi->offset);
> >   prev_vi->next = argvi;
> >   prev_vi = argvi;
> > }
> >
> >   return vi;
> >
> >
> > So I made the same changes in the pass where this fragment was used.
> > But after making the changes the pass is now giving an "internal
> > compiler error" and a "segmentation fault" at runtime.
> >
> > After debugging I could narrow it down to the function
> > build_fake_var_decl() and to be specific at the memory allocation
> > statement highlighted below.
> >
> >
> > tree
> > build_fake_var_decl (tree type)
> > {
> > / My debugging showed that the control came
> > here */
> >   tree decl = (tree) XOBNEW (&fake_var_decl_obstack, struct tree_var_decl);
> > / But did not come here
> > **/
> >   memset (decl, 0, sizeof (struct tree_var_decl));
> >   TREE_SET_CODE (decl, VAR_DECL);
> >   TREE_TYPE (decl) = type;
> >   DECL_UID (decl) = allocate_decl_uid ();
> >   SET_DECL_PT_UID (decl, -1);
> >   layout_decl (decl, 0);
> >   return decl;
> > }
> >
> > The builf_fake_var_decl() function is a gcc function defined in
> > tree-ssa-structalias.c. To be able to use it in my pass, I removed the
> > keyword static in its definition.
> >
> > I cannot figure out what can possibly cause this error in the XOBNEW 
> > function.
> >
> > Please help!!!
>
> Don't use build_fake_var_decl, use what 4.6 did, create_tmp_var_raw.
>
> Richard.
>
>

But 4.6 used get_var_ann() also along with create_tmp_var_raw()  which
has been removed from 4.7.

> > Sudakshina Das


Re: A pass that worked in gcc-4.6.2 fails in gcc-4.7.2

2013-01-25 Thread Sudakshina Das
On Fri, Jan 25, 2013 at 9:46 AM, Sudakshina Das
 wrote:
>
> On Thu, Jan 24, 2013 at 5:15 PM, Richard Biener
>  wrote:
> >
> > On Thu, Jan 24, 2013 at 7:06 AM, Sudakshina Das
> >  wrote:
> > > Dear all,
> > >
> > > I am currently updating a pass that was made for gcc-4.6.*, so that it
> > > works for gcc.4.7.2.
> > >
> > > In the pass for gcc-4.6.*, a code fragment from tree-ssa-structalias.c
> > > was picked up and used.
> > > Given below is the fragment taken form create_function_info_for () .
> > > This fragment was used to create variable information for the function
> > > and it was picked up to perform a similar operation in the added pass
> > > as well.
> > >
> > > But in gcc-4.7.2 some changes are introduced in the fragment. The code
> > > given below shows the changes that have been introduced in
> > > create_function_info_for () of tree-ssa-structalias.c in gcc-4.7.2
> > > along with the original code in the comments.
> > >
> > >   /* Add one representative for all further args.  */
> > >   if (is_varargs)
> > > {
> > >   varinfo_t argvi;
> > >   const char *newname;
> > >   char *tempname;
> > >   tree decl;
> > >
> > >   asprintf (&tempname, "%s.varargs", name);
> > >   newname = ggc_strdup (tempname);
> > >   free (tempname);
> > >
> > >   /* We need sth that can be pointed to for va_start.  */
> > >
> > > / CHANGED CODE in GCC-4.7.2 ***/
> > >   decl = build_fake_var_decl (ptr_type_node);
> > >
> > > / ORIGINAL CODE in GCC-4.6.2 ***
> > > /*  decl = create_tmp_var_raw (ptr_type_node, name);
> > > get_var_ann (decl);
> > > */
> > >
> > >   argvi = new_var_info (decl, newname);
> > >   argvi->offset = fi_parm_base + num_args;
> > >   argvi->size = ~0;
> > >   argvi->is_full_var = true;
> > >   argvi->is_heap_var = true;
> > >   argvi->fullsize = vi->fullsize;
> > >   gcc_assert (prev_vi->offset < argvi->offset);
> > >   prev_vi->next = argvi;
> > >   prev_vi = argvi;
> > > }
> > >
> > >   return vi;
> > >
> > >
> > > So I made the same changes in the pass where this fragment was used.
> > > But after making the changes the pass is now giving an "internal
> > > compiler error" and a "segmentation fault" at runtime.
> > >
> > > After debugging I could narrow it down to the function
> > > build_fake_var_decl() and to be specific at the memory allocation
> > > statement highlighted below.
> > >
> > >
> > > tree
> > > build_fake_var_decl (tree type)
> > > {
> > > / My debugging showed that the control came
> > > here */
> > >   tree decl = (tree) XOBNEW (&fake_var_decl_obstack, struct 
> > > tree_var_decl);
> > > / But did not come here
> > > **/
> > >   memset (decl, 0, sizeof (struct tree_var_decl));
> > >   TREE_SET_CODE (decl, VAR_DECL);
> > >   TREE_TYPE (decl) = type;
> > >   DECL_UID (decl) = allocate_decl_uid ();
> > >   SET_DECL_PT_UID (decl, -1);
> > >   layout_decl (decl, 0);
> > >   return decl;
> > > }
> > >
> > > The builf_fake_var_decl() function is a gcc function defined in
> > > tree-ssa-structalias.c. To be able to use it in my pass, I removed the
> > > keyword static in its definition.
> > >
> > > I cannot figure out what can possibly cause this error in the XOBNEW 
> > > function.
> > >
> > > Please help!!!
> >
> > Don't use build_fake_var_decl, use what 4.6 did, create_tmp_var_raw.
> >
> > Richard.
> >
> >
>
> But 4.6 used get_var_ann() also along with create_tmp_var_raw()  which
> has been removed from 4.7.


I would like to clarify my above statement by saying that 4.6 used 2
functions [ie. create_tmp_var_raw() and get_var_ann()] whereas 4.7
used only one function [build_fake_var_decl()] for the same purpose.
Now in 4.7 get_var_ann() is unavailable. So is it safe to use only
create_tmp_var_raw(). In other words, was get_var_ann() a redundant
function in 4.6?


>
> > > Sudakshina Das


Re: A pass that worked in gcc-4.6.2 fails in gcc-4.7.2

2013-01-25 Thread Sudakshina Das
On Fri, Jan 25, 2013 at 8:02 PM, Richard Biener
 wrote:
> On Fri, Jan 25, 2013 at 3:05 PM, Sudakshina Das
>  wrote:
>> On Fri, Jan 25, 2013 at 9:46 AM, Sudakshina Das
>>  wrote:
>>>
>>> On Thu, Jan 24, 2013 at 5:15 PM, Richard Biener
>>>  wrote:
>>> >
>>> > On Thu, Jan 24, 2013 at 7:06 AM, Sudakshina Das
>>> >  wrote:
>>> > > Dear all,
>>> > >
>>> > > I am currently updating a pass that was made for gcc-4.6.*, so that it
>>> > > works for gcc.4.7.2.
>>> > >
>>> > > In the pass for gcc-4.6.*, a code fragment from tree-ssa-structalias.c
>>> > > was picked up and used.
>>> > > Given below is the fragment taken form create_function_info_for () .
>>> > > This fragment was used to create variable information for the function
>>> > > and it was picked up to perform a similar operation in the added pass
>>> > > as well.
>>> > >
>>> > > But in gcc-4.7.2 some changes are introduced in the fragment. The code
>>> > > given below shows the changes that have been introduced in
>>> > > create_function_info_for () of tree-ssa-structalias.c in gcc-4.7.2
>>> > > along with the original code in the comments.
>>> > >
>>> > >   /* Add one representative for all further args.  */
>>> > >   if (is_varargs)
>>> > > {
>>> > >   varinfo_t argvi;
>>> > >   const char *newname;
>>> > >   char *tempname;
>>> > >   tree decl;
>>> > >
>>> > >   asprintf (&tempname, "%s.varargs", name);
>>> > >   newname = ggc_strdup (tempname);
>>> > >   free (tempname);
>>> > >
>>> > >   /* We need sth that can be pointed to for va_start.  */
>>> > >
>>> > > / CHANGED CODE in GCC-4.7.2 ***/
>>> > >   decl = build_fake_var_decl (ptr_type_node);
>>> > >
>>> > > / ORIGINAL CODE in GCC-4.6.2 ***
>>> > > /*  decl = create_tmp_var_raw (ptr_type_node, name);
>>> > > get_var_ann (decl);
>>> > > */
>>> > >
>>> > >   argvi = new_var_info (decl, newname);
>>> > >   argvi->offset = fi_parm_base + num_args;
>>> > >   argvi->size = ~0;
>>> > >   argvi->is_full_var = true;
>>> > >   argvi->is_heap_var = true;
>>> > >   argvi->fullsize = vi->fullsize;
>>> > >   gcc_assert (prev_vi->offset < argvi->offset);
>>> > >   prev_vi->next = argvi;
>>> > >   prev_vi = argvi;
>>> > > }
>>> > >
>>> > >   return vi;
>>> > >
>>> > >
>>> > > So I made the same changes in the pass where this fragment was used.
>>> > > But after making the changes the pass is now giving an "internal
>>> > > compiler error" and a "segmentation fault" at runtime.
>>> > >
>>> > > After debugging I could narrow it down to the function
>>> > > build_fake_var_decl() and to be specific at the memory allocation
>>> > > statement highlighted below.
>>> > >
>>> > >
>>> > > tree
>>> > > build_fake_var_decl (tree type)
>>> > > {
>>> > > / My debugging showed that the control came
>>> > > here */
>>> > >   tree decl = (tree) XOBNEW (&fake_var_decl_obstack, struct 
>>> > > tree_var_decl);
>>> > > / But did not come here
>>> > > **/
>>> > >   memset (decl, 0, sizeof (struct tree_var_decl));
>>> > >   TREE_SET_CODE (decl, VAR_DECL);
>>> > >   TREE_TYPE (decl) = type;
>>> > >   DECL_UID (decl) = allocate_decl_uid ();
>>> > >   SET_DECL_PT_UID (decl, -1);
>>> > >   layout_decl (decl, 0);
>>> > >   return decl;
>>> > > }
>>> > >
>>> > > The builf_fake_var_decl() function is a gcc function defined in
>>> > > tree-ssa-structalias.c. To be able to use it in my pass, I removed the
>>> &g

Re: A pass that worked in gcc-4.6.2 fails in gcc-4.7.2

2013-01-25 Thread Sudakshina Das
On Fri, Jan 25, 2013 at 9:27 PM, Richard Biener
 wrote:
> On Fri, Jan 25, 2013 at 3:57 PM, Sudakshina Das
>  wrote:
>> On Fri, Jan 25, 2013 at 8:02 PM, Richard Biener
>>  wrote:
>>> On Fri, Jan 25, 2013 at 3:05 PM, Sudakshina Das
>>>  wrote:
>>>> On Fri, Jan 25, 2013 at 9:46 AM, Sudakshina Das
>>>>  wrote:
>>>>>
>>>>> On Thu, Jan 24, 2013 at 5:15 PM, Richard Biener
>>>>>  wrote:
>>>>> >
>>>>> > On Thu, Jan 24, 2013 at 7:06 AM, Sudakshina Das
>>>>> >  wrote:
>>>>> > > Dear all,
>>>>> > >
>>>>> > > I am currently updating a pass that was made for gcc-4.6.*, so that it
>>>>> > > works for gcc.4.7.2.
>>>>> > >
>>>>> > > In the pass for gcc-4.6.*, a code fragment from tree-ssa-structalias.c
>>>>> > > was picked up and used.
>>>>> > > Given below is the fragment taken form create_function_info_for () .
>>>>> > > This fragment was used to create variable information for the function
>>>>> > > and it was picked up to perform a similar operation in the added pass
>>>>> > > as well.
>>>>> > >
>>>>> > > But in gcc-4.7.2 some changes are introduced in the fragment. The code
>>>>> > > given below shows the changes that have been introduced in
>>>>> > > create_function_info_for () of tree-ssa-structalias.c in gcc-4.7.2
>>>>> > > along with the original code in the comments.
>>>>> > >
>>>>> > >   /* Add one representative for all further args.  */
>>>>> > >   if (is_varargs)
>>>>> > > {
>>>>> > >   varinfo_t argvi;
>>>>> > >   const char *newname;
>>>>> > >   char *tempname;
>>>>> > >   tree decl;
>>>>> > >
>>>>> > >   asprintf (&tempname, "%s.varargs", name);
>>>>> > >   newname = ggc_strdup (tempname);
>>>>> > >   free (tempname);
>>>>> > >
>>>>> > >   /* We need sth that can be pointed to for va_start.  */
>>>>> > >
>>>>> > > / CHANGED CODE in GCC-4.7.2 ***/
>>>>> > >   decl = build_fake_var_decl (ptr_type_node);
>>>>> > >
>>>>> > > / ORIGINAL CODE in GCC-4.6.2 ***
>>>>> > > /*  decl = create_tmp_var_raw (ptr_type_node, name);
>>>>> > > get_var_ann (decl);
>>>>> > > */
>>>>> > >
>>>>> > >   argvi = new_var_info (decl, newname);
>>>>> > >   argvi->offset = fi_parm_base + num_args;
>>>>> > >   argvi->size = ~0;
>>>>> > >   argvi->is_full_var = true;
>>>>> > >   argvi->is_heap_var = true;
>>>>> > >   argvi->fullsize = vi->fullsize;
>>>>> > >   gcc_assert (prev_vi->offset < argvi->offset);
>>>>> > >   prev_vi->next = argvi;
>>>>> > >   prev_vi = argvi;
>>>>> > > }
>>>>> > >
>>>>> > >   return vi;
>>>>> > >
>>>>> > >
>>>>> > > So I made the same changes in the pass where this fragment was used.
>>>>> > > But after making the changes the pass is now giving an "internal
>>>>> > > compiler error" and a "segmentation fault" at runtime.
>>>>> > >
>>>>> > > After debugging I could narrow it down to the function
>>>>> > > build_fake_var_decl() and to be specific at the memory allocation
>>>>> > > statement highlighted below.
>>>>> > >
>>>>> > >
>>>>> > > tree
>>>>> > > build_fake_var_decl (tree type)
>>>>> > > {
>>>>> > > / My debugging showed that the control came
>>>>> > > here */
>>>>> > >   tree decl = (tree) XOBNEW (&fake_var_decl_obstack, struct 
>>>>> > > tree_var_decl);
>>>>

Re: A pass that worked in gcc-4.6.2 fails in gcc-4.7.2

2013-02-02 Thread Sudakshina Das
Hello,

Now I am trying to convert the same pass into a dynamic plugin. Since
I was having trouble doing so, I tried adding a simple dynamic plugin
which would just dump the cfg using gimple_dump_cfg. But even in this
simple plugin I faced the same problem, as explained below.

When I build my plugin using ../install/bin/g++ it would not give any
errors. But when I used gcc instead of g++, it gave the following
error during runtime :

cc1: error: cannot load plugin ./plugin.so
./plugin.so: undefined symbol: decl_assembler_name
make: *** [test] Error 1

However, this symbol decl_assembler_name (a function) and is not
present anywhere in my plugin. It is declared in tree.c so and is not
static, so I even tried including tree.h and declaring the function as
extern.

I don't know what else to do!!

Sudakshina




On Sat, Jan 26, 2013 at 1:16 AM, Sudakshina Das
 wrote:
>
> On Fri, Jan 25, 2013 at 9:27 PM, Richard Biener
>  wrote:
> > On Fri, Jan 25, 2013 at 3:57 PM, Sudakshina Das
> >  wrote:
> >> On Fri, Jan 25, 2013 at 8:02 PM, Richard Biener
> >>  wrote:
> >>> On Fri, Jan 25, 2013 at 3:05 PM, Sudakshina Das
> >>>  wrote:
> >>>> On Fri, Jan 25, 2013 at 9:46 AM, Sudakshina Das
> >>>>  wrote:
> >>>>>
> >>>>> On Thu, Jan 24, 2013 at 5:15 PM, Richard Biener
> >>>>>  wrote:
> >>>>> >
> >>>>> > On Thu, Jan 24, 2013 at 7:06 AM, Sudakshina Das
> >>>>> >  wrote:
> >>>>> > > Dear all,
> >>>>> > >
> >>>>> > > I am currently updating a pass that was made for gcc-4.6.*, so
> >>>>> > > that it
> >>>>> > > works for gcc.4.7.2.
> >>>>> > >
> >>>>> > > In the pass for gcc-4.6.*, a code fragment from
> >>>>> > > tree-ssa-structalias.c
> >>>>> > > was picked up and used.
> >>>>> > > Given below is the fragment taken form create_function_info_for
> >>>>> > > () .
> >>>>> > > This fragment was used to create variable information for the
> >>>>> > > function
> >>>>> > > and it was picked up to perform a similar operation in the added
> >>>>> > > pass
> >>>>> > > as well.
> >>>>> > >
> >>>>> > > But in gcc-4.7.2 some changes are introduced in the fragment.
> >>>>> > > The code
> >>>>> > > given below shows the changes that have been introduced in
> >>>>> > > create_function_info_for () of tree-ssa-structalias.c in
> >>>>> > > gcc-4.7.2
> >>>>> > > along with the original code in the comments.
> >>>>> > >
> >>>>> > >   /* Add one representative for all further args.  */
> >>>>> > >   if (is_varargs)
> >>>>> > > {
> >>>>> > >   varinfo_t argvi;
> >>>>> > >   const char *newname;
> >>>>> > >   char *tempname;
> >>>>> > >   tree decl;
> >>>>> > >
> >>>>> > >   asprintf (&tempname, "%s.varargs", name);
> >>>>> > >   newname = ggc_strdup (tempname);
> >>>>> > >   free (tempname);
> >>>>> > >
> >>>>> > >   /* We need sth that can be pointed to for va_start.  */
> >>>>> > >
> >>>>> > > / CHANGED CODE in GCC-4.7.2 ***/
> >>>>> > >   decl = build_fake_var_decl (ptr_type_node);
> >>>>> > >
> >>>>> > > / ORIGINAL CODE in GCC-4.6.2 ***
> >>>>> > > /*  decl = create_tmp_var_raw (ptr_type_node, name);
> >>>>> > > get_var_ann (decl);
> >>>>> > > */
> >>>>> > >
> >>>>> > >   argvi = new_var_info (decl, newname);
> >>>>> > >   argvi->offset = fi_parm_base + num_args;
> >>>>> > >   argvi->size = ~0;
> >>>>> > >   argvi->is_full_var = true;
> >>>>> > >   argvi->is_heap_var = true;
> >>>>> > >   argvi->fullsize = vi->fullsize;
> >>>>&g