Avinash Bole
2015-May-07 07:06 UTC
[LLVMdev] How to Store variable allocation in Registers
Hello, Im trying to build a Backend using LLVM. My Architecture doesnt have a stack. So,I need to store all the variables in Registers. I found in xxxFrameLowering.cpp (where xxx is any target name) references to stack and frame pointer. I tried to remove all those references by placing Register class in place of stack but of no use. Can anyone please suggest the way to do this...,would be very helpful if you can share some code or reference links too.. Thank you, Avinash -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150507/db6440eb/attachment.html>
What language are you compiling? If it is anything remotely like C then you absolutely need a stack (or a heap), because of the possibility of recursion. If the hardware doesn't provide one then you have to create your own using a normal pointer register (or, worst case, a global pointer variable). It is possible to compile languages such as traditional FORTRAN and COBOL without a stack, but you still need a frame for each function to hold the return address and any local variables that don't fit into registers. It's just that the frames can be allocated as global variables instead of on a stack. You still need to calculate a frame layout. You probably even still want a frame pointer, to avoid having possibly large absolute addresses when referencing slots in the frame. On Thu, May 7, 2015 at 10:06 AM, Avinash Bole <boleavinash at gmail.com> wrote:> Hello, > > Im trying to build a Backend using LLVM. My Architecture doesnt have a > stack. So,I need to store all the variables in Registers. > > I found in xxxFrameLowering.cpp (where xxx is any target name) references > to stack and frame pointer. I tried to remove all those references by > placing Register class in place of stack but of no use. > > Can anyone please suggest the way to do this...,would be very helpful if > you can share some code or reference links too.. > > Thank you, > Avinash > > > _______________________________________________ > 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/20150508/d40dbed7/attachment.html>
Avinash Bole
2015-May-11 11:08 UTC
[LLVMdev] How to Store variable allocation in Registers
Hi Bruce!! Im using "C" language. As you said...,i tried using Global pointer..,but i still am not able to get the Registers exactly as i wanted. I found "-mem2reg" as a better alternative. But Problem is even though the resulting Intermediate file( .ll ) is good...,the final assembly file( .s) file is making a lot of DCE. Im Posting an example : *Original Intermediate file :* define void @main() #0 { %a = alloca i32, align 4 %b = alloca i32, align 4 %c = alloca i32, align 4 store i32 2, i32* %a, align 4 store i32 3, i32* %b, align 4 store i32 4, i32* %c, align 4 %1 = load i32* %a, align 4 %2 = add nsw i32 %1, 10 store i32 %2, i32* %a, align 4 %3 = load i32* %a, align 4 %4 = load i32* %b, align 4 %5 = add nsw i32 %3, %4 store i32 %5, i32* %a, align 4 store i32 5, i32* %a, align 4 %6 = load i32* %b, align 4 %7 = sub nsw i32 %6, 2 store i32 %7, i32* %b, align 4 %8 = load i32* %b, align 4 %9 = load i32* %a, align 4 %10 = sub nsw i32 %8, %9 store i32 %10, i32* %b, align 4 %11 = load i32* %c, align 4 %12 = xor i32 %11, 4 store i32 %12, i32* %c, align 4 %13 = load i32* %c, align 4 %14 = load i32* %c, align 4 %15 = xor i32 %13, %14 store i32 %15, i32* %c, align 4 %16 = load i32* %a, align 4 %17 = load i32* %b, align 4 %18 = or i32 %16, %17 store i32 %18, i32* %a, align 4 %19 = load i32* %b, align 4 %20 = and i32 %19, 2 store i32 %20, i32* %b, align 4 store i32 7, i32* %a, align 4 %21 = load i32* %a, align 4 %22 = or i32 %21, 2 %23 = load i32* %b, align 4 %24 = load i32* %c, align 4 %25 = or i32 %23, %24 %26 = and i32 %22, %25 store i32 %26, i32* %b, align 4 ret void } *After using "-mem2reg"*: define void @main() #0 { %1 = add nsw i32 2, 10 %2 = add nsw i32 %1, 3 %3 = sub nsw i32 3, 2 %4 = sub nsw i32 %3, 5 %5 = xor i32 4, 4 %6 = xor i32 %5, %5 %7 = or i32 5, %4 %8 = and i32 %4, 2 %9 = or i32 7, 2 %10 = or i32 %8, %6 %11 = and i32 %9, %10 ret void } *Assembly file:* Return; As you can see...,all the code is eliminated as dead code...,now is there a possibility to stop Dead code elimination? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150511/c182e0ff/attachment.html>
Reasonably Related Threads
- [LLVMdev] How to Store variable allocation in Registers
- Question about Prolog/Epilog Code Insertion
- [LLVMdev] How can I output assembly comments from emitPrologue()?
- Not able to display domain users using wbinfo
- Enforcing local profile doesn't let Home Directory mapping