public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* fold_builtin changes tree
@ 2012-03-19 17:51 Paulo J. Matos
  2012-03-20  5:50 ` Ian Lance Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: Paulo J. Matos @ 2012-03-19 17:51 UTC (permalink / raw)
  To: gcc

Hi,

I have builtin __function_size(foobar) that is applied to functions.
This should be folded to a symbol foobar@size.

The problem comes when I mark in the fold_builtin function in my backend 
that DECL_PRESERVE(foobar) = 1;

The reason I need to do this is so that foobar is not removed if we 
happen to use __function_size(foobar) since I will need foobar during 
linking phase to do some calculations with regards to its size.

As a consequence of DECL_PRESERVE(foobar) I cannot build GCC with --
enable-checking because it fails the check in: fold-const.c and shows the 
message:
internal compiler error: fold check: original tree changed by fold

This is really annoying since I like to run my tests with --enable-
checking=full to get the most of the checks in GCC but I can't with this 
issue lying around. I am open to suggestions on how to mark the function 
as preserve is the function name is referred to by a function builtin.

Cheers,

-- 
PMatos

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: fold_builtin changes tree
  2012-03-19 17:51 fold_builtin changes tree Paulo J. Matos
@ 2012-03-20  5:50 ` Ian Lance Taylor
  2012-03-20 10:22   ` Paulo J. Matos
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Lance Taylor @ 2012-03-20  5:50 UTC (permalink / raw)
  To: Paulo J. Matos; +Cc: gcc

"Paulo J. Matos" <paulo@matos-sorge.com> writes:

> I have builtin __function_size(foobar) that is applied to functions.
> This should be folded to a symbol foobar@size.
>
> The problem comes when I mark in the fold_builtin function in my backend 
> that DECL_PRESERVE(foobar) = 1;
>
> The reason I need to do this is so that foobar is not removed if we 
> happen to use __function_size(foobar) since I will need foobar during 
> linking phase to do some calculations with regards to its size.
>
> As a consequence of DECL_PRESERVE(foobar) I cannot build GCC with --
> enable-checking because it fails the check in: fold-const.c and shows the 
> message:
> internal compiler error: fold check: original tree changed by fold
>
> This is really annoying since I like to run my tests with --enable-
> checking=full to get the most of the checks in GCC but I can't with this 
> issue lying around. I am open to suggestions on how to mark the function 
> as preserve is the function name is referred to by a function builtin.

I'm not sure what you are folding the builtin to, but perhaps you could
retain a reference to the function.

Or, you could write a tiny pass which set DECL_PRESERVED_P for each
function passed to __function_size.

Or, perhaps you could handle it in expand_builtin rather than
fold_builtin.

Ian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: fold_builtin changes tree
  2012-03-20  5:50 ` Ian Lance Taylor
@ 2012-03-20 10:22   ` Paulo J. Matos
  2012-03-20 10:30     ` Jakub Jelinek
  0 siblings, 1 reply; 5+ messages in thread
From: Paulo J. Matos @ 2012-03-20 10:22 UTC (permalink / raw)
  To: gcc

On Mon, 19 Mar 2012 22:49:39 -0700, Ian Lance Taylor wrote:

> 
> I'm not sure what you are folding the builtin to, but perhaps you could
> retain a reference to the function.
> 

I am folding the function call __function_size(foobar) to a new symbol 
foobar@size. The reference to function foobar disappears. Can I keep a 
reference foobar attached to the symbol somehow?

> Or, you could write a tiny pass which set DECL_PRESERVED_P for each
> function passed to __function_size.
> 

Might do as a last resort.

> Or, perhaps you could handle it in expand_builtin rather than
> fold_builtin.
> 

I thought that the only way to replace a builtin expression was to use 
fold_builtin and expand_builtin had other purposes. How can I use the 
expand_builtin to do replacement?

Cheers,

Paulo Matos




-- 
PMatos

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: fold_builtin changes tree
  2012-03-20 10:22   ` Paulo J. Matos
@ 2012-03-20 10:30     ` Jakub Jelinek
  2012-03-21 16:30       ` Paulo J. Matos
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2012-03-20 10:30 UTC (permalink / raw)
  To: Paulo J. Matos; +Cc: gcc

On Tue, Mar 20, 2012 at 10:21:45AM +0000, Paulo J. Matos wrote:
> > I'm not sure what you are folding the builtin to, but perhaps you could
> > retain a reference to the function.
> > 
> 
> I am folding the function call __function_size(foobar) to a new symbol 
> foobar@size. The reference to function foobar disappears. Can I keep a 
> reference foobar attached to the symbol somehow?

Folding it, at least too early, is definitely a bad idea, especially if you
set DECL_PRESERVED_P.  Because that will prevent the referenced function
from being removed, even if the function containing __function_size is
removed.  You really want to do it in the expander instead.

> I thought that the only way to replace a builtin expression was to use 
> fold_builtin and expand_builtin had other purposes. How can I use the 
> expand_builtin to do replacement?

Like any other builtin expander?  There are many dozens of examples in
builtins.c.  It is called with the tree argument, so you verify it, complain
if the argument is not the one you are expecting, and just expand it as the
symbol instead of expanding the call.  Basically you could do what you
currently do in the folder, and feed what you'd return from that to
expand_normal or expand_expr.

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: fold_builtin changes tree
  2012-03-20 10:30     ` Jakub Jelinek
@ 2012-03-21 16:30       ` Paulo J. Matos
  0 siblings, 0 replies; 5+ messages in thread
From: Paulo J. Matos @ 2012-03-21 16:30 UTC (permalink / raw)
  To: gcc

On 20/03/12 10:30, Jakub Jelinek wrote:
 >
> Like any other builtin expander?  There are many dozens of examples in
> builtins.c.  It is called with the tree argument, so you verify it, complain
> if the argument is not the one you are expecting, and just expand it as the
> symbol instead of expanding the call.  Basically you could do what you
> currently do in the folder, and feed what you'd return from that to
> expand_normal or expand_expr.
>
> 	Jakub
>

Thanks Jakub. I guess that might work but I have to reimplement my 
function since part of my folder would look for the initial function 
definition.

So, for example if I had:
int lt(int x) { return x < 0;}
int sizeof_lt(void) { return __function_size(lt); }

Since lt, argument to __function_size, is not void (*) (void), the that 
got the folder was:
void (*lt.TEMP)(void) = lt;
return __function_size(lt.TEMP);

So in the folder I was looking through the sequence of statements to 
find the real function lt from the argument to __function_size: lt.TEMP. 
This in the expander doesn't work anymore since we now have basic blocks 
and are handling gimple instead of trees.

If you have any further suggestions, let me know.

Thanks.

-- 
PMatos

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-03-21 16:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-19 17:51 fold_builtin changes tree Paulo J. Matos
2012-03-20  5:50 ` Ian Lance Taylor
2012-03-20 10:22   ` Paulo J. Matos
2012-03-20 10:30     ` Jakub Jelinek
2012-03-21 16:30       ` Paulo J. Matos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).