Unfillable branch delay slots

DJ Delorie dj@redhat.com
Thu Apr 26 09:17:00 GMT 2001


> My MIPS-like port fails to generate NOP to fill a delay slot when no
> useful insn will fit.  I don't see any mention of this case in the
> GCC manual.  How is this supposed to be done?

Heh, I just fixed this one myself yesterday.  It's not obvious from
the documentation, but it works like this:

Hook DBR_OUTPUT_SEQEND.  If `final_sequence' (a global in output.h) is
not null, then gcc has scheduled one or more insns into the delay
slot.  `final_sequence' itself is a SEQUENCE rtl, the first entry of
which is the insn that has delay slots.  Examine this insn to
determine the number of delay slots needed.  Call
dbr_sequence_length() to determine how many have already been filled.
Use fprintf to emit the remaining nops.

There's a catch.  If *zero* delay slots were filled, there is no
SEQUENCE, and dbr_output_seqend is never called (I consider this a
bug; gcc should create a SEQUENCE anyway to make the API cleaner).
You need to detect this in the emit phase of your insn, i.e. in the md
file, use something like "* return chip_emit_this_insn(operands);".
If `final_sequence' is NULL, return a string for your opcode and the
nops for the delay slots (i.e. return "mov %1,%2\n\tnop\n\tnop").  If
it is not NULL, just return the opcode string.

If you get it working, consider submitting a doc patch.



More information about the Gcc mailing list