public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: RTL obscurities
@ 2007-05-25 14:01 Nick Maclaren
  2007-05-25 14:06 ` Andrew Haley
  2007-05-25 16:46 ` Ian Lance Taylor
  0 siblings, 2 replies; 6+ messages in thread
From: Nick Maclaren @ 2007-05-25 14:01 UTC (permalink / raw)
  To: gcc-help; +Cc: Andrew Haley

> If course, but you haven't told us what you want to know.  The
> question above reads like a request for a detailed RTL cookbook and
> manual, and you aren't going to get that in an email response.

ANY pointer to ANY information that will save me time reverse
engineering the code!  It is the same requirement that I had before,
and which you gave me some pointers on the second aspect.
Unfortunately, it is the first one that is critical :-(

I really do mean that I have drawn a complete blank looking for any
useful information, and have looked through several gcc internals
documents and searched the Web as far as I can!  Some time back,
I found the right place to modify (ix86_expand_prologue in i386.c),
and have inserted some RTL, but not useful RTL.

What I need to do is to insert the following:

    extern void *__limit;
    extern void __failure (void);
    if (%SP < __limit) __failure();


And the call doesn't need to be a standard one, either, though it
does need to provide __failure with a way of getting back.


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1@cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679

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

* Re: RTL obscurities
  2007-05-25 14:01 RTL obscurities Nick Maclaren
@ 2007-05-25 14:06 ` Andrew Haley
  2007-05-25 19:27   ` Nick Maclaren
  2007-05-25 16:46 ` Ian Lance Taylor
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Haley @ 2007-05-25 14:06 UTC (permalink / raw)
  To: Nick Maclaren; +Cc: gcc-help

Nick Maclaren writes:
 > > If course, but you haven't told us what you want to know.  The
 > > question above reads like a request for a detailed RTL cookbook and
 > > manual, and you aren't going to get that in an email response.
 > 
 > ANY pointer to ANY information that will save me time reverse
 > engineering the code!

Well, I don't know what you don't know.  Have you found the GCC
internals manual?

 > It is the same requirement that I had before, and which you gave me
 > some pointers on the second aspect.  Unfortunately, it is the first
 > one that is critical :-(
 > 
 > I really do mean that I have drawn a complete blank looking for any
 > useful information, and have looked through several gcc internals
 > documents

Okay, so you have found the GCC internals manual.

 > and searched the Web as far as I can!  Some time back, I found the
 > right place to modify (ix86_expand_prologue in i386.c), and have
 > inserted some RTL, but not useful RTL.
 > 
 > What I need to do is to insert the following:
 > 
 >     extern void *__limit;
 >     extern void __failure (void);
 >     if (%SP < __limit) __failure();
 > 
 > 
 > And the call doesn't need to be a standard one, either, though it
 > does need to provide __failure with a way of getting back.

Firstly, you'll need to generate decls for the externs.  Then you'll
need to generate RTL like this:

(insn 13 12 14 1 (set (reg:CC 17 flags)
        (compare:CC (reg:SP)
            (mem:DI (symbol_ref:DI ("__limit") <var_decl 0x2aaaae1958f0 __limit>) ))) -1 (nil)
    (nil))

(jump_insn 14 13 15 1 (set (pc)
        (if_then_else (geu (reg:CC 17 flags)
                (const_int 0 [0x0]))
            (label_ref 18)
            (pc))) -1 (nil)
    )

(call_insn 17 16 18 2 (call (mem:DI (symbol_ref:DI ("__failure") <function_decl 0x2aaaae196b00 __failure>))
        (const_int 0 [0x0])) -1 (nil)
    (nil)
    (nil))

(code_label 18 17 19 3 2 "" [1 uses])

This construct doesn't need any scratch registers.  This is good.

You've already seen how to generate RTL by perusing
ix86_expand_prologue, so you know that generating this RTL will be
done by things like

  tmp = ix86_expand_int_compare (GEU, stack_pointer_rtx, limit);
  tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
			      gen_rtx_LABEL_REF (VOIDmode, label),
		              pc_rtx);

  emit_jump_insn (tmp);
  emit_call_insn ...
  emit_label (label);

... etc.

Andrew.

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

* Re: RTL obscurities
  2007-05-25 14:01 RTL obscurities Nick Maclaren
  2007-05-25 14:06 ` Andrew Haley
@ 2007-05-25 16:46 ` Ian Lance Taylor
  1 sibling, 0 replies; 6+ messages in thread
From: Ian Lance Taylor @ 2007-05-25 16:46 UTC (permalink / raw)
  To: Nick Maclaren; +Cc: gcc-help

Nick Maclaren <nmm1@cus.cam.ac.uk> writes:

> What I need to do is to insert the following:
> 
>     extern void *__limit;
>     extern void __failure (void);
>     if (%SP < __limit) __failure();

This is similar to what probe_stack_range in explow.c does, so that a
look at that function.

It's obviously easier to answer more detailed questions.  The general
flow of RTL is:

  * Define insn FOO in .md file
  * Generate it using emit_insn (gen_FOO (operands)).
  * Use standard names for, e.g., addition insns so that gcc knows
    which ones to use when generating code.

There are literally thousands of example of RTL generation in the gcc
code base.

Ian

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

* Re: RTL obscurities
  2007-05-25 14:06 ` Andrew Haley
@ 2007-05-25 19:27   ` Nick Maclaren
  0 siblings, 0 replies; 6+ messages in thread
From: Nick Maclaren @ 2007-05-25 19:27 UTC (permalink / raw)
  To: gcc-help; +Cc: Andrew Haley

Thank you VERY much!  That is all I need for now.  I will insert
things along those lines and see how much further I can get.


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1@cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679

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

* Re: RTL obscurities
  2007-05-25 13:15 Nick Maclaren
@ 2007-05-25 13:32 ` Andrew Haley
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Haley @ 2007-05-25 13:32 UTC (permalink / raw)
  To: Nick Maclaren; +Cc: gcc-help

Nick Maclaren writes:

 > I am trying to reverse engineer gcc's generation of RTL and failing
 > dismally.  Alll the documentation seems to be in terms of the
 > string representation, and I can find nothing that links that to
 > the relevant calls.  I can find some calls, but nothing that will
 > do what I need to two.
 > 
 > And this is just to generate 3 instructions in the prologue!
 > 
 > Can anyone help at all with this?

If course, but you haven't told us what you want to know.  The
question above reads like a request for a detailed RTL cookbook and
manual, and you aren't going to get that in an email response.

Andrew.

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

* RTL obscurities
@ 2007-05-25 13:15 Nick Maclaren
  2007-05-25 13:32 ` Andrew Haley
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Maclaren @ 2007-05-25 13:15 UTC (permalink / raw)
  To: gcc-help

I am trying to reverse engineer gcc's generation of RTL and failing
dismally.  Alll the documentation seems to be in terms of the string
representation, and I can find nothing that links that to the
relevant calls.  I can find some calls, but nothing that will do
what I need to two.

And this is just to generate 3 instructions in the prologue!

Can anyone help at all with this?


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1@cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679

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

end of thread, other threads:[~2007-05-25 16:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-25 14:01 RTL obscurities Nick Maclaren
2007-05-25 14:06 ` Andrew Haley
2007-05-25 19:27   ` Nick Maclaren
2007-05-25 16:46 ` Ian Lance Taylor
  -- strict thread matches above, loose matches on Subject: below --
2007-05-25 13:15 Nick Maclaren
2007-05-25 13:32 ` Andrew Haley

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).