This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How to add a NOP instruction in each basic block for obj code that gcc generates
If you don't want to change the generated code other than inserting
the nops, and you can restrict yourself to a processor which does not
need to track addresses to avoid out-of-range branches, then you could
approximate what you want by emitting a nop in final_scan_insn when
you see a CODE_LABEL, after the label. You'll need to also emit a nop
in the first basic block in the function. That probably won't be the
precise set of basic blocks as the compiler sees them, but basic block
is a somewhat nebulous concept and that may be good enough for your
purposes, whatever they are.
Thanks, Ian. I don't want the NOPs to affect gcc's optimization.
I've found the function final_scan_insn, which is in ./gcc/final.c.
Here is the code snippet related to CODE_LABEL:
case CODE_LABEL:
/* The target port might emit labels in the output function for
some insn, e.g. sh.c output_branchy_insn. */
if (CODE_LABEL_NUMBER (insn) <= max_labelno)
{
int align = LABEL_TO_ALIGNMENT (insn);
#ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
int max_skip = LABEL_TO_MAX_SKIP (insn);
#endif
if (align && NEXT_INSN (insn))
{
#ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
ASM_OUTPUT_MAX_SKIP_ALIGN (file, align, max_skip);
#else
#ifdef ASM_OUTPUT_ALIGN_WITH_NOP
ASM_OUTPUT_ALIGN_WITH_NOP (file, align);
#else
ASM_OUTPUT_ALIGN (file, align);
#endif
#endif
}
}
Which function should I use in order to emit a nop?
Thanks,
Jeff