Villmow, Micah
2008-Oct-20 21:14 UTC
[LLVMdev] Virtual Register allocation across functions
I'm targeting a language that uses virtual registers and not physical registers. So the easiest way to implement this is to use virtual registers, except that they are being restarted after each function and clobbering registers in previous functions. For example: start function 0 r1024 = mov %var0.0 r1025 = mov %var0.1 lots of intermediate code call function1 w/ 3 parameters more intermediate code %r1300 = add %call.result, %r1024 end function 0 start function 1 %r1024 = mov %var1.0 %r1025 = mov %var1.1 %r1026 = mov %var1.2 some code return some value end function 0 The mov to r1024 in function 1 clobbers the data from function 0. The only ways I can think to get around this, is to push every virtual register used in a function to a stack or some internal data structure and then pull them back out for each function call. The other option is to run a separate pass just to renumber register. This is not what I would like to do as the easiest solution is just to get a variable start point. Any other ideas that might accomplish what I want, that I might be missing? Thanks, ________________________________ From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Evan Cheng Sent: Monday, October 20, 2008 2:03 PM To: LLVM Developers Mailing List Subject: Re: [LLVMdev] Virtual Register allocation across functions No, there isn't something like that right now. What are you trying to accomplish? If you wish to implement this, it shouldn't be hard to do. Right now, MachineRegisterInfo re-starts virtual register number at TargetRegisterInfo::FirstVirtualRegister. You can add a mechanism to change that to a variable instead. Evan On Oct 20, 2008, at 1:43 PM, Villmow, Micah wrote: Is there currently a way to have virtual register allocation information be saved across functions so that if I create a new virtual register in a function that it doesn't use a virtual register allocated in any previous function? Thanks, Micah Villmow Systems Engineer Advanced Technology & Performance Advanced Micro Devices Inc. 4555 Great America Pkwy, Santa Clara, CA. 95054 P: 408-572-6219 F: 408-572-6596 _______________________________________________ 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/20081020/98005733/attachment.html>
On Mon, Oct 20, 2008 at 2:14 PM, Villmow, Micah <Micah.Villmow at amd.com> wrote:> The mov to r1024 in function 1 clobbers the data from function 0. The only > ways I can think to get around this, is to push every virtual register used > in a function to a stack or some internal data structure and then pull them > back out for each function call.Just to double-check, are you planning on compiling code which uses recursion? If you are, you have to have some way of saving registers. -Eli
Villmow, Micah
2008-Oct-21 15:57 UTC
[LLVMdev] Virtual Register allocation across functions
There is no notion of recursion in the language that I am compiling from but the target language does handle recursion. Since these are virtual registers, as long as the virtual registers do not clobber each others data, the lower level compiler handles the recursion and final register allocation for me. The main issue is that all registers are global in scope, so I can't have duplicate register uses in different functions. My current solution is just to renumber sequentially every def register in the program using a separate pass and allocate extra virtual registers whenever I use up all the ones I currently have. Not the cleanest solution, but it is working for now while I continue understanding LLVM more. -----Original Message----- From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Eli Friedman Sent: Monday, October 20, 2008 5:27 PM To: LLVM Developers Mailing List Subject: Re: [LLVMdev] Virtual Register allocation across functions On Mon, Oct 20, 2008 at 2:14 PM, Villmow, Micah <Micah.Villmow at amd.com> wrote:> The mov to r1024 in function 1 clobbers the data from function 0. Theonly> ways I can think to get around this, is to push every virtual registerused> in a function to a stack or some internal data structure and then pullthem> back out for each function call.Just to double-check, are you planning on compiling code which uses recursion? If you are, you have to have some way of saving registers. -Eli _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
On Oct 20, 2008, at 2:14 PM, Villmow, Micah wrote:> I’m targeting a language that uses virtual registers and not > physical registers. So the easiest way to implement this is to use > virtual registers, except that they are being restarted after each > function and clobbering registers in previous functions. For example: > > > start function 0 > r1024 = mov %var0.0 > r1025 = mov %var0.1 > lots of intermediate code > call function1 w/ 3 parameters > more intermediate code > %r1300 = add %call.result, %r1024 > end function 0 > > start function 1 > %r1024 = mov %var1.0 > %r1025 = mov %var1.1 > %r1026 = mov %var1.2 > some code > return some value > end function 0 > > The mov to r1024 in function 1 clobbers the data from function 0. > The only ways I can think to get around this, is to push every > virtual register used in a function to a stack or some internal data > structure and then pull them back out forThat's similar to other targets where registers are saved across calls (or by the calls). However, I can see this might be very inefficient for your target.> each function call. The other option is to run a separate pass just > to renumber register. This is not what I would like to do as the > easiest solution is just to get a variable start point. > > Any other ideas that might accomplish what I want, that I might be > missing?I don't have a non-hacky solution. The least hacky solution I can think of is to enhance MachineRegisterInfo to tell it to start virtual register number at something the user specified. Evan> > Thanks, > > > From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev- > bounces at cs.uiuc.edu] On Behalf Of Evan Cheng > Sent: Monday, October 20, 2008 2:03 PM > To: LLVM Developers Mailing List > Subject: Re: [LLVMdev] Virtual Register allocation across functions > > No, there isn't something like that right now. What are you trying > to accomplish? > > If you wish to implement this, it shouldn't be hard to do. Right > now, MachineRegisterInfo re-starts virtual register number at > TargetRegisterInfo::FirstVirtualRegister. You can add a mechanism to > change that to a variable instead. > > Evan > > On Oct 20, 2008, at 1:43 PM, Villmow, Micah wrote: > > > Is there currently a way to have virtual register allocation > information be saved across functions so that if I create a new > virtual register in a function that it doesn’t use a virtual > register allocated in any previous function? > > Thanks, > > Micah Villmow > Systems Engineer > Advanced Technology & Performance > Advanced Micro Devices Inc. > 4555 Great America Pkwy, > Santa Clara, CA. 95054 > P: 408-572-6219 > F: 408-572-6596 > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > _______________________________________________ > 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/20081021/8ee2c7ae/attachment.html>