[PATCH] print_rtx: implement support for reuse IDs

Bernd Schmidt bschmidt@redhat.com
Tue Oct 25 12:47:00 GMT 2016


On 10/21/2016 10:27 PM, David Malcolm wrote:
> Thanks.  I attemped to use those fields of recog_data, but it doesn't
> seem to be exactly what's needed here.

Yeah, I may have been confused. I'm not sure that just looking at 
SCRATCHes is the right thing either, but I think you're on the right 
track, and we can use something like your patch for now and extend it 
later if necessary.

> + public:
> +  rtx_reuse_manager ();
> +  ~rtx_reuse_manager ();
> +  static rtx_reuse_manager *get () { return singleton; }

OTOH, this setup looks a bit odd to me. Are you trying to avoid 
converting the print_rtx stuff to its own class, or avoid passing the 
reuse manager as an argument to a lot of functions?

Some of this setup might not even be necessary. We have a "used" flag on 
rtx objects which is used to unshare RTL, and I think could also be used 
for a similar purpose when dumping. So, before printing, call 
reset_insn_used_flags on everything, then have another pass to set bits 
on everything that could conceivably be shared, and when you find 
something that already has the bit set, enter it into a table. Finally, 
print everything out, using the table. I think this would be somewhat 
simpler than adding another header file and class definition.

> +void
> +rtx_reuse_manager::preprocess (const_rtx x)
> +{
> +  subrtx_iterator::array_type array;
> +  FOR_EACH_SUBRTX (iter, array, x, NONCONST)
> +    if (uses_rtx_reuse_p (*iter))
> +      {
> +	if (int *count = m_rtx_occurrence_count.get (*iter))
> +	  {
> +	    if (*count == 1)
> +	      {
> +		m_rtx_reuse_ids.put (*iter, m_next_id++);
> +	      }
> +	    (*count)++;
> +	  }
> +	else
> +	  m_rtx_occurrence_count.put (*iter, 1);
> +      }

Formatting rules suggest no braces around single statements, I think a 
more readable version of this would be:

   if (uses_rtx_reuse_p (*iter))
     {
       int *count = m_rtx_occurrence_count.get (*iter)
       if (count)
         {
           if ((*count)++ == 1)
             m_rtx_reuse_ids.put (*iter, m_next_id++);
         }
       else
	m_rtx_occurrence_count.put (*iter, 1);
     }


Bernd



More information about the Gcc-patches mailing list