Jeff wrote:
I added fprintf (asm_out_file, "\tnop\n"); to the end of case CODE_LABEL. Then I recompile the gcc. Unfortunately, it doesn't seem that a NOP was inserted. Any ideaes?
What testcase did you try? Not every basic block starts with a label. Only basic blocks that are the target of a branch start with a label, which is maybe only half of them. So if you tried a simple testcase without an if statement or loop, then you won't get a nop emitted.
A more serious problem however is that emitting an extra instruction like this will cause out-of-range addressing problems. Many targets have limited range branch offsets, and adding extra instructions can cause the branches to end up out of range. (Likewise, trying to do this at the assembler level has the same problem.) Some targets with very limited addressing modes (thumb, mips16, sh, etc) require inline constant pools that are carefully constructed to be within range, and may end up out-of-range if you emit extra instructions.
So to do this portably, you need to emit the extra instructions before branch shortening, and before the machine dependent reorg pass. You can try using gen_nop () if the target has a named "nop" pattern in the md file, but you might need to construct an pattern that looks like a user extended asm construct. Making it volatile will prevent the optimizer from deleting it.
The simplest way to get an insn into every basic block would be to use the CFG. Scan all basic blocks, and insert an instruction into each one. FOR_EACH_BB will interate over all basic blocks. Try looking at some of the places that use it.
-- Jim Wilson, GNU Tools Support, http://www.specifix.com