public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* inserting instructions into prologue/epilogue
@ 2005-08-03 14:40 Gunther Nikl
  2005-08-03 14:50 ` Nathan Sidwell
  2005-08-03 17:50 ` Ian Lance Taylor
  0 siblings, 2 replies; 8+ messages in thread
From: Gunther Nikl @ 2005-08-03 14:40 UTC (permalink / raw)
  To: gcc

Hello!

I am trying to add instructions into function prologue/epilogue. These
instructions shall save and load "fixed" registers to avoid assembly.

Register saving in the prologue appears to work. The restore code in the
epilogue aborts in flow.c/propagate_one_insn with

  "Attempt to delete prologue/epilogue insn"

unless the stackslot was marked with MEM_VOLATILE_P. I don't think thats
the proper fix.

Then I used TARGET_ASM_FUNCTION_END_PROLOGUE to emit additional assembly
code. However this hook is _only_ called if prologue/epilogue instructions
are scheduled. Is that the expected behaviour? tm.texi doesn't mention this.
I tried to get rid of TARGET_ASM_FUNCTION_END_PROLOGUE by emitting the
loads as RTL, but then I also get flow.c aborts if prologue and epilogue
are scheduled. It works when not scheduling. This is the load code:

     ref = gen_rtx_SYMBOL_REF (Pmode, "symbol");
     emit_insn (gen_elf_high (reg, ref));
     emit_insn (gen_elf_low (reg, reg, ref));

How do I prevent the aborts from flow? Any help appreciated.

Gunther Nikl

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

* Re: inserting instructions into prologue/epilogue
  2005-08-03 14:40 inserting instructions into prologue/epilogue Gunther Nikl
@ 2005-08-03 14:50 ` Nathan Sidwell
  2005-08-03 14:53   ` Nathan Sidwell
  2005-08-03 17:50 ` Ian Lance Taylor
  1 sibling, 1 reply; 8+ messages in thread
From: Nathan Sidwell @ 2005-08-03 14:50 UTC (permalink / raw)
  To: Gunther Nikl; +Cc: gcc

Gunther Nikl wrote:
> Hello!
> 
> I am trying to add instructions into function prologue/epilogue. These
> instructions shall save and load "fixed" registers to avoid assembly.
> 
> Register saving in the prologue appears to work. The restore code in the
> epilogue aborts in flow.c/propagate_one_insn with
> 
>   "Attempt to delete prologue/epilogue insn"
> 
> unless the stackslot was marked with MEM_VOLATILE_P. I don't think thats
> the proper fix.

you can add a (USE reg) after the restore in the prologue.  Then flow considers 
the register, and the preceding load, to be live at that point.

nathan
-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

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

* Re: inserting instructions into prologue/epilogue
  2005-08-03 14:50 ` Nathan Sidwell
@ 2005-08-03 14:53   ` Nathan Sidwell
  2005-08-03 15:27     ` Gunther Nikl
  0 siblings, 1 reply; 8+ messages in thread
From: Nathan Sidwell @ 2005-08-03 14:53 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: Gunther Nikl, gcc

Nathan Sidwell wrote:

> you can add a (USE reg) after the restore in the prologue.  Then flow
in the EPILOGUE, of course
> considers the register, and the preceding load, to be live at that point.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

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

* Re: inserting instructions into prologue/epilogue
  2005-08-03 14:53   ` Nathan Sidwell
@ 2005-08-03 15:27     ` Gunther Nikl
  2005-08-03 18:09       ` Richard Henderson
  0 siblings, 1 reply; 8+ messages in thread
From: Gunther Nikl @ 2005-08-03 15:27 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: gcc

On Wed, Aug 03, 2005 at 03:50:09PM +0100, Nathan Sidwell wrote:
> Gunther Nikl wrote:
> >I am trying to add instructions into function prologue/epilogue. These
> >instructions shall save and load "fixed" registers to avoid assembly.
> >
> >Register saving in the prologue appears to work. The restore code in the
> >epilogue aborts in flow.c/propagate_one_insn with
> >
> >  "Attempt to delete prologue/epilogue insn"
> >
> >unless the stackslot was marked with MEM_VOLATILE_P. I don't think thats
> >the proper fix.
> 
> you can add a (USE reg) after the restore in the prologue.  Then flow 
> considers the register, and the preceding load, to be live at that point.

  Thank you. With "emit_insn (gen_rtx_USE (VOIDmode, reg))" the abort
  disappears. The same approach seems to fix the loads in the prologue.
  I hope that this is the correct solution.

On Wed, Aug 03, 2005 at 03:53:21PM +0100, Nathan Sidwell wrote:
> Nathan Sidwell wrote:
> 
> >you can add a (USE reg) after the restore in the prologue.  Then flow
> in the EPILOGUE, of course

  I wouldn't have notice this mistake without your mail.

  Thank you for the help.

  Gunther

> >considers the register, and the preceding load, to be live at that point.

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

* Re: inserting instructions into prologue/epilogue
  2005-08-03 14:40 inserting instructions into prologue/epilogue Gunther Nikl
  2005-08-03 14:50 ` Nathan Sidwell
@ 2005-08-03 17:50 ` Ian Lance Taylor
  2005-08-04 12:02   ` Gunther Nikl
  1 sibling, 1 reply; 8+ messages in thread
From: Ian Lance Taylor @ 2005-08-03 17:50 UTC (permalink / raw)
  To: Gunther Nikl; +Cc: gcc

Gunther Nikl <gni@gecko.de> writes:

> I am trying to add instructions into function prologue/epilogue. These
> instructions shall save and load "fixed" registers to avoid assembly.
> 
> Register saving in the prologue appears to work. The restore code in the
> epilogue aborts in flow.c/propagate_one_insn with
> 
>   "Attempt to delete prologue/epilogue insn"
> 
> unless the stackslot was marked with MEM_VOLATILE_P. I don't think thats
> the proper fix.

As Nathan said, you can add a USE.  Or in some cases the correct fix
is to define EPILOGUE_USES and/or EH_USES.

In some cases this error message can indicate a bug in the
prologue/epilogue code.  For example, if you accidentally try to save
two different registers into the same stack slot, flow will cleverly
try to delete the first store, and then cleverly notice that it is
deleting a prologue insn.  Similarly if you accidentally save a
register into a stack slot which is being used for a temporary
variable.

Ian

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

* Re: inserting instructions into prologue/epilogue
  2005-08-03 15:27     ` Gunther Nikl
@ 2005-08-03 18:09       ` Richard Henderson
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2005-08-03 18:09 UTC (permalink / raw)
  To: Gunther Nikl; +Cc: Nathan Sidwell, gcc

On Wed, Aug 03, 2005 at 05:28:43PM +0200, Gunther Nikl wrote:
>   Thank you. With "emit_insn (gen_rtx_USE (VOIDmode, reg))" the abort
>   disappears. The same approach seems to fix the loads in the prologue.
>   I hope that this is the correct solution.

No, it isn't.  Your problem is that you havn't properly described
the lifetime of these fixed registers.  That's why they are being
considered dead by flow.

You probably need to modify CALL_USED_REGISTERS or
CALL_REALLY_USED_REGISTERS.


r~

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

* Re: inserting instructions into prologue/epilogue
  2005-08-03 17:50 ` Ian Lance Taylor
@ 2005-08-04 12:02   ` Gunther Nikl
  2005-08-04 16:57     ` Ian Lance Taylor
  0 siblings, 1 reply; 8+ messages in thread
From: Gunther Nikl @ 2005-08-04 12:02 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc

On Wed, Aug 03, 2005 at 10:49:49AM -0700, Ian Lance Taylor wrote:
> Gunther Nikl <gni@gecko.de> writes:
> 
> >   "Attempt to delete prologue/epilogue insn"
> > 
> > unless the stackslot was marked with MEM_VOLATILE_P. I don't think thats
> > the proper fix.
> 
> As Nathan said, you can add a USE.  Or in some cases the correct fix
> is to define EPILOGUE_USES and/or EH_USES.

  Is EPILOGUE_USES only for the save and restore? I would have to add
  some big chunk of code to it and that would propagate to several
  places. It seems emitting a USE has lower impact.

> In some cases this error message can indicate a bug in the
> prologue/epilogue code.

  Here is what I am trying to do: I have a rs6000 port using V.4 ABI.
  The ABI has two fixed registers: r2 (_SDA2_BASE_) and r13 (_SDA_BASE_).
  I suppose normally these are initialized in an assembly file. I want
  the compiler emitting the appropriate load through a function attribute.
  Since I change the register it has to be saved and restored as well.

  Gunther

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

* Re: inserting instructions into prologue/epilogue
  2005-08-04 12:02   ` Gunther Nikl
@ 2005-08-04 16:57     ` Ian Lance Taylor
  0 siblings, 0 replies; 8+ messages in thread
From: Ian Lance Taylor @ 2005-08-04 16:57 UTC (permalink / raw)
  To: Gunther Nikl; +Cc: gcc

Gunther Nikl <gni@gecko.de> writes:

>   Is EPILOGUE_USES only for the save and restore? I would have to add
>   some big chunk of code to it and that would propagate to several
>   places. It seems emitting a USE has lower impact.

EPILOGUE_USES doesn't emit code.  It simply takes a register and
returns whether the epilogue uses it, so that flow does not get
confused.

> > In some cases this error message can indicate a bug in the
> > prologue/epilogue code.
> 
>   Here is what I am trying to do: I have a rs6000 port using V.4 ABI.
>   The ABI has two fixed registers: r2 (_SDA2_BASE_) and r13 (_SDA_BASE_).
>   I suppose normally these are initialized in an assembly file. I want
>   the compiler emitting the appropriate load through a function attribute.
>   Since I change the register it has to be saved and restored as well.

Perhaps you should make sure that they are clear in
CALL_USED_REGISTERS, so that flow knows that they should not be
modified by the function, and that they are not modified by function
calls.  That is how you describe that the register value is live after
the function completes.

Although I guess that wouldn't work on a function by function basis,
so maybe EPILOGUE_USES would be an appropriate solution.
EPILOGUE_USES is another way to say that the value of the register is
live at the end of the function.

Ian

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

end of thread, other threads:[~2005-08-04 16:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-03 14:40 inserting instructions into prologue/epilogue Gunther Nikl
2005-08-03 14:50 ` Nathan Sidwell
2005-08-03 14:53   ` Nathan Sidwell
2005-08-03 15:27     ` Gunther Nikl
2005-08-03 18:09       ` Richard Henderson
2005-08-03 17:50 ` Ian Lance Taylor
2005-08-04 12:02   ` Gunther Nikl
2005-08-04 16:57     ` Ian Lance Taylor

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