Thanks John, The reason I want to do this is that register allocator works only on SSA form, and if you instrument regallocated code with non-regallocated machine instructions, then you cannot regallocate the result. A workaround is to assign physical registers while doing the instrumentation, which I don't think is as easy as the above. On Tue, Sep 23, 2014 at 11:01 AM, John Criswell <jtcriswel at gmail.com> wrote:> On 9/23/14, 10:52 AM, Rahman Lavaee wrote: > >> Hi, >> >> I'm wondering how I can convert "register allocated" code back to SSA >> form. I realized from MachineRegisterInfo.h that a function leaves SSA form >> only once and cannot be taken back to it. >> > > Are you wanting to put MachineInstr's into SSA form? If you want to do > that, you'll need to implement the SSA construction algorithm yourself so > that it works on MachineInstrs. Also, such a pass will need to work with > virtual registers as you'll need an unlimited supply of temporary > variables. In essence, you'll be undoing register allocation. > > Can you describe why you want to put MachineInstrs into SSA form? I > suspect that putting MachineIntrs back into SSA form is not what you want > to do. > > Regards, > > John Criswell > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140923/c46d4dc3/attachment.html>
Two options: 1) Do the instrumentation at the MachineInstr level but before register allocation and let normal regalloc handle things for you. 2) Do it late, being careful to use only a very small number of registers, and use the RegisterScavenger to fix up the allocation (ARM does this for materializing stack offset immediates, e.g.) Option 1 is easier, but may not work well depending on the details of your instrumentation and whether later passes might muck about with them. You might be able to work around that w/ clever pseudo-instructions, though, so I’d definitely encourage experimenting a bit along this route. Option 2 allows doing things much later, but is trickier in general and more likely to expose odd corner cases both in the new code you’ll be inserting and in the rest of the backend. -Jim> On Sep 23, 2014, at 8:14 AM, Rahman Lavaee <rlavaee at cs.rochester.edu> wrote: > > Thanks John, > > The reason I want to do this is that register allocator works only on SSA form, and if you instrument regallocated code with non-regallocated machine instructions, then you cannot regallocate the result. > > A workaround is to assign physical registers while doing the instrumentation, which I don't think is as easy as the above. > > On Tue, Sep 23, 2014 at 11:01 AM, John Criswell <jtcriswel at gmail.com <mailto:jtcriswel at gmail.com>> wrote: > On 9/23/14, 10:52 AM, Rahman Lavaee wrote: > Hi, > > I'm wondering how I can convert "register allocated" code back to SSA form. I realized from MachineRegisterInfo.h that a function leaves SSA form only once and cannot be taken back to it. > > Are you wanting to put MachineInstr's into SSA form? If you want to do that, you'll need to implement the SSA construction algorithm yourself so that it works on MachineInstrs. Also, such a pass will need to work with virtual registers as you'll need an unlimited supply of temporary variables. In essence, you'll be undoing register allocation. > > Can you describe why you want to put MachineInstrs into SSA form? I suspect that putting MachineIntrs back into SSA form is not what you want to do. > > Regards, > > John Criswell > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140923/abc19d06/attachment.html>
On 9/23/14, 11:14 AM, Rahman Lavaee wrote:> Thanks John, > > The reason I want to do this is that register allocator works only on > SSA form, and if you instrument regallocated code with > non-regallocated machine instructions, then you cannot regallocate the > result. > > A workaround is to assign physical registers while doing the > instrumentation, which I don't think is as easy as the above.Actually, it is pretty simple as long as you don't care about performance. All you have to do is insert code to push the registers that you want to use on to the stack, use those registers in your instrumentation, and then restore them with pops off the stack. Regards, John Criswell> > On Tue, Sep 23, 2014 at 11:01 AM, John Criswell <jtcriswel at gmail.com > <mailto:jtcriswel at gmail.com>> wrote: > > On 9/23/14, 10:52 AM, Rahman Lavaee wrote: > > Hi, > > I'm wondering how I can convert "register allocated" code back > to SSA form. I realized from MachineRegisterInfo.h that a > function leaves SSA form only once and cannot be taken back to it. > > > Are you wanting to put MachineInstr's into SSA form? If you want > to do that, you'll need to implement the SSA construction > algorithm yourself so that it works on MachineInstrs. Also, such > a pass will need to work with virtual registers as you'll need an > unlimited supply of temporary variables. In essence, you'll be > undoing register allocation. > > Can you describe why you want to put MachineInstrs into SSA form? > I suspect that putting MachineIntrs back into SSA form is not what > you want to do. > > Regards, > > John Criswell > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140923/7e730443/attachment.html>
Dear John and Jim, Thanks for your answers. I agree that it is easy to do option 1 below and simple to use the stack as John suggests, and maybe a bit more difficult when using RegisterScavenger. However, I was just wondering maybe "Undoing the Register Allocation" has already been done as part of some LLVM-based disassembler. On Tue, Sep 23, 2014 at 12:23 PM, John Criswell <jtcriswel at gmail.com> wrote:> On 9/23/14, 11:14 AM, Rahman Lavaee wrote: > > Thanks John, > > The reason I want to do this is that register allocator works only on SSA > form, and if you instrument regallocated code with non-regallocated machine > instructions, then you cannot regallocate the result. > > A workaround is to assign physical registers while doing the > instrumentation, which I don't think is as easy as the above. > > > Actually, it is pretty simple as long as you don't care about > performance. All you have to do is insert code to push the registers that > you want to use on to the stack, use those registers in your > instrumentation, and then restore them with pops off the stack. > > Regards, > > John Criswell > > > On Tue, Sep 23, 2014 at 11:01 AM, John Criswell <jtcriswel at gmail.com> > wrote: > >> On 9/23/14, 10:52 AM, Rahman Lavaee wrote: >> >>> Hi, >>> >>> I'm wondering how I can convert "register allocated" code back to SSA >>> form. I realized from MachineRegisterInfo.h that a function leaves SSA form >>> only once and cannot be taken back to it. >>> >> >> Are you wanting to put MachineInstr's into SSA form? If you want to do >> that, you'll need to implement the SSA construction algorithm yourself so >> that it works on MachineInstrs. Also, such a pass will need to work with >> virtual registers as you'll need an unlimited supply of temporary >> variables. In essence, you'll be undoing register allocation. >> >> Can you describe why you want to put MachineInstrs into SSA form? I >> suspect that putting MachineIntrs back into SSA form is not what you want >> to do. >> >> Regards, >> >> John Criswell >> >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140923/dd1eaaf2/attachment.html>