This is the mail archive of the
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:
/* 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);
int max_skip = LABEL_TO_MAX_SKIP (insn);
if (align && NEXT_INSN (insn))
ASM_OUTPUT_MAX_SKIP_ALIGN (file, align, max_skip);
ASM_OUTPUT_ALIGN_WITH_NOP (file, align);
ASM_OUTPUT_ALIGN (file, align);
Which function should I use in order to emit a nop?