Avinash Bole
2015-May-20 09:57 UTC
[LLVMdev] How to stop target from writing results back to memory in MSP430
Hello!! Im trying to write a C Backend using LLVM. I tried modifying the target "MSP430" to suit my backend. My target Architecture doesnt have a STACK. so i used "mem2reg" option using "OPT". Now Problem i have is..., the results produced are being written back to memory. Following example should illustrate the problem *Intermediate file after MEM2REG pass:* @.str = private unnamed_addr constant [9 x i8] c"%d %d %d\00", align 1 ; Function Attrs: nounwind 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 %12 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([9 x i8]* @.str, i32 0, i32 0), i32 7, i32 %11, i32 %6) ret void } *Assembly file in my target:* main: ; @main ; BB#0: Mov REG[12],.L.str,4 Mov 0(REG[1]), REG[12],4 Mov 6(REG[1]), 0,4 Mov 4(REG[1]), 0,4 Mov 2(REG[1]), 7,4 Call printf Nop Nop Return; .Ltmp0: .size main, .Ltmp0-main .type .L.str, at object ; @.str .section .rodata.str1.1,"aMS", at progbits,1 .L.str: .asciz "%d %d %d" .size .L.str, 9 As you can see..., 0 is written to 6(REG[1]) in third line. here REG[1] is my frame pointer register and the compiler is writing result to memory location 6(REG[1]). This would have been valid with a stack..,but since my target doesnt have a stack, i need to keep the results in REGISTERS ONLY. So...,please suggest me how to prevent writing the final results to memory Regards, Avinash -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150520/a50730e8/attachment.html>
Bruce Hoult
2015-May-20 13:19 UTC
[LLVMdev] How to stop target from writing results back to memory in MSP430
Hi Avinash, As previously pointed out to you, you can't compile a high level function-based language without using frames. If recursion is not allowed (traditional FORTRAN or COBOL, but not C!) then the frames can be statically allocated at fixed global addreses. If you have hundreds or thousands of registers then registers could be allocated to frames. But with a normal number of registers that is not possible. If recursion is allowed, then the frames will have to be stored on a heap, or a stack. It is irrelevant whether or not your hardware provides convenient stack instructions. If not, then you have to create one yourself, in software. On Wed, May 20, 2015 at 12:57 PM, Avinash Bole <boleavinash at gmail.com> wrote:> Hello!! > > Im trying to write a C Backend using LLVM. I tried modifying the target > "MSP430" to suit my backend. My target Architecture doesnt have a STACK. so > i used "mem2reg" option using "OPT". Now Problem i have is..., the results > produced are being written back to memory. > > Following example should illustrate the problem > > *Intermediate file after MEM2REG pass:* > > @.str = private unnamed_addr constant [9 x i8] c"%d %d %d\00", align 1 > > ; Function Attrs: nounwind > 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 > %12 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([9 x i8]* > @.str, i32 0, i32 0), i32 7, i32 %11, i32 %6) > ret void > } > > *Assembly file in my target:* > > main: ; @main > ; BB#0: > Mov REG[12],.L.str,4 > Mov 0(REG[1]), REG[12],4 > Mov 6(REG[1]), 0,4 > Mov 4(REG[1]), 0,4 > Mov 2(REG[1]), 7,4 > Call printf > Nop > Nop > Return; > .Ltmp0: > .size main, .Ltmp0-main > > .type .L.str, at object ; @.str > .section .rodata.str1.1,"aMS", at progbits,1 > > .L.str: > .asciz "%d %d %d" > .size .L.str, 9 > > > As you can see..., 0 is written to 6(REG[1]) in third line. here REG[1] is > my frame pointer register and the compiler is writing result to memory > location 6(REG[1]). > > This would have been valid with a stack..,but since my target doesnt have > a stack, i need to keep the results in REGISTERS ONLY. > > So...,please suggest me how to prevent writing the final results to memory > > Regards, > 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/20150520/2abdfbd3/attachment.html>