Hi all, I have recently encountered a problem when creating LLVM IRs. I am wondering if there is a standard or easy way to create a load from a certain register? For example, CreateLoad(rbp, NAME). Thanks, Chen -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131213/ec277276/attachment.html>
Hi Chen,> I have recently encountered a problem when creating LLVM IRs. I am wondering > if there is a standard or easy way to create a load from a certain register? > For example, CreateLoad(rbp, NAME).LLVM doesn't directly provide access to any machine registers. If you want %rbp because it's the frame pointer then for that one case there is actually an @llvm.frameaddress intrinsic you can call to get it. But if you want other registers as well, the only way I can think of is through inline assembly. This is roughly the line clang produces, and should be sufficient: %my_value = call i64 asm "movq $0, %rbp", "=r"() Cheers. Tim.
Hi Tim, Thanks for the reply. All I need right now are %rbp and %rsp, in other words are frame pointer and stack pointer. I guess @llvm.frameaddress intrinsic work for %rbp in this case, and does @llvm.stacksave return the stack pointer? Thanks, Chen On Dec 13, 2013, at 11:42 PM, Tim Northover <t.p.northover at gmail.com> wrote:> Hi Chen, > >> I have recently encountered a problem when creating LLVM IRs. I am wondering >> if there is a standard or easy way to create a load from a certain register? >> For example, CreateLoad(rbp, NAME). > > LLVM doesn't directly provide access to any machine registers. If you > want %rbp because it's the frame pointer then for that one case there > is actually an @llvm.frameaddress intrinsic you can call to get it. > But if you want other registers as well, the only way I can think of > is through inline assembly. > > This is roughly the line clang produces, and should be sufficient: > > %my_value = call i64 asm "movq $0, %rbp", "=r"() > > Cheers. > > Tim.