Nuno Lopes
2010-Mar-24 23:16 UTC
[LLVMdev] insertion points for newly created instructions
Hi, I've been scratching my head with a little problem: how to determine the insertion point for a newly created instruction? The operands of these instructions can be defined in different BBs, and they may have several users. Thereby determining where to put those instructions is not obvious. In my case, these instructions don't have side-effects, and so they could be placed anywhere after the definition of the "more-recently-defined" operand, but before the last dominator of all the users. Does LLVM already has any function that will do this (i.e., magically insert an instruction in a valid point)? If not, is there any way I can implement this without transversing all the instructions in the enclosing function? Thanks, Nuno
Devang Patel
2010-Mar-25 15:25 UTC
[LLVMdev] insertion points for newly created instructions
On Wed, Mar 24, 2010 at 4:16 PM, Nuno Lopes <nunoplopes at sapo.pt> wrote:> Hi, > > I've been scratching my head with a little problem: how to determine the > insertion point for a newly created instruction? > The operands of these instructions can be defined in different BBs, and they > may have several users. Thereby determining where to put those instructions > is not obvious. In my case, these instructions don't have side-effects, and > so they could be placed anywhere after the definition of the > "more-recently-defined" operand, but before the last dominator of all the > users. > > Does LLVM already has any function that will do this (i.e., magically insert > an instruction in a valid point)?There is no magical utility function available to do this.> If not, is there any way I can implement > this without transversing all the instructions in the enclosing function?Find a user that dominates all other users and then insert this instruction just before the dominating users. - Devang
Nuno Lopes
2010-Mar-25 19:40 UTC
[LLVMdev] insertion points for newly created instructions
Thanks for your reply!> On Wed, Mar 24, 2010 at 4:16 PM, Nuno Lopes <nunoplopes at sapo.pt> wrote: >> Hi, >> >> I've been scratching my head with a little problem: how to determine the >> insertion point for a newly created instruction? >> The operands of these instructions can be defined in different BBs, and >> they >> may have several users. Thereby determining where to put those >> instructions >> is not obvious. In my case, these instructions don't have side-effects, >> and >> so they could be placed anywhere after the definition of the >> "more-recently-defined" operand, but before the last dominator of all the >> users. >> >> Does LLVM already has any function that will do this (i.e., magically >> insert >> an instruction in a valid point)? > > There is no magical utility function available to do this.That's what I was afraid of :)>> If not, is there any way I can implement >> this without transversing all the instructions in the enclosing function? > > Find a user that dominates all other users and then insert this > instruction just before the dominating users.The problem is if none of the users dominates the other ones. That's why I wanted to somewhat insert the new instruction after the last definition of the operands. I guess that's a tricky business.. Nuno