Add instructions in the beginning of a function

Segher Boessenkool segher@kernel.crashing.org
Mon Oct 5 00:17:00 GMT 2015


On Sun, Oct 04, 2015 at 04:53:23PM -0400, Marios Pomonis wrote:
> I'm trying to add some instructions in the beginning of each function 
> using a gcc plugin in RTL (after "vartrack").
> I am currently doing this by iterating the instructions in the first 
> basic block and calling `emit_insn_before()' when reaching the first 
> "real" instruction (one that has INSN, CALL or JUMP as code).
> 
> This works ok if the first "real" instruction is not part of a loop, 
> because in this case the additional instructions are also executed as well.
> I know that this happens because there is at least one CODE_LABEL rtx 
> before the first "real" instruction, however all my attempts to fix this 
> (e.g. by adding the additional instructions before the labels and 
> splitting the basic block) failed.
> 
> Does anyone have a suggestion on how this should be fixed properly?

You split the entry edge, and you put the insns in the new basic block.
Or, less manually, you use insert_insn_on_edge (on the entry edge) and
then commit_edge_insertions.


Segher



More information about the Gcc-help mailing list