[llvm-dev] How to create a proper MachineMemOperand?

92 views
Skip to first unread message

Will Lester via llvm-dev

unread,
Apr 16, 2018, 4:25:34 AM4/16/18
to via llvm-dev
Hi all,
I met a new problem in the process of my project.
I have got an address by mmap. And I want to build a MachineInstr of MOV64mr to move a value to the address. But it seems that the MachinePointerInfo needs a pointer to a Value.
So can I create a MachineMemOperand directly with the address (is a long*) ? Or I need to try some other methods?
Thanks a lot,
Will

陳韋任 via llvm-dev

unread,
Apr 16, 2018, 9:20:19 AM4/16/18
to Will Lester, via llvm-dev
Usually I will search the target directory, X86 in your case, to see
how MOV64mr is used with BuildMI to generate the instruction I want.

> _______________________________________________
> LLVM Developers mailing list
> llvm...@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>

--
Wei-Ren Chen (陳韋任)
Homepage: https://people.cs.nctu.edu.tw/~chenwj
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Will Lester via llvm-dev

unread,
Apr 16, 2018, 10:49:43 PM4/16/18
to 陳韋任, via llvm-dev
Thanks for your advice. But I have searched X86 and find no more information than I have known.
The problem is not to create a MachineMemOperand, but to create a MachineMemOperand with certain address. This scene does not exist in the original code.
Since I have to do this in the process of register allocating, inserting IR instruction seems to be infeasible. I have thought of storing the address in a global variable in the IR, and loading it afterwards. But it seems to be improper as mentioned before.
May I do not create a MachineMemOperand, just store the address in a register, and use some MachineInstr to store the value to the address?

Tim Northover via llvm-dev

unread,
Apr 17, 2018, 5:50:14 AM4/17/18
to Will Lester, via llvm-dev
On 17 April 2018 at 03:49, Will Lester via llvm-dev

<llvm...@lists.llvm.org> wrote:
> The problem is not to create a MachineMemOperand, but to create a
> MachineMemOperand with certain address. This scene does not exist in the
> original code.

MachineMemOperands are used to tell compiler optimizations where a
memory instruction will access. It's not the actual representation
used to tell the CPU where to load or store. So you can conservatively
create a dummy one that essentially tells LLVM "this may write
anywhere" and your program will compile correctly.

To do that you'd write something like
"MF->getMachineMemOperand(MachinePointerInfo(),
MachineMemOperand::MOStore, 0, 1)". I've not tested this in code, so
you may have to tweak it.

Cheers.

Tim.

Reply all
Reply to author
Forward
0 new messages