[llvm-dev] Quick question: How to BuildMI mov64mi32 arbitrary MMB address to memory

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 25 01:49:11 PDT 2018


On Tue, 25 Sep 2018 at 00:29, K Jelesnianski <kjski at vt.edu> wrote:
> My question now is how would you create the BuildMI for the second assembly instr (addq (LBB0_0 - func), %rax) you proposed? I know I can get the global address of the MF we are currently in with .addGlobalAddress(M->getNamedValue(MF.getName())) but how do we take that and make an expression out of it. I am not sure the MBB object gives us any way to  get its address and perform the given subtraction expression of LBB0_0 - func.
> [...]
> If I try to put a simple asm.s into llvm-mc -show-inst, it tells me to use MCExpr, but I am not sure that is correct (shown below). There does exist .addExpr but it only valid for MCInstBuilder, not MachineInstrBuilder::BuildMI.

Yes, I don't think you can put an MCExpr on a MachineInstr so you'll
probably need a pseudo-instruction that's expanded in
X86MCInstLower::Lower (when the MachineInstr gets converted to an
MCInst). You can use MachineBasicBlock::getSymbol and probably
something like GetSymbolFromOperand for the function (i.e. global)

Cheers.

Tim.


More information about the llvm-dev mailing list